Run-time configuration of U-Boot via a flat device tree (fdt)
Subsystems (3)
v3 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 = "disabled"'. Board device tree files should adjust only the devices they use, setting 'status = 'ok"' in each case, and leaving the existing devices alone and disabled. 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 := tegra250
This means that ARCH_CPU_DTS will point to arch/arm/dts/tegra250.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.
Changes in v2:
- Add example proposed decode helper library
- Modify Makefile to create combined U-boot/fdt (u-boot-dtb.bin)
- Add note about CONFIG_ARCH_DEVICE_TREE
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
- Add fdtcontroladdr environment variable
- Add note about CONFIG_ARCH_DEVICE_TREE
- Move fdt files into board/<vendor>/dts
- Provide access to ARCH_CPU_DTS which is the CPU's base device tree
- Rename gd->blob to gd->fdt_blob
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 embedded and separate device tree
fdt: ARM: Add fdtcontroladdr to set device tree address in
environment
fdt: add decode helper library
.gitignore | 1 + Makefile | 12 +++ 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 | 109 +++++++++++++++++++++ include/common.h | 1 + include/fdtdec.h | 122 ++++++++++++++++++++++++ lib/Makefile | 1 + lib/fdtdec.c | 131 +++++++++++++++++++++++++ 12 files changed, 642 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 v3 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 embedding it in U-Boot.
---
Changes in v3:
- Rename gd->blob to gd->fdt_blob
README | 11 +++++++++++ arch/arm/include/asm/global_data.h | 1 + 2 files changed, 12 insertions(+), 0 deletions(-)
README +11 -0
@@ -810,6 +810,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->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 v3 1/6 fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL)
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 2 lines
This adds a device tree pointer to the global data. It can be set by board code. A later commit will add support for embedding it in U-Boot.
s/it/the device-tree/?
...
Quoted 1 line
README +0
-0
...
README The following options need to be configured: · line 819
Quoted 7 lines
+- Device tree:
README +6
-0+ 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->blob.
gd->fdt_blob
Signature · 1 line
nvpublic
PATCH v3 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
Makefile | 4 ++ README | 11 ++++- config.mk | 1 + dts/Makefile | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/common.h | 1 + 5 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 dts/Makefile
Makefile +4 -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
README +9 -2
@@ -818,8 +818,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->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 #########################################################################
dts/Makefile new file +109 -0
109 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 v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 3 lines
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.
...
Quoted 1 line
dts/Makefile +0
-0
...
dts/Makefile line 49
Quoted 2 lines
+$(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
dts/Makefile +1
-0+ cat $< | $(CPP) -P $(DTS_CPPFLAGS) - >[email protected]
Couldn't that just be:
$(CPP) -P $(DTS_CPPFLAGS) $< >[email protected]
Quoted 2 lines
dts/Makefile +2
-0+ $(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} [email protected] + rm [email protected]
Signature · 1 line
nvpublic
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Hi Stephen,
Quoted 5 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 3 lines
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.
...
Quoted 11 lines
Quoted 1 line
dts/Makefile +0
-0...
Quoted 2 lines
+$(DT_BIN): $(TOPDIR)/board/$(VENDOR)/dts/$(DEVICE_TREE).dts
+ ? ? cat $< | $(CPP) -P $(DTS_CPPFLAGS) - >[email protected]Couldn't that just be:
? ? ? ?$(CPP) -P $(DTS_CPPFLAGS) $< >[email protected]
Quoted 2 lines
+ ? ? $(DTC) -R 4 -p
0x1000-O dtb -o ${DT_BIN} [email protected]
+ ? ? rm [email protected]
I did have that originally, but got this warning:
armv7a-cros-linux-gnueabi-gcc.real: warning:/home/sjg/trunk/src/third_party/u-boot/files/board/nvidia/dts/seaboard.dts:
linker input file unused because linking not done
so I fell back to doing as I have done. I think it might be because gcc normally assumes that anything it cannot understand must be a link script.
Regards,
Simon
Quoted 5 lines
--
nvpublic
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
In reply to Simon GlassSimon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 9 lines
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.
...
Quoted 21 lines
dts/Makefile new file +21
-0+process_lds = \ + $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' + +# Run the compiler and get the link script from the linker +GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 + +$(obj)dt.o: $(DT_BIN) + # We want the output format and arch. + # We also hope to win a prize for ugliest Makefile / shell interaction + # We look in the LDSCRIPT first. + # Then try the linker which should give us the answer. + # Then check it worked. + oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` ;\ + oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ + \ + [ -z $${oformat} ] && \ + oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ + [ -z $${oarch} ] && \ + oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ + \ + [ -z $${oformat} ] && \
dts/Makefile line 83
Quoted 10 lines
dts/Makefile new file +10
-0+ echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ + exit 1 || true ;\ + [ -z $${oarch} ] && \ + echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ + exit 1 || true ;\ + \ + cd $(dir ${DT_BIN}) && \ + $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ + $(notdir ${DT_BIN}) $@ + rm $(DT_BIN)
Instead of all that, can't you just run a trivial script to generate a .c file containing the data from DTB_BIN, and then use the compiler to compile that, i.e. spit out something like:
const unsigned char dtb[] = {
0xaa, 0x55, ......
};
That'd certainly drastically simplify the makefile, although waste a little more time and temp disk space.
Signature · 1 line
nvpublic
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Hi Stephen,
Quoted 47 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 9 lines
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.
...
Quoted 21 lines
(quoted diff) +21
-0+process_lds = \ + ? ? $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' + +# Run the compiler and get the link script from the linker +GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 + +$(obj)dt.o: $(DT_BIN) + ? ? # We want the output format and arch. + ? ? # We also hope to win a prize for ugliest Makefile / shell interaction + ? ? # We look in the LDSCRIPT first. + ? ? # Then try the linker which should give us the answer. + ? ? # Then check it worked. + ? ? oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` ;\ + ? ? oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \ + ? ? ? ? ? ? oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? \ + ? ? cd $(dir ${DT_BIN}) && \ + ? ? $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ + ? ? ? ? ? ? $(notdir ${DT_BIN}) $@ + ? ? rm $(DT_BIN)Instead of all that, can't you just run a trivial script to generate a .c file containing the data from
DTB_BIN, and then use the compiler to compile that, i.e. spit out something like:
Quoted 6 lines
const unsigned char dtb[] = {
?0xaa,0x55, ......
};That'd certainly drastically simplify the makefile, although waste a little more time and temp disk space.
What, and withdraw my Makefile contest entry? :-)
I feel that objcopy is designed to do exactly this, and generating C code is a roundabout way of producing an object file with data in it. The difficulty of finding out the output format/architecture is something we might clean up in U-Boot generally at some point (e.g. figure it out as part of the original 'make ..._config') in which case this would all go away.
Thoughts?
Regards,
Simon
Quoted 5 lines
--
nvpublic
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Simon Glass wrote at Thursday, October 13, 2011 3:25 PM:
Quoted 50 lines
Hi Stephen,
Quoted 47 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 9 lines
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.
...
Quoted 21 lines
(quoted diff) +21
-0+process_lds = \ + ? ? $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' + +# Run the compiler and get the link script from the linker +GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 + +$(obj)dt.o: $(DT_BIN) + ? ? # We want the output format and arch. + ? ? # We also hope to win a prize for ugliest Makefile / shell interaction + ? ? # We look in the LDSCRIPT first. + ? ? # Then try the linker which should give us the answer. + ? ? # Then check it worked. + ? ? oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` ;\ + ? ? oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \ + ? ? ? ? ? ? oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? \ + ? ? cd $(dir ${DT_BIN}) && \ + ? ? $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ + ? ? ? ? ? ? $(notdir ${DT_BIN}) $@ + ? ? rm $(DT_BIN)Instead of all that, can't you just run a trivial script to generate a .c file containing the data from
DTB_BIN, and then use the compiler to compile that, i.e. spit out something like:
Quoted 8 lines
Quoted 6 lines
const unsigned char dtb[] = {
?0xaa,0x55, ......
};That'd certainly drastically simplify the makefile, although waste a little more time and temp disk space.
What, and withdraw my
Makefilecontest entry? :-)
:-)
Quoted 8 lines
I feel that objcopy is designed to do exactly this, and generating C code is a roundabout way of producing an object file with data in it. The difficulty of finding out the output format/architecture is something we might clean up in U-Boot generally at some point (e.g. figure it out as part of the original 'make ..._config') in which case this would all go away.
Thoughts?
Looking some more, dtc has option "-O asm" which writes directly to a text file that can be assembled; there'd be no extra temp files or conversions if you used that.
Signature · 1 line
nvpublic
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Hi Stephen,
Quoted 69 lines · Stephen Warren
Simon Glass wrote at Thursday, October 13, 2011 3:25 PM:
Quoted 50 lines
Hi Stephen,
Quoted 47 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 9 lines
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.
...
Quoted 21 lines
(quoted diff) +21
-0+process_lds = \ + ? ? $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' + +# Run the compiler and get the link script from the linker +GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 + +$(obj)dt.o: $(DT_BIN) + ? ? # We want the output format and arch. + ? ? # We also hope to win a prize for ugliest Makefile / shell interaction + ? ? # We look in the LDSCRIPT first. + ? ? # Then try the linker which should give us the answer. + ? ? # Then check it worked. + ? ? oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` ;\ + ? ? oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \ + ? ? ? ? ? ? oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? \ + ? ? cd $(dir ${DT_BIN}) && \ + ? ? $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ + ? ? ? ? ? ? $(notdir ${DT_BIN}) $@ + ? ? rm $(DT_BIN)Instead of all that, can't you just run a trivial script to generate a .c file containing the data from
DTB_BIN, and then use the compiler to compile that, i.e. spit out something like:Quoted 8 lines
Quoted 6 lines
const unsigned char dtb[] = {
?0xaa,0x55, ......
};That'd certainly drastically simplify the makefile, although waste a little more time and temp disk space.
What, and withdraw my
Makefilecontest entry? :-):-)
Quoted 7 lines
I feel that objcopy is designed to do exactly this, and generating C code is a roundabout way of producing an object file with data in it. The difficulty of finding out the output format/architecture is something we might clean up in U-Boot generally at some point (e.g. figure it out as part of the original 'make ..._config') in which case this would all go away.
Quoted 5 lines
Quoted 1 line
Thoughts?
Looking some more, dtc has option "-O asm" which writes directly to a text file that can be assembled; there'd be no extra temp files or conversions if you used that.
Yes! That's much better - I will use that. I think I should still create the temp files just so that people can see what went wrong with a failed build. For example, if there is an error in the device tree file it is nice to see the exact file that was compiled, including preprocessing.
But it gets rid of the architecture stuff. I do feel that objcopy is there partly to support putting binary bobs into object files, but the reality is that it is just too ugly.
Thanks very much for looking into this and for the suggestion.
Regards,
Simon
Quoted 5 lines
--
nvpublic
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
In reply to Stephen WarrenQuoted 69 lines · Stephen Warren
Simon Glass wrote at Thursday, October 13, 2011 3:25 PM:
Quoted 50 lines
Hi Stephen,
Quoted 47 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 9 lines
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.
...
Quoted 21 lines
(quoted diff) +21
-0+process_lds = \ + ? ? $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' + +# Run the compiler and get the link script from the linker +GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 + +$(obj)dt.o: $(DT_BIN) + ? ? # We want the output format and arch. + ? ? # We also hope to win a prize for ugliest Makefile / shell interaction + ? ? # We look in the LDSCRIPT first. + ? ? # Then try the linker which should give us the answer. + ? ? # Then check it worked. + ? ? oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` ;\ + ? ? oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \ + ? ? ? ? ? ? oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? \ + ? ? cd $(dir ${DT_BIN}) && \ + ? ? $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ + ? ? ? ? ? ? $(notdir ${DT_BIN}) $@ + ? ? rm $(DT_BIN)Instead of all that, can't you just run a trivial script to generate a .c file containing the data from
DTB_BIN, and then use the compiler to compile that, i.e. spit out something like:Quoted 8 lines
Quoted 6 lines
const unsigned char dtb[] = {
?0xaa,0x55, ......
};That'd certainly drastically simplify the makefile, although waste a little more time and temp disk space.
What, and withdraw my
Makefilecontest entry? :-):-)
Quoted 7 lines
I feel that objcopy is designed to do exactly this, and generating C code is a roundabout way of producing an object file with data in it. The difficulty of finding out the output format/architecture is something we might clean up in U-Boot generally at some point (e.g. figure it out as part of the original 'make ..._config') in which case this would all go away.
Quoted 5 lines
Quoted 1 line
Thoughts?
Looking some more, dtc has option "-O asm" which writes directly to a text file that can be assembled; there'd be no extra temp files or conversions if you used that.
I recommend *not* using the asm output option. It's not nearly as well tested and it is likely to have some big-endian-isms in it that don't work well. I prefer the objcopy approach myself. That's what it is for.
g.
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
Hi Grant,
Quoted 72 lines · Grant Likely
Quoted 71 lines · Stephen Warren
Simon Glass wrote at Thursday, October 13, 2011 3:25 PM:
Quoted 50 lines
Hi Stephen,
Quoted 47 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 9 lines
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.
...
Quoted 21 lines
(quoted diff) +21
-0+process_lds = \ + ? ? $(1) | sed -r -n 's/^OUTPUT_$(2)[ ("]*([^")]*).*/\1/p' + +# Run the compiler and get the link script from the linker +GET_LDS = $(CC) $(CFLAGS) $(LDFLAGS) -Wl,--verbose 2>&1 + +$(obj)dt.o: $(DT_BIN) + ? ? # We want the output format and arch. + ? ? # We also hope to win a prize for ugliest Makefile / shell interaction + ? ? # We look in the LDSCRIPT first. + ? ? # Then try the linker which should give us the answer. + ? ? # Then check it worked. + ? ? oformat=`$(call process_lds,cat $(LDSCRIPT),FORMAT)` ;\ + ? ? oarch=`$(call process_lds,cat $(LDSCRIPT),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \ + ? ? ? ? ? ? oformat=`$(call process_lds,$(GET_LDS),FORMAT)` ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? oarch=`$(call process_lds,$(GET_LDS),ARCH)` ;\ + ? ? \ + ? ? [ -z $${oformat} ] && \Review
Quoted 10 lines
(quoted diff) +10
-0+ ? ? ? ? ? ? echo "Cannot read OUTPUT_FORMAT from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? [ -z $${oarch} ] && \ + ? ? ? ? ? ? echo "Cannot read OUTPUT_ARCH from lds file $(LDSCRIPT)" && \ + ? ? ? ? ? ? exit 1 || true ;\ + ? ? \ + ? ? cd $(dir ${DT_BIN}) && \ + ? ? $(OBJCOPY) -I binary -O $${oformat} -B $${oarch} \ + ? ? ? ? ? ? $(notdir ${DT_BIN}) $@ + ? ? rm $(DT_BIN)Instead of all that, can't you just run a trivial script to generate a .c file containing the data from
DTB_BIN, and then use the compiler to compile that, i.e. spit out something like:Quoted 8 lines
Quoted 6 lines
const unsigned char dtb[] = {
?0xaa,0x55, ......
};That'd certainly drastically simplify the makefile, although waste a little more time and temp disk space.
What, and withdraw my
Makefilecontest entry? :-):-)
Quoted 8 lines
I feel that objcopy is designed to do exactly this, and generating C code is a roundabout way of producing an object file with data in it. The difficulty of finding out the output format/architecture is something we might clean up in U-Boot generally at some point (e.g. figure it out as part of the original 'make ..._config') in which case this would all go away.
Thoughts?
Quoted 8 lines
Quoted 3 lines
Looking some more, dtc has option "-O asm" which writes directly to a text file that can be assembled; there'd be no extra temp files or conversions if you used that.
I recommend *not* using the asm output option. ?It's not nearly as well tested and it is likely to have some big-endian-isms in it that don't work well. ?I prefer the objcopy approach myself. ?That's what it is for.
Oh dear that sounds bad. The difficultly is in figuring out the arguments to objcopy (architecture and oformat). But we do need it to work reliably, so I will move back to the original approach for now.
Regards,
Simon
Quoted 3 lines
g.
PATCH v3 2/6 fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
In reply to Simon Glassdts/Makefile line 100
Quoted 8 lines · On Tuesday 11 October 2011 18:26:07 Simon Glass wrote:
dts/Makefile new file +5
-0+clean: + rm -f $(OBJS) $(LIB) + rm -f $(DT_BIN) + +distclean: clean
i don't think this actually gets used, so punt it
-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/20111013/ec529ae4/attachment.pgp
PATCH v3 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)
- Add note about CONFIG_ARCH_DEVICE_TREE
.gitignore | 1 + Makefile | 8 ++ README | 16 ++++- doc/README.fdt-control | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 doc/README.fdt-control
.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
@@ -818,8 +818,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->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
@@ -828,6 +828,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
doc/README.fdt-control new file +172 -0
172 lines not on this page · raw message
Signature · 1 line
1.7.3.1
PATCH v3 3/6 fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE)
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 11 lines
This 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
Makefileis modified to provide this file in u-boot-dtb.bin.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- ModifyMakefileto create combined U-boot/fdt (u-boot-dtb.bin)
- Add note aboutCONFIG_ARCH_DEVICE_TREE
Quoted 6 lines
.gitignore | 1 + Makefile | 8 ++ README | 16 ++++- doc/README.fdt-control | 172 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 doc/README.fdt-control
Should the documentation be in the first patch; it seems a little random to include it in one of the two somewhat equivalent patches that add build support for a DTB transport mechanism.
Signature · 1 line
nvpublic
PATCH v3 3/6 fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE)
Hi Stephen,
Quoted 19 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 11 lines
This 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
Makefileis modified to provide this file in u-boot-dtb.bin.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- ModifyMakefileto create combined U-boot/fdt (u-boot-dtb.bin)
- Add note aboutCONFIG_ARCH_DEVICE_TREEQuoted 6 lines
?.gitignore ? ? ? ? ? ? | ? ?1 + ?Makefile ? ? ? ? ? ? ? | ? ?8 ++ ?README ? ? ? ? ? ? ? ? | ? 16 ++++- ?doc/README.fdt-control | ?172 ++++++++++++++++++++++++++++++++++++++++++++++++?4 files changed, 195 insertions(+), 2 deletions(-) ?create mode 100644 doc/README.fdt-control
Quoted 3 lines
Should the documentation be in the first patch; it seems a little random to include it in one of the two somewhat equivalent patches that add build support for a DTB transport mechanism.
Unfortunately the first patch is ARM-specific so I probably should not put it there (maybe this is just a minor issue, I'm not sure). I have not done patches to enable fdt in all architectures so far and I'm not sure this is wanted / required. I will move the README up one patch to the first non-ARM-specific patch.
Regards,
Simon
Quoted 5 lines
--
nvpublic
PATCH v3 4/6 fdt: ARM: Implement 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.
---
Changes in v3:
- Add note about CONFIG_ARCH_DEVICE_TREE
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 v3 4/6 fdt: ARM: Implement embedded and separate device tree
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 5 lines
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.
The subject of this patch seems a little misleading; something more like "fdt: ARM: Check that a control fdt is present" would be more accurate.
Sorry for the trivial comments!
Signature · 1 line
nvpublic
PATCH v3 4/6 fdt: ARM: Implement embedded and separate device tree
Hi Stephen,
Quoted 9 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
Quoted 5 lines
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.The subject of this patch seems a little misleading; something more like "fdt: ARM: Check that a control fdt is present" would be more accurate.
It does also implement it. Before this, there is no code to find the device tree on ARM. But yes it also checks that it gets something valid. I will change the name to something like 'fdt: ARM: Implement and verify embedded and separate device tree'
Quoted 2 lines
Sorry for the trivial comments!
Thanks for looking at it.
Regards,
Simon
Quoted 5 lines
--
nvpublic
PATCH v3 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
@@ -3489,6 +3489,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 v3 5/6 fdt: ARM: Add fdtcontroladdr to set device tree address in environment
Quoted 11 lines · On Tuesday 11 October 2011 18:26:10 Simon Glass wrote:
arch/arm/lib/board.c +8
-0+/** +* 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
arch/arm/lib/board.c void blue_led_off(void) __attribute__((weak, alias("__blue_led_off"))); · line 136
Quoted 10 lines
arch/arm/lib/board.c +10
-0+*/ +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; +}
pretty much everyone does this with gd->baudrate. would make sense to put this into common/cmd_nvedit.c and convert all arches.
-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/20111013/6b35acb2/attachment.pgp
PATCH v3 5/6 fdt: ARM: Add fdtcontroladdr to set device tree address in environment
Hi Mike,
Quoted 18 lines · Mike Frysinger
Quoted 17 lines · On Tuesday 11 October 2011 18:26:10 Simon Glass wrote:
arch/arm/lib/board.c +14
-0+/** +* 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)); +
Quoted 9 lines
Quoted 4 lines
+ ? ? return (i > 0)
+ ? ? ? ? ? ? ? (int)simple_strtoul(tmp, NULL, base)
+ ? ? ? ? ? ? :default_val;
+}pretty much everyone does this with
gd->baudrate. ?would make sense to put this intocommon/cmd_nvedit.cand convert all arches.
-mike
I was worried someone might say that. I will take a look.
Regards,
Simon
PATCH v3 5/6 fdt: ARM: Add fdtcontroladdr to set device tree address in environment
Hi Mike,
Quoted 31 lines · Simon Glass
Hi Mike,
Quoted 18 lines · Mike Frysinger
Quoted 17 lines · On Tuesday 11 October 2011 18:26:10 Simon Glass wrote:
arch/arm/lib/board.c +14
-0+/** +* 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)); +Quoted 9 lines
Quoted 4 lines
+ ? ? return (i > 0)
+ ? ? ? ? ? ? ? (int)simple_strtoul(tmp, NULL, base)
+ ? ? ? ? ? ? :default_val;
+}pretty much everyone does this with
gd->baudrate. ?would make sense to put this intocommon/cmd_nvedit.cand convert all arches.
-mike
Quoted 1 line
I was worried someone might say that. I will take a look.
That patch series has been posted, so if it is accepted then we can remove the definition of this function from the patch series. I am going to send the fdt series against upstream/master but will happily adjust this particular patch if getenv_ulong() is accepted.
Regards,
Simon
PATCH v3 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
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 addr_t ; +#define ADDR_T_NONE (-1ULL) +#define addr_to_cpu (reg) be64_to_cpu(reg) +#else +typedef u32 addr_t ; +#define ADDR_T_NONE (-1U) +#define addr_to_cpu (reg) be32_to_cpu(reg) +#endif + +/* Information obtained about memory from the FDT */ +struct fdt_memory { +addr_t start; +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 ADDR_T_NONE if not +*/ +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 v3 6/6 fdt: add decode helper library
Quoted 6 lines · On Tuesday 11 October 2011 18:26:11 Simon Glass wrote:
include/fdtdec.h new file +3
-0+/* +* A typedef for a physical address. Note that fdt data is always big +* endian even on a litle endian machine.
include/fdtdec.h line 45
Quoted 10 lines
include/fdtdec.h new file +10
-0+*/ +#ifdef CONFIG_PHYS_64BIT +typedef u64 addr_t ; +#define ADDR_T_NONE (-1ULL) +#define addr_to_cpu (reg) be64_to_cpu(reg) +#else +typedef u32 addr_t ; +#define ADDR_T_NONE (-1U) +#define addr_to_cpu (reg) be32_to_cpu(reg) +#endif
"addr" is fairly generic. how about "fdt_addr" instead ?
lib/fdtdec.c line 28
Quoted 5 lines
lib/fdtdec.c new file +2
-0+/* we need a generic GPIO interface here */ +#include <asm/arch/gpio.h>
we have asm/gpio.h now, although i don't see this code using anything from the gpio header to need this include ...
Quoted 1 line
+static const char *compat_names[COMPAT_COUNT] = {
static const char * const compat_names[COMPAT_COUNT] = {
lib/fdtdec.c line 122
Quoted 8 lines
lib/fdtdec.c new file +8
-0+int fdtdec_next_alias (const void *blob,const char *name, +enum fdt_compat_id id,int *upto) +{ +#define MAX_STR_LEN 20 +char str[MAX_STR_LEN +20 ]; +int node, err; + +sprintf (str,"%.*s%d" ,MAX_STR_LEN , name, *upto);
where's that "20" coming from ? just arbitrarily defined ? might want to add an assert(strlen(name) <= MAX_STR_LEN).
-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/20111013/c6b28a7b/attachment.pgp
PATCH v3 6/6 fdt: add decode helper library
Hi Mike,
Quoted 4 lines · Mike Frysinger
Quoted 3 lines · On Tuesday 11 October 2011 18:26:11 Simon Glass wrote:
include/fdtdec.h new file +0
-0
Quoted 15 lines
include/fdtdec.h line 45
Quoted 13 lines
include/fdtdec.h new file +13
-0+/* +* 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 addr_t ; +#define ADDR_T_NONE (-1ULL) +#define addr_to_cpu (reg) be64_to_cpu(reg) +#else +typedef u32 addr_t ; +#define ADDR_T_NONE (-1U) +#define addr_to_cpu (reg) be32_to_cpu(reg) +#endif "addr" is fairly generic. ?how about "
fdt_addr" instead ?
OK
Quoted 9 lines
lib/fdtdec.c line 28
Quoted 6 lines
lib/fdtdec.c new file +2
-0+/* we need a generic GPIO interface here */ +#include <asm/arch/gpio.h> we have
asm/gpio.hnow, although i don't see this code using anything from the gpio header to need this include ...
Will remove it.
Quoted 5 lines
Quoted 2 lines
+static const char *compat_names[COMPAT_COUNT] = {
static const char * const compat_names[COMPAT_COUNT] = {
Quoted 13 lines
lib/fdtdec.c
Quoted 8 lines
lib/fdtdec.c new file +8
-0+int fdtdec_next_alias (const void *blob,const char *name, + ? ? ? ? ? ? enum fdt_compat_id id, int *upto) +{ +#define MAX_STR_LEN 20 + ? ? char str[MAX_STR_LEN + 20]; + ? ? int node, err; + + ? ? sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto);where's that "20" coming from ? ?just arbitrarily defined ? ?might want to add an
assert(strlen(name) <= MAX_STR_LEN).
-mike
OK. Of course I would like to use snprintf()...
Regards,
Simon
PATCH v3 6/6 fdt: add decode helper library
Quoted 14 lines · On Thursday 13 October 2011 17:28:10 Simon Glass wrote:
Quoted 12 lines · Mike Frysinger
lib/fdtdec.c line 122
Quoted 8 lines · On Tuesday 11 October 2011 18:26:11 Simon Glass wrote:
lib/fdtdec.c new file +8
-0+int fdtdec_next_alias (const void *blob,const char *name, +enum fdt_compat_id id,int *upto) +{ +#define MAX_STR_LEN 20 +char str[MAX_STR_LEN +20 ]; +int node, err; + +sprintf (str,"%.*s%d" ,MAX_STR_LEN , name, *upto);where's that "20" coming from ? just arbitrarily defined ? might want to add an
assert(strlen(name) <= MAX_STR_LEN).
Quoted 1 line
OK. Of course I would like to use
snprintf()...
i think that might be nicer anyways than %.*s
char str[40]; /* an arbitrary len */ snprintf(str, sizeof(str), "%s%d", name, *upto);
-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/20111013/0f112de4/attachment.pgp
PATCH v3 6/6 fdt: add decode helper library
Hi Mike,
Quoted 15 lines · Mike Frysinger
Quoted 14 lines · On Thursday 13 October 2011 17:28:10 Simon Glass wrote:
Quoted 12 lines · Mike Frysinger
lib/fdtdec.c
Quoted 8 lines · On Tuesday 11 October 2011 18:26:11 Simon Glass wrote:
lib/fdtdec.c new file +8
-0+int fdtdec_next_alias (const void *blob,const char *name, + ? ? ? ? ? ? enum fdt_compat_id id, int *upto) +{ +#define MAX_STR_LEN 20 + ? ? char str[MAX_STR_LEN + 20]; + ? ? int node, err; + + ? ? sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto);where's that "20" coming from ? ?just arbitrarily defined ? ?might want to add an
assert(strlen(name) <= MAX_STR_LEN).
Quoted 8 lines
Quoted 1 line
OK. Of course I would like to use
snprintf()...i think that might be nicer anyways than %.*s
? ? ? ?char str[40]; ? /* an arbitrary len */ ? ? ? ?snprintf(str, sizeof(str), "%s%d", name, *upto); -mike
Yes I agree, but we have the minor issue that snprintf() is not merged yet :-(
Regards,
Simon
PATCH v3 6/6 fdt: add decode helper library
Quoted 5 lines · On Thursday 13 October 2011 19:16:52 Simon Glass wrote:
Quoted 2 lines · Mike Frysinger
char str[40]; /* an arbitrary len */
snprintf(str, sizeof(str), "%s%d", name, *upto);Yes I agree, but we have the minor issue that
snprintf()is not merged yet
ah, good point. obviously didn't realize :).
-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/20111013/334ba38b/attachment.pgp
PATCH v3 6/6 fdt: add decode helper library
In reply to Simon GlassQuoted 27 lines · Simon Glass
This 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 integersWhile 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.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add example proposed decode helper libraryChanges in v3:
- Simplify decode library to remove provide only primitive functions
- Remove i2c decode function
- Renamefdt_decodeto fdtdec, since it will be used a lot
- Movedfdt_decode.cto /lib
- Export almost all functions from fdtdec, to allow widespread use
- Remove use ofFDT_ERR_MISSINGwhich is not strictly needed now
Quoted 6 lines
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 100644lib/fdtdec.c
I think this is the wrong approach. If we intend to go down the path of embedded a device tree we should look at produce a live tree structure that can be used like Linux has.
There are a lot of places we are manipulate device tree blobs that would be more efficient if we had a live tree structure in place.
I think that will only get worse with the addition of embedding a tree.
- k
PATCH v3 6/6 fdt: add decode helper library
Hi Kumar,
Quoted 30 lines · Kumar Gala
Quoted 27 lines · Simon Glass
This 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 integersWhile 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.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add example proposed decode helper libraryChanges in v3:
- Simplify decode library to remove provide only primitive functions
- Remove i2c decode function
- Renamefdt_decodeto fdtdec, since it will be used a lot
- Movedfdt_decode.cto /lib
- Export almost all functions from fdtdec, to allow widespread use
- Remove use ofFDT_ERR_MISSINGwhich is not strictly needed now
Quoted 8 lines
Quoted 6 lines
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 100644lib/fdtdec.cI think this is the wrong approach. ?If we intend to go down the path of embedded a device tree we should look at produce a live tree structure that can be used like Linux has.
The intent of this patch set is to provide U-Boot with a simple run-time configuration system.
Can you please explain why you want a live tree for use by U-Boot? U-Boot already has one that it passes on to Linux, and this is under control of scripts, etc., quite separate from this.
This fdt is for configuration of devices used by U-Boot itself.
What can U-Boot find out that it would want to put into this private fdt? Are you thinking of probing for devices early on and then using them later in U-Boot? If so, surely no code can exist which does this now, since this patch set is new.
Quoted 2 lines
There are a lot of places we are manipulate device tree blobs that would be more efficient if we had a live tree structure in place.
Please can you point to these? Are you sure you are not referring to the working_fdt? As I understand it this is already a live structure.
Quoted 2 lines
I think that will only get worse with the addition of embedding a tree.
I need a bit more info / understanding before I can respond to this email properly.
Regards,
Simon
Quoted 4 lines
- k
PATCH v3 6/6 fdt: add decode helper library
Hi,
Quoted 3 lines · Simon Glass
Hi Kumar,
On Fri, Oct 14, 2011 at 11:12 AM, Kumar Gala <[email protected]>
Quoted 61 lines · wrote:
Quoted 37 lines · Simon Glass
Quoted 27 lines
This 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 integersWhile 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.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add example proposed decode helper libraryChanges in v3:
- Simplify decode library to remove provide only primitive functions
- Remove i2c decode function
- Renamefdt_decodeto fdtdec, since it will be used a lot
- Movedfdt_decode.cto /lib
- Export almost all functions from fdtdec, to allow widespread use
- Remove use ofFDT_ERR_MISSINGwhich is not strictly needed nowQuoted 8 lines
include/fdtdec.h| 122
++++++++++++++++++++++++++++++++++++++++++++++++++ lib/Makefile |
1 +lib/fdtdec.c| 131
++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+), 0 deletions(-)
create mode 100644include/fdtdec.h
create mode 100644lib/fdtdec.cQuoted 3 lines
I think this is the wrong approach. If we intend to go down the path of embedded a device tree we should look at produce a live tree structure that can be used like Linux has.
The intent of this patch set is to provide U-Boot with a simple run-time configuration system.
Can you please explain why you want a live tree for use by U-Boot? U-Boot already has one that it passes on to Linux, and this is under control of scripts, etc., quite separate from this.
This fdt is for configuration of devices used by U-Boot itself.
What can U-Boot find out that it would want to put into this private fdt? Are you thinking of probing for devices early on and then using them later in U-Boot? If so, surely no code can exist which does this now, since this patch set is new.
Quoted 2 lines
There are a lot of places we are manipulate device tree blobs that would be more efficient if we had a live tree structure in place.
Please can you point to these? Are you sure you are not referring to the
working_fdt? As I understand it this is already a live structure.
Quoted 10 lines
Quoted 1 line
I think that will only get worse with the addition of embedding a tree.
I need a bit more info / understanding before I can respond to this email properly.
Regards,
SimonQuoted 1 line
- k
This would actually be helpful for us. We have switched our bootloader to make use of the FDT and use it both within our common SOC code which is linked to our U-Boot image as well as what we pass to the Linux kernel.
We use a single FDT image for both.
We currently have our FDT for each board contain all possible options and then at runtime trim the parts that are not detected at runtime. Many of our boards have pluggable networking modules for example which are supported by our U- Boot image.
-Aaron
Signature · 2 lines
Aaron Williams <[email protected]> (408) 943-7198
PATCH v3 6/6 fdt: add decode helper library
Hi Aaron,
Quoted 73 lines · Aaron Williams
Hi,
Quoted 3 lines · Simon Glass
Hi Kumar,
On Fri, Oct 14, 2011 at 11:12 AM, Kumar Gala <[email protected]>
Quoted 66 lines · wrote:
Quoted 37 lines · Simon Glass
Quoted 27 lines
This 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 integersWhile 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.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add example proposed decode helper libraryChanges in v3:
- Simplify decode library to remove provide only primitive functions
- Remove i2c decode function
- Renamefdt_decodeto fdtdec, since it will be used a lot
- Movedfdt_decode.cto /lib
- Export almost all functions from fdtdec, to allow widespread use
- Remove use ofFDT_ERR_MISSINGwhich is not strictly needed nowQuoted 8 lines
include/fdtdec.h| ?122 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/Makefile ? ? | ?1 +lib/fdtdec.c? ? | ?131 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 254 insertions(+), 0 deletions(-)
create mode 100644include/fdtdec.h
create mode 100644lib/fdtdec.cQuoted 3 lines
I think this is the wrong approach. ?If we intend to go down the path of embedded a device tree we should look at produce a live tree structure that can be used like Linux has.
The intent of this patch set is to provide U-Boot with a simple run-time configuration system.
Can you please explain why you want a live tree for use by U-Boot? U-Boot already has one that it passes on to Linux, and this is under control of scripts, etc., quite separate from this.
This fdt is for configuration of devices used by U-Boot itself.
What can U-Boot find out that it would want to put into this private fdt? Are you thinking of probing for devices early on and then using them later in U-Boot? If so, surely no code can exist which does this now, since this patch set is new.
Quoted 2 lines
There are a lot of places we are manipulate device tree blobs that would be more efficient if we had a live tree structure in place.
Please can you point to these? Are you sure you are not referring to the
working_fdt? As I understand it this is already a live structure.Quoted 1 line
I think that will only get worse with the addition of embedding a tree.
I need a bit more info / understanding before I can respond to this email properly.
Quoted 8 lines
Quoted 5 lines
Regards,
SimonQuoted 1 line
- k
This would actually be helpful for us. We have switched our bootloader to make use of the FDT and use it both within our common SOC code which is linked to our U-Boot image as well as what we pass to the Linux kernel.
Do you like the fdt with U-Boot or find it in flash somewhere?
Quoted 2 lines
We use a single FDT image for both.
This is easy enough with the current patch set in that the build system can provide the same fdt to both U-Boot and the kernel. It would also be possible to make a copy of the U-Boot one (through some new 'fdt' command), update it and pass it to the kernel. It might be a little early to do that though - at least on the ARM side many fdt things in the kernel are still in flux and there might be a desire to limit the U-Boot changes (dealing with changed fdt definitions for peripherals, etc.) forced by changes in the kernel.
Quoted 5 lines
We currently have our FDT for each board contain all possible options and then at runtime trim the parts that are not detected at runtime. Many of our boards have pluggable networking modules for example which are supported by our U- Boot image.
Sounds great. On ARM SOCs there is often not much interest in probing since it either isn't possible or isn't useful (since things are known at build time anyway). So far my patch set does not deal with a dynamic fdt - it is just a basic implementation to get started. I'm sure it can expand as need dictates.
Regards,
Simon
Quoted 7 lines
-Aaron
--
Aaron Williams <[email protected]>
?(408) 943-7198
v3 cover Run-time configuration of U-Boot via a flat device tree (fdt)
In reply to Simon GlassSimon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
...
Quoted 10 lines
and add some defines to your board (only ARM is currently supported):
#define
CONFIG_OF_CONTROL(to enable run-time config control via fdt)
#defineCONFIG_OF_EMBEDorCONFIG_OF_SEPARATE
(either build the fdt blob into U-Boot, or create a separate u-boot.dtb
and u-boot-dtb.bin)
#defineCONFIG_DEFAULT_DEVICE_TREE"<your name>"
(to specify the name of the device tree file is
board/<vendor>/dts/<your name>.dts)
Quoted 5 lines
Typically a CPU device tree include file is provided which defines all the devices available on that CPU/SOC, with each set to 'status = "disabled"'. Board device tree files should adjust only the devices they use, setting 'status = 'ok"' in each case, and leaving the existing devices alone and disabled.
s/existing/other/ in the second-to-last line? Well, I guess given this is patch 0, that's not important.
In the Linux kernel, things used to work exactly as described above, but the kernel has switched to having no "status" properties in the SoC base file (and hence everything defaults to enabled), with the per-board .dts files set 'status = "disabled"' where desired. I imagine U-Boot should follow the same practice.
I forget the exact reason for this in the kernel; it may simply have been due to precedent on PowerPC. Grant Likely would know the details.
...
Quoted 6 lines
For example, for Tegra2 we might have in
arch/arm/cpu/armv7/tegra2/config.mkthese lines:
CONFIG_ARCH_DEVICE_TREE:= tegra250This means that
ARCH_CPU_DTSwill point toarch/arm/dts/tegra250.dtsi.
In the kernel, we renamed this to tegra20; "Tegra 250" is a marketing name, whereas "Tegra 20" is an engineering name. Engineering names should be more stable, and probably fewer in number, and so are more suitable for device- tree.
(I guess that's not particularly important for this patchset, since it doesn't include tegra250.dtsi, but it'll be relevant soon I'm sure:-)
Signature · 1 line
nvpublic
v3 cover Run-time configuration of U-Boot via a flat device tree (fdt)
Hi Stephen,
Quoted 12 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
...Quoted 10 lines
and add some defines to your board (only ARM is currently supported):
?#define
CONFIG_OF_CONTROL? ? ? (to enable run-time config control via fdt) ?#defineCONFIG_OF_EMBEDorCONFIG_OF_SEPARATE
?(either build the fdt blob into U-Boot, or create a separate u-boot.dtb ? and u-boot-dtb.bin)
?#defineCONFIG_DEFAULT_DEVICE_TREE? "<your name>"
?(to specify the name of the device tree file is
? board/<vendor>/dts/<your name>.dts)
Quoted 8 lines
Quoted 5 lines
Typically a CPU device tree include file is provided which defines all the devices available on that CPU/SOC, with each set to 'status = "disabled"'. Board device tree files should adjust only the devices they use, setting 'status = 'ok"' in each case, and leaving the existing devices alone and disabled.
s/existing/other/ in the second-to-last line? Well, I guess given this is patch 0, that's not important.
Will fix.
Quoted 9 lines
In the Linux kernel, things used to work exactly as described above, but the kernel has switched to having no "status" properties in the SoC base file (and hence everything defaults to enabled), with the per-board .dts files set 'status = "disabled"' where desired. I imagine U-Boot should follow the same practice.
I forget the exact reason for this in the kernel; it may simply have been due to precedent on PowerPC. Grant Likely would know the details.
Well it's going to create a bit of work for boards that use only a subset of these 30-peripheral SOCs, but perhaps the expectation is that you would be buying a simpler SOC if you didn't need all the features.
Quoted 9 lines
...
Quoted 6 lines
For example, for Tegra2 we might have in
arch/arm/cpu/armv7/tegra2/config.mkthese lines:
CONFIG_ARCH_DEVICE_TREE:= tegra250This means that
ARCH_CPU_DTSwill point toarch/arm/dts/tegra250.dtsi.
Quoted 7 lines
In the kernel, we renamed this to tegra20; "Tegra 250" is a marketing name, whereas "Tegra 20" is an engineering name. Engineering names should be more stable, and probably fewer in number, and so are more suitable for device- tree.
(I guess that's not particularly important for this patchset, since it doesn't include
tegra250.dtsi, but it'll be relevant soon I'm sure:-)
Yes I did see that on the list. I will change the message in this patch set, and try to remember when we get to 'soon' :-)
Regards,
Simon
Quoted 5 lines
--
nvpublic
v3 cover Run-time configuration of U-Boot via a flat device tree (fdt)
Simon, Stephen,
Quoted 20 lines · Simon Glass
Hi Stephen,
Quoted 17 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
...Quoted 15 lines
and add some defines to your board (only ARM is currently supported):
?#define
CONFIG_OF_CONTROL? ? ? (to enable run-time config control via fdt) ?#defineCONFIG_OF_EMBEDorCONFIG_OF_SEPARATE
?(either build the fdt blob into U-Boot, or create a separate u-boot.dtb ? and u-boot-dtb.bin)
?#defineCONFIG_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 = "disabled"'. Board device tree files should adjust only the devices they use, setting 'status = 'ok"' in each case, and leaving the existing devices alone and disabled.
...
Quoted 7 lines
Quoted 7 lines
In the Linux kernel, things used to work exactly as described above, but the kernel has switched to having no "status" properties in the SoC base file (and hence everything defaults to enabled), with the per-board .dts files set 'status = "disabled"' where desired. I imagine U-Boot should follow the same practice.
Quoted 7 lines
Quoted 2 lines
I forget the exact reason for this in the kernel; it may simply have been due to precedent on PowerPC. Grant Likely would know the details.
Well it's going to create a bit of work for boards that use only a subset of these 30-peripheral SOCs, but perhaps the expectation is that you would be buying a simpler SOC if you didn't need all the features.
I imagine u-boot's methodology of loading drivers only as needed will prevent the unnecessary initialization of 30 drivers which are default 'status = "enabled";'. Or, am I missing something?
thx,
Jason.
v3 cover Run-time configuration of U-Boot via a flat device tree (fdt)
Hi Jason,
Quoted 34 lines · Jason
Simon, Stephen,
Quoted 20 lines · Simon Glass
Hi Stephen,
Quoted 17 lines · Stephen Warren
Simon Glass wrote at Tuesday, October 11, 2011 4:26 PM:
...Quoted 15 lines
and add some defines to your board (only ARM is currently supported):
?#define
CONFIG_OF_CONTROL? ? ? (to enable run-time config control via fdt) ?#defineCONFIG_OF_EMBEDorCONFIG_OF_SEPARATE
?(either build the fdt blob into U-Boot, or create a separate u-boot.dtb ? and u-boot-dtb.bin)
?#defineCONFIG_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 = "disabled"'. Board device tree files should adjust only the devices they use, setting 'status = 'ok"' in each case, and leaving the existing devices alone and disabled.
...
Quoted 10 lines
Quoted 9 lines
In the Linux kernel, things used to work exactly as described above, but the kernel has switched to having no "status" properties in the SoC base file (and hence everything defaults to enabled), with the per-board .dts files set 'status = "disabled"' where desired. I imagine U-Boot should follow the same practice.
I forget the exact reason for this in the kernel; it may simply have been due to precedent on PowerPC. Grant Likely would know the details.
Quoted 8 lines
Quoted 4 lines
Well it's going to create a bit of work for boards that use only a subset of these 30-peripheral SOCs, but perhaps the expectation is that you would be buying a simpler SOC if you didn't need all the features.
I imagine u-boot's methodology of loading drivers only as needed will prevent the unnecessary initialization of 30 drivers which are default 'status = "enabled";'. ?Or, am I missing something?
The glorious U-Boot driver refactor of 2015? :-) For now I don't know how this will turn out, and I will change the commit message in the next patch set.
Regards,
Simon
Quoted 5 lines
thx,
Jason.