summaryrefslogtreecommitdiff
path: root/config/coreboot/next/patches/0003-util-ifdtool-add-nuke-flag-all-0xFF-on-region.patch
blob: afa778a52d6b30fd74afa3d554c5ee5630f8ed7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
From 50ae904625d6917c68ff8f8f50c280d79842142b Mon Sep 17 00:00:00 2001
From: Leah Rowe <info@minifree.org>
Date: Sun, 19 Feb 2023 18:21:43 +0000
Subject: [PATCH 3/5] util/ifdtool: add --nuke flag (all 0xFF on region)

When this option is used, the region's contents are overwritten
with all ones (0xFF).

Example:

./ifdtool --nuke gbe coreboot.rom
./ifdtool --nuke bios coreboot.com
./ifdtool --nuke me coreboot.com

Rebased since the last revision update in lbmk.

Signed-off-by: Leah Rowe <leah@libreboot.org>
---
 util/ifdtool/ifdtool.c | 114 ++++++++++++++++++++++++++++++-----------
 1 file changed, 83 insertions(+), 31 deletions(-)

diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c
index 36477eef66..3ebef74042 100644
--- a/util/ifdtool/ifdtool.c
+++ b/util/ifdtool/ifdtool.c
@@ -2217,6 +2217,7 @@ static void print_usage(const char *name)
 	       "                                         tgl    - Tiger Lake\n"
 	       "                                         wbg    - Wellsburg\n"
 	       "   -S | --setpchstrap                    Write a PCH strap\n"
+	       "   -N | --nuke <region>                  Overwrite the specified region with 0xFF (all ones)\n"
 	       "   -V | --newvalue                       The new value to write into PCH strap specified by -S\n"
 	       "   -v | --version:                       print the version\n"
 	       "   -h | --help:                          print this help\n\n"
@@ -2225,6 +2226,60 @@ static void print_usage(const char *name)
 	       "\n");
 }
 
+static int
+get_region_type_string(const char *region_type_string)
+{
+       if (!strcasecmp("Descriptor", region_type_string))
+               return 0;
+       else if (!strcasecmp("BIOS", region_type_string))
+               return 1;
+       else if (!strcasecmp("ME", region_type_string))
+               return 2;
+       else if (!strcasecmp("GbE", region_type_string))
+               return 3;
+       else if (!strcasecmp("Platform Data", region_type_string))
+               return 4;
+       else if (!strcasecmp("Device Exp1", region_type_string))
+               return 5;
+       else if (!strcasecmp("Secondary BIOS", region_type_string))
+               return 6;
+       else if (!strcasecmp("Reserved", region_type_string))
+               return 7;
+       else if (!strcasecmp("EC", region_type_string))
+               return 8;
+       else if (!strcasecmp("Device Exp2", region_type_string))
+               return 9;
+       else if (!strcasecmp("IE", region_type_string))
+               return 10;
+       else if (!strcasecmp("10GbE_0", region_type_string))
+               return 11;
+       else if (!strcasecmp("10GbE_1", region_type_string))
+               return 12;
+       else if (!strcasecmp("PTT", region_type_string))
+               return 15;
+       return -1;
+}
+
+static void
+nuke(const char *filename, char *image, int size, int region_type)
+{
+       int i;
+       struct region region;
+       const struct frba *frba = find_frba(image, size);
+       if (!frba)
+               exit(EXIT_FAILURE);
+
+       region = get_region(frba, region_type);
+       if (region.size > 0) {
+               for (i = region.base; i <= region.limit; i++) {
+                       if ((i + 1) > (size))
+                               break;
+                       image[i] = 0xFF;
+               }
+               write_image(filename, image, size);
+       }
+}
+
 int main(int argc, char *argv[])
 {
 	int opt, option_index = 0;
@@ -2232,6 +2287,7 @@ int main(int argc, char *argv[])
 	int mode_em100 = 0, mode_locked = 0, mode_unlocked = 0, mode_validate = 0;
 	int mode_layout = 0, mode_newlayout = 0, mode_density = 0, mode_setstrap = 0;
 	int mode_read = 0, mode_altmedisable = 0, altmedisable = 0, mode_fmap_template = 0;
+	int mode_nuke = 0;
 	int mode_gpr0_disable = 0, mode_gpr0_enable = 0, mode_gpr0_status = 0;
 	char *region_type_string = NULL, *region_fname = NULL;
 	const char *layout_fname = NULL;
@@ -2267,6 +2323,7 @@ int main(int argc, char *argv[])
 		{"validate", 0, NULL, 't'},
 		{"setpchstrap", 1, NULL, 'S'},
 		{"newvalue", 1, NULL, 'V'},
+		{"nuke", 1, NULL, 'N'},
 		{0, 0, 0, 0}
 	};
 
@@ -2316,35 +2373,8 @@ int main(int argc, char *argv[])
 			region_fname++;
 			// Descriptor, BIOS, ME, GbE, Platform
 			// valid type?
-			if (!strcasecmp("Descriptor", region_type_string))
-				region_type = 0;
-			else if (!strcasecmp("BIOS", region_type_string))
-				region_type = 1;
-			else if (!strcasecmp("ME", region_type_string))
-				region_type = 2;
-			else if (!strcasecmp("GbE", region_type_string))
-				region_type = 3;
-			else if (!strcasecmp("Platform Data", region_type_string))
-				region_type = 4;
-			else if (!strcasecmp("Device Exp1", region_type_string))
-				region_type = 5;
-			else if (!strcasecmp("Secondary BIOS", region_type_string))
-				region_type = 6;
-			else if (!strcasecmp("Reserved", region_type_string))
-				region_type = 7;
-			else if (!strcasecmp("EC", region_type_string))
-				region_type = 8;
-			else if (!strcasecmp("Device Exp2", region_type_string))
-				region_type = 9;
-			else if (!strcasecmp("IE", region_type_string))
-				region_type = 10;
-			else if (!strcasecmp("10GbE_0", region_type_string))
-				region_type = 11;
-			else if (!strcasecmp("10GbE_1", region_type_string))
-				region_type = 12;
-			else if (!strcasecmp("PTT", region_type_string))
-				region_type = 15;
-			if (region_type == -1) {
+			if ((region_type =
+			    get_region_type_string(region_type_string)) == -1) {
 				fprintf(stderr, "No such region type: '%s'\n\n",
 					region_type_string);
 				fprintf(stderr, "run '%s -h' for usage\n", argv[0]);
@@ -2521,6 +2551,22 @@ int main(int argc, char *argv[])
 		case 't':
 			mode_validate = 1;
 			break;
+               case 'N':
+                       region_type_string = strdup(optarg);
+                       if (!region_type_string) {
+                               fprintf(stderr, "No region specified\n");
+                               print_usage(argv[0]);
+                               exit(EXIT_FAILURE);
+                       }
+                       if ((region_type =
+                           get_region_type_string(region_type_string)) == -1) {
+                               fprintf(stderr, "No such region type: '%s'\n\n",
+                                       region_type_string);
+                               print_usage(argv[0]);
+                               exit(EXIT_FAILURE);
+                       }
+                       mode_nuke = 1;
+                       break;
 		case 'v':
 			print_version();
 			exit(EXIT_SUCCESS);
@@ -2540,7 +2586,8 @@ int main(int argc, char *argv[])
 	if ((mode_dump + mode_layout + mode_fmap_template + mode_extract + mode_inject +
 			mode_setstrap + mode_newlayout + (mode_spifreq | mode_em100 |
 			mode_unlocked | mode_locked) + mode_altmedisable + mode_validate +
-			(mode_gpr0_disable | mode_gpr0_enable) + mode_gpr0_status) > 1) {
+			(mode_gpr0_disable | mode_gpr0_enable) + mode_gpr0_status +
+			mode_nuke) > 1) {
 		fprintf(stderr, "You may not specify more than one mode.\n\n");
 		fprintf(stderr, "run '%s -h' for usage\n", argv[0]);
 		exit(EXIT_FAILURE);
@@ -2549,7 +2596,8 @@ int main(int argc, char *argv[])
 	if ((mode_dump + mode_layout + mode_fmap_template + mode_extract + mode_inject +
 			mode_setstrap + mode_newlayout + mode_spifreq + mode_em100 +
 			mode_locked + mode_unlocked + mode_density + mode_altmedisable +
-			mode_validate + (mode_gpr0_disable | mode_gpr0_enable) + mode_gpr0_status) == 0) {
+			mode_validate + (mode_gpr0_disable | mode_gpr0_enable) + mode_gpr0_status +
+			mode_nuke) == 0) {
 		fprintf(stderr, "You need to specify a mode.\n\n");
 		fprintf(stderr, "run '%s -h' for usage\n", argv[0]);
 		exit(EXIT_FAILURE);
@@ -2662,6 +2710,10 @@ int main(int argc, char *argv[])
 		write_image(new_filename, image, size);
 	}
 
+	if (mode_nuke) {
+		nuke(new_filename, image, size, region_type);
+	}
+
 	if (mode_altmedisable) {
 		struct fpsba *fpsba = find_fpsba(image, size);
 		struct fmsba *fmsba = find_fmsba(image, size);
-- 
2.39.5