Patrick Georgi | ea063cb | 2020-05-08 19:28:13 +0200 | [diff] [blame] | 1 | /* ifdtool - dump Intel Firmware Descriptor information */ |
Patrick Georgi | 7333a11 | 2020-05-08 20:48:04 +0200 | [diff] [blame] | 2 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 3 | |
| 4 | #include <unistd.h> |
| 5 | #include <stdlib.h> |
| 6 | #include <stdio.h> |
| 7 | #include <string.h> |
| 8 | #include <getopt.h> |
| 9 | #include <fcntl.h> |
| 10 | #include <sys/types.h> |
| 11 | #include <sys/stat.h> |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 12 | #include <commonlib/helpers.h> |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 13 | #include <fmap.h> |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 14 | #include "ifdtool.h" |
| 15 | |
Scott Duplichan | f2c9837 | 2014-12-12 21:03:06 -0600 | [diff] [blame] | 16 | #ifndef O_BINARY |
| 17 | #define O_BINARY 0 |
| 18 | #endif |
| 19 | |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 20 | /** |
| 21 | * PTR_IN_RANGE - examine whether a pointer falls in [base, base + limit) |
| 22 | * @param ptr: the non-void* pointer to a single arbitrary-sized object. |
| 23 | * @param base: base address represented with char* type. |
| 24 | * @param limit: upper limit of the legal address. |
| 25 | * |
| 26 | */ |
| 27 | #define PTR_IN_RANGE(ptr, base, limit) \ |
| 28 | ((const char *)(ptr) >= (base) && \ |
| 29 | (const char *)&(ptr)[1] <= (base) + (limit)) |
| 30 | |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 31 | /** |
| 32 | * PLATFORM_HAS_GBE_REGION - some platforms do not support the PCH GbE LAN region |
| 33 | */ |
| 34 | #define PLATFORM_HAS_GBE_REGION (platform != PLATFORM_DNV) |
| 35 | |
| 36 | /* |
| 37 | * PLATFORM_HAS_EC_REGION - some platforms do not support the EC region |
| 38 | */ |
| 39 | #define PLATFORM_HAS_EC_REGION (ifd_version >= IFD_VERSION_2 && platform != PLATFORM_DNV) |
| 40 | |
| 41 | /* |
| 42 | * PLATFORM_HAS_10GBE_X_REGION - some platforms have 1 or more 10GbE LAN regions |
| 43 | */ |
| 44 | #define PLATFORM_HAS_10GBE_0_REGION (platform == PLATFORM_DNV) |
| 45 | #define PLATFORM_HAS_10GBE_1_REGION (platform == PLATFORM_DNV) |
| 46 | |
Patrick Rudolph | 98ecaa4 | 2022-10-24 15:06:15 +0200 | [diff] [blame] | 47 | static int max_regions_from_fdbar(const fdbar_t *fdb); |
| 48 | |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 49 | static int ifd_version; |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 50 | static int chipset; |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 51 | static unsigned int max_regions = 0; |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 52 | static int selected_chip = 0; |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 53 | static int platform = -1; |
Chris Douglass | e271865 | 2014-02-28 08:54:41 -0500 | [diff] [blame] | 54 | |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 55 | static const struct region_name region_names[MAX_REGIONS] = { |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 56 | { "Flash Descriptor", "fd", "flashregion_0_flashdescriptor.bin", "SI_DESC" }, |
| 57 | { "BIOS", "bios", "flashregion_1_bios.bin", "SI_BIOS" }, |
| 58 | { "Intel ME", "me", "flashregion_2_intel_me.bin", "SI_ME" }, |
| 59 | { "GbE", "gbe", "flashregion_3_gbe.bin", "SI_GBE" }, |
| 60 | { "Platform Data", "pd", "flashregion_4_platform_data.bin", "SI_PDR" }, |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 61 | { "Device Exp1", "devexp", "flashregion_5_device_exp.bin", "SI_DEVICEEXT" }, |
| 62 | { "Secondary BIOS", "bios2", "flashregion_6_bios2.bin", "SI_BIOS2" }, |
| 63 | { "Reserved", "res7", "flashregion_7_reserved.bin", NULL }, |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 64 | { "EC", "ec", "flashregion_8_ec.bin", "SI_EC" }, |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 65 | { "Device Exp2", "devexp2", "flashregion_9_device_exp.bin", "SI_DEVICEEXT2" }, |
| 66 | { "IE", "ie", "flashregion_10_ie.bin", "SI_IE" }, |
| 67 | { "10GbE_0", "10gbe_0", "flashregion_11_10gbe0.bin", "SI_10GBE0" }, |
| 68 | { "10GbE_1", "10gbe_1", "flashregion_12_10gbe1.bin", "SI_10GBE1" }, |
| 69 | { "Reserved", "res13", "flashregion_13_reserved.bin", NULL }, |
| 70 | { "Reserved", "res14", "flashregion_14_reserved.bin", NULL }, |
| 71 | { "PTT", "ptt", "flashregion_15_ptt.bin", "SI_PTT" }, |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 72 | }; |
| 73 | |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 74 | /* port from flashrom */ |
| 75 | static const char *const ich_chipset_names[] = { |
| 76 | "Unknown ICH", |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 77 | "ICH8", |
| 78 | "ICH9", |
| 79 | "ICH10", |
Subrata Banik | 89db225 | 2020-08-26 14:49:17 +0530 | [diff] [blame] | 80 | "Unknown PCH", |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 81 | "5 series Ibex Peak", |
| 82 | "6 series Cougar Point", |
| 83 | "7 series Panther Point", |
| 84 | "8 series Lynx Point", |
| 85 | "Baytrail", |
| 86 | "8 series Lynx Point LP", |
| 87 | "8 series Wellsburg", |
| 88 | "9 series Wildcat Point", |
| 89 | "9 series Wildcat Point LP", |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 90 | "Apollo Lake: N3xxx, J3xxx", |
Subrata Banik | 89db225 | 2020-08-26 14:49:17 +0530 | [diff] [blame] | 91 | "Gemini Lake: N5xxx, J5xxx, N4xxx, J4xxx", |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 92 | "Jasper Lake: N6xxx, N51xx, N45xx", |
| 93 | "Elkhart Lake: x6000 series Atom", |
Subrata Banik | 89db225 | 2020-08-26 14:49:17 +0530 | [diff] [blame] | 94 | "100/200 series Sunrise Point", |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 95 | "300 series Cannon Point", |
| 96 | "400 series Ice Point", |
Subrata Banik | a5f4781 | 2020-09-29 11:43:01 +0530 | [diff] [blame] | 97 | "500 series Tiger Point/ 600 series Alder Point", |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 98 | "C620 series Lewisburg", |
Patrick Rudolph | 1920900 | 2022-10-22 10:34:05 +0200 | [diff] [blame] | 99 | "Denverton: C39xx", |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 100 | NULL |
| 101 | }; |
| 102 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 103 | static fdbar_t *find_fd(char *image, int size) |
| 104 | { |
| 105 | int i, found = 0; |
| 106 | |
| 107 | /* Scan for FD signature */ |
| 108 | for (i = 0; i < (size - 4); i += 4) { |
| 109 | if (*(uint32_t *) (image + i) == 0x0FF0A55A) { |
| 110 | found = 1; |
| 111 | break; // signature found. |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | if (!found) { |
| 116 | printf("No Flash Descriptor found in this image\n"); |
| 117 | return NULL; |
| 118 | } |
| 119 | |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 120 | fdbar_t *fdb = (fdbar_t *) (image + i); |
| 121 | return PTR_IN_RANGE(fdb, image, size) ? fdb : NULL; |
| 122 | } |
| 123 | |
Stefan Tauner | 0d22614 | 2018-08-05 18:56:53 +0200 | [diff] [blame] | 124 | static char *find_flumap(char *image, int size) |
| 125 | { |
| 126 | /* The upper map is located in the word before the 256B-long OEM section |
| 127 | * at the end of the 4kB-long flash descriptor. In the official |
| 128 | * documentation this is defined as FDBAR + 0xEFC. However, starting |
| 129 | * with B-Step of Ibex Peak (5 series) the signature (and thus FDBAR) |
| 130 | * has moved 16 bytes back to offset 0x10 of the image. Although |
| 131 | * official documentation still maintains the offset relative to FDBAR |
| 132 | * this is wrong and a simple fixed offset from the start of the image |
| 133 | * works. |
| 134 | */ |
| 135 | char *flumap = image + 4096 - 256 - 4; |
| 136 | return PTR_IN_RANGE(flumap, image, size) ? flumap : NULL; |
| 137 | } |
| 138 | |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 139 | static fcba_t *find_fcba(char *image, int size) |
| 140 | { |
| 141 | fdbar_t *fdb = find_fd(image, size); |
| 142 | if (!fdb) |
| 143 | return NULL; |
| 144 | fcba_t *fcba = (fcba_t *) (image + ((fdb->flmap0 & 0xff) << 4)); |
| 145 | return PTR_IN_RANGE(fcba, image, size) ? fcba : NULL; |
| 146 | |
| 147 | } |
| 148 | |
| 149 | static fmba_t *find_fmba(char *image, int size) |
| 150 | { |
| 151 | fdbar_t *fdb = find_fd(image, size); |
| 152 | if (!fdb) |
| 153 | return NULL; |
| 154 | fmba_t *fmba = (fmba_t *) (image + ((fdb->flmap1 & 0xff) << 4)); |
| 155 | return PTR_IN_RANGE(fmba, image, size) ? fmba : NULL; |
| 156 | } |
| 157 | |
| 158 | static frba_t *find_frba(char *image, int size) |
| 159 | { |
| 160 | fdbar_t *fdb = find_fd(image, size); |
| 161 | if (!fdb) |
| 162 | return NULL; |
| 163 | frba_t *frba = |
| 164 | (frba_t *) (image + (((fdb->flmap0 >> 16) & 0xff) << 4)); |
| 165 | return PTR_IN_RANGE(frba, image, size) ? frba : NULL; |
| 166 | } |
| 167 | |
| 168 | static fpsba_t *find_fpsba(char *image, int size) |
| 169 | { |
| 170 | fdbar_t *fdb = find_fd(image, size); |
| 171 | if (!fdb) |
| 172 | return NULL; |
| 173 | fpsba_t *fpsba = |
| 174 | (fpsba_t *) (image + (((fdb->flmap1 >> 16) & 0xff) << 4)); |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 175 | |
| 176 | int SSL = ((fdb->flmap1 >> 24) & 0xff) * sizeof(uint32_t); |
| 177 | if ((((char *)fpsba) + SSL) >= (image + size)) |
| 178 | return NULL; |
| 179 | return fpsba; |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | static fmsba_t *find_fmsba(char *image, int size) |
| 183 | { |
| 184 | fdbar_t *fdb = find_fd(image, size); |
| 185 | if (!fdb) |
| 186 | return NULL; |
| 187 | fmsba_t *fmsba = (fmsba_t *) (image + ((fdb->flmap2 & 0xff) << 4)); |
| 188 | return PTR_IN_RANGE(fmsba, image, size) ? fmsba : NULL; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 191 | /* port from flashrom */ |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 192 | static enum ich_chipset ifd1_guess_chipset(char *image, int size) |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 193 | { |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 194 | const fdbar_t *fdb = find_fd(image, size); |
| 195 | if (!fdb) |
| 196 | exit(EXIT_FAILURE); |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 197 | uint32_t iccriba = (fdb->flmap2 >> 16) & 0xff; |
| 198 | uint32_t msl = (fdb->flmap2 >> 8) & 0xff; |
| 199 | uint32_t isl = (fdb->flmap1 >> 24); |
Subrata Banik | 89db225 | 2020-08-26 14:49:17 +0530 | [diff] [blame] | 200 | |
| 201 | /* Rest for IFD1 chipset type */ |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 202 | if (iccriba == 0x00) { |
| 203 | if (msl == 0 && isl <= 2) |
| 204 | return CHIPSET_ICH8; |
| 205 | else if (isl <= 2) |
| 206 | return CHIPSET_ICH9; |
| 207 | else if (isl <= 10) |
| 208 | return CHIPSET_ICH10; |
| 209 | else if (isl <= 16) |
| 210 | return CHIPSET_5_SERIES_IBEX_PEAK; |
| 211 | printf("Peculiar firmware descriptor, assuming Ibex Peak compatibility.\n"); |
| 212 | return CHIPSET_5_SERIES_IBEX_PEAK; |
| 213 | } else if (iccriba < 0x31 && (fdb->flmap2 & 0xff) < 0x30) { |
| 214 | if (msl == 0 && isl <= 17) |
| 215 | return CHIPSET_BAYTRAIL; |
| 216 | else if (msl <= 1 && isl <= 18) |
| 217 | return CHIPSET_6_SERIES_COUGAR_POINT; |
| 218 | else if (msl <= 1 && isl <= 21) |
| 219 | return CHIPSET_8_SERIES_LYNX_POINT; |
| 220 | printf("Peculiar firmware descriptor, assuming Wildcat Point compatibility.\n"); |
| 221 | return CHIPSET_9_SERIES_WILDCAT_POINT; |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 222 | } |
Jan Tatje | b7eec4a | 2021-07-05 08:03:07 +0200 | [diff] [blame] | 223 | return CHIPSET_PCH_UNKNOWN; |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 224 | } |
| 225 | |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 226 | static enum ich_chipset ifd2_platform_to_chipset(const int pindex) |
| 227 | { |
| 228 | switch (pindex) { |
Subrata Banik | 6da003c | 2021-07-14 13:52:03 +0530 | [diff] [blame] | 229 | case PLATFORM_APL: |
| 230 | return CHIPSET_N_J_SERIES_APOLLO_LAKE; |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 231 | case PLATFORM_GLK: |
| 232 | return CHIPSET_N_J_SERIES_GEMINI_LAKE; |
| 233 | case PLATFORM_JSL: |
| 234 | return CHIPSET_N_SERIES_JASPER_LAKE; |
| 235 | case PLATFORM_EHL: |
| 236 | return CHIPSET_x6000_SERIES_ELKHART_LAKE; |
Jan Tatje | b7eec4a | 2021-07-05 08:03:07 +0200 | [diff] [blame] | 237 | case PLATFORM_SKLKBL: |
| 238 | return CHIPSET_100_200_SERIES_SUNRISE_POINT; |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 239 | case PLATFORM_CNL: |
| 240 | return CHIPSET_300_SERIES_CANNON_POINT; |
| 241 | case PLATFORM_TGL: |
| 242 | case PLATFORM_ADL: |
Wonkyu Kim | 3922aa5 | 2022-02-02 15:19:05 -0800 | [diff] [blame] | 243 | case PLATFORM_IFD2: |
Subrata Banik | ca82e61 | 2022-01-20 18:51:21 +0530 | [diff] [blame] | 244 | case PLATFORM_MTL: |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 245 | return CHIPSET_500_600_SERIES_TIGER_ALDER_POINT; |
| 246 | case PLATFORM_ICL: |
| 247 | return CHIPSET_400_SERIES_ICE_POINT; |
Johnny Lin | e273a02 | 2021-06-22 11:26:46 +0800 | [diff] [blame] | 248 | case PLATFORM_LBG: |
| 249 | return CHIPSET_C620_SERIES_LEWISBURG; |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 250 | case PLATFORM_DNV: |
| 251 | return CHIPSET_DENVERTON; |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 252 | case PLATFORM_WBG: |
| 253 | return CHIPSET_8_SERIES_WELLSBURG; |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 254 | default: |
| 255 | return CHIPSET_PCH_UNKNOWN; |
| 256 | } |
| 257 | } |
| 258 | |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 259 | /* |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 260 | * Some newer platforms have re-defined the FCBA field that was used to |
| 261 | * distinguish IFD v1 v/s v2. Define a list of platforms that we know do not |
| 262 | * have the required FCBA field, but are IFD v2 and return true if current |
| 263 | * platform is one of them. |
| 264 | */ |
| 265 | static int is_platform_ifd_2(void) |
| 266 | { |
| 267 | static const int ifd_2_platforms[] = { |
Subrata Banik | 6da003c | 2021-07-14 13:52:03 +0530 | [diff] [blame] | 268 | PLATFORM_APL, |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 269 | PLATFORM_GLK, |
| 270 | PLATFORM_CNL, |
Johnny Lin | e273a02 | 2021-06-22 11:26:46 +0800 | [diff] [blame] | 271 | PLATFORM_LBG, |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 272 | PLATFORM_DNV, |
Aamir Bohra | 1018be2 | 2018-06-29 15:08:50 +0530 | [diff] [blame] | 273 | PLATFORM_ICL, |
Ravi Sarawadi | 7d9d63b | 2019-10-22 13:45:36 -0700 | [diff] [blame] | 274 | PLATFORM_TGL, |
rkanabar | d64b046 | 2019-08-30 11:40:08 +0530 | [diff] [blame] | 275 | PLATFORM_JSL, |
Lean Sheng Tan | 0faba3c | 2021-06-09 07:52:24 -0700 | [diff] [blame] | 276 | PLATFORM_EHL, |
Subrata Banik | 46f8073 | 2020-03-14 15:01:42 +0530 | [diff] [blame] | 277 | PLATFORM_ADL, |
Jan Tatje | b7eec4a | 2021-07-05 08:03:07 +0200 | [diff] [blame] | 278 | PLATFORM_SKLKBL, |
Wonkyu Kim | 3922aa5 | 2022-02-02 15:19:05 -0800 | [diff] [blame] | 279 | PLATFORM_IFD2, |
Subrata Banik | ca82e61 | 2022-01-20 18:51:21 +0530 | [diff] [blame] | 280 | PLATFORM_MTL, |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 281 | PLATFORM_WBG, |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 282 | }; |
| 283 | unsigned int i; |
| 284 | |
| 285 | for (i = 0; i < ARRAY_SIZE(ifd_2_platforms); i++) { |
| 286 | if (platform == ifd_2_platforms[i]) |
| 287 | return 1; |
| 288 | } |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 293 | static void check_ifd_version(char *image, int size) |
| 294 | { |
Patrick Rudolph | 98ecaa4 | 2022-10-24 15:06:15 +0200 | [diff] [blame] | 295 | const fdbar_t *fdb = find_fd(image, size); |
| 296 | |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 297 | if (is_platform_ifd_2()) { |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 298 | chipset = ifd2_platform_to_chipset(platform); |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 299 | if (chipset == CHIPSET_8_SERIES_WELLSBURG) |
| 300 | ifd_version = IFD_VERSION_1_5; |
| 301 | else |
| 302 | ifd_version = IFD_VERSION_2; |
Patrick Rudolph | 98ecaa4 | 2022-10-24 15:06:15 +0200 | [diff] [blame] | 303 | max_regions = MIN(max_regions_from_fdbar(fdb), MAX_REGIONS); |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 304 | } else { |
| 305 | ifd_version = IFD_VERSION_1; |
| 306 | chipset = ifd1_guess_chipset(image, size); |
Patrick Rudolph | 98ecaa4 | 2022-10-24 15:06:15 +0200 | [diff] [blame] | 307 | max_regions = MIN(max_regions_from_fdbar(fdb), MAX_REGIONS_OLD); |
Subrata Banik | 8c082e5 | 2021-06-10 23:02:29 +0530 | [diff] [blame] | 308 | } |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 311 | static region_t get_region(const frba_t *frba, unsigned int region_type) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 312 | { |
Aaron Durbin | 0a31e59 | 2015-08-12 11:44:02 -0500 | [diff] [blame] | 313 | int base_mask; |
| 314 | int limit_mask; |
Ronald G. Minnich | 8db3c2a | 2017-05-25 10:48:57 -0700 | [diff] [blame] | 315 | uint32_t flreg; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 316 | region_t region; |
Aaron Durbin | 0a31e59 | 2015-08-12 11:44:02 -0500 | [diff] [blame] | 317 | |
| 318 | if (ifd_version >= IFD_VERSION_2) |
| 319 | base_mask = 0x7fff; |
| 320 | else |
| 321 | base_mask = 0xfff; |
| 322 | |
| 323 | limit_mask = base_mask << 16; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 324 | |
Youness Alaoui | f68e3ba | 2017-10-04 11:35:59 -0400 | [diff] [blame] | 325 | if (region_type >= max_regions) { |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 326 | fprintf(stderr, "Invalid region type %d.\n", region_type); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 327 | exit (EXIT_FAILURE); |
| 328 | } |
| 329 | |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 330 | flreg = frba->flreg[region_type]; |
Ronald G. Minnich | 8db3c2a | 2017-05-25 10:48:57 -0700 | [diff] [blame] | 331 | region.base = (flreg & base_mask) << 12; |
| 332 | region.limit = ((flreg & limit_mask) >> 4) | 0xfff; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 333 | region.size = region.limit - region.base + 1; |
Aaron Durbin | 0a31e59 | 2015-08-12 11:44:02 -0500 | [diff] [blame] | 334 | |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 335 | if (region.size < 0) |
| 336 | region.size = 0; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 337 | |
| 338 | return region; |
| 339 | } |
| 340 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 341 | static void set_region(frba_t *frba, unsigned int region_type, |
| 342 | const region_t *region) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 343 | { |
Youness Alaoui | f68e3ba | 2017-10-04 11:35:59 -0400 | [diff] [blame] | 344 | if (region_type >= max_regions) { |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 345 | fprintf(stderr, "Invalid region type %u.\n", region_type); |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 346 | exit (EXIT_FAILURE); |
| 347 | } |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 348 | |
| 349 | frba->flreg[region_type] = |
| 350 | (((region->limit >> 12) & 0x7fff) << 16) | |
| 351 | ((region->base >> 12) & 0x7fff); |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 352 | } |
| 353 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 354 | static const char *region_name(unsigned int region_type) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 355 | { |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 356 | if (region_type >= max_regions) { |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 357 | fprintf(stderr, "Invalid region type.\n"); |
| 358 | exit (EXIT_FAILURE); |
| 359 | } |
| 360 | |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 361 | return region_names[region_type].pretty; |
| 362 | } |
| 363 | |
Patrick Rudolph | ef5ebdb | 2022-10-22 11:19:02 +0200 | [diff] [blame^] | 364 | static const char *region_name_fmap(unsigned int region_type) |
| 365 | { |
| 366 | if (region_type >= max_regions) { |
| 367 | fprintf(stderr, "Invalid region type.\n"); |
| 368 | exit(EXIT_FAILURE); |
| 369 | } |
| 370 | |
| 371 | return region_names[region_type].fmapname; |
| 372 | } |
| 373 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 374 | static const char *region_name_short(unsigned int region_type) |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 375 | { |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 376 | if (region_type >= max_regions) { |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 377 | fprintf(stderr, "Invalid region type.\n"); |
| 378 | exit (EXIT_FAILURE); |
| 379 | } |
| 380 | |
| 381 | return region_names[region_type].terse; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 382 | } |
| 383 | |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 384 | static int region_num(const char *name) |
| 385 | { |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 386 | unsigned int i; |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 387 | |
Alexander Couzens | fd5c658 | 2016-10-08 00:37:24 +0200 | [diff] [blame] | 388 | for (i = 0; i < max_regions; i++) { |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 389 | if (strcasecmp(name, region_names[i].pretty) == 0) |
| 390 | return i; |
| 391 | if (strcasecmp(name, region_names[i].terse) == 0) |
| 392 | return i; |
| 393 | } |
| 394 | |
| 395 | return -1; |
| 396 | } |
| 397 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 398 | static const char *region_filename(unsigned int region_type) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 399 | { |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 400 | if (region_type >= max_regions) { |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 401 | fprintf(stderr, "Invalid region type %d.\n", region_type); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 402 | exit (EXIT_FAILURE); |
| 403 | } |
| 404 | |
Bill XIE | 1bf6506 | 2017-09-12 11:31:37 +0800 | [diff] [blame] | 405 | return region_names[region_type].filename; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 406 | } |
| 407 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 408 | static void dump_region(unsigned int num, const frba_t *frba) |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 409 | { |
| 410 | region_t region = get_region(frba, num); |
| 411 | printf(" Flash Region %d (%s): %08x - %08x %s\n", |
| 412 | num, region_name(num), region.base, region.limit, |
| 413 | region.size < 1 ? "(unused)" : ""); |
| 414 | } |
| 415 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 416 | static void dump_region_layout(char *buf, size_t bufsize, unsigned int num, |
| 417 | const frba_t *frba) |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 418 | { |
| 419 | region_t region = get_region(frba, num); |
| 420 | snprintf(buf, bufsize, "%08x:%08x %s\n", |
| 421 | region.base, region.limit, region_name_short(num)); |
| 422 | } |
| 423 | |
Patrick Rudolph | 98ecaa4 | 2022-10-24 15:06:15 +0200 | [diff] [blame] | 424 | static int sort_compare(const void *a, const void *b) |
| 425 | { |
| 426 | return *(size_t *)a - *(size_t *)b; |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * IFDv1 always has 8 regions, while IFDv2 always has 16 regions. |
| 431 | * |
| 432 | * It's platform specific which regions are used or are reserved. |
| 433 | * The 'SPI programming guide' as the name says is a guide only, |
| 434 | * not a specification what the hardware actually does. |
| 435 | * The best to do is not to rely on the guide, but detect how many |
| 436 | * regions are present in the IFD and expose them all. |
| 437 | * |
| 438 | * Very early IFDv2 chipsets, sometimes unofficially referred to as |
| 439 | * IFDv1.5 platforms, only have 8 regions. To not corrupt the IFD when |
| 440 | * operating on an IFDv1.5 detect how much space is actually present |
| 441 | * in the IFD. |
| 442 | */ |
| 443 | static int max_regions_from_fdbar(const fdbar_t *fdb) |
| 444 | { |
| 445 | const size_t fcba = (fdb->flmap0 & 0xff) << 4; |
| 446 | const size_t fmba = (fdb->flmap1 & 0xff) << 4; |
| 447 | const size_t frba = ((fdb->flmap0 >> 16) & 0xff) << 4; |
| 448 | const size_t fpsba = ((fdb->flmap1 >> 16) & 0xff) << 4; |
| 449 | const size_t flumap = 4096 - 256 - 4; |
| 450 | size_t sorted[5] = {fcba, fmba, frba, fpsba, flumap}; |
| 451 | |
| 452 | qsort(sorted, ARRAY_SIZE(sorted), sizeof(size_t), sort_compare); |
| 453 | |
| 454 | for (size_t i = 0; i < 4; i++) { |
| 455 | /* |
| 456 | * Find FRBA in the sorted array and determine the size of the |
| 457 | * region by the start of the next region. Every region requires |
| 458 | * 4 bytes of space. |
| 459 | */ |
| 460 | if (sorted[i] == frba) |
| 461 | return MIN((sorted[i+1] - sorted[i])/4, MAX_REGIONS); |
| 462 | } |
| 463 | /* Never reaches this point */ |
| 464 | return 0; |
| 465 | } |
| 466 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 467 | static void dump_frba(const frba_t *frba) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 468 | { |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 469 | unsigned int i; |
Subrata Banik | d52df3cd | 2020-08-26 14:02:01 +0530 | [diff] [blame] | 470 | region_t region; |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 471 | printf("Found Region Section\n"); |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 472 | for (i = 0; i < max_regions; i++) { |
Subrata Banik | d52df3cd | 2020-08-26 14:02:01 +0530 | [diff] [blame] | 473 | region = get_region(frba, i); |
| 474 | /* Skip unused & reserved Flash Region */ |
| 475 | if (region.size < 1 && !strcmp(region_name(i), "Reserved")) |
| 476 | continue; |
| 477 | |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 478 | printf("FLREG%u: 0x%08x\n", i, frba->flreg[i]); |
| 479 | dump_region(i, frba); |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 480 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 483 | static void dump_frba_layout(const frba_t *frba, const char *layout_fname) |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 484 | { |
| 485 | char buf[LAYOUT_LINELEN]; |
| 486 | size_t bufsize = LAYOUT_LINELEN; |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 487 | unsigned int i; |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 488 | |
| 489 | int layout_fd = open(layout_fname, O_WRONLY | O_CREAT | O_TRUNC, |
| 490 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
| 491 | if (layout_fd == -1) { |
| 492 | perror("Could not open file"); |
| 493 | exit(EXIT_FAILURE); |
| 494 | } |
| 495 | |
Alexander Couzens | fd5c658 | 2016-10-08 00:37:24 +0200 | [diff] [blame] | 496 | for (i = 0; i < max_regions; i++) { |
Alexander Couzens | eff596b | 2016-10-08 00:53:09 +0200 | [diff] [blame] | 497 | region_t region = get_region(frba, i); |
| 498 | /* is region invalid? */ |
| 499 | if (region.size < 1) |
| 500 | continue; |
| 501 | |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 502 | dump_region_layout(buf, bufsize, i, frba); |
| 503 | if (write(layout_fd, buf, strlen(buf)) < 0) { |
| 504 | perror("Could not write to file"); |
| 505 | exit(EXIT_FAILURE); |
| 506 | } |
| 507 | } |
| 508 | close(layout_fd); |
| 509 | printf("Wrote layout to %s\n", layout_fname); |
| 510 | } |
| 511 | |
Subrata Banik | d16ef4d | 2020-08-26 15:53:00 +0530 | [diff] [blame] | 512 | static void _decode_spi_frequency(unsigned int freq) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 513 | { |
| 514 | switch (freq) { |
| 515 | case SPI_FREQUENCY_20MHZ: |
| 516 | printf("20MHz"); |
| 517 | break; |
| 518 | case SPI_FREQUENCY_33MHZ: |
| 519 | printf("33MHz"); |
| 520 | break; |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 521 | case SPI_FREQUENCY_48MHZ: |
| 522 | printf("48MHz"); |
| 523 | break; |
| 524 | case SPI_FREQUENCY_50MHZ_30MHZ: |
| 525 | switch (ifd_version) { |
| 526 | case IFD_VERSION_1: |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 527 | case IFD_VERSION_1_5: |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 528 | printf("50MHz"); |
| 529 | break; |
| 530 | case IFD_VERSION_2: |
| 531 | printf("30MHz"); |
| 532 | break; |
| 533 | } |
| 534 | break; |
| 535 | case SPI_FREQUENCY_17MHZ: |
| 536 | printf("17MHz"); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 537 | break; |
| 538 | default: |
| 539 | printf("unknown<%x>MHz", freq); |
| 540 | } |
| 541 | } |
| 542 | |
Subrata Banik | d16ef4d | 2020-08-26 15:53:00 +0530 | [diff] [blame] | 543 | static void _decode_spi_frequency_500_series(unsigned int freq) |
| 544 | { |
| 545 | switch (freq) { |
| 546 | case SPI_FREQUENCY_100MHZ: |
| 547 | printf("100MHz"); |
| 548 | break; |
| 549 | case SPI_FREQUENCY_50MHZ: |
| 550 | printf("50MHz"); |
| 551 | break; |
| 552 | case SPI_FREQUENCY_500SERIES_33MHZ: |
| 553 | printf("33MHz"); |
| 554 | break; |
| 555 | case SPI_FREQUENCY_25MHZ: |
| 556 | printf("25MHz"); |
| 557 | break; |
| 558 | case SPI_FREQUENCY_14MHZ: |
| 559 | printf("14MHz"); |
| 560 | break; |
| 561 | default: |
| 562 | printf("unknown<%x>MHz", freq); |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | static void decode_spi_frequency(unsigned int freq) |
| 567 | { |
Subrata Banik | a5f4781 | 2020-09-29 11:43:01 +0530 | [diff] [blame] | 568 | if (chipset == CHIPSET_500_600_SERIES_TIGER_ALDER_POINT) |
Subrata Banik | d16ef4d | 2020-08-26 15:53:00 +0530 | [diff] [blame] | 569 | _decode_spi_frequency_500_series(freq); |
| 570 | else |
| 571 | _decode_spi_frequency(freq); |
| 572 | } |
| 573 | |
Subrata Banik | e5d3992 | 2020-08-26 16:01:42 +0530 | [diff] [blame] | 574 | static void _decode_espi_frequency(unsigned int freq) |
| 575 | { |
| 576 | switch (freq) { |
| 577 | case ESPI_FREQUENCY_20MHZ: |
| 578 | printf("20MHz"); |
| 579 | break; |
| 580 | case ESPI_FREQUENCY_24MHZ: |
| 581 | printf("24MHz"); |
| 582 | break; |
| 583 | case ESPI_FREQUENCY_30MHZ: |
| 584 | printf("30MHz"); |
| 585 | break; |
| 586 | case ESPI_FREQUENCY_48MHZ: |
| 587 | printf("48MHz"); |
| 588 | break; |
| 589 | case ESPI_FREQUENCY_60MHZ: |
| 590 | printf("60MHz"); |
| 591 | break; |
| 592 | case ESPI_FREQUENCY_17MHZ: |
| 593 | printf("17MHz"); |
| 594 | break; |
| 595 | default: |
| 596 | printf("unknown<%x>MHz", freq); |
| 597 | } |
| 598 | } |
| 599 | |
| 600 | static void _decode_espi_frequency_500_series(unsigned int freq) |
| 601 | { |
| 602 | switch (freq) { |
| 603 | case ESPI_FREQUENCY_500SERIES_20MHZ: |
| 604 | printf("20MHz"); |
| 605 | break; |
| 606 | case ESPI_FREQUENCY_500SERIES_24MHZ: |
| 607 | printf("24MHz"); |
| 608 | break; |
| 609 | case ESPI_FREQUENCY_500SERIES_25MHZ: |
| 610 | printf("25MHz"); |
| 611 | break; |
| 612 | case ESPI_FREQUENCY_500SERIES_48MHZ: |
| 613 | printf("48MHz"); |
| 614 | break; |
| 615 | case ESPI_FREQUENCY_500SERIES_60MHZ: |
| 616 | printf("60MHz"); |
| 617 | break; |
| 618 | default: |
| 619 | printf("unknown<%x>MHz", freq); |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | static void decode_espi_frequency(unsigned int freq) |
| 624 | { |
Subrata Banik | a5f4781 | 2020-09-29 11:43:01 +0530 | [diff] [blame] | 625 | if (chipset == CHIPSET_500_600_SERIES_TIGER_ALDER_POINT) |
Subrata Banik | e5d3992 | 2020-08-26 16:01:42 +0530 | [diff] [blame] | 626 | _decode_espi_frequency_500_series(freq); |
| 627 | else |
| 628 | _decode_espi_frequency(freq); |
| 629 | } |
| 630 | |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 631 | static void decode_component_density(unsigned int density) |
| 632 | { |
| 633 | switch (density) { |
| 634 | case COMPONENT_DENSITY_512KB: |
| 635 | printf("512KB"); |
| 636 | break; |
| 637 | case COMPONENT_DENSITY_1MB: |
| 638 | printf("1MB"); |
| 639 | break; |
| 640 | case COMPONENT_DENSITY_2MB: |
| 641 | printf("2MB"); |
| 642 | break; |
| 643 | case COMPONENT_DENSITY_4MB: |
| 644 | printf("4MB"); |
| 645 | break; |
| 646 | case COMPONENT_DENSITY_8MB: |
| 647 | printf("8MB"); |
| 648 | break; |
| 649 | case COMPONENT_DENSITY_16MB: |
| 650 | printf("16MB"); |
| 651 | break; |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 652 | case COMPONENT_DENSITY_32MB: |
| 653 | printf("32MB"); |
| 654 | break; |
| 655 | case COMPONENT_DENSITY_64MB: |
| 656 | printf("64MB"); |
| 657 | break; |
| 658 | case COMPONENT_DENSITY_UNUSED: |
| 659 | printf("UNUSED"); |
| 660 | break; |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 661 | default: |
| 662 | printf("unknown<%x>MB", density); |
| 663 | } |
| 664 | } |
| 665 | |
Subrata Banik | 26058dc | 2020-08-26 15:12:16 +0530 | [diff] [blame] | 666 | static int is_platform_with_pch(void) |
| 667 | { |
| 668 | if (chipset >= CHIPSET_5_SERIES_IBEX_PEAK) |
| 669 | return 1; |
| 670 | |
| 671 | return 0; |
| 672 | } |
Subrata Banik | ac1b1dd | 2020-08-26 15:29:58 +0530 | [diff] [blame] | 673 | |
| 674 | /* FLMAP0 register bit 24 onwards are reserved from SPT PCH */ |
| 675 | static int is_platform_with_100x_series_pch(void) |
| 676 | { |
| 677 | if (chipset >= CHIPSET_100_200_SERIES_SUNRISE_POINT && |
Subrata Banik | a5f4781 | 2020-09-29 11:43:01 +0530 | [diff] [blame] | 678 | chipset <= CHIPSET_500_600_SERIES_TIGER_ALDER_POINT) |
Subrata Banik | ac1b1dd | 2020-08-26 15:29:58 +0530 | [diff] [blame] | 679 | return 1; |
| 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
Subrata Banik | e5d3992 | 2020-08-26 16:01:42 +0530 | [diff] [blame] | 684 | static void dump_fcba(const fcba_t *fcba, const fpsba_t *fpsba) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 685 | { |
Subrata Banik | e5d3992 | 2020-08-26 16:01:42 +0530 | [diff] [blame] | 686 | unsigned int freq; |
| 687 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 688 | printf("\nFound Component Section\n"); |
| 689 | printf("FLCOMP 0x%08x\n", fcba->flcomp); |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 690 | printf(" Dual Output Fast Read Support: %ssupported\n", |
| 691 | (fcba->flcomp & (1 << 30))?"":"not "); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 692 | printf(" Read ID/Read Status Clock Frequency: "); |
| 693 | decode_spi_frequency((fcba->flcomp >> 27) & 7); |
| 694 | printf("\n Write/Erase Clock Frequency: "); |
| 695 | decode_spi_frequency((fcba->flcomp >> 24) & 7); |
| 696 | printf("\n Fast Read Clock Frequency: "); |
| 697 | decode_spi_frequency((fcba->flcomp >> 21) & 7); |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 698 | printf("\n Fast Read Support: %ssupported", |
| 699 | (fcba->flcomp & (1 << 20))?"":"not "); |
Subrata Banik | e5d3992 | 2020-08-26 16:01:42 +0530 | [diff] [blame] | 700 | if (is_platform_with_100x_series_pch() && |
| 701 | chipset != CHIPSET_100_200_SERIES_SUNRISE_POINT) { |
| 702 | printf("\n Read eSPI/EC Bus Frequency: "); |
Subrata Banik | a5f4781 | 2020-09-29 11:43:01 +0530 | [diff] [blame] | 703 | if (chipset == CHIPSET_500_600_SERIES_TIGER_ALDER_POINT) |
Subrata Banik | e5d3992 | 2020-08-26 16:01:42 +0530 | [diff] [blame] | 704 | freq = (fpsba->pchstrp[22] & 0x38) >> 3; |
| 705 | else |
| 706 | freq = (fcba->flcomp >> 17) & 7; |
| 707 | decode_espi_frequency(freq); |
| 708 | } else { |
| 709 | printf("\n Read Clock Frequency: "); |
| 710 | decode_spi_frequency((fcba->flcomp >> 17) & 7); |
| 711 | } |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 712 | |
| 713 | switch (ifd_version) { |
| 714 | case IFD_VERSION_1: |
| 715 | printf("\n Component 2 Density: "); |
| 716 | decode_component_density((fcba->flcomp >> 3) & 7); |
| 717 | printf("\n Component 1 Density: "); |
| 718 | decode_component_density(fcba->flcomp & 7); |
| 719 | break; |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 720 | case IFD_VERSION_1_5: |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 721 | case IFD_VERSION_2: |
| 722 | printf("\n Component 2 Density: "); |
| 723 | decode_component_density((fcba->flcomp >> 4) & 0xf); |
| 724 | printf("\n Component 1 Density: "); |
| 725 | decode_component_density(fcba->flcomp & 0xf); |
| 726 | break; |
| 727 | } |
| 728 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 729 | printf("\n"); |
| 730 | printf("FLILL 0x%08x\n", fcba->flill); |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 731 | printf(" Invalid Instruction 3: 0x%02x\n", |
| 732 | (fcba->flill >> 24) & 0xff); |
| 733 | printf(" Invalid Instruction 2: 0x%02x\n", |
| 734 | (fcba->flill >> 16) & 0xff); |
| 735 | printf(" Invalid Instruction 1: 0x%02x\n", |
| 736 | (fcba->flill >> 8) & 0xff); |
| 737 | printf(" Invalid Instruction 0: 0x%02x\n", |
| 738 | fcba->flill & 0xff); |
Subrata Banik | ac1b1dd | 2020-08-26 15:29:58 +0530 | [diff] [blame] | 739 | if (is_platform_with_100x_series_pch()) { |
| 740 | printf("FLILL1 0x%08x\n", fcba->flpb); |
| 741 | printf(" Invalid Instruction 7: 0x%02x\n", |
| 742 | (fcba->flpb >> 24) & 0xff); |
| 743 | printf(" Invalid Instruction 6: 0x%02x\n", |
| 744 | (fcba->flpb >> 16) & 0xff); |
| 745 | printf(" Invalid Instruction 5: 0x%02x\n", |
| 746 | (fcba->flpb >> 8) & 0xff); |
| 747 | printf(" Invalid Instruction 4: 0x%02x\n", |
| 748 | fcba->flpb & 0xff); |
| 749 | } else { |
| 750 | printf("FLPB 0x%08x\n", fcba->flpb); |
| 751 | printf(" Flash Partition Boundary Address: 0x%06x\n\n", |
| 752 | (fcba->flpb & 0xfff) << 12); |
| 753 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 756 | static void dump_fpsba(const fdbar_t *fdb, const fpsba_t *fpsba) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 757 | { |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 758 | unsigned int i; |
Arthur Heymans | 0424a2c | 2021-06-22 11:14:24 +0200 | [diff] [blame] | 759 | /* SoC Straps, aka PSL, aka ISL */ |
| 760 | unsigned int SS = (fdb->flmap1 >> 24) & 0xff; |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 761 | |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 762 | printf("Found PCH Strap Section\n"); |
Arthur Heymans | 0424a2c | 2021-06-22 11:14:24 +0200 | [diff] [blame] | 763 | for (i = 0; i < SS; i++) |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 764 | printf("PCHSTRP%-3u: 0x%08x\n", i, fpsba->pchstrp[i]); |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 765 | |
| 766 | if (ifd_version >= IFD_VERSION_2) { |
| 767 | printf("HAP bit is %sset\n", |
| 768 | fpsba->pchstrp[0] & (1 << 16) ? "" : "not "); |
| 769 | } else if (chipset >= CHIPSET_ICH8 |
| 770 | && chipset <= CHIPSET_ICH10) { |
| 771 | printf("ICH_MeDisable bit is %sset\n", |
| 772 | fpsba->pchstrp[0] & 1 ? "" : "not "); |
| 773 | } else { |
| 774 | printf("AltMeDisable bit is %sset\n", |
| 775 | fpsba->pchstrp[10] & (1 << 7) ? "" : "not "); |
| 776 | } |
| 777 | |
Bill XIE | 4651d45 | 2017-09-12 11:54:48 +0800 | [diff] [blame] | 778 | printf("\n"); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | static void decode_flmstr(uint32_t flmstr) |
| 782 | { |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 783 | int wr_shift, rd_shift; |
| 784 | if (ifd_version >= IFD_VERSION_2) { |
| 785 | wr_shift = FLMSTR_WR_SHIFT_V2; |
| 786 | rd_shift = FLMSTR_RD_SHIFT_V2; |
| 787 | } else { |
| 788 | wr_shift = FLMSTR_WR_SHIFT_V1; |
| 789 | rd_shift = FLMSTR_RD_SHIFT_V1; |
| 790 | } |
| 791 | |
| 792 | /* EC region access only available on v2+ */ |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 793 | if (PLATFORM_HAS_EC_REGION) |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 794 | printf(" EC Region Write Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 795 | (flmstr & (1 << (wr_shift + 8))) ? |
| 796 | "enabled" : "disabled"); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 797 | printf(" Platform Data Region Write Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 798 | (flmstr & (1 << (wr_shift + 4))) ? "enabled" : "disabled"); |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 799 | if (PLATFORM_HAS_GBE_REGION) { |
| 800 | printf(" GbE Region Write Access: %s\n", |
| 801 | (flmstr & (1 << (wr_shift + 3))) ? "enabled" : "disabled"); |
| 802 | } |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 803 | printf(" Intel ME Region Write Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 804 | (flmstr & (1 << (wr_shift + 2))) ? "enabled" : "disabled"); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 805 | printf(" Host CPU/BIOS Region Write Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 806 | (flmstr & (1 << (wr_shift + 1))) ? "enabled" : "disabled"); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 807 | printf(" Flash Descriptor Write Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 808 | (flmstr & (1 << wr_shift)) ? "enabled" : "disabled"); |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 809 | if (PLATFORM_HAS_10GBE_0_REGION) { |
| 810 | printf(" 10GbE_0 Write Access: %s\n", |
| 811 | (flmstr & (1 << (wr_shift + 11))) ? "enabled" : "disabled"); |
| 812 | } |
| 813 | if (PLATFORM_HAS_10GBE_1_REGION) { |
| 814 | printf(" 10GbE_1 Write Access: %s\n", |
| 815 | (flmstr & (1 << 4)) ? "enabled" : "disabled"); |
| 816 | } |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 817 | |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 818 | if (PLATFORM_HAS_EC_REGION) |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 819 | printf(" EC Region Read Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 820 | (flmstr & (1 << (rd_shift + 8))) ? |
| 821 | "enabled" : "disabled"); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 822 | printf(" Platform Data Region Read Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 823 | (flmstr & (1 << (rd_shift + 4))) ? "enabled" : "disabled"); |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 824 | if (PLATFORM_HAS_GBE_REGION) { |
| 825 | printf(" GbE Region Read Access: %s\n", |
| 826 | (flmstr & (1 << (rd_shift + 3))) ? "enabled" : "disabled"); |
| 827 | } |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 828 | printf(" Intel ME Region Read Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 829 | (flmstr & (1 << (rd_shift + 2))) ? "enabled" : "disabled"); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 830 | printf(" Host CPU/BIOS Region Read Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 831 | (flmstr & (1 << (rd_shift + 1))) ? "enabled" : "disabled"); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 832 | printf(" Flash Descriptor Read Access: %s\n", |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 833 | (flmstr & (1 << rd_shift)) ? "enabled" : "disabled"); |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 834 | if (PLATFORM_HAS_10GBE_0_REGION) { |
| 835 | printf(" 10GbE_0 Read Access: %s\n", |
| 836 | (flmstr & (1 << (rd_shift + 11))) ? "enabled" : "disabled"); |
| 837 | } |
| 838 | if (PLATFORM_HAS_10GBE_1_REGION) { |
| 839 | printf(" 10GbE_1 Read Access: %s\n", |
| 840 | (flmstr & (1 << 0)) ? "enabled" : "disabled"); |
| 841 | } |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 842 | |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 843 | /* Requestor ID doesn't exist for ifd 2 */ |
| 844 | if (ifd_version < IFD_VERSION_2) |
| 845 | printf(" Requester ID: 0x%04x\n\n", |
| 846 | flmstr & 0xffff); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 847 | } |
| 848 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 849 | static void dump_fmba(const fmba_t *fmba) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 850 | { |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 851 | printf("Found Master Section\n"); |
| 852 | printf("FLMSTR1: 0x%08x (Host CPU/BIOS)\n", fmba->flmstr1); |
| 853 | decode_flmstr(fmba->flmstr1); |
| 854 | printf("FLMSTR2: 0x%08x (Intel ME)\n", fmba->flmstr2); |
| 855 | decode_flmstr(fmba->flmstr2); |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 856 | if (PLATFORM_HAS_GBE_REGION) { |
| 857 | printf("FLMSTR3: 0x%08x (GbE)\n", fmba->flmstr3); |
| 858 | decode_flmstr(fmba->flmstr3); |
| 859 | if (ifd_version >= IFD_VERSION_2) { |
| 860 | printf("FLMSTR5: 0x%08x (EC)\n", fmba->flmstr5); |
| 861 | decode_flmstr(fmba->flmstr5); |
| 862 | } |
| 863 | } else { |
| 864 | printf("FLMSTR6: 0x%08x (IE)\n", fmba->flmstr6); |
| 865 | decode_flmstr(fmba->flmstr6); |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 866 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 869 | static void dump_fmsba(const fmsba_t *fmsba) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 870 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 871 | unsigned int i; |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 872 | printf("Found Processor Strap Section\n"); |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 873 | for (i = 0; i < ARRAY_SIZE(fmsba->data); i++) |
| 874 | printf("????: 0x%08x\n", fmsba->data[i]); |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 875 | |
| 876 | if (chipset >= CHIPSET_ICH8 && chipset <= CHIPSET_ICH10) { |
| 877 | printf("MCH_MeDisable bit is %sset\n", |
| 878 | fmsba->data[0] & 1 ? "" : "not "); |
| 879 | printf("MCH_AltMeDisable bit is %sset\n", |
| 880 | fmsba->data[0] & (1 << 7) ? "" : "not "); |
| 881 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 882 | } |
| 883 | |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 884 | static void dump_jid(uint32_t jid) |
| 885 | { |
Elyes HAOUAS | 99e54fe | 2020-01-30 15:08:03 +0100 | [diff] [blame] | 886 | printf(" SPI Component Vendor ID: 0x%02x\n", |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 887 | jid & 0xff); |
Elyes HAOUAS | 99e54fe | 2020-01-30 15:08:03 +0100 | [diff] [blame] | 888 | printf(" SPI Component Device ID 0: 0x%02x\n", |
Stefan Tauner | 27bb066 | 2018-08-06 00:40:15 +0200 | [diff] [blame] | 889 | (jid >> 8) & 0xff); |
Elyes HAOUAS | 99e54fe | 2020-01-30 15:08:03 +0100 | [diff] [blame] | 890 | printf(" SPI Component Device ID 1: 0x%02x\n", |
Stefan Tauner | 27bb066 | 2018-08-06 00:40:15 +0200 | [diff] [blame] | 891 | (jid >> 16) & 0xff); |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | static void dump_vscc(uint32_t vscc) |
| 895 | { |
| 896 | printf(" Lower Erase Opcode: 0x%02x\n", |
| 897 | vscc >> 24); |
| 898 | printf(" Lower Write Enable on Write Status: 0x%02x\n", |
| 899 | vscc & (1 << 20) ? 0x06 : 0x50); |
| 900 | printf(" Lower Write Status Required: %s\n", |
| 901 | vscc & (1 << 19) ? "Yes" : "No"); |
| 902 | printf(" Lower Write Granularity: %d bytes\n", |
| 903 | vscc & (1 << 18) ? 64 : 1); |
| 904 | printf(" Lower Block / Sector Erase Size: "); |
| 905 | switch ((vscc >> 16) & 0x3) { |
| 906 | case 0: |
| 907 | printf("256 Byte\n"); |
| 908 | break; |
| 909 | case 1: |
| 910 | printf("4KB\n"); |
| 911 | break; |
| 912 | case 2: |
| 913 | printf("8KB\n"); |
| 914 | break; |
| 915 | case 3: |
| 916 | printf("64KB\n"); |
| 917 | break; |
| 918 | } |
| 919 | |
| 920 | printf(" Upper Erase Opcode: 0x%02x\n", |
| 921 | (vscc >> 8) & 0xff); |
| 922 | printf(" Upper Write Enable on Write Status: 0x%02x\n", |
| 923 | vscc & (1 << 4) ? 0x06 : 0x50); |
| 924 | printf(" Upper Write Status Required: %s\n", |
| 925 | vscc & (1 << 3) ? "Yes" : "No"); |
| 926 | printf(" Upper Write Granularity: %d bytes\n", |
| 927 | vscc & (1 << 2) ? 64 : 1); |
| 928 | printf(" Upper Block / Sector Erase Size: "); |
| 929 | switch (vscc & 0x3) { |
| 930 | case 0: |
| 931 | printf("256 Byte\n"); |
| 932 | break; |
| 933 | case 1: |
| 934 | printf("4KB\n"); |
| 935 | break; |
| 936 | case 2: |
| 937 | printf("8KB\n"); |
| 938 | break; |
| 939 | case 3: |
| 940 | printf("64KB\n"); |
| 941 | break; |
| 942 | } |
| 943 | } |
| 944 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 945 | static void dump_vtba(const vtba_t *vtba, int vtl) |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 946 | { |
| 947 | int i; |
Stefan Tauner | 0d22614 | 2018-08-05 18:56:53 +0200 | [diff] [blame] | 948 | int max_len = sizeof(vtba_t)/sizeof(vscc_t); |
| 949 | int num = (vtl >> 1) < max_len ? (vtl >> 1) : max_len; |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 950 | |
| 951 | printf("ME VSCC table:\n"); |
| 952 | for (i = 0; i < num; i++) { |
| 953 | printf(" JID%d: 0x%08x\n", i, vtba->entry[i].jid); |
| 954 | dump_jid(vtba->entry[i].jid); |
| 955 | printf(" VSCC%d: 0x%08x\n", i, vtba->entry[i].vscc); |
| 956 | dump_vscc(vtba->entry[i].vscc); |
| 957 | } |
| 958 | printf("\n"); |
| 959 | } |
| 960 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 961 | static void dump_oem(const uint8_t *oem) |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 962 | { |
| 963 | int i, j; |
| 964 | printf("OEM Section:\n"); |
| 965 | for (i = 0; i < 4; i++) { |
| 966 | printf("%02x:", i << 4); |
| 967 | for (j = 0; j < 16; j++) |
| 968 | printf(" %02x", oem[(i<<4)+j]); |
| 969 | printf ("\n"); |
| 970 | } |
| 971 | printf ("\n"); |
| 972 | } |
| 973 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 974 | static void dump_fd(char *image, int size) |
| 975 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 976 | const fdbar_t *fdb = find_fd(image, size); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 977 | if (!fdb) |
| 978 | exit(EXIT_FAILURE); |
| 979 | |
Subrata Banik | 26058dc | 2020-08-26 15:12:16 +0530 | [diff] [blame] | 980 | printf("%s", is_platform_with_pch() ? "PCH" : "ICH"); |
| 981 | printf(" Revision: %s\n", ich_chipset_names[chipset]); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 982 | printf("FLMAP0: 0x%08x\n", fdb->flmap0); |
Subrata Banik | ac1b1dd | 2020-08-26 15:29:58 +0530 | [diff] [blame] | 983 | if (!is_platform_with_100x_series_pch()) |
| 984 | printf(" NR: %d\n", (fdb->flmap0 >> 24) & 7); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 985 | printf(" FRBA: 0x%x\n", ((fdb->flmap0 >> 16) & 0xff) << 4); |
| 986 | printf(" NC: %d\n", ((fdb->flmap0 >> 8) & 3) + 1); |
| 987 | printf(" FCBA: 0x%x\n", ((fdb->flmap0) & 0xff) << 4); |
| 988 | |
| 989 | printf("FLMAP1: 0x%08x\n", fdb->flmap1); |
Subrata Banik | ac1b1dd | 2020-08-26 15:29:58 +0530 | [diff] [blame] | 990 | printf(" %s: ", is_platform_with_100x_series_pch() ? "PSL" : "ISL"); |
| 991 | printf("0x%02x\n", (fdb->flmap1 >> 24) & 0xff); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 992 | printf(" FPSBA: 0x%x\n", ((fdb->flmap1 >> 16) & 0xff) << 4); |
| 993 | printf(" NM: %d\n", (fdb->flmap1 >> 8) & 3); |
| 994 | printf(" FMBA: 0x%x\n", ((fdb->flmap1) & 0xff) << 4); |
| 995 | |
Subrata Banik | ac1b1dd | 2020-08-26 15:29:58 +0530 | [diff] [blame] | 996 | if (!is_platform_with_100x_series_pch()) { |
| 997 | printf("FLMAP2: 0x%08x\n", fdb->flmap2); |
| 998 | printf(" PSL: 0x%04x\n", (fdb->flmap2 >> 8) & 0xffff); |
| 999 | printf(" FMSBA: 0x%x\n", ((fdb->flmap2) & 0xff) << 4); |
| 1000 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1001 | |
Subrata Banik | a5f4781 | 2020-09-29 11:43:01 +0530 | [diff] [blame] | 1002 | if (chipset == CHIPSET_500_600_SERIES_TIGER_ALDER_POINT) { |
Subrata Banik | bd2da5a | 2020-08-26 15:43:51 +0530 | [diff] [blame] | 1003 | printf("FLMAP3: 0x%08x\n", fdb->flmap3); |
| 1004 | printf(" Minor Revision ID: 0x%04x\n", (fdb->flmap3 >> 14) & 0x7f); |
| 1005 | printf(" Major Revision ID: 0x%04x\n", (fdb->flmap3 >> 21) & 0x7ff); |
| 1006 | } |
| 1007 | |
Stefan Tauner | 0d22614 | 2018-08-05 18:56:53 +0200 | [diff] [blame] | 1008 | char *flumap = find_flumap(image, size); |
| 1009 | uint32_t flumap1 = *(uint32_t *)flumap; |
| 1010 | printf("FLUMAP1: 0x%08x\n", flumap1); |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 1011 | printf(" Intel ME VSCC Table Length (VTL): %d\n", |
Stefan Tauner | 0d22614 | 2018-08-05 18:56:53 +0200 | [diff] [blame] | 1012 | (flumap1 >> 8) & 0xff); |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 1013 | printf(" Intel ME VSCC Table Base Address (VTBA): 0x%06x\n\n", |
Stefan Tauner | 0d22614 | 2018-08-05 18:56:53 +0200 | [diff] [blame] | 1014 | (flumap1 & 0xff) << 4); |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 1015 | dump_vtba((vtba_t *) |
Stefan Tauner | 0d22614 | 2018-08-05 18:56:53 +0200 | [diff] [blame] | 1016 | (image + ((flumap1 & 0xff) << 4)), |
| 1017 | (flumap1 >> 8) & 0xff); |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1018 | dump_oem((const uint8_t *)image + 0xf00); |
| 1019 | |
| 1020 | const frba_t *frba = find_frba(image, size); |
| 1021 | const fcba_t *fcba = find_fcba(image, size); |
| 1022 | const fpsba_t *fpsba = find_fpsba(image, size); |
| 1023 | const fmba_t *fmba = find_fmba(image, size); |
| 1024 | const fmsba_t *fmsba = find_fmsba(image, size); |
| 1025 | |
| 1026 | if (frba && fcba && fpsba && fmba && fmsba) { |
| 1027 | dump_frba(frba); |
Subrata Banik | e5d3992 | 2020-08-26 16:01:42 +0530 | [diff] [blame] | 1028 | dump_fcba(fcba, fpsba); |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1029 | dump_fpsba(fdb, fpsba); |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1030 | dump_fmba(fmba); |
| 1031 | dump_fmsba(fmsba); |
| 1032 | } else { |
| 1033 | printf("FD is corrupted!\n"); |
| 1034 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1037 | static void dump_layout(char *image, int size, const char *layout_fname) |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 1038 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1039 | const frba_t *frba = find_frba(image, size); |
| 1040 | if (!frba) |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 1041 | exit(EXIT_FAILURE); |
| 1042 | |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1043 | dump_frba_layout(frba, layout_fname); |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 1044 | } |
| 1045 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1046 | static void write_regions(char *image, int size) |
| 1047 | { |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1048 | unsigned int i; |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1049 | const frba_t *frba = find_frba(image, size); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1050 | |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1051 | if (!frba) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1052 | exit(EXIT_FAILURE); |
| 1053 | |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1054 | for (i = 0; i < max_regions; i++) { |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1055 | region_t region = get_region(frba, i); |
Stefan Reinauer | 4a17d29 | 2012-09-27 12:42:15 -0700 | [diff] [blame] | 1056 | dump_region(i, frba); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1057 | if (region.size > 0) { |
| 1058 | int region_fd; |
| 1059 | region_fd = open(region_filename(i), |
Scott Duplichan | f2c9837 | 2014-12-12 21:03:06 -0600 | [diff] [blame] | 1060 | O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1061 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
Patrick Georgi | 38fa6ed | 2014-08-03 12:18:45 +0200 | [diff] [blame] | 1062 | if (region_fd < 0) { |
| 1063 | perror("Error while trying to open file"); |
| 1064 | exit(EXIT_FAILURE); |
| 1065 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1066 | if (write(region_fd, image + region.base, region.size) != region.size) |
Stefan Reinauer | a9f670a | 2012-06-18 16:02:20 -0700 | [diff] [blame] | 1067 | perror("Error while writing"); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1068 | close(region_fd); |
| 1069 | } |
| 1070 | } |
| 1071 | } |
| 1072 | |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 1073 | static void validate_layout(char *image, int size) |
| 1074 | { |
| 1075 | uint i, errors = 0; |
| 1076 | struct fmap *fmap; |
| 1077 | long int fmap_loc = fmap_find((uint8_t *)image, size); |
| 1078 | const frba_t *frba = find_frba(image, size); |
| 1079 | |
| 1080 | if (fmap_loc < 0 || !frba) |
| 1081 | exit(EXIT_FAILURE); |
| 1082 | |
| 1083 | fmap = (struct fmap *)(image + fmap_loc); |
| 1084 | |
| 1085 | for (i = 0; i < max_regions; i++) { |
Patrick Rudolph | ef5ebdb | 2022-10-22 11:19:02 +0200 | [diff] [blame^] | 1086 | if (region_name_fmap(i) == NULL) |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 1087 | continue; |
| 1088 | |
| 1089 | region_t region = get_region(frba, i); |
| 1090 | |
| 1091 | if (region.size == 0) |
| 1092 | continue; |
| 1093 | |
| 1094 | const struct fmap_area *area = |
Patrick Rudolph | ef5ebdb | 2022-10-22 11:19:02 +0200 | [diff] [blame^] | 1095 | fmap_find_area(fmap, region_name_fmap(i)); |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 1096 | |
| 1097 | if (!area) |
| 1098 | continue; |
| 1099 | |
| 1100 | if ((uint)region.base != area->offset || |
| 1101 | (uint)region.size != area->size) { |
| 1102 | printf("Region mismatch between %s and %s\n", |
| 1103 | region_names[i].terse, area->name); |
| 1104 | printf(" Descriptor region %s:\n", region_names[i].terse); |
| 1105 | printf(" offset: 0x%08x\n", region.base); |
| 1106 | printf(" length: 0x%08x\n", region.size); |
| 1107 | printf(" FMAP area %s:\n", area->name); |
| 1108 | printf(" offset: 0x%08x\n", area->offset); |
| 1109 | printf(" length: 0x%08x\n", area->size); |
| 1110 | errors++; |
| 1111 | } |
| 1112 | } |
| 1113 | |
| 1114 | if (errors > 0) |
| 1115 | exit(EXIT_FAILURE); |
| 1116 | } |
| 1117 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1118 | static void write_image(const char *filename, char *image, int size) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1119 | { |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1120 | int new_fd; |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 1121 | printf("Writing new image to %s\n", filename); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1122 | |
| 1123 | // Now write out new image |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 1124 | new_fd = open(filename, |
Scott Duplichan | f2c9837 | 2014-12-12 21:03:06 -0600 | [diff] [blame] | 1125 | O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1126 | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); |
Patrick Georgi | 38fa6ed | 2014-08-03 12:18:45 +0200 | [diff] [blame] | 1127 | if (new_fd < 0) { |
| 1128 | perror("Error while trying to open file"); |
| 1129 | exit(EXIT_FAILURE); |
| 1130 | } |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1131 | if (write(new_fd, image, size) != size) |
Stefan Reinauer | a9f670a | 2012-06-18 16:02:20 -0700 | [diff] [blame] | 1132 | perror("Error while writing"); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1133 | close(new_fd); |
| 1134 | } |
| 1135 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1136 | static void set_spi_frequency(const char *filename, char *image, int size, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1137 | enum spi_frequency freq) |
| 1138 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1139 | fcba_t *fcba = find_fcba(image, size); |
| 1140 | if (!fcba) |
| 1141 | exit(EXIT_FAILURE); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1142 | |
| 1143 | /* clear bits 21-29 */ |
| 1144 | fcba->flcomp &= ~0x3fe00000; |
| 1145 | /* Read ID and Read Status Clock Frequency */ |
| 1146 | fcba->flcomp |= freq << 27; |
| 1147 | /* Write and Erase Clock Frequency */ |
| 1148 | fcba->flcomp |= freq << 24; |
| 1149 | /* Fast Read Clock Frequency */ |
| 1150 | fcba->flcomp |= freq << 21; |
| 1151 | |
| 1152 | write_image(filename, image, size); |
| 1153 | } |
| 1154 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1155 | static void set_em100_mode(const char *filename, char *image, int size) |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 1156 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1157 | fcba_t *fcba = find_fcba(image, size); |
| 1158 | if (!fcba) |
| 1159 | exit(EXIT_FAILURE); |
| 1160 | |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1161 | int freq; |
| 1162 | |
| 1163 | switch (ifd_version) { |
| 1164 | case IFD_VERSION_1: |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 1165 | case IFD_VERSION_1_5: |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1166 | freq = SPI_FREQUENCY_20MHZ; |
| 1167 | break; |
| 1168 | case IFD_VERSION_2: |
| 1169 | freq = SPI_FREQUENCY_17MHZ; |
| 1170 | break; |
Alexandru Gagniuc | 71a7ba2 | 2015-09-10 08:37:42 -0700 | [diff] [blame] | 1171 | default: |
| 1172 | freq = SPI_FREQUENCY_17MHZ; |
| 1173 | break; |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1174 | } |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 1175 | |
| 1176 | fcba->flcomp &= ~(1 << 30); |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1177 | set_spi_frequency(filename, image, size, freq); |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1180 | static void set_chipdensity(const char *filename, char *image, int size, |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1181 | unsigned int density) |
| 1182 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1183 | fcba_t *fcba = find_fcba(image, size); |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1184 | uint8_t mask, chip2_offset; |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1185 | if (!fcba) |
| 1186 | exit(EXIT_FAILURE); |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1187 | |
| 1188 | printf("Setting chip density to "); |
| 1189 | decode_component_density(density); |
| 1190 | printf("\n"); |
| 1191 | |
| 1192 | switch (ifd_version) { |
| 1193 | case IFD_VERSION_1: |
| 1194 | /* fail if selected density is not supported by this version */ |
| 1195 | if ( (density == COMPONENT_DENSITY_32MB) || |
| 1196 | (density == COMPONENT_DENSITY_64MB) || |
| 1197 | (density == COMPONENT_DENSITY_UNUSED) ) { |
| 1198 | printf("error: Selected density not supported in IFD version 1.\n"); |
| 1199 | exit(EXIT_FAILURE); |
| 1200 | } |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1201 | mask = 0x7; |
| 1202 | chip2_offset = 3; |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1203 | break; |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 1204 | case IFD_VERSION_1_5: |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1205 | case IFD_VERSION_2: |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1206 | mask = 0xf; |
| 1207 | chip2_offset = 4; |
| 1208 | break; |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1209 | default: |
| 1210 | printf("error: Unknown IFD version\n"); |
| 1211 | exit(EXIT_FAILURE); |
| 1212 | break; |
| 1213 | } |
| 1214 | |
| 1215 | /* clear chip density for corresponding chip */ |
| 1216 | switch (selected_chip) { |
| 1217 | case 1: |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1218 | fcba->flcomp &= ~mask; |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1219 | break; |
| 1220 | case 2: |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1221 | fcba->flcomp &= ~(mask << chip2_offset); |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1222 | break; |
| 1223 | default: /*both chips*/ |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1224 | fcba->flcomp &= ~(mask | (mask << chip2_offset)); |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1225 | break; |
| 1226 | } |
| 1227 | |
| 1228 | /* set the new density */ |
| 1229 | if (selected_chip == 1 || selected_chip == 0) |
| 1230 | fcba->flcomp |= (density); /* first chip */ |
| 1231 | if (selected_chip == 2 || selected_chip == 0) |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1232 | fcba->flcomp |= (density << chip2_offset); /* second chip */ |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1233 | |
| 1234 | write_image(filename, image, size); |
| 1235 | } |
| 1236 | |
Duncan Laurie | 7775d67 | 2019-06-06 13:39:26 -0700 | [diff] [blame] | 1237 | static int check_region(const frba_t *frba, unsigned int region_type) |
| 1238 | { |
| 1239 | region_t region; |
| 1240 | |
| 1241 | if (!frba) |
| 1242 | return 0; |
| 1243 | |
| 1244 | region = get_region(frba, region_type); |
| 1245 | return !!((region.base < region.limit) && (region.size > 0)); |
| 1246 | } |
| 1247 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1248 | static void lock_descriptor(const char *filename, char *image, int size) |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 1249 | { |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 1250 | int wr_shift, rd_shift; |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1251 | fmba_t *fmba = find_fmba(image, size); |
Duncan Laurie | 7775d67 | 2019-06-06 13:39:26 -0700 | [diff] [blame] | 1252 | const frba_t *frba = find_frba(image, size); |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1253 | if (!fmba) |
| 1254 | exit(EXIT_FAILURE); |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 1255 | |
| 1256 | if (ifd_version >= IFD_VERSION_2) { |
| 1257 | wr_shift = FLMSTR_WR_SHIFT_V2; |
| 1258 | rd_shift = FLMSTR_RD_SHIFT_V2; |
| 1259 | |
| 1260 | /* Clear non-reserved bits */ |
| 1261 | fmba->flmstr1 &= 0xff; |
| 1262 | fmba->flmstr2 &= 0xff; |
| 1263 | fmba->flmstr3 &= 0xff; |
Lijian Zhao | 9871b04 | 2019-01-26 16:48:38 -0800 | [diff] [blame] | 1264 | fmba->flmstr5 &= 0xff; |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 1265 | } else { |
| 1266 | wr_shift = FLMSTR_WR_SHIFT_V1; |
| 1267 | rd_shift = FLMSTR_RD_SHIFT_V1; |
| 1268 | |
| 1269 | fmba->flmstr1 = 0; |
| 1270 | fmba->flmstr2 = 0; |
| 1271 | /* Requestor ID */ |
| 1272 | fmba->flmstr3 = 0x118; |
| 1273 | } |
| 1274 | |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 1275 | switch (platform) { |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 1276 | case PLATFORM_APL: |
| 1277 | case PLATFORM_GLK: |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 1278 | /* CPU/BIOS can read descriptor and BIOS */ |
| 1279 | fmba->flmstr1 |= 0x3 << rd_shift; |
| 1280 | /* CPU/BIOS can write BIOS */ |
| 1281 | fmba->flmstr1 |= 0x2 << wr_shift; |
| 1282 | /* TXE can read descriptor, BIOS and Device Expansion */ |
| 1283 | fmba->flmstr2 |= 0x23 << rd_shift; |
| 1284 | /* TXE can only write Device Expansion */ |
| 1285 | fmba->flmstr2 |= 0x20 << wr_shift; |
| 1286 | break; |
Lijian Zhao | 3e88b18 | 2019-01-25 23:20:16 -0800 | [diff] [blame] | 1287 | case PLATFORM_CNL: |
| 1288 | case PLATFORM_ICL: |
Furquan Shaikh | 088b6e8 | 2018-03-21 10:42:37 -0700 | [diff] [blame] | 1289 | case PLATFORM_SKLKBL: |
Ravi Sarawadi | 7d9d63b | 2019-10-22 13:45:36 -0700 | [diff] [blame] | 1290 | case PLATFORM_TGL: |
Subrata Banik | a717e2f | 2020-07-30 11:22:53 +0530 | [diff] [blame] | 1291 | case PLATFORM_JSL: |
Lean Sheng Tan | 0faba3c | 2021-06-09 07:52:24 -0700 | [diff] [blame] | 1292 | case PLATFORM_EHL: |
Subrata Banik | 46f8073 | 2020-03-14 15:01:42 +0530 | [diff] [blame] | 1293 | case PLATFORM_ADL: |
Wonkyu Kim | 3922aa5 | 2022-02-02 15:19:05 -0800 | [diff] [blame] | 1294 | case PLATFORM_IFD2: |
Subrata Banik | ca82e61 | 2022-01-20 18:51:21 +0530 | [diff] [blame] | 1295 | case PLATFORM_MTL: |
Duncan Laurie | 7775d67 | 2019-06-06 13:39:26 -0700 | [diff] [blame] | 1296 | /* CPU/BIOS can read descriptor and BIOS. */ |
| 1297 | fmba->flmstr1 |= (1 << REGION_DESC) << rd_shift; |
| 1298 | fmba->flmstr1 |= (1 << REGION_BIOS) << rd_shift; |
| 1299 | /* CPU/BIOS can write BIOS. */ |
| 1300 | fmba->flmstr1 |= (1 << REGION_BIOS) << wr_shift; |
| 1301 | /* ME can read descriptor and ME. */ |
| 1302 | fmba->flmstr2 |= (1 << REGION_DESC) << rd_shift; |
| 1303 | fmba->flmstr2 |= (1 << REGION_ME) << rd_shift; |
Furquan Shaikh | 088b6e8 | 2018-03-21 10:42:37 -0700 | [diff] [blame] | 1304 | /* ME can write ME. */ |
Duncan Laurie | 7775d67 | 2019-06-06 13:39:26 -0700 | [diff] [blame] | 1305 | fmba->flmstr2 |= (1 << REGION_ME) << wr_shift; |
| 1306 | if (check_region(frba, REGION_GBE)) { |
| 1307 | /* BIOS can read/write GbE. */ |
| 1308 | fmba->flmstr1 |= (1 << REGION_GBE) << rd_shift; |
| 1309 | fmba->flmstr1 |= (1 << REGION_GBE) << wr_shift; |
| 1310 | /* ME can read GbE. */ |
| 1311 | fmba->flmstr2 |= (1 << REGION_GBE) << rd_shift; |
| 1312 | /* GbE can read descriptor and read/write GbE.. */ |
| 1313 | fmba->flmstr3 |= (1 << REGION_DESC) << rd_shift; |
| 1314 | fmba->flmstr3 |= (1 << REGION_GBE) << rd_shift; |
| 1315 | fmba->flmstr3 |= (1 << REGION_GBE) << wr_shift; |
| 1316 | } |
| 1317 | if (check_region(frba, REGION_PDR)) { |
| 1318 | /* BIOS can read/write PDR. */ |
| 1319 | fmba->flmstr1 |= (1 << REGION_PDR) << rd_shift; |
| 1320 | fmba->flmstr1 |= (1 << REGION_PDR) << wr_shift; |
| 1321 | } |
| 1322 | if (check_region(frba, REGION_EC)) { |
| 1323 | /* BIOS can read EC. */ |
| 1324 | fmba->flmstr1 |= (1 << REGION_EC) << rd_shift; |
| 1325 | /* EC can read descriptor and read/write EC. */ |
| 1326 | fmba->flmstr5 |= (1 << REGION_DESC) << rd_shift; |
| 1327 | fmba->flmstr5 |= (1 << REGION_EC) << rd_shift; |
| 1328 | fmba->flmstr5 |= (1 << REGION_EC) << wr_shift; |
| 1329 | } |
Furquan Shaikh | 088b6e8 | 2018-03-21 10:42:37 -0700 | [diff] [blame] | 1330 | break; |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 1331 | case PLATFORM_DNV: |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 1332 | case PLATFORM_WBG: |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 1333 | /* CPU/BIOS can read descriptor and BIOS. */ |
| 1334 | fmba->flmstr1 |= (1 << REGION_DESC) << rd_shift; |
| 1335 | fmba->flmstr1 |= (1 << REGION_BIOS) << rd_shift; |
| 1336 | /* CPU/BIOS can write BIOS. */ |
| 1337 | fmba->flmstr1 |= (1 << REGION_BIOS) << wr_shift; |
| 1338 | /* ME can read descriptor and ME. */ |
| 1339 | fmba->flmstr2 |= (1 << REGION_DESC) << rd_shift; |
| 1340 | fmba->flmstr2 |= (1 << REGION_ME) << rd_shift; |
| 1341 | /* ME can write ME. */ |
| 1342 | fmba->flmstr2 |= (1 << REGION_ME) << wr_shift; |
| 1343 | break; |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 1344 | default: |
Duncan Laurie | 7775d67 | 2019-06-06 13:39:26 -0700 | [diff] [blame] | 1345 | /* CPU/BIOS can read descriptor and BIOS. */ |
| 1346 | fmba->flmstr1 |= (1 << REGION_DESC) << rd_shift; |
| 1347 | fmba->flmstr1 |= (1 << REGION_BIOS) << rd_shift; |
| 1348 | /* CPU/BIOS can write BIOS. */ |
| 1349 | fmba->flmstr1 |= (1 << REGION_BIOS) << wr_shift; |
| 1350 | /* ME can read descriptor and ME. */ |
| 1351 | fmba->flmstr2 |= (1 << REGION_DESC) << rd_shift; |
| 1352 | fmba->flmstr2 |= (1 << REGION_ME) << rd_shift; |
| 1353 | /* ME can write ME. */ |
| 1354 | fmba->flmstr2 |= (1 << REGION_ME) << wr_shift; |
| 1355 | if (check_region(frba, REGION_GBE)) { |
| 1356 | /* BIOS can read GbE. */ |
| 1357 | fmba->flmstr1 |= (1 << REGION_GBE) << rd_shift; |
| 1358 | /* BIOS can write GbE. */ |
| 1359 | fmba->flmstr1 |= (1 << REGION_GBE) << wr_shift; |
| 1360 | /* ME can read GbE. */ |
| 1361 | fmba->flmstr2 |= (1 << REGION_GBE) << rd_shift; |
| 1362 | /* ME can write GbE. */ |
| 1363 | fmba->flmstr2 |= (1 << REGION_GBE) << wr_shift; |
| 1364 | /* GbE can write GbE. */ |
| 1365 | fmba->flmstr3 |= (1 << REGION_GBE) << rd_shift; |
| 1366 | /* GbE can read GbE. */ |
| 1367 | fmba->flmstr3 |= (1 << REGION_GBE) << wr_shift; |
| 1368 | } |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 1369 | break; |
| 1370 | } |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 1371 | |
| 1372 | write_image(filename, image, size); |
| 1373 | } |
| 1374 | |
Usha P | 412679d | 2020-10-15 11:25:08 +0530 | [diff] [blame] | 1375 | static void enable_cpu_read_me(const char *filename, char *image, int size) |
| 1376 | { |
| 1377 | int rd_shift; |
| 1378 | fmba_t *fmba = find_fmba(image, size); |
| 1379 | |
| 1380 | if (!fmba) |
| 1381 | exit(EXIT_FAILURE); |
| 1382 | |
| 1383 | if (ifd_version >= IFD_VERSION_2) |
| 1384 | rd_shift = FLMSTR_RD_SHIFT_V2; |
| 1385 | else |
| 1386 | rd_shift = FLMSTR_RD_SHIFT_V1; |
| 1387 | |
| 1388 | /* CPU/BIOS can read ME. */ |
| 1389 | fmba->flmstr1 |= (1 << REGION_ME) << rd_shift; |
| 1390 | |
| 1391 | write_image(filename, image, size); |
| 1392 | } |
| 1393 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1394 | static void unlock_descriptor(const char *filename, char *image, int size) |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 1395 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1396 | fmba_t *fmba = find_fmba(image, size); |
| 1397 | if (!fmba) |
| 1398 | exit(EXIT_FAILURE); |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 1399 | |
| 1400 | if (ifd_version >= IFD_VERSION_2) { |
| 1401 | /* Access bits for each region are read: 19:8 write: 31:20 */ |
| 1402 | fmba->flmstr1 = 0xffffff00 | (fmba->flmstr1 & 0xff); |
| 1403 | fmba->flmstr2 = 0xffffff00 | (fmba->flmstr2 & 0xff); |
| 1404 | fmba->flmstr3 = 0xffffff00 | (fmba->flmstr3 & 0xff); |
Lijian Zhao | 9871b04 | 2019-01-26 16:48:38 -0800 | [diff] [blame] | 1405 | fmba->flmstr5 = 0xffffff00 | (fmba->flmstr5 & 0xff); |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 1406 | } else { |
| 1407 | fmba->flmstr1 = 0xffff0000; |
| 1408 | fmba->flmstr2 = 0xffff0000; |
Patrick Rudolph | 8a06cc7 | 2017-01-08 09:57:47 +0100 | [diff] [blame] | 1409 | /* Keep chipset specific Requester ID */ |
| 1410 | fmba->flmstr3 = 0x08080000 | (fmba->flmstr3 & 0xffff); |
Shawn Nematbakhsh | d2cb118 | 2015-09-10 19:07:13 -0700 | [diff] [blame] | 1411 | } |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 1412 | |
| 1413 | write_image(filename, image, size); |
| 1414 | } |
| 1415 | |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1416 | static void set_pchstrap(fpsba_t *fpsba, const fdbar_t *fdb, const int strap, |
| 1417 | const unsigned int value) |
| 1418 | { |
| 1419 | if (!fpsba || !fdb) { |
| 1420 | fprintf(stderr, "Internal error\n"); |
| 1421 | exit(EXIT_FAILURE); |
| 1422 | } |
| 1423 | |
Arthur Heymans | 0424a2c | 2021-06-22 11:14:24 +0200 | [diff] [blame] | 1424 | /* SoC Strap, aka PSL, aka ISL */ |
| 1425 | int SS = (fdb->flmap1 >> 24) & 0xff; |
| 1426 | if (strap >= SS) { |
| 1427 | fprintf(stderr, "Strap index %d out of range (max: %d)\n", strap, SS); |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1428 | exit(EXIT_FAILURE); |
| 1429 | } |
| 1430 | fpsba->pchstrp[strap] = value; |
| 1431 | } |
| 1432 | |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 1433 | /* Set the AltMeDisable (or HAP for >= IFD_VERSION_2) */ |
Jacob Garber | 595d926 | 2019-06-27 17:33:10 -0600 | [diff] [blame] | 1434 | static void fpsba_set_altmedisable(fpsba_t *fpsba, fmsba_t *fmsba, bool altmedisable) |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 1435 | { |
| 1436 | if (ifd_version >= IFD_VERSION_2) { |
| 1437 | printf("%sting the HAP bit to %s Intel ME...\n", |
| 1438 | altmedisable?"Set":"Unset", |
| 1439 | altmedisable?"disable":"enable"); |
| 1440 | if (altmedisable) |
| 1441 | fpsba->pchstrp[0] |= (1 << 16); |
| 1442 | else |
| 1443 | fpsba->pchstrp[0] &= ~(1 << 16); |
| 1444 | } else { |
| 1445 | if (chipset >= CHIPSET_ICH8 && chipset <= CHIPSET_ICH10) { |
| 1446 | printf("%sting the ICH_MeDisable, MCH_MeDisable, " |
| 1447 | "and MCH_AltMeDisable to %s Intel ME...\n", |
| 1448 | altmedisable?"Set":"Unset", |
| 1449 | altmedisable?"disable":"enable"); |
| 1450 | if (altmedisable) { |
| 1451 | /* MCH_MeDisable */ |
| 1452 | fmsba->data[0] |= 1; |
| 1453 | /* MCH_AltMeDisable */ |
| 1454 | fmsba->data[0] |= (1 << 7); |
| 1455 | /* ICH_MeDisable */ |
| 1456 | fpsba->pchstrp[0] |= 1; |
| 1457 | } else { |
| 1458 | fmsba->data[0] &= ~1; |
| 1459 | fmsba->data[0] &= ~(1 << 7); |
| 1460 | fpsba->pchstrp[0] &= ~1; |
| 1461 | } |
| 1462 | } else { |
| 1463 | printf("%sting the AltMeDisable to %s Intel ME...\n", |
| 1464 | altmedisable?"Set":"Unset", |
| 1465 | altmedisable?"disable":"enable"); |
| 1466 | if (altmedisable) |
| 1467 | fpsba->pchstrp[10] |= (1 << 7); |
| 1468 | else |
| 1469 | fpsba->pchstrp[10] &= ~(1 << 7); |
| 1470 | } |
| 1471 | } |
| 1472 | } |
| 1473 | |
Jacob Garber | 595d926 | 2019-06-27 17:33:10 -0600 | [diff] [blame] | 1474 | static void inject_region(const char *filename, char *image, int size, |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1475 | unsigned int region_type, const char *region_fname) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1476 | { |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1477 | frba_t *frba = find_frba(image, size); |
| 1478 | if (!frba) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1479 | exit(EXIT_FAILURE); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 1480 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1481 | region_t region = get_region(frba, region_type); |
| 1482 | if (region.size <= 0xfff) { |
| 1483 | fprintf(stderr, "Region %s is disabled in target. Not injecting.\n", |
| 1484 | region_name(region_type)); |
| 1485 | exit(EXIT_FAILURE); |
| 1486 | } |
| 1487 | |
Scott Duplichan | f2c9837 | 2014-12-12 21:03:06 -0600 | [diff] [blame] | 1488 | int region_fd = open(region_fname, O_RDONLY | O_BINARY); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1489 | if (region_fd == -1) { |
| 1490 | perror("Could not open file"); |
| 1491 | exit(EXIT_FAILURE); |
| 1492 | } |
| 1493 | struct stat buf; |
| 1494 | if (fstat(region_fd, &buf) == -1) { |
| 1495 | perror("Could not stat file"); |
| 1496 | exit(EXIT_FAILURE); |
| 1497 | } |
| 1498 | int region_size = buf.st_size; |
| 1499 | |
| 1500 | printf("File %s is %d bytes\n", region_fname, region_size); |
| 1501 | |
| 1502 | if ( (region_size > region.size) || ((region_type != 1) && |
Vadim Bendebury | bb1177e | 2011-11-09 14:11:26 -0800 | [diff] [blame] | 1503 | (region_size > region.size))) { |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1504 | fprintf(stderr, "Region %s is %d(0x%x) bytes. File is %d(0x%x)" |
| 1505 | " bytes. Not injecting.\n", |
| 1506 | region_name(region_type), region.size, |
| 1507 | region.size, region_size, region_size); |
| 1508 | exit(EXIT_FAILURE); |
| 1509 | } |
| 1510 | |
| 1511 | int offset = 0; |
| 1512 | if ((region_type == 1) && (region_size < region.size)) { |
| 1513 | fprintf(stderr, "Region %s is %d(0x%x) bytes. File is %d(0x%x)" |
| 1514 | " bytes. Padding before injecting.\n", |
| 1515 | region_name(region_type), region.size, |
| 1516 | region.size, region_size, region_size); |
| 1517 | offset = region.size - region_size; |
| 1518 | memset(image + region.base, 0xff, offset); |
| 1519 | } |
| 1520 | |
Stefan Reinauer | 5e93b37 | 2012-09-25 13:30:48 -0700 | [diff] [blame] | 1521 | if (size < region.base + offset + region_size) { |
| 1522 | fprintf(stderr, "Output file is too small. (%d < %d)\n", |
| 1523 | size, region.base + offset + region_size); |
| 1524 | exit(EXIT_FAILURE); |
| 1525 | } |
| 1526 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1527 | if (read(region_fd, image + region.base + offset, region_size) |
| 1528 | != region_size) { |
| 1529 | perror("Could not read file"); |
| 1530 | exit(EXIT_FAILURE); |
| 1531 | } |
| 1532 | |
| 1533 | close(region_fd); |
| 1534 | |
| 1535 | printf("Adding %s as the %s section of %s\n", |
| 1536 | region_fname, region_name(region_type), filename); |
| 1537 | write_image(filename, image, size); |
| 1538 | } |
| 1539 | |
Jacob Garber | 595d926 | 2019-06-27 17:33:10 -0600 | [diff] [blame] | 1540 | static unsigned int next_pow2(unsigned int x) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1541 | { |
| 1542 | unsigned int y = 1; |
| 1543 | if (x == 0) |
| 1544 | return 0; |
| 1545 | while (y <= x) |
| 1546 | y = y << 1; |
| 1547 | |
| 1548 | return y; |
| 1549 | } |
| 1550 | |
| 1551 | /** |
| 1552 | * Determine if two memory regions overlap. |
| 1553 | * |
| 1554 | * @param r1, r2 Memory regions to compare. |
Elyes HAOUAS | a1ccaed | 2018-08-24 07:58:00 +0200 | [diff] [blame] | 1555 | * @return 0 if the two regions are separate |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1556 | * @return 1 if the two regions overlap |
| 1557 | */ |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1558 | static int regions_collide(const region_t *r1, const region_t *r2) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1559 | { |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1560 | if ((r1->size == 0) || (r2->size == 0)) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1561 | return 0; |
| 1562 | |
Nico Huber | 844eda0 | 2019-01-05 00:06:19 +0100 | [diff] [blame] | 1563 | /* r1 should be either completely below or completely above r2 */ |
| 1564 | return !(r1->limit < r2->base || r1->base > r2->limit); |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1565 | } |
| 1566 | |
Jacob Garber | 595d926 | 2019-06-27 17:33:10 -0600 | [diff] [blame] | 1567 | static void new_layout(const char *filename, char *image, int size, |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1568 | const char *layout_fname) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1569 | { |
| 1570 | FILE *romlayout; |
| 1571 | char tempstr[256]; |
| 1572 | char layout_region_name[256]; |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1573 | unsigned int i, j; |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1574 | int region_number; |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1575 | region_t current_regions[MAX_REGIONS]; |
| 1576 | region_t new_regions[MAX_REGIONS]; |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1577 | int new_extent = 0; |
| 1578 | char *new_image; |
| 1579 | |
| 1580 | /* load current descriptor map and regions */ |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1581 | frba_t *frba = find_frba(image, size); |
| 1582 | if (!frba) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1583 | exit(EXIT_FAILURE); |
| 1584 | |
Alexander Couzens | fd5c658 | 2016-10-08 00:37:24 +0200 | [diff] [blame] | 1585 | for (i = 0; i < max_regions; i++) { |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1586 | current_regions[i] = get_region(frba, i); |
| 1587 | new_regions[i] = get_region(frba, i); |
| 1588 | } |
| 1589 | |
| 1590 | /* read new layout */ |
| 1591 | romlayout = fopen(layout_fname, "r"); |
| 1592 | |
| 1593 | if (!romlayout) { |
| 1594 | perror("Could not read layout file.\n"); |
| 1595 | exit(EXIT_FAILURE); |
| 1596 | } |
| 1597 | |
| 1598 | while (!feof(romlayout)) { |
| 1599 | char *tstr1, *tstr2; |
| 1600 | |
Patrick Georgi | 802ad52 | 2014-08-09 17:12:23 +0200 | [diff] [blame] | 1601 | if (2 != fscanf(romlayout, "%255s %255s\n", tempstr, |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1602 | layout_region_name)) |
| 1603 | continue; |
| 1604 | |
| 1605 | region_number = region_num(layout_region_name); |
| 1606 | if (region_number < 0) |
| 1607 | continue; |
| 1608 | |
| 1609 | tstr1 = strtok(tempstr, ":"); |
| 1610 | tstr2 = strtok(NULL, ":"); |
| 1611 | if (!tstr1 || !tstr2) { |
| 1612 | fprintf(stderr, "Could not parse layout file.\n"); |
| 1613 | exit(EXIT_FAILURE); |
| 1614 | } |
| 1615 | new_regions[region_number].base = strtol(tstr1, |
| 1616 | (char **)NULL, 16); |
| 1617 | new_regions[region_number].limit = strtol(tstr2, |
| 1618 | (char **)NULL, 16); |
| 1619 | new_regions[region_number].size = |
| 1620 | new_regions[region_number].limit - |
| 1621 | new_regions[region_number].base + 1; |
| 1622 | |
| 1623 | if (new_regions[region_number].size < 0) |
| 1624 | new_regions[region_number].size = 0; |
| 1625 | } |
| 1626 | fclose(romlayout); |
| 1627 | |
| 1628 | /* check new layout */ |
Alexander Couzens | fd5c658 | 2016-10-08 00:37:24 +0200 | [diff] [blame] | 1629 | for (i = 0; i < max_regions; i++) { |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1630 | if (new_regions[i].size == 0) |
| 1631 | continue; |
| 1632 | |
| 1633 | if (new_regions[i].size < current_regions[i].size) { |
| 1634 | printf("DANGER: Region %s is shrinking.\n", |
| 1635 | region_name(i)); |
| 1636 | printf(" The region will be truncated to fit.\n"); |
| 1637 | printf(" This may result in an unusable image.\n"); |
| 1638 | } |
| 1639 | |
Alexander Couzens | fd5c658 | 2016-10-08 00:37:24 +0200 | [diff] [blame] | 1640 | for (j = i + 1; j < max_regions; j++) { |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1641 | if (regions_collide(&new_regions[i], &new_regions[j])) { |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1642 | fprintf(stderr, "Regions would overlap.\n"); |
| 1643 | exit(EXIT_FAILURE); |
| 1644 | } |
| 1645 | } |
| 1646 | |
| 1647 | /* detect if the image size should grow */ |
| 1648 | if (new_extent < new_regions[i].limit) |
| 1649 | new_extent = new_regions[i].limit; |
| 1650 | } |
| 1651 | |
Marcello Sylvester Bauer | 6f9a778 | 2020-02-04 17:20:50 +0100 | [diff] [blame] | 1652 | /* check if the image is actually a Flash Descriptor region */ |
| 1653 | if (size == new_regions[0].size) { |
| 1654 | printf("The image is a single Flash Descriptor:\n"); |
| 1655 | printf(" Only the descriptor will be modified\n"); |
| 1656 | new_extent = size; |
| 1657 | } else { |
| 1658 | new_extent = next_pow2(new_extent - 1); |
| 1659 | if (new_extent != size) { |
| 1660 | printf("The image has changed in size.\n"); |
| 1661 | printf("The old image is %d bytes.\n", size); |
| 1662 | printf("The new image is %d bytes.\n", new_extent); |
| 1663 | } |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | /* copy regions to a new image */ |
| 1667 | new_image = malloc(new_extent); |
| 1668 | memset(new_image, 0xff, new_extent); |
Alexander Couzens | fd5c658 | 2016-10-08 00:37:24 +0200 | [diff] [blame] | 1669 | for (i = 0; i < max_regions; i++) { |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1670 | int copy_size = new_regions[i].size; |
| 1671 | int offset_current = 0, offset_new = 0; |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1672 | const region_t *current = ¤t_regions[i]; |
| 1673 | const region_t *new = &new_regions[i]; |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1674 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1675 | if (new->size == 0) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1676 | continue; |
| 1677 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1678 | if (new->size > current->size) { |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1679 | /* copy from the end of the current region */ |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1680 | copy_size = current->size; |
Wim Vervoorn | 05bc9b3 | 2020-01-17 13:48:00 +0100 | [diff] [blame] | 1681 | if (i == REGION_BIOS) |
| 1682 | offset_new = new->size - current->size; |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1683 | } |
| 1684 | |
Wim Vervoorn | 05bc9b3 | 2020-01-17 13:48:00 +0100 | [diff] [blame] | 1685 | if ((i == REGION_BIOS) && (new->size < current->size)) { |
| 1686 | /* copy BIOS region to the end of the new region */ |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1687 | offset_current = current->size - new->size; |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1688 | } |
| 1689 | |
Marcello Sylvester Bauer | 6f9a778 | 2020-02-04 17:20:50 +0100 | [diff] [blame] | 1690 | if (size < current->base + offset_current + copy_size) { |
| 1691 | printf("Skip descriptor %d (%s) (region missing in the old image)\n", i, |
| 1692 | region_name(i)); |
| 1693 | continue; |
| 1694 | }; |
| 1695 | |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1696 | printf("Copy Descriptor %d (%s) (%d bytes)\n", i, |
| 1697 | region_name(i), copy_size); |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1698 | printf(" from %08x+%08x:%08x (%10d)\n", current->base, |
| 1699 | offset_current, current->limit, current->size); |
| 1700 | printf(" to %08x+%08x:%08x (%10d)\n", new->base, |
| 1701 | offset_new, new->limit, new->size); |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1702 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1703 | memcpy(new_image + new->base + offset_new, |
| 1704 | image + current->base + offset_current, |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1705 | copy_size); |
| 1706 | } |
| 1707 | |
| 1708 | /* update new descriptor regions */ |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1709 | frba = find_frba(new_image, new_extent); |
| 1710 | if (!frba) |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1711 | exit(EXIT_FAILURE); |
| 1712 | |
Marcello Sylvester Bauer | 6f9a778 | 2020-02-04 17:20:50 +0100 | [diff] [blame] | 1713 | printf("Modify Flash Descriptor regions\n"); |
Bill XIE | 612ec0e | 2017-08-30 16:10:27 +0800 | [diff] [blame] | 1714 | for (i = 1; i < max_regions; i++) |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1715 | set_region(frba, i, &new_regions[i]); |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1716 | |
| 1717 | write_image(filename, new_image, new_extent); |
| 1718 | free(new_image); |
| 1719 | } |
| 1720 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1721 | static void print_version(void) |
| 1722 | { |
| 1723 | printf("ifdtool v%s -- ", IFDTOOL_VERSION); |
| 1724 | printf("Copyright (C) 2011 Google Inc.\n\n"); |
| 1725 | printf |
| 1726 | ("This program is free software: you can redistribute it and/or modify\n" |
| 1727 | "it under the terms of the GNU General Public License as published by\n" |
| 1728 | "the Free Software Foundation, version 2 of the License.\n\n" |
| 1729 | "This program is distributed in the hope that it will be useful,\n" |
| 1730 | "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" |
| 1731 | "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" |
Martin Roth | eb20e60 | 2016-01-12 13:30:50 -0700 | [diff] [blame] | 1732 | "GNU General Public License for more details.\n\n"); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | static void print_usage(const char *name) |
| 1736 | { |
| 1737 | printf("usage: %s [-vhdix?] <filename>\n", name); |
| 1738 | printf("\n" |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1739 | " -d | --dump: dump intel firmware descriptor\n" |
| 1740 | " -f | --layout <filename> dump regions into a flashrom layout file\n" |
| 1741 | " -t | --validate Validate that the firmware descriptor layout matches the fmap layout\n" |
| 1742 | " -x | --extract: extract intel fd modules\n" |
| 1743 | " -i | --inject <region>:<module> inject file <module> into region <region>\n" |
| 1744 | " -n | --newlayout <filename> update regions using a flashrom layout file\n" |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 1745 | " -O | --output <filename> output filename\n" |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1746 | " -s | --spifreq <17|20|30|33|48|50> set the SPI frequency\n" |
| 1747 | " -D | --density <512|1|2|4|8|16|32|64> set chip density (512 in KByte, others in MByte)\n" |
| 1748 | " -C | --chip <0|1|2> select spi chip on which to operate\n" |
| 1749 | " can only be used once per run:\n" |
| 1750 | " 0 - both chips (default), 1 - first chip, 2 - second chip\n" |
| 1751 | " -e | --em100 set SPI frequency to 20MHz and disable\n" |
| 1752 | " Dual Output Fast Read Support\n" |
| 1753 | " -l | --lock Lock firmware descriptor and ME region\n" |
Usha P | 412679d | 2020-10-15 11:25:08 +0530 | [diff] [blame] | 1754 | " -r | --read Enable CPU/BIOS read access for ME region\n" |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1755 | " -u | --unlock Unlock firmware descriptor and ME region\n" |
Evgeny Zinoviev | 8c4c370 | 2020-02-16 20:34:26 +0300 | [diff] [blame] | 1756 | " -M | --altmedisable <0|1> Set the MeDisable and AltMeDisable (or HAP for skylake or newer platform)\n" |
| 1757 | " bits to disable ME\n" |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1758 | " -p | --platform Add platform-specific quirks\n" |
Subrata Banik | 15da174 | 2020-08-26 13:27:21 +0530 | [diff] [blame] | 1759 | " adl - Alder Lake\n" |
| 1760 | " aplk - Apollo Lake\n" |
| 1761 | " cnl - Cannon Lake\n" |
Johnny Lin | e273a02 | 2021-06-22 11:26:46 +0800 | [diff] [blame] | 1762 | " lbg - Lewisburg PCH\n" |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 1763 | " dnv - Denverton\n" |
Lean Sheng Tan | 0faba3c | 2021-06-09 07:52:24 -0700 | [diff] [blame] | 1764 | " ehl - Elkhart Lake\n" |
Subrata Banik | 15da174 | 2020-08-26 13:27:21 +0530 | [diff] [blame] | 1765 | " glk - Gemini Lake\n" |
| 1766 | " icl - Ice Lake\n" |
Wonkyu Kim | 3922aa5 | 2022-02-02 15:19:05 -0800 | [diff] [blame] | 1767 | " ifd2 - IFDv2 Platform\n" |
Subrata Banik | 15da174 | 2020-08-26 13:27:21 +0530 | [diff] [blame] | 1768 | " jsl - Jasper Lake\n" |
| 1769 | " sklkbl - Sky Lake/Kaby Lake\n" |
| 1770 | " tgl - Tiger Lake\n" |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 1771 | " wbg - Wellsburg\n" |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1772 | " -S | --setpchstrap Write a PCH strap\n" |
| 1773 | " -V | --newvalue The new value to write into PCH strap specified by -S\n" |
Arthur Heymans | 4cb888e | 2019-10-17 19:37:45 +0200 | [diff] [blame] | 1774 | " -v | --version: print the version\n" |
| 1775 | " -h | --help: print this help\n\n" |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 1776 | "<region> is one of Descriptor, BIOS, ME, GbE, Platform Data, Secondary BIOS, " |
| 1777 | "Device Exp1, EC, Device Exp2, IE, 10GbE_0, 10GbE_1, PTT\n" |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1778 | "\n"); |
| 1779 | } |
| 1780 | |
| 1781 | int main(int argc, char *argv[]) |
| 1782 | { |
| 1783 | int opt, option_index = 0; |
| 1784 | int mode_dump = 0, mode_extract = 0, mode_inject = 0, mode_spifreq = 0; |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 1785 | int mode_em100 = 0, mode_locked = 0, mode_unlocked = 0, mode_validate = 0; |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1786 | int mode_layout = 0, mode_newlayout = 0, mode_density = 0, mode_setstrap = 0; |
Usha P | 412679d | 2020-10-15 11:25:08 +0530 | [diff] [blame] | 1787 | int mode_read = 0, mode_altmedisable = 0, altmedisable = 0; |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1788 | char *region_type_string = NULL, *region_fname = NULL; |
| 1789 | const char *layout_fname = NULL; |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 1790 | char *new_filename = NULL; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1791 | int region_type = -1, inputfreq = 0; |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1792 | unsigned int value = 0; |
| 1793 | unsigned int pchstrap = 0; |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1794 | unsigned int new_density = 0; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1795 | enum spi_frequency spifreq = SPI_FREQUENCY_20MHZ; |
| 1796 | |
Bill XIE | fa5f994 | 2017-09-12 11:22:29 +0800 | [diff] [blame] | 1797 | static const struct option long_options[] = { |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1798 | {"dump", 0, NULL, 'd'}, |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 1799 | {"layout", 1, NULL, 'f'}, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1800 | {"extract", 0, NULL, 'x'}, |
| 1801 | {"inject", 1, NULL, 'i'}, |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1802 | {"newlayout", 1, NULL, 'n'}, |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 1803 | {"output", 1, NULL, 'O'}, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1804 | {"spifreq", 1, NULL, 's'}, |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1805 | {"density", 1, NULL, 'D'}, |
| 1806 | {"chip", 1, NULL, 'C'}, |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 1807 | {"altmedisable", 1, NULL, 'M'}, |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 1808 | {"em100", 0, NULL, 'e'}, |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 1809 | {"lock", 0, NULL, 'l'}, |
Usha P | 412679d | 2020-10-15 11:25:08 +0530 | [diff] [blame] | 1810 | {"read", 0, NULL, 'r'}, |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 1811 | {"unlock", 0, NULL, 'u'}, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1812 | {"version", 0, NULL, 'v'}, |
| 1813 | {"help", 0, NULL, 'h'}, |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 1814 | {"platform", 0, NULL, 'p'}, |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 1815 | {"validate", 0, NULL, 't'}, |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1816 | {"setpchstrap", 1, NULL, 'S'}, |
| 1817 | {"newvalue", 1, NULL, 'V'}, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1818 | {0, 0, 0, 0} |
| 1819 | }; |
| 1820 | |
Usha P | 412679d | 2020-10-15 11:25:08 +0530 | [diff] [blame] | 1821 | while ((opt = getopt_long(argc, argv, "S:V:df:D:C:M:xi:n:O:s:p:elruvth?", |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1822 | long_options, &option_index)) != EOF) { |
| 1823 | switch (opt) { |
| 1824 | case 'd': |
| 1825 | mode_dump = 1; |
| 1826 | break; |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 1827 | case 'S': |
| 1828 | mode_setstrap = 1; |
| 1829 | pchstrap = strtoul(optarg, NULL, 0); |
| 1830 | break; |
| 1831 | case 'V': |
| 1832 | value = strtoul(optarg, NULL, 0); |
| 1833 | break; |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 1834 | case 'f': |
| 1835 | mode_layout = 1; |
| 1836 | layout_fname = strdup(optarg); |
| 1837 | if (!layout_fname) { |
| 1838 | fprintf(stderr, "No layout file specified\n"); |
| 1839 | print_usage(argv[0]); |
| 1840 | exit(EXIT_FAILURE); |
| 1841 | } |
| 1842 | break; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1843 | case 'x': |
| 1844 | mode_extract = 1; |
| 1845 | break; |
| 1846 | case 'i': |
| 1847 | // separate type and file name |
| 1848 | region_type_string = strdup(optarg); |
| 1849 | region_fname = strchr(region_type_string, ':'); |
| 1850 | if (!region_fname) { |
| 1851 | print_usage(argv[0]); |
| 1852 | exit(EXIT_FAILURE); |
| 1853 | } |
| 1854 | region_fname[0] = '\0'; |
| 1855 | region_fname++; |
| 1856 | // Descriptor, BIOS, ME, GbE, Platform |
| 1857 | // valid type? |
| 1858 | if (!strcasecmp("Descriptor", region_type_string)) |
| 1859 | region_type = 0; |
| 1860 | else if (!strcasecmp("BIOS", region_type_string)) |
| 1861 | region_type = 1; |
| 1862 | else if (!strcasecmp("ME", region_type_string)) |
| 1863 | region_type = 2; |
| 1864 | else if (!strcasecmp("GbE", region_type_string)) |
| 1865 | region_type = 3; |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 1866 | else if (!strcasecmp("Platform Data", region_type_string)) |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1867 | region_type = 4; |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 1868 | else if (!strcasecmp("Device Exp1", region_type_string)) |
Stefan Reinauer | e4e08f2 | 2020-10-26 10:15:42 -0700 | [diff] [blame] | 1869 | region_type = 5; |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 1870 | else if (!strcasecmp("Secondary BIOS", region_type_string)) |
Stefan Reinauer | e4e08f2 | 2020-10-26 10:15:42 -0700 | [diff] [blame] | 1871 | region_type = 6; |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 1872 | else if (!strcasecmp("Reserved", region_type_string)) |
Stefan Reinauer | e4e08f2 | 2020-10-26 10:15:42 -0700 | [diff] [blame] | 1873 | region_type = 7; |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1874 | else if (!strcasecmp("EC", region_type_string)) |
| 1875 | region_type = 8; |
Jeff Daly | 3623eca | 2022-01-05 23:51:40 -0500 | [diff] [blame] | 1876 | else if (!strcasecmp("Device Exp2", region_type_string)) |
| 1877 | region_type = 9; |
| 1878 | else if (!strcasecmp("IE", region_type_string)) |
| 1879 | region_type = 10; |
| 1880 | else if (!strcasecmp("10GbE_0", region_type_string)) |
| 1881 | region_type = 11; |
| 1882 | else if (!strcasecmp("10GbE_1", region_type_string)) |
| 1883 | region_type = 12; |
| 1884 | else if (!strcasecmp("PTT", region_type_string)) |
| 1885 | region_type = 15; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1886 | if (region_type == -1) { |
| 1887 | fprintf(stderr, "No such region type: '%s'\n\n", |
| 1888 | region_type_string); |
| 1889 | print_usage(argv[0]); |
| 1890 | exit(EXIT_FAILURE); |
| 1891 | } |
| 1892 | mode_inject = 1; |
| 1893 | break; |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 1894 | case 'n': |
| 1895 | mode_newlayout = 1; |
| 1896 | layout_fname = strdup(optarg); |
| 1897 | if (!layout_fname) { |
| 1898 | fprintf(stderr, "No layout file specified\n"); |
| 1899 | print_usage(argv[0]); |
| 1900 | exit(EXIT_FAILURE); |
| 1901 | } |
| 1902 | break; |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 1903 | case 'O': |
| 1904 | new_filename = strdup(optarg); |
| 1905 | if (!new_filename) { |
| 1906 | fprintf(stderr, "No output filename specified\n"); |
| 1907 | print_usage(argv[0]); |
| 1908 | exit(EXIT_FAILURE); |
| 1909 | } |
| 1910 | break; |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 1911 | case 'D': |
| 1912 | mode_density = 1; |
| 1913 | new_density = strtoul(optarg, NULL, 0); |
| 1914 | switch (new_density) { |
| 1915 | case 512: |
| 1916 | new_density = COMPONENT_DENSITY_512KB; |
| 1917 | break; |
| 1918 | case 1: |
| 1919 | new_density = COMPONENT_DENSITY_1MB; |
| 1920 | break; |
| 1921 | case 2: |
| 1922 | new_density = COMPONENT_DENSITY_2MB; |
| 1923 | break; |
| 1924 | case 4: |
| 1925 | new_density = COMPONENT_DENSITY_4MB; |
| 1926 | break; |
| 1927 | case 8: |
| 1928 | new_density = COMPONENT_DENSITY_8MB; |
| 1929 | break; |
| 1930 | case 16: |
| 1931 | new_density = COMPONENT_DENSITY_16MB; |
| 1932 | break; |
| 1933 | case 32: |
| 1934 | new_density = COMPONENT_DENSITY_32MB; |
| 1935 | break; |
| 1936 | case 64: |
| 1937 | new_density = COMPONENT_DENSITY_64MB; |
| 1938 | break; |
| 1939 | case 0: |
| 1940 | new_density = COMPONENT_DENSITY_UNUSED; |
| 1941 | break; |
| 1942 | default: |
| 1943 | printf("error: Unknown density\n"); |
| 1944 | print_usage(argv[0]); |
| 1945 | exit(EXIT_FAILURE); |
| 1946 | } |
| 1947 | break; |
| 1948 | case 'C': |
| 1949 | selected_chip = strtol(optarg, NULL, 0); |
| 1950 | if (selected_chip > 2) { |
| 1951 | fprintf(stderr, "error: Invalid chip selection\n"); |
| 1952 | print_usage(argv[0]); |
| 1953 | exit(EXIT_FAILURE); |
| 1954 | } |
| 1955 | break; |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 1956 | case 'M': |
| 1957 | mode_altmedisable = 1; |
| 1958 | altmedisable = strtol(optarg, NULL, 0); |
| 1959 | if (altmedisable > 1) { |
| 1960 | fprintf(stderr, "error: Illegal value\n"); |
| 1961 | print_usage(argv[0]); |
| 1962 | exit(EXIT_FAILURE); |
| 1963 | } |
| 1964 | break; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1965 | case 's': |
| 1966 | // Parse the requested SPI frequency |
| 1967 | inputfreq = strtol(optarg, NULL, 0); |
| 1968 | switch (inputfreq) { |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1969 | case 17: |
| 1970 | spifreq = SPI_FREQUENCY_17MHZ; |
| 1971 | break; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1972 | case 20: |
| 1973 | spifreq = SPI_FREQUENCY_20MHZ; |
| 1974 | break; |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1975 | case 30: |
| 1976 | spifreq = SPI_FREQUENCY_50MHZ_30MHZ; |
| 1977 | break; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1978 | case 33: |
| 1979 | spifreq = SPI_FREQUENCY_33MHZ; |
| 1980 | break; |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1981 | case 48: |
| 1982 | spifreq = SPI_FREQUENCY_48MHZ; |
| 1983 | break; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1984 | case 50: |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 1985 | spifreq = SPI_FREQUENCY_50MHZ_30MHZ; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 1986 | break; |
| 1987 | default: |
| 1988 | fprintf(stderr, "Invalid SPI Frequency: %d\n", |
| 1989 | inputfreq); |
| 1990 | print_usage(argv[0]); |
| 1991 | exit(EXIT_FAILURE); |
| 1992 | } |
| 1993 | mode_spifreq = 1; |
| 1994 | break; |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 1995 | case 'e': |
| 1996 | mode_em100 = 1; |
| 1997 | break; |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 1998 | case 'l': |
| 1999 | mode_locked = 1; |
| 2000 | if (mode_unlocked == 1) { |
| 2001 | fprintf(stderr, "Locking/Unlocking FD and ME are mutually exclusive\n"); |
| 2002 | exit(EXIT_FAILURE); |
| 2003 | } |
| 2004 | break; |
Usha P | 412679d | 2020-10-15 11:25:08 +0530 | [diff] [blame] | 2005 | case 'r': |
| 2006 | mode_read = 1; |
| 2007 | break; |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 2008 | case 'u': |
| 2009 | mode_unlocked = 1; |
| 2010 | if (mode_locked == 1) { |
| 2011 | fprintf(stderr, "Locking/Unlocking FD and ME are mutually exclusive\n"); |
| 2012 | exit(EXIT_FAILURE); |
| 2013 | } |
| 2014 | break; |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 2015 | case 'p': |
| 2016 | if (!strcmp(optarg, "aplk")) { |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 2017 | platform = PLATFORM_APL; |
| 2018 | } else if (!strcmp(optarg, "cnl")) { |
| 2019 | platform = PLATFORM_CNL; |
Johnny Lin | e273a02 | 2021-06-22 11:26:46 +0800 | [diff] [blame] | 2020 | } else if (!strcmp(optarg, "lbg")) { |
| 2021 | platform = PLATFORM_LBG; |
Jeff Daly | abd4b96 | 2022-01-06 00:52:30 -0500 | [diff] [blame] | 2022 | } else if (!strcmp(optarg, "dnv")) { |
| 2023 | platform = PLATFORM_DNV; |
Lean Sheng Tan | 0faba3c | 2021-06-09 07:52:24 -0700 | [diff] [blame] | 2024 | } else if (!strcmp(optarg, "ehl")) { |
| 2025 | platform = PLATFORM_EHL; |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 2026 | } else if (!strcmp(optarg, "glk")) { |
| 2027 | platform = PLATFORM_GLK; |
Aamir Bohra | 1018be2 | 2018-06-29 15:08:50 +0530 | [diff] [blame] | 2028 | } else if (!strcmp(optarg, "icl")) { |
| 2029 | platform = PLATFORM_ICL; |
rkanabar | d64b046 | 2019-08-30 11:40:08 +0530 | [diff] [blame] | 2030 | } else if (!strcmp(optarg, "jsl")) { |
Lean Sheng Tan | 0faba3c | 2021-06-09 07:52:24 -0700 | [diff] [blame] | 2031 | platform = PLATFORM_JSL; |
Furquan Shaikh | 088b6e8 | 2018-03-21 10:42:37 -0700 | [diff] [blame] | 2032 | } else if (!strcmp(optarg, "sklkbl")) { |
| 2033 | platform = PLATFORM_SKLKBL; |
Ravi Sarawadi | 7d9d63b | 2019-10-22 13:45:36 -0700 | [diff] [blame] | 2034 | } else if (!strcmp(optarg, "tgl")) { |
| 2035 | platform = PLATFORM_TGL; |
Subrata Banik | 46f8073 | 2020-03-14 15:01:42 +0530 | [diff] [blame] | 2036 | } else if (!strcmp(optarg, "adl")) { |
| 2037 | platform = PLATFORM_ADL; |
Wonkyu Kim | 3922aa5 | 2022-02-02 15:19:05 -0800 | [diff] [blame] | 2038 | } else if (!strcmp(optarg, "ifd2")) { |
| 2039 | platform = PLATFORM_IFD2; |
Subrata Banik | ca82e61 | 2022-01-20 18:51:21 +0530 | [diff] [blame] | 2040 | } else if (!strcmp(optarg, "mtl")) { |
| 2041 | platform = PLATFORM_MTL; |
Patrick Rudolph | 1659874 | 2022-10-21 15:13:43 +0200 | [diff] [blame] | 2042 | } else if (!strcmp(optarg, "wbg")) { |
| 2043 | platform = PLATFORM_WBG; |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 2044 | } else { |
| 2045 | fprintf(stderr, "Unknown platform: %s\n", optarg); |
| 2046 | exit(EXIT_FAILURE); |
| 2047 | } |
Furquan Shaikh | c0257dd | 2018-05-02 23:29:04 -0700 | [diff] [blame] | 2048 | fprintf(stderr, "Platform is: %s\n", optarg); |
Andrey Petrov | 96ecb77 | 2016-10-31 19:31:54 -0700 | [diff] [blame] | 2049 | break; |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 2050 | case 't': |
| 2051 | mode_validate = 1; |
| 2052 | break; |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2053 | case 'v': |
| 2054 | print_version(); |
| 2055 | exit(EXIT_SUCCESS); |
| 2056 | break; |
| 2057 | case 'h': |
| 2058 | case '?': |
| 2059 | default: |
| 2060 | print_usage(argv[0]); |
| 2061 | exit(EXIT_SUCCESS); |
| 2062 | break; |
| 2063 | } |
| 2064 | } |
| 2065 | |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 2066 | if ((mode_dump + mode_layout + mode_extract + mode_inject + mode_setstrap + |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 2067 | mode_newlayout + (mode_spifreq | mode_em100 | mode_unlocked | |
Samuel Holland | dc9025c | 2019-10-14 20:28:37 -0500 | [diff] [blame] | 2068 | mode_locked) + mode_altmedisable + mode_validate) > 1) { |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 2069 | fprintf(stderr, "You may not specify more than one mode.\n\n"); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2070 | print_usage(argv[0]); |
| 2071 | exit(EXIT_FAILURE); |
| 2072 | } |
| 2073 | |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 2074 | if ((mode_dump + mode_layout + mode_extract + mode_inject + mode_setstrap + |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 2075 | mode_newlayout + mode_spifreq + mode_em100 + mode_locked + |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 2076 | mode_unlocked + mode_density + mode_altmedisable + mode_validate) == 0) { |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2077 | fprintf(stderr, "You need to specify a mode.\n\n"); |
| 2078 | print_usage(argv[0]); |
| 2079 | exit(EXIT_FAILURE); |
| 2080 | } |
| 2081 | |
| 2082 | if (optind + 1 != argc) { |
| 2083 | fprintf(stderr, "You need to specify a file.\n\n"); |
| 2084 | print_usage(argv[0]); |
| 2085 | exit(EXIT_FAILURE); |
| 2086 | } |
| 2087 | |
| 2088 | char *filename = argv[optind]; |
Scott Duplichan | f2c9837 | 2014-12-12 21:03:06 -0600 | [diff] [blame] | 2089 | int bios_fd = open(filename, O_RDONLY | O_BINARY); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2090 | if (bios_fd == -1) { |
| 2091 | perror("Could not open file"); |
| 2092 | exit(EXIT_FAILURE); |
| 2093 | } |
| 2094 | struct stat buf; |
| 2095 | if (fstat(bios_fd, &buf) == -1) { |
| 2096 | perror("Could not stat file"); |
| 2097 | exit(EXIT_FAILURE); |
| 2098 | } |
| 2099 | int size = buf.st_size; |
| 2100 | |
| 2101 | printf("File %s is %d bytes\n", filename, size); |
| 2102 | |
| 2103 | char *image = malloc(size); |
| 2104 | if (!image) { |
| 2105 | printf("Out of memory.\n"); |
| 2106 | exit(EXIT_FAILURE); |
| 2107 | } |
| 2108 | |
| 2109 | if (read(bios_fd, image, size) != size) { |
| 2110 | perror("Could not read file"); |
| 2111 | exit(EXIT_FAILURE); |
| 2112 | } |
| 2113 | |
| 2114 | close(bios_fd); |
| 2115 | |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2116 | // generate new filename |
| 2117 | if (new_filename == NULL) { |
| 2118 | new_filename = (char *) malloc((strlen(filename) + 5) * sizeof(char)); |
| 2119 | if (!new_filename) { |
| 2120 | printf("Out of memory.\n"); |
| 2121 | exit(EXIT_FAILURE); |
| 2122 | } |
| 2123 | // - 5: leave room for ".new\0" |
| 2124 | strcpy(new_filename, filename); |
| 2125 | strcat(new_filename, ".new"); |
| 2126 | } |
| 2127 | |
Duncan Laurie | 1f7fd72 | 2015-06-22 11:14:48 -0700 | [diff] [blame] | 2128 | check_ifd_version(image, size); |
| 2129 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2130 | if (mode_dump) |
| 2131 | dump_fd(image, size); |
| 2132 | |
Chris Douglass | 03ce014 | 2014-02-26 13:30:13 -0500 | [diff] [blame] | 2133 | if (mode_layout) |
| 2134 | dump_layout(image, size, layout_fname); |
| 2135 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2136 | if (mode_extract) |
| 2137 | write_regions(image, size); |
| 2138 | |
Mathew King | c7ddc99 | 2019-08-08 14:59:25 -0600 | [diff] [blame] | 2139 | if (mode_validate) |
| 2140 | validate_layout(image, size); |
| 2141 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2142 | if (mode_inject) |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2143 | inject_region(new_filename, image, size, region_type, |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2144 | region_fname); |
| 2145 | |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 2146 | if (mode_newlayout) |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2147 | new_layout(new_filename, image, size, layout_fname); |
Chris Douglass | 4eabe1e | 2014-02-27 09:25:19 -0500 | [diff] [blame] | 2148 | |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2149 | if (mode_spifreq) |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2150 | set_spi_frequency(new_filename, image, size, spifreq); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2151 | |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 2152 | if (mode_density) |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2153 | set_chipdensity(new_filename, image, size, new_density); |
Jan Tatje | fa31751 | 2016-03-11 00:52:07 +0100 | [diff] [blame] | 2154 | |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 2155 | if (mode_em100) |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2156 | set_em100_mode(new_filename, image, size); |
Stefan Reinauer | 1b1309f | 2012-05-11 15:53:43 -0700 | [diff] [blame] | 2157 | |
Alexander Couzens | d12ea11 | 2016-09-10 13:33:05 +0200 | [diff] [blame] | 2158 | if (mode_locked) |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2159 | lock_descriptor(new_filename, image, size); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 2160 | |
Usha P | 412679d | 2020-10-15 11:25:08 +0530 | [diff] [blame] | 2161 | if (mode_read) |
| 2162 | enable_cpu_read_me(new_filename, image, size); |
| 2163 | |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 2164 | if (mode_unlocked) |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2165 | unlock_descriptor(new_filename, image, size); |
Stefan Reinauer | 3c53d33 | 2012-09-26 17:33:39 -0700 | [diff] [blame] | 2166 | |
Patrick Rudolph | 802cbee | 2020-05-25 12:18:11 +0200 | [diff] [blame] | 2167 | if (mode_setstrap) { |
| 2168 | fpsba_t *fpsba = find_fpsba(image, size); |
| 2169 | const fdbar_t *fdb = find_fd(image, size); |
| 2170 | set_pchstrap(fpsba, fdb, pchstrap, value); |
| 2171 | write_image(new_filename, image, size); |
| 2172 | } |
| 2173 | |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 2174 | if (mode_altmedisable) { |
| 2175 | fpsba_t *fpsba = find_fpsba(image, size); |
| 2176 | fmsba_t *fmsba = find_fmsba(image, size); |
| 2177 | fpsba_set_altmedisable(fpsba, fmsba, altmedisable); |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2178 | write_image(new_filename, image, size); |
Bill XIE | b3e15a2 | 2017-09-07 18:34:50 +0800 | [diff] [blame] | 2179 | } |
| 2180 | |
Marcello Sylvester Bauer | dc1596c | 2020-02-11 13:31:38 +0100 | [diff] [blame] | 2181 | free(new_filename); |
Stefan Reinauer | 1c795ad1 | 2011-10-14 12:49:41 -0700 | [diff] [blame] | 2182 | free(image); |
| 2183 | |
| 2184 | return 0; |
| 2185 | } |