-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsetup_boot_sequence.pl
executable file
·104 lines (74 loc) · 2.58 KB
/
setup_boot_sequence.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl
if ( $#ARGV != 1 ) {
die "Usage: setup_boot_sequence.pl path to boot partition of new disk";
}
my $BOOT_PARTITION = $ARGV[0];
my $PLATFORM_BRANCH = $ARGV[1];
sub trim {
my ( $l ) = @_;
$l =~ s/^\s*//;
$l =~ s/\s*$//;
return $l;
}
#
# Switch to the new disk, but with a readonly-memory overlay, the root pivot also happens in new
# init script
#
sub readonly_boot_line {
my ( $part1, $part2 ) = @_;
my @a = split(/\s+/, trim( $part2) );
@a = grep {$_ ne "quiet" && $_ !~ "^root=" && $_ !~ "^init="} @a;
push( @a, "root=/dev/mmcblk0p1" );
push( @a, "init=/sbin/overlayRoot.sh" );
push( @a, "sbtsroot=$BOOT_PARTITION" );
my $b = join( ',', @a );
return $part1 ."APPEND " . join( " ", @a);
}
#
# Simply change the boot device to the SSD, gets mounted normally, i.e. read-write
#
sub readwrite_boot_line {
my ( $part1, $part2 ) = @_;
my @a = split(/\s+/, trim( $part2) );
@a = grep {$_ ne "quiet" && $_ !~ "^init="} @a;
push( @a, "sbtsroot=$BOOT_PARTITION" );
my $b = join( ',', @a );
return $part1 ."APPEND " . join( " ", @a);
}
sub create_readonly_conf {
my ( $l ) = @_;
open( my $out, ">", "/boot/extlinux/readonly_extlinux.conf" ) || die "Can't create file /boot/extlinux/readonly_extlinux.conf: $!\n";
#if ( $PLATFORM_BRANCH ne "sbts-jetson-nano" ) {
if ( 0 ) {
$l =~ s%^(\s*)(INITRD.*)$%$1#$2\n$1INITRD /boot/initrd-xusb.img%gm;
}
my $readonly = $l;
$readonly =~ s%^(\s*)APPEND(.*)$%readonly_boot_line($1, $2)%gem;
print $out $readonly;
close $out;
system("cat /boot/extlinux/readonly_extlinux.conf");
}
sub create_readwrite_conf {
my ( $l ) = @_;
open( my $out, ">", "/boot/extlinux/readwrite_extlinux.conf" ) || die "Can't create file /boot/extlinux/readonly_extlinux.conf: $!\n";
#if ( $PLATFORM_BRANCH ne "sbts-jetson-nano" ) {
if ( 0 ) {
$l =~ s%^(\s*)(INITRD.*)$%$1#$2\n$1INITRD /boot/initrd-xusb.img%gm;
}
my $readonly = $l;
$readonly =~ s%^(\s*)APPEND(.*)$%readwrite_boot_line($1, $2)%gem;
print $out $readonly;
close $out;
system("cat /boot/extlinux/readwrite_extlinux.conf");
}
my $CONF_FILE = "/boot/extlinux/orig_extlinux.conf";
system( "cp /boot/extlinux/extlinux.conf /boot/extlinux/orig_extlinux.conf" );
open( my $in, "<", $CONF_FILE ) || die "Can't open $CONF_FILE: $!\n";
$l = do { local $/;<$in> };
#if ( $PLATFORM_BRANCH ne "sbts-jetson-nano" ) {
if ( 0 ) {
$l =~ s%^(\s*)(INITRD.*)$%$1#$2\n$1INITRD /boot/initrd-xusb.img%gm;
}
close( $in );
create_readonly_conf( $l );
create_readwrite_conf( $l );