4fa9f2ae8b
Casts from integer to pointer are usually a case for phys_to_virt(). Change-Id: I861d435ff2361cdc26a2abd46d43b9346fa67ccc Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/62246 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Julius Werner <jwerner@chromium.org>
18 lines
568 B
C
18 lines
568 B
C
/* SPDX-License-Identifier: BSD-3-Clause */
|
|
|
|
#include <arch/virtual.h>
|
|
#include <boot_device.h>
|
|
#include <commonlib/bsd/cb_err.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <sysinfo.h>
|
|
|
|
__attribute__((weak)) ssize_t boot_device_read(void *buf, size_t offset, size_t size)
|
|
{
|
|
/* Memory-mapping usually only works for the top 16MB. */
|
|
if (!lib_sysinfo.boot_media_size || lib_sysinfo.boot_media_size - offset > 16 * MiB)
|
|
return CB_ERR_ARG;
|
|
const void *const ptr = phys_to_virt(0 - lib_sysinfo.boot_media_size + offset);
|
|
memcpy(buf, ptr, size);
|
|
return size;
|
|
}
|