1
0
Fork 0
forked from len0rd/rockbox

hibyos_nativepatcher: rewrite for either fresh install or uninstall

Since we can easily create our own install files for erosqnative,
modify script to create fresh install image from bootloader.erosq
or add bootloader to installation manifest of stock update file
to uninstall rockbox.

USAGE:

    hibyos_nativepatcher.sh <mkrbinstall/mkstockuboot> [arguments depend on mode, see below]

    hibyos_nativepatcher.sh mkrbinstall <OFVERNAME (erosq or eros_h2)>
        <path/to/output> <path/to/bootloader.erosq> <HWVER (hw1hw2 or hw3)>
        Output file will be path/to/output/erosqnative_RBVER-HWVER-OFVERNAME.upt.
        Only the Hifiwalker H2 v1.3 uses "eros_h2", everything else uses "erosq".

    hibyos_nativepatcher.sh mkstockuboot <path/to/OFupdatefile.upt>
        Output file will be path/to/OFupdatefile-rbuninstall.upt.

Change-Id: I16bc6e43c42f99475ebdd5ec1ac1bae047129745
This commit is contained in:
Dana Conrad 2024-09-11 02:24:22 +00:00 committed by Solomon Peachy
parent 85652e6bd1
commit 2a0f3c8276

View file

@ -1,7 +1,25 @@
#!/bin/bash #!/bin/bash
# USAGE: ./hibyos_nativepatcher.sh <path/to/updatefile.upt> <path/to/bootloader.erosq> # hibyos_nativepatcher.sh
#
# NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS # NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS
usage="hibyos_nativepatcher.sh
USAGE:
hibyos_nativepatcher.sh <mkrbinstall/mkstockuboot> [arguments depend on mode, see below]
hibyos_nativepatcher.sh mkrbinstall <OFVERNAME (erosq or eros_h2)>
<path/to/output> <path/to/bootloader.erosq> <HWVER (hw1hw2 or hw3)>
Output file will be path/to/output/erosqnative_RBVER-HWVER-OFVERNAME.upt.
Only the Hifiwalker H2 v1.3 uses "eros_h2", everything else uses "erosq".
hibyos_nativepatcher.sh mkstockuboot <path/to/OFupdatefile.upt>
Output file will be path/to/OFupdatefile-rbuninstall.upt.
NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS!"
# check OS type and for any needed tools
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
echo "$OSTYPE DETECTED" echo "$OSTYPE DETECTED"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
@ -19,99 +37,185 @@ else
exit 1 exit 1
fi fi
# make sure we can find patch_manifest
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then
echo "couldn't find patch_manifest.pl!" echo "couldn't find patch_manifest.pl!"
exit 1 exit 1
fi fi
updatefile=$(realpath --relative-base=$(pwd) $1) ###########################################################################
updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") # MKRBINSTALL
updatefile_name=$(basename $updatefile) ###########################################################################
updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") if [[ "$1" == "mkrbinstall" ]]; then
bootfile=$(realpath --relative-base=$(pwd) $2) echo "Creating installation image from bootloader file..."
echo "This will patch $updatefile with $bootfile..."
echo "MAKE WORKING DIR..." # make sure all arguments are accounted for...
mkdir $updatefile_path/working_dir if [[ -z "$5" ]]; then
working_dir=$(realpath $updatefile_path/working_dir) echo "not all parameters included, please see usage:"
echo "$usage"
exit 1
fi
# copy update.upt to update.iso # validate arguments
cp $updatefile $working_dir/$updatefile_name_noext\_cpy.iso outputdir=$(realpath --relative-base=$(pwd) $3)
if !(ls $outputdir >& /dev/null); then
echo "directory $outputdir doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh."
exit 1
fi
mkdir $working_dir/image_contents # note, bootloaderfile might still be a valid path, but not a valid bootloader file... check to make sure tar can extract it okay.
bootloaderfile=$(realpath --relative-base=$(pwd) $4)
if !(ls $bootloaderfile >& /dev/null); then
echo "bootloader file $bootloaderfile doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh."
exit 1
fi
# attach/mount iso # make working directory...
echo "mount/extract/unmount original iso..." mkdir $outputdir/working_dir
if [[ "$OSTYPE" == "darwin"* ]]; then workingdir=$(realpath $outputdir/working_dir)
# macos mkdir $workingdir/bootloader
hdiutil attach $working_dir/$updatefile_name_noext\_cpy.iso -mountpoint $working_dir/contentsiso
# copy out iso contents # extract bootloader file
cp $working_dir/contentsiso/* $working_dir/image_contents if [[ "$OSTYPE" == "darwin"* ]]; then
# macos
tar -xvf $bootloaderfile --cd $workingdir/bootloader
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# linux-gnu
tar -xvf $bootloaderfile -C $workingdir/bootloader
fi
# unmount iso # make sure we got what we wanted
hdiutil detach $working_dir/contentsiso if !(ls $workingdir/bootloader/bootloader.ucl >& /dev/null); then
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then echo "can't find bootloader.ucl! help!"
# linux-gnu rm -rf $workingdir
7z -o$working_dir/image_contents x $working_dir/$updatefile_name_noext\_cpy.iso exit 1
fi elif !(ls $workingdir/bootloader/spl.erosq >& /dev/null); then
echo "can't find spl.erosq! help!"
rm -rf $workingdir
exit 1
fi
chmod 777 $working_dir/image_contents/* bootver=$(cat $workingdir/bootloader/bootloader-info.txt)
if [ -z "$bootver" ]; then
echo "COULDN'T FIND BOOTLOADER-INFO!"
rm -rf $workingdir
exit 1
fi
# extract spl, bootloader # if uboot.bin already exists, something is weird.
echo "extract bootloader..." if (ls $workingdir/image_contents/uboot.bin >& /dev/null); then
mkdir $working_dir/bootloader echo "$workingdir/image_contents/uboot.bin already exists, something went weird."
rm -rf $workingdir
exit 1
fi
if [[ "$OSTYPE" == "darwin"* ]]; then # everything exists, make the bin
# macos mkdir $workingdir/image_contents/
tar -xvf $bootfile --cd $working_dir/bootloader touch $workingdir/image_contents/uboot.bin
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then echo "PATCHING!"
# linux-gnu dd if=$workingdir/bootloader/spl.erosq of=$workingdir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc
tar -xvf $bootfile -C $working_dir/bootloader dd if=$workingdir/bootloader/bootloader.ucl of=$workingdir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc
fi
bootver=$(cat $working_dir/bootloader/bootloader-info.txt) # create update.txt
if [ -z "$bootver" ]; then md5=($(md5sum $workingdir/image_contents/uboot.bin))
echo "COULDN'T FIND BOOTLOADER-INFO!" if [ -z "$md5" ]; then
echo "cleaning up..." echo "COULDN'T MD5SUM UBOOT.BIN!"
rm -rf $working_dir rm -rf $workingdir
exit 1
fi
echo "Create update manifest with md5sum $md5"
echo "" > $workingdir/image_contents/update.txt
$SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt
# create version.txt
echo "version={
name=$2
ver=2024-09-10T14:42:18+08:00
}" > $workingdir/image_contents/version.txt
outputfilename="erosqnative_$bootver-$5-$2"
###########################################################################
# MKSTOCKUBOOT
###########################################################################
elif [[ "$1" == "mkstockuboot" ]]; then
echo "Creating uninstallation image from stock update image..."
# make sure all arguments are accounted for...
if [[ -z "$2" ]]; then
echo "not all parameters included, please see usage:"
echo "$usage"
exit 1
fi
updatefile=$(realpath --relative-base=$(pwd) $2)
updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print")
updatefile_name=$(basename $updatefile)
updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print")
outputdir=$updatefile_path
outputfilename="$updatefile_name_noext-rbuninstall"
mkdir $updatefile_path/working_dir
workingdir=$(realpath $updatefile_path/working_dir)
# copy update.upt to update.iso
cp $updatefile $workingdir/$updatefile_name_noext-cpy.iso
mkdir $workingdir/image_contents
# extract iso
if [[ "$OSTYPE" == "darwin"* ]]; then
# macos
hdiutil attach $workingdir/$updatefile_name_noext-cpy.iso -mountpoint $workingdir/contentsiso
# copy out iso contents
cp $workingdir/contentsiso/* $workingdir/image_contents
# unmount iso
hdiutil detach $workingdir/contentsiso
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# linux-gnu
7z -o$workingdir/image_contents x $workingdir/$updatefile_name_noext-cpy.iso
fi
chmod 777 $workingdir/image_contents/*
# modify update.txt
md5=($(md5sum $workingdir/image_contents/uboot.bin))
if [ -z "$md5" ]; then
echo "COULDN'T MD5SUM UBOOT.BIN!"
rm -rf $working_dir
exit 1
fi
echo "add to update manifest with md5sum $md5"
$SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt
######################################################################
# PRINT USAGE
######################################################################
else
echo "$usage"
exit 1 exit 1
fi fi
echo "FOUND VERSION $bootver"
# patch uboot.bin ######################################################################
echo "PATCH!" # Common: make the image
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 # make the image
# 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 if [[ "$OSTYPE" == "darwin"* ]]; then
# macos # macos
hdiutil makehybrid -iso -joliet -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ hdiutil makehybrid -iso -joliet -o $outputdir/output.iso $workingdir/image_contents/
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# linux-gnu # linux-gnu
genisoimage -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ genisoimage -o $outputdir/output.iso $workingdir/image_contents/
fi fi
# rename to something.upt and put in original directory # rename
echo "final output file $updatefile_name_noext\_patched_$bootver.upt" mv $outputdir/output.iso $outputdir/$outputfilename.upt
mv $working_dir/$updatefile_name_noext\_patched_$bootver.iso $updatefile_path/$updatefile_name_noext\_patched_$bootver.upt
# clean up # cleaning up
echo "cleaning up..." rm -rf $workingdir
rm -rf $working_dir
exit 0