From 19fcc89fe085fad2e7aba52375b4190463667fdb Mon Sep 17 00:00:00 2001 From: T Michael Turney Date: Wed, 20 Mar 2019 14:37:34 -0700 Subject: lib/fmap: Add area read/write functions Change-Id: I7669b8dc07b1aa5f00e7d8d0b1305b3de6c5949c Signed-off-by: T Michael Turney Reviewed-on: https://review.coreboot.org/c/coreboot/+/32287 Tested-by: build bot (Jenkins) Reviewed-by: Julius Werner --- src/include/fmap.h | 8 ++++++++ src/lib/fmap.c | 22 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/include/fmap.h b/src/include/fmap.h index 5834831489..ab7e5ab895 100644 --- a/src/include/fmap.h +++ b/src/include/fmap.h @@ -40,4 +40,12 @@ int fmap_locate_area(const char *name, struct region *r); * Return 0 on success, < 0 on error. */ int fmap_find_region_name(const struct region * const ar, char name[FMAP_STRLEN]); + +/* Read fmap area into provided buffer. + * Return size read on success, < 0 on error. */ +ssize_t fmap_read_area(const char *name, void *buffer, size_t size); + +/* Write provided buffer into fmap area. + * Return size written on success, < 0 on error. */ +ssize_t fmap_overwrite_area(const char *name, const void *buffer, size_t size); #endif diff --git a/src/lib/fmap.c b/src/lib/fmap.c index 9602134d94..2b4e3bae2c 100644 --- a/src/lib/fmap.c +++ b/src/lib/fmap.c @@ -173,3 +173,25 @@ int fmap_find_region_name(const struct region * const ar, return -1; } + +ssize_t fmap_read_area(const char *name, void *buffer, size_t size) +{ + struct region_device rdev; + if (fmap_locate_area_as_rdev(name, &rdev)) + return -1; + return rdev_readat(&rdev, buffer, 0, + MIN(size, region_device_sz(&rdev))); +} + +ssize_t fmap_overwrite_area(const char *name, const void *buffer, size_t size) +{ + struct region_device rdev; + + if (fmap_locate_area_as_rdev_rw(name, &rdev)) + return -1; + if (size > region_device_sz(&rdev)) + return -1; + if (rdev_eraseat(&rdev, 0, region_device_sz(&rdev)) < 0) + return -1; + return rdev_writeat(&rdev, buffer, 0, size); +} -- cgit v1.2.3