From 93f6b8a8cc7b7cd8580b0d0bc76d7b676bef739e Mon Sep 17 00:00:00 2001 From: Krystian Hebel Date: Wed, 30 Sep 2020 18:23:14 +0200 Subject: src/lib/fmap.c: use le*toh() functions where needed FMAP was developed with assumption about endianness of the target machine. This broke the parsing of the structure on big endian architectures. This patch converts the endianness of the fields where applicable. Signed-off-by: Krystian Hebel Change-Id: I8784ac29101531db757249496315f43e4008de4f Reviewed-on: https://review.coreboot.org/c/coreboot/+/55038 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/lib/fmap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/lib/fmap.c b/src/lib/fmap.c index 254d7877f6..6ff8431b04 100644 --- a/src/lib/fmap.c +++ b/src/lib/fmap.c @@ -8,6 +8,7 @@ #include #include #include +#include #include "fmap_config.h" @@ -49,7 +50,8 @@ static void report(const struct fmap *fmap) print_once(BIOS_DEBUG, "FMAP: Found \"%s\" version %d.%d at %#x.\n", fmap->name, fmap->ver_major, fmap->ver_minor, FMAP_OFFSET); print_once(BIOS_DEBUG, "FMAP: base = %#llx size = %#x #areas = %d\n", - (long long)fmap->base, fmap->size, fmap->nareas); + (long long)le64toh(fmap->base), le32toh(fmap->size), + le16toh(fmap->nareas)); fmap_print_once = 1; } @@ -188,10 +190,10 @@ int fmap_locate_area(const char *name, struct region *ar) } printk(BIOS_DEBUG, "FMAP: area %s found @ %x (%d bytes)\n", - name, area->offset, area->size); + name, le32toh(area->offset), le32toh(area->size)); - ar->offset = area->offset; - ar->size = area->size; + ar->offset = le32toh(area->offset); + ar->size = le32toh(area->size); rdev_munmap(&fmrd, area); @@ -226,8 +228,8 @@ int fmap_find_region_name(const struct region * const ar, if (area == NULL) return -1; - if ((ar->offset != area->offset) || - (ar->size != area->size)) { + if ((ar->offset != le32toh(area->offset)) || + (ar->size != le32toh(area->size))) { rdev_munmap(&fmrd, area); offset += sizeof(struct fmap_area); continue; -- cgit v1.2.3