forked from dpavlin/android-command-line
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrockchip-flash-helper.pl
executable file
·74 lines (53 loc) · 1.86 KB
/
rockchip-flash-helper.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Long;
my @files = @ARGV;
my $mode = lc(shift @files) || die "usage: $0 (backup|restore|update|flash /path/to/file.img)\n";
my $cmdline = <DATA>;
my $rkflashtool = '/virtual/android/android-command-line/rkflashtool/rkflashtool';
die "rkflashtool not found: $!" unless -x $rkflashtool;
$cmdline =~ s/^.*mtdparts=\w+:([^\s]+)\s.*$/$1/;
warn $cmdline;
foreach ( split(/,/,$cmdline) ) {
print "$_\n";
my ($size,$start,$name) = split(/[\@\(\)]/, $_, 4);
my $cmd;
my $backup_file = "$start-$size-$name";
if ( $mode eq 'backup' ) {
$cmd = "$rkflashtool r $start $size > $backup_file";
} elsif ( $mode eq 'restore' ) {
if ( -e $backup_file && -s $backup_file ) {
$cmd = "$rkflashtool w $start $size < $backup_file";
} else {
warn "SKIP $backup_file restore: $!\n";
next;
}
} elsif ( $mode eq 'update' ) {
if ( -e "$name.img" ) {
$cmd = "$rkflashtool w $start $size < $name.img";
} else {
warn "SKIP $start $size $name - not found in update\n";
next;
}
} elsif ( $mode eq 'flash' ) {
foreach my $file ( @files ) {
if ( $file =~ m/$name/ && -e $file ) {
$cmd = "$rkflashtool w $start $size < $file";
} else {
next;
}
}
next if ! $cmd;
} else {
die "unknown mode $mode\n";
}
warn "# $cmd\n";
system($cmd) == 0 || die $!;
}
if ( $mode eq 'update' || $mode eq 'restore' ) {
warn "# reboot Android\n";
system("$rkflashtool b");
}
__DATA__
console=ttyFIQ0 androidboot.console=ttyFIQ0 init=/init initrd=0x62000000,0x00200000 mtdparts=rk29xxnand:0x00002000@0x00002000(misc),0x00004000@0x00004000(kernel),0x00008000@0x00008000(boot),0x00008000@0x00010000(recovery),0x000C0000@0x00018000(backup),0x00040000@0x000D8000(cache),0x00300000@0x00118000(userdata),0x00002000@0x00418000(kpanic),0x00100000@0x0041A000(system),-@0x0053A000(user) bootver=2012-08-08#1.14 firmware_ver=4.0.4