summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/hiby_patcher.pl267
1 files changed, 160 insertions, 107 deletions
diff --git a/tools/hiby_patcher.pl b/tools/hiby_patcher.pl
index af98cfdafc..e8ade006b1 100755
--- a/tools/hiby_patcher.pl
+++ b/tools/hiby_patcher.pl
@@ -9,7 +9,7 @@
9# 9#
10# Hiby patcher Copyright (C) 2020 Solomon Peachy <pizza@shaftnet.org> 10# Hiby patcher Copyright (C) 2020 Solomon Peachy <pizza@shaftnet.org>
11# 11#
12# Licensed under the GNU GPLv2 (or newer) 12# Licensed under the GNU GPLv2 (or later)
13# 13#
14################## 14##################
15 15
@@ -29,6 +29,8 @@ my $rbbname = $ARGV[2];
29my $prefix = "/tmp"; # XXX mktmp 29my $prefix = "/tmp"; # XXX mktmp
30my $debug = 0; # Set to 1 to prevent cleaning up work dirs 30my $debug = 0; # Set to 1 to prevent cleaning up work dirs
31 31
32my $hiby = 1; # 1 for hibyplayer-style updates, 0 for ingenic updates
33
32#### Let's get to work 34#### Let's get to work
33 35
34my @ubiopts; 36my @ubiopts;
@@ -42,6 +44,7 @@ if ($model eq 'rocker') {
42 @ubiopts = ("-e", "124KiB", "-c", "1024", "-m", "2048", "-j", "8192KiB", "-U"); 44 @ubiopts = ("-e", "124KiB", "-c", "1024", "-m", "2048", "-j", "8192KiB", "-U");
43} elsif ($model eq 'm3k') { 45} elsif ($model eq 'm3k') {
44 @ubiopts = ("-e", "124KiB", "-c", "2048", "-m", "2048", "-j", "8192KiB", "-U"); 46 @ubiopts = ("-e", "124KiB", "-c", "2048", "-m", "2048", "-j", "8192KiB", "-U");
47 $hiby = 0;
45} else { 48} else {
46 die ("Unknown hiby model: $model\n"); 49 die ("Unknown hiby model: $model\n");
47} 50}
@@ -52,69 +55,88 @@ my $isowork = "$prefix/iso.$uptname";
52my $rootfsdir = "$prefix/rootfs.$uptname"; 55my $rootfsdir = "$prefix/rootfs.$uptname";
53my $ubiname; 56my $ubiname;
54my $ubinamenew; 57my $ubinamenew;
55
56
57my @sysargs;
58
59
60### Extract outer ISO9660 image
61system("rm -Rf $isowork");
62mkdir($isowork) || die ("Can't create '$isowork'");
63@sysargs = ("7z", "x", "-aoa", "-o$isowork", $inname);
64system(@sysargs);
65
66### figure out the rootfs image filenames
67my $updatename; 58my $updatename;
68if ( -e "$isowork/UPDATE.TXT") {
69 $updatename = "$isowork/UPDATE.TXT";
70} elsif ( -e "$isowork/update.txt") {
71 $updatename = "$isowork/update.txt";
72}
73my $versionname; 59my $versionname;
74if ( -e "$isowork/VERSION.TXT") {
75 $versionname = "$isowork/VERSION.TXT";
76} elsif ( -e "$isowork/version.txt") {
77 $versionname = "$isowork/version.txt";
78}
79 60
80open UPDATE, $updatename || die ("Can't open update.txt!");; 61my @sysargs;
62
63#### Extract OF image wrapper
64if ($hiby) {
65 system("rm -Rf $isowork");
66 mkdir($isowork) || die ("Can't create '$isowork'");
67 @sysargs = ("7z", "x", "-aoa", "-o$isowork", $inname);
68 system(@sysargs);
69
70 ### figure out the rootfs image filenames
71 if ( -e "$isowork/UPDATE.TXT") {
72 $updatename = "$isowork/UPDATE.TXT";
73 } elsif ( -e "$isowork/update.txt") {
74 $updatename = "$isowork/update.txt";
75 }
76 if ( -e "$isowork/VERSION.TXT") {
77 $versionname = "$isowork/VERSION.TXT";
78 } elsif ( -e "$isowork/version.txt") {
79 $versionname = "$isowork/version.txt";
80 }
81 81
82my $rootfs_found = 0; 82 open UPDATE, $updatename || die ("Can't open update.txt!");;
83while (<UPDATE>) { 83
84 chomp; 84 my $rootfs_found = 0;
85 if ($rootfs_found) { 85 while (<UPDATE>) {
86 if (/file_path=(.*)/) { 86 chomp;
87 $ubiname = basename($1); 87 if ($rootfs_found) {
88 last; 88 if (/file_path=(.*)/) {
89 $ubiname = basename($1);
90 last;
91 }
92 } else {
93 if (/rootfs/) {
94 $rootfs_found = 1;
89 } 95 }
90 } else {
91 if (/rootfs/) {
92 $rootfs_found = 1;
93 } 96 }
94 } 97 }
95} 98 close UPDATE;
96close UPDATE;
97 99
98if (! -e "$isowork/$ubiname") { 100 if (! -e "$isowork/$ubiname") {
99 $ubiname =~ tr/[a-z]/[A-Z]/; 101 $ubiname =~ tr/[a-z]/[A-Z]/;
100 die("can't locate rootfs image ($ubiname)") if (! -e "$isowork/$ubiname"); 102 die("can't locate rootfs image ($ubiname)") if (! -e "$isowork/$ubiname");
101} 103 }
104
105 $ubiname = "$isowork/$ubiname";
106} else {
107 # Deconstruct original file
108 # TODO. Rough sequence:
109
110# unzip m3k.fw
111# for x in recovery-update/nand/update*zip ; do unzip -o $x ; done
112# rm -Rf *zip META-INF
113# parse update000/update.xml:
114# <name>system.ubi</name>
115# <type>ubifs</type>
116# <size>###</size> ## total size, bytes
117# <chunksize>##</chunksize> ## max for each one I guess [optional, 0 def]
118# <chunkcount>##</chunkcount> ## add up [optional, 1 def]
119#
120# * Track name, start block
121# * when we find the first ubifs block, record name, start block #, end block #
122#
123# alternatively, cat update*/$name* > combined.ubi
102 124
103$ubiname = "$isowork/$ubiname"; 125 $ubiname = "$uptname";
126}
104 127
105### Extract RootFS 128#### Extract RootFS
106system("rm -Rf $rootfsdir"); 129system("rm -Rf $rootfsdir");
107mkdir($rootfsdir) || die ("Can't create '$rootfsdir'"); 130mkdir($rootfsdir) || die ("Can't create '$rootfsdir'");
108 131
109@sysargs = ("ubireader_extract_files", "-k", "-o", $rootfsdir, $ubiname); 132@sysargs = ("ubireader_extract_files", "-k", "-o", $rootfsdir, $ubiname);
110system(@sysargs); 133system(@sysargs);
111 134
112# exit(0);
113### Mangle RootFS
114
115# Generate rb_bootloader.sh
116my $rbbasename = basename($rbbname); 135my $rbbasename = basename($rbbname);
117my $bootloader_sh = 136
137#### Mangle RootFS
138if ($hiby) {
139 my $bootloader_sh =
118 "#!/bin/sh 140 "#!/bin/sh
119 141
120#mkdir -p /mnt/sd_0 142#mkdir -p /mnt/sd_0
@@ -135,21 +157,21 @@ killall -9 $rbbasename &>/dev/null
135sleep 1 157sleep 1
136reboot 158reboot
137"; 159";
138open FILE, ">$rootfsdir/usr/bin/hiby_player.sh" || die ("can't write bootloader script!"); 160 open FILE, ">$rootfsdir/usr/bin/hiby_player.sh" || die ("can't write bootloader script!");
139print FILE $bootloader_sh; 161 print FILE $bootloader_sh;
140close FILE; 162 close FILE;
141chmod 0755, "$rootfsdir/usr/bin/hiby_player.sh"; 163 chmod 0755, "$rootfsdir/usr/bin/hiby_player.sh";
142 164
143# Auto mount/unmount external USB drives and SD card 165 # Auto mount/unmount external USB drives and SD card
144open FILE, ">>$rootfsdir/etc/mdev.conf" || die ("can't access mdev conf!"); 166 open FILE, ">>$rootfsdir/etc/mdev.conf" || die ("can't access mdev conf!");
145print FILE "sd[a-z][0-9]+ 0:0 664 @ /etc/rb_inserting.sh\n"; 167 print FILE "sd[a-z][0-9]+ 0:0 664 @ /etc/rb_inserting.sh\n";
146print FILE "mmcblk[0-9]p[0-9] 0:0 664 @ /etc/rb_inserting.sh\n"; 168 print FILE "mmcblk[0-9]p[0-9] 0:0 664 @ /etc/rb_inserting.sh\n";
147print FILE "mmcblk[0-9] 0:0 664 @ /etc/rb_inserting.sh\n"; 169 print FILE "mmcblk[0-9] 0:0 664 @ /etc/rb_inserting.sh\n";
148print FILE "sd[a-z] 0:0 664 \$ /etc/rb_removing.sh"; 170 print FILE "sd[a-z] 0:0 664 \$ /etc/rb_removing.sh";
149print FILE "mmcblk[0-9] 0:0 664 \$ /etc/rb_removing.sh\n"; 171 print FILE "mmcblk[0-9] 0:0 664 \$ /etc/rb_removing.sh\n";
150close FILE; 172 close FILE;
151 173
152my $insert_sh = ' 174 my $insert_sh = '
153#!/bin/sh 175#!/bin/sh
154# $MDEV is the device 176# $MDEV is the device
155 177
@@ -169,25 +191,51 @@ fi
169mount $MDEV $MNT_POINT 191mount $MDEV $MNT_POINT
170'; 192';
171 193
172open FILE, ">$rootfsdir/etc/rb_inserting.sh" || die("can't write hotplug helpers!"); 194 open FILE, ">$rootfsdir/etc/rb_inserting.sh" || die("can't write hotplug helpers!");
173print FILE $insert_sh; 195 print FILE $insert_sh;
174close FILE; 196 close FILE;
175chmod 0755, "$rootfsdir/etc/rb_inserting.sh"; 197 chmod 0755, "$rootfsdir/etc/rb_inserting.sh";
176 198
177my $remove_sh = ' 199 my $remove_sh = '
178#!/bin/sh 200#!/bin/sh
179# $MDEV is the device 201# $MDEV is the device
180sync; 202sync;
181unmount -f $MDEV; 203unmount -f $MDEV;
182'; 204';
183 205
184open FILE, ">$rootfsdir/etc/rb_removing.sh" || die("can't write hotplug helpers!"); 206 open FILE, ">$rootfsdir/etc/rb_removing.sh" || die("can't write hotplug helpers!");
185print FILE $remove_sh; 207 print FILE $remove_sh;
186close FILE; 208 close FILE;
187chmod 0755, "$rootfsdir/etc/rb_removing.sh"; 209 chmod 0755, "$rootfsdir/etc/rb_removing.sh";
188 210
189# Deal with a nasty race condition in automount scripts 211 # Deal with a nasty race condition in automount scripts
190system("perl -pni -e 's/rm -rf/#rm -Rf/;' $rootfsdir/etc/init.d/S50sys_server"); 212 system("perl -pni -e 's/rm -rf/#rm -Rf/;' $rootfsdir/etc/init.d/S50sys_server");
213} else {
214 my $bootloader_sh =
215 "#!/bin/sh
216
217killall $rbbasename &>/dev/null
218killall -9 $rbbasename &>/dev/null
219
220source /etc/profile
221
222# Try to save the flash
223if ! [ -L /data/userfs/app.log ] ; then
224 rm -f /data/userfs/app.log
225 ln -s /dev/null /data/userfs/app.log
226fi
227
228# Rockbox launcher!
229/usr/bin/$rbbasename
230sleep 1
231reboot
232";
233 open FILE, ">$rootfsdir/usr/project/bin/play.sh" || die ("can't write bootloader script!");
234 print FILE $bootloader_sh;
235 close FILE;
236 chmod 0755, "$rootfsdir/usr/project/bin/play.sh";
237
238}
191 239
192# Copy bootloader over 240# Copy bootloader over
193@sysargs=("cp", "$rbbname", "$rootfsdir/usr/bin/$rbbasename"); 241@sysargs=("cp", "$rbbname", "$rootfsdir/usr/bin/$rbbasename");
@@ -201,49 +249,54 @@ system(@sysargs);
201 249
202system("rm -Rf $rootfsdir") if (!$debug); 250system("rm -Rf $rootfsdir") if (!$debug);
203 251
204# md5sum 252if ($hiby) {
205my $md5 = `md5sum $ubinamenew | cut -d ' ' -f 1`; 253 # md5sum
254 my $md5 = `md5sum $ubinamenew | cut -d ' ' -f 1`;
206 255
207system("mv $ubinamenew $ubiname"); 256 system("mv $ubinamenew $ubiname");
208 257
209### Generate new ISO9660 update image 258 ### Generate new ISO9660 update image
210 259
211# Correct md5sum for new rootfs image 260 # Correct md5sum for new rootfs image
212open UPDATE, "<$updatename" || die ("Can't open update.txt!"); 261 open UPDATE, "<$updatename" || die ("Can't open update.txt!");
213open UPDATEO, ">$updatename.new" || die ("Can't open update.txt!"); 262 open UPDATEO, ">$updatename.new" || die ("Can't open update.txt!");
214 263
215$rootfs_found = 0; 264 my $rootfs_found = 0;
216while (<UPDATE>) { 265 while (<UPDATE>) {
217 if ($rootfs_found) { 266 if ($rootfs_found) {
218 if (s/md5=.*/md5=$md5/) { 267 if (s/md5=.*/md5=$md5/) {
219 $rootfs_found=0; 268 $rootfs_found=0;
220 } 269 }
221 } else { 270 } else {
222 if (/rootfs/) { 271 if (/rootfs/) {
223 $rootfs_found = 1; 272 $rootfs_found = 1;
273 }
224 } 274 }
275 print UPDATEO;
225 } 276 }
226 print UPDATEO; 277 close UPDATE;
227} 278 close UPDATEO;
228close UPDATE; 279 system("mv $updatename.new $updatename");
229close UPDATEO;
230system("mv $updatename.new $updatename");
231 280
232# Fix up version text, if needed (AGPTek Rocker 1.31 beta) 281 # Fix up version text, if needed (AGPTek Rocker 1.31 beta)
233 282
234open UPDATE, "<$versionname" || die ("Can't open version.txt!");; 283 open UPDATE, "<$versionname" || die ("Can't open version.txt!");;
235open UPDATEO, ">$versionname.new" || die ("Can't open version.txt!"); 284 open UPDATEO, ">$versionname.new" || die ("Can't open version.txt!");
236 285
237while (<UPDATE>) { 286 while (<UPDATE>) {
238 s/ver=1\.0\.0\.0/ver=2018-10-07T00:00:00+08:00/; 287 s/ver=1\.0\.0\.0/ver=2018-10-07T00:00:00+08:00/;
239 print UPDATEO; 288 print UPDATEO;
240} 289 }
241 290
242close UPDATE; 291 close UPDATE;
243close UPDATEO; 292 close UPDATEO;
244system("mv $versionname.new $versionname"); 293 system("mv $versionname.new $versionname");
245 294
246@sysargs = ("mkisofs", "-volid", "CDROM", "-o", $uptnamenew, $isowork); 295 @sysargs = ("mkisofs", "-volid", "CDROM", "-o", $uptnamenew, $isowork);
247system(@sysargs); 296 system(@sysargs);
248 297
249system("rm -Rf $isowork") if (!$debug); 298 system("rm -Rf $isowork") if (!$debug);
299} else {
300 # Reconstruct fiio/ingenic firmware update image
301 # very TODO
302}