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.

catrom.pl 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/perl -w
  2. use warnings;
  3. use strict;
  4. use bytes;
  5. use constant MAX_ROM_LEN => 1024*1024;
  6. use constant PCI_OFF => 0x18;
  7. use constant INDICATOR_OFF => 0x15;
  8. my $total_len = 0;
  9. my @romfiles = @ARGV
  10. or die "Usage: $0 rom-file-1 rom-file-2 ... > multi-rom-file\n";
  11. while ( my $romfile = shift @romfiles ) {
  12. my $last = @romfiles ? 0 : 1;
  13. open ROM, "<$romfile" or die "Could not open $romfile: $!\n";
  14. my $len = read ( ROM, my $romdata, MAX_ROM_LEN )
  15. or die "Could not read $romfile: $!\n";
  16. close ROM;
  17. die "$romfile is not a ROM file\n"
  18. unless substr ( $romdata, 0, 2 ) eq "\x55\xAA";
  19. ( my $checklen ) = unpack ( 'C', substr ( $romdata, 2, 1 ) );
  20. $checklen *= 512;
  21. die "$romfile has incorrect length field $checklen (should be $len)\n"
  22. unless $len == $checklen;
  23. ( my $pci ) = unpack ( 'v', substr ( $romdata, PCI_OFF, 2 ) );
  24. die "Invalid PCI offset field in $romfile\n"
  25. if $pci >= $len;
  26. die "No PCIR signature in $romfile\n"
  27. unless substr ( $romdata, $pci, 4 ) eq "PCIR";
  28. ( my $indicator ) =
  29. unpack ( 'C', substr ( $romdata, $pci + INDICATOR_OFF, 1 ) );
  30. my $msg = sprintf ( "$romfile: indicator was %02x, ", $indicator );
  31. $indicator &= ! ( 1 << 7 );
  32. $indicator |= ( $last << 7 );
  33. $msg .= sprintf ( "now %02x\n", $indicator );
  34. substr ( $romdata, $pci + INDICATOR_OFF, 1 ) = pack ( 'C', $indicator );
  35. warn $msg;
  36. print $romdata;
  37. }