2 # Automatically generates the StellarisParts struct in src/flash/nor/stellaris.c
3 # Uses the header files from TI/Luminary's StellarisWare complete Firmware Development Package
4 # available from: http://www.luminarymicro.com/products/software_updates.html
6 $comment = "// Autogenerated by contrib/gen-stellaris-part-header.pl
7 // From Stellaris Firmware Development Package revision";
9 $struct_header = "static struct {
16 $struct_footer = "\t{0,\"Unknown part\"}\n};\n";
18 $#ARGV == 1 || die "Usage: $0 <inc directory> <output file>\n";
19 -d
$ARGV[0] || die $ARGV[0]." is not a directory\n";
21 -f
$ARGV[1] || die $ARGV[1]." is not a file\n";
23 print STDERR
"Scanning $dir, Updating $file\n";
25 opendir(DIR
, $dir) || die "can't open $dir: $!";
26 @files = readdir(DIR
);
29 @short_files = sort(grep(/lm3s...\.h/, @files));
30 @long_files = sort(grep(/lm3s....\.h/, @files));
33 $new_struct = $struct_header;
34 process_file
(@short_files);
35 process_file
(@long_files);
36 $new_struct .= $struct_footer;
38 $dump = "$comment $ver\n$new_struct";
41 open(INPUT
, $file) || die "can't open $file: $!";
46 $old_struct = qr/((^\/\
/.*?\n)*)\Q$struct_header\E.*?$struct_footer/sm;
47 $contents =~ s/$old_struct/$dump/;
48 open(OUTPUT
, ">$file") || die "can't open file $file for writing: $!";
49 print OUTPUT
$contents;
53 foreach $h_file (@_) {
54 ($base) = ($h_file =~ m/lm3s(.{3,4})\.h/ig);
57 open(FILE
, "$dir/$h_file");
61 if ($content =~ /This is part of revision (\d+) of/) {
62 if ($ver != 0 and $ver != $1) {
63 print STDERR
"File version mismatch: $ver != $1\n";
69 if ($content =~ /SYSCTL_DID1_VER_[^M]\s+0x(\S+)/) {
72 print STDERR
"$h_file is missing SYSCTL_DID1_VER\n";
76 if ($content =~ /SYSCTL_DID1_PRTNO_$base\s+0x(\S+)/) {
79 print STDERR
"$h_file is missing SYSCTL_DID1_PRTNO\n";
83 $id = ($did1_ver | $prtno) >> 16;
84 $new_member = sprintf "{0x%04X,\"LM3S%s\"},", $id, $base;
86 #$new_struct .= "\t//$new_member\t// Invalid\n";
88 $new_struct .= "\t$new_member\n";