diff mbox series

[U-Boot,v3,005/108] binman: Add a library to access binman entries

Message ID 20191021033322.217715-6-sjg@chromium.org
State Superseded
Delegated to: Bin Meng
Headers show
Series x86: Add initial support for apollolake | expand

Commit Message

Simon Glass Oct. 21, 2019, 3:31 a.m. UTC
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>
---

Changes in v3: None
Changes in v2: None

 common/board_r.c | 10 ++++++++++
 include/binman.h | 27 +++++++++++++++++++++++++++
 lib/Kconfig      | 10 ++++++++++
 lib/Makefile     |  1 +
 lib/binman.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 96 insertions(+)
 create mode 100644 include/binman.h
 create mode 100644 lib/binman.c

Comments

Bin Meng Oct. 28, 2019, 3:27 a.m. UTC | #1
Hi Simon,

On Mon, Oct 21, 2019 at 11:33 AM Simon Glass <sjg@chromium.org> wrote:
>
> 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>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  common/board_r.c | 10 ++++++++++
>  include/binman.h | 27 +++++++++++++++++++++++++++
>  lib/Kconfig      | 10 ++++++++++
>  lib/Makefile     |  1 +
>  lib/binman.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 96 insertions(+)
>  create mode 100644 include/binman.h
>  create mode 100644 lib/binman.c
>
> diff --git a/common/board_r.c b/common/board_r.c
> index d6fb5047a26..e0f3eb325aa 100644
> --- a/common/board_r.c
> +++ b/common/board_r.c
> @@ -15,6 +15,7 @@
>  #if defined(CONFIG_CMD_BEDBUG)
>  #include <bedbug/type.h>
>  #endif
> +#include <binman.h>
>  #include <command.h>
>  #include <console.h>
>  #include <dm.h>
> @@ -342,6 +343,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)
>  {
> @@ -693,6 +702,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 00000000000..cc9ec77797f
> --- /dev/null
> +++ b/include/binman.h
> @@ -0,0 +1,27 @@
> +/* 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;
> +};
> +
> +int binman_entry_find(const char *name, struct binman_entry *entry);
> +
> +int binman_init(void);

Please add the comment block with parameters/return value for the
above 2 functions.

> +
> +#endif
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 135f0b372b0..291d42324d1 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
> +       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 d248d8626ce..0c89b4896fe 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -19,6 +19,7 @@ obj-$(CONFIG_ARCH_AT91) += at91/
>  obj-$(CONFIG_OPTEE) += optee/
>
>  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 00000000000..1774bdf2e5c
> --- /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;
> +}
> --

Regards,
Bin
diff mbox series

Patch

diff --git a/common/board_r.c b/common/board_r.c
index d6fb5047a26..e0f3eb325aa 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -15,6 +15,7 @@ 
 #if defined(CONFIG_CMD_BEDBUG)
 #include <bedbug/type.h>
 #endif
+#include <binman.h>
 #include <command.h>
 #include <console.h>
 #include <dm.h>
@@ -342,6 +343,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)
 {
@@ -693,6 +702,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 00000000000..cc9ec77797f
--- /dev/null
+++ b/include/binman.h
@@ -0,0 +1,27 @@ 
+/* 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;
+};
+
+int binman_entry_find(const char *name, struct binman_entry *entry);
+
+int binman_init(void);
+
+#endif
diff --git a/lib/Kconfig b/lib/Kconfig
index 135f0b372b0..291d42324d1 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
+	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 d248d8626ce..0c89b4896fe 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -19,6 +19,7 @@  obj-$(CONFIG_ARCH_AT91) += at91/
 obj-$(CONFIG_OPTEE) += optee/
 
 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 00000000000..1774bdf2e5c
--- /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;
+}