051d54d
From 6a09f5e80038570b15f81fdb1e5bde897e01868a Mon Sep 17 00:00:00 2001
c09f014
From: Rob Clark <robdclark@gmail.com>
c09f014
Date: Fri, 23 Jun 2017 15:36:33 -0400
051d54d
Subject: [PATCH] dm: core: also parse chosen node
c09f014
c09f014
This is the node that would contain, for example, the framebuffer setup
c09f014
by an earlier stage.
c09f014
c09f014
Signed-off-by: Rob Clark <robdclark@gmail.com>
c09f014
---
051d54d
 arch/sandbox/dts/test.dts |  7 +++++++
051d54d
 drivers/core/root.c       | 12 ++++++++++++
051d54d
 test/dm/bus.c             |  2 +-
051d54d
 test/dm/test-fdt.c        |  2 +-
051d54d
 4 files changed, 21 insertions(+), 2 deletions(-)
c09f014
051d54d
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
051d54d
index e67d428eb2..3f9e788e6c 100644
051d54d
--- a/arch/sandbox/dts/test.dts
051d54d
+++ b/arch/sandbox/dts/test.dts
051d54d
@@ -478,6 +478,13 @@
051d54d
 	wdt0: wdt@0 {
051d54d
 		compatible = "sandbox,wdt";
051d54d
 	};
051d54d
+
051d54d
+	chosen {
051d54d
+		chosen-test {
051d54d
+			compatible = "denx,u-boot-fdt-test";
051d54d
+			reg = <9 1>;
051d54d
+		};
051d54d
+	};
051d54d
 };
051d54d
 
051d54d
 #include "sandbox_pmic.dtsi"
c09f014
diff --git a/drivers/core/root.c b/drivers/core/root.c
051d54d
index 976e2c4fdd..5a1c5994f6 100644
c09f014
--- a/drivers/core/root.c
c09f014
+++ b/drivers/core/root.c
051d54d
@@ -266,6 +266,18 @@ static int dm_scan_fdt_node(struct udevice *parent, const void *blob,
051d54d
 	for (offset = fdt_first_subnode(blob, offset);
051d54d
 	     offset > 0;
051d54d
 	     offset = fdt_next_subnode(blob, offset)) {
c09f014
+
051d54d
+		/* "chosen" node isn't a device itself but may contain some: */
051d54d
+		if (!strcmp(fdt_get_name(blob, offset, NULL), "chosen")) {
051d54d
+			pr_debug("parsing subnodes of \"chosen\"\n");
c09f014
+
051d54d
+			err = dm_scan_fdt_node(parent, blob, offset,
051d54d
+					       pre_reloc_only);
051d54d
+			if (err && !ret)
051d54d
+				ret = err;
051d54d
+			continue;
051d54d
+		}
c09f014
+
051d54d
 		if (pre_reloc_only &&
051d54d
 		    !dm_fdt_pre_reloc(blob, offset))
051d54d
 			continue;
051d54d
diff --git a/test/dm/bus.c b/test/dm/bus.c
051d54d
index 7006d4163d..1da398ae3a 100644
051d54d
--- a/test/dm/bus.c
051d54d
+++ b/test/dm/bus.c
051d54d
@@ -105,7 +105,7 @@ UCLASS_DRIVER(testbus) = {
051d54d
 /* Test that we can probe for children */
051d54d
 static int dm_test_bus_children(struct unit_test_state *uts)
051d54d
 {
051d54d
-	int num_devices = 6;
051d54d
+	int num_devices = 7;
051d54d
 	struct udevice *bus;
051d54d
 	struct uclass *uc;
051d54d
 
051d54d
diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
051d54d
index dcc2ef8b65..920ccbf016 100644
051d54d
--- a/test/dm/test-fdt.c
051d54d
+++ b/test/dm/test-fdt.c
051d54d
@@ -167,7 +167,7 @@ int dm_check_devices(struct unit_test_state *uts, int num_devices)
051d54d
 /* Test that FDT-based binding works correctly */
051d54d
 static int dm_test_fdt(struct unit_test_state *uts)
051d54d
 {
051d54d
-	const int num_devices = 6;
051d54d
+	const int num_devices = 7;
051d54d
 	struct udevice *dev;
051d54d
 	struct uclass *uc;
051d54d
 	int ret;
c09f014
051d54d
From 310feda7f7f40afbb26a158183e16c2c46eea28a Mon Sep 17 00:00:00 2001
c09f014
From: Rob Clark <robdclark@gmail.com>
c09f014
Date: Thu, 3 Aug 2017 09:52:14 -0400
051d54d
Subject: [PATCH] fdtdec: allow board to provide fdt for CONFIG_OF_SEPARATE
c09f014
c09f014
Similar to CONFIG_OF_BOARD, but in this case the fdt is still built by
c09f014
u-boot build.  This allows the board to patch the fdt, etc.
c09f014
c09f014
In the specific case of dragonboard 410c, we pass the u-boot generated
c09f014
fdt to the previous stage of bootloader (by embedding it in the
c09f014
u-boot.img that is loaded by lk/aboot), which patches the fdt and passes
c09f014
it back to u-boot.
c09f014
c09f014
Signed-off-by: Rob Clark <robdclark@gmail.com>
c09f014
---
c09f014
 include/fdtdec.h |  3 ++-
051d54d
 lib/fdtdec.c     | 35 +++++++++++++++++++++++------------
051d54d
 2 files changed, 25 insertions(+), 13 deletions(-)
c09f014
c09f014
diff --git a/include/fdtdec.h b/include/fdtdec.h
051d54d
index 1ba02be8e1..c5acb8dae1 100644
c09f014
--- a/include/fdtdec.h
c09f014
+++ b/include/fdtdec.h
c09f014
@@ -988,7 +988,8 @@ int fdtdec_setup(void);
c09f014
 
c09f014
 /**
c09f014
  * Board-specific FDT initialization. Returns the address to a device tree blob.
c09f014
- * Called when CONFIG_OF_BOARD is defined.
c09f014
+ * Called when CONFIG_OF_BOARD is defined, or if CONFIG_OF_SEPARATE is defined
c09f014
+ * and the board implements it.
c09f014
  */
c09f014
 void *board_fdt_blob_setup(void);
c09f014
 
c09f014
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
051d54d
index 45f3fe7baf..15bd9b2572 100644
c09f014
--- a/lib/fdtdec.c
c09f014
+++ b/lib/fdtdec.c
051d54d
@@ -1258,6 +1258,28 @@ static int uncompress_blob(const void *src, ulong sz_src, void **dstp)
051d54d
 # endif
c09f014
 #endif
c09f014
 
c09f014
+#ifdef CONFIG_OF_SEPARATE
c09f014
+/*
c09f014
+ * For CONFIG_OF_SEPARATE, the board may optionally implement this to
c09f014
+ * provide and/or fixup the fdt.
c09f014
+ */
c09f014
+__weak void *board_fdt_blob_setup(void)
051d54d
+{
c09f014
+	void *fdt_blob = NULL;
c09f014
+#ifdef CONFIG_SPL_BUILD
051d54d
+	/* FDT is at end of BSS unless it is in a different memory region */
051d54d
+	if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
c09f014
+		fdt_blob = (ulong *)&_image_binary_end;
051d54d
+	else
c09f014
+		fdt_blob = (ulong *)&__bss_end;
c09f014
+#else
051d54d
+	/* FDT is at end of image */
c09f014
+	fdt_blob = (ulong *)&_end;
051d54d
+#endif
c09f014
+	return fdt_blob;
c09f014
+}
c09f014
+#endif
c09f014
+
051d54d
 int fdtdec_setup(void)
051d54d
 {
051d54d
 #if CONFIG_IS_ENABLED(OF_CONTROL)
051d54d
@@ -1267,18 +1289,7 @@ int fdtdec_setup(void)
051d54d
 # ifdef CONFIG_OF_EMBED
051d54d
 	/* Get a pointer to the FDT */
051d54d
 	gd->fdt_blob = __dtb_dt_begin;
051d54d
-# elif defined CONFIG_OF_SEPARATE
051d54d
-#  ifdef CONFIG_SPL_BUILD
051d54d
-	/* FDT is at end of BSS unless it is in a different memory region */
051d54d
-	if (IS_ENABLED(CONFIG_SPL_SEPARATE_BSS))
051d54d
-		gd->fdt_blob = (ulong *)&_image_binary_end;
051d54d
-	else
051d54d
-		gd->fdt_blob = (ulong *)&__bss_end;
051d54d
-#  else
051d54d
-	/* FDT is at end of image */
051d54d
-	gd->fdt_blob = (ulong *)&_end;
051d54d
-#  endif
051d54d
-# elif defined(CONFIG_OF_BOARD)
c09f014
+# elif defined(CONFIG_OF_SEPARATE) || defined(CONFIG_OF_BOARD)
051d54d
 	/* Allow the board to override the fdt address. */
c09f014
 	gd->fdt_blob = board_fdt_blob_setup();
c09f014
 # elif defined(CONFIG_OF_HOSTFILE)
c09f014