Attention is currently required from: Stefan Reinauer.
Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/68695 )
Change subject: ifdtool: Move regions to seperate file ......................................................................
ifdtool: Move regions to seperate file
Change-Id: I6a1ba1799c69881b1f48d903b8f86e7cd93815c2 Signed-off-by: Patrick Rudolph patrick.rudolph@9elements.com --- M util/ifdtool/Makefile.inc M util/ifdtool/ifdtool.c M util/ifdtool/ifdtool.h A util/ifdtool/regions.c 4 files changed, 169 insertions(+), 137 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/95/68695/1
diff --git a/util/ifdtool/Makefile.inc b/util/ifdtool/Makefile.inc index eb3a700..9bc8cc2 100644 --- a/util/ifdtool/Makefile.inc +++ b/util/ifdtool/Makefile.inc @@ -1,6 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause
-ifdtoolobj = ifdtool.o fmap.o kv_pair.o valstr.o +ifdtoolobj = ifdtool.o regions.o fmap.o kv_pair.o valstr.o
IFDTOOLCFLAGS = -O2 -g -Wall -Wextra -Wmissing-prototypes -Werror IFDTOOLCFLAGS += -I$(top)/src/commonlib/include -I$(top)/src/commonlib/bsd/include diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c index 3d57e02..69d738f 100644 --- a/util/ifdtool/ifdtool.c +++ b/util/ifdtool/ifdtool.c @@ -44,31 +44,12 @@ #define PLATFORM_HAS_10GBE_0_REGION (platform == PLATFORM_DNV) #define PLATFORM_HAS_10GBE_1_REGION (platform == PLATFORM_DNV)
-static int ifd_version; +int ifd_version; static int chipset; -static unsigned int max_regions = 0; +extern unsigned int max_regions; static int selected_chip = 0; static int platform = -1;
-static const struct region_name region_names[MAX_REGIONS] = { - { "Flash Descriptor", "fd", "flashregion_0_flashdescriptor.bin", "SI_DESC" }, - { "BIOS", "bios", "flashregion_1_bios.bin", "SI_BIOS" }, - { "Intel ME", "me", "flashregion_2_intel_me.bin", "SI_ME" }, - { "GbE", "gbe", "flashregion_3_gbe.bin", "SI_GBE" }, - { "Platform Data", "pd", "flashregion_4_platform_data.bin", "SI_PDR" }, - { "Device Exp1", "devexp", "flashregion_5_device_exp.bin", "SI_DEVICEEXT" }, - { "Secondary BIOS", "bios2", "flashregion_6_bios2.bin", "SI_BIOS2" }, - { "Reserved", "res7", "flashregion_7_reserved.bin", NULL }, - { "EC", "ec", "flashregion_8_ec.bin", "SI_EC" }, - { "Device Exp2", "devexp2", "flashregion_9_device_exp.bin", "SI_DEVICEEXT2" }, - { "IE", "ie", "flashregion_10_ie.bin", "SI_IE" }, - { "10GbE_0", "10gbe_0", "flashregion_11_10gbe0.bin", "SI_10GBE0" }, - { "10GbE_1", "10gbe_1", "flashregion_12_10gbe1.bin", "SI_10GBE1" }, - { "Reserved", "res13", "flashregion_13_reserved.bin", NULL }, - { "Reserved", "res14", "flashregion_14_reserved.bin", NULL }, - { "PTT", "ptt", "flashregion_15_ptt.bin", "SI_PTT" }, -}; - /* port from flashrom */ static const char *const ich_chipset_names[] = { "Unknown ICH", @@ -305,119 +286,6 @@ } }
-static region_t get_region(const frba_t *frba, unsigned int region_type) -{ - int base_mask; - int limit_mask; - uint32_t flreg; - region_t region; - - if (ifd_version >= IFD_VERSION_2) - base_mask = 0x7fff; - else - base_mask = 0xfff; - - limit_mask = base_mask << 16; - - if (region_type >= max_regions) { - fprintf(stderr, "Invalid region type %d.\n", region_type); - exit (EXIT_FAILURE); - } - - flreg = frba->flreg[region_type]; - region.base = (flreg & base_mask) << 12; - region.limit = ((flreg & limit_mask) >> 4) | 0xfff; - region.size = region.limit - region.base + 1; - - if (region.size < 0) - region.size = 0; - - return region; -} - -static void set_region(frba_t *frba, unsigned int region_type, - const region_t *region) -{ - if (region_type >= max_regions) { - fprintf(stderr, "Invalid region type %u.\n", region_type); - exit (EXIT_FAILURE); - } - - frba->flreg[region_type] = - (((region->limit >> 12) & 0x7fff) << 16) | - ((region->base >> 12) & 0x7fff); -} - -static const char *region_name(unsigned int region_type) -{ - if (region_type >= max_regions) { - fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); - } - - return region_names[region_type].pretty; -} - -static const char *region_name_fmap(unsigned int region_type) -{ - if (region_type >= max_regions) { - fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); - } - - return region_names[region_type].fmapname; -} - -static const char *region_name_short(unsigned int region_type) -{ - if (region_type >= max_regions) { - fprintf(stderr, "Invalid region type.\n"); - exit (EXIT_FAILURE); - } - - return region_names[region_type].terse; -} - -static int region_num(const char *name) -{ - unsigned int i; - - for (i = 0; i < max_regions; i++) { - if (strcasecmp(name, region_names[i].pretty) == 0) - return i; - if (strcasecmp(name, region_names[i].terse) == 0) - return i; - } - - return -1; -} - -static const char *region_filename(unsigned int region_type) -{ - if (region_type >= max_regions) { - fprintf(stderr, "Invalid region type %d.\n", region_type); - exit (EXIT_FAILURE); - } - - return region_names[region_type].filename; -} - -static void dump_region(unsigned int num, const frba_t *frba) -{ - region_t region = get_region(frba, num); - printf(" Flash Region %d (%s): %08x - %08x %s\n", - num, region_name(num), region.base, region.limit, - region.size < 1 ? "(unused)" : ""); -} - -static void dump_region_layout(char *buf, size_t bufsize, unsigned int num, - const frba_t *frba) -{ - region_t region = get_region(frba, num); - snprintf(buf, bufsize, "%08x:%08x %s\n", - region.base, region.limit, region_name_short(num)); -} - static void dump_frba(const frba_t *frba) { unsigned int i; @@ -1052,8 +920,8 @@ if ((uint)region.base != area->offset || (uint)region.size != area->size) { printf("Region mismatch between %s and %s\n", - region_names[i].terse, area->name); - printf(" Descriptor region %s:\n", region_names[i].terse); + region_name_short(i), area->name); + printf(" Descriptor region %s:\n", region_name_short(i)); printf(" offset: 0x%08x\n", region.base); printf(" length: 0x%08x\n", region.size); printf(" FMAP area %s:\n", area->name); diff --git a/util/ifdtool/ifdtool.h b/util/ifdtool/ifdtool.h index 0a3444f..700609b 100644 --- a/util/ifdtool/ifdtool.h +++ b/util/ifdtool/ifdtool.h @@ -201,3 +201,15 @@ const char *filename; const char *fmapname; }; + +region_t get_region(const frba_t *frba, unsigned int region_type); +void set_region(frba_t *frba, unsigned int region_type, + const region_t *region); +const char *region_name(unsigned int region_type); +const char *region_name_short(unsigned int region_type); +const char *region_name_fmap(unsigned int region_type); +int region_num(const char *name); +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 diff --git a/util/ifdtool/regions.c b/util/ifdtool/regions.c new file mode 100644 index 0000000..8a22eb0 --- /dev/null +++ b/util/ifdtool/regions.c @@ -0,0 +1,142 @@ +/* ifdtool - dump Intel Firmware Descriptor information */ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "ifdtool.h" + +extern int ifd_version; +unsigned int max_regions = 0; + +static const struct region_name region_names[MAX_REGIONS] = { + { "Flash Descriptor", "fd", "flashregion_0_flashdescriptor.bin", "SI_DESC" }, + { "BIOS", "bios", "flashregion_1_bios.bin", "SI_BIOS" }, + { "Intel ME", "me", "flashregion_2_intel_me.bin", "SI_ME" }, + { "GbE", "gbe", "flashregion_3_gbe.bin", "SI_GBE" }, + { "Platform Data", "pd", "flashregion_4_platform_data.bin", "SI_PDR" }, + { "Device Exp1", "devexp", "flashregion_5_device_exp.bin", "SI_DEVICEEXT" }, + { "Secondary BIOS", "bios2", "flashregion_6_bios2.bin", "SI_BIOS2" }, + { "Reserved", "res7", "flashregion_7_reserved.bin", NULL }, + { "EC", "ec", "flashregion_8_ec.bin", "SI_EC" }, + { "Device Exp2", "devexp2", "flashregion_9_device_exp.bin", "SI_DEVICEEXT2" }, + { "IE", "ie", "flashregion_10_ie.bin", "SI_IE" }, + { "10GbE_0", "10gbe_0", "flashregion_11_10gbe0.bin", "SI_10GBE0" }, + { "10GbE_1", "10gbe_1", "flashregion_12_10gbe1.bin", "SI_10GBE1" }, + { "Reserved", "res13", "flashregion_13_reserved.bin", NULL }, + { "Reserved", "res14", "flashregion_14_reserved.bin", NULL }, + { "PTT", "ptt", "flashregion_15_ptt.bin", "SI_PTT" }, +}; + +region_t get_region(const frba_t *frba, unsigned int region_type) +{ + int base_mask; + int limit_mask; + uint32_t flreg; + region_t region; + + if (ifd_version >= IFD_VERSION_2) + base_mask = 0x7fff; + else + base_mask = 0xfff; + + limit_mask = base_mask << 16; + + if (region_type >= max_regions) { + fprintf(stderr, "Invalid region type %d.\n", region_type); + exit (EXIT_FAILURE); + } + + flreg = frba->flreg[region_type]; + region.base = (flreg & base_mask) << 12; + region.limit = ((flreg & limit_mask) >> 4) | 0xfff; + region.size = region.limit - region.base + 1; + + if (region.size < 0) + region.size = 0; + + return region; +} + +void set_region(frba_t *frba, unsigned int region_type, + const region_t *region) +{ + if (region_type >= max_regions) { + fprintf(stderr, "Invalid region type %u.\n", region_type); + exit (EXIT_FAILURE); + } + + frba->flreg[region_type] = + (((region->limit >> 12) & 0x7fff) << 16) | + ((region->base >> 12) & 0x7fff); +} + +const char *region_name(unsigned int region_type) +{ + if (region_type >= max_regions) { + fprintf(stderr, "Invalid region type.\n"); + exit (EXIT_FAILURE); + } + + return region_names[region_type].pretty; +} + +const char *region_name_short(unsigned int region_type) +{ + if (region_type >= max_regions) { + fprintf(stderr, "Invalid region type.\n"); + exit (EXIT_FAILURE); + } + + return region_names[region_type].terse; +} + +const char *region_name_fmap(unsigned int region_type) +{ + if (region_type >= max_regions) { + fprintf(stderr, "Invalid region type.\n"); + exit (EXIT_FAILURE); + } + + return region_names[region_type].fmapname; +} + +int region_num(const char *name) +{ + unsigned int i; + + for (i = 0; i < max_regions; i++) { + if (strcasecmp(name, region_names[i].pretty) == 0) + return i; + if (strcasecmp(name, region_names[i].terse) == 0) + return i; + } + + return -1; +} + +const char *region_filename(unsigned int region_type) +{ + if (region_type >= max_regions) { + fprintf(stderr, "Invalid region type %d.\n", region_type); + exit (EXIT_FAILURE); + } + + return region_names[region_type].filename; +} + +void dump_region(unsigned int num, const frba_t *frba) +{ + region_t region = get_region(frba, num); + printf(" Flash Region %d (%s): %08x - %08x %s\n", + num, region_name(num), region.base, region.limit, + region.size < 1 ? "(unused)" : ""); +} + +void dump_region_layout(char *buf, size_t bufsize, unsigned int num, + const frba_t *frba) +{ + region_t region = get_region(frba, num); + snprintf(buf, bufsize, "%08x:%08x %s\n", + region.base, region.limit, region_name_short(num)); +} \ No newline at end of file