ich9show.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * ich9show.c
  3. * Just a little hack by Leah to show the ICH9 region read/write status
  4. *
  5. * Purpose: disable and remove the ME from ich9m/gm45 systems in coreboot.
  6. *
  7. * Copyright (C) 2014 Steve Shenton <sgsit@libreboot.org>
  8. * Copyright (C) 2014,2015,2019 Leah Rowe <info@minifree.org>
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation, either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /* Initially based on proof of concept by Steve Shenton. */
  24. /* Original utility can be found at https://gitorious.org/ich9descriptortool */
  25. /*
  26. * Read a factory.rom dump (ich9m/gm45 systems) and
  27. * modify the flash descriptor to remove all regions except descriptor,
  28. * Gbe and BIOS. Set BIOS region to full size of the ROM image (after
  29. * the flash descriptor and gbe). Basically, deblob the descriptor.
  30. *
  31. * This will will generate a concatenated descriptor+gbe dump suitable
  32. * for use in libreboot. Currently tested: ThinkPad X200 (coreboot/libreboot)
  33. */
  34. /*
  35. * See docs/hardware/x200_remove_me.html for info plus links to datasheet (also linked below)
  36. *
  37. * Info about flash descriptor (read page 845 onwards):
  38. * http://www.intel.co.uk/content/dam/doc/datasheet/io-controller-hub-9-datasheet.pdf
  39. *
  40. * Info about Gbe region (read whole datasheet):
  41. * http://www.intel.co.uk/content/dam/doc/application-note/i-o-controller-hub-9m-82567lf-lm-v-nvm-map-appl-note.pdf
  42. * https://web.archive.org/web/20150912070329/https://communities.intel.com/community/wired/blog/2010/10/14/how-to-basic-eeprom-checksums
  43. */
  44. #include "ich9show.h"
  45. int main(int argc, char *argv[])
  46. {
  47. if(argc!=2) {
  48. printf("Incorrect number of arguments. Please specify *one* ROM path.\n");
  49. return 1;
  50. } /* TODO: Make ich9show support dumping stats of multiple ROM images */
  51. struct DESCRIPTORREGIONRECORD descriptorStruct;
  52. uint8_t* descriptorBuffer = (uint8_t*)&descriptorStruct;
  53. struct GBEREGIONRECORD_8K gbeStruct8k;
  54. uint8_t* gbeBuffer8k = (uint8_t*)&gbeStruct8k;
  55. uint32_t gbeRegionStart;
  56. char* romFilename = argv[1];
  57. unsigned int bufferLength;
  58. unsigned int romSize;
  59. /*
  60. * ------------------------------------------------------------------
  61. * Compatibility checks. This version of ich9deblob is not yet portable.
  62. * ------------------------------------------------------------------
  63. */
  64. if (systemOrCompilerIncompatible(descriptorStruct, gbeStruct8k)) return 1;
  65. /* If true, fail with error message */
  66. /*
  67. * ------------------------------------------------------------------
  68. * Extract the descriptor and gbe regions from the factory.rom dump
  69. * ------------------------------------------------------------------
  70. */
  71. FILE* fp = NULL;
  72. fp = fopen(romFilename, "rb");
  73. if (NULL == fp)
  74. {
  75. printf("\nerror: could not open %s\n", romFilename);
  76. fclose(fp);
  77. return 1;
  78. }
  79. printf("\n%s opened successfully\n", romFilename);
  80. /*
  81. * Get the descriptor region dump from the the given ROM
  82. * (goes in factoryDescriptorBuffer variable)
  83. */
  84. bufferLength = fread(descriptorBuffer, 1, DESCRIPTORREGIONSIZE, fp);
  85. if (DESCRIPTORREGIONSIZE != bufferLength) //
  86. {
  87. printf("\nerror: could not read descriptor from %s (%i) bytes read\n", romFilename, bufferLength);
  88. fclose(fp);
  89. return 1;
  90. }
  91. printf("\ndescriptor region read successfully\n");
  92. if(!validDescriptor(descriptorStruct)) {
  93. printf("Invalid input: incorrect signature in the given descriptor.");
  94. fclose(fp);
  95. return 1;
  96. }
  97. if (descriptorDefinesGbeRegion(descriptorStruct))
  98. {
  99. gbeRegionStart = descriptorStruct.regionSection.flReg3.BASE << FLREGIONBITSHIFT;
  100. /*
  101. * Set offset so that we can read the data from
  102. * the gbe region
  103. */
  104. fseek(fp, gbeRegionStart, SEEK_SET);
  105. /* Read the gbe data from the given ROM and put it in factoryGbeBuffer8k */
  106. bufferLength = fread(gbeBuffer8k, 1, GBEREGIONSIZE_8K, fp);
  107. if (GBEREGIONSIZE_8K != bufferLength)
  108. {
  109. printf("\nerror: could not read GBe region from %s (%i) bytes read\n", romFilename, bufferLength);
  110. fclose(fp);
  111. return 1;
  112. }
  113. printf("\ngbe (8KiB) region read successfully\n");
  114. }
  115. fseek(fp, 0L, SEEK_END);
  116. romSize = ftell(fp);
  117. printf("\n%s size: [%i] bytes\n", romFilename, romSize);
  118. fclose(fp);
  119. showDescriptorData(descriptorStruct);
  120. if (descriptorDefinesGbeRegion(descriptorStruct))
  121. {
  122. printf("\nMain GbE region:\n\n");
  123. showGbeData(gbeStruct8k.main);
  124. printf("\n");
  125. printf("\nBackup GbE region:\n\n");
  126. showGbeData(gbeStruct8k.backup);
  127. printf("\n");
  128. }
  129. return 0;
  130. }