1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-04-26 14:42:36 +02:00

fmap: Update major/minor version check

It's not valid to separately check the major and minor versions. The
proper minor check would be something like:

  if (fmap->ver_major == FMAP_VER_MAJOR &&
      fmap->ver_minor > FMAP_VER_MINOR)
    ERROR();

But this code was alleged (at introduction in [1]) to have come from
cbfstool, and cbfstool doesn't bother with a minor version check. This
check is only for finding the FMAP while searching the flash; it isn't
actually here for integrity and compatibility purpose.

Drop the MINOR version check; align with cbfstool on the MAJOR version
check; and match the cbfstool comments for is_valid_fmap(), to emphasize
the lack of precision.

[1] Commit c82900b66142 ("Add support to get layout from fmap (e.g.
    coreboot rom)")

BRANCH=none
BUG=b:288327526
TEST=libflashrom + ChromiumOS flashmap

Change-Id: I984835579d3b257a2462906f1f5091b179891bd0
Signed-off-by: Brian Norris <briannorris@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/79060
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
This commit is contained in:
Brian Norris 2023-11-14 15:18:06 -08:00 committed by Anastasia Klimchuk
parent f2a750475a
commit 7be490758e

5
fmap.c
View File

@ -47,14 +47,13 @@ static size_t fmap_size(const struct fmap *fmap)
return sizeof(*fmap) + (fmap->nareas * sizeof(struct fmap_area));
}
/* Make a best-effort assessment if the given fmap is real */
static int is_valid_fmap(const struct fmap *fmap)
{
if (memcmp(fmap, FMAP_SIGNATURE, strlen(FMAP_SIGNATURE)) != 0)
return 0;
/* strings containing the magic tend to fail here */
if (fmap->ver_major > FMAP_VER_MAJOR)
return 0;
if (fmap->ver_minor > FMAP_VER_MINOR)
if (fmap->ver_major != FMAP_VER_MAJOR)
return 0;
/* a basic consistency check: flash address space size should be larger
* than the size of the fmap data structure */