Stefan Reinauer has uploaded this change for review. ( https://review.coreboot.org/c/flashrom/+/75646?usp=email )
Change subject: Replace all flashchips accesses with get functions ......................................................................
Replace all flashchips accesses with get functions
Abstract access to struct flashchip flashchips[].
Change-Id: Ibc89e32c83975e01c958b8cf0d11dad73c461a53 Signed-off-by: Stefan Reinauer stefan.reinauer@coreboot.org --- M cli_classic.c M flashchips.c M flashrom.c M ichspi.c M include/flash.h M libflashrom.c M print.c 7 files changed, 37 insertions(+), 4 deletions(-)
git pull ssh://review.coreboot.org:29418/flashrom refs/changes/46/75646/1
diff --git a/cli_classic.c b/cli_classic.c index 60f3fd5..7367825 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -917,6 +917,8 @@ print_version(); print_banner();
+ struct flashchip *flashchips = get_flashchips(); + /* FIXME: Delay calibration should happen in programmer code. */ if (flashrom_init(1)) exit(1); diff --git a/flashchips.c b/flashchips.c index ccc1e8c..418f4b9 100644 --- a/flashchips.c +++ b/flashchips.c @@ -31,7 +31,7 @@ * The usual intention is that that this list is sorted by vendor, then chip * family and chip density, which is useful for the output of 'flashrom -L'. */ -const struct flashchip flashchips[] = { +static const struct flashchip internal_flashchips[] = {
/* * .vendor = Vendor name @@ -20838,4 +20838,15 @@ {0} };
-const unsigned int flashchips_size = ARRAY_SIZE(flashchips); +static const unsigned int internal_flashchips_size = ARRAY_SIZE(internal_flashchips); + + +struct flashchip *get_flashchips(void) +{ + return (struct flashchip *)&internal_flashchips; +} + +unsigned int get_flashchips_size(void) +{ + return (unsigned int)internal_flashchips_size; +} diff --git a/flashrom.c b/flashrom.c index b6e5cf8..8c79fdb 100644 --- a/flashrom.c +++ b/flashrom.c @@ -1094,6 +1094,10 @@ enum chipbustype buses_common; char *tmp;
+ struct flashchip *flashchips = get_flashchips(); + if (!flashchips) + return -1; + for (chip = flashchips + startchip; chip && chip->name; chip++) { if (chip_to_probe && strcmp(chip->name, chip_to_probe) != 0) continue; @@ -1885,6 +1889,9 @@ unsigned int i; int ret = 0;
+ struct flashchip *flashchips = get_flashchips(); + unsigned int flashchips_size = get_flashchips_size(); + for (i = 0; i < programmer_table_size; i++) { const struct programmer_entry *const p = programmer_table[i]; if (p == NULL) { diff --git a/ichspi.c b/ichspi.c index e9668ef..50a1121 100644 --- a/ichspi.c +++ b/ichspi.c @@ -1468,6 +1468,11 @@ { const struct flashchip *chip;
+ struct flashchip *flashchips=get_flashchips(); + + if (!flashchips) + return NULL; + for (chip = &flashchips[0]; chip->vendor; chip++) { if ((chip->manufacture_id == mfg_id) && (chip->model_id == model_id) && diff --git a/include/flash.h b/include/flash.h index 0eace15..507bd72 100644 --- a/include/flash.h +++ b/include/flash.h @@ -569,8 +569,8 @@ #define TIMING_IGNORED -1 #define TIMING_ZERO -2
-extern const struct flashchip flashchips[]; -extern const unsigned int flashchips_size; +struct flashchip *get_flashchips(void); +unsigned int get_flashchips_size(void);
/* parallel.c */ void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr); diff --git a/libflashrom.c b/libflashrom.c index 4a59e2a..1dd4f85 100644 --- a/libflashrom.c +++ b/libflashrom.c @@ -91,6 +91,12 @@
struct flashrom_flashchip_info *flashrom_supported_flash_chips(void) { + struct flashchip *flashchips = get_flashchips(); + unsigned int flashchips_size = get_flashchips_size(); + + if (!flashchips) + return NULL; + struct flashrom_flashchip_info *supported_flashchips = malloc(flashchips_size * sizeof(*supported_flashchips));
diff --git a/print.c b/print.c index 0caa0da..93d5242 100644 --- a/print.c +++ b/print.c @@ -59,6 +59,8 @@ char *tmpven, *tmpdev, *tmpven_save, *tmpdev_save; int tmpvenlen, tmpdevlen, curvenlen, curdevlen;
+ struct flashchip *flashchips = get_flashchips(); + /* calculate maximum column widths and by iterating over all chips */ for (chip = flashchips; chip->name != NULL; chip++) { /* Ignore generic entries. */