2 # SPDX-License-Identifier: GPL-2.0-or-later
4 # Automatically generates the StellarisParts struct in src/flash/nor/stellaris.c
5 # Uses the header files from TI/Luminary's StellarisWare complete Firmware Development Package
6 # available from: http://www.luminarymicro.com/products/software_updates.html
8 $comment = "// Autogenerated by contrib/gen-stellaris-part-header.pl
9 // From Stellaris Firmware Development Package revision";
11 $struct_header = "static const struct {
15 } StellarisParts[] = {
18 $struct_footer = "\t{0xFF, 0x00, \"Unknown Part\"}\n};\n";
20 $#ARGV == 1 || die "Usage: $0 <inc directory> <output file>\n";
21 -d
$ARGV[0] || die $ARGV[0]." is not a directory\n";
23 -f
$ARGV[1] || die $ARGV[1]." is not a file\n";
25 print STDERR
"Scanning $dir, Updating $file\n";
27 opendir(DIR
, $dir) || die "can't open $dir: $!";
28 @files = readdir(DIR
);
31 @header_files = sort(grep(/lm.+\.h/, @files));
34 $new_struct = $struct_header;
35 process_file
(@header_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/lm..(.{3,7})\.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";
70 if ($content =~ /SYSCTL_DID0_CLASS_[^M].+?0x(\S+)/s) {
71 $class = hex($1) >> 16;
73 # attempt another way to get class
74 if ($content =~ /\s(\S+)-class/) {
75 $class = getclass
($1);
77 print STDERR
"$h_file unknown class\n";
81 print STDERR
"$h_file is missing SYSCTL_DID0_CLASS_\n";
87 if ($content =~ /SYSCTL_DID1_PRTNO_$base.+0x(\S+)/) {
89 $base = "LM3S" . $base;
91 # LM4F have a changed header
92 if ($content =~ /SYSCTL_DID1_PRTNO_LM4F$base.+?0x(\S+)/s) {
94 $base = "LM4F" . $base;
96 print STDERR
"$h_file is missing SYSCTL_DID1_PRTNO\n";
101 $new_member = sprintf "{0x%02X, 0x%02X, \"%s\"},", $class, $prtno >> 16, $base;
103 #$new_struct .= "\t//$new_member\t// Invalid\n";
105 $new_struct .= "\t$new_member\n";
112 if ($class =~ /Sandstorm/i) {
114 } elsif ($class =~ /Fury/i) {
116 } elsif ($class =~ /DustDevil/i) {
118 } elsif ($class =~ /Tempest/i) {
120 } elsif ($class =~ /Blizzard/i) {
122 } elsif ($class =~ /Firestorm/i) {