diff options
author | Dana Conrad <dconrad@fastmail.com> | 2024-08-31 15:49:28 +0000 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2024-09-08 12:29:23 -0400 |
commit | 89fd4d0a519a0185c6446de127fc5236990b6a8c (patch) | |
tree | 624299658b0d6f3799cee8991537ddb60db381e0 | |
parent | a5462d6192909dd0abbae15b19d634ca1c0ed4a2 (diff) | |
download | rockbox-89fd4d0a51.tar.gz rockbox-89fd4d0a51.zip |
hibyOS: OF patcher script for Native ports
This is a script to patch a native bootloader
(bootloader.*) into a stock OF firmware image (update.upt).
Usage: hibyos_nativepatcher.sh <path/to/update.upt>
<path/to/bootloder.*>
Resulting file will be placed next to the original update, and will
be named [$orig_name]_patched_[$rbver].upt
Now with some rudimentary error checking at key points!
Works on macos.
Works on linux, at least debian in docker. Linux
usage requires 7z and genisoimage.
Change-Id: I2878e7ab4652b73f44c6f1efd54047953f636c86
-rwxr-xr-x | tools/hibyos_nativepatcher/hibyos_nativepatcher.sh | 117 | ||||
-rwxr-xr-x | tools/hibyos_nativepatcher/patch_manifest.pl | 27 |
2 files changed, 144 insertions, 0 deletions
diff --git a/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh b/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh new file mode 100755 index 0000000000..e0a76da5c2 --- /dev/null +++ b/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh @@ -0,0 +1,117 @@ +#!/bin/bash +# USAGE: ./hibyos_nativepatcher.sh <path/to/updatefile.upt> <path/to/bootloader.erosq> +# NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS + +if [[ "$OSTYPE" == "darwin"* ]]; then + echo "$OSTYPE DETECTED" +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + echo "$OSTYPE DETECTED" + if !(which 7z > /dev/null); then + echo "PLEASE INSTALL 7z (usually part of p7zip-full package)" + exit 1 + fi + if !(which genisoimage > /dev/null); then + echo "PLEASE INSTALL genisoimage" + exit 1 + fi +else + echo "SCRIPT NOT IMPLEMENTED ON $OSTYPE YET!" + exit 1 +fi + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then + echo "couldn't find patch_manifest.pl!" + exit 1 +fi + +updatefile=$(realpath --relative-base=$(pwd) $1) +updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") +updatefile_name=$(basename $updatefile) +updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") +bootfile=$(realpath --relative-base=$(pwd) $2) +echo "This will patch $updatefile with $bootfile..." + +echo "MAKE WORKING DIR..." +mkdir $updatefile_path/working_dir +working_dir=$(realpath $updatefile_path/working_dir) + +# copy update.upt to update.iso +cp $updatefile $working_dir/$updatefile_name_noext\_cpy.iso + +mkdir $working_dir/image_contents + +# attach/mount iso +echo "mount/extract/unmount original iso..." +if [[ "$OSTYPE" == "darwin"* ]]; then + # macos + hdiutil attach $working_dir/$updatefile_name_noext\_cpy.iso -mountpoint $working_dir/contentsiso + + # copy out iso contents + cp $working_dir/contentsiso/* $working_dir/image_contents + + # unmount iso + hdiutil detach $working_dir/contentsiso +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # linux-gnu + 7z -o$working_dir/image_contents x $working_dir/$updatefile_name_noext\_cpy.iso +fi + +chmod 777 $working_dir/image_contents/* + +# extract spl, bootloader +echo "extract bootloader..." +mkdir $working_dir/bootloader + +if [[ "$OSTYPE" == "darwin"* ]]; then + # macos + tar -xvf $bootfile --cd $working_dir/bootloader +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # linux-gnu + tar -xvf $bootfile -C $working_dir/bootloader +fi + +bootver=$(cat $working_dir/bootloader/bootloader-info.txt) +if [ -z "$bootver" ]; then + echo "COULDN'T FIND BOOTLOADER-INFO!" + echo "cleaning up..." + rm -rf $working_dir + exit 1 +fi +echo "FOUND VERSION $bootver" + +# patch uboot.bin +echo "PATCH!" +dd if=$working_dir/bootloader/spl.erosq of=$working_dir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc +dd if=$working_dir/bootloader/bootloader.ucl of=$working_dir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc + +# modify update.txt +md5=($(md5sum $working_dir/image_contents/uboot.bin)) +if [ -z "$md5" ]; then + echo "COULDN'T MD5SUM UBOOT.BIN!" + echo "cleaning up..." + rm -rf $working_dir + exit 1 +fi +echo "add to update manifest with md5sum $md5" +$SCRIPT_DIR/patch_manifest.pl $md5 $working_dir/image_contents/update.txt + +# modify version.txt? + +# create iso +echo "make new iso..." +if [[ "$OSTYPE" == "darwin"* ]]; then + # macos + hdiutil makehybrid -iso -joliet -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + # linux-gnu + genisoimage -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ +fi + +# rename to something.upt and put in original directory +echo "final output file $updatefile_name_noext\_patched_$bootver.upt" +mv $working_dir/$updatefile_name_noext\_patched_$bootver.iso $updatefile_path/$updatefile_name_noext\_patched_$bootver.upt + +# clean up +echo "cleaning up..." +rm -rf $working_dir diff --git a/tools/hibyos_nativepatcher/patch_manifest.pl b/tools/hibyos_nativepatcher/patch_manifest.pl new file mode 100755 index 0000000000..82c6378c65 --- /dev/null +++ b/tools/hibyos_nativepatcher/patch_manifest.pl @@ -0,0 +1,27 @@ +#!/usr/bin/perl +# add bootloader info to update manifest +# usage: ./patch_manifest.pl <md5sum> <path/to/update.txt> + +my $md5 = $ARGV[0]; +my $updatefile = $ARGV[1]; +my $bootloader_manif = +"bootloader={ + name=uboot + file_path=autoupdate/uboot.bin + md5=$md5 +}\n"; + +# read in existing manifest +open(FH, '<', "$updatefile"); +read(FH, my $manifest, -s FH); +close(FH); + +# delete existing bootloader entry if exists +$manifest =~ s/bootloader\s*=\s*{[^}]*}//; + +# add our own bootloader entry +$manifest = "$bootloader_manif$manifest"; + +open(FH, '>', "$updatefile"); +print FH $manifest; +close(FH); |