Attention is currently required from: Stefan Reinauer.
Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/68696 )
Change subject: ifdtool: Hardcode supported regions for every chipset ......................................................................
ifdtool: Hardcode supported regions for every chipset
Hardcode the supported regions for every chipset. This allows to decide if a region is reserved and it allows to get the maximum number of regions per chipset.
Update max_regions using the introduced array to prevent corruption of IFDs that have less than 16 regions.
Change-Id: Ie9757999cb2ab4b16a5352baacdc11c61164dd46 Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M util/ifdtool/ifdtool.c M util/ifdtool/ifdtool.h M util/ifdtool/regions.c 3 files changed, 70 insertions(+), 7 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/68696/1
diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c index 69d738f..d00e609 100644 --- a/util/ifdtool/ifdtool.c +++ b/util/ifdtool/ifdtool.c @@ -275,15 +275,11 @@ if (is_platform_ifd_2()) { ifd_version = IFD_VERSION_2; chipset = ifd2_platform_to_chipset(platform); - if (chipset == CHIPSET_8_SERIES_WELLSBURG) - max_regions = MAX_REGIONS_WBG; - else - max_regions = MAX_REGIONS; } else { ifd_version = IFD_VERSION_1; chipset = ifd1_guess_chipset(image, size); - max_regions = MAX_REGIONS_OLD; } + max_regions = max_regions_per_chipset(chipset); }
static void dump_frba(const frba_t *frba) diff --git a/util/ifdtool/ifdtool.h b/util/ifdtool/ifdtool.h index 700609b..53f46dc 100644 --- a/util/ifdtool/ifdtool.h +++ b/util/ifdtool/ifdtool.h @@ -117,7 +117,6 @@
// regions #define MAX_REGIONS 16 -#define MAX_REGIONS_WBG 6 #define MAX_REGIONS_OLD 5
enum flash_regions { @@ -212,4 +211,5 @@ const char *region_filename(unsigned int region_type); void dump_region(unsigned int num, const frba_t *frba); void dump_region_layout(char *buf, size_t bufsize, unsigned int num, - const frba_t *frba); \ No newline at end of file + const frba_t *frba); +int max_regions_per_chipset(const enum ich_chipset chip); \ No newline at end of file diff --git a/util/ifdtool/regions.c b/util/ifdtool/regions.c index 8a22eb0..09c9dbe 100644 --- a/util/ifdtool/regions.c +++ b/util/ifdtool/regions.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <commonlib/helpers.h> #include "ifdtool.h"
extern int ifd_version; @@ -28,6 +29,39 @@ { "PTT", "ptt", "flashregion_15_ptt.bin", "SI_PTT" }, };
+/* Bitmask of supported regions per chipset. + * + * Reserved regions are cleared, supported have set the bit. + * The MSB gives the maximum supported region count. + */ +static const uint32_t region_support_by_chipset[] = { // Document Id + [CHIPSET_ICH_UNKNOWN] = 0x1f, + [CHIPSET_ICH7] = 0x1f, + [CHIPSET_ICH8] = 0x1f, + [CHIPSET_ICH9] = 0x1f, + [CHIPSET_ICH10] = 0x1f, + [CHIPSET_PCH_UNKNOWN] = 0x1f, + [CHIPSET_5_SERIES_IBEX_PEAK] = 0x1f, // 403598 + [CHIPSET_6_SERIES_COUGAR_POINT] = 0x1f, + [CHIPSET_7_SERIES_PANTHER_POINT] = 0x1f, // 475653 + [CHIPSET_8_SERIES_LYNX_POINT] = 0x1f, // 489495 + [CHIPSET_BAYTRAIL] = 0x1f, + [CHIPSET_8_SERIES_LYNX_POINT_LP] = 0x1f, + [CHIPSET_8_SERIES_WELLSBURG] = 0x3f, // 516552 + [CHIPSET_9_SERIES_WILDCAT_POINT] = 0x1f, + [CHIPSET_9_SERIES_WILDCAT_POINT_LP] = 0x1f, + [CHIPSET_N_J_SERIES_APOLLO_LAKE] = 0x37, // 559702 + [CHIPSET_N_J_SERIES_GEMINI_LAKE] = 0x11f, // 571036 + [CHIPSET_N_SERIES_JASPER_LAKE] = 0x3f, + [CHIPSET_x6000_SERIES_ELKHART_LAKE] = 0x3f, + [CHIPSET_100_200_SERIES_SUNRISE_POINT] = 0x11f, // 550696 + [CHIPSET_300_SERIES_CANNON_POINT] = 0x3f, + [CHIPSET_400_SERIES_ICE_POINT] = 0x3f, + [CHIPSET_500_600_SERIES_TIGER_ALDER_POINT] = 0x11f, + [CHIPSET_C620_SERIES_LEWISBURG] = 0x9f7f, // 559021 + [CHIPSET_DENVERTON] = 0x1c17, // 559462 +}; + region_t get_region(const frba_t *frba, unsigned int region_type) { int base_mask; @@ -139,4 +173,20 @@ region_t region = get_region(frba, num); snprintf(buf, bufsize, "%08x:%08x %s\n", region.base, region.limit, region_name_short(num)); +} + +int max_regions_per_chipset(const enum ich_chipset chip) +{ + int num = MAX_REGIONS; + if (chip >= ARRAY_SIZE(region_support_by_chipset)) { + fprintf(stderr, "Unknown chipset: %d\n", chip); + return num; + } + + do { + if (region_support_by_chipset[chip] & (1 << num)) + break; + } while (num--); + + return num + 1; } \ No newline at end of file