All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt)
@ 2011-09-01 20:49 Simon Glass
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL) Simon Glass
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Simon Glass @ 2011-09-01 20:49 UTC (permalink / raw)
  To: u-boot

At present in U-Boot configuration is mostly done using CONFIG options in the
board file. This patch set 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.

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)
 #define CONFIG_DEFAULT_DEVICE_TREE	"<your name>"
     (to specify the name of the device tree file is
      board/<vendor>/<board>/<your name>.dts)

This patch set does not include any drivers which actually use the fdt. I have
some concerns about spreading fdt code around the U-Boot code base so am
thinking of having a support file which makes this easier. I can provide a
UART driver modified to use fdt if there is interest.

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.


Simon Glass (4):
  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

 .gitignore                         |    1 +
 Makefile                           |    9 ++
 README                             |   25 ++++++
 arch/arm/include/asm/global_data.h |    1 +
 arch/arm/lib/board.c               |   22 +++++
 config.mk                          |    1 +
 doc/README.fdt-control             |  168 ++++++++++++++++++++++++++++++++++++
 dts/Makefile                       |  100 +++++++++++++++++++++
 include/common.h                   |    1 +
 9 files changed, 328 insertions(+), 0 deletions(-)
 create mode 100644 doc/README.fdt-control
 create mode 100644 dts/Makefile

-- 
1.7.3.1

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL)
  2011-09-01 20:49 [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Simon Glass
@ 2011-09-01 20:49 ` Simon Glass
  2011-09-02 16:32   ` Mike Frysinger
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 2/4] fdt: Add support for embedded device tree (CONFIG_OF_EMBED) Simon Glass
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 11+ messages in thread
From: Simon Glass @ 2011-09-01 20:49 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 README                             |   11 +++++++++++
 arch/arm/include/asm/global_data.h |    1 +
 2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/README b/README
index 0886987..812805f 100644
--- a/README
+++ b/README
@@ -795,6 +795,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
diff --git a/arch/arm/include/asm/global_data.h b/arch/arm/include/asm/global_data.h
index 4fc51fd..818eced 100644
--- a/arch/arm/include/asm/global_data.h
+++ b/arch/arm/include/asm/global_data.h
@@ -73,6 +73,7 @@ typedef	struct	global_data {
 #if !(defined(CONFIG_SYS_ICACHE_OFF) && defined(CONFIG_SYS_DCACHE_OFF))
 	unsigned long	tlb_addr;
 #endif
+	const void	*blob;		/* Our device tree, NULL if none */
 	void		**jt;		/* jump table */
 	char		env_buf[32];	/* buffer for getenv() before reloc. */
 } gd_t;
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 2/4] fdt: Add support for embedded device tree (CONFIG_OF_EMBED)
  2011-09-01 20:49 [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Simon Glass
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL) Simon Glass
@ 2011-09-01 20:49 ` Simon Glass
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 3/4] fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE) Simon Glass
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2011-09-01 20:49 UTC (permalink / raw)
  To: u-boot

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 <sjg@chromium.org>
---
 Makefile         |    4 ++
 README           |   11 +++++-
 config.mk        |    1 +
 dts/Makefile     |  100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/common.h |    1 +
 5 files changed, 115 insertions(+), 2 deletions(-)
 create mode 100644 dts/Makefile

diff --git a/Makefile b/Makefile
index 03d80b7..c53d573 100644
--- a/Makefile
+++ b/Makefile
@@ -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 \
@@ -1045,6 +1048,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
diff --git a/README b/README
index 812805f..5a2f060 100644
--- a/README
+++ b/README
@@ -803,8 +803,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
diff --git a/config.mk b/config.mk
index e2b440d..6e61eb6 100644
--- a/config.mk
+++ b/config.mk
@@ -124,6 +124,7 @@ STRIP	= $(CROSS_COMPILE)strip
 OBJCOPY = $(CROSS_COMPILE)objcopy
 OBJDUMP = $(CROSS_COMPILE)objdump
 RANLIB	= $(CROSS_COMPILE)RANLIB
+DTC	= dtc
 
 #########################################################################
 
diff --git a/dts/Makefile b/dts/Makefile
new file mode 100644
index 0000000..e70a16b
--- /dev/null
+++ b/dts/Makefile
@@ -0,0 +1,100 @@
+#
+# 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 Foundatio; 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 Makefile builds the internal U-Boot fdt if CONFIG_OF_CONTROL is
+# enabled. See doc/README.fdt-control for more details.
+
+include $(TOPDIR)/config.mk
+
+LIB	= $(obj)libdts.o
+
+$(if $(CONFIG_DEFAULT_DEVICE_TREE),,\
+$(error Please define CONFIG_DEFAULT_DEVICE_TREE in your board header file))
+DEVICE_TREE = $(subst ",,$(CONFIG_DEFAULT_DEVICE_TREE))
+
+all:	$(obj).depend $(LIB)
+
+# Use a constant name for this so we can access it from C code.
+# objcopy doesn't seem to allow us to set the symbol name independently of
+# the filename.
+DT_BIN	:= $(obj)dt.dtb
+
+$(DT_BIN): $(TOPDIR)/board/$(BOARDDIR)/$(DEVICE_TREE).dts
+	$(DTC) -R 4 -p 0x1000 -O dtb -o ${DT_BIN} $<
+
+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} ] && \
+		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)
+
+OBJS-$(CONFIG_OF_EMBED)	:= dt.o
+
+COBJS	:= $(OBJS-y)
+
+OBJS	:= $(addprefix $(obj),$(COBJS))
+
+binary:	$(DT_BIN)
+
+$(LIB):	$(OBJS) $(DTB)
+	$(call cmd_link_o_target, $(OBJS))
+
+clean:
+	rm -f $(OBJS) $(LIB)
+	rm -f $(DT_BIN)
+
+distclean:	clean
+
+#########################################################################
+
+# defines $(obj).depend target
+include $(SRCTREE)/rules.mk
+
+sinclude $(obj).depend
+
+#########################################################################
diff --git a/include/common.h b/include/common.h
index 12a1074..2fd7ef5 100644
--- a/include/common.h
+++ b/include/common.h
@@ -249,6 +249,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);
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 3/4] fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE)
  2011-09-01 20:49 [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Simon Glass
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL) Simon Glass
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 2/4] fdt: Add support for embedded device tree (CONFIG_OF_EMBED) Simon Glass
@ 2011-09-01 20:49 ` Simon Glass
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 4/4] fdt: ARM: Implement embedded and separate device tree Simon Glass
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2011-09-01 20:49 UTC (permalink / raw)
  To: u-boot

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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 .gitignore             |    1 +
 Makefile               |    5 ++
 README                 |   11 +++-
 doc/README.fdt-control |  168 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 183 insertions(+), 2 deletions(-)
 create mode 100644 doc/README.fdt-control

diff --git a/.gitignore b/.gitignore
index dbf545f..c4ebd34 100644
--- a/.gitignore
+++ b/.gitignore
@@ -34,6 +34,7 @@
 /u-boot.dis
 /u-boot.lds
 /u-boot.ubl
+/u-boot.dtb
 
 #
 # Generated files
diff --git a/Makefile b/Makefile
index c53d573..3a36ef5 100644
--- a/Makefile
+++ b/Makefile
@@ -352,9 +352,14 @@ 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
 
 all:		$(ALL-y)
 
+$(obj)u-boot.dtb:	$(obj)u-boot
+		$(MAKE) -C dts binary
+		mv $(obj)dts/dt.dtb $@
+
 $(obj)u-boot.hex:	$(obj)u-boot
 		$(OBJCOPY) ${OBJCFLAGS} -O ihex $< $@
 
diff --git a/README b/README
index 5a2f060..0b8f338 100644
--- a/README
+++ b/README
@@ -803,8 +803,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
@@ -813,6 +813,13 @@ 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
+
 - Watchdog:
 		CONFIG_WATCHDOG
 		If this variable is defined, it enables watchdog
diff --git a/doc/README.fdt-control b/doc/README.fdt-control
new file mode 100644
index 0000000..dfc8f06
--- /dev/null
+++ b/doc/README.fdt-control
@@ -0,0 +1,168 @@
+#
+# 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 Foundatio; 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
+#
+
+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.
+
+
+What is a Flat Device Tree?
+---------------------------
+
+An fdt can be specified in source format as a text file. To read about
+the fdt syntax, 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
+
+There is also a mailing list:
+
+	http://lists.ozlabs.org/listinfo/devicetree-discuss
+
+In case you are wondering, OF stands for Open Firmware.
+
+
+Tools
+-----
+
+To use this feature you will need to get the device tree compiler here:
+
+	git://jdl.com/software/dtc.git
+
+For example:
+
+	$ git clone git://jdl.com/software/dtc.git
+	$ cd dtc
+	$ make
+	$ sudo make install
+
+Then run the compiler (your version will vary):
+
+	$ dtc -v
+	Version: DTC 1.2.0-g2cb4b51f
+	$ make tests
+	$ cd tests
+	$ ./run_tests.sh
+	********** TEST SUMMARY
+	*     Total testcases:	1371
+	*                PASS:	1371
+	*                FAIL:	0
+	*   Bad configuration:	0
+	* Strange test result:	0
+
+You will also find a useful ftdump utility for decoding a binary file.
+
+
+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>/<board>/<name>.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
+
+and then flash image.bin onto your board.
+
+You cannot use both of these options at the same time.
+
+
+Limitations
+-----------
+
+U-Boot is designed to build with a single architecture type and CPU
+type. So for example it is not possible to build a single ARM binary
+which runs on your AT91 and OMAP boards, relying on an fdt to configure
+the various features. This is because you must select one of
+the CPU families within arch/arm/cpu/arm926ejs (omap or at91) at build
+time. Similarly you cannot build for multiple cpu types or
+architectures.
+
+That said the complexity reduction by using fdt to support variants of
+boards which use the same SOC / CPU can be substantial.
+
+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.
+
+--
+Simon Glass <sjg@chromium.org>
+1-Sep-11
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 4/4] fdt: ARM: Implement embedded and separate device tree
  2011-09-01 20:49 [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Simon Glass
                   ` (2 preceding siblings ...)
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 3/4] fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE) Simon Glass
@ 2011-09-01 20:49 ` Simon Glass
  2011-09-02 11:42 ` [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Jerry Van Baren
  2011-09-02 16:33 ` Mike Frysinger
  5 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2011-09-01 20:49 UTC (permalink / raw)
  To: u-boot

This 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.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 arch/arm/lib/board.c |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/arch/arm/lib/board.c b/arch/arm/lib/board.c
index 14a56f6..1f4061e 100644
--- a/arch/arm/lib/board.c
+++ b/arch/arm/lib/board.c
@@ -48,6 +48,7 @@
 #include <nand.h>
 #include <onenand_uboot.h>
 #include <mmc.h>
+#include <libfdt.h>
 
 #ifdef CONFIG_BITBANGMII
 #include <miiphy.h>
@@ -195,6 +196,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->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...
  *
@@ -237,6 +249,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,
@@ -274,6 +289,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->blob = _binary_dt_dtb_start;
+#elif defined CONFIG_OF_SEPARATE
+	/* FDT is at end of image */
+	gd->blob = (void *)(_end_ofs + _TEXT_BASE);
+#endif
 
 #ifdef CONFIG_MACH_TYPE
 	gd->bd->bi_arch_number = CONFIG_MACH_TYPE; /* board id for Linux */
-- 
1.7.3.1

^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt)
  2011-09-01 20:49 [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Simon Glass
                   ` (3 preceding siblings ...)
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 4/4] fdt: ARM: Implement embedded and separate device tree Simon Glass
@ 2011-09-02 11:42 ` Jerry Van Baren
  2011-09-02 17:14   ` Simon Glass
  2011-09-02 16:33 ` Mike Frysinger
  5 siblings, 1 reply; 11+ messages in thread
From: Jerry Van Baren @ 2011-09-02 11:42 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On 09/01/2011 04:49 PM, Simon Glass wrote:
> At present in U-Boot configuration is mostly done using CONFIG options in the
> board file. This patch set 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.

Very exciting.  I've thought about doing this for years, but never had 
the ambition (or time).

[snip]

> 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)
>   #define CONFIG_DEFAULT_DEVICE_TREE	"<your name>"
>       (to specify the name of the device tree file is
>        board/<vendor>/<board>/<your name>.dts)
>
> This patch set does not include any drivers which actually use the fdt. I have
> some concerns about spreading fdt code around the U-Boot code base so am
> thinking of having a support file which makes this easier. I can provide a
> UART driver modified to use fdt if there is interest.

Please.  A concrete reference is very useful, especially for discussion.

> 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.

Sounds reasonable and practical.  One of the things u-boot struggles 
with is staying small (but it is nice to be able to make it all 
inclusive and big if you have the flash).

> While only ARM is supported in this patch series, it should be easy enough to
> add support for other architectures.

Exercise left for the students.  :-)

[snip]

Thanks!
gvb

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL)
  2011-09-01 20:49 ` [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL) Simon Glass
@ 2011-09-02 16:32   ` Mike Frysinger
  2011-09-02 17:18     ` Simon Glass
  0 siblings, 1 reply; 11+ messages in thread
From: Mike Frysinger @ 2011-09-02 16:32 UTC (permalink / raw)
  To: u-boot

On Thursday, September 01, 2011 16:49:06 Simon Glass wrote:
> --- a/arch/arm/include/asm/global_data.h
> +++ b/arch/arm/include/asm/global_data.h
>  
> +	const void	*blob;		/* Our device tree, NULL if none */

let's call it "fdt_blob" or something less generic than "blob"
-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/20110902/8b256d34/attachment.pgp 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt)
  2011-09-01 20:49 [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Simon Glass
                   ` (4 preceding siblings ...)
  2011-09-02 11:42 ` [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Jerry Van Baren
@ 2011-09-02 16:33 ` Mike Frysinger
  2011-09-02 17:06   ` Simon Glass
  5 siblings, 1 reply; 11+ messages in thread
From: Mike Frysinger @ 2011-09-02 16:33 UTC (permalink / raw)
  To: u-boot

On Thursday, September 01, 2011 16:49:05 Simon Glass wrote:
> At present in U-Boot configuration is mostly done using CONFIG options in
> the board file. This patch set 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.

i guess the important questions for u-boot: size and speed.  have you done any 
comparisons in this area ?
-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/20110902/eeb02433/attachment.pgp 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt)
  2011-09-02 16:33 ` Mike Frysinger
@ 2011-09-02 17:06   ` Simon Glass
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2011-09-02 17:06 UTC (permalink / raw)
  To: u-boot

HI Mike,

On Fri, Sep 2, 2011 at 9:33 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Thursday, September 01, 2011 16:49:05 Simon Glass wrote:
>> At present in U-Boot configuration is mostly done using CONFIG options in
>> the board file. This patch set 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.
>
> i guess the important questions for u-boot: size and speed. ?have you done any
> comparisons in this area ?

In general the main difference between compile-time and run-time
config is the device init. Rather than spreading CONFIG_ items through
the driiver, we can define a structure which holds the config. Then it
can be set up at driver init, either by assigning from CONFIG items,
or decoding values from the fdt. Using this structure could in some
cases have some small affect on code size and performance within the
driver. For example, if the driver has something like:

   for (very tight loop executed 1000 times) {
      writel(CONFIG_SOME_VALUE / 9, &periph->reg);
   }

then the compiler can work out the value at run time, whereas when the
driver is modified to use a structure:

      writel(config.some_value / 9, &periph->reg);

the compiler must actually do the calculation. I don't see much of
this in the code base though. So overall the performance difference is
small, and with a little effort can be close to zero.

In terms of code size, apart from adding the init code to decode from
the fdt, I don't see a difference. I think an fdt_decode library is a
good idea so that drivers have helper functions for doing common tasks
(higher level than the existing fdt_support library, with specific
driver decode support). That means that the fdt decode code size hit
might happen once per driver class, maybe.

Regards,
Simon

> -mike
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt)
  2011-09-02 11:42 ` [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Jerry Van Baren
@ 2011-09-02 17:14   ` Simon Glass
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2011-09-02 17:14 UTC (permalink / raw)
  To: u-boot

Hi Jerry,

On Fri, Sep 2, 2011 at 4:42 AM, Jerry Van Baren <gvb.uboot@gmail.com> wrote:
> Hi Simon,
>
> On 09/01/2011 04:49 PM, Simon Glass wrote:
>>
>> At present in U-Boot configuration is mostly done using CONFIG options in
>> the
>> board file. This patch set 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.
>
> Very exciting. ?I've thought about doing this for years, but never had the
> ambition (or time).

Thanks for your comments. Yes there was mention of it in the UBML a
few years ago:

http://lists.denx.de/pipermail/u-boot/2008-August/038052.html

where Wolfgang said:

> A much more powerful concept is to have U-Boot read and interpret the
> DT dynamically - only then can you use the same U-Boot  binary  image
> on  different board configurations, which is an important feature for
> many board vendors.

This is basically what my patch set sets out to do.

>
> [snip]
>
>> 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)
>> ?#define CONFIG_DEFAULT_DEVICE_TREE ? ?"<your name>"
>> ? ? ?(to specify the name of the device tree file is
>> ? ? ? board/<vendor>/<board>/<your name>.dts)
>>
>> This patch set does not include any drivers which actually use the fdt. I
>> have
>> some concerns about spreading fdt code around the U-Boot code base so am
>> thinking of having a support file which makes this easier. I can provide a
>> UART driver modified to use fdt if there is interest.
>
> Please. ?A concrete reference is very useful, especially for discussion.

I will try to create a driver for something for which we have a device
tree definition in the kernel. Will post to the list as an RFC.

>
>> 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.
>
> Sounds reasonable and practical. ?One of the things u-boot struggles with is
> staying small (but it is nice to be able to make it all inclusive and big if
> you have the flash).

Yes to some extent this is a halfway house, but it is a way of
introducing this feature without changing the way things currently
work. I almost feel as if there are two types of configs, and perhaps
the naming should recognize that (SELECT_ and CONFIG_?). No, I don't
want to modify all the board files...

>
>> While only ARM is supported in this patch series, it should be easy enough
>> to
>> add support for other architectures.
>
> Exercise left for the students. ?:-)

Yes - you can pretty-much just copy the ARM board.c code into your
board.c file to try this out.

Regards,
Simon

>
> [snip]
>
> Thanks!
> gvb
>

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL)
  2011-09-02 16:32   ` Mike Frysinger
@ 2011-09-02 17:18     ` Simon Glass
  0 siblings, 0 replies; 11+ messages in thread
From: Simon Glass @ 2011-09-02 17:18 UTC (permalink / raw)
  To: u-boot

Hi Mike,

On Fri, Sep 2, 2011 at 9:32 AM, Mike Frysinger <vapier@gentoo.org> wrote:
> On Thursday, September 01, 2011 16:49:06 Simon Glass wrote:
>> --- a/arch/arm/include/asm/global_data.h
>> +++ b/arch/arm/include/asm/global_data.h
>>
>> + ? ? const void ? ? ?*blob; ? ? ? ? ?/* Our device tree, NULL if none */
>
> let's call it "fdt_blob" or something less generic than "blob"
> -mike
>

OK, will change to fdt_blob within the global data.

Regards,
Simon

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2011-09-02 17:18 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-01 20:49 [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Simon Glass
2011-09-01 20:49 ` [U-Boot] [RFC PATCH 1/4] fdt: ARM: Add device tree control of U-Boot (CONFIG_OF_CONTROL) Simon Glass
2011-09-02 16:32   ` Mike Frysinger
2011-09-02 17:18     ` Simon Glass
2011-09-01 20:49 ` [U-Boot] [RFC PATCH 2/4] fdt: Add support for embedded device tree (CONFIG_OF_EMBED) Simon Glass
2011-09-01 20:49 ` [U-Boot] [RFC PATCH 3/4] fdt: Add support for a separate device tree (CONFIG_OF_SEPARATE) Simon Glass
2011-09-01 20:49 ` [U-Boot] [RFC PATCH 4/4] fdt: ARM: Implement embedded and separate device tree Simon Glass
2011-09-02 11:42 ` [U-Boot] [RFC PATCH 0/4] Run-time configuration of U-Boot via a flat device tree (fdt) Jerry Van Baren
2011-09-02 17:14   ` Simon Glass
2011-09-02 16:33 ` Mike Frysinger
2011-09-02 17:06   ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.