-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_flash_files.pl
executable file
·69 lines (55 loc) · 1.22 KB
/
find_flash_files.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
#!/usr/bin/env perl
use warnings;
use strict;
sub read_file
{
my @lines;
my $file = shift;
open(my $fh, "<", $file)
or die "Can't read $file: $!";
push @lines, $_ foreach <$fh>;
close $fh;
return wantarray ? @lines : join('', @lines);
}
my $str = read_file $ARGV[0];
my @files = read_file $ARGV[1];
my %PIT;
while ($str =~ m/^Partition\hName:\h+(?<partition>\w+)\n
Flash\hFilename:\h+(?<filename>(?:\w+\.(?:bin|img))|-)?$/gmx) {
$PIT{$+{partition}} = $+{filename} if $+{filename} && $+{filename} ne '-';
}
my %FILES;
foreach (@files) {
chomp;
my $basename = substr($_, rindex($_, '/') + 1);
$FILES{$basename} = $_;
}
foreach (keys %PIT) {
my $fn = $PIT{$_};
if ($FILES{$fn}) {
$PIT{$_} = $FILES{$fn};
delete $FILES{$fn};
} else {
warn "Can't find PIT $_ file $fn\n";
delete $PIT{$_};
}
}
foreach (keys %FILES) {
warn "Can't find PIT to flash file $FILES{$_}\n";
}
my %prio = (
BL => 1,
AP => 2,
CP => 3,
CSC => 4
);
my $cmd = '';
foreach (sort {
# 6 - strlen(files/)
my $d1 = substr($PIT{$a}, 6, index($PIT{$a}, '/', 6) - 6);
my $d2 = substr($PIT{$b}, 6, index($PIT{$b}, '/', 6) - 6);
$prio{$d1} <=> $prio{$d2} || $a cmp $b
} keys %PIT) {
$cmd .= '--' . $_ . " $PIT{$_} ";
}
print $cmd . "\n";