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.
 
 
 
 
 
 

125 lines
3.1 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 const struct {
  8. uint8_t class;
  9. uint8_t partno;
  10. const char *partname;
  11. } StellarisParts[] = {
  12. ";
  13. $struct_footer = "\t{0xFF, 0x00, \"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. @header_files = sort(grep(/lm.+\.h/, @files));
  24. $ver = 0;
  25. $new_struct = $struct_header;
  26. process_file(@header_files);
  27. $new_struct .= $struct_footer;
  28. $dump = "$comment $ver\n$new_struct";
  29. {
  30. local($/, *INPUT);
  31. open(INPUT, $file) || die "can't open $file: $!";
  32. $contents = <INPUT>;
  33. close(INPUT);
  34. }
  35. $old_struct = qr/((^\/\/.*?\n)*)\Q$struct_header\E.*?$struct_footer/sm;
  36. $contents =~ s/$old_struct/$dump/;
  37. open(OUTPUT, ">$file") || die "can't open file $file for writing: $!";
  38. print OUTPUT $contents;
  39. close(OUTPUT);
  40. sub process_file {
  41. foreach $h_file (@_) {
  42. ($base) = ($h_file =~ m/lm..(.{3,7})\.h/ig);
  43. $base = uc($base);
  44. local($/, *FILE);
  45. open(FILE, "$dir/$h_file");
  46. $content = <FILE>;
  47. close(FILE);
  48. $invalid = 0;
  49. if ($content =~ /This is part of revision (\d+) of/) {
  50. if ($ver != 0 and $ver != $1) {
  51. print STDERR "File version mismatch: $ver != $1\n";
  52. $ver = max($ver, $1);
  53. } else {
  54. $ver = $1;
  55. }
  56. }
  57. if ($content =~ /SYSCTL_DID0_CLASS_[^M].+?0x(\S+)/s) {
  58. $class = hex($1) >> 16;
  59. } else {
  60. # attempt another way to get class
  61. if ($content =~ /\s(\S+)-class/) {
  62. $class = getclass($1);
  63. if ($class eq 0xFF) {
  64. print STDERR "$h_file unknown class\n";
  65. $invalid = 1;
  66. }
  67. } else {
  68. print STDERR "$h_file is missing SYSCTL_DID0_CLASS_\n";
  69. $class = 0;
  70. $invalid = 1;
  71. }
  72. }
  73. if ($content =~ /SYSCTL_DID1_PRTNO_$base.+0x(\S+)/) {
  74. $prtno = hex($1);
  75. $base = "LM3S" . $base;
  76. } else {
  77. # LM4F have a changed header
  78. if ($content =~ /SYSCTL_DID1_PRTNO_LM4F$base.+?0x(\S+)/s) {
  79. $prtno = hex($1);
  80. $base = "LM4F" . $base;
  81. } else {
  82. print STDERR "$h_file is missing SYSCTL_DID1_PRTNO\n";
  83. $prtno = 0;
  84. $invalid = 1;
  85. }
  86. }
  87. $new_member = sprintf "{0x%02X, 0x%02X, \"%s\"},", $class, $prtno >> 16, $base;
  88. if ($invalid == 1) {
  89. #$new_struct .= "\t//$new_member\t// Invalid\n";
  90. } else {
  91. $new_struct .= "\t$new_member\n";
  92. }
  93. }
  94. }
  95. sub getclass {
  96. $class = $_[0];
  97. if ($class =~ /Sandstorm/i) {
  98. return 0;
  99. } elsif ($class =~ /Fury/i) {
  100. return 1;
  101. } elsif ($class =~ /DustDevil/i) {
  102. return 3;
  103. } elsif ($class =~ /Tempest/i) {
  104. return 4;
  105. } elsif ($class =~ /Blizzard/i) {
  106. return 5;
  107. } elsif ($class =~ /Firestorm/i) {
  108. return 6;
  109. }
  110. return 0xFF;
  111. }