aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2019-12-06 21:41:34 -0700
committerBin Meng <bmeng.cn@gmail.com>2019-12-15 08:48:33 +0800
commit3c10dc95bdd0706ff85ffdc25ecd6381c3d51e4c (patch)
treefe9a2f30a15fdf3fc36fb7c7194a568b981e4024
parent553cb06887825314e74a9bdac337467c77d1db88 (diff)
downloadu-boot-3c10dc95bdd0706ff85ffdc25ecd6381c3d51e4c.zip
u-boot-3c10dc95bdd0706ff85ffdc25ecd6381c3d51e4c.tar.gz
u-boot-3c10dc95bdd0706ff85ffdc25ecd6381c3d51e4c.tar.bz2
binman: Add a library to access binman entries
SPL and TPL can access information about binman entries using link-time symbols but this is not available in U-Boot proper. Of course it could be made available, but the intention is to just read the device tree. Add support for this, so that U-Boot can locate entries. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
-rw-r--r--common/board_r.c10
-rw-r--r--include/binman.h45
-rw-r--r--lib/Kconfig10
-rw-r--r--lib/Makefile1
-rw-r--r--lib/binman.c48
5 files changed, 114 insertions, 0 deletions
diff --git a/common/board_r.c b/common/board_r.c
index 5464172..9902c51 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -18,6 +18,7 @@
#if defined(CONFIG_CMD_BEDBUG)
#include <bedbug/type.h>
#endif
+#include <binman.h>
#include <command.h>
#include <console.h>
#include <dm.h>
@@ -347,6 +348,14 @@ static int initr_manual_reloc_cmdtable(void)
}
#endif
+static int initr_binman(void)
+{
+ if (!CONFIG_IS_ENABLED(BINMAN_FDT))
+ return 0;
+
+ return binman_init();
+}
+
#if defined(CONFIG_MTD_NOR_FLASH)
static int initr_flash(void)
{
@@ -697,6 +706,7 @@ static init_fnc_t init_sequence_r[] = {
#ifdef CONFIG_EFI_LOADER
efi_memory_init,
#endif
+ initr_binman,
stdio_init_tables,
initr_serial,
initr_announce,
diff --git a/include/binman.h b/include/binman.h
new file mode 100644
index 0000000..b462dc8
--- /dev/null
+++ b/include/binman.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: Intel */
+/*
+ * Access to binman information at runtime
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#ifndef _BINMAN_H_
+#define _BINMAN_H_
+
+/**
+ *struct binman_entry - information about a binman entry
+ *
+ * @image_pos: Position of entry in the image
+ * @size: Size of entry
+ */
+struct binman_entry {
+ u32 image_pos;
+ u32 size;
+};
+
+/**
+ * binman_entry_find() - Find a binman symbol
+ *
+ * This searches the binman information in the device tree for a symbol of the
+ * given name
+ *
+ * @name: Path to entry to examine (e.g. "/read-only/u-boot")
+ * @entry: Returns information about the entry
+ * @return 0 if OK, -ENOENT if the path is not found, other -ve value if the
+ * binman information is invalid (missing image-pos or size)
+ */
+int binman_entry_find(const char *name, struct binman_entry *entry);
+
+/**
+ * binman_init() - Set up the binman symbol information
+ *
+ * This locates the binary symbol information in the device tree ready for use
+ *
+ * @return 0 if OK, -ENOMEM if out of memory, -EINVAL if there is no binman node
+ */
+int binman_init(void);
+
+#endif
diff --git a/lib/Kconfig b/lib/Kconfig
index 965cf7b..d040a87 100644
--- a/lib/Kconfig
+++ b/lib/Kconfig
@@ -7,6 +7,16 @@ config BCH
This is used by SoC platforms which do not have built-in ELM
hardware engine required for BCH ECC correction.
+config BINMAN_FDT
+ bool "Allow access to binman information in the device tree"
+ depends on BINMAN && OF_CONTROL
+ default y
+ help
+ This enables U-Boot to access information about binman entries,
+ stored in the device tree in a binman node. Typical uses are to
+ locate entries in the firmware image. See binman.h for the available
+ functionality.
+
config CC_OPTIMIZE_LIBS_FOR_SPEED
bool "Optimize libraries for speed"
help
diff --git a/lib/Makefile b/lib/Makefile
index 1fb650c..7a713a5 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_ASN1_DECODER) += asn1_decoder.o
obj-y += crypto/
obj-$(CONFIG_AES) += aes.o
+obj-$(CONFIG_$(SPL_TPL_)BINMAN_FDT) += binman.o
ifndef API_BUILD
ifneq ($(CONFIG_UT_UNICODE)$(CONFIG_EFI_LOADER),)
diff --git a/lib/binman.c b/lib/binman.c
new file mode 100644
index 0000000..1774bdf
--- /dev/null
+++ b/lib/binman.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: Intel
+/*
+ * Access to binman information at runtime
+ *
+ * Copyright 2019 Google LLC
+ * Written by Simon Glass <sjg@chromium.org>
+ */
+
+#include <common.h>
+#include <binman.h>
+#include <dm.h>
+
+struct binman_info {
+ ofnode image;
+};
+
+static struct binman_info *binman;
+
+int binman_entry_find(const char *name, struct binman_entry *entry)
+{
+ ofnode node;
+ int ret;
+
+ node = ofnode_find_subnode(binman->image, name);
+ if (!ofnode_valid(node))
+ return log_msg_ret("no binman node", -ENOENT);
+
+ ret = ofnode_read_u32(node, "image-pos", &entry->image_pos);
+ if (ret)
+ return log_msg_ret("bad binman node1", ret);
+ ret = ofnode_read_u32(node, "size", &entry->size);
+ if (ret)
+ return log_msg_ret("bad binman node2", ret);
+
+ return 0;
+}
+
+int binman_init(void)
+{
+ binman = malloc(sizeof(struct binman_info));
+ if (!binman)
+ return log_msg_ret("space for binman", -ENOMEM);
+ binman->image = ofnode_path("/binman");
+ if (!ofnode_valid(binman->image))
+ return log_msg_ret("binman node", -EINVAL);
+
+ return 0;
+}