Skip to contentSkip to conversation

dtc: update and add raspberry pi overlay support

PATCH Superseded Peter Seiderer 3 participants 13 messages Jan 13, 2015 – Jan 18, 2015

lore
Share & tools
lore
#0 lore raw

v3 cover dtc: update and add raspberry pi overlay support

There are two different dtb files used for raspberry pi booting:
- overwrite the firmware provided videocore dtb configuration ([1])
- linux kernel dtb configuration and dtb overlays ([2])

Example for Raspberry Pi B+ and Adafruit PiTFT 320x240 TFT module with capcacitive touchscreen ([3]).

The PiTFT module has 4 buttons which can connect gpio 17, 22, 23 or 27 to GND, this means this gpios have to be configured to input with pull up termination (input is '1' with switch open, input is '0' with switch closed).

Setting the gpio parameters can be done by direct register setting (see [4] for example, similare code can be put into arch/arm/mach-bcm2708/bcm2708.c) or by the modern way, overwrite the videocore dtb boot configuration.

For the example with the 4 buttons do the following:

- get the original videocore dts file:

	$ wget http://www.raspberrypi.org/documentation/configuration/images/dt-blob.dts

- apply the following patch:

dt-blob.dts 2015-01-11 18:01:15.715903945 +0100 renamed from dt-blob.dts 2015-01-11 17:32:56.730450241 +0100 +4 -0
@@ -186,6 +186,10 @@
                   }; // pin
                   pin at p14 { function = "uart0";  termination = "no_pulling"; drive_strength_mA = < 8 >; }; // TX uart0
                   pin at p15 { function = "uart0";  termination = "pull_up"; drive_strength_mA = < 8 >; }; // RX uart0
+                  pin at p17 { function = "input"; termination = "pull_up";}; // adafruit28 - button 4
+                  pin at p22 { function = "input"; termination = "pull_up";}; // adafruit28 - button 2
+                  pin at p23 { function = "input"; termination = "pull_up";}; // adafruit28 - button 1
+                  pin at p27 { function = "input"; termination = "pull_up";}; // adafruit28 - button 3
                   pin at p28 { function = "i2c0";   termination = "pull_up";    }; // I2C 0 SDA
                   pin at p29 { function = "i2c0";   termination = "pull_up";    }; // I2C 0 SCL
                   pin at p31 { function = "output"; termination = "pull_down"; }; // LAN NRESET

- compile to dtb file:

	$ host/usr/bin/dtc -I dts -O dtb -o dt-blob.bin dt-blob.dts

- copy the resulting dt-blob.bin to the Raspberry Pi boot partition, the videocore will use it automatically

After this steps you can use the 4 buttons, for example do the following on the target (for the fist button):

	$ echo 23 > /sys/class/gpio/export
	$ while true; do echo -n "gpio-23: "; cat /sys/class/gpio/gpio23/value; sleep 2; done

The second use case is for the linux kernel dtb configuration using overlays, e.g. enable spi when using a device tree enabled Raspberry Pi linux kernel ([5]):

- use the following adafruit28-spi0.dts file:
/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2708";
   fragment at 0 {
      target = <&spi0>;
      __overlay__ {
         status = "okay";
         spidev at 0{
            spi-max-frequency = <32000000>;
         };
         spidev at 1{
            spi-max-frequency = <32000000>;
         };
      };

};
};

- compile to dtb overlay file

	$ host/usr/bin/dtc -@ -I dts -O dtb -o adafruit28-spi0.dtb adafruit28-spi0.dts

- copy the resulting adafruit28-spi0.dtb to the Raspberry Pi boot partition overlay directory and add the following line to the file config.txt on the boot partition:

device_tree_overlay=overlays/adafruit28-spi0.dtb

This will enable the spi bus used for the PiTFT 320x240 TFT module (which is otherwise disabled by default).

The same dtb overlay method is used for BeagleBone (see [6]).

[1] http://www.raspberrypi.org/documentation/configuration/pin-configuration.md
[2] https://github.com/raspberrypi/documentation/blob/master/configuration/device-tree.md
[3] http://www.adafruit.com/products/1983
[4] https://github.com/adafruit/adafruit-rpi-fbtft/commit/b4a3d8e481eae0290d5f0d3327be5624b0077c54
[5] http://lists.busybox.net/pipermail/buildroot/2015-January/116919.html
[6] https://learn.adafruit.com/introduction-to-the-beaglebone-black-device-tree/device-tree-overlays

Peter Seiderer (7):
dtc: fix project and download url
dtc: rename patches to new convention
dtc: bump version to 1.4.1
dtc: add hash
dtc: add host build
dtc: add patches for raspberry pi overlay support
linux: install dtc only in case package host dtc is not selected

 linux/linux.mk                                     |   3 +-
 package/Config.in.host                             |   1 +
 ...-extra_cflags.patch => 0002-extra-cflags.patch} |   2 +-
 .../0003-dtc-Dynamic-symbols-fixup-support.patch   | 581 +++++++++++++++++++++
 .../0004-dtc-v-takes-no-argument-drop-extra.patch  |  44 ++
 package/dtc/Config.in                              |   2 +-
 package/dtc/Config.in.host                         |   9 +
 package/dtc/dtc-separate-lib-install.patch         |  28 -
 package/dtc/dtc.hash                               |   2 +
 package/dtc/dtc.mk                                 |  27 +-
 10 files changed, 657 insertions(+), 42 deletions(-)
 rename package/dtc/{dtc-extra_cflags.patch => 0002-extra-cflags.patch} (92%)
 create mode 100644 package/dtc/0003-dtc-Dynamic-symbols-fixup-support.patch
 create mode 100644 package/dtc/0004-dtc-v-takes-no-argument-drop-extra.patch
 create mode 100644 package/dtc/Config.in.host
 delete mode 100644 package/dtc/dtc-separate-lib-install.patch
 create mode 100644 package/dtc/dtc.hash
Signature · 1 line
2.1.2
#1 lore raw

PATCH v3 1/7 dtc: fix project and download url

This fix the error:

fatal: unable to connect to git.jdl.com:
git.jdl.com[0: 208.123.73.151]: errno=Connection refused

---
Changes v2 -> v3:
- split rename patches to extra patch (suggested by Thomas Petazzoni)
- add download failure log extract (borrowed from Fabio Porcedda suggested patch)

---
 package/dtc/Config.in | 2 +-
 package/dtc/dtc.mk    | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)
package/dtc/Config.in +1 -1
index 7b02dd2..39223f7 100644
@@ -8,7 +8,7 @@ config BR2_PACKAGE_DTC
 	  Note that only the library is installed.
 	  If you want the programs, say 'y' here, and to "dtc programs", below.
 
-	  http://git.jdl.com/gitweb/?p=dtc.git  (no home page)
+	  https://git.kernel.org/cgit/utils/dtc/dtc.git
 
 if BR2_PACKAGE_DTC
 
package/dtc/dtc.mk +3 -2
index 51b5b4e..6fd5064 100644
@@ -4,8 +4,9 @@
 #
 ################################################################################
 
-DTC_VERSION = v1.4.0
-DTC_SITE = git://git.jdl.com/software/dtc.git
+DTC_VERSION = 1.4.0
+DTC_SOURCE = dtc-$(DTC_VERSION).tar.xz
+DTC_SITE = https://www.kernel.org/pub/software/utils/dtc
 DTC_LICENSE = GPLv2+/BSD-2c
 DTC_LICENSE_FILES = README.license GPL
 DTC_INSTALL_STAGING = YES
Signature · 1 line
2.1.2
#2 lore raw

PATCH v3 2/7 dtc: rename patches to new convention

In reply to Peter Seiderer
---
 .../{dtc-separate-lib-install.patch => 0001-separate-lib-install.patch}   | 0
 package/dtc/{dtc-extra_cflags.patch => 0002-extra-cflags.patch}           | 0
 2 files changed, 0 insertions(+), 0 deletions(-)
 rename package/dtc/{dtc-separate-lib-install.patch => 0001-separate-lib-install.patch} (100%)
 rename package/dtc/{dtc-extra_cflags.patch => 0002-extra-cflags.patch} (100%)
package/dtc/0001-separate-lib-install.patch renamed from package/dtc/dtc-separate-lib-install.patch +0 -0
similarity index 100%
rename from package/dtc/dtc-separate-lib-install.patch
rename to package/dtc/0001-separate-lib-install.patch
package/dtc/0002-extra-cflags.patch renamed from package/dtc/dtc-extra_cflags.patch +0 -0
similarity index 100%
rename from package/dtc/dtc-extra_cflags.patch
rename to package/dtc/0002-extra-cflags.patch
Signature · 1 line
2.1.2
#3 lore raw

PATCH v3 3/7 dtc: bump version to 1.4.1

In reply to Peter Seiderer

Patch 0001-separate-lib-install.patch is no longer needed, original Makefile already contains separate install-lib target (but build always complete default target).

Remove superfluous CFLAGS setting.

Adjust 0002-extra-cflags.patch.

---
Changes v2 -> v3:
- always use default build target, avoids build failure (suggested by Thomas Petazzoni)
- no need for extra CFLAGS setting (suggested by Thomas Petazzoni)
- split add hash to extra commit

Changes v1 -> v2:
- delete additional invalid comment

---
 package/dtc/0001-separate-lib-install.patch | 28 ----------------------------
 package/dtc/0002-extra-cflags.patch         |  2 +-
 package/dtc/dtc.mk                          | 14 ++++----------
 3 files changed, 5 insertions(+), 39 deletions(-)
 delete mode 100644 package/dtc/0001-separate-lib-install.patch
package/dtc/0001-separate-lib-install.patch deleted +0 -28
deleted file mode 100644
index c86d587..0000000
@@ -1,28 +0,0 @@
-Makefile: add a rule to only install libfdt
-
-Signed-off-by: "Yann E. MORIN" <[email protected]>
-
----
-Patch not sent upstream.
-
-It's really specific to buildroot, and is probably not
-good (aka generic) enough to be pushed upstream.
-
-diff --git a/Makefile b/Makefile
-index 1169e6c..39e7190 100644
---- a/Makefile
-+++ b/Makefile
-@@ -160,10 +160,12 @@ endif
- # intermediate target and building them again "for real"
- .SECONDARY: $(DTC_GEN_SRCS) $(CONVERT_GEN_SRCS)
- 
--install: all $(SCRIPTS)
-+install: all $(SCRIPTS) libfdt_install
- 	@$(VECHO) INSTALL
- 	$(INSTALL) -d $(DESTDIR)$(BINDIR)
- 	$(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR)
-+
-+libfdt_install: libfdt
- 	$(INSTALL) -d $(DESTDIR)$(LIBDIR)
- 	$(INSTALL) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
- 	ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname)
package/dtc/0002-extra-cflags.patch +1 -1
index 51b7957..f070692 100644
@@ -23,7 +23,7 @@ index 962f94eba661..bf6b317158cf 100644
  CPPFLAGS = -I libfdt -I .
 -WARNINGS = -Werror -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
 +WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
- 	-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls
+ 	-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow
 -CFLAGS = -g -Os -fPIC -Werror $(WARNINGS)
 +CFLAGS ?= -g -Os
 +CFLAGS += -fPIC $(WARNINGS)
package/dtc/dtc.mk +4 -10
index 6fd5064..c01fe7b 100644
@@ -4,7 +4,7 @@
 #
 ################################################################################
 
-DTC_VERSION = 1.4.0
+DTC_VERSION = 1.4.1
 DTC_SOURCE = dtc-$(DTC_VERSION).tar.xz
 DTC_SITE = https://www.kernel.org/pub/software/utils/dtc
 DTC_LICENSE = GPLv2+/BSD-2c
@@ -19,8 +19,6 @@ endef
 ifeq ($(BR2_PACKAGE_DTC_PROGRAMS),y)
 
 DTC_LICENSE += (for the library), GPLv2+ (for the executables)
-# Use default goal to build everything
-DTC_BUILD_GOAL =
 DTC_INSTALL_GOAL = install
 ifeq ($(BR2_PACKAGE_BASH),)
 DTC_POST_INSTALL_TARGET_HOOKS += DTC_POST_INSTALL_TARGET_RM_DTDIFF
@@ -28,21 +26,17 @@ endif
 
 else # $(BR2_PACKAGE_DTC_PROGRAMS) != y
 
-DTC_BUILD_GOAL = libfdt
-#?libfdt_install is our own install rule added by our patch
-DTC_INSTALL_GOAL = libfdt_install
+DTC_INSTALL_GOAL = install-lib
 
 endif # $(BR2_PACKAGE_DTC_PROGRAMS) != y
 
 define DTC_BUILD_CMDS
-	$(TARGET_CONFIGURE_OPTS)    \
-	CFLAGS="$(TARGET_CFLAGS)"   \
-	$(MAKE) -C $(@D) PREFIX=/usr $(DTC_BUILD_GOAL)
+	$(TARGET_CONFIGURE_OPTS) $(MAKE) -C $(@D) PREFIX=/usr
 endef
 
 # For staging, only the library is needed
 define DTC_INSTALL_STAGING_CMDS
-	$(MAKE) -C $(@D) DESTDIR=$(STAGING_DIR) PREFIX=/usr libfdt_install
+	$(MAKE) -C $(@D) DESTDIR=$(STAGING_DIR) PREFIX=/usr install-lib
 endef
 
 define DTC_INSTALL_TARGET_CMDS
Signature · 1 line
2.1.2
#4 lore raw

PATCH v3 4/7 dtc: add hash

In reply to Peter Seiderer
---
 package/dtc/dtc.hash | 2 ++
 1 file changed, 2 insertions(+)
 create mode 100644 package/dtc/dtc.hash
package/dtc/dtc.hash new file +2 -0
new file mode 100644
index 0000000..8b3af33
@@ -0,0 +1,2 @@
+# from https://www.kernel.org/pub/software/utils/dtc/sha256sums.asc
+sha256 77992ad8eac7b68f553d0ba58e5b51604ac803d126196c99e3ae38aaae28bb94  dtc-1.4.1.tar.xz
Signature · 1 line
2.1.2
#5 lore raw

PATCH v3 5/7 dtc: add host build

In reply to Peter Seiderer

---
Changes v2 -> v3:
- remove extra HOST_DTC_DEPENDENCIES (suggested by Thomas Petazzoni)
- no need for extra CFLAGS setting (suggested by Thomas Petazzoni)

Changes v1 -> v2:
- fix host build command (use native compiler instead of cross compiler)

---
 package/Config.in.host     |  1 +
 package/dtc/Config.in.host |  9 +++++++++
 package/dtc/dtc.mk         | 10 ++++++++++
 3 files changed, 20 insertions(+)
 create mode 100644 package/dtc/Config.in.host
package/Config.in.host +1 -0
index 94981ad..6a63e57 100644
@@ -5,6 +5,7 @@ menu "Host utilities"
 	source "package/dfu-util/Config.in.host"
 	source "package/dos2unix/Config.in.host"
 	source "package/dosfstools/Config.in.host"
+	source "package/dtc/Config.in.host"
 	source "package/e2fsprogs/Config.in.host"
 	source "package/e2tools/Config.in.host"
 	source "package/genext2fs/Config.in.host"
package/dtc/Config.in.host new file +9 -0
new file mode 100644
index 0000000..cbabf0a
@@ -0,0 +1,9 @@
+config BR2_PACKAGE_HOST_DTC
+	bool "host dtc"
+	help
+	  The Device Tree Compiler, dtc, takes as input a device-tree in
+	  a given format and outputs a device-tree in another format.
+
+	  Install host tools: dtc, convert-dtsv0, fdtdump, fdtget and fdtput.
+
+	  https://git.kernel.org/cgit/utils/dtc/dtc.git
package/dtc/dtc.mk +10 -0
index c01fe7b..b0e2f28 100644
@@ -43,4 +43,14 @@ define DTC_INSTALL_TARGET_CMDS
 	$(MAKE) -C $(@D) DESTDIR=$(TARGET_DIR) PREFIX=/usr $(DTC_INSTALL_GOAL)
 endef
 
+# host build
+define HOST_DTC_BUILD_CMDS
+	$(HOST_CONFIGURE_OPTS) $(MAKE) -C $(@D) PREFIX=/usr
+endef
+
+define HOST_DTC_INSTALL_CMDS
+	$(MAKE) -C $(@D) DESTDIR=$(HOST_DIR) PREFIX=/usr install-bin
+endef
+
 $(eval $(generic-package))
+$(eval $(host-generic-package))
Signature · 1 line
2.1.2
#6 lore raw

PATCH v3 5/7 dtc: add host build

Peter, All,

On 2015-01-13 20:40 +0100, Peter Seiderer spake thusly:

Quoted 1 line

[--SNIP--]

package/dtc/dtc.mk define DTC_INSTALL_TARGET_CMDS · line 48

Quoted 11 lines
package/dtc/dtc.mk +3 -0
index c01fe7b..b0e2f28 100644
@@ -43,4 +43,14 @@ define DTC_INSTALL_TARGET_CMDS
 	$(MAKE) -C $(@D) DESTDIR=$(TARGET_DIR) PREFIX=/usr $(DTC_INSTALL_GOAL)
 endef
 
+# host build
+define HOST_DTC_BUILD_CMDS
+	$(HOST_CONFIGURE_OPTS) $(MAKE) -C $(@D) PREFIX=/usr

This is a host tool, you should set PREFIX=$(HOST_DIR)/usr ...

package/dtc/dtc.mk define DTC_INSTALL_TARGET_CMDS · line 52

Quoted 4 lines
package/dtc/dtc.mk +4 -0
+endef
+
+define HOST_DTC_INSTALL_CMDS
+	$(MAKE) -C $(@D) DESTDIR=$(HOST_DIR) PREFIX=/usr install-bin

... ditto, and not set a DESTDIR.

Regards,
Yann E. MORIN.

Quoted 7 lines
package/dtc/dtc.mk +3 -0
+endef
+
 $(eval $(generic-package))
+$(eval $(host-generic-package))
Signature · 1 line
2.1.2
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

PATCH v3 5/7 dtc: add host build

Hello Yann,

Quoted 19 lines

Gesendet: Sonntag, 18. Januar 2015 um 17:51 Uhr
Von: "Yann E. MORIN" <[email protected]>
An: "Peter Seiderer" <[email protected]>
Cc: buildroot at busybox.net, "Fabio Porcedda" <[email protected]>, "Jeremy Kerr" <[email protected]>, "Thomas Petazzoni" <[email protected]>, "Matthew Weber" <[email protected]>
Betreff: Re: [PATCH v3 5/7] dtc: add host build

Peter, All,

On 2015-01-13 20:40 +0100, Peter Seiderer spake thusly:

Quoted 1 line

[--SNIP--]

Quoted 8 lines
package/dtc/dtc.mk +0 -0
index c01fe7b..b0e2f28 100644
@@ -43,4 +43,14 @@ define DTC_INSTALL_TARGET_CMDS
 	$(MAKE) -C $(@D) DESTDIR=$(TARGET_DIR) PREFIX=/usr $(DTC_INSTALL_GOAL)
 endef
 
Quoted 6 lines

package/dtc/dtc.mk define DTC_INSTALL_TARGET_CMDS · line 48

Quoted 3 lines
package/dtc/dtc.mk +3 -0
+# host build
+define HOST_DTC_BUILD_CMDS
+	$(HOST_CONFIGURE_OPTS) $(MAKE) -C $(@D) PREFIX=/usr

This is a host tool, you should set PREFIX=$(HOST_DIR)/usr ...

O.k. (was copy/paste from the target build command), will fix on next patch iteration...

Quoted 7 lines

package/dtc/dtc.mk define DTC_INSTALL_TARGET_CMDS · line 52

Quoted 4 lines
package/dtc/dtc.mk +4 -0
+endef
+
+define HOST_DTC_INSTALL_CMDS
+	$(MAKE) -C $(@D) DESTDIR=$(HOST_DIR) PREFIX=/usr install-bin

... ditto, and not set a DESTDIR.

O.k, will fix, thanks for review...

Regards,
Peter

Quoted 19 lines

Regards,
Yann E. MORIN.

Quoted 7 lines
package/dtc/dtc.mk +3 -0
+endef
+
 $(eval $(generic-package))
+$(eval $(host-generic-package))
Signature · 1 line
2.1.2
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#8 lore raw

PATCH v3 6/7 dtc: add patches for raspberry pi overlay support

In reply to Peter Seiderer

See [1] for documentation of raspberry pi kernel dt overlay support.

The following patches (see original download urls) where adjusted to dtc-1.4.1:

- 0003-dtc-Dynamic-symbols-fixup-support.patch
https://github.com/RobertCNelson/dtc/commit/dd6a0533e846e8d5e690a618fa35cc15a6103efb.patch

- 0004-dtc-v-takes-no-argument-drop-extra.patch
https://github.com/RobertCNelson/dtc/commit/f345d9e48c9e1169edf047de742da142cc5687bc.patch

[1] https://github.com/raspberrypi/documentation/blob/master/configuration/device-tree.md

---
 .../0003-dtc-Dynamic-symbols-fixup-support.patch   | 581 +++++++++++++++++++++
 .../0004-dtc-v-takes-no-argument-drop-extra.patch  |  44 ++
 2 files changed, 625 insertions(+)
 create mode 100644 package/dtc/0003-dtc-Dynamic-symbols-fixup-support.patch
 create mode 100644 package/dtc/0004-dtc-v-takes-no-argument-drop-extra.patch
package/dtc/0003-dtc-Dynamic-symbols-fixup-support.patch new file +581 -0
new file mode 100644
index 0000000..125cd96
@@ -0,0 +1,581 @@
+From 144952b04835af4ee235ea0735e6ba999eab559c Mon Sep 17 00:00:00 2001
+From: Pantelis Antoniou <[email protected]>
+Date: Fri, 4 Jan 2013 21:16:21 +0200
+Subject: [PATCH 3/4] dtc: Dynamic symbols & fixup support
+
+Enable the generation of symbol & fixup information for
+usage with dynamic DT loading.
+
+Passing the -@ option generates a __symbols__ node at the
+root node of the resulting blob for any node labels used.
+
+When using the /plugin/ tag all unresolved label references
+be tracked in the __fixups__ node, while all local phandle
+references will the tracked in the __local_fixups__ node.
+
+This is sufficient to implement a dynamic DT object loader.
+
+Signed-off-by: Pantelis Antoniou <[email protected]>
+Signed-off-by: Stefan Agner <[email protected]>
+
+Adjusted to dtc-1.4.1:
+Signed-off-by: Peter Seiderer <[email protected]>
+---
+ Documentation/dts-format.txt |   7 +++
+ Documentation/manual.txt     |   8 +++
+ checks.c                     | 120 +++++++++++++++++++++++++++++++++++--
+ dtc-lexer.l                  |   5 ++
+ dtc-parser.y                 |  23 ++++++-
+ dtc.c                        |   9 ++-
+ dtc.h                        |  38 ++++++++++++
+ flattree.c                   | 139 +++++++++++++++++++++++++++++++++++++++++++
+ 8 files changed, 340 insertions(+), 9 deletions(-)
+
+diff --git a/Documentation/dts-format.txt b/Documentation/dts-format.txt
+index 41741df..4da515c 100644
+--- a/Documentation/dts-format.txt
++++ b/Documentation/dts-format.txt
+@@ -115,7 +115,14 @@ Version 1 DTS files have the overall layout:
+ 
+ * C style (/* ... */) and C++ style (// ...) comments are supported.
+ 
++Device Tree Objects
++-------------------
+ 
++Using the plugin tag enables dynamic tree objects.
++
++	/plugin/;
++
++For the full details please see Documentation/dt-object-internal.txt
+ 
+ 	-- David Gibson <[email protected]>
+ 	-- Yoder Stuart <[email protected]>
+diff --git a/Documentation/manual.txt b/Documentation/manual.txt
+index 398de32..07321ff 100644
+--- a/Documentation/manual.txt
++++ b/Documentation/manual.txt
+@@ -131,6 +131,14 @@ Options:
+ 	By default the most recent version is generated.
+ 	Relevant for dtb and asm output only.
+ 
++    -@
++        Dynamic resolution mode. For non /plugin/ compilations generate
++	a __symbols__ node containing a list of all nodes with a label.
++	When /plugin/ is used, unresolved references are recorded in
++	a __fixups__ node, while local phandle references are recorded
++	in a __local_fixups__ node.
++	See Documentation/dt-object-internal.txt
++
+ 
+ The <output_version> defines what version of the "blob" format will be
+ generated.  Supported versions are 1, 2, 3, 16 and 17.  The default is
+diff --git a/checks.c b/checks.c
+index 3bf0fa4..078a50e 100644
+--- a/checks.c
++++ b/checks.c
+@@ -457,22 +457,93 @@ static void fixup_phandle_references(struct check *c, struct node *dt,
+ 				     struct node *node, struct property *prop)
+ {
+ 	struct marker *m = prop->val.markers;
++	struct fixup *f, **fp;
++	struct fixup_entry *fe, **fep;
+ 	struct node *refnode;
+ 	cell_t phandle;
++	int has_phandle_refs;
++
++	has_phandle_refs = 0;
++	for_each_marker_of_type(m, REF_PHANDLE) {
++		has_phandle_refs = 1;
++		break;
++	}
++
++	if (!has_phandle_refs)
++		return;
+ 
+ 	for_each_marker_of_type(m, REF_PHANDLE) {
+ 		assert(m->offset + sizeof(cell_t) <= prop->val.len);
+ 
+ 		refnode = get_node_by_ref(dt, m->ref);
+-		if (! refnode) {
++		if (!refnode && !symbol_fixup_support) {
+ 			FAIL(c, "Reference to non-existent node or label \"%s\"\n",
+-			     m->ref);
++				m->ref);
+ 			continue;
+ 		}
+ 
+-		phandle = get_node_phandle(dt, refnode);
+-		*((cell_t *)(prop->val.val + m->offset)) = cpu_to_fdt32(phandle);
++		if (!refnode) {
++			/* allocate fixup entry */
++			fe = xmalloc(sizeof(*fe));
++
++			fe->node = node;
++			fe->prop = prop;
++			fe->offset = m->offset;
++			fe->next = NULL;
++
++			/* search for an already existing fixup */
++			for_each_fixup(dt, f)
++				if (strcmp(f->ref, m->ref) == 0)
++					break;
++
++			/* no fixup found, add new */
++			if (f == NULL) {
++				f = xmalloc(sizeof(*f));
++				f->ref = m->ref;
++				f->entries = NULL;
++				f->next = NULL;
++
++				/* add it to the tree */
++				fp = &dt->fixups;
++				while (*fp)
++					fp = &(*fp)->next;
++				*fp = f;
++			}
++
++			/* and now append fixup entry */
++			fep = &f->entries;
++			while (*fep)
++				fep = &(*fep)->next;
++			*fep = fe;
++
++			/* mark the entry as unresolved */
++			phandle = 0xdeadbeef;
++		} else {
++			phandle = get_node_phandle(dt, refnode);
++
++			/* if it's a plugin, we need to record it */
++			if (symbol_fixup_support && dt->is_plugin) {
++
++				/* allocate a new local fixup entry */
++				fe = xmalloc(sizeof(*fe));
++
++				fe->node = node;
++				fe->prop = prop;
++				fe->offset = m->offset;
++				fe->next = NULL;
++
++				/* append it to the local fixups */
++				fep = &dt->local_fixups;
++				while (*fep)
++					fep = &(*fep)->next;
++				*fep = fe;
++			}
++		}
++
++		*((cell_t *)(prop->val.val + m->offset)) =
++			cpu_to_fdt32(phandle);
+ 	}
++
+ }
+ ERROR(phandle_references, NULL, NULL, fixup_phandle_references, NULL,
+       &duplicate_node_names, &explicit_phandles);
+@@ -651,6 +722,45 @@ static void check_obsolete_chosen_interrupt_controller(struct check *c,
+ }
+ TREE_WARNING(obsolete_chosen_interrupt_controller, NULL);
+ 
++static void check_auto_label_phandles(struct check *c, struct node *dt,
++				       struct node *node)
++{
++	struct label *l;
++	struct symbol *s, **sp;
++	int has_label;
++
++	if (!symbol_fixup_support)
++		return;
++
++	has_label = 0;
++	for_each_label(node->labels, l) {
++		has_label = 1;
++		break;
++	}
++
++	if (!has_label)
++		return;
++
++	/* force allocation of a phandle for this node */
++	(void)get_node_phandle(dt, node);
++
++	/* add the symbol */
++	for_each_label(node->labels, l) {
++
++		s = xmalloc(sizeof(*s));
++		s->label = l;
++		s->node = node;
++		s->next = NULL;
++
++		/* add it to the symbols list */
++		sp = &dt->symbols;
++		while (*sp)
++			sp = &((*sp)->next);
++		*sp = s;
++	}
++}
++NODE_WARNING(auto_label_phandles, NULL);
++
+ static struct check *check_table[] = {
+ 	&duplicate_node_names, &duplicate_property_names,
+ 	&node_name_chars, &node_name_format, &property_name_chars,
+@@ -669,6 +779,8 @@ static struct check *check_table[] = {
+ 	&avoid_default_addr_size,
+ 	&obsolete_chosen_interrupt_controller,
+ 
++	&auto_label_phandles,
++
+ 	&always_fail,
+ };
+ 
+diff --git a/dtc-lexer.l b/dtc-lexer.l
+index 0ee1caf..dd44ba2 100644
+--- a/dtc-lexer.l
++++ b/dtc-lexer.l
+@@ -113,6 +113,11 @@ static void lexical_error(const char *fmt, ...);
+ 			return DT_V1;
+ 		}
+ 
++<*>"/plugin/"	{
++			DPRINT("Keyword: /plugin/\n");
++			return DT_PLUGIN;
++		}
++
+ <*>"/memreserve/"	{
+ 			DPRINT("Keyword: /memreserve/\n");
+ 			BEGIN_DEFAULT();
+diff --git a/dtc-parser.y b/dtc-parser.y
+index ea57e0a..687ccad 100644
+--- a/dtc-parser.y
++++ b/dtc-parser.y
+@@ -19,6 +19,7 @@
+  */
+ %{
+ #include <stdio.h>
++#include <inttypes.h>
+ 
+ #include "dtc.h"
+ #include "srcpos.h"
+@@ -52,9 +53,11 @@ extern bool treesource_error;
+ 	struct node *nodelist;
+ 	struct reserve_info *re;
+ 	uint64_t integer;
++	int is_plugin;
+ }
+ 
+ %token DT_V1
++%token DT_PLUGIN
+ %token DT_MEMRESERVE
+ %token DT_LSHIFT DT_RSHIFT DT_LE DT_GE DT_EQ DT_NE DT_AND DT_OR
+ %token DT_BITS
+@@ -71,6 +74,7 @@ extern bool treesource_error;
+ 
+ %type <data> propdata
+ %type <data> propdataprefix
++%type <is_plugin> plugindecl
+ %type <re> memreserve
+ %type <re> memreserves
+ %type <array> arrayprefix
+@@ -101,10 +105,23 @@ extern bool treesource_error;
+ %%
+ 
+ sourcefile:
+-	  DT_V1 ';' memreserves devicetree
++	  DT_V1 ';' plugindecl memreserves devicetree
+ 		{
+-			the_boot_info = build_boot_info($3, $4,
+-							guess_boot_cpuid($4));
++			$5->is_plugin = $3;
++			$5->is_root = 1;
++			the_boot_info = build_boot_info($4, $5,
++							guess_boot_cpuid($5));
++		}
++	;
++
++plugindecl:
++	/* empty */
++		{
++			$$ = 0;
++		}
++	| DT_PLUGIN ';'
++		{
++			$$ = 1;
+ 		}
+ 	;
+ 
+diff --git a/dtc.c b/dtc.c
+index 8c4add6..f4d56e5 100644
+--- a/dtc.c
++++ b/dtc.c
+@@ -29,6 +29,7 @@ int reservenum;		/* Number of memory reservation slots */
+ int minsize;		/* Minimum blob size */
+ int padsize;		/* Additional padding to blob */
+ int phandle_format = PHANDLE_BOTH;	/* Use linux,phandle or phandle properties */
++int symbol_fixup_support = 0;
+ 
+ static void fill_fullpaths(struct node *tree, const char *prefix)
+ {
+@@ -51,7 +52,7 @@ static void fill_fullpaths(struct node *tree, const char *prefix)
+ #define FDT_VERSION(version)	_FDT_VERSION(version)
+ #define _FDT_VERSION(version)	#version
+ static const char usage_synopsis[] = "dtc [options] <input file>";
+-static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv";
++static const char usage_short_opts[] = "qI:O:o:V:d:R:S:p:fb:i:H:sW:E:hv:@";
+ static struct option const usage_long_opts[] = {
+ 	{"quiet",            no_argument, NULL, 'q'},
+ 	{"in-format",         a_argument, NULL, 'I'},
+@@ -69,6 +70,7 @@ static struct option const usage_long_opts[] = {
+ 	{"phandle",           a_argument, NULL, 'H'},
+ 	{"warning",           a_argument, NULL, 'W'},
+ 	{"error",             a_argument, NULL, 'E'},
++	{"symbols",           a_argument, NULL, '@'},
+ 	{"help",             no_argument, NULL, 'h'},
+ 	{"version",          no_argument, NULL, 'v'},
+ 	{NULL,               no_argument, NULL, 0x0},
+@@ -99,6 +101,7 @@ static const char * const usage_opts_help[] = {
+ 	 "\t\tboth   - Both \"linux,phandle\" and \"phandle\" properties",
+ 	"\n\tEnable/disable warnings (prefix with \"no-\")",
+ 	"\n\tEnable/disable errors (prefix with \"no-\")",
++	"\n\tSymbols and Fixups support",
+ 	"\n\tPrint this help and exit",
+ 	"\n\tPrint version and exit",
+ 	NULL,
+@@ -186,7 +189,9 @@ int main(int argc, char *argv[])
+ 		case 'E':
+ 			parse_checks_option(false, true, optarg);
+ 			break;
+-
++		case '@':
++			symbol_fixup_support = 1;
++			break;
+ 		case 'h':
+ 			usage(NULL);
+ 		default:
+diff --git a/dtc.h b/dtc.h
+index 56212c8..fe45748 100644
+--- a/dtc.h
++++ b/dtc.h
+@@ -54,6 +54,7 @@ extern int reservenum;		/* Number of memory reservation slots */
+ extern int minsize;		/* Minimum blob size */
+ extern int padsize;		/* Additional padding to blob */
+ extern int phandle_format;	/* Use linux,phandle or phandle properties */
++extern int symbol_fixup_support;/* enable symbols & fixup support */
+ 
+ #define PHANDLE_LEGACY	0x1
+ #define PHANDLE_EPAPR	0x2
+@@ -132,6 +133,25 @@ struct label {
+ 	struct label *next;
+ };
+ 
++struct fixup_entry {
++	int offset;
++	struct node *node;
++	struct property *prop;
++	struct fixup_entry *next;
++};
++
++struct fixup {
++	char *ref;
++	struct fixup_entry *entries;
++	struct fixup *next;
++};
++
++struct symbol {
++	struct label *label;
++	struct node *node;
++	struct symbol *next;
++};
++
+ struct property {
+ 	bool deleted;
+ 	char *name;
+@@ -158,6 +178,12 @@ struct node {
+ 	int addr_cells, size_cells;
+ 
+ 	struct label *labels;
++
++	int is_root;
++	int is_plugin;
++	struct fixup *fixups;
++	struct symbol *symbols;
++	struct fixup_entry *local_fixups;
+ };
+ 
+ #define for_each_label_withdel(l0, l) \
+@@ -181,6 +207,18 @@ struct node {
+ 	for_each_child_withdel(n, c) \
+ 		if (!(c)->deleted)
+ 
++#define for_each_fixup(n, f) \
++	for ((f) = (n)->fixups; (f); (f) = (f)->next)
++
++#define for_each_fixup_entry(f, fe) \
++	for ((fe) = (f)->entries; (fe); (fe) = (fe)->next)
++
++#define for_each_symbol(n, s) \
++	for ((s) = (n)->symbols; (s); (s) = (s)->next)
++
++#define for_each_local_fixup_entry(n, fe) \
++	for ((fe) = (n)->local_fixups; (fe); (fe) = (fe)->next)
++
+ void add_label(struct label **labels, char *label);
+ void delete_labels(struct label **labels);
+ 
+diff --git a/flattree.c b/flattree.c
+index bd99fa2..7f3df74 100644
+--- a/flattree.c
++++ b/flattree.c
+@@ -262,6 +262,12 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
+ 	struct property *prop;
+ 	struct node *child;
+ 	bool seen_name_prop = false;
++	struct symbol *sym;
++	struct fixup *f;
++	struct fixup_entry *fe;
++	char *name, *s;
++	const char *fullpath;
++	int namesz, nameoff, vallen;
+ 
+ 	if (tree->deleted)
+ 		return;
+@@ -310,6 +316,139 @@ static void flatten_tree(struct node *tree, struct emitter *emit,
+ 		flatten_tree(child, emit, etarget, strbuf, vi);
+ 	}
+ 
++	if (!symbol_fixup_support)
++		goto no_symbols;
++
++	/* add the symbol nodes (if any) */
++	if (tree->symbols) {
++
++		emit->beginnode(etarget, NULL);
++		emit->string(etarget, "__symbols__", 0);
++		emit->align(etarget, sizeof(cell_t));
++
++		for_each_symbol(tree, sym) {
++
++			vallen = strlen(sym->node->fullpath);
++
++			nameoff = stringtable_insert(strbuf, sym->label->label);
++
++			emit->property(etarget, NULL);
++			emit->cell(etarget, vallen + 1);
++			emit->cell(etarget, nameoff);
++
++			if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
++				emit->align(etarget, 8);
++
++			emit->string(etarget, sym->node->fullpath,
++					strlen(sym->node->fullpath));
++			emit->align(etarget, sizeof(cell_t));
++		}
++
++		emit->endnode(etarget, NULL);
++	}
++
++	/* add the fixup nodes */
++	if (tree->fixups) {
++
++		/* emit the external fixups */
++		emit->beginnode(etarget, NULL);
++		emit->string(etarget, "__fixups__", 0);
++		emit->align(etarget, sizeof(cell_t));
++
++		for_each_fixup(tree, f) {
++
++			namesz = 0;
++			for_each_fixup_entry(f, fe) {
++				fullpath = fe->node->fullpath;
++				if (fullpath[0] == '\0')
++					fullpath = "/";
++				namesz += strlen(fullpath) + 1;
++			      	namesz += strlen(fe->prop->name) + 1;
++				namesz += 32;	/* space for :<number> + '\0' */
++			}
++
++			name = xmalloc(namesz);
++
++			s = name;
++			for_each_fixup_entry(f, fe) {
++				fullpath = fe->node->fullpath;
++				if (fullpath[0] == '\0')
++					fullpath = "/";
++				snprintf(s, name + namesz - s, "%s:%s:%d",
++						fullpath,
++						fe->prop->name, fe->offset);
++				s += strlen(s) + 1;
++			}
++
++			nameoff = stringtable_insert(strbuf, f->ref);
++			vallen = s - name - 1;
++
++			emit->property(etarget, NULL);
++			emit->cell(etarget, vallen + 1);
++			emit->cell(etarget, nameoff);
++
++			if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
++				emit->align(etarget, 8);
++
++			emit->string(etarget, name, vallen);
++			emit->align(etarget, sizeof(cell_t));
++
++			free(name);
++		}
++
++		emit->endnode(etarget, tree->labels);
++	}
++
++	/* add the local fixup property */
++	if (tree->local_fixups) {
++
++		/* emit the external fixups */
++		emit->beginnode(etarget, NULL);
++		emit->string(etarget, "__local_fixups__", 0);
++		emit->align(etarget, sizeof(cell_t));
++
++		namesz = 0;
++		for_each_local_fixup_entry(tree, fe) {
++			fullpath = fe->node->fullpath;
++			if (fullpath[0] == '\0')
++				fullpath = "/";
++			namesz += strlen(fullpath) + 1;
++			namesz += strlen(fe->prop->name) + 1;
++			namesz += 32;	/* space for :<number> + '\0' */
++		}
++
++		name = xmalloc(namesz);
++
++		s = name;
++		for_each_local_fixup_entry(tree, fe) {
++			fullpath = fe->node->fullpath;
++			if (fullpath[0] == '\0')
++				fullpath = "/";
++			snprintf(s, name + namesz - s, "%s:%s:%d",
++					fullpath, fe->prop->name,
++					fe->offset);
++			s += strlen(s) + 1;
++		}
++
++		nameoff = stringtable_insert(strbuf, "fixup");
++		vallen = s - name - 1;
++
++		emit->property(etarget, NULL);
++		emit->cell(etarget, vallen + 1);
++		emit->cell(etarget, nameoff);
++
++		if ((vi->flags & FTF_VARALIGN) && vallen >= 8)
++			emit->align(etarget, 8);
++
++		emit->string(etarget, name, vallen);
++		emit->align(etarget, sizeof(cell_t));
++
++		free(name);
++
++		emit->endnode(etarget, tree->labels);
++	}
++
++no_symbols:
+ 	emit->endnode(etarget, tree->labels);
+ }
+ 
+-- 
+2.1.2
+
package/dtc/0004-dtc-v-takes-no-argument-drop-extra.patch new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
2.1.2
#9 lore raw

PATCH v3 7/7 linux: install dtc only in case package host dtc is not selected

In reply to Peter Seiderer

Suggested by Matthew Weber (see [1]) to avoid double installation of host dtc.

[1] http://lists.busybox.net/pipermail/buildroot/2015-January/117121.html

---
 linux/linux.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux/linux.mk +2 -1
index 8256641..de15650 100644
@@ -284,13 +284,14 @@ endef
 endif
 
 
+ifeq ($BR2_PACKAGE_HOST_DTC,)
 define LINUX_INSTALL_HOST_TOOLS
 	# Installing dtc (device tree compiler) as host tool, if selected
 	if grep -q "CONFIG_DTC=y" $(@D)/.config; then 	\
 		$(INSTALL) -D -m 0755 $(@D)/scripts/dtc/dtc $(HOST_DIR)/usr/bin/dtc ;	\
 	fi
 endef
-
+endif
 
 define LINUX_INSTALL_IMAGES_CMDS
 	cp $(LINUX_IMAGE_PATH) $(BINARIES_DIR)
Signature · 1 line
2.1.2
#10 lore raw

v3 cover dtc: update and add raspberry pi overlay support

In reply to Peter Seiderer

Dear Peter Seiderer,

Quoted 5 lines · Peter Seiderer

Peter Seiderer (7):
dtc: fix project and download url
dtc: rename patches to new convention
dtc: bump version to 1.4.1
dtc: add hash

I've applied those four initial patches.

Quoted 3 lines

dtc: add host build
dtc: add patches for raspberry pi overlay support
linux: install dtc only in case package host dtc is not selected

I'm not quite decided about those ones yet.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#11 lore raw

v3 cover dtc: update and add raspberry pi overlay support

In reply to Peter Seiderer

Peter, All,

On 2015-01-13 20:40 +0100, Peter Seiderer spake thusly:

Quoted 3 lines

There are two different dtb files used for raspberry pi booting:
- overwrite the firmware provided videocore dtb configuration ([1])
- linux kernel dtb configuration and dtb overlays ([2])

Well, I haven't yet tried to use overlays, but from what I understood, DTB overlays can be handled seamlessly from the RPi bootloader:

device_tree_overlay=path/to-overlay.dtb

So, is it really required that we do patch dtc for overlay support?

Instead, I would very much prefer we stick to what upstream dtc provide, and when overlay support has been merged in there, we can bump our dtc version (or backport just the overlay support if bumping is not practical).

It would be very unmaintainable to bundle overlay support in Buildroot, if upstream eventually decide to not support them, or decide to support them in a very different way. We can not afford this, I'm afraid.

In the meantime, and that's unfortunate, we won't support overlays in dtc... :-(

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#12 lore raw

v3 cover dtc: update and add raspberry pi overlay support

Hello Yann,

Quoted 9 lines

Gesendet: Sonntag, 18. Januar 2015 um 17:49 Uhr
Von: "Yann E. MORIN" <[email protected]>
An: "Peter Seiderer" <[email protected]>
Cc: buildroot at busybox.net, "Fabio Porcedda" <[email protected]>, "Jeremy Kerr" <[email protected]>, "Thomas Petazzoni" <[email protected]>, "Matthew Weber" <[email protected]>
Betreff: Re: [PATCH v3 0/7] dtc: update and add raspberry pi overlay support

Peter, All,

On 2015-01-13 20:40 +0100, Peter Seiderer spake thusly:

Quoted 9 lines
Quoted 3 lines

There are two different dtb files used for raspberry pi booting:
- overwrite the firmware provided videocore dtb configuration ([1])
- linux kernel dtb configuration and dtb overlays ([2])

Well, I haven't yet tried to use overlays, but from what I understood, DTB overlays can be handled seamlessly from the RPi bootloader:

device_tree_overlay=path/to-overlay.dtb

Yes thats the way you 'activate' a given overlay...

Quoted 2 lines

So, is it really required that we do patch dtc for overlay support?

Yes, you have to patch the dtc tool to be able to generate a suitable overlay dtb file...

Quoted 4 lines

Instead, I would very much prefer we stick to what upstream dtc provide, and when overlay support has been merged in there, we can bump our dtc version (or backport just the overlay support if bumping is not practical).

This means no overlay dtb file generation until 'official' support (do not know if the patches where ever suggested upstream)?

Quoted 5 lines

It would be very unmaintainable to bundle overlay support in Buildroot, if upstream eventually decide to not support them, or decide to support them in a very different way. We can not afford this, I'm afraid.

If this happens the 'patch' support could be dropped easily...

Quoted 3 lines

In the meantime, and that's unfortunate, we won't support overlays in dtc... :-(

Though people have to find the right patches again and again...

But I understand the point that patch care in buildroot is not easy...

Regards,
Peter

Quoted 11 lines

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'