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.

ocromutil.c 2.5KB

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