sansapatcher: move sectorbuf pointer into sansa_t structure.
[maemo-rb.git] / tools / mkinfo.pl
blob12d32bc7dcefa8caf4bae070c12a6fe7e4d980ce
1 #!/usr/bin/perl
2 # __________ __ ___.
3 # Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 # Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 # Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 # Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 # \/ \/ \/ \/ \/
9 # Purpose: extract and gather info from a build and put that in a standard
10 # way in the output file. Meant to be put in rockbox zip package to help and
11 # aid machine installers and more.
14 my $output = $ARGV[0];
16 sub filesize {
17 my ($f)=@_;
18 my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
19 $atime,$mtime,$ctime,$blksize,$blocks)
20 = stat($f);
21 return $size;
24 sub cmd1line {
25 my ($c)=@_;
26 my @out=`$c 2>/dev/null`;
27 chomp $out[0];
28 return $out[0];
31 sub definescan {
32 my ($f, $d)=($_[0], $_[1]);
33 my $v;
34 open(M, "<$f");
35 while(<M>) {
36 if($_ =~ /\#define\s+$d\s+([^\s]+)\s?/) {
37 $v = $1;
38 last;
41 close(M);
43 return $v;
46 sub mapscan {
47 my ($f)=@_;
48 my $start, $end;
49 open(M, "<$f");
50 while(<M>) {
51 if($_ =~ / +0x([0-9a-f]+) *_end = \./) {
52 $end = $1;
53 last;
55 elsif($_ =~ / +0x([0-9a-f]+) *_loadaddress = \./) {
56 $start = $1;
59 close(M);
61 # return number of bytes
62 return hex($end) - hex($start);
65 sub features {
66 my ($f)=@_;
67 my $feat;
68 open(M, "<$f");
69 while(<M>) {
70 chomp;
71 if($feat) {
72 $feat.=":";
74 $feat.=$_;
76 close(M);
77 return $feat;
80 if(!$output) {
81 print "Usage: mkinfo.pl <filename>\n";
82 exit;
84 open(O, ">$output") || die "couldn't open $output for writing";
86 # Variables identifying the target, that should remain the same as long
87 # as the hardware is unmodified
88 printf O ("Target: %s\n", $ENV{'MODELNAME'});
89 printf O ("Target id: %d\n", $ENV{'TARGET_ID'});
90 printf O ("Target define: %s\n", $ENV{'TARGET'});
91 printf O ("Memory: %d\n", $ENV{'MEMORYSIZE'});
92 printf O ("CPU: %s\n", $ENV{'CPU'});
93 printf O ("Manufacturer: %s\n", $ENV{'MANUFACTURER'});
95 # Variables identifying Rockbox and bootloader properties. Possibly changing
96 # every software upgrade.
97 printf O ("Version: %s", `$ENV{TOOLSDIR}/version.sh $ENV{ROOTDIR}`);
98 printf O ("Binary: %s\n", $ENV{'BINARY'});
99 printf O ("Binary size: %s\n", filesize($ENV{'BINARY'}));
100 printf O ("Voice format: %s\n", definescan("$ENV{APPSDIR}/talk.h", "VOICE_VERSION"));
102 if ($ENV{'APPSDIR'} =~ /\/apps$/) {
103 printf O ("Actual size: %s\n", filesize("rockbox.bin"));
104 printf O ("RAM usage: %s\n", mapscan("rockbox.map"));
105 printf O ("Features: %s\n", features("apps/features"));
106 } elsif ($ENV{'APPSDIR'} =~ /\/bootloader$/) {
107 printf O ("Actual size: %s\n", filesize("bootloader.bin"));
108 printf O ("RAM usage: %s\n", mapscan("bootloader.map"));
111 # Variables identifying tool and build environment details
112 printf O ("gcc: %s\n", cmd1line("$ENV{'CC'} --version"));
113 printf O ("ld: %s\n", cmd1line("$ENV{'LD'} --version"));
114 printf O ("Host gcc: %s\n", cmd1line("$ENV{'HOSTCC'} --version"));
115 printf O ("Host system: %s\n", $ENV{'UNAME'});
117 close(O);