summaryrefslogtreecommitdiffstats
path: root/common/efi
diff options
context:
space:
mode:
authorSteffen Trumtrar <s.trumtrar@pengutronix.de>2017-07-10 12:33:52 +0200
committerLucas Stach <l.stach@pengutronix.de>2017-07-11 15:45:20 +0200
commitb00a9d7b5c8bcce3d08b663b467f0686dc2466d9 (patch)
treeddaae97f26a38b455248017dca8d5149534231a9 /common/efi
parent18dd855d0d9a8ac224fa53e4f3ad16fdf685c7b8 (diff)
downloadbarebox-b00a9d7b5c8bcce3d08b663b467f0686dc2466d9.tar.gz
efi: efi: load state from devicetree
Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Diffstat (limited to 'common/efi')
-rw-r--r--common/efi/efi.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/common/efi/efi.c b/common/efi/efi.c
index f924385..3423c8a 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,63 @@ static int efi_postcore_init(void)
}
postcore_initcall(efi_postcore_init);
+static int efi_late_init(void)
+{
+ char *state_desc;
+ int ret;
+
+ if (!IS_ENABLED(CONFIG_STATE))
+ return 0;
+
+ 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);