Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cromutil.c 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * 3c905cutil.c - perform various control ops on the 3C905C bios rom
  3. * which we assume to be an AT49BV512
  4. *
  5. */
  6. #ifndef __i386__
  7. # error "This program can't compile or run on non-intel computers"
  8. #else
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <unistd.h>
  12. #include <sys/io.h>
  13. int main(int argc, char **argv)
  14. {
  15. unsigned int ioaddr, i, n;
  16. unsigned char b;
  17. setuid(0); /* if we're setuid, do it really */
  18. if (argc != 3) {
  19. printf("Usage: romid ioaddr [erase|id|read >file|prog <file]\n");
  20. exit(-1);
  21. }
  22. if (iopl(3)) {
  23. perror("iopl()");
  24. exit(1);
  25. }
  26. sscanf(argv[1],"%x",&ioaddr);
  27. /* Set the register window to 0 for the 3C905C */
  28. outw(0x800, ioaddr+0xe);
  29. if (strcmp(argv[2], "erase") == 0) {
  30. /* do the funky chicken to erase the rom contents */
  31. outl(0x5555, ioaddr+0x4);
  32. outb(0xaa, ioaddr+0x8);
  33. outl(0x2aaa, ioaddr+0x4);
  34. outb(0x55, ioaddr+0x8);
  35. outl(0x5555, ioaddr+0x4);
  36. outb(0x80, ioaddr+0x8);
  37. outl(0x5555, ioaddr+0x4);
  38. outb(0xaa, ioaddr+0x8);
  39. outl(0x2aaa, ioaddr+0x4);
  40. outb(0x55, ioaddr+0x8);
  41. outl(0x5555, ioaddr+0x4);
  42. outb(0x10, ioaddr+0x8);
  43. sleep (1);
  44. printf("Bios ROM at %04x has been erased\n", ioaddr);
  45. } else if (strcmp(argv[2], "id") == 0) {
  46. outl(0x5555, ioaddr+0x4);
  47. outb(0xaa, ioaddr+0x8);
  48. outl(0x2aaa, ioaddr+0x4);
  49. outb(0x55, ioaddr+0x8);
  50. outl(0x5555, ioaddr+0x4);
  51. outb(0x90, ioaddr+0x8);
  52. /* 10ms delay needed */
  53. printf("Manufacturer ID - ");
  54. /* manuf. id */
  55. outl(0x0000, ioaddr+0x4);
  56. printf("%02x\n", inb(ioaddr+0x8));
  57. /* device id */
  58. outl(0x0001, ioaddr+0x4);
  59. printf("Device ID - %02x\n", inb(ioaddr+0x8));
  60. /* undo the funky chicken */
  61. outl(0x5555, ioaddr+0x4);
  62. outb(0xaa, ioaddr+0x8);
  63. outl(0x2aaa, ioaddr+0x4);
  64. outb(0x55, ioaddr+0x8);
  65. outl(0x5555, ioaddr+0x4);
  66. outb(0xf0, ioaddr+0x8);
  67. } else if (strcmp(argv[2], "read") == 0) {
  68. for (i = 0; i < 65536; i++) {
  69. outl(i, ioaddr+0x4);
  70. b = inb(ioaddr+0x8);
  71. write(1, &b, 1);
  72. }
  73. } else if (strcmp(argv[2], "prog") == 0) {
  74. for (i = 0; i < 65536; i++) {
  75. n = read(0, &b, 1);
  76. if (n == 0)
  77. break;
  78. if (n < 0) {
  79. perror("File Error");
  80. exit(-3);
  81. }
  82. outl(0x5555, ioaddr+0x4);
  83. outb(0xaa, ioaddr+0x8);
  84. outl(0x2aaa, ioaddr+0x4);
  85. outb(0x55, ioaddr+0x8);
  86. outl(0x5555, ioaddr+0x4);
  87. outb(0xA0, ioaddr+0x8);
  88. outl(i, ioaddr+0x4);
  89. outb(b, ioaddr+0x8);
  90. while (inb(ioaddr+0x8) != b)
  91. ;
  92. }
  93. }
  94. return 0;
  95. }
  96. #endif /* __i386__ */