summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDana Conrad <dconrad@fastmail.com>2024-08-31 15:49:28 +0000
committerSolomon Peachy <pizza@shaftnet.org>2024-09-08 12:29:23 -0400
commit89fd4d0a519a0185c6446de127fc5236990b6a8c (patch)
tree624299658b0d6f3799cee8991537ddb60db381e0 /tools
parenta5462d6192909dd0abbae15b19d634ca1c0ed4a2 (diff)
downloadrockbox-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
Diffstat (limited to 'tools')
-rwxr-xr-xtools/hibyos_nativepatcher/hibyos_nativepatcher.sh117
-rwxr-xr-xtools/hibyos_nativepatcher/patch_manifest.pl27
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
5if [[ "$OSTYPE" == "darwin"* ]]; then
6 echo "$OSTYPE DETECTED"
7elif [[ "$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
17else
18 echo "SCRIPT NOT IMPLEMENTED ON $OSTYPE YET!"
19 exit 1
20fi
21
22SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
23if !(which $SCRIPT_DIR/patch_manifest.pl > /dev/null); then
24 echo "couldn't find patch_manifest.pl!"
25 exit 1
26fi
27
28updatefile=$(realpath --relative-base=$(pwd) $1)
29updatefile_path=$(echo "$updatefile" | perl -ne "s/\/[\w\.\_\-]*$// && print")
30updatefile_name=$(basename $updatefile)
31updatefile_name_noext=$(echo "$updatefile_name" | perl -ne "s/\.\w*$// && print")
32bootfile=$(realpath --relative-base=$(pwd) $2)
33echo "This will patch $updatefile with $bootfile..."
34
35echo "MAKE WORKING DIR..."
36mkdir $updatefile_path/working_dir
37working_dir=$(realpath $updatefile_path/working_dir)
38
39# copy update.upt to update.iso
40cp $updatefile $working_dir/$updatefile_name_noext\_cpy.iso
41
42mkdir $working_dir/image_contents
43
44# attach/mount iso
45echo "mount/extract/unmount original iso..."
46if [[ "$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
55elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
56 # linux-gnu
57 7z -o$working_dir/image_contents x $working_dir/$updatefile_name_noext\_cpy.iso
58fi
59
60chmod 777 $working_dir/image_contents/*
61
62# extract spl, bootloader
63echo "extract bootloader..."
64mkdir $working_dir/bootloader
65
66if [[ "$OSTYPE" == "darwin"* ]]; then
67 # macos
68 tar -xvf $bootfile --cd $working_dir/bootloader
69elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
70 # linux-gnu
71 tar -xvf $bootfile -C $working_dir/bootloader
72fi
73
74bootver=$(cat $working_dir/bootloader/bootloader-info.txt)
75if [ -z "$bootver" ]; then
76 echo "COULDN'T FIND BOOTLOADER-INFO!"
77 echo "cleaning up..."
78 rm -rf $working_dir
79 exit 1
80fi
81echo "FOUND VERSION $bootver"
82
83# patch uboot.bin
84echo "PATCH!"
85dd if=$working_dir/bootloader/spl.erosq of=$working_dir/image_contents/uboot.bin obs=1 seek=0 conv=notrunc
86dd if=$working_dir/bootloader/bootloader.ucl of=$working_dir/image_contents/uboot.bin obs=1 seek=26624 conv=notrunc
87
88# modify update.txt
89md5=($(md5sum $working_dir/image_contents/uboot.bin))
90if [ -z "$md5" ]; then
91 echo "COULDN'T MD5SUM UBOOT.BIN!"
92 echo "cleaning up..."
93 rm -rf $working_dir
94 exit 1
95fi
96echo "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
102echo "make new iso..."
103if [[ "$OSTYPE" == "darwin"* ]]; then
104 # macos
105 hdiutil makehybrid -iso -joliet -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/
106elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
107 # linux-gnu
108 genisoimage -o $working_dir/$updatefile_name_noext\_patched_$bootver.iso $working_dir/image_contents/
109fi
110
111# rename to something.upt and put in original directory
112echo "final output file $updatefile_name_noext\_patched_$bootver.upt"
113mv $working_dir/$updatefile_name_noext\_patched_$bootver.iso $updatefile_path/$updatefile_name_noext\_patched_$bootver.upt
114
115# clean up
116echo "cleaning up..."
117rm -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
5my $md5 = $ARGV[0];
6my $updatefile = $ARGV[1];
7my $bootloader_manif =
8"bootloader={
9 name=uboot
10 file_path=autoupdate/uboot.bin
11 md5=$md5
12}\n";
13
14# read in existing manifest
15open(FH, '<', "$updatefile");
16read(FH, my $manifest, -s FH);
17close(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
25open(FH, '>', "$updatefile");
26print FH $manifest;
27close(FH);