xref: /aosp_15_r20/external/coreboot/payloads/libpayload/arch/x86/boot_media.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 
3 #include <libpayload.h>
4 #include <boot_device.h>
5 
boot_device_read(void * buf,size_t offset,size_t size)6 __attribute__((weak)) ssize_t boot_device_read(void *buf, size_t offset, size_t size)
7 {
8 	/* Memory-mapping usually only works for the top 16MB. */
9 	if (!lib_sysinfo.boot_media_size || lib_sysinfo.boot_media_size - offset > 16 * MiB)
10 		return CB_ERR_ARG;
11 	const void *const ptr = phys_to_virt(0 - lib_sysinfo.boot_media_size + offset);
12 	memcpy(buf, ptr, size);
13 	return size;
14 }
15