diff options
author | Dana Conrad <dconrad@fastmail.com> | 2024-09-11 02:24:22 +0000 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2024-09-12 17:09:52 -0400 |
commit | 2a0f3c8276c397b384ffa8b57fa62f38f3cea6a9 (patch) | |
tree | 63baf57542a4b40d176d5d6d57821168d411c6e1 | |
parent | 85652e6bd153b5775cb4a57c7bad66fee85d415f (diff) | |
download | rockbox-2a0f3c8276c397b384ffa8b57fa62f38f3cea6a9.tar.gz rockbox-2a0f3c8276c397b384ffa8b57fa62f38f3cea6a9.zip |
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
-rwxr-xr-x | tools/hibyos_nativepatcher/hibyos_nativepatcher.sh | 246 |
1 files changed, 175 insertions, 71 deletions
diff --git a/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh b/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh index e0a76da5c2..3c6661863f 100755 --- a/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh +++ b/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh | |||
@@ -1,7 +1,25 @@ | |||
1 | #!/bin/bash | 1 | #!/bin/bash |
2 | # USAGE: ./hibyos_nativepatcher.sh <path/to/updatefile.upt> <path/to/bootloader.erosq> | 2 | # hibyos_nativepatcher.sh |
3 | # | ||
3 | # NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS | 4 | # NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS |
4 | 5 | ||
6 | usage="hibyos_nativepatcher.sh | ||
7 | |||
8 | USAGE: | ||
9 | |||
10 | hibyos_nativepatcher.sh <mkrbinstall/mkstockuboot> [arguments depend on mode, see below] | ||
11 | |||
12 | hibyos_nativepatcher.sh mkrbinstall <OFVERNAME (erosq or eros_h2)> | ||
13 | <path/to/output> <path/to/bootloader.erosq> <HWVER (hw1hw2 or hw3)> | ||
14 | Output file will be path/to/output/erosqnative_RBVER-HWVER-OFVERNAME.upt. | ||
15 | Only the Hifiwalker H2 v1.3 uses "eros_h2", everything else uses "erosq". | ||
16 | |||
17 | hibyos_nativepatcher.sh mkstockuboot <path/to/OFupdatefile.upt> | ||
18 | Output file will be path/to/OFupdatefile-rbuninstall.upt. | ||
19 | |||
20 | NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS!" | ||
21 | |||
22 | # check OS type and for any needed tools | ||
5 | if [[ "$OSTYPE" == "darwin"* ]]; then | 23 | if [[ "$OSTYPE" == "darwin"* ]]; then |
6 | echo "$OSTYPE DETECTED" | 24 | echo "$OSTYPE DETECTED" |
7 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | 25 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then |
@@ -19,99 +37,185 @@ else | |||
19 | exit 1 | 37 | exit 1 |
20 | fi | 38 | fi |
21 | 39 | ||
40 | # make sure we can find patch_manifest | ||
22 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | 41 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
23 | if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then | 42 | if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then |
24 | echo "couldn't find patch_manifest.pl!" | 43 | echo "couldn't find patch_manifest.pl!" |
25 | exit 1 | 44 | exit 1 |
26 | fi | 45 | fi |
27 | 46 | ||
28 | updatefile=$(realpath --relative-base=$(pwd) $1) | 47 | ########################################################################### |
29 | updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") | 48 | # MKRBINSTALL |
30 | updatefile_name=$(basename $updatefile) | 49 | ########################################################################### |
31 | updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") | 50 | if [[ "$1" == "mkrbinstall" ]]; then |
32 | bootfile=$(realpath --relative-base=$(pwd) $2) | 51 | echo "Creating installation image from bootloader file..." |
33 | echo "This will patch $updatefile with $bootfile..." | ||
34 | 52 | ||
35 | echo "MAKE WORKING DIR..." | 53 | # make sure all arguments are accounted for... |
36 | mkdir $updatefile_path/working_dir | 54 | if [[ -z "$5" ]]; then |
37 | working_dir=$(realpath $updatefile_path/working_dir) | 55 | echo "not all parameters included, please see usage:" |
56 | echo "$usage" | ||
57 | exit 1 | ||
58 | fi | ||
38 | 59 | ||
39 | # copy update.upt to update.iso | 60 | # validate arguments |
40 | cp $updatefile $working_dir/$updatefile_name_noext\_cpy.iso | 61 | outputdir=$(realpath --relative-base=$(pwd) $3) |
62 | if !(ls $outputdir >& /dev/null); then | ||
63 | echo "directory $outputdir doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh." | ||
64 | exit 1 | ||
65 | fi | ||
41 | 66 | ||
42 | mkdir $working_dir/image_contents | 67 | # note, bootloaderfile might still be a valid path, but not a valid bootloader file... check to make sure tar can extract it okay. |
68 | bootloaderfile=$(realpath --relative-base=$(pwd) $4) | ||
69 | if !(ls $bootloaderfile >& /dev/null); then | ||
70 | echo "bootloader file $bootloaderfile doesn't seem to exist. Please make sure it exists, then re-run hibyos_nativepatcher.sh." | ||
71 | exit 1 | ||
72 | fi | ||
43 | 73 | ||
44 | # attach/mount iso | 74 | # make working directory... |
45 | echo "mount/extract/unmount original iso..." | 75 | mkdir $outputdir/working_dir |
46 | if [[ "$OSTYPE" == "darwin"* ]]; then | 76 | workingdir=$(realpath $outputdir/working_dir) |
47 | # macos | 77 | mkdir $workingdir/bootloader |
48 | hdiutil attach $working_dir/$updatefile_name_noext\_cpy.iso -mountpoint $working_dir/contentsiso | 78 | |
79 | # extract bootloader file | ||
80 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
81 | # macos | ||
82 | tar -xvf $bootloaderfile --cd $workingdir/bootloader | ||
83 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
84 | # linux-gnu | ||
85 | tar -xvf $bootloaderfile -C $workingdir/bootloader | ||
86 | fi | ||
49 | 87 | ||
50 | # copy out iso contents | 88 | # make sure we got what we wanted |
51 | cp $working_dir/contentsiso/* $working_dir/image_contents | 89 | if !(ls $workingdir/bootloader/bootloader.ucl >& /dev/null); then |
90 | echo "can't find bootloader.ucl! help!" | ||
91 | rm -rf $workingdir | ||
92 | exit 1 | ||
93 | elif !(ls $workingdir/bootloader/spl.erosq >& /dev/null); then | ||
94 | echo "can't find spl.erosq! help!" | ||
95 | rm -rf $workingdir | ||
96 | exit 1 | ||
97 | fi | ||
52 | 98 | ||
53 | # unmount iso | 99 | bootver=$(cat $workingdir/bootloader/bootloader-info.txt) |
54 | hdiutil detach $working_dir/contentsiso | 100 | if [ -z "$bootver" ]; then |
55 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | 101 | echo "COULDN'T FIND BOOTLOADER-INFO!" |
56 | # linux-gnu | 102 | rm -rf $workingdir |
57 | 7z -o$working_dir/image_contents x $working_dir/$updatefile_name_noext\_cpy.iso | 103 | exit 1 |
58 | fi | 104 | fi |
59 | 105 | ||
60 | chmod 777 $working_dir/image_contents/* | 106 | # if uboot.bin already exists, something is weird. |
107 | if (ls $workingdir/image_contents/uboot.bin >& /dev/null); then | ||
108 | echo "$workingdir/image_contents/uboot.bin already exists, something went weird." | ||
109 | rm -rf $workingdir | ||
110 | exit 1 | ||
111 | fi | ||
61 | 112 | ||
62 | # extract spl, bootloader | 113 | # everything exists, make the bin |
63 | echo "extract bootloader..." | 114 | mkdir $workingdir/image_contents/ |
64 | mkdir $working_dir/bootloader | 115 | touch $workingdir/image_contents/uboot.bin |
116 | echo "PATCHING!" | ||
117 | dd if=$workingdir/bootloader/spl.erosq of=$workingdir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc | ||
118 | dd if=$workingdir/bootloader/bootloader.ucl of=$workingdir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc | ||
119 | |||
120 | # create update.txt | ||
121 | md5=($(md5sum $workingdir/image_contents/uboot.bin)) | ||
122 | if [ -z "$md5" ]; then | ||
123 | echo "COULDN'T MD5SUM UBOOT.BIN!" | ||
124 | rm -rf $workingdir | ||
125 | exit 1 | ||
126 | fi | ||
127 | echo "Create update manifest with md5sum $md5" | ||
128 | echo "" > $workingdir/image_contents/update.txt | ||
129 | $SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt | ||
65 | 130 | ||
66 | if [[ "$OSTYPE" == "darwin"* ]]; then | 131 | # create version.txt |
67 | # macos | 132 | echo "version={ |
68 | tar -xvf $bootfile --cd $working_dir/bootloader | 133 | name=$2 |
69 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | 134 | ver=2024-09-10T14:42:18+08:00 |
70 | # linux-gnu | 135 | }" > $workingdir/image_contents/version.txt |
71 | tar -xvf $bootfile -C $working_dir/bootloader | ||
72 | fi | ||
73 | 136 | ||
74 | bootver=$(cat $working_dir/bootloader/bootloader-info.txt) | 137 | outputfilename="erosqnative_$bootver-$5-$2" |
75 | if [ -z "$bootver" ]; then | 138 | |
76 | echo "COULDN'T FIND BOOTLOADER-INFO!" | 139 | |
77 | echo "cleaning up..." | 140 | ########################################################################### |
78 | rm -rf $working_dir | 141 | # MKSTOCKUBOOT |
79 | exit 1 | 142 | ########################################################################### |
80 | fi | 143 | elif [[ "$1" == "mkstockuboot" ]]; then |
81 | echo "FOUND VERSION $bootver" | 144 | echo "Creating uninstallation image from stock update image..." |
82 | 145 | ||
83 | # patch uboot.bin | 146 | # make sure all arguments are accounted for... |
84 | echo "PATCH!" | 147 | if [[ -z "$2" ]]; then |
85 | dd if=$working_dir/bootloader/spl.erosq of=$working_dir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc | 148 | echo "not all parameters included, please see usage:" |
86 | dd if=$working_dir/bootloader/bootloader.ucl of=$working_dir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc | 149 | echo "$usage" |
87 | 150 | exit 1 | |
88 | # modify update.txt | 151 | fi |
89 | md5=($(md5sum $working_dir/image_contents/uboot.bin)) | 152 | |
90 | if [ -z "$md5" ]; then | 153 | updatefile=$(realpath --relative-base=$(pwd) $2) |
91 | echo "COULDN'T MD5SUM UBOOT.BIN!" | 154 | updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") |
92 | echo "cleaning up..." | 155 | updatefile_name=$(basename $updatefile) |
93 | rm -rf $working_dir | 156 | updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") |
157 | outputdir=$updatefile_path | ||
158 | outputfilename="$updatefile_name_noext-rbuninstall" | ||
159 | |||
160 | mkdir $updatefile_path/working_dir | ||
161 | workingdir=$(realpath $updatefile_path/working_dir) | ||
162 | |||
163 | # copy update.upt to update.iso | ||
164 | cp $updatefile $workingdir/$updatefile_name_noext-cpy.iso | ||
165 | |||
166 | mkdir $workingdir/image_contents | ||
167 | |||
168 | # extract iso | ||
169 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
170 | # macos | ||
171 | hdiutil attach $workingdir/$updatefile_name_noext-cpy.iso -mountpoint $workingdir/contentsiso | ||
172 | |||
173 | # copy out iso contents | ||
174 | cp $workingdir/contentsiso/* $workingdir/image_contents | ||
175 | |||
176 | # unmount iso | ||
177 | hdiutil detach $workingdir/contentsiso | ||
178 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
179 | # linux-gnu | ||
180 | 7z -o$workingdir/image_contents x $workingdir/$updatefile_name_noext-cpy.iso | ||
181 | fi | ||
182 | |||
183 | chmod 777 $workingdir/image_contents/* | ||
184 | |||
185 | # modify update.txt | ||
186 | md5=($(md5sum $workingdir/image_contents/uboot.bin)) | ||
187 | if [ -z "$md5" ]; then | ||
188 | echo "COULDN'T MD5SUM UBOOT.BIN!" | ||
189 | rm -rf $working_dir | ||
190 | exit 1 | ||
191 | fi | ||
192 | echo "add to update manifest with md5sum $md5" | ||
193 | $SCRIPT_DIR/patch_manifest.pl $md5 $workingdir/image_contents/update.txt | ||
194 | |||
195 | ###################################################################### | ||
196 | # PRINT USAGE | ||
197 | ###################################################################### | ||
198 | else | ||
199 | echo "$usage" | ||
94 | exit 1 | 200 | exit 1 |
95 | fi | 201 | fi |
96 | echo "add to update manifest with md5sum $md5" | ||
97 | $SCRIPT_DIR/patch_manifest.pl $md5 $working_dir/image_contents/update.txt | ||
98 | |||
99 | # modify version.txt? | ||
100 | 202 | ||
101 | # create iso | 203 | ###################################################################### |
102 | echo "make new iso..." | 204 | # Common: make the image |
205 | ###################################################################### | ||
206 | # make the image | ||
103 | if [[ "$OSTYPE" == "darwin"* ]]; then | 207 | if [[ "$OSTYPE" == "darwin"* ]]; then |
104 | # macos | 208 | # macos |
105 | hdiutil makehybrid -iso -joliet -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ | 209 | hdiutil makehybrid -iso -joliet -o $outputdir/output.iso $workingdir/image_contents/ |
106 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | 210 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then |
107 | # linux-gnu | 211 | # linux-gnu |
108 | genisoimage -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ | 212 | genisoimage -o $outputdir/output.iso $workingdir/image_contents/ |
109 | fi | 213 | fi |
110 | 214 | ||
111 | # rename to something.upt and put in original directory | 215 | # rename |
112 | echo "final output file $updatefile_name_noext\_patched_$bootver.upt" | 216 | mv $outputdir/output.iso $outputdir/$outputfilename.upt |
113 | mv $working_dir/$updatefile_name_noext\_patched_$bootver.iso $updatefile_path/$updatefile_name_noext\_patched_$bootver.upt | 217 | |
218 | # cleaning up | ||
219 | rm -rf $workingdir | ||
114 | 220 | ||
115 | # clean up | 221 | exit 0 |
116 | echo "cleaning up..." | ||
117 | rm -rf $working_dir | ||