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.

parserom.pl 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/perl -w
  2. #
  3. # Parse PCI_ROM and ISA_ROM entries from a source file on stdin and
  4. # output the relevant Makefile variable definitions to stdout
  5. #
  6. # Based upon portions of Ken Yap's genrules.pl
  7. use strict;
  8. use warnings;
  9. die "Syntax: $0 driver_source.c" unless @ARGV == 1;
  10. my $source = shift;
  11. open DRV, "<$source" or die "Could not open $source: $!\n";
  12. ( my $family, my $driver_name ) = ( $source =~ /^(.*?([^\/]+))\..$/ )
  13. or die "Could not parse source file name \"$source\"\n";
  14. my $printed_family;
  15. sub rom {
  16. ( my $type, my $image, my $desc, my $vendor, my $device ) = @_;
  17. my $ids = $vendor ? "$vendor,$device" : "-";
  18. unless ( $printed_family ) {
  19. print "\n";
  20. print "# NIC\t\n";
  21. print "# NIC\tfamily\t$family\n";
  22. print "DRIVERS += $driver_name\n";
  23. $printed_family = 1;
  24. }
  25. print "\n";
  26. print "# NIC\t$image\t$ids\t$desc\n";
  27. print "DRIVER_$image = $driver_name\n";
  28. print "ROM_TYPE_$image = $type\n";
  29. print "ROM_DESCRIPTION_$image = \"$desc\"\n";
  30. print "PCI_VENDOR_$image = 0x$vendor\n" if $vendor;
  31. print "PCI_DEVICE_$image = 0x$device\n" if $device;
  32. print "ROMS += $image\n";
  33. print "ROMS_$driver_name += $image\n";
  34. }
  35. while ( <DRV> ) {
  36. next unless /(PCI|ISA)_ROM\s*\(/;
  37. if ( /^\s*PCI_ROM\s*\(
  38. \s*0x([0-9A-Fa-f]{4})\s*, # PCI vendor
  39. \s*0x([0-9A-Fa-f]{4})\s*, # PCI device
  40. \s*\"([^\"]*)\"\s*, # Image
  41. \s*\"([^\"]*)\"\s*, # Description
  42. \s*.*\s* # Driver data
  43. \)/x ) {
  44. ( my $vendor, my $device, my $image, my $desc ) = ( lc $1, lc $2, $3, $4 );
  45. rom ( "pci", $image, $desc, $vendor, $device );
  46. rom ( "pci", lc "${vendor}${device}", $desc, $vendor, $device );
  47. } elsif ( /^\s*ISA_ROM\s*\(
  48. \s*\"([^\"]*)\"\s*, # Image
  49. \s*\"([^\"]*)\"\s* # Description
  50. \)/x ) {
  51. ( my $image, my $desc ) = ( $1, $2 );
  52. rom ( "isa", $image, $desc );
  53. } else {
  54. warn "Malformed PCI_ROM or ISA_ROM macro on line $. of $source\n";
  55. }
  56. }
  57. close DRV;