]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - scripts/knlinfo
2 # ----------------------------------------------------------------------
3 # knlinfo by Phil Elwell for Raspberry Pi
5 # (c) 2014,2015 Raspberry Pi (Trading) Limited <info@raspberrypi.org>
7 # Licensed under the terms of the GNU General Public License.
8 # ----------------------------------------------------------------------
15 my $trailer_magic = 'RPTL';
19 'DDTK' => \
&format_bool
,
20 'DTOK' => \
&format_bool
,
21 'KVer' => \
&format_string
,
22 '270X' => \
&format_bool
,
23 '283X' => \
&format_bool
,
24 '283x' => \
&format_bool
,
29 print ("Usage: knlinfo <kernel image>\n");
33 my $kernel_file = $ARGV[0];
36 my ($atoms, $pos) = read_trailer
($kernel_file);
40 printf("Kernel trailer found at %d/0x%x:\n", $pos, $pos);
42 foreach my $atom (@$atoms)
44 printf(" %s: %s\n", $atom->[0], format_atom
($atom));
51 my ($kernel_file) = @_;
54 if (!open($fh, '<', $kernel_file))
56 print ("* Failed to open '$kernel_file'\n");
60 if (!seek($fh, -12, SEEK_END
))
62 print ("* seek error in '$kernel_file'\n");
67 sysread($fh, $last_bytes, 12);
69 my ($trailer_len, $data_len, $magic) = unpack('VVa4', $last_bytes);
71 if (($magic ne $trailer_magic) || ($data_len != 4))
73 print ("* no trailer\n");
76 if (!seek($fh, -12, SEEK_END
))
78 print ("* seek error in '$kernel_file'\n");
84 while ($trailer_len > 0)
88 print ("* truncated atom header in trailer\n");
91 if (!seek($fh, -8, SEEK_CUR
))
93 print ("* seek error in '$kernel_file'\n");
99 sysread($fh, $atom_hdr, 8);
100 my ($atom_len, $atom_type) = unpack('Va4', $atom_hdr);
102 if ($trailer_len < $atom_len)
104 print ("* truncated atom data in trailer\n");
108 my $rounded_len = (($atom_len + 3) & ~3);
109 if (!seek($fh, -(8 + $rounded_len), SEEK_CUR
))
111 print ("* seek error in '$kernel_file'\n");
114 $trailer_len -= $rounded_len;
117 sysread($fh, $atom_data, $atom_len);
119 if (!seek($fh, -$atom_len, SEEK_CUR
))
121 print ("* seek error in '$kernel_file'\n");
125 push @$atoms, [ $atom_type, $atom_data ];
128 if (($$atoms[-1][0] eq "\x00\x00\x00\x00") &&
129 ($$atoms[-1][1] eq ""))
135 print ("* end marker missing from trailer\n");
138 return ($atoms, tell($fh));
145 my $format_func = $atom_formats{$atom->[0]} || \
&format_hex
;
146 return $format_func->($atom->[1]);
152 return unpack('V', $data) ?
'y' : 'n';
158 return unpack('V', $data);
164 return '"'.$data.'"';
170 return unpack('H*', $data);