mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 5/5] efi: add device tree configuration table support
Date: Mon, 10 Oct 2022 08:08:42 +0200	[thread overview]
Message-ID: <20221010060842.2083550-5-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20221010060842.2083550-1-a.fatoum@pengutronix.de>

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>
---
 common/efi/guid.c           |  1 +
 common/efi/payload/Makefile |  1 +
 common/efi/payload/fdt.c    | 43 +++++++++++++++++++++++++++++++++++++
 include/efi.h               |  1 +
 4 files changed, 46 insertions(+)
 create mode 100644 common/efi/payload/fdt.c

diff --git a/common/efi/guid.c b/common/efi/guid.c
index 93418d57b469..ca16f4520ff2 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 bcbdda335f06..eeed046b0045 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 000000000000..dbbc93fb7d68
--- /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);
diff --git a/include/efi.h b/include/efi.h
index 36e08af67bf3..3595cf05ccb7 100644
--- a/include/efi.h
+++ b/include/efi.h
@@ -541,6 +541,7 @@ extern efi_guid_t efi_block_io_protocol_guid;
 extern efi_guid_t efi_rng_protocol_guid;
 extern efi_guid_t efi_barebox_vendor_guid;
 extern efi_guid_t efi_systemd_vendor_guid;
+extern efi_guid_t efi_fdt_guid;
 
 typedef struct {
 	efi_guid_t guid;
-- 
2.30.2




  parent reply	other threads:[~2022-10-10  6:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-10  6:08 [PATCH 1/5] efi: retire efi_bool_t Ahmad Fatoum
2022-10-10  6:08 ` [PATCH 2/5] efi: capitalize enumeration constants Ahmad Fatoum
2022-10-10  6:08 ` [PATCH 3/5] hw_random: add EFI RNG driver Ahmad Fatoum
2022-10-10  6:08 ` [PATCH 4/5] efi: implement and use for_each_efi_config_table Ahmad Fatoum
2022-10-10  6:08 ` Ahmad Fatoum [this message]
2022-10-13  6:33 ` [PATCH 1/5] efi: retire efi_bool_t Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221010060842.2083550-5-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox