diff mbox series

[v6,001/102] binman: Add a library to access binman entries

Message ID 20191206213936.v6.1.I8c03ae7027508705f6f535ba5137b5e6c5dea840@changeid
State Accepted
Commit 3c10dc95bdd0706ff85ffdc25ecd6381c3d51e4c
Delegated to: Bin Meng
Headers show
Series x86: Add initial support for apollolake | expand

Commit Message

Simon Glass Dec. 7, 2019, 4:41 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>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v6: None
Changes in v5:
- Fix build errors on some PowerPC boards

Changes in v4:
- Add comments to functions

Changes in v3: None
Changes in v2: None

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

Comments

Bin Meng Dec. 8, 2019, 1:08 a.m. UTC | #1
On Sat, Dec 7, 2019 at 12:45 PM 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>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
> Changes in v6: None
> Changes in v5:
> - Fix build errors on some PowerPC boards
>
> Changes in v4:
> - Add comments to functions
>
> Changes in v3: None
> Changes in v2: None
>
>  common/board_r.c | 10 ++++++++++
>  include/binman.h | 45 +++++++++++++++++++++++++++++++++++++++++++++
>  lib/Kconfig      | 10 ++++++++++
>  lib/Makefile     |  1 +
>  lib/binman.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 114 insertions(+)
>  create mode 100644 include/binman.h
>  create mode 100644 lib/binman.c
>

applied to u-boot-x86/next, thanks!
Stephen Warren Jan. 7, 2020, 5:32 p.m. UTC | #2
On 12/7/19 6:08 PM, Bin Meng wrote:
> On Sat, Dec 7, 2019 at 12:45 PM 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.
...
> applied to u-boot-x86/next, thanks!

This patch caused a failure during early boot on Jetson TX2. Can you 
please take a look, or revert the patch until this can be investigated? 
Thanks.

U-Boot 2020.01-rc4-00256-g3c10dc95bdd0 (Jan 07 2020 - 10:25:00 -0700)

SoC: tegra186
Model: NVIDIA P2771-0000-500
Board: NVIDIA P2771-0000
DRAM:  7.8 GiB
initcall sequence 00000000fffb7858 failed at call 00000000800955a8 (err=-22)
### ERROR ### Please RESET the board ###
Stephen Warren Jan. 7, 2020, 5:57 p.m. UTC | #3
On 1/7/20 10:32 AM, Stephen Warren wrote:
> On 12/7/19 6:08 PM, Bin Meng wrote:
>> On Sat, Dec 7, 2019 at 12:45 PM 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.
> ...
>> applied to u-boot-x86/next, thanks!
> 
> This patch caused a failure during early boot on Jetson TX2. Can you 
> please take a look, or revert the patch until this can be investigated? 
> Thanks.
> 
> U-Boot 2020.01-rc4-00256-g3c10dc95bdd0 (Jan 07 2020 - 10:25:00 -0700)
> 
> SoC: tegra186
> Model: NVIDIA P2771-0000-500
> Board: NVIDIA P2771-0000
> DRAM:  7.8 GiB
> initcall sequence 00000000fffb7858 failed at call 00000000800955a8 
> (err=-22)
> ### ERROR ### Please RESET the board ###

Nevermind; I found some strange DT inconsistency introduced long ago 
that now triggers some issue in this patch. I'll send a patch for this soon.
Simon Glass Jan. 8, 2020, 2:14 a.m. UTC | #4
On Tue, 7 Jan 2020 at 10:57, Stephen Warren <swarren@wwwdotorg.org> wrote:
>
> On 1/7/20 10:32 AM, Stephen Warren wrote:
> > On 12/7/19 6:08 PM, Bin Meng wrote:
> >> On Sat, Dec 7, 2019 at 12:45 PM 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.
> > ...
> >> applied to u-boot-x86/next, thanks!
> >
> > This patch caused a failure during early boot on Jetson TX2. Can you
> > please take a look, or revert the patch until this can be investigated?
> > Thanks.
> >
> > U-Boot 2020.01-rc4-00256-g3c10dc95bdd0 (Jan 07 2020 - 10:25:00 -0700)
> >
> > SoC: tegra186
> > Model: NVIDIA P2771-0000-500
> > Board: NVIDIA P2771-0000
> > DRAM:  7.8 GiB
> > initcall sequence 00000000fffb7858 failed at call 00000000800955a8
> > (err=-22)
> > ### ERROR ### Please RESET the board ###
>
> Nevermind; I found some strange DT inconsistency introduced long ago
> that now triggers some issue in this patch. I'll send a patch for this soon.

Thanks Stephen.

- Simon
Frank Wunderlich Jan. 22, 2020, 3:49 p.m. UTC | #5
Hi,

this Patch seems to break init-chain at least on bpi-r64 if BINMAN_FDT not disabled (enabled by default). adding some code for debugging

38 int binman_init(void)
39 {
40         binman = malloc(sizeof(struct binman_info));
41         printf("%s:%d",__FUNCTION__,__LINE__);
42         if (!binman)
43                 return log_msg_ret("space for binman", -ENOMEM);
44         printf("%s:%d",__FUNCTION__,__LINE__);
45         binman->image = ofnode_path("/binman");
46         printf("%s:%d",__FUNCTION__,__LINE__);
47         if (!ofnode_valid(binman->image))
48                 return log_msg_ret("binman node", -EINVAL); <<<<<<<<<<< this seems to break init-flow
49
50         printf("%s:%d",__FUNCTION__,__LINE__);
51         return 0;
52 }

results in this:

binman_init:41binman_init:44binman_init:46initcall sequence 000000004ffd2588 failed at call 0000000041e0cdec (err=-22)

regards Frank
Frank Wunderlich Jan. 24, 2020, 6:15 p.m. UTC | #6
Hi,

a bit more info about this...

this line [1] (in my case) breaks the init-chain:

return log_msg_ret("binman node", -EINVAL);

the binman_init [2] is added to init_sequence_r[] which is executed by initcall_run_list

./common/board_r.c:897:	if (initcall_run_list(init_sequence_r))

exiting the binman-function [3] with error-code (return <> 0) exits the full chain (./include/initcall.h) [4] with message

initcall sequence %p failed at call %p

how to deal with this?

- do not select binman as default=y in Kconfig
- adding the binman-node [1] to all dts
- do not exit with error-code (only print/log message)
- do not exit the init-sequence on binman-error [3]
- more ideas?

in our case we disabled option CONFIG_BINMAN_FDT [5]

regards Frank

[1] https://gitlab.denx.de/u-boot/u-boot/blob/master/lib/binman.c#L45
[2] https://gitlab.denx.de/u-boot/u-boot/blob/master/common/board_r.c#L722
[3] https://gitlab.denx.de/u-boot/u-boot/blob/master/common/board_r.c#L369
[4] https://gitlab.denx.de/u-boot/u-boot/blob/master/include/initcall.h#L42

[5] http://forum.banana-pi.org/t/bpi-r64-current-u-boot-support/10077/69
Simon Glass Feb. 11, 2020, 11:03 p.m. UTC | #7
Hi Frank,

On Fri, 24 Jan 2020 at 11:15, Frank Wunderlich <frank-w@public-files.de> wrote:
>
> Hi,
>
> a bit more info about this...

Sorry for the delay. Stephen hit this also.

>
> this line [1] (in my case) breaks the init-chain:
>
> return log_msg_ret("binman node", -EINVAL);
>
> the binman_init [2] is added to init_sequence_r[] which is executed by initcall_run_list
>
> ./common/board_r.c:897: if (initcall_run_list(init_sequence_r))
>
> exiting the binman-function [3] with error-code (return <> 0) exits the full chain (./include/initcall.h) [4] with message
>
> initcall sequence %p failed at call %p
>
> how to deal with this?
>
> - do not select binman as default=y in Kconfig

Where is it selected by default?

bpi-r64 uses binman to build its image so I think BINMAN is on.

> - adding the binman-node [1] to all dts

Yes, but in fact it should already be there. I see in the Makefile
that 64-bit sunxi uses 'cat' instead of 'binman'. It should use
binman.

> - do not exit with error-code (only print/log message)

Not keen on that

> - do not exit the init-sequence on binman-error [3]

or that

> - more ideas?

Let's convert bpi-64 as above.

>
> in our case we disabled option CONFIG_BINMAN_FDT [5]
>
> regards Frank
>
> [1] https://gitlab.denx.de/u-boot/u-boot/blob/master/lib/binman.c#L45
> [2] https://gitlab.denx.de/u-boot/u-boot/blob/master/common/board_r.c#L722
> [3] https://gitlab.denx.de/u-boot/u-boot/blob/master/common/board_r.c#L369
> [4] https://gitlab.denx.de/u-boot/u-boot/blob/master/include/initcall.h#L42
>
> [5] http://forum.banana-pi.org/t/bpi-r64-current-u-boot-support/10077/69
>

Regards,
Simon
Frank Wunderlich Feb. 12, 2020, 11:50 a.m. UTC | #8
Am 12. Februar 2020 00:03:18 MEZ schrieb Simon Glass <sjg@chromium.org>:
>Hi Frank,
>
>Sorry for the delay. Stephen hit this also.

Hi Simon,
good that my mail was not lost 😁

>>
>> this line [1] (in my case) breaks the init-chain:
>>
>> return log_msg_ret("binman node", -EINVAL);
>>
>> the binman_init [2] is added to init_sequence_r[] which is executed
>by initcall_run_list
>>
>> ./common/board_r.c:897: if (initcall_run_list(init_sequence_r))
>>
>> exiting the binman-function [3] with error-code (return <> 0) exits
>the full chain (./include/initcall.h) [4] with message
>>
>> initcall sequence %p failed at call %p
>>
>> how to deal with this?
>>
>> - do not select binman as default=y in Kconfig
>
>Where is it selected by default?

https://gitlab.denx.de/u-boot/u-boot/blob/master/lib/Kconfig#L13

>bpi-r64 uses binman to build its image so I think BINMAN is on.
>
>> - adding the binman-node [1] to all dts
>
>Yes, but in fact it should already be there. I see in the Makefile
>that 64-bit sunxi uses 'cat' instead of 'binman'. It should use
>binman.

https://gitlab.denx.de/u-boot/u-boot/blob/master/arch/arm/dts/mt7622.dtsi
https://gitlab.denx.de/u-boot/u-boot/blob/master/arch/arm/dts/mt7622-rfb.dts

I see no binman there

>> - do not exit with error-code (only print/log message)
>
>Not keen on that
>
>> - do not exit the init-sequence on binman-error [3]
>
>or that
>
>> - more ideas?
>
>Let's convert bpi-64 as above.

What do i need to add/change

>>
>> in our case we disabled option CONFIG_BINMAN_FDT [5]
>>
>> regards Frank
>>
>> [1] https://gitlab.denx.de/u-boot/u-boot/blob/master/lib/binman.c#L45
>> [2]
>https://gitlab.denx.de/u-boot/u-boot/blob/master/common/board_r.c#L722
>> [3]
>https://gitlab.denx.de/u-boot/u-boot/blob/master/common/board_r.c#L369
>> [4]
>https://gitlab.denx.de/u-boot/u-boot/blob/master/include/initcall.h#L42
>>
>> [5]
>http://forum.banana-pi.org/t/bpi-r64-current-u-boot-support/10077/69
>>
>
>Regards,
>Simon


Mit freundlichen Grüßen
Frank Wunderlich
Simon Glass Feb. 12, 2020, 5:14 p.m. UTC | #9
Hi Frank,

On Wed, 12 Feb 2020 at 04:50, Frank Wunderlich <frank-w@public-files.de> wrote:
>
> Am 12. Februar 2020 00:03:18 MEZ schrieb Simon Glass <sjg@chromium.org>:
> >Hi Frank,
> >
> >Sorry for the delay. Stephen hit this also.
>
> Hi Simon,
> good that my mail was not lost
>
> >>
> >> this line [1] (in my case) breaks the init-chain:
> >>
> >> return log_msg_ret("binman node", -EINVAL);
> >>
> >> the binman_init [2] is added to init_sequence_r[] which is executed
> >by initcall_run_list
> >>
> >> ./common/board_r.c:897: if (initcall_run_list(init_sequence_r))
> >>
> >> exiting the binman-function [3] with error-code (return <> 0) exits
> >the full chain (./include/initcall.h) [4] with message
> >>
> >> initcall sequence %p failed at call %p
> >>
> >> how to deal with this?
> >>
> >> - do not select binman as default=y in Kconfig
> >
> >Where is it selected by default?
>
> https://gitlab.denx.de/u-boot/u-boot/blob/master/lib/Kconfig#L13
>
> >bpi-r64 uses binman to build its image so I think BINMAN is on.
> >
> >> - adding the binman-node [1] to all dts
> >
> >Yes, but in fact it should already be there. I see in the Makefile
> >that 64-bit sunxi uses 'cat' instead of 'binman'. It should use
> >binman.
>
> https://gitlab.denx.de/u-boot/u-boot/blob/master/arch/arm/dts/mt7622.dtsi
> https://gitlab.denx.de/u-boot/u-boot/blob/master/arch/arm/dts/mt7622-rfb.dts
>
> I see no binman there
>
> >> - do not exit with error-code (only print/log message)
> >
> >Not keen on that
> >
> >> - do not exit the init-sequence on binman-error [3]
> >
> >or that
> >
> >> - more ideas?
> >
> >Let's convert bpi-64 as above.
>
> What do i need to add/change

This code in the Makefile should do the same thing for ARM64 and 32:

ifneq ($(CONFIG_ARCH_SUNXI),)
ifeq ($(CONFIG_ARM64),)
u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img u-boot.dtb FORCE
$(call if_changed,binman)
else
u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
$(call if_changed,cat)
endif
endif

To make this work I think you'll need to add a new 'sunxi-itb' entry
type into binman as a first step. That is ugly but it will work.

Then mksunxi_fit_atf.sh should move into binman, with 'sunxi-itb'
becoming a new method that generates the .its from source. I can help
with that bit.

Regards,
Simon
Frank Wunderlich Feb. 12, 2020, 6:02 p.m. UTC | #10
Hi

Why not just disable binman_fdt (or not default y)? Your way sounds more complex. As i do not understand it and see no benefit for this board, i would leave it disabled. This leave time for a thoughtful solution
Maybe mtk knows a better way...

Sunxi sounds wrong because board is not with allwinner soc. Maybe a more generic name as target for boards not yet supported by binman_fdt?

Regards Frank

Am 12. Februar 2020 18:14:29 MEZ schrieb Simon Glass <sjg@chromium.org>:
>
>This code in the Makefile should do the same thing for ARM64 and 32:
>
>ifneq ($(CONFIG_ARCH_SUNXI),)
>ifeq ($(CONFIG_ARM64),)
>u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img u-boot.dtb
>FORCE
>$(call if_changed,binman)
>else
>u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
>$(call if_changed,cat)
>endif
>endif
>
>To make this work I think you'll need to add a new 'sunxi-itb' entry
>type into binman as a first step. That is ugly but it will work.
>
>Then mksunxi_fit_atf.sh should move into binman, with 'sunxi-itb'
>becoming a new method that generates the .its from source. I can help
>with that bit.
>
>Regards,
>Simon
Simon Glass Feb. 13, 2020, 5:40 p.m. UTC | #11
Hi Frank,

On Wed, 12 Feb 2020 at 11:02, Frank Wunderlich <frank-w@public-files.de> wrote:
>
> Hi
>
> Why not just disable binman_fdt (or not default y)? Your way sounds more complex. As i do not understand it and see no benefit for this board, i would leave it disabled. This leave time for a thoughtful solution
> Maybe mtk knows a better way...
>
> Sunxi sounds wrong because board is not with allwinner soc. Maybe a more generic name as target for boards not yet supported by binman_fdt?

Oh so now I am confused. What U-Boot board name are you referring to?
I assumed it was bananapi_m64.

Regards,
Simon


>
> Regards Frank
>
> Am 12. Februar 2020 18:14:29 MEZ schrieb Simon Glass <sjg@chromium.org>:
> >
> >This code in the Makefile should do the same thing for ARM64 and 32:
> >
> >ifneq ($(CONFIG_ARCH_SUNXI),)
> >ifeq ($(CONFIG_ARM64),)
> >u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.img u-boot.dtb
> >FORCE
> >$(call if_changed,binman)
> >else
> >u-boot-sunxi-with-spl.bin: spl/sunxi-spl.bin u-boot.itb FORCE
> >$(call if_changed,cat)
> >endif
> >endif
> >
> >To make this work I think you'll need to add a new 'sunxi-itb' entry
> >type into binman as a first step. That is ugly but it will work.
> >
> >Then mksunxi_fit_atf.sh should move into binman, with 'sunxi-itb'
> >becoming a new method that generates the .its from source. I can help
> >with that bit.
> >
> >Regards,
> >Simon
Frank Wunderlich Feb. 13, 2020, 5:51 p.m. UTC | #12
Hi,

i guess you mean this (board is bananapi R64, not M64):

board/mediatek/mt7622/mt7622_rfb.c
arch/arm/dts/mt7622.dtsi
arch/arm/dts/mt7622-rfb.dts

currently i have added

CONFIG_BINMAN_FDT=n

to configs/mt7622_rfb_defconfig to avoid the Problem

regards Frank


> Gesendet: Donnerstag, 13. Februar 2020 um 18:40 Uhr
> Von: "Simon Glass" <sjg@chromium.org>
> Betreff: Re: [BUG] binman: Add a library to access binman entries
>
> Hi Frank,
>
> On Wed, 12 Feb 2020 at 11:02, Frank Wunderlich <frank-w@public-files.de> wrote:
> >
> > Hi
> >
> > Why not just disable binman_fdt (or not default y)? Your way sounds more complex. As i do not understand it and see no benefit for this board, i would leave it disabled. This leave time for a thoughtful solution
> > Maybe mtk knows a better way...
> >
> > Sunxi sounds wrong because board is not with allwinner soc. Maybe a more generic name as target for boards not yet supported by binman_fdt?
>
> Oh so now I am confused. What U-Boot board name are you referring to?
> I assumed it was bananapi_m64.
>
> Regards,
> Simon
Simon Glass Feb. 17, 2020, 3:55 a.m. UTC | #13
Hi Frank,

On Thu, 13 Feb 2020 at 10:51, Frank Wunderlich <frank-w@public-files.de> wrote:
>
> Hi,
>
> i guess you mean this (board is bananapi R64, not M64):
>
> board/mediatek/mt7622/mt7622_rfb.c
> arch/arm/dts/mt7622.dtsi
> arch/arm/dts/mt7622-rfb.dts
>
> currently i have added
>
> CONFIG_BINMAN_FDT=n
>
> to configs/mt7622_rfb_defconfig to avoid the Problem

The problem is that in ARCH_MEDIATEK you have 'select BINMAN'. If
binan is used, it expects that you will use it at run time, so enables
BINMAN_FDT.

If you are not actually using binman, why is it enabled?

Regards,
Simon
Frank Wunderlich Feb. 17, 2020, 7:04 a.m. UTC | #14
Hi Simon,Ryder

The binman-option is introduced by this commit:

https://gitlab.denx.de/u-boot/u-boot/commit/cbd2fba1eca11300649052e289685e7404e0b81c

add basic support for MT7629 boards


@ryder is binman used (mt7629)? R2 and r64 are affected from this issue (boot broken by binman_fdt). Have it disabled in my repo for both boards but upstream is broken. Binman was not active for these 2 till this commit so i guess it is unused.maybe only for mt7629

Regards Frank

Am 17. Februar 2020 04:55:50 MEZ schrieb Simon Glass <sjg@chromium.org>:
>Hi Frank,
>
>On Thu, 13 Feb 2020 at 10:51, Frank Wunderlich
><frank-w@public-files.de> wrote:
>>
>> Hi,
>>
>> i guess you mean this (board is bananapi R64, not M64):
>>
>> board/mediatek/mt7622/mt7622_rfb.c
>> arch/arm/dts/mt7622.dtsi
>> arch/arm/dts/mt7622-rfb.dts
>>
>> currently i have added
>>
>> CONFIG_BINMAN_FDT=n
>>
>> to configs/mt7622_rfb_defconfig to avoid the Problem
>
>The problem is that in ARCH_MEDIATEK you have 'select BINMAN'. If
>binan is used, it expects that you will use it at run time, so enables
>BINMAN_FDT.
>
>If you are not actually using binman, why is it enabled?
>
>Regards,
>Simon
diff mbox series

Patch

diff --git a/common/board_r.c b/common/board_r.c
index 5464172259..9902c51c5e 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 0000000000..b462dc8542
--- /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 965cf7bc03..d040a87d26 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 1fb650cd90..7a713a54dc 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 0000000000..1774bdf2e5
--- /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;
+}