diff options
Diffstat (limited to 'tools/hibyos_nativepatcher')
-rwxr-xr-x | tools/hibyos_nativepatcher/hibyos_nativepatcher.sh | 221 | ||||
-rwxr-xr-x | tools/hibyos_nativepatcher/patch_manifest.pl | 27 |
2 files changed, 248 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..3c6661863f --- /dev/null +++ b/tools/hibyos_nativepatcher/hibyos_nativepatcher.sh | |||
@@ -0,0 +1,221 @@ | |||
1 | #!/bin/bash | ||
2 | # hibyos_nativepatcher.sh | ||
3 | # | ||
4 | # NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS | ||
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 | ||
23 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
24 | echo "$OSTYPE DETECTED" | ||
25 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
26 | echo "$OSTYPE DETECTED" | ||
27 | if !(which 7z > /dev/null); then | ||
28 | echo "PLEASE INSTALL 7z (usually part of p7zip-full package)" | ||
29 | exit 1 | ||
30 | fi | ||
31 | if !(which genisoimage > /dev/null); then | ||
32 | echo "PLEASE INSTALL genisoimage" | ||
33 | exit 1 | ||
34 | fi | ||
35 | else | ||
36 | echo "SCRIPT NOT IMPLEMENTED ON $OSTYPE YET!" | ||
37 | exit 1 | ||
38 | fi | ||
39 | |||
40 | # make sure we can find patch_manifest | ||
41 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
42 | if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then | ||
43 | echo "couldn't find patch_manifest.pl!" | ||
44 | exit 1 | ||
45 | fi | ||
46 | |||
47 | ########################################################################### | ||
48 | # MKRBINSTALL | ||
49 | ########################################################################### | ||
50 | if [[ "$1" == "mkrbinstall" ]]; then | ||
51 | echo "Creating installation image from bootloader file..." | ||
52 | |||
53 | # make sure all arguments are accounted for... | ||
54 | if [[ -z "$5" ]]; then | ||
55 | echo "not all parameters included, please see usage:" | ||
56 | echo "$usage" | ||
57 | exit 1 | ||
58 | fi | ||
59 | |||
60 | # validate arguments | ||
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 | ||
66 | |||
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 | ||
73 | |||
74 | # make working directory... | ||
75 | mkdir $outputdir/working_dir | ||
76 | workingdir=$(realpath $outputdir/working_dir) | ||
77 | mkdir $workingdir/bootloader | ||
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 | ||
87 | |||
88 | # make sure we got what we wanted | ||
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 | ||
98 | |||
99 | bootver=$(cat $workingdir/bootloader/bootloader-info.txt) | ||
100 | if [ -z "$bootver" ]; then | ||
101 | echo "COULDN'T FIND BOOTLOADER-INFO!" | ||
102 | rm -rf $workingdir | ||
103 | exit 1 | ||
104 | fi | ||
105 | |||
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 | ||
112 | |||
113 | # everything exists, make the bin | ||
114 | mkdir $workingdir/image_contents/ | ||
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 | ||
130 | |||
131 | # create version.txt | ||
132 | echo "version={ | ||
133 | name=$2 | ||
134 | ver=2024-09-10T14:42:18+08:00 | ||
135 | }" > $workingdir/image_contents/version.txt | ||
136 | |||
137 | outputfilename="erosqnative_$bootver-$5-$2" | ||
138 | |||
139 | |||
140 | ########################################################################### | ||
141 | # MKSTOCKUBOOT | ||
142 | ########################################################################### | ||
143 | elif [[ "$1" == "mkstockuboot" ]]; then | ||
144 | echo "Creating uninstallation image from stock update image..." | ||
145 | |||
146 | # make sure all arguments are accounted for... | ||
147 | if [[ -z "$2" ]]; then | ||
148 | echo "not all parameters included, please see usage:" | ||
149 | echo "$usage" | ||
150 | exit 1 | ||
151 | fi | ||
152 | |||
153 | updatefile=$(realpath --relative-base=$(pwd) $2) | ||
154 | updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") | ||
155 | updatefile_name=$(basename $updatefile) | ||
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" | ||
200 | exit 1 | ||
201 | fi | ||
202 | |||
203 | ###################################################################### | ||
204 | # Common: make the image | ||
205 | ###################################################################### | ||
206 | # make the image | ||
207 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
208 | # macos | ||
209 | hdiutil makehybrid -iso -joliet -o $outputdir/output.iso $workingdir/image_contents/ | ||
210 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
211 | # linux-gnu | ||
212 | genisoimage -o $outputdir/output.iso $workingdir/image_contents/ | ||
213 | fi | ||
214 | |||
215 | # rename | ||
216 | mv $outputdir/output.iso $outputdir/$outputfilename.upt | ||
217 | |||
218 | # cleaning up | ||
219 | rm -rf $workingdir | ||
220 | |||
221 | exit 0 | ||
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 @@ | |||
1 | #!/usr/bin/perl | ||
2 | # add bootloader info to update manifest | ||
3 | # usage: ./patch_manifest.pl <md5sum> <path/to/update.txt> | ||
4 | |||
5 | my $md5 = $ARGV[0]; | ||
6 | my $updatefile = $ARGV[1]; | ||
7 | my $bootloader_manif = | ||
8 | "bootloader={ | ||
9 | name=uboot | ||
10 | file_path=autoupdate/uboot.bin | ||
11 | md5=$md5 | ||
12 | }\n"; | ||
13 | |||
14 | # read in existing manifest | ||
15 | open(FH, '<', "$updatefile"); | ||
16 | read(FH, my $manifest, -s FH); | ||
17 | close(FH); | ||
18 | |||
19 | # delete existing bootloader entry if exists | ||
20 | $manifest =~ s/bootloader\s*=\s*{[^}]*}//; | ||
21 | |||
22 | # add our own bootloader entry | ||
23 | $manifest = "$bootloader_manif$manifest"; | ||
24 | |||
25 | open(FH, '>', "$updatefile"); | ||
26 | print FH $manifest; | ||
27 | close(FH); | ||