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.

disrom.pl 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #!/usr/bin/perl -w
  2. #
  3. # Copyright (C) 2008 Michael Brown <mbrown@fensystems.co.uk>.
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU General Public License as
  7. # published by the Free Software Foundation; either version 2 of the
  8. # License, or any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. # 02110-1301, USA.
  19. use strict;
  20. use warnings;
  21. use FindBin;
  22. use lib "$FindBin::Bin";
  23. use Option::ROM qw ( :all );
  24. my $romfile = shift || "-";
  25. my $rom = new Option::ROM;
  26. $rom->load ( $romfile );
  27. my $index = 0;
  28. do {
  29. die "Not an option ROM image\n"
  30. unless $rom->{signature} == ROM_SIGNATURE;
  31. my $romlength = ( $rom->{length} * 512 );
  32. my $filelength = $rom->length;
  33. die "ROM image truncated (is $filelength, should be $romlength)\n"
  34. if $filelength < $romlength;
  35. printf "Index: %d, offset: 0x%08x\n\n", $index++, $rom->file_offset;
  36. printf "ROM header:\n\n";
  37. printf " %-16s 0x%02x (%d)\n", "Length:",
  38. $rom->{length}, ( $rom->{length} * 512 );
  39. printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $rom->{checksum},
  40. ( ( $rom->checksum () == 0 ) ? "" : "INCORRECT: " ), $rom->checksum () if ( exists $rom->{checksum} );
  41. printf " %-16s 0x%04x\n", "Init:", $rom->{init} if ( defined $rom->{init} );
  42. printf " %-16s 0x%04x\n", "UNDI header:", $rom->{undi_header} if ( exists $rom->{undi_header} );
  43. printf " %-16s 0x%04x\n", "PCI header:", $rom->{pci_header};
  44. printf " %-16s 0x%04x\n", "PnP header:", $rom->{pnp_header} if ( exists $rom->{pnp_header} );
  45. printf "\n";
  46. my $efi = $rom->efi_header();
  47. if ( $efi ) {
  48. printf "EFI header:\n\n";
  49. printf " %-16s 0x%04x (%d)\n", "Init size:",
  50. $efi->{init_size}, ( $efi->{init_size} * 512 );
  51. printf " %-16s 0x%08x\n", "EFI Signature:", $efi->{efi_signature};
  52. printf " %-16s 0x%04x\n", "EFI Subsystem:", $efi->{efi_subsystem};
  53. printf " %-16s 0x%04x\n", "EFI Machine type:", $efi->{efi_machine_type};
  54. printf " %-16s 0x%04x\n", "Compression type:", $efi->{compression_type};
  55. printf " %-16s 0x%04x\n", "EFI Image offset:", $efi->{efi_image_offset};
  56. printf "\n";
  57. }
  58. my $pci = $rom->pci_header();
  59. if ( $pci ) {
  60. printf "PCI header:\n\n";
  61. printf " %-16s %s\n", "Signature:", $pci->{signature};
  62. printf " %-16s 0x%04x\n", "Vendor ID:", $pci->{vendor_id};
  63. printf " %-16s 0x%04x\n", "Device ID:", $pci->{device_id};
  64. if ( $pci->{device_list} ) {
  65. printf " %-16s %s\n", "Device list:",
  66. ( join ( ", ", map { sprintf "0x%04x", $_ } $pci->device_list ) );
  67. }
  68. printf " %-16s 0x%02x%02x%02x\n", "Device class:",
  69. $pci->{base_class}, $pci->{sub_class}, $pci->{prog_intf};
  70. printf " %-16s 0x%04x (%d)\n", "Image length:",
  71. $pci->{image_length}, ( $pci->{image_length} * 512 );
  72. printf " %-16s 0x%04x (%d)\n", "Runtime length:",
  73. $pci->{runtime_length}, ( $pci->{runtime_length} * 512 );
  74. printf " %-16s 0x%02x\n", "Code type:", $pci->{code_type};
  75. if ( exists $pci->{conf_header} ) {
  76. printf " %-16s 0x%04x\n", "Config header:", $pci->{conf_header};
  77. printf " %-16s 0x%04x\n", "CLP entry:", $pci->{clp_entry};
  78. }
  79. printf "\n";
  80. }
  81. my $pnp = $rom->pnp_header();
  82. if ( $pnp ) {
  83. printf "PnP header:\n\n";
  84. printf " %-16s %s\n", "Signature:", $pnp->{signature};
  85. printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $pnp->{checksum},
  86. ( ( $pnp->checksum == 0 ) ? "" : "INCORRECT: " ), $pnp->checksum;
  87. printf " %-16s 0x%04x \"%s\"\n", "Manufacturer:",
  88. $pnp->{manufacturer}, $pnp->manufacturer;
  89. printf " %-16s 0x%04x \"%s\"\n", "Product:",
  90. $pnp->{product}, $pnp->product;
  91. printf " %-16s 0x%04x\n", "BCV:", $pnp->{bcv};
  92. printf " %-16s 0x%04x\n", "BDV:", $pnp->{bdv};
  93. printf " %-16s 0x%04x\n", "BEV:", $pnp->{bev};
  94. printf "\n";
  95. }
  96. my $undi = $rom->undi_header();
  97. if ( $undi ) {
  98. printf "UNDI header:\n\n";
  99. printf " %-16s %s\n", "Signature:", $undi->{signature};
  100. printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $undi->{checksum},
  101. ( ( $undi->checksum == 0 ) ? "" : "INCORRECT: " ), $undi->checksum;
  102. printf " %-16s %d.%d.%d\n", "UNDI version:", $undi->{version_major},
  103. $undi->{version_minor}, $undi->{version_revision};
  104. printf " %-16s 0x%04x\n", "Loader entry:", $undi->{loader_entry};
  105. printf " %-16s 0x%04x\n", "Stack size:", $undi->{stack_size};
  106. printf " %-16s 0x%04x\n", "Data size:", $undi->{data_size};
  107. printf " %-16s 0x%04x\n", "Code size:", $undi->{code_size};
  108. printf " %-16s %s\n", "Bus type:", $undi->{bus_type};
  109. printf "\n";
  110. }
  111. my $ipxe = $rom->ipxe_header();
  112. if ( $ipxe ) {
  113. printf "iPXE header:\n\n";
  114. printf " %-16s 0x%02x (%s0x%02x)\n", "Checksum:", $ipxe->{checksum},
  115. ( ( $ipxe->checksum == 0 ) ? "" : "INCORRECT: " ), $ipxe->checksum;
  116. printf " %-16s 0x%02x (%d)\n", "Shrunk length:",
  117. $ipxe->{shrunk_length}, ( $ipxe->{shrunk_length} * 512 );
  118. printf " %-16s 0x%08x\n", "Build ID:", $ipxe->{build_id};
  119. printf "\n";
  120. }
  121. } while ( $rom = $rom->next_image );