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-89fd4d0a519a0185c6446de127fc5236990b6a8c.tar.gz rockbox-89fd4d0a519a0185c6446de127fc5236990b6a8c.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 @@ | |||
1 | #!/bin/bash | ||
2 | # USAGE: ./hibyos_nativepatcher.sh <path/to/updatefile.upt> <path/to/bootloader.erosq> | ||
3 | # NOTE: THIS SCRIPT IS NOT TOLERANT OF WHITESPACE IN FILENAMES OR PATHS | ||
4 | |||
5 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
6 | echo "$OSTYPE DETECTED" | ||
7 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
8 | echo "$OSTYPE DETECTED" | ||
9 | if !(which 7z > /dev/null); then | ||
10 | echo "PLEASE INSTALL 7z (usually part of p7zip-full package)" | ||
11 | exit 1 | ||
12 | fi | ||
13 | if !(which genisoimage > /dev/null); then | ||
14 | echo "PLEASE INSTALL genisoimage" | ||
15 | exit 1 | ||
16 | fi | ||
17 | else | ||
18 | echo "SCRIPT NOT IMPLEMENTED ON $OSTYPE YET!" | ||
19 | exit 1 | ||
20 | fi | ||
21 | |||
22 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
23 | if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then | ||
24 | echo "couldn't find patch_manifest.pl!" | ||
25 | exit 1 | ||
26 | fi | ||
27 | |||
28 | updatefile=$(realpath --relative-base=$(pwd) $1) | ||
29 | updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print") | ||
30 | updatefile_name=$(basename $updatefile) | ||
31 | updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print") | ||
32 | bootfile=$(realpath --relative-base=$(pwd) $2) | ||
33 | echo "This will patch $updatefile with $bootfile..." | ||
34 | |||
35 | echo "MAKE WORKING DIR..." | ||
36 | mkdir $updatefile_path/working_dir | ||
37 | working_dir=$(realpath $updatefile_path/working_dir) | ||
38 | |||
39 | # copy update.upt to update.iso | ||
40 | cp $updatefile $working_dir/$updatefile_name_noext\_cpy.iso | ||
41 | |||
42 | mkdir $working_dir/image_contents | ||
43 | |||
44 | # attach/mount iso | ||
45 | echo "mount/extract/unmount original iso..." | ||
46 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
47 | # macos | ||
48 | hdiutil attach $working_dir/$updatefile_name_noext\_cpy.iso -mountpoint $working_dir/contentsiso | ||
49 | |||
50 | # copy out iso contents | ||
51 | cp $working_dir/contentsiso/* $working_dir/image_contents | ||
52 | |||
53 | # unmount iso | ||
54 | hdiutil detach $working_dir/contentsiso | ||
55 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
56 | # linux-gnu | ||
57 | 7z -o$working_dir/image_contents x $working_dir/$updatefile_name_noext\_cpy.iso | ||
58 | fi | ||
59 | |||
60 | chmod 777 $working_dir/image_contents/* | ||
61 | |||
62 | # extract spl, bootloader | ||
63 | echo "extract bootloader..." | ||
64 | mkdir $working_dir/bootloader | ||
65 | |||
66 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
67 | # macos | ||
68 | tar -xvf $bootfile --cd $working_dir/bootloader | ||
69 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
70 | # linux-gnu | ||
71 | tar -xvf $bootfile -C $working_dir/bootloader | ||
72 | fi | ||
73 | |||
74 | bootver=$(cat $working_dir/bootloader/bootloader-info.txt) | ||
75 | if [ -z "$bootver" ]; then | ||
76 | echo "COULDN'T FIND BOOTLOADER-INFO!" | ||
77 | echo "cleaning up..." | ||
78 | rm -rf $working_dir | ||
79 | exit 1 | ||
80 | fi | ||
81 | echo "FOUND VERSION $bootver" | ||
82 | |||
83 | # patch uboot.bin | ||
84 | echo "PATCH!" | ||
85 | dd if=$working_dir/bootloader/spl.erosq of=$working_dir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc | ||
86 | dd if=$working_dir/bootloader/bootloader.ucl of=$working_dir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc | ||
87 | |||
88 | # modify update.txt | ||
89 | md5=($(md5sum $working_dir/image_contents/uboot.bin)) | ||
90 | if [ -z "$md5" ]; then | ||
91 | echo "COULDN'T MD5SUM UBOOT.BIN!" | ||
92 | echo "cleaning up..." | ||
93 | rm -rf $working_dir | ||
94 | exit 1 | ||
95 | 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 | |||
101 | # create iso | ||
102 | echo "make new iso..." | ||
103 | if [[ "$OSTYPE" == "darwin"* ]]; then | ||
104 | # macos | ||
105 | hdiutil makehybrid -iso -joliet -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ | ||
106 | elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
107 | # linux-gnu | ||
108 | genisoimage -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/ | ||
109 | fi | ||
110 | |||
111 | # rename to something.upt and put in original directory | ||
112 | echo "final output file $updatefile_name_noext\_patched_$bootver.upt" | ||
113 | mv $working_dir/$updatefile_name_noext\_patched_$bootver.iso $updatefile_path/$updatefile_name_noext\_patched_$bootver.upt | ||
114 | |||
115 | # clean up | ||
116 | echo "cleaning up..." | ||
117 | 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 @@ | |||
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); | ||