diff options
author | Ahmad Fatoum <a.fatoum@pengutronix.de> | 2022-10-10 08:08:42 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2022-10-13 08:33:37 +0200 |
commit | 27d0cd75ae65360af7007109772a03fed0bdd92d (patch) | |
tree | 1755d87dd8e0e73bce1e9ab44fdabd7c71eb49d0 /common/efi | |
parent | de9916f574b4c5805732f251e2b37b8efe2d6db5 (diff) | |
download | barebox-27d0cd75ae65360af7007109772a03fed0bdd92d.tar.gz barebox-27d0cd75ae65360af7007109772a03fed0bdd92d.tar.xz |
efi: add device tree configuration table support
When running on device-tree enabled systems, barebox as EFI payload may
be passed a device tree via the system table. We've no use for that just
yet, but lets make it available as /efi.dtb.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Link: https://lore.barebox.org/20221010060842.2083550-5-a.fatoum@pengutronix.de
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/efi')
-rw-r--r-- | common/efi/guid.c | 1 | ||||
-rw-r--r-- | common/efi/payload/Makefile | 1 | ||||
-rw-r--r-- | common/efi/payload/fdt.c | 43 |
3 files changed, 45 insertions, 0 deletions
diff --git a/common/efi/guid.c b/common/efi/guid.c index 93418d57b4..ca16f4520f 100644 --- a/common/efi/guid.c +++ b/common/efi/guid.c @@ -14,6 +14,7 @@ efi_guid_t efi_block_io_protocol_guid = EFI_BLOCK_IO_PROTOCOL_GUID; efi_guid_t efi_rng_protocol_guid = EFI_RNG_PROTOCOL_GUID; efi_guid_t efi_barebox_vendor_guid = EFI_BAREBOX_VENDOR_GUID; efi_guid_t efi_systemd_vendor_guid = EFI_SYSTEMD_VENDOR_GUID; +efi_guid_t efi_fdt_guid = EFI_DEVICE_TREE_GUID; #define EFI_GUID_STRING(guid, short, long) do { \ if (!efi_guidcmp(guid, *g)) \ diff --git a/common/efi/payload/Makefile b/common/efi/payload/Makefile index bcbdda335f..eeed046b00 100644 --- a/common/efi/payload/Makefile +++ b/common/efi/payload/Makefile @@ -2,5 +2,6 @@ obj-y += init.o obj-y += image.o +obj-$(CONFIG_OFTREE) += fdt.o bbenv-y += env-efi obj-$(CONFIG_CMD_IOMEM) += iomem.o diff --git a/common/efi/payload/fdt.c b/common/efi/payload/fdt.c new file mode 100644 index 0000000000..dbbc93fb7d --- /dev/null +++ b/common/efi/payload/fdt.c @@ -0,0 +1,43 @@ +// SPDX-License-Identifier: GPL-2.0 + +#define pr_fmt(fmt) "efi-fdt: " fmt + +#include <common.h> +#include <init.h> +#include <libfile.h> +#include <efi/efi-payload.h> +#include <efi/efi-device.h> + +static int efi_fdt_probe(void) +{ + efi_config_table_t *ect; + + for_each_efi_config_table(ect) { + struct fdt_header *oftree; + u32 magic, size; + int ret; + + if (efi_guidcmp(ect->guid, EFI_DEVICE_TREE_GUID)) + continue; + + oftree = (void *)ect->table; + magic = be32_to_cpu(oftree->magic); + + if (magic != FDT_MAGIC) { + pr_err("table has invalid magic 0x%08x\n", magic); + return -EILSEQ; + } + + size = be32_to_cpu(oftree->totalsize); + ret = write_file("/efi.dtb", oftree, size); + if (ret) { + pr_err("error saving /efi.dtb: %pe\n", ERR_PTR(ret)); + return ret; + } + + return 0; + } + + return 0; +} +late_initcall(efi_fdt_probe); |