From 1516420f3f91b7582fe562e71028181a0bdf3d9a Mon Sep 17 00:00:00 2001 From: Matt DeVillier Date: Mon, 19 May 2025 07:49:37 -0500 Subject: [PATCH] fmap: Skip unreadable regions when attempting to locate FMAP When using the on-chip FMAP to restrict flashrom operations to one or more regions (--fmap), flashrom must first locate the FMAP. This requires flashrom to read from multiple addresses, some of which may be located in regions which are not readable (such as the Intel ME region). In order to avoid a substantial amount of output from read_flash() when trying to locate the FMAP in these regions, set `the skip_unreadable_regions` flag before performing any reads to locate the FMAP, and restore the original flag value when finished. This resolves https://ticket.coreboot.org/issues/587 TEST=build flashrom, use cli to update COREBOOT and EC FMAP regions on an Intel Alderlake-N platform board (starlabs/starlite_adl). Change-Id: Ie78b977b4e6a5db02a25e69603f697834043ea99 Signed-off-by: Matt DeVillier Reviewed-on: https://review.coreboot.org/c/flashrom/+/87748 Tested-by: build bot (Jenkins) Reviewed-by: Anastasia Klimchuk --- fmap.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/fmap.c b/fmap.c index 50cb96900..70815984a 100644 --- a/fmap.c +++ b/fmap.c @@ -190,6 +190,7 @@ static int fmap_bsearch_rom(struct fmap **fmap_out, struct flashctx *const flash struct fmap *fmap; const unsigned int chip_size = flashctx->chip->total_size * 1024; const int sig_len = strlen(FMAP_SIGNATURE); + bool skip_unreadable_orig = flashctx->flags.skip_unreadable_regions; if (rom_offset + len > flashctx->chip->total_size * 1024) return 1; @@ -206,6 +207,13 @@ static int fmap_bsearch_rom(struct fmap **fmap_out, struct flashctx *const flash goto _free_ret; } + /* + * Ignore unreadable regions when trying to locate the FMAP, in order + * to avoid a large amount of false-error prints to stderr. Unreadable + * regions have already reported so errors here are redundant. + */ + flashctx->flags.skip_unreadable_regions = true; + /* * For efficient operation, we start with the largest stride possible * and then decrease the stride on each iteration. Also, check for a @@ -264,6 +272,9 @@ static int fmap_bsearch_rom(struct fmap **fmap_out, struct flashctx *const flash break; } + /* Restore original flag, since we're done searching */ + flashctx->flags.skip_unreadable_regions = skip_unreadable_orig; + if (!fmap_found) goto _free_ret;