mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Steffen Trumtrar <s.trumtrar@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Steffen Trumtrar <s.trumtrar@pengutronix.de>
Subject: [PATCH v2 6/9] efi: efi: load state from devicetree
Date: Mon, 10 Jul 2017 12:33:52 +0200	[thread overview]
Message-ID: <20170710103355.15652-6-s.trumtrar@pengutronix.de> (raw)
In-Reply-To: <20170710103355.15652-1-s.trumtrar@pengutronix.de>

Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de>
---
Changes since v1:
  - add documentation

 Documentation/boards/efi.rst |  4 ++++
 common/efi/efi.c             | 56 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/Documentation/boards/efi.rst b/Documentation/boards/efi.rst
index ecadb3ebba57..8f78a800ef74 100644
--- a/Documentation/boards/efi.rst
+++ b/Documentation/boards/efi.rst
@@ -42,6 +42,10 @@ architectures. Switching to USB boot in the BIOS should then be enough to
 start barebox via USB. Some BIOSes allow to specify a path to a binary to
 be executed, others have a "start UEFI shell" entry which executes
 EFI/Shellx64.efi on the :term:`ESP`. This can be a barebox binary aswell.
+To use the :ref:`state_framework`, the describing devicetree file ``state.dtb``
+has to be put into the ``EFI/barebox/`` directory.
+Supported backends for EFI are raw partitions that can be discovered via a
+partition UUID.
 
 Running EFI barebox on qemu
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/common/efi/efi.c b/common/efi/efi.c
index f924385958e1..cc3051dedae9 100644
--- a/common/efi/efi.c
+++ b/common/efi/efi.c
@@ -40,6 +40,8 @@
 #include <efi.h>
 #include <efi/efi.h>
 #include <efi/efi-device.h>
+#include <libfile.h>
+#include <state.h>
 
 efi_runtime_services_t *RT;
 efi_boot_services_t *BS;
@@ -384,6 +386,60 @@ static int efi_postcore_init(void)
 }
 postcore_initcall(efi_postcore_init);
 
+static int efi_late_init(void)
+{
+	char *state_desc;
+	int ret;
+
+	state_desc = xasprintf("/boot/EFI/barebox/state.dtb");
+
+	if (state_desc) {
+		void *fdt;
+		size_t size;
+		struct device_node *root = NULL;
+		struct device_node *np = NULL;
+		struct state *state;
+
+		fdt = read_file(state_desc, &size);
+		if (!fdt) {
+			pr_err("unable to read %s: %s\n", state_desc,
+			       strerror(errno));
+			return -errno;
+		}
+
+		if (file_detect_type(fdt, size) != filetype_oftree) {
+			pr_err("%s is not an oftree file.\n", state_desc);
+			free(fdt);
+			return -EINVAL;
+		}
+
+		root = of_unflatten_dtb(fdt);
+
+		free(fdt);
+
+		if (IS_ERR(root))
+			return PTR_ERR(root);
+
+		of_set_root_node(root);
+
+		np = of_find_node_by_alias(root, "state");
+
+		state = state_new_from_node(np, NULL, 0, 0, false);
+		if (IS_ERR(state))
+			return PTR_ERR(state);
+
+		ret = state_load(state);
+		if (ret)
+			pr_warn("Failed to load persistent state, continuing with defaults, %d\n",
+				ret);
+
+		return 0;
+	}
+
+	return 0;
+}
+late_initcall(efi_late_init);
+
 static int do_efiexit(int argc, char *argv[])
 {
 	return BS->exit(efi_parent_image, EFI_SUCCESS, 0, NULL);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2017-07-10 10:34 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-10 10:33 [PATCH v2 1/9] state: fix compile warnings for dev_err expansion Steffen Trumtrar
2017-07-10 10:33 ` [PATCH v2 2/9] common: efi: do not use undefined kconfig option Steffen Trumtrar
2017-07-10 10:33 ` [PATCH v2 3/9] fs: efi: return with correct error code in efifs_stat Steffen Trumtrar
2017-07-10 10:33 ` [PATCH v2 4/9] devfs-core: add function to find cdev by partuuid Steffen Trumtrar
2017-07-10 10:33 ` [PATCH v2 5/9] of: of_path: find device via partuuid Steffen Trumtrar
2017-07-10 10:33 ` Steffen Trumtrar [this message]
2017-07-10 13:49   ` [PATCH v2 6/9] efi: efi: load state from devicetree Lucas Stach
2017-07-11 15:00     ` Lucas Stach
2017-07-10 10:33 ` [PATCH v2 7/9] blspec: skip all devicetree tests if entry doesn't specify one Steffen Trumtrar
2017-07-10 10:33 ` [PATCH v2 8/9] efi: efi: register barebox-update handler Steffen Trumtrar
2017-07-10 10:33 ` [PATCH v2 9/9] efi_defconfig: enable STATE Steffen Trumtrar

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=20170710103355.15652-6-s.trumtrar@pengutronix.de \
    --to=s.trumtrar@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