Bill XIE has uploaded this change for review. ( https://review.coreboot.org/21510
Change subject: ifdtool: redesign some structures ......................................................................
ifdtool: redesign some structures
Redesign some array-like structures as true arrays, and rewrite functions to dump them as loops.
This commit is one separated from the original I6d05418c.
Change-Id: I161c9a2ae83d26e658d67d0804e943fff95fe076 Signed-off-by: Bill XIE persmule@gmail.com --- M util/ifdtool/Makefile M util/ifdtool/ifdtool.c M util/ifdtool/ifdtool.h 3 files changed, 21 insertions(+), 120 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/10/21510/1
diff --git a/util/ifdtool/Makefile b/util/ifdtool/Makefile index 77547ef..936aa50 100644 --- a/util/ifdtool/Makefile +++ b/util/ifdtool/Makefile @@ -18,7 +18,7 @@ CC = gcc INSTALL = /usr/bin/install PREFIX = /usr/local -CFLAGS = -O2 -g -Wall -W -Werror +CFLAGS = -O2 -g -Wall -W -Werror -I../../src/commonlib/include LDFLAGS =
OBJS = ifdtool.o diff --git a/util/ifdtool/ifdtool.c b/util/ifdtool/ifdtool.c index 03b28f4..f6524c9 100644 --- a/util/ifdtool/ifdtool.c +++ b/util/ifdtool/ifdtool.c @@ -21,6 +21,7 @@ #include <fcntl.h> #include <sys/types.h> #include <sys/stat.h> +#include <commonlib/helpers.h> #include "ifdtool.h"
#ifndef O_BINARY @@ -106,7 +107,6 @@ int base_mask; int limit_mask; uint32_t flreg; - const void *v; region_t region;
if (ifd_version >= IFD_VERSION_2) @@ -116,40 +116,12 @@
limit_mask = base_mask << 16;
- switch (region_type) { - case 0: - v = &frba->flreg0; - break; - case 1: - v = &frba->flreg1; - break; - case 2: - v = &frba->flreg2; - break; - case 3: - v = &frba->flreg3; - break; - case 4: - v = &frba->flreg4; - break; - case 5: - v = &frba->flreg5; - break; - case 6: - v = &frba->flreg6; - break; - case 7: - v = &frba->flreg7; - break; - case 8: - v = &frba->flreg8; - break; - default: + if (region_type >= MAX_REGIONS) { fprintf(stderr, "Invalid region type %d.\n", region_type); exit (EXIT_FAILURE); }
- memmove(&flreg, v, sizeof(flreg)); + 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; @@ -163,31 +135,14 @@ static void set_region(frba_t *frba, unsigned int region_type, const region_t *region) { - switch (region_type) { - case 0: - frba->flreg0 = (((region->limit >> 12) & 0x7fff) << 16) - | ((region->base >> 12) & 0x7fff); - break; - case 1: - frba->flreg1 = (((region->limit >> 12) & 0x7fff) << 16) - | ((region->base >> 12) & 0x7fff); - break; - case 2: - frba->flreg2 = (((region->limit >> 12) & 0x7fff) << 16) - | ((region->base >> 12) & 0x7fff); - break; - case 3: - frba->flreg3 = (((region->limit >> 12) & 0x7fff) << 16) - | ((region->base >> 12) & 0x7fff); - break; - case 4: - frba->flreg4 = (((region->limit >> 12) & 0x7fff) << 16) - | ((region->base >> 12) & 0x7fff); - break; - default: - fprintf(stderr, "Invalid region type.\n"); + if (region_type >= MAX_REGIONS_OLD) { + fprintf(stderr, "Invalid region type %d.\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) @@ -252,27 +207,11 @@
static void dump_frba(const frba_t *frba) { + unsigned int i; printf("Found Region Section\n"); - printf("FLREG0: 0x%08x\n", frba->flreg0); - dump_region(0, frba); - printf("FLREG1: 0x%08x\n", frba->flreg1); - dump_region(1, frba); - printf("FLREG2: 0x%08x\n", frba->flreg2); - dump_region(2, frba); - printf("FLREG3: 0x%08x\n", frba->flreg3); - dump_region(3, frba); - printf("FLREG4: 0x%08x\n", frba->flreg4); - dump_region(4, frba); - - if (ifd_version >= IFD_VERSION_2) { - printf("FLREG5: 0x%08x\n", frba->flreg5); - dump_region(5, frba); - printf("FLREG6: 0x%08x\n", frba->flreg6); - dump_region(6, frba); - printf("FLREG7: 0x%08x\n", frba->flreg7); - dump_region(7, frba); - printf("FLREG8: 0x%08x\n", frba->flreg8); - dump_region(8, frba); + for (i = 0; i < max_regions; i++) { + printf("FLREG%u: 0x%08x\n", i, frba->flreg[i]); + dump_region(i, frba); } }
@@ -419,25 +358,11 @@
static void dump_fpsba(const fpsba_t *fpsba) { + unsigned int i; printf("Found PCH Strap Section\n"); - printf("PCHSTRP0: 0x%08x\n", fpsba->pchstrp0); - printf("PCHSTRP1: 0x%08x\n", fpsba->pchstrp1); - printf("PCHSTRP2: 0x%08x\n", fpsba->pchstrp2); - printf("PCHSTRP3: 0x%08x\n", fpsba->pchstrp3); - printf("PCHSTRP4: 0x%08x\n", fpsba->pchstrp4); - printf("PCHSTRP5: 0x%08x\n", fpsba->pchstrp5); - printf("PCHSTRP6: 0x%08x\n", fpsba->pchstrp6); - printf("PCHSTRP7: 0x%08x\n", fpsba->pchstrp7); - printf("PCHSTRP8: 0x%08x\n", fpsba->pchstrp8); - printf("PCHSTRP9: 0x%08x\n", fpsba->pchstrp9); - printf("PCHSTRP10: 0x%08x\n", fpsba->pchstrp10); - printf("PCHSTRP11: 0x%08x\n", fpsba->pchstrp11); - printf("PCHSTRP12: 0x%08x\n", fpsba->pchstrp12); - printf("PCHSTRP13: 0x%08x\n", fpsba->pchstrp13); - printf("PCHSTRP14: 0x%08x\n", fpsba->pchstrp14); - printf("PCHSTRP15: 0x%08x\n", fpsba->pchstrp15); - printf("PCHSTRP16: 0x%08x\n", fpsba->pchstrp16); - printf("PCHSTRP17: 0x%08x\n\n", fpsba->pchstrp17); + for (i = 0; i < ARRAY_SIZE(fpsba->pchstrp); i++) + printf("PCHSTRP%u: 0x%08x\n", i, fpsba->pchstrp[i]); + printf("\n"); }
static void decode_flmstr(uint32_t flmstr) diff --git a/util/ifdtool/ifdtool.h b/util/ifdtool/ifdtool.h index f50f6be..0cce8e4 100644 --- a/util/ifdtool/ifdtool.h +++ b/util/ifdtool/ifdtool.h @@ -60,16 +60,9 @@ // regions #define MAX_REGIONS 9 #define MAX_REGIONS_OLD 5 + typedef struct { - uint32_t flreg0; - uint32_t flreg1; - uint32_t flreg2; - uint32_t flreg3; - uint32_t flreg4; - uint32_t flreg5; - uint32_t flreg6; - uint32_t flreg7; - uint32_t flreg8; + uint32_t flreg[MAX_REGIONS]; } __attribute__((packed)) frba_t;
// component section @@ -81,24 +74,7 @@
// pch strap typedef struct { - uint32_t pchstrp0; - uint32_t pchstrp1; - uint32_t pchstrp2; - uint32_t pchstrp3; - uint32_t pchstrp4; - uint32_t pchstrp5; - uint32_t pchstrp6; - uint32_t pchstrp7; - uint32_t pchstrp8; - uint32_t pchstrp9; - uint32_t pchstrp10; - uint32_t pchstrp11; - uint32_t pchstrp12; - uint32_t pchstrp13; - uint32_t pchstrp14; - uint32_t pchstrp15; - uint32_t pchstrp16; - uint32_t pchstrp17; + uint32_t pchstrp[18]; } __attribute__((packed)) fpsba_t;
/*