You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

92 lines
2.4 KiB

  1. #!/usr/bin/perl
  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
  5. $comment = "// Autogenerated by contrib/gen-stellaris-part-header.pl
  6. // From Stellaris Firmware Development Package revision";
  7. $struct_header = "static struct {
  8. uint32_t partno;
  9. const char *partname;
  10. } StellarisParts[] =
  11. {
  12. ";
  13. $struct_footer = "\t{0,\"Unknown part\"}\n};\n";
  14. $#ARGV == 1 || die "Usage: $0 <inc directory> <output file>\n";
  15. -d $ARGV[0] || die $ARGV[0]." is not a directory\n";
  16. $dir = $ARGV[0];
  17. -f $ARGV[1] || die $ARGV[1]." is not a file\n";
  18. $file = $ARGV[1];
  19. print STDERR "Scanning $dir, Updating $file\n";
  20. opendir(DIR, $dir) || die "can't open $dir: $!";
  21. @files = readdir(DIR);
  22. closedir(DIR);
  23. @short_files = sort(grep(/lm3s...\.h/, @files));
  24. @long_files = sort(grep(/lm3s....\.h/, @files));
  25. $ver = 0;
  26. $new_struct = $struct_header;
  27. process_file(@short_files);
  28. process_file(@long_files);
  29. $new_struct .= $struct_footer;
  30. $dump = "$comment $ver\n$new_struct";
  31. {
  32. local($/, *INPUT);
  33. open(INPUT, $file) || die "can't open $file: $!";
  34. $contents = <INPUT>;
  35. close(INPUT);
  36. }
  37. $old_struct = qr/((^\/\/.*?\n)*)\Q$struct_header\E.*?$struct_footer/sm;
  38. $contents =~ s/$old_struct/$dump/;
  39. open(OUTPUT, ">$file") || die "can't open file $file for writing: $!";
  40. print OUTPUT $contents;
  41. close(OUTPUT);
  42. sub process_file {
  43. foreach $h_file (@_) {
  44. ($base) = ($h_file =~ m/lm3s(.{3,4})\.h/ig);
  45. $base = uc($base);
  46. local($/, *FILE);
  47. open(FILE, "$dir/$h_file");
  48. $content = <FILE>;
  49. close(FILE);
  50. $invalid = 0;
  51. if ($content =~ /This is part of revision (\d+) of/) {
  52. if ($ver != 0 and $ver != $1) {
  53. print STDERR "File version mismatch: $ver != $1\n";
  54. $ver = max($ver, $1);
  55. } else {
  56. $ver = $1;
  57. }
  58. }
  59. if ($content =~ /SYSCTL_DID1_VER_[^M]\s+0x(\S+)/) {
  60. $did1_ver = hex($1);
  61. } else {
  62. print STDERR "$h_file is missing SYSCTL_DID1_VER\n";
  63. $did1_ver = 255;
  64. $invalid = 1;
  65. }
  66. if ($content =~ /SYSCTL_DID1_PRTNO_$base\s+0x(\S+)/) {
  67. $prtno = hex($1);
  68. } else {
  69. print STDERR "$h_file is missing SYSCTL_DID1_PRTNO\n";
  70. $prtno = 0;
  71. $invalid = 1;
  72. }
  73. $id = ($did1_ver | $prtno) >> 16;
  74. $new_member = sprintf "{0x%04X,\"LM3S%s\"},", $id, $base;
  75. if ($invalid == 1) {
  76. #$new_struct .= "\t//$new_member\t// Invalid\n";
  77. } else {
  78. $new_struct .= "\t$new_member\n";
  79. }
  80. }
  81. }