summaryrefslogtreecommitdiff
path: root/payloads/libpayload/arch/x86/boot_media.c
blob: ce0283273d695ee85194a2e622d305ba5ae4a0a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* SPDX-License-Identifier: BSD-3-Clause */

#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;
	void *ptr = (void *)(uintptr_t)(0 - lib_sysinfo.boot_media_size + offset);
	memcpy(buf, ptr, size);
	return size;
}