0016-util-ifdtool-add-nuke-flag-all-0xFF-on-region.patch 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. From 32a961895ed41cd2bb1f9ae00ab0200c4bfb0bf3 Mon Sep 17 00:00:00 2001
  2. From: Leah Rowe <leah@libreboot.org>
  3. Date: Sun, 19 Feb 2023 18:21:43 +0000
  4. Subject: [PATCH 16/18] util/ifdtool: add --nuke flag (all 0xFF on region)
  5. When this option is used, the region's contents are overwritten
  6. with all ones (0xFF).
  7. Example:
  8. ./ifdtool --nuke gbe coreboot.rom
  9. ./ifdtool --nuke bios coreboot.com
  10. ./ifdtool --nuke me coreboot.com
  11. Rebased since the last revision update in lbmk.
  12. ---
  13. util/ifdtool/ifdtool.c | 117 ++++++++++++++++++++++++++++++-----------
  14. 1 file changed, 85 insertions(+), 32 deletions(-)
  15. diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
  16. index 98afa4bbcf..5509721018 100644
  17. --- a/util/ifdtool/ifdtool.c
  18. +++ b/util/ifdtool/ifdtool.c
  19. @@ -1771,6 +1771,7 @@ static void print_usage(const char *name)
  20. " wbg - Wellsburg\n"
  21. " -S | --setpchstrap Write a PCH strap\n"
  22. " -V | --newvalue The new value to write into PCH strap specified by -S\n"
  23. + " -N | --nuke <region> Overwrite the specified region with 0xFF (all ones)\n"
  24. " -v | --version: print the version\n"
  25. " -h | --help: print this help\n\n"
  26. "<region> is one of Descriptor, BIOS, ME, GbE, Platform Data, Secondary BIOS, "
  27. @@ -1778,13 +1779,70 @@ static void print_usage(const char *name)
  28. "\n");
  29. }
  30. +static int
  31. +get_region_type_string(const char *region_type_string)
  32. +{
  33. + if (region_type_string == NULL)
  34. + return -1;
  35. + else if (!strcasecmp("Descriptor", region_type_string))
  36. + region_type = 0;
  37. + else if (!strcasecmp("BIOS", region_type_string))
  38. + region_type = 1;
  39. + else if (!strcasecmp("ME", region_type_string))
  40. + region_type = 2;
  41. + else if (!strcasecmp("GbE", region_type_string))
  42. + region_type = 3;
  43. + else if (!strcasecmp("Platform Data", region_type_string))
  44. + region_type = 4;
  45. + else if (!strcasecmp("Device Exp1", region_type_string))
  46. + region_type = 5;
  47. + else if (!strcasecmp("Secondary BIOS", region_type_string))
  48. + region_type = 6;
  49. + else if (!strcasecmp("Reserved", region_type_string))
  50. + region_type = 7;
  51. + else if (!strcasecmp("EC", region_type_string))
  52. + region_type = 8;
  53. + else if (!strcasecmp("Device Exp2", region_type_string))
  54. + region_type = 9;
  55. + else if (!strcasecmp("IE", region_type_string))
  56. + region_type = 10;
  57. + else if (!strcasecmp("10GbE_0", region_type_string))
  58. + region_type = 11;
  59. + else if (!strcasecmp("10GbE_1", region_type_string))
  60. + region_type = 12;
  61. + else if (!strcasecmp("PTT", region_type_string))
  62. + region_type = 15;
  63. + else
  64. + return -1;
  65. +}
  66. +
  67. +static void
  68. +nuke(const char *filename, char *image, int size, int region_type)
  69. +{
  70. + int i;
  71. + region_t region;
  72. + const frba_t *frba = find_frba(image, size);
  73. + if (!frba)
  74. + exit(EXIT_FAILURE);
  75. +
  76. + region = get_region(frba, region_type);
  77. + if (region.size > 0) {
  78. + for (i = region.base; i <= region.limit; i++) {
  79. + if ((i + 1) > (size))
  80. + break;
  81. + image[i] = 0xFF;
  82. + }
  83. + write_image(filename, image, size);
  84. + }
  85. +}
  86. +
  87. int main(int argc, char *argv[])
  88. {
  89. int opt, option_index = 0;
  90. int mode_dump = 0, mode_extract = 0, mode_inject = 0, mode_spifreq = 0;
  91. int mode_em100 = 0, mode_locked = 0, mode_unlocked = 0, mode_validate = 0;
  92. int mode_layout = 0, mode_newlayout = 0, mode_density = 0, mode_setstrap = 0;
  93. - int mode_read = 0, mode_altmedisable = 0, altmedisable = 0;
  94. + int mode_read = 0, mode_altmedisable = 0, altmedisable = 0, mode_nuke = 0;
  95. char *region_type_string = NULL, *region_fname = NULL;
  96. const char *layout_fname = NULL;
  97. char *new_filename = NULL;
  98. @@ -1815,6 +1873,7 @@ int main(int argc, char *argv[])
  99. {"validate", 0, NULL, 't'},
  100. {"setpchstrap", 1, NULL, 'S'},
  101. {"newvalue", 1, NULL, 'V'},
  102. + {"nuke", 1, NULL, 'N'},
  103. {0, 0, 0, 0}
  104. };
  105. @@ -1855,35 +1914,8 @@ int main(int argc, char *argv[])
  106. region_fname++;
  107. // Descriptor, BIOS, ME, GbE, Platform
  108. // valid type?
  109. - if (!strcasecmp("Descriptor", region_type_string))
  110. - region_type = 0;
  111. - else if (!strcasecmp("BIOS", region_type_string))
  112. - region_type = 1;
  113. - else if (!strcasecmp("ME", region_type_string))
  114. - region_type = 2;
  115. - else if (!strcasecmp("GbE", region_type_string))
  116. - region_type = 3;
  117. - else if (!strcasecmp("Platform Data", region_type_string))
  118. - region_type = 4;
  119. - else if (!strcasecmp("Device Exp1", region_type_string))
  120. - region_type = 5;
  121. - else if (!strcasecmp("Secondary BIOS", region_type_string))
  122. - region_type = 6;
  123. - else if (!strcasecmp("Reserved", region_type_string))
  124. - region_type = 7;
  125. - else if (!strcasecmp("EC", region_type_string))
  126. - region_type = 8;
  127. - else if (!strcasecmp("Device Exp2", region_type_string))
  128. - region_type = 9;
  129. - else if (!strcasecmp("IE", region_type_string))
  130. - region_type = 10;
  131. - else if (!strcasecmp("10GbE_0", region_type_string))
  132. - region_type = 11;
  133. - else if (!strcasecmp("10GbE_1", region_type_string))
  134. - region_type = 12;
  135. - else if (!strcasecmp("PTT", region_type_string))
  136. - region_type = 15;
  137. - if (region_type == -1) {
  138. + if ((region_type =
  139. + get_region_type_string(region_type_string)) == -1) {
  140. fprintf(stderr, "No such region type: '%s'\n\n",
  141. region_type_string);
  142. print_usage(argv[0]);
  143. @@ -2050,6 +2082,22 @@ int main(int argc, char *argv[])
  144. case 't':
  145. mode_validate = 1;
  146. break;
  147. + case 'N':
  148. + region_type_string = strdup(optarg);
  149. + if (!region_type_string) {
  150. + fprintf(stderr, "No region specified\n");
  151. + print_usage(argv[0]);
  152. + exit(EXIT_FAILURE);
  153. + }
  154. + if ((region_type =
  155. + get_region_type_string(region_type_string)) == -1) {
  156. + fprintf(stderr, "No such region type: '%s'\n\n",
  157. + region_type_string);
  158. + print_usage(argv[0]);
  159. + exit(EXIT_FAILURE);
  160. + }
  161. + mode_nuke = 1;
  162. + break;
  163. case 'v':
  164. print_version();
  165. exit(EXIT_SUCCESS);
  166. @@ -2065,7 +2113,7 @@ int main(int argc, char *argv[])
  167. if ((mode_dump + mode_layout + mode_extract + mode_inject + mode_setstrap +
  168. mode_newlayout + (mode_spifreq | mode_em100 | mode_unlocked |
  169. - mode_locked) + mode_altmedisable + mode_validate) > 1) {
  170. + mode_locked) + mode_altmedisable + mode_validate + mode_nuke) > 1) {
  171. fprintf(stderr, "You may not specify more than one mode.\n\n");
  172. print_usage(argv[0]);
  173. exit(EXIT_FAILURE);
  174. @@ -2073,7 +2121,8 @@ int main(int argc, char *argv[])
  175. if ((mode_dump + mode_layout + mode_extract + mode_inject + mode_setstrap +
  176. mode_newlayout + mode_spifreq + mode_em100 + mode_locked +
  177. - mode_unlocked + mode_density + mode_altmedisable + mode_validate) == 0) {
  178. + mode_unlocked + mode_density + mode_altmedisable + mode_validate +
  179. + mode_nuke) == 0) {
  180. fprintf(stderr, "You need to specify a mode.\n\n");
  181. print_usage(argv[0]);
  182. exit(EXIT_FAILURE);
  183. @@ -2171,6 +2220,10 @@ int main(int argc, char *argv[])
  184. write_image(new_filename, image, size);
  185. }
  186. + if (mode_nuke) {
  187. + nuke(new_filename, image, size, region_type);
  188. + }
  189. +
  190. if (mode_altmedisable) {
  191. fpsba_t *fpsba = find_fpsba(image, size);
  192. fmsba_t *fmsba = find_fmsba(image, size);
  193. --
  194. 2.39.2