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