summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorEric Wetzel <thewetzel@gmail.com>2011-01-18 11:17:22 -0500
committerØyvind Harboe <oyvind.harboe@zylin.com>2011-01-19 08:41:03 +0100
commita72741818431d693e48b0f016258be0fec1f79da (patch)
tree5e9d2c6bcbbe5973364c61e7e0ebd5ec7f71aa75 /contrib
parent4749a40821de2dcc88cc02d3b3ab5a5418e02c2e (diff)
downloadopenocd_libswd-a72741818431d693e48b0f016258be0fec1f79da.tar.gz
openocd_libswd-a72741818431d693e48b0f016258be0fec1f79da.tar.bz2
openocd_libswd-a72741818431d693e48b0f016258be0fec1f79da.tar.xz
openocd_libswd-a72741818431d693e48b0f016258be0fec1f79da.zip
stellaris: automatically generate and update device IDs
Added a Perl script to contrib that uses the header files in StellarisWare complete Firmware Development Package provided by TI/Luminary to generate a new list of device IDs Used Perl script and revision 6734 of TI/Luminary StellarisWare to update device IDs
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/gen-stellaris-part-header.pl91
1 files changed, 91 insertions, 0 deletions
diff --git a/contrib/gen-stellaris-part-header.pl b/contrib/gen-stellaris-part-header.pl
new file mode 100755
index 00000000..24ddcb12
--- /dev/null
+++ b/contrib/gen-stellaris-part-header.pl
@@ -0,0 +1,91 @@
+#!/usr/bin/perl
+# Automatically generates the StellarisParts struct in src/flash/nor/stellaris.c
+# Uses the header files from TI/Luminary's StellarisWare complete Firmware Development Package
+# available from: http://www.luminarymicro.com/products/software_updates.html
+
+$comment = "// Autogenerated by contrib/gen-stellaris-part-header.pl
+// From Stellaris Firmware Development Package revision";
+
+$struct_header = "static struct {
+ uint32_t partno;
+ const char *partname;
+} StellarisParts[] =
+{
+";
+
+$struct_footer = "\t{0,\"Unknown part\"}\n};\n";
+
+$#ARGV == 1 || die "Usage: $0 <inc directory> <output file>\n";
+-d $ARGV[0] || die $ARGV[0]." is not a directory\n";
+$dir = $ARGV[0];
+-f $ARGV[1] || die $ARGV[1]." is not a file\n";
+$file = $ARGV[1];
+print STDERR "Scanning $dir, Updating $file\n";
+
+opendir(DIR, $dir) || die "can't open $dir: $!";
+@files = readdir(DIR);
+closedir(DIR);
+
+@short_files = sort(grep(/lm3s...\.h/, @files));
+@long_files = sort(grep(/lm3s....\.h/, @files));
+
+$ver = 0;
+$new_struct = $struct_header;
+process_file(@short_files);
+process_file(@long_files);
+$new_struct .= $struct_footer;
+
+$dump = "$comment $ver\n$new_struct";
+{
+ local($/, *INPUT);
+ open(INPUT, $file) || die "can't open $file: $!";
+ $contents = <INPUT>;
+ close(INPUT);
+}
+
+$old_struct = qr/((^\/\/.*?\n)*)\Q$struct_header\E.*?$struct_footer/sm;
+$contents =~ s/$old_struct/$dump/;
+open(OUTPUT, ">$file") || die "can't open file $file for writing: $!";
+print OUTPUT $contents;
+close(OUTPUT);
+
+sub process_file {
+ foreach $h_file (@_) {
+ ($base) = ($h_file =~ m/lm3s(.{3,4})\.h/ig);
+ $base = uc($base);
+ local($/, *FILE);
+ open(FILE, "$dir/$h_file");
+ $content = <FILE>;
+ close(FILE);
+ $invalid = 0;
+ if ($content =~ /This is part of revision (\d+) of/) {
+ if ($ver != 0 and $ver != $1) {
+ print STDERR "File version mismatch: $ver != $1\n";
+ $ver = max($ver, $1);
+ } else {
+ $ver = $1;
+ }
+ }
+ if ($content =~ /SYSCTL_DID1_VER_[^M]\s+0x(\S+)/) {
+ $did1_ver = hex($1);
+ } else {
+ print STDERR "$h_file is missing SYSCTL_DID1_VER\n";
+ $did1_ver = 255;
+ $invalid = 1;
+ }
+ if ($content =~ /SYSCTL_DID1_PRTNO_$base\s+0x(\S+)/) {
+ $prtno = hex($1);
+ } else {
+ print STDERR "$h_file is missing SYSCTL_DID1_PRTNO\n";
+ $prtno = 0;
+ $invalid = 1;
+ }
+ $id = ($did1_ver | $prtno) >> 16;
+ $new_member = sprintf "{0x%04X,\"LM3S%s\"},", $id, $base;
+ if ($invalid == 1) {
+ #$new_struct .= "\t//$new_member\t// Invalid\n";
+ } else {
+ $new_struct .= "\t$new_member\n";
+ }
+ }
+}