aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/remove-boot-splash
blob: e63c3b5f30ae11b9b781ec5c34e3f2c1de5f8df2 (plain)
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
#!/usr/bin/perl

@ARGV == 1 or die "usage: remove-splash <initrd>\n";

my $magic = 'BOOTSPL3';
my $buffer_size = 15;

my ($initrd) = @ARGV;
open(my $F, "+< $initrd") or die "can't open $initrd: $!\n";

while (1) {
    my $got = read($F, my $buffer, $buffer_size);
    $got > length($magic) or last;

    my $index = index($buffer, $magic);
    if ($index >= 0) {
	my $offset = $index + tell($F) - $got;

	seek($F, $offset + 12, 0) && read($F, my $tmp, 4) or last;
	my $splash_size = unpack("V", $tmp) + 38;

	my $initrd_size = seek($F, 0, 2) && tell($F);
	
	if ($offset + $splash_size == $initrd_size) {
	    truncate($F, $offset);
	    exit 0;
	} else {
	    warn "bootsplash found at offset $offset, but it is not at the end ($offset + $splash_size != $initrd_size)\n";
	}
    }
    seek($F, -length($magic), 1); # handle the case BOOTSPL3 when overlaps between buffers
}

warn "bootsplash not found in $initrd\n";