8 die "Format: $0 [-s <systemmap-file>] <vmlinux-file> <keyring-file>\n"
9 if ($#ARGV != 1 && $#ARGV != 3 ||
10 $#ARGV == 3 && $ARGV[0] ne "-s");
19 my $vmlinux = $ARGV[0];
20 my $keyring = $ARGV[1];
23 # Parse the vmlinux section table
25 open FD
, "objdump -h $vmlinux |" || die $vmlinux;
27 close(FD
) || die $vmlinux;
31 foreach my $line (@lines) {
33 if ($line =~ /\s*([0-9]+)\s+(\S+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+([0-9a-f]+)\s+2[*][*]([0-9]+)/
37 my $len = Math
::BigInt
->new("0x" . $3);
38 my $vma = Math
::BigInt
->new("0x" . $4);
39 my $lma = Math
::BigInt
->new("0x" . $5);
40 my $foff = Math
::BigInt
->new("0x" . $6);
43 push @sections, { name
=> $name,
50 print "Have $#sections sections\n";
53 # Try and parse the vmlinux symbol table. If the vmlinux file has been created
54 # from a vmlinuz file with extract-vmlinux then the symbol table will be empty.
56 open FD
, "nm $vmlinux 2>/dev/null |" || die $vmlinux;
58 close(FD
) || die $vmlinux;
63 sub parse_symbols
(@
) {
64 foreach my $line (@_) {
66 if ($line =~ /([0-9a-f]+)\s([a-zA-Z])\s(\S+)/
72 $symbols{$name} = $addr;
77 parse_symbols
(@lines);
79 if ($nr_symbols == 0 && $sysmap ne "") {
80 print "No symbols in vmlinux, trying $sysmap\n";
82 open FD
, "<$sysmap" || die $sysmap;
84 close(FD
) || die $sysmap;
85 parse_symbols
(@lines);
88 die "No symbols available\n"
89 if ($nr_symbols == 0);
91 print "Have $nr_symbols symbols\n";
93 die "Can't find system certificate list"
94 unless (exists($symbols{"__cert_list_start"}) &&
95 exists($symbols{"system_certificate_list_size"}));
97 my $start = Math
::BigInt
->new($symbols{"__cert_list_start"});
100 my $size_sym = Math
::BigInt
->new($symbols{"system_certificate_list_size"});
102 open FD
, "<$vmlinux" || die $vmlinux;
106 foreach my $sec (@sections) {
107 my $s_name = $sec->{name
};
108 my $s_vma = $sec->{vma
};
109 my $s_len = $sec->{len
};
110 my $s_foff = $sec->{foff
};
111 my $s_vend = $s_vma + $s_len;
113 next unless ($start >= $s_vma);
114 next if ($start >= $s_vend);
116 die "Certificate list size was not found on the same section\n"
117 if ($size_sym < $s_vma || $size_sym > $s_vend);
119 die "Cert object in multiple sections: ", $s_name, " and ", $s->{name
}, "\n"
122 my $size_off = $size_sym -$s_vma + $s_foff;
124 die $vmlinux if (!defined(sysseek(FD
, $size_off, SEEK_SET
)));
125 sysread(FD
, $packed, 8);
126 $size = unpack 'L!', $packed;
127 $end = $start + $size;
129 printf "Have %u bytes of certs at VMA 0x%x\n", $size, $start;
131 die "Cert object partially overflows section $s_name\n"
137 die "Cert object not inside a section\n"
140 print "Certificate list in section ", $s->{name
}, "\n";
142 my $foff = $start - $s->{vma
} + $s->{foff
};
144 printf "Certificate list at file offset 0x%x\n", $foff;
146 die $vmlinux if (!defined(sysseek(FD
, $foff, SEEK_SET
)));
148 my $len = sysread(FD
, $buf, $size);
149 die "$vmlinux" if (!defined($len));
150 die "Short read on $vmlinux\n" if ($len != $size);
151 close(FD
) || die $vmlinux;
153 open FD
, ">$keyring" || die $keyring;
155 $len = syswrite(FD
, $buf, $size);
156 die "$keyring" if (!defined($len));
157 die "Short write on $keyring\n" if ($len != $size);
158 close(FD
) || die $keyring;