summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-04-03 17:30:35 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-04-05 18:18:03 +0200
commit0efa73f0ecfbc9d907220dbbf9a8202dff9dfddf (patch)
treed14e699e531cb49e12e72e8c7e27cc7f16b3ef8c
parentee3894f2857735862cbbfe21d86e75f4179e8f80 (diff)
downloadrockbox-0efa73f0ecfbc9d907220dbbf9a8202dff9dfddf.tar.gz
rockbox-0efa73f0ecfbc9d907220dbbf9a8202dff9dfddf.zip
tools: Add a tool that patches Hiby_player-derived firmware images.
Confirmed to work on the AGPTek Rocker and xDuoo X3ii targets! Change-Id: I721c62b88b28282d1c85fd33e49262265cd2d6a5
-rwxr-xr-xtools/hiby_patcher.pl165
1 files changed, 165 insertions, 0 deletions
diff --git a/tools/hiby_patcher.pl b/tools/hiby_patcher.pl
new file mode 100755
index 0000000000..e1aa30733e
--- /dev/null
+++ b/tools/hiby_patcher.pl
@@ -0,0 +1,165 @@
1#!/usr/bin/perl -w
2##################
3# __________ __ ___.
4# Open \______ \ ____ ____ | | _\_ |__ _______ ___
5# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
6# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8# \/ \/ \/ \/ \/
9#
10# Hiby patcher Copyright (C) 2020 Solomon Peachy <pizza@shaftnet.org>
11#
12# Licensed under the GNU GPLv2 (or newer)
13#
14##################
15
16# usage: hiby_patcher.pl model imagefile bootloaderfile
17
18# need '7z', 'mkisofs', 'md5sum', 'mkfs.ubifs'
19# and https://github.com/jrspruitt/ubi_reader
20
21# Rocker: PEB size 128KiB, I/O 2048, LEBs size: 124KiB, max LEBs 1024 (?)
22
23use strict;
24
25use File::Basename;
26
27my $model = $ARGV[0];
28my $inname = $ARGV[1];
29my $rbbname = $ARGV[2];
30
31my $prefix = "/tmp"; # XXX mktmp
32my $debug = 0; # Set to 1 to prevent cleaning up work dirs
33
34#### Let's get to work
35
36my @ubiopts;
37if ($model eq 'rocker') {
38 @ubiopts = ("-e", "124KiB", "-c", "1024", "-m", "2048", "-j", "8192KiB", "-U");
39} elsif ($model eq 'x3ii') {
40 @ubiopts = ("-e", "124KiB", "-c", "1024", "-m", "2048", "-j", "8192KiB", "-U");
41} elsif ($model eq 'x20') {
42 @ubiopts = ("-e", "124KiB", "-c", "1024", "-m", "2048", "-j", "8192KiB", "-U");
43} else {
44 die ("Unknown hiby model: $model\n");
45}
46
47my $uptname = basename($inname);
48my $uptnamenew = "rb-$uptname";
49my $isowork = "$prefix/iso.$uptname";
50my $rootfsdir = "$prefix/rootfs.$uptname";
51my $ubiname;
52my $ubinamenew;
53
54
55my @sysargs;
56
57
58### Extract outer ISO9660 image
59system("rm -Rf $isowork");
60mkdir($isowork) || die ("Can't create '$isowork'");
61@sysargs = ("7z", "x", "-aoa", "-o$isowork", $inname);
62system(@sysargs);
63
64### figure out the rootfs image filename
65my $updatename;
66if ( -e "$isowork/UPDATE.TXT") {
67 $updatename = "$isowork/UPDATE.TXT";
68} elsif ( -e "$isowork/update.txt") {
69 $updatename = "$isowork/update.txt";
70}
71open UPDATE, $updatename || die ("Can't open update.txt!");;
72
73my $rootfs_found = 0;
74while (<UPDATE>) {
75 chomp;
76 if ($rootfs_found) {
77 if (/file_path=(.*)/) {
78 $ubiname = basename($1);
79 $ubiname =~ tr/[a-z]/[A-Z]/;
80 last;
81 }
82 } else {
83 if (/rootfs/) {
84 $rootfs_found = 1;
85 }
86 }
87}
88close UPDATE;
89
90die("can't locate rootfs image") if (! -e "$isowork/$ubiname");
91$ubiname = "$isowork/$ubiname";
92
93### Extract RootFS
94system("rm -Rf $rootfsdir");
95mkdir($rootfsdir) || die ("Can't create '$rootfsdir'");
96
97@sysargs = ("ubireader_extract_files", "-k", "-o", $rootfsdir, $ubiname);
98system(@sysargs);
99
100### Mangle RootFS
101
102# Generate rb_bootloader.sh
103my $rbbasename = basename($rbbname);
104my $bootloader_sh =
105 "#!/bin/sh
106
107mount /dev/mmcblk0 /mnt/sd_0 &>/dev/null || \
108mount /dev/mmcblk0p1 /mnt/sd_0 &>/dev/null
109
110killall $rbbasename
111killall -9 $rbbasename
112
113/usr/bin/$rbbasename
114sleep 1
115reboot
116 ";
117open FILE, ">$rootfsdir/usr/bin/hiby_player.sh" || die ("can't write bootloader script!");
118print FILE $bootloader_sh;
119close FILE;
120
121# Copy bootloader over
122@sysargs=("cp", "$rbbname", "$rootfsdir/usr/bin/$rbbasename");
123system(@sysargs);
124
125### Generate new RootFS UBI image
126$ubinamenew = "$ubiname.new";
127
128@sysargs = ("mkfs.ubifs", @ubiopts, "-v", "-o", $ubinamenew, "-r", "$rootfsdir");
129system(@sysargs);
130
131system("rm -Rf $rootfsdir") if (!$debug);
132
133# md5sum
134my $md5 = `md5sum $ubinamenew | cut -d ' ' -f 1`;
135
136system("mv $ubinamenew $ubiname");
137
138### Generate new ISO9660 update image
139
140# Update version string as needed XXX
141
142open UPDATE, "<$updatename" || die ("Can't open update.txt!");;
143open UPDATEO, ">$updatename.new" || die ("Can't open update.txt!");;
144
145$rootfs_found = 0;
146while (<UPDATE>) {
147 if ($rootfs_found) {
148 if (s/md5=.*/md5=$md5/) {
149 print "#### $_ ####\n";
150 $rootfs_found=0;
151 }
152 } else {
153 if (/rootfs/) {
154 $rootfs_found = 1;
155 }
156 }
157 print UPDATEO;
158}
159close UPDATE;
160close UPDATEO;
161system("mv $updatename.new $updatename");
162@sysargs = ("mkisofs", "-volid", "CDROM", "-o", $uptnamenew, $isowork);
163system(@sysargs);
164
165system("rm -Rf $isowork") if (!$debug);