Run-time configuration of U-Boot via a flat device tree (fdt)
Subsystems (3)
v4 cover Run-time configuration of U-Boot via a flat device tree (fdt)
At present in U-Boot configuration is mostly done using CONFIG options in the board file. This patch set makes it possible for a single U-Boot binary to support multiple boards, with the exact configuration of each board controlled by a flat device tree (fdt). This is the approach recently taken by the ARM Linux kernel and has been used by PowerPC for some time.
In other words, manufacturers can potentially use a single U-Boot binary across an entire product line, with one fdt per model.
The fdt is a convenient vehicle for implementing run-time configuration for three reasons. Firstly it is easy to use, being a simple text file. It is extensible since it consists of nodes and properties in a nice hierarchical format.
Finally, there is already excellent infrastructure for the fdt: a compiler checks the text file and converts it to a compact binary format, and a library is already available in U-Boot (libfdt) for handling this format.
To read about fdts, take a look at the specification here:
https://www.power.org/resources/downloads/Power_ePAPR_APPROVED_v1.0.pdf
You also might find this section of the Linux kernel documentation useful:
(access this in the Linux kernel source code)
Documentation/devicetree/booting-without-of.txt
To use this patch set you will need to get the device tree compiler here:
git://jdl.com/software/dtc.git
and add some defines to your board (only ARM is currently supported):
#define CONFIG_OF_CONTROL (to enable run-time config control via fdt)
#define CONFIG_OF_EMBED or CONFIG_OF_SEPARATE
(either build the fdt blob into U-Boot, or create a separate u-boot.dtb
and u-boot-dtb.bin)
#define CONFIG_DEFAULT_DEVICE_TREE "<your name>"
(to specify the name of the device tree file is
board/<vendor>/dts/<your name>.dts)
Typically a CPU device tree include file is provided which defines all the devices available on that CPU/SOC, with each set to 'status = "ok"'. Board device tree files should adjust only the devices they need to. If a device should be disabled, then it should be changed to
'status = 'disabled"' to indicate this. To facilitate this, a CPU/SOC device tree header is supported in arch/<arch>/dts. The name of this is defined by CONFIG_ARCH_DEVICE_TREE, typically defined in arch/<arch>/cpu/.../config.mk. You can use the following line within the board device tree file to include this header:
/include/ ARCH_CPU_DTS
For example, for Tegra2 we might have in arch/arm/cpu/armv7/tegra2/config.mk these lines:
CONFIG_ARCH_DEVICE_TREE := tegra20
This means that ARCH_CPU_DTS will point to arch/arm/dts/tegra20.dtsi.
This patch set does not include any drivers which actually use the fdt, but there is a basic fdt decode library (fdtdec) to simplify this process. I have provided an example i2c implementation previously:
http://patchwork.ozlabs.org/patch/114425/
It is important to understand that the fdt only selects options available in the platform / drivers. It cannot add new drivers (yet). So you must still have the CONFIG option to enable the driver. For example, you need to define CONFIG_SYS_NS16550 to bring in the NS16550 driver, but can use the fdt to specific the UART clock, peripheral address, etc. In very broad terms, the CONFIG options in general control *what* driver files are pulled in, and the fdt controls *how* those files work.
While only ARM is supported in this patch series, it should be easy enough to add support for other architectures.
I experimented with using dtc's asm output to avoid all the arch/oformat ugliness in dts/Makefile as suggested by Stephen Warren <[email protected]>. This simplified the Makefile commands greatly by removing the need to detect the output format and architecture. However Grant Likely <[email protected]> explained that this feature is not well tested and still has some big-endian-ims in it.
Changes in v2:
- Modify Makefile to create combined U-boot/fdt (u-boot-dtb.bin)
- Add example proposed decode helper library
Changes in v3:
- Rename gd->blob to gd->fdt_blob
- Move fdt files into board/<vendor>/dts
- Provide access to ARCH_CPU_DTS which is the CPU's base device tree
- Add fdtcontroladdr environment variable
- Simplify decode library to remove provide only primitive functions
- Remove i2c decode function
- Rename fdt_decode to fdtdec, since it will be used a lot
- Moved fdt_decode.c to /lib
- Export almost all functions from fdtdec, to allow widespread use
- Remove use of FDT_ERR_MISSING which is not strictly needed now
Changes in v4:
- Fix reference to gd->blob which should be gd->fdt_blob
- Remove unused 'clean' targets in dts/Makefile (remmove *.tmp at top-level)
- Move documentation into the first 'fdt' patch in the series
- Add note about CONFIG_ARCH_DEVICE_TREE
- Add assert on sprintf() string length
- Rename addr_t to fdt_addr_t to make it more fdt-specific
- Remove gpio.h header in fdtdec.c which is not needed yet
Simon Glass (6):
fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL)
fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE)
fdt: ARM: Implement and verify embedded and separate device tree
fdt: ARM: Add fdtcontroladdr to set device tree address in
environment
fdt: add decode helper library
.gitignore | 1 + Makefile | 13 +++ README | 34 +++++++ arch/arm/include/asm/global_data.h | 1 + arch/arm/lib/board.c | 52 +++++++++-- config.mk | 1 + doc/README.fdt-control | 184 ++++++++++++++++++++++++++++++++++++ dts/Makefile | 103 ++++++++++++++++++++ include/common.h | 1 + include/fdtdec.h | 122 ++++++++++++++++++++++++ lib/Makefile | 1 + lib/fdtdec.c | 131 +++++++++++++++++++++++++ 12 files changed, 637 insertions(+), 7 deletions(-) create mode 100644 doc/README.fdt-control create mode 100644 dts/Makefile create mode 100644 include/fdtdec.h create mode 100644 lib/fdtdec.c
Signature · 1 line
1.7.3.1
PATCH v4 1/6 fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL)
This adds a device tree pointer to the global data. It can be set by board code. A later commit will add support for making a device tree binary blob available to U-Boot for run-time configuration.
---
Changes in v3:
- Rename gd->blob to gd->fdt_blob
Changes in v4:
- Fix reference to gd->blob which should be gd->fdt_blob
README | 11 +++++++++++ arch/arm/include/asm/global_data.h | 1 + 2 files changed, 12 insertions(+), 0 deletions(-)
README +11 -0
@@ -811,6 +811,17 @@ The following options need to be configured: XXX - this list needs to get updated! +- Device tree: + CONFIG_OF_CONTROL + If this variable is defined, U-Boot will use a device tree + to configure its devices, instead of relying on statically + compiled #defines in the board file. This option is + experimental and only available on a few boards. The device + tree is available in the global data as gd->fdt_blob. + + U-Boot needs to get its device tree from somewhere. This will + be enabled in a future patch. + - Watchdog: CONFIG_WATCHDOG If this variable is defined, it enables watchdog
arch/arm/include/asm/global_data.h +1 -0
@@ -76,6 +76,7 @@ typedef struct global_data {#if !(defined(CONFIG_SYS_ICACHE_OFF ) && defined(CONFIG_SYS_DCACHE_OFF ))unsigned long tlb_addr;#endif +const void *fdt_blob;/* Our device tree, NULL if none */ void **jt;/* jump table */ char env_buf[32 ];/* buffer for getenv() before reloc. */ #if defined(CONFIG_POST ) || defined(CONFIG_LOGBUFFER )
Signature · 1 line
1.7.3.1
PATCH v4 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
In reply to Simon GlassThis new option allows U-Boot to embed a binary device tree into its image to allow run-time control of peripherals. This device tree is for U-Boot's own use and is not necessarily the same one as is passed to the kernel.
The device tree compiler output should be placed in the $(obj) rooted tree. Since $(OBJCOPY) insists on adding the path to the generated symbol names, to ensure consistency it should be invoked from the directory where the .dtb file is located and given the input file name without the path.
This commit contains my entry for the ugliest Makefile / shell interaction competition.
---
Changes in v3:
- Move fdt files into board/<vendor>/dts
- Provide access to ARCH_CPU_DTS which is the CPU's base device tree
Changes in v4:
- Remove unused 'clean' targets in dts/Makefile (remmove *.tmp at top-level)
- Move documentation into the first 'fdt' patch in the series
- Add note about CONFIG_ARCH_DEVICE_TREE
Makefile | 5 ++ README | 11 +++- config.mk | 1 + doc/README.fdt-control | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ dts/Makefile | 103 +++++++++++++++++++++++++++++ include/common.h | 1 + 6 files changed, 291 insertions(+), 2 deletions(-) create mode 100644 doc/README.fdt-control create mode 100644 dts/Makefile
Makefile +5 -0
@@ -224,6 +224,9 @@ endif ifeq ($(CPU),ixp) LIBS += arch/arm/cpu/ixp/npe/libnpe.o endif +ifeq ($(CONFIG_OF_EMBED),y) +LIBS += dts/libdts.o +endif LIBS += arch/$(ARCH)/lib/lib$(ARCH).o LIBS += fs/cramfs/libcramfs.o fs/fat/libfat.o fs/fdos/libfdos.o fs/jffs2/libjffs2.o \ fs/reiserfs/libreiserfs.o fs/ext2/libext2fs.o fs/yaffs2/libyaffs2.o \
@@ -962,6 +965,7 @@ clobber: clean @rm -f $(obj)u-boot.kwb @rm -f $(obj)u-boot.imx @rm -f $(obj)u-boot.ubl + @rm -f $(obj)u-boot.dtb @rm -f $(obj)tools/{env/crc32.c,inca-swap-bytes} @rm -f $(obj)arch/powerpc/cpu/mpc824x/bedbug_603e.c @rm -fr $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm
@@ -969,6 +973,7 @@ clobber: clean @[ ! -d $(obj)nand_spl ] || find $(obj)nand_spl -name "*" -type l -print | xargs rm -f @[ ! -d $(obj)onenand_ipl ] || find $(obj)onenand_ipl -name "*" -type l -print | xargs rm -f @[ ! -d $(obj)mmc_spl ] || find $(obj)mmc_spl -name "*" -type l -print | xargs rm -f + @rm -f $(obj)dts/*.tmp mrproper \ distclean: clobber unconfig
README +9 -2
@@ -819,8 +819,15 @@ The following options need to be configured: experimental and only available on a few boards. The device tree is available in the global data as gd->fdt_blob. - U-Boot needs to get its device tree from somewhere. This will - be enabled in a future patch. + U-Boot needs to get its device tree from somewhere. At present + the only way is to embed it in the image with CONFIG_OF_EMBED. + + CONFIG_OF_EMBED + If this variable is defined, U-Boot will embed a device tree + binary in its image. This device tree file should be in the + board directory and called <soc>-<board>.dts. The binary file + is then picked up in board_init_f() and made available through + the global data structure as gd->blob. - Watchdog: CONFIG_WATCHDOG
config.mk +1 -0
@@ -124,6 +124,7 @@ STRIP = $(CROSS_COMPILE)strip OBJCOPY = $(CROSS_COMPILE)objcopy OBJDUMP = $(CROSS_COMPILE)objdump RANLIB = $(CROSS_COMPILE)RANLIB +DTC = dtc #########################################################################
doc/README.fdt-control new file +172 -0
172 lines not on this page · raw message
dts/Makefile new file +103 -0
103 lines not on this page · raw message
include/common.h +1 -0
@@ -270,6 +270,7 @@ int checkdram (void);int last_stage_init (void );extern ulong monitor_flash_len;int mac_read_from_eeprom (void ); +extern u8 _binary_dt_dtb_start[];/* embedded device tree blob */ /* common/flash.c */ void flash_perror (int );
Signature · 1 line
1.7.3.1
PATCH v4 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Dear Simon,
Quoted 15 lines · Simon Glass
This new option allows U-Boot to embed a binary device tree into its image to allow run-time control of peripherals. This device tree is for U-Boot's own use and is not necessarily the same one as is passed to the kernel.
The device tree compiler output should be placed in the $(obj) rooted tree. Since $(OBJCOPY) insists on adding the path to the generated symbol names, to ensure consistency it should be invoked from the directory where the .dtb file is located and given the input file name without the path.
This commit contains my entry for the ugliest
Makefile/ shell interaction competition.Signed-off-by Simon Glass<[email protected]>---
...
doc/README.fdt-control
Quoted 5 lines
doc/README.fdt-control new file +0
-0
...
Reading your README.fdt-control and browsing the source code a little for the CONFIG_OF_* options I found two questions. Sorry if I haven't read carefully enough ;)
Quoted 31 lines
doc/README.fdt-control new file +31
-0+Device Tree Control in U-Boot +============================= + +This feature provides for run-time configuration of U-Boot via a flat +device tree (fdt). U-Boot configuration has traditionally been done +using CONFIG options in the board config file. This feature aims to +make it possible for a single U-Boot binary to support multiple boards, +with the exact configuration of each board controlled by a flat device +tree (fdt). This is the approach recently taken by the ARM Linux kernel +and has been used by PowerPC for some time. + +The fdt is a convenient vehicle for implementing run-time configuration +for three reasons. Firstly it is easy to use, being a simple text file. +It is extensible since it consists of nodes and properties in a nice +hierarchical format. + +Finally, there is already excellent infrastructure for the fdt: a +compiler checks the text file and converts it to a compact binary +format, and a library is already available in U-Boot (libfdt) for +handling this format. + +The dts directory contains a Makefile for building the device tree blob +and embedding it in your U-Boot image. This is useful since it allows +U-Boot to configure itself according to what it finds there. If you have +a number of similar boards with different peripherals, you can describe +the features of each board in the device tree file, and have a single +generic source base. + +To enable this feature, add CONFIG_OF_CONTROL to your board config file. + +
...
Quoted 29 lines
doc/README.fdt-control new file +29
-0+Where do I get an fdt file for my board? +---------------------------------------- + +You may find that the Linux kernel has a suitable file. Look in the +kernel source in arch/<arch>/boot/dts. + +If not you might find other boards with suitable files that you can +modify to your needs. Look in the board directories for files with a +.dts extension. + +Failing that, you could write one from scratch yourself! + + +Configuration +------------- + +Use: + +#define CONFIG_DEFAULT_DEVICE_TREE "<name>" + +to set the filename of the device tree source. Then put your device tree +file into + + board/<vendor>/dts/<name>.dts + +This should include your CPU or SOC's device tree file, placed in +arch/<arch>/dts, and then make any adjustments required. The name of this +is CONFIG_ARCH_DEVICE_TREE.dts. +
doc/README.fdt-control line 143
Quoted 10 lines
doc/README.fdt-control new file +10
-0+If CONFIG_OF_EMBED is defined, then it will be picked up and built into +the U-Boot image (including u-boot.bin). + +If CONFIG_OF_SEPARATE is defined, then it will be built and placed in +a u-boot.dtb file alongside u-boot.bin. A common approach is then to +join the two: + + cat u-boot.bin u-boot.dtb>image.bin + +and then flash image.bin onto your board.
1. Above, the README.fdt-control talks about "make it possible for a single U-Boot binary to support multiple boards". Now, if I understood correctly, the 'Configuration' section above describes how to include/append *one* dtb. But wouldn't we need to include *multiple* dtbs to support multiple boards?
2. The section 'Where do I get an fdt file for my board' talks about taking the fdt from the Linux kernel. This is fine. Is U-Boot able to pass the included/appended (OF_EMBED/OF_SEPARATE) dtb to the Linux kernel, then, too? Or is the included/appended dtb only used for the U-Boot configuration? And the one passed to the Linux kernel has to be taken from anywhere else, additionally?
Many thanks and best regards
Dirk
P.S.: Any idea about
http://lists.denx.de/pipermail/u-boot/2012-March/120916.html
?
PATCH v4 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Hi Dirk,
Quoted 107 lines · Dirk Behme
Dear Simon,
Quoted 16 lines · Simon Glass
This new option allows U-Boot to embed a binary device tree into its image to allow run-time control of peripherals. This device tree is for U-Boot's own use and is not necessarily the same one as is passed to the kernel.
The device tree compiler output should be placed in the $(obj) rooted tree. Since $(OBJCOPY) insists on adding the path to the generated symbol names, to ensure consistency it should be invoked from the directory where the .dtb file is located and given the input file name without the path.
This commit contains my entry for the ugliest
Makefile/ shell interaction competition.Signed-off-by Simon Glass<[email protected]>---
...
doc/README.fdt-control
Quoted 5 lines
doc/README.fdt-control new file +0
-0...
Reading your README.fdt-control and browsing the source code a little for the CONFIG_OF_* options I found two questions. Sorry if I haven't read carefully enough ;)
Quoted 31 lines
doc/README.fdt-control new file +31
-0+Device Tree Control in U-Boot +============================= + +This feature provides for run-time configuration of U-Boot via a flat +device tree (fdt). U-Boot configuration has traditionally been done +using CONFIG options in the board config file. This feature aims to +make it possible for a single U-Boot binary to support multiple boards, +with the exact configuration of each board controlled by a flat device +tree (fdt). This is the approach recently taken by the ARM Linux kernel +and has been used by PowerPC for some time. + +The fdt is a convenient vehicle for implementing run-time configuration +for three reasons. Firstly it is easy to use, being a simple text file. +It is extensible since it consists of nodes and properties in a nice +hierarchical format. + +Finally, there is already excellent infrastructure for the fdt: a +compiler checks the text file and converts it to a compact binary +format, and a library is already available in U-Boot (libfdt) for +handling this format. + +The dts directory contains a Makefile for building the device tree blob +and embedding it in your U-Boot image. This is useful since it allows +U-Boot to configure itself according to what it finds there. If you have +a number of similar boards with different peripherals, you can describe +the features of each board in the device tree file, and have a single +generic source base. + +To enable this feature, add CONFIG_OF_CONTROL to your board config file. + +...
Quoted 37 lines
doc/README.fdt-control new file +37
-0+Where do I get an fdt file for my board? +---------------------------------------- + +You may find that the Linux kernel has a suitable file. Look in the +kernel source in arch/<arch>/boot/dts. + +If not you might find other boards with suitable files that you can +modify to your needs. Look in the board directories for files with a +.dts extension. + +Failing that, you could write one from scratch yourself! + + +Configuration +------------- + +Use: + +#define CONFIG_DEFAULT_DEVICE_TREE ? ? "<name>" + +to set the filename of the device tree source. Then put your device tree +file into + + ? ? ? board/<vendor>/dts/<name>.dts + +This should include your CPU or SOC's device tree file, placed in +arch/<arch>/dts, and then make any adjustments required. The name of this +is CONFIG_ARCH_DEVICE_TREE.dts. + +If CONFIG_OF_EMBED is defined, then it will be picked up and built into +the U-Boot image (including u-boot.bin). + +If CONFIG_OF_SEPARATE is defined, then it will be built and placed in +a u-boot.dtb file alongside u-boot.bin. A common approach is then to +join the two: + + ? ? ? cat u-boot.bin u-boot.dtb>image.bin
Quoted 8 lines
doc/README.fdt-control
Quoted 2 lines
doc/README.fdt-control new file +2
-0+ +and then flash image.bin onto your board.1. Above, the README.fdt-control talks about "make it possible for a single U-Boot binary to support multiple boards". Now, if I understood correctly, the 'Configuration' section above describes how to
include/append*one* dtb. But wouldn't we need to include *multiple* dtbs to support multiple boards?
The intent is that you build one u-boot.bin (same for all your boards), and then flash it along with the correct device tree binary for your board, when you flash your board.
What you ask for isn't necessarily useful for U-Boot in the same way as it is for the kernel, since there is in general no way for U-Boot to probe which hardware it has. For the kernel we can do this by having U-Boot select from the available FDTs and pass one to the kernel. For U-Boot there would need to be some sort of hardware register / strapping to select this. This would be a board-specific thing and one wonders whether it might not be better just to select the correct hardware/device tree at flashing time.
Quoted 7 lines
2. The section 'Where do I get an fdt file for my board' talks about taking the fdt from the Linux kernel. This is fine. Is U-Boot able to pass the included/appended (OF_EMBED/OF_SEPARATE) dtb to the Linux kernel, then, too? Or is the included/appended dtb only used for the U-Boot configuration? And the one passed to the Linux kernel has to be taken from anywhere else, additionally?
There is no specific support for passing the appended dtb to the kernel, although it would not be hard to add. The reason is that is is common to field-upgrade U-Boot and the kernel at different times. In fact U-Boot may never change after shipping, yet every kernel may require a new device tree binary to go with it.
Basically the intent was not to interfere in any way with the way U-Boot already selects and passes an device tree to the kernel.
Quoted 8 lines
Many thanks and best regards
Dirk
P.S.: Any idea abouthttp://lists.denx.de/pipermail/u-boot/2012-March/120916.html
Will take a look.
Quoted 4 lines
?
Regards,
Simon
PATCH v4 3/6 fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE)
In reply to Simon GlassThis adds support for an FDT to be build as a separate binary file called u-boot.dtb. This can be concatenated with the U-Boot binary to provide a device tree located at run-time by U-Boot. The Makefile is modified to provide this file in u-boot-dtb.bin.
---
Changes in v2:
- Modify Makefile to create combined U-boot/fdt (u-boot-dtb.bin)
.gitignore | 1 + Makefile | 8 ++++++++ README | 16 ++++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-)
.gitignore +1 -0
@@ -35,6 +35,7 @@ /u-boot.dis /u-boot.lds /u-boot.ubl +/u-boot.dtb # # Generated files
Makefile +8 -0
@@ -354,9 +354,17 @@ ALL-$(CONFIG_ONENAND_U_BOOT) += $(obj)u-boot-onenand.bin ONENAND_BIN ?= $(obj)onenand_ipl/onenand-ipl-2k.bin ALL-$(CONFIG_MMC_U_BOOT) += $(obj)mmc_spl/u-boot-mmc-spl.bin ALL-$(CONFIG_SPL) += $(obj)spl/u-boot-spl.bin +ALL-$(CONFIG_OF_SEPARATE) += $(obj)u-boot.dtb $(obj)u-boot-dtb.bin all: $(ALL-y) +$(obj)u-boot.dtb: $(obj)u-boot + $(MAKE) -C dts binary + mv $(obj)dts/dt.dtb $@ + +$(obj)u-boot-dtb.bin: $(obj)u-boot.bin $(obj)u-boot.dtb + cat $^ >$@ + $(obj)u-boot.hex: $(obj)u-boot $(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@
README +14 -2
@@ -819,8 +819,8 @@ The following options need to be configured: experimental and only available on a few boards. The device tree is available in the global data as gd->fdt_blob. - U-Boot needs to get its device tree from somewhere. At present - the only way is to embed it in the image with CONFIG_OF_EMBED. + U-Boot needs to get its device tree from somewhere. This can + be done using one of the two options below: CONFIG_OF_EMBED If this variable is defined, U-Boot will embed a device tree
@@ -829,6 +829,18 @@ The following options need to be configured: is then picked up in board_init_f() and made available through the global data structure as gd->blob. + CONFIG_OF_SEPARATE + If this variable is defined, U-Boot will build a device tree + binary. It will be called u-boot.dtb. Architecture-specific + code will locate it at run-time. Generally this works by: + + cat u-boot.bin u-boot.dtb >image.bin + + and in fact, U-Boot does this for you, creating a file called + u-boot-dtb.bin which is useful in the common case. You can + still use the individual files if you need something more + exotic. + - Watchdog: CONFIG_WATCHDOG If this variable is defined, it enables watchdog
Signature · 1 line
1.7.3.1
PATCH v4 4/6 fdt: ARM: Implement and verify embedded and separate device tree
In reply to Simon GlassThis locates the device tree either embedded within U-Boot or attached to the end as a separate binary.
When CONFIG_OF_CONTROL is defined, U-Boot requires a valid fdt. A check is provided for this early in initialisation.
--- arch/arm/lib/board.c | 22 ++++++++++++++++++++++ 1 files changed, 22 insertions(+), 0 deletions(-)
arch/arm/lib/board.c +22 -0
@@ -48,6 +48,7 @@#include <nand.h> #include <onenand_uboot.h> #include <mmc.h> +#include <libfdt.h> #include <post.h> #include <logbuff.h>
@@ -197,6 +198,17 @@ static int arm_pci_init(void) }#endif /* CONFIG_CMD_PCI || CONFIG_PCI */ +#ifdef CONFIG_OF_CONTROL +static int check_fdt (void ) +{ +/* We must have an fdt */ +if (fdt_check_header (gd->fdt_blob)) +panic ("No valid fdt found - please append one to U-Boot\n" +"binary or define CONFIG_OF_EMBED\n" ); +return 0 ; +} +#endif +/* * Breathe some life into the board... *
@@ -239,6 +251,9 @@ init_fnc_t *init_sequence[] = {#if defined(CONFIG_BOARD_EARLY_INIT_F ) board_early_init_f,#endif +#ifdef CONFIG_OF_CONTROL + check_fdt, +#endif timer_init, /* initialize timer */#ifdef CONFIG_FSL_ESDHC get_clocks,
@@ -276,6 +291,13 @@ void board_init_f(ulong bootflag)memset ((void *)gd,0 ,sizeof (gd_t)); gd->mon_len = _bss_end_ofs; +#ifdef CONFIG_OF_EMBED +/* Get a pointer to the FDT */ + gd->fdt_blob = _binary_dt_dtb_start; +#elif definedCONFIG_OF_SEPARATE +/* FDT is at end of image */ + gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE); +#endif for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {if ((*init_fnc_ptr)() !=0 ) {
Signature · 1 line
1.7.3.1
PATCH v4 4/6 fdt: ARM: Implement and verify embedded and separate device tree
Quoted 28 lines · Simon Glass
This locates the device tree either embedded within U-Boot or attached to the end as a separate binary.
When
CONFIG_OF_CONTROLis defined, U-Boot requires a valid fdt. A check is provided for this early in initialisation.Signed-off-by Simon Glass <[email protected]>---
arch/arm/lib/board.c| 22 ++++++++++++++++++++++1 files changed, 22 insertions(+), 0 deletions(-)arch/arm/lib/board.c +2
-0@@ -48,6 +48,7 @@#include <nand.h> #include <onenand_uboot.h> #include <mmc.h> +#include <libfdt.h> #include <post.h> #include <logbuff.h> @@ -197,6 +198,17 @@ static int arm_pci_init(void) }#endif /* CONFIG_CMD_PCI || CONFIG_PCI */ +#ifdef CONFIG_OF_CONTROL
arch/arm/lib/board.c static int arm_pci_init(void) · line 211
Quoted 10 lines
arch/arm/lib/board.c +10
-0+static int check_fdt (void ) +{ +/* We must have an fdt */ +if (fdt_check_header (gd->fdt_blob)) +panic ("No valid fdt found - please append one to U-Boot\n" +"binary or define CONFIG_OF_EMBED\n" ); +return 0 ; +} +#endif +
this isn't arm specific, maybe put in fdt_support.c
Quoted 29 lines
arch/arm/lib/board.c +10
-0/* * Breathe some life into the board... * @@ -239,6 +251,9 @@ init_fnc_t *init_sequence[] = {#if defined(CONFIG_BOARD_EARLY_INIT_F ) board_early_init_f,#endif +#ifdef CONFIG_OF_CONTROL + check_fdt, +#endif timer_init, /* initialize timer */#ifdef CONFIG_FSL_ESDHC get_clocks,@@ -276,6 +291,13 @@ void board_init_f(ulong bootflag)memset ((void *)gd,0 ,sizeof (gd_t)); gd->mon_len = _bss_end_ofs; +#ifdef CONFIG_OF_EMBED +/* Get a pointer to the FDT */ + gd->fdt_blob = _binary_dt_dtb_start; +#elif definedCONFIG_OF_SEPARATE +/* FDT is at end of image */ + gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE); +#endif for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {if ((*init_fnc_ptr)() !=0 ) {Signature · 1 line
1.7.3.1
PATCH v4 4/6 fdt: ARM: Implement and verify embedded and separate device tree
Hi Kumar,
Quoted 30 lines · Kumar Gala
Quoted 27 lines · Simon Glass
This locates the device tree either embedded within U-Boot or attached to the end as a separate binary.
When
CONFIG_OF_CONTROLis defined, U-Boot requires a valid fdt. A check is provided for this early in initialisation.Signed-off-by Simon Glass <[email protected]>---
arch/arm/lib/board.c| ? 22 ++++++++++++++++++++++1 files changed, 22 insertions(+), 0 deletions(-)arch/arm/lib/board.c +1
-0@@ -48,6 +48,7 @@#include <nand.h> #include <onenand_uboot.h> #include <mmc.h> +#include <libfdt.h> #include <post.h> #include <logbuff.h> @@ -197,6 +198,17 @@ static int arm_pci_init(void) }#endif /* CONFIG_CMD_PCI || CONFIG_PCI */
Quoted 13 lines
arch/arm/lib/board.c static int arm_pci_init(void) · line 211
Quoted 11 lines
arch/arm/lib/board.c +11
-0+#ifdef CONFIG_OF_CONTROL +static int check_fdt (void ) +{ + ? ? /* We must have an fdt */ + ? ? if (fdt_check_header(gd->fdt_blob)) + ? ? ? ? ? ? panic("No valid fdt found - please append one to U-Boot\n" + ? ? ? ? ? ? ? ? ? ? "binary or define CONFIG_OF_EMBED\n"); + ? ? return 0; +} +#endif +this isn't arm specific, maybe put in
fdt_support.c
Thanks. I have made this change in v6.
Regards,
Simon
Quoted 32 lines
Quoted 30 lines
arch/arm/lib/board.c +0
-0/* ?* Breathe some life into the board...
?*arch/arm/lib/board.c +3
-0@@ -239,6 +251,9 @@ init_fnc_t *init_sequence[] = {#if defined(CONFIG_BOARD_EARLY_INIT_F ) ? ? ? board_early_init_f,#endif +#ifdef CONFIG_OF_CONTROL + ? ? check_fdt, +#endif ? ? ?
timer_init, ? ? ? ? ? ? /* initialize timer */ #ifdefCONFIG_FSL_ESDHC
? ? ?get_clocks,arch/arm/lib/board.c +7
-1@@ -276,6 +291,13 @@ void board_init_f(ulong bootflag) ? ? ? memset((void *)gd, 0, sizeof(gd_t)); ? ? ? gd->mon_len = _bss_end_ofs; +#ifdef CONFIG_OF_EMBED + ? ? /* Get a pointer to the FDT */ + ? ? gd->fdt_blob = _binary_dt_dtb_start; +#elif definedCONFIG_OF_SEPARATE + ? ? /* FDT is at end of image */ + ? ? gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE); +#endif ? ? ? for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) { ? ? ? ? ? ? ? if ((*init_fnc_ptr)() != 0) { --1.7.3.1
PATCH v4 5/6 fdt: ARM: Add fdtcontroladdr to set device tree address in environment
In reply to Simon GlassThis adds support for a new environment variable called 'fdtcontroladdr'. If defined, the hex address is used as the address of the control fdt for U-Boot.
Note: I have not changed CONFIG_PRAM section as I already have an outstanding patch on that.
---
Changes in v3:
- Add fdtcontroladdr environment variable
README | 4 ++++ arch/arm/lib/board.c | 30 +++++++++++++++++++++++------- doc/README.fdt-control | 12 ++++++++++++ 3 files changed, 39 insertions(+), 7 deletions(-)
README +4 -0
@@ -3493,6 +3493,10 @@ List of environment variables (most likely not complete): add the information it needs into it, and the memory must be accessible by the kernel. + fdtcontroladdr- if set this is the address of the control flattened + device tree used by U-Boot when CONFIG_OF_CONTROL is + defined. + i2cfast - (PPC405GP|PPC405EP only) if set to 'y' configures Linux I2C driver for fast mode (400kHZ). This environment variable is used in
arch/arm/lib/board.c +23 -7
@@ -116,18 +116,31 @@ void blue_led_off(void) __attribute__((weak, alias("__blue_led_off")));* but let's get it working (again) first... */ +/** +* Decode the value of an environment variable and return it. +* +* @param name Name of environemnt variable +* @param base Number base to use (normally 10, or 16 for hex) +* @param default_val Default value to return if the variable is not +* found +* @return the decoded value, or default_val if not found +*/ +static int getenv_int (const char *name,int base,int default_val) +{ +char tmp[64 ];/* long enough for environment variables */ +int i =getenv_f (name, tmp,sizeof (tmp)); + +return (i >0 ) + ? (int )simple_strtoul (tmp,NULL , base) + : default_val; +} +#if defined(CONFIG_ARM_DCC ) && !defined(CONFIG_BAUDRATE )#define CONFIG_BAUDRATE 115200#endif static int init_baudrate (void ) { -char tmp[64 ];/* long enough for environment variables */ -int i =getenv_f ("baudrate" , tmp,sizeof (tmp)); - - gd->baudrate = (i >0 ) - ? (int )simple_strtoul (tmp,NULL ,10 ) - :CONFIG_BAUDRATE ; - + gd->baudrate =getenv_int ("baudrate" ,10 ,CONFIG_BAUDRATE );return (0 ); }
@@ -298,6 +311,9 @@ void board_init_f(ulong bootflag)/* FDT is at end of image */ gd->fdt_blob = (void *)(_end_ofs + _TEXT_BASE);#endif +/* Allow the early environment to override the fdt address */ + gd->fdt_blob = (void *)getenv_int ("fdtcontroladdr" ,16 , + (uintptr_t )gd->fdt_blob);for (init_fnc_ptr = init_sequence; *init_fnc_ptr; ++init_fnc_ptr) {if ((*init_fnc_ptr)() !=0 ) {
doc/README.fdt-control +12 -0
@@ -144,6 +144,18 @@ and then flash image.bin onto your board. You cannot use both of these options at the same time. +If you wish to put the fdt at a different address in memory, you can +define the "fdtcontroladdr" environment variable. This is the hex +address of the fdt binary blob, and will override either of the options. +Be aware that this environment variable is checked prior to relocation, +when only the compiled-in environment is available. Therefore it is not +possible to define this variable in the saved SPI/NAND flash +environment, for example (it will be ignored). + +To use this, put something like this in your board header file: + +#define CONFIG_EXTRA_ENV_SETTINGS "fdtcontroladdr=10000\0" + Limitations -----------
Signature · 1 line
1.7.3.1
PATCH v4 6/6 fdt: add decode helper library
In reply to Simon GlassThis library provides useful functions to drivers which want to use the fdt to control their operation. Functions are provided to:
- look up and enumerate a device type (for example assigning i2c bus 0,
i2c bus 1, etc.)
- decode basic types from the fdt, like addresses and integers
While this library is not strictly necessary, it helps to minimise the changes to a driver, in order to make it work under fdt control. Less code is required, and so the barrier to switch drivers over is lower.
Additional functions to read arrays and GPIOs could be made available here also.
---
Changes in v2:
- Add example proposed decode helper library
Changes in v3:
- Simplify decode library to remove provide only primitive functions
- Remove i2c decode function
- Rename fdt_decode to fdtdec, since it will be used a lot
- Moved fdt_decode.c to /lib
- Export almost all functions from fdtdec, to allow widespread use
- Remove use of FDT_ERR_MISSING which is not strictly needed now
Changes in v4:
- Add assert on sprintf() string length
- Rename addr_t to fdt_addr_t to make it more fdt-specific
- Remove gpio.h header in fdtdec.c which is not needed yet
include/fdtdec.h | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/Makefile | 1 + lib/fdtdec.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+), 0 deletions(-) create mode 100644 include/fdtdec.h create mode 100644 lib/fdtdec.c
include/fdtdec.h new file +122 -0
@@ -0,0 +1,122 @@ +/* +* Copyright (c) 2011 The Chromium OS Authors. +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place, Suite 330, Boston, +* MA 02111-1307 USA +*/ + + +/* +* This file contains convenience functions for decoding useful and +* enlightening information from FDTs. It is intended to be used by device +* drivers and board-specific code within U-Boot. It aims to reduce the +* amount of FDT munging required within U-Boot itself, so that driver code +* changes to support FDT are minimized. +*/ + +#include <libfdt.h> + +/* +* A typedef for a physical address. Note that fdt data is always big +* endian even on a litle endian machine. +*/ +#ifdef CONFIG_PHYS_64BIT +typedef u64 fdt_addr_t ; +#define FDT_ADDR_T_NONE (-1ULL) +#define fdt_addr_to_cpu (reg) be64_to_cpu(reg) +#else +typedef u32 fdt_addr_t ; +#define FDT_ADDR_T_NONE (-1U) +#define fdt_addr_to_cpu (reg) be32_to_cpu(reg) +#endif + +/* Information obtained about memory from the FDT */ +struct fdt_memory { +fdt_addr_t start; +fdt_addr_t end; +}; + +/** +* Compat types that we know about and for which we might have drivers. +* Each is named COMPAT_<dir>_<filename> where <dir> is the directory +* within drivers. +*/ +enum fdt_compat_id { +COMPAT_UNKNOWN , + +COMPAT_COUNT , +}; + +/** +* Find the next numbered alias for a peripheral. This is used to enumerate +* all the peripherals of a certain type. +* +* Do the first call with *upto = 0. Assuming /aliases/<name>0 exists then +* this function will return a pointer to the node the alias points to, and +* then update *upto to 1. Next time you call this function, the next node +* will be returned. +* +* All nodes returned will match the compatible ID, as it is assumed that +* all peripherals use the same driver. +* +* @param blob FDT blob to use +* @param name Root name of alias to search for +* @param id Compatible ID to look for +* @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more +*/ +int fdtdec_next_alias (const void *blob,const char *name, +enum fdt_compat_id id,int *upto); + +/** +* Look up an address property in a node and return it as an address. +* The property must hold either one address with no trailing data or +* one address with a length. This is only tested on 32-bit machines. +* +* @param blob FDT blob +* @param node node to examine +* @param prop_name name of property to find +* @return address, if found, or FDT_ADDR_T_NONE if not +*/ +fdt_addr_t fdtdec_get_addr (const void *blob,int node, +const char *prop_name); + +/** +* Look up a 32-bit integer property in a node and return it. The property +* must have at least 4 bytes of data. The value of the first cell is +* returned. +* +* @param blob FDT blob +* @param node node to examine +* @param prop_name name of property to find +* @param default_val default value to return if the property is not found +* @return integer value, if found, or default_val if not +*/ +s32 fdtdec_get_int (const void *blob,int node,const char *prop_name, +s32 default_val); + +/** +* Checks whether a node is enabled. +* This looks for a 'status' property. If this exists, then returns 1 if +* the status is 'ok' and 0 otherwise. If there is no status property, +* it returns the default value. +* +* @param blob FDT blob +* @param node node to examine +* @param default_val default value to return if no 'status' property exists +* @return integer value 0/1, if found, or default_val if not +*/ +int fdtdec_get_is_enabled (const void *blob,int node,int default_val);
lib/Makefile +1 -0
@@ -38,6 +38,7 @@ COBJS-y += crc16.o COBJS-y += crc32.o COBJS-y += display_options.o COBJS-y += errno.o +COBJS-$(CONFIG_OF_CONTROL) += fdtdec.o COBJS-$(CONFIG_GZIP) += gunzip.o COBJS-y += hashtable.o COBJS-$(CONFIG_LMB) += lmb.o
lib/fdtdec.c new file +131 -0
131 lines not on this page · raw message
Signature · 1 line
1.7.3.1
PATCH v4 6/6 fdt: add decode helper library
lib/fdtdec.c
Quoted 4 lines · On Saturday 15 October 2011 11:48:25 Simon Glass wrote:
lib/fdtdec.c new file +1
-0+static const char *compat_names[COMPAT_COUNT ] = {
static const char * const compat_names[COMPAT_COUNT] = {
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
Url : http://lists.denx.de/pipermail/u-boot/attachments/20111016/e4ccb433/attachment.pgp
PATCH v4 6/6 fdt: add decode helper library
Hi Mike,
Quoted 9 lines · Mike Frysinger
lib/fdtdec.c
Quoted 4 lines · On Saturday 15 October 2011 11:48:25 Simon Glass wrote:
lib/fdtdec.c new file +1
-0+static const char *compat_names[COMPAT_COUNT ] = {static const char * const compat_names[COMPAT_COUNT] = { -mike
Oops I missed that one - will send another version for just this patch. Thanks for spotting it.
Regards,
Simon
v4 cover Run-time configuration of U-Boot via a flat device tree (fdt)
In reply to Simon GlassDear Simon Glass,
is there going to be an updated version of this patch series?
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "The algorithm to do that is extremely nasty. You might want to mug someone with it." - M. Devine, Computer Science 340
v4 cover Run-time configuration of U-Boot via a flat device tree (fdt)
Hi Wolfgang,
Quoted 3 lines · Wolfgang Denk
Dear Simon Glass,
is there going to be an updated version of this patch series?
There was a request to move the check_fdt function into the fdtdec library, and I think it makes sense. So I will do that and send an update. I don't have any other changes ATM.
Regards,
Simon
Quoted 12 lines
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "The algorithm to do that is extremely nasty. You might want ?to ?mug someone with it." ? ? ? ? ? ? ? ? ? - M. Devine, Computer Science 340
v4 cover Run-time configuration of U-Boot via a flat device tree (fdt)
Dear Simon Glass,
Quoted 3 lines · In message <CAPnjgZ22OPHxn5DDuOLoRwaeCDeWV11FdqeqpD4e=ba9ZyfsHA@mail.gmail.com>…
There was a request to move the
check_fdtfunction into the fdtdec library, and I think it makes sense. So I will do that and send an
That was my unerstanding, too.
Quoted 1 line
update. I don't have any other changes ATM.
And that's why I asked :-)
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "To IBM, 'open' means there is a modicum of interoperability among some of their equipment." - Harv Masterson
v4 cover Run-time configuration of U-Boot via a flat device tree (fdt)
Hi Wolfgang,
Quoted 4 lines · Wolfgang Denk
Dear Simon Glass,
Quoted 1 line · In message <CAPnjgZ22OPHxn5DDuOLoRwaeCDeWV11FdqeqpD4e=ba9ZyfsHA@mail.gmail.com>…
Quoted 8 lines
Quoted 2 lines
There was a request to move the
check_fdtfunction into the fdtdec library, and I think it makes sense. So I will do that and send anThat was my unerstanding, too.
Quoted 1 line
update. I don't have any other changes ATM.
And that's why I asked :-)
OK I have sent v6 with that change.
Regards,
Simon
Quoted 12 lines
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, ? ? MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de "To IBM, 'open' means there is a modicum ?of ?interoperability ?among some of their equipment." ? ? ? ? ? ? ? ? ? ? ? ? ? ?- Harv Masterson