Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

romid.c 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* This little program is my try to provide information about the
  2. EtherBoot rom via environment variables to a batch file. This
  3. could be done better, I think, but it works...
  4. The program compiles with Borland C 3.1; other versions not tested.
  5. The C code for setting the environment variables I got from an
  6. archive, it was written by Richard Marks <rmarks@KSP.unisys.COM>.
  7. ROMID is written by Guenter Knauf <eflash@gmx.net>
  8. */
  9. #define VERSION "0.6"
  10. #define VDATE "2003-08-24"
  11. #include <fcntl.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #define ROMSTART 0xC8000
  16. #define ROMEND 0xE8000
  17. #define ROMINCREMENT 0x00800
  18. #define ROMMASK 0x03FFF
  19. int verbose = 0;
  20. int settheenv(char *symbol, char *val);
  21. static int rom_scan(const unsigned char huge *rom,long offset,long len) {
  22. long size,i,j;
  23. char symbol[16];
  24. char val[64];
  25. char romid[64];
  26. char *rptr;
  27. if (rom[offset] != 0x55 || rom[offset+1] != 0xAA)
  28. return 0;
  29. size = (long)rom[offset+2]*512L;
  30. if (verbose) {
  31. printf("Found ROM header at %04lX:0000; announces %ldk image\n", offset/16,(size+512)/1024);
  32. if (offset & ROMMASK)
  33. printf(" This is a unusual position; not all BIOSs might find it.\n"
  34. " Try to move to a 16kB boundary.\n");
  35. if (size > len) {
  36. printf(" This image extends beyond %04X:0000. It clashes with the system BIOS\n", ROMEND/16);
  37. size = len;
  38. }
  39. }
  40. for (i=0; i<64; i++) {
  41. if (rom[offset+size-3-i] == 0xff)
  42. break;
  43. }
  44. if (20<i && i<63) {
  45. i--;
  46. for (j=0; j<i; j++)
  47. val[j] = rom[offset+size-3-i+j];
  48. val[i] = 0;
  49. } else
  50. return 0;
  51. if (strstr(val, "therboot") == NULL)
  52. return 0;
  53. if (verbose)
  54. printf("ROM Signature '%s'\n", val);
  55. if ((rptr = strstr(val, "rom")) != NULL) {
  56. for (i=1; i<4; i++) {
  57. rptr--;
  58. if (rptr[0] == 0x2E)
  59. break;
  60. }
  61. i = 0;
  62. while (!(rptr[0] == 0x20 || rptr < val)) {
  63. i++;
  64. rptr--;
  65. }
  66. rptr++;
  67. i--;
  68. strncpy(romid, rptr, i);
  69. romid[i] = 0;
  70. if (verbose)
  71. printf("ROM Driver ID '%s'\n", romid);
  72. strcpy(symbol, "ROMID");
  73. if (settheenv(symbol, romid))
  74. printf("Error setting evironment var %s with value %s\n", symbol, romid);
  75. } else {
  76. if (verbose)
  77. printf("Couldnt find driver name!\n");
  78. return 0;
  79. }
  80. if (rom[offset+0x1C] == 'P' && rom[offset+0x1D] == 'C' && rom[offset+0x1E] == 'I') {
  81. sprintf(val, "%02X%02X:%02X%02X", rom[offset+0x21], rom[offset+0x20],
  82. rom[offset+0x23], rom[offset+0x22]);
  83. if (verbose)
  84. printf("ROM Vendor ID '%s'\n", val);
  85. strcpy(symbol, "PCIID");
  86. if (settheenv(symbol, val))
  87. printf("Error setting evironment var %s with value %s\n", symbol, val);
  88. }
  89. return 1;
  90. }
  91. /* **************** main stuff **************** */
  92. int main (int argc, char *argv[]) {
  93. long i;
  94. printf("\nROM-ID for Etherboot v%s (c) G. Knauf %s\n", VERSION, VDATE);
  95. if (argc > 1) {
  96. /* parse input parameters */
  97. for (argc--, argv++; *argv; argc--, argv++) {
  98. if ((strnicmp (*argv, "-", 1) == 0) || (strnicmp (*argv, "/", 1) == 0)) {
  99. if ((strnicmp (*argv, "-V", 2) == 0) || (strnicmp (*argv, "/V", 2) == 0)) {
  100. verbose = 1;
  101. } else {
  102. printf("Usage: %s [-v]\n");
  103. }
  104. }
  105. }
  106. }
  107. for (i = ROMEND; (i -= ROMINCREMENT) >= ROMSTART;)
  108. if (rom_scan(0,i,ROMEND-i))
  109. break;
  110. return 0;
  111. }