Some formatting fixes, reported by Alexander Levin
[kugel-rb.git] / tools / mkinfo.pl
blob464cbb24f284a2598c120fe37422d79fd445ea5e
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
8 # $Id$
10 # Purpose: extract and gather info from a build and put that in a standard
11 # way in the output file. Meant to be put in rockbox zip package to help and
12 # aid machine installers and more.
15 my $output = $ARGV[0];
17 sub filesize {
18 my ($f)=@_;
19 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
20 $atime,$mtime,$ctime,$blksize,$blocks)
21 = stat($f);
22 return $size;
25 sub cmd1line {
26 my ($c)=@_;
27 my @out=`$c 2>/dev/null`;
28 chomp $out[0];
29 return $out[0];
32 sub mapscan {
33 my ($f)=@_;
34 my $start, $end;
35 open(M, "<$f");
36 while(<M>) {
37 if($_ =~ / +0x([0-9a-f]+) *_end = \./) {
38 $end = $1;
39 last;
41 elsif($_ =~ / +0x([0-9a-f]+) *_loadaddress = \./) {
42 $start = $1;
45 close(M);
47 # return number of bytes
48 return hex($end) - hex($start);
51 sub features {
52 my ($f)=@_;
53 my $feat;
54 open(M, "<$f");
55 while(<M>) {
56 chomp;
57 if($feat) {
58 $feat.=":";
60 $feat.=$_;
62 close(M);
63 return $feat;
66 if(!$output) {
67 print "Usage: mkinfo.pl <filename>\n";
68 exit;
70 open(O, ">$output") || die "couldn't open $output for writing";
72 # Variables identifying the target, that should remain the same as long
73 # as the hardware is unmodified
74 printf O ("Target: %s\n", $ENV{'MODELNAME'});
75 printf O ("Target id: %d\n", $ENV{'TARGET_ID'});
76 printf O ("Target define: %s\n", $ENV{'TARGET'});
77 printf O ("Memory: %d\n", $ENV{'MEMORYSIZE'});
78 printf O ("CPU: %s\n", $ENV{'CPU'});
79 printf O ("Manufacturer: %s\n", $ENV{'MANUFACTURER'});
81 # Variables identifying Rockbox and bootloader properties. Possibly changing
82 # every software upgrade.
83 printf O ("Version: %s\n", $ENV{'VERSION'});
84 printf O ("Binary: %s\n", $ENV{'BINARY'});
85 printf O ("Binary size: %s\n", filesize($ENV{'BINARY'}));
87 if ($ENV{'APPSDIR'} =~ /\/apps$/) {
88 printf O ("Actual size: %s\n", filesize("rockbox.bin"));
89 printf O ("RAM usage: %s\n", mapscan("rockbox.map"));
90 printf O ("Features: %s\n", features("apps/features"));
91 } elsif ($ENV{'APPSDIR'} =~ /\/bootloader$/) {
92 printf O ("Actual size: %s\n", filesize("bootloader.bin"));
93 printf O ("RAM usage: %s\n", mapscan("bootloader.map"));
96 # Variables identifying tool and build environment details
97 printf O ("gcc: %s\n", cmd1line("$ENV{'CC'} --version"));
98 printf O ("ld: %s\n", cmd1line("$ENV{'LD'} --version"));
99 printf O ("Host gcc: %s\n", cmd1line("$ENV{'HOSTCC'} --version"));
100 printf O ("Host system: %s\n", $ENV{'UNAME'});
102 close(O);