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