Jakub Czapiga has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/59492 )
Change subject: libpayload: Add libpayload_boot_device_read function ......................................................................
libpayload: Add libpayload_boot_device_read function
This patch adds a new way of implementing flash access for libpayload. Until now all reads had to be performed using cbfs_media, which is obsolete. From now on all reads should be performed using libpayload_boot_device_read(). This patch also provides a fallback implementation of this function using cbfs_media, but it will be removed in the future together with cbfs_media API.
Change-Id: I1babd2a8414ed9de3ca49903fcb4f036997b5ff3 Signed-off-by: Jakub Czapiga jacz@semihalf.com --- A payloads/libpayload/include/boot_device.h M payloads/libpayload/include/libpayload.h M payloads/libpayload/libc/Makefile.inc A payloads/libpayload/libc/boot_device.c 4 files changed, 46 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/92/59492/1
diff --git a/payloads/libpayload/include/boot_device.h b/payloads/libpayload/include/boot_device.h new file mode 100644 index 0000000..c2cf105 --- /dev/null +++ b/payloads/libpayload/include/boot_device.h @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-Clause OR GPS-2.0-or-later */ + +#ifndef _BOOT_DEVICE_H +#define _BOOT_DEVICE_H + +#include <stddef.h> + +/** + * This is a boot device access function, which is used by libpayload to read data from + * the flash memory (or other boot device). It has to be implemented by payloads using + * FlashMap and libCBFS. + * + * @param buf The output buffer to which the data should be written to. + * @param offset Absolute offset in bytes of the requested boot device memory area. Not aligned. + * @param size Size in bytes of the requested boot device memory area. Not aligned. + * + * @returns Number of bytes returned to the buffer, or negative value on error. Typically should + * be equal to the `size`, and not aligned forcefully. + */ +ssize_t libpayload_boot_device_read(void *buf, size_t offset, size_t size); + +#endif /* _BOOT_DEVICE_H */ diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index e08d211..42748e3 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -64,6 +64,7 @@ #include <sysinfo.h> #include <pci.h> #include <archive.h> +#include <boot_device.h>
/* Double-evaluation unsafe min/max, for bitfields and outside of functions */ #define __CMP_UNSAFE(a, b, op) ((a) op (b) ? (a) : (b)) diff --git a/payloads/libpayload/libc/Makefile.inc b/payloads/libpayload/libc/Makefile.inc index f9006ae..74b710e 100644 --- a/payloads/libpayload/libc/Makefile.inc +++ b/payloads/libpayload/libc/Makefile.inc @@ -39,3 +39,4 @@ libc-$(CONFIG_LP_LIBC) += coreboot.c libc-$(CONFIG_LP_LIBC) += fmap.c libc-$(CONFIG_LP_LIBC) += fpmath.c +libc-$(CONFIG_LP_LIBC) += boot_device.c diff --git a/payloads/libpayload/libc/boot_device.c b/payloads/libpayload/libc/boot_device.c new file mode 100644 index 0000000..17bad0d --- /dev/null +++ b/payloads/libpayload/libc/boot_device.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: BSD-3-clause OR GPL-2.0-or-later */ + +#include <boot_device.h> +#include <cbfs.h> +#include <stddef.h> + +/* Default fallback implementation using cbfs_media */ +__attribute__((weak)) ssize_t libpayload_boot_device_read(void *buf, size_t offset, size_t size) +{ + struct cbfs_media default_media; + struct cbfs_media *media = &default_media; + ssize_t ret = 0; + + if (init_default_cbfs_media(media) != 0) + return 0; + + media->open(media); + ret = media->read(media, buf, offset, size); + media->close(media); + + return ret; +}