linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/7] Add basic ARM device tree support
@ 2010-02-19 19:26 Grant Likely
  2010-02-19 19:27 ` [PATCH 1/7] arm-dt: Add ATAG_DEVTREE tag Grant Likely
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:26 UTC (permalink / raw)
  To: linux-arm-kernel

Hi everyone.  It's been a long time coming, but I thing Jeremy and I have
things to a point where the basic patches needs to add flattened device
tree support to ARM are pretty stable.  This series doesn't really do
much other than making CONFIG_OF selectable, allowing a device tree to
be passed in at boot via an ATAG, and unpacking the tree into the
struct device_node* tree used by drivers/of/*.  No platforms actually
use any of the data yet, but the tree can be browsed in /proc/device-tree

Patches 1-5 are the important ones.  As you can see, the impact is
pretty low.  Biggest change is some refactoring of
arch/arm/mm/init.c so that the memory region occupied by the
device tree blob (dtb) gets reserved in the same way as for an initrd.

Patches 6 is RFC only, and it doesn't fully work yet because it isn't
able to handle relocating the .dtb if it overlaps the final kernel
location.  I'm still working on it, but I'm not even convinced that it
is the best approach yet.  I include it here so that people can build
a kernel image that embeds the dtb and so give the device tree code a
spin without having to modify firmware.  Patch 7 is a complete hack to
work around the problem in patch 6.

These patches depend on the merge of PowerPC and Microblaze device tree
code.  The merge work is in linux-next and I'll be asking Linus to pull
it when he opens the window.  It also depends on the earlier patch
posted by Jeremy Kerr to use generic infrastructure for early_params.
These patches are available in the test-devicetree branch of my
linux-2.6 git tree:

git://git.secretlab.ca/git/linux-2.6 test-devicetree

>From here, there are 2 things being worked on.  Jeremy is working on
the early init code to make device tree data available earlier in the
boot process so that device tree data can be used for machine probing
and memory setup.  I'm focusing on parsing the device tree data for
registering platform, i2c and spi devices.  Each of those tasks are
mostly independent and can be posted/reviewed when they are working.

Thanks
g.

---

Grant Likely (3):
      arm/boot/hack: set uImage load address to 0x81000000
      arm/devicetree: Allow .dtb to be carried in the zImage payload
      arm/devicetree: Reserve memory used by dtb blob

Jeremy Kerr (4):
      arm-dt: unflatten device tree
      arm-dt: add devictree node reference to dev_archdata
      arm-dt: Allow CONFIG_OF on ARM
      arm-dt: Add ATAG_DEVTREE tag


 arch/arm/Kconfig                        |   27 ++++++++
 arch/arm/boot/Makefile                  |    2 -
 arch/arm/boot/compressed/Makefile       |   23 ++++++-
 arch/arm/boot/compressed/head.S         |   10 +++
 arch/arm/boot/compressed/misc.c         |   30 +++++++++
 arch/arm/boot/compressed/piggy.dtb.S    |    6 ++
 arch/arm/boot/compressed/vmlinux.lds.in |    2 +
 arch/arm/include/asm/device.h           |    3 +
 arch/arm/include/asm/prom.h             |   19 ++++++
 arch/arm/include/asm/setup.h            |    9 +++
 arch/arm/kernel/Makefile                |    1 
 arch/arm/kernel/devtree.c               |   34 ++++++++++
 arch/arm/kernel/setup.c                 |    3 +
 arch/arm/mm/init.c                      |  102 +++++++++++++++++++++++++------
 14 files changed, 248 insertions(+), 23 deletions(-)
 create mode 100644 arch/arm/boot/compressed/piggy.dtb.S
 create mode 100644 arch/arm/include/asm/prom.h
 create mode 100644 arch/arm/kernel/devtree.c

-- 
Signature

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

* [PATCH 1/7] arm-dt: Add ATAG_DEVTREE tag
  2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
@ 2010-02-19 19:27 ` Grant Likely
  2010-02-19 19:27 ` [PATCH 2/7] arm-dt: Allow CONFIG_OF on ARM Grant Likely
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:27 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jeremy Kerr <jeremy.kerr@canonical.com>

We'd like to provide a pointer to the device tree blob through the atags
mechanism, so add a tag type containing a physical dtb pointer.

We won't need a parser for this, as we'll need to do the devtree parsing
a little earlier than other tags.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 arch/arm/include/asm/setup.h |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/setup.h b/arch/arm/include/asm/setup.h
index dfa9ddf..ee77cec 100644
--- a/arch/arm/include/asm/setup.h
+++ b/arch/arm/include/asm/setup.h
@@ -126,6 +126,14 @@ struct tag_cmdline {
 	char	cmdline[1];	/* this is the minimum size */
 };
 
+/* flattened device tree blob pointer */
+#define ATAG_DEVTREE	0x5441000a
+
+struct tag_devtree {
+	__u32 start;	/* physical start address */
+	__u32 size;	/* size of dtb image in bytes */
+};
+
 /* acorn RiscPC specific information */
 #define ATAG_ACORN	0x41000101
 
@@ -155,6 +163,7 @@ struct tag {
 		struct tag_revision	revision;
 		struct tag_videolfb	videolfb;
 		struct tag_cmdline	cmdline;
+		struct tag_devtree	devtree;
 
 		/*
 		 * Acorn specific

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

* [PATCH 2/7] arm-dt: Allow CONFIG_OF on ARM
  2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
  2010-02-19 19:27 ` [PATCH 1/7] arm-dt: Add ATAG_DEVTREE tag Grant Likely
@ 2010-02-19 19:27 ` Grant Likely
  2010-02-19 19:27 ` [PATCH 3/7] arm-dt: add devictree node reference to dev_archdata Grant Likely
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:27 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jeremy Kerr <jeremy.kerr@canonical.com>

Add some basic empty infrastructure for DT support on ARM.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 arch/arm/Kconfig            |    6 ++++++
 arch/arm/include/asm/prom.h |   19 +++++++++++++++++++
 arch/arm/kernel/Makefile    |    1 +
 arch/arm/kernel/devtree.c   |   34 ++++++++++++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 0 deletions(-)
 create mode 100644 arch/arm/include/asm/prom.h
 create mode 100644 arch/arm/kernel/devtree.c

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 4c33ca8..5a8edc2 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1258,6 +1258,12 @@ endmenu
 
 menu "Boot options"
 
+config OF
+	bool "Device tree support"
+	select OF_FLATTREE
+	help
+	  Support for OpenFirmware-style device trees
+
 # Compressed boot loader in ROM.  Yes, we really want to ask about
 # TEXT and BSS so we preserve their values in the config files.
 config ZBOOT_ROM_TEXT
diff --git a/arch/arm/include/asm/prom.h b/arch/arm/include/asm/prom.h
new file mode 100644
index 0000000..20b42fb
--- /dev/null
+++ b/arch/arm/include/asm/prom.h
@@ -0,0 +1,19 @@
+/*
+ *  arch/arm/include/asm/prom.h
+ *
+ *  Copyright (C) 2009 Canonical Ltd. <jeremy.kerr@canonical.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+#ifndef __ASMARM_PROM_H
+#define __ASMARM_PROM_H
+
+#include <asm/setup.h>
+
+/* _ALIGN expects upwards alignment */
+#define _ALIGN(addr, size)		(((addr)+((size)-1))&(~((size)-1)))
+
+#endif
diff --git a/arch/arm/kernel/Makefile b/arch/arm/kernel/Makefile
index dd00f74..35c8bdf 100644
--- a/arch/arm/kernel/Makefile
+++ b/arch/arm/kernel/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_ARM_THUMBEE)	+= thumbee.o
 obj-$(CONFIG_KGDB)		+= kgdb.o
 obj-$(CONFIG_ARM_UNWIND)	+= unwind.o
 obj-$(CONFIG_HAVE_TCM)		+= tcm.o
+obj-$(CONFIG_OF)		+= devtree.o
 
 obj-$(CONFIG_CRUNCH)		+= crunch.o crunch-bits.o
 AFLAGS_crunch-bits.o		:= -Wa,-mcpu=ep9312
diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c
new file mode 100644
index 0000000..5909d08
--- /dev/null
+++ b/arch/arm/kernel/devtree.c
@@ -0,0 +1,34 @@
+/*
+ *  linux/arch/arm/kernel/devtree.c
+ *
+ *  Copyright (C) 2009 Canonical Ltd. <jeremy.kerr@canonical.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/errno.h>
+#include <linux/types.h>
+#include <linux/bootmem.h>
+#include <linux/of.h>
+#include <linux/of_fdt.h>
+
+#include <asm/setup.h>
+#include <asm/page.h>
+
+void __init early_init_dt_add_memory_arch(u64 base, u64 size)
+{
+	arm_add_memory(base, size);
+}
+
+u64 __init early_init_dt_alloc_memory_arch(u64 size, u64 align)
+{
+	return __pa(__alloc_bootmem(size, align, __pa(MAX_DMA_ADDRESS)));
+}
+
+void early_init_dt_scan_chosen_arch(unsigned long node) { }
+
+void early_init_dt_setup_initrd_arch(unsigned long start,
+					    unsigned long end) { }

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

* [PATCH 3/7] arm-dt: add devictree node reference to dev_archdata
  2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
  2010-02-19 19:27 ` [PATCH 1/7] arm-dt: Add ATAG_DEVTREE tag Grant Likely
  2010-02-19 19:27 ` [PATCH 2/7] arm-dt: Allow CONFIG_OF on ARM Grant Likely
@ 2010-02-19 19:27 ` Grant Likely
  2010-02-19 19:27 ` [PATCH 4/7] arm/devicetree: Reserve memory used by dtb blob Grant Likely
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:27 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jeremy Kerr <jeremy.kerr@canonical.com>

We'll need to parse device info from the device tree, so add the OF node
to dev->archdata.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 arch/arm/include/asm/device.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h
index 9f390ce..167b156 100644
--- a/arch/arm/include/asm/device.h
+++ b/arch/arm/include/asm/device.h
@@ -10,6 +10,9 @@ struct dev_archdata {
 #ifdef CONFIG_DMABOUNCE
 	struct dmabounce_device_info *dmabounce;
 #endif
+#ifdef CONFIG_OF
+	struct device_node *of_node;
+#endif
 };
 
 struct pdev_archdata {

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

* [PATCH 4/7] arm/devicetree: Reserve memory used by dtb blob
  2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
                   ` (2 preceding siblings ...)
  2010-02-19 19:27 ` [PATCH 3/7] arm-dt: add devictree node reference to dev_archdata Grant Likely
@ 2010-02-19 19:27 ` Grant Likely
  2010-02-19 19:28 ` [PATCH 5/7] arm-dt: unflatten device tree Grant Likely
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:27 UTC (permalink / raw)
  To: linux-arm-kernel

The device tree memory needs to be reserved as bootmem so that it doesn't
get overwritten by normal allocations later.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 arch/arm/mm/init.c |  102 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 83 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
index a340569..2ceb21b 100644
--- a/arch/arm/mm/init.c
+++ b/arch/arm/mm/init.c
@@ -17,6 +17,8 @@
 #include <linux/initrd.h>
 #include <linux/sort.h>
 #include <linux/highmem.h>
+#include <linux/of.h>
+#include <linux/of_fdt.h>
 
 #include <asm/mach-types.h>
 #include <asm/sections.h>
@@ -68,6 +70,20 @@ static int __init parse_tag_initrd2(const struct tag *tag)
 
 __tagtable(ATAG_INITRD2, parse_tag_initrd2);
 
+#if defined(CONFIG_OF_FLATTREE)
+static unsigned long phys_devtree_start __initdata = 0;
+static unsigned long phys_devtree_size __initdata = 0;
+
+static int __init parse_tag_devtree(const struct tag *tag)
+{
+	phys_devtree_start = tag->u.devtree.start;
+	phys_devtree_size = tag->u.devtree.size;
+	return 0;
+}
+
+__tagtable(ATAG_DEVTREE, parse_tag_devtree);
+#endif
+
 /*
  * This keeps memory configuration data used by a couple memory
  * initialization functions, as well as show_mem() for the skipping
@@ -191,29 +207,33 @@ find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages)
 	return bootmap_pfn;
 }
 
-static int __init check_initrd(struct meminfo *mi)
+static int __init check_region(struct meminfo *mi,
+			       unsigned long start, unsigned long size)
 {
-	int initrd_node = -2;
-#ifdef CONFIG_BLK_DEV_INITRD
-	unsigned long end = phys_initrd_start + phys_initrd_size;
-
-	/*
-	 * Make sure that the initrd is within a valid area of
-	 * memory.
-	 */
-	if (phys_initrd_size) {
-		unsigned int i;
+	unsigned long end = start + size - 1;
+	unsigned int i;
 
-		initrd_node = -1;
+	if (!size)
+		return -2;
 
-		for (i = 0; i < mi->nr_banks; i++) {
-			struct membank *bank = &mi->bank[i];
-			if (bank_phys_start(bank) <= phys_initrd_start &&
-			    end <= bank_phys_end(bank))
-				initrd_node = bank->node;
-		}
+	/* Make sure that the region is within a valid bank of memory. */
+	for (i = 0; i < mi->nr_banks; i++) {
+		struct membank *bank = &mi->bank[i];
+		if (bank_phys_start(bank) <= start &&
+		    end <= bank_phys_end(bank))
+			return bank->node;
 	}
 
+	/* Region is outside of physical memory */
+	return -1;
+}
+
+static int __init check_initrd(struct meminfo *mi)
+{
+	int initrd_node = -2;
+
+#if defined(CONFIG_BLK_DEV_INITRD)
+	initrd_node = check_region(mi, phys_initrd_start, phys_initrd_size);
 	if (initrd_node == -1) {
 		printk(KERN_ERR "INITRD: 0x%08lx+0x%08lx extends beyond "
 		       "physical memory - disabling initrd\n",
@@ -225,6 +245,27 @@ static int __init check_initrd(struct meminfo *mi)
 	return initrd_node;
 }
 
+static int __init check_devtree(struct meminfo *mi)
+{
+	int node = -2;
+
+#if defined(CONFIG_OF_FLATTREE)
+	if ((phys_devtree_start == 0) || (phys_devtree_size == 0))
+		goto out;
+
+	node = check_region(mi, phys_devtree_start, phys_devtree_size);
+	if (node == -1) {
+		phys_devtree_start = phys_devtree_size = 0;
+		pr_err("DEVICETREE: 0x%08lx+0x%08lx extends beyond "
+		       "physical memory - disabling device tree\n",
+		       phys_devtree_start, phys_devtree_size);
+	}
+#endif
+
+ out:
+	return node;
+}
+
 static inline void map_memory_bank(struct membank *bank)
 {
 #ifdef CONFIG_MMU
@@ -305,6 +346,25 @@ static void __init bootmem_reserve_initrd(int node)
 #endif
 }
 
+static void __init bootmem_reserve_devtree(int node)
+{
+#if defined(CONFIG_OF_FLATTREE)
+	pg_data_t *pgdat = NODE_DATA(node);
+	int res;
+
+	res = reserve_bootmem_node(pgdat, phys_devtree_start,
+				   phys_devtree_size, BOOTMEM_EXCLUSIVE);
+	if (res) {
+		pr_err("DEVICETREE: 0x%08lx+0x%08lx overlaps in-use "
+		       "memory region - disabling device tree\n",
+			phys_devtree_start, phys_devtree_size);
+		return;
+	}
+
+	initial_boot_params = (void *)__phys_to_virt(phys_devtree_start);
+#endif
+}
+
 static void __init bootmem_free_node(int node, struct meminfo *mi)
 {
 	unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
@@ -397,7 +457,7 @@ void __init bootmem_init(void)
 {
 	struct meminfo *mi = &meminfo;
 	unsigned long min, max_low, max_high;
-	int node, initrd_node;
+	int node, initrd_node, devtree_node;
 
 	sort(&mi->bank, mi->nr_banks, sizeof(mi->bank[0]), meminfo_cmp, NULL);
 
@@ -405,6 +465,7 @@ void __init bootmem_init(void)
 	 * Locate which node contains the ramdisk image, if any.
 	 */
 	initrd_node = check_initrd(mi);
+	devtree_node = check_devtree(mi);
 
 	max_low = max_high = 0;
 
@@ -438,9 +499,12 @@ void __init bootmem_init(void)
 
 		/*
 		 * If the initrd is in this node, reserve its memory.
+		 * and do the same for the device tree blob
 		 */
 		if (node == initrd_node)
 			bootmem_reserve_initrd(node);
+		if (node == devtree_node)
+			bootmem_reserve_devtree(node);
 
 		/*
 		 * Sparsemem tries to allocate bootmem in memory_present(),

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

* [PATCH 5/7] arm-dt: unflatten device tree
  2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
                   ` (3 preceding siblings ...)
  2010-02-19 19:27 ` [PATCH 4/7] arm/devicetree: Reserve memory used by dtb blob Grant Likely
@ 2010-02-19 19:28 ` Grant Likely
  2010-02-19 19:29 ` [RFC/PATCH 6/7] arm/devicetree: Allow .dtb to be carried in the zImage payload Grant Likely
  2010-02-19 19:29 ` [PATCH 7/7] arm/boot/hack: set uImage load address to 0x81000000 Grant Likely
  6 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:28 UTC (permalink / raw)
  To: linux-arm-kernel

From: Jeremy Kerr <jeremy.kerr@canonical.com>

If we've found a device tree, unflatten it.

Also, allow the unflattened tree to be exposed at /proc/device-tree.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
---

 arch/arm/Kconfig        |    8 ++++++++
 arch/arm/kernel/setup.c |    3 +++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 5a8edc2..50eea35 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1264,6 +1264,14 @@ config OF
 	help
 	  Support for OpenFirmware-style device trees
 
+config PROC_DEVICETREE
+	bool "Support for device tree in /proc"
+	depends on PROC_FS
+	help
+	  This option adds a device-tree directory under /proc which contains
+	  an image of the device tree that the kernel copies from Open
+	  Firmware or other boot firmware. If unsure, say Y here.
+
 # Compressed boot loader in ROM.  Yes, we really want to ask about
 # TEXT and BSS so we preserve their values in the config files.
 config ZBOOT_ROM_TEXT
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 84fd876..dc057ad 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -24,6 +24,7 @@
 #include <linux/interrupt.h>
 #include <linux/smp.h>
 #include <linux/fs.h>
+#include <linux/of_fdt.h>
 
 #include <asm/unified.h>
 #include <asm/cpu.h>
@@ -715,6 +716,8 @@ void __init setup_arch(char **cmdline_p)
 	paging_init(mdesc);
 	request_standard_resources(&meminfo, mdesc);
 
+	unflatten_device_tree();
+
 #ifdef CONFIG_SMP
 	smp_init_cpus();
 #endif

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

* [RFC/PATCH 6/7] arm/devicetree: Allow .dtb to be carried in the zImage payload
  2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
                   ` (4 preceding siblings ...)
  2010-02-19 19:28 ` [PATCH 5/7] arm-dt: unflatten device tree Grant Likely
@ 2010-02-19 19:29 ` Grant Likely
  2010-02-19 19:29 ` [PATCH 7/7] arm/boot/hack: set uImage load address to 0x81000000 Grant Likely
  6 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:29 UTC (permalink / raw)
  To: linux-arm-kernel

This patch allows a device tree blob to be linked into the zImage
executable to be passed into the kernel via an ATAG.  The kernel
can either use the linked in .dtb, or override it with a .dtb
passed in by firmware.

This patch doesn't handle relocation correctly yet.  Not ready to be merged
---

 arch/arm/Kconfig                        |   13 +++++++++++++
 arch/arm/boot/compressed/Makefile       |   23 ++++++++++++++++++++---
 arch/arm/boot/compressed/head.S         |   10 ++++++++++
 arch/arm/boot/compressed/misc.c         |   30 ++++++++++++++++++++++++++++++
 arch/arm/boot/compressed/piggy.dtb.S    |    6 ++++++
 arch/arm/boot/compressed/vmlinux.lds.in |    2 ++
 6 files changed, 81 insertions(+), 3 deletions(-)
 create mode 100644 arch/arm/boot/compressed/piggy.dtb.S

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 50eea35..fa957c8 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -1272,6 +1272,19 @@ config PROC_DEVICETREE
 	  an image of the device tree that the kernel copies from Open
 	  Firmware or other boot firmware. If unsure, say Y here.
 
+config FDT_LINKED_INTO_ZIMAGE
+	bool "Link a flattened device tree blob into the kernel image"
+	select DTC
+	depends on OF_FLATTREE
+
+config FDT_SOURCE
+	string "Flattened Device Tree source filename"
+	depends on FDT_LINKED_INTO_ZIMAGE
+	default "board.dts"
+
+config DTC
+	bool
+
 # Compressed boot loader in ROM.  Yes, we really want to ask about
 # TEXT and BSS so we preserve their values in the config files.
 config ZBOOT_ROM_TEXT
diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile
index 2d4d88b..558b31f 100644
--- a/arch/arm/boot/compressed/Makefile
+++ b/arch/arm/boot/compressed/Makefile
@@ -66,8 +66,13 @@ SEDFLAGS	= s/TEXT_START/$(ZTEXTADDR)/;s/BSS_START/$(ZBSSADDR)/
 suffix_$(CONFIG_KERNEL_GZIP) = gzip
 suffix_$(CONFIG_KERNEL_LZO)  = lzo
 
-targets       := vmlinux vmlinux.lds \
-		 piggy.$(suffix_y) piggy.$(suffix_y).o \
+# Payload objects
+OBJS	+= piggy.$(suffix_y).o
+ifeq ($(CONFIG_FDT_LINKED_INTO_ZIMAGE),y)
+OBJS	+= piggy.dtb.o
+endif
+
+targets       := vmlinux vmlinux.lds piggy.$(suffix_y) \
 		 font.o font.c head.o misc.o $(OBJS)
 
 ifeq ($(CONFIG_FUNCTION_TRACER),y)
@@ -110,7 +115,7 @@ $(obj)/lib1funcs.S: $(srctree)/arch/$(SRCARCH)/lib/lib1funcs.S FORCE
 # would otherwise mess up our GOT table
 CFLAGS_misc.o := -Dstatic=
 
-$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) $(obj)/piggy.$(suffix_y).o \
+$(obj)/vmlinux: $(obj)/vmlinux.lds $(obj)/$(HEAD) \
 	 	$(addprefix $(obj)/, $(OBJS)) $(lib1funcs) FORCE
 	$(call if_changed,ld)
 	@:
@@ -127,3 +132,15 @@ $(obj)/font.c: $(FONTC)
 
 $(obj)/vmlinux.lds: $(obj)/vmlinux.lds.in arch/arm/boot/Makefile .config
 	@sed "$(SEDFLAGS)" < $< > $@
+
+# Rule to build device tree blobs
+
+DTC = $(objtree)/scripts/dtc/dtc
+
+$(obj)/piggy.dts: $(obj)/../$(subst ",,$(CONFIG_FDT_SOURCE))
+	cp $< $@
+
+$(obj)/piggy.dtb.o: $(obj)/piggy.dtb
+
+$(obj)/%.dtb: $(obj)/%.dts
+	$(DTC) -O dtb -o $(obj)/$*.dtb -b 0 $(DTS_FLAGS) $(obj)/$*.dts
diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S
index 4fddc50..820e0e1 100644
--- a/arch/arm/boot/compressed/head.S
+++ b/arch/arm/boot/compressed/head.S
@@ -240,6 +240,16 @@ not_relocated:	mov	r0, #0
 		 */
 		bl	cache_on
 
+#if defined(CONFIG_FDT_LINKED_INTO_ZIMAGE)
+/*
+ * Graft device tree pointer onto the end of the ATAGs list
+ * r0    = atags pointer
+ * r1-r3 = unused
+ */
+		mov	r0, r8			@ Pass atags pointer
+		bl	graft_devicetree_atag
+#endif
+
 		mov	r1, sp			@ malloc space above stack
 		add	r2, sp, #0x10000	@ 64k max
 
diff --git a/arch/arm/boot/compressed/misc.c b/arch/arm/boot/compressed/misc.c
index 56a0d11..694a541 100644
--- a/arch/arm/boot/compressed/misc.c
+++ b/arch/arm/boot/compressed/misc.c
@@ -27,6 +27,7 @@ unsigned int __machine_arch_type;
 #include <linux/linkage.h>
 
 #include <asm/unaligned.h>
+#include <asm/setup.h>
 
 #ifdef STANDALONE_DEBUG
 #define putstr printf
@@ -272,6 +273,35 @@ asmlinkage void __div0(void)
 	error("Attempting division by 0!");
 }
 
+#if defined(CONFIG_FDT_LINKED_INTO_ZIMAGE)
+extern char dtb_data[];
+extern char dtb_data_end[];
+
+void graft_devicetree_atag(unsigned long atag_list)
+{
+	struct tag *tag;
+
+	/* Loop over ATAG list and find the end.  If a devicetree tag
+	 * already exists, then just bail */
+	for_each_tag(tag, (void *)atag_list) {
+		if (tag->hdr.tag == ATAG_DEVTREE)
+			return;
+	}
+
+	/* Replace the end of the list with an ATAG_DEVTREE */
+	putstr("Appending device tree tag\n");
+	tag->hdr.size = tag_size(tag_devtree);
+	tag->hdr.tag = ATAG_DEVTREE;
+	tag->u.devtree.start = (__u32)dtb_data;
+	tag->u.devtree.size = (__u32)dtb_data_end - (__u32)dtb_data;
+
+	/* And create a new ATAG_NONE tag after it */
+	tag = tag_next(tag);
+	tag->hdr.size = 0;
+	tag->hdr.tag = ATAG_NONE;
+}
+#endif
+
 #ifndef STANDALONE_DEBUG
 
 unsigned long
diff --git a/arch/arm/boot/compressed/piggy.dtb.S b/arch/arm/boot/compressed/piggy.dtb.S
new file mode 100644
index 0000000..822337f
--- /dev/null
+++ b/arch/arm/boot/compressed/piggy.dtb.S
@@ -0,0 +1,6 @@
+	.section .piggydtb,#alloc
+	.globl	dtb_data
+dtb_data:
+	.incbin	"arch/arm/boot/compressed/piggy.dtb"
+	.globl	dtb_data_end
+dtb_data_end:
diff --git a/arch/arm/boot/compressed/vmlinux.lds.in b/arch/arm/boot/compressed/vmlinux.lds.in
index a5924b9..7f50b64 100644
--- a/arch/arm/boot/compressed/vmlinux.lds.in
+++ b/arch/arm/boot/compressed/vmlinux.lds.in
@@ -30,6 +30,8 @@ SECTIONS
     *(.rodata.*)
     *(.glue_7)
     *(.glue_7t)
+    . = ALIGN(4096); /* Page aligned DTBs can be directly used by the kernel */
+    *(.piggydtb)
     *(.piggydata)
     . = ALIGN(4);
   }

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

* [PATCH 7/7] arm/boot/hack: set uImage load address to 0x81000000
  2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
                   ` (5 preceding siblings ...)
  2010-02-19 19:29 ` [RFC/PATCH 6/7] arm/devicetree: Allow .dtb to be carried in the zImage payload Grant Likely
@ 2010-02-19 19:29 ` Grant Likely
  6 siblings, 0 replies; 8+ messages in thread
From: Grant Likely @ 2010-02-19 19:29 UTC (permalink / raw)
  To: linux-arm-kernel

Total hack.
Don't merge.
This will go away when I fix patch 6/7

g.

---

 arch/arm/boot/Makefile |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/arch/arm/boot/Makefile b/arch/arm/boot/Makefile
index 4a590f4..9aeea2f 100644
--- a/arch/arm/boot/Makefile
+++ b/arch/arm/boot/Makefile
@@ -67,7 +67,7 @@ quiet_cmd_uimage = UIMAGE  $@
 ifeq ($(CONFIG_ZBOOT_ROM),y)
 $(obj)/uImage: LOADADDR=$(CONFIG_ZBOOT_ROM_TEXT)
 else
-$(obj)/uImage: LOADADDR=$(ZRELADDR)
+$(obj)/uImage: LOADADDR=0x81000000
 endif
 
 ifeq ($(CONFIG_THUMB2_KERNEL),y)

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

end of thread, other threads:[~2010-02-19 19:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-02-19 19:26 [PATCH 0/7] Add basic ARM device tree support Grant Likely
2010-02-19 19:27 ` [PATCH 1/7] arm-dt: Add ATAG_DEVTREE tag Grant Likely
2010-02-19 19:27 ` [PATCH 2/7] arm-dt: Allow CONFIG_OF on ARM Grant Likely
2010-02-19 19:27 ` [PATCH 3/7] arm-dt: add devictree node reference to dev_archdata Grant Likely
2010-02-19 19:27 ` [PATCH 4/7] arm/devicetree: Reserve memory used by dtb blob Grant Likely
2010-02-19 19:28 ` [PATCH 5/7] arm-dt: unflatten device tree Grant Likely
2010-02-19 19:29 ` [RFC/PATCH 6/7] arm/devicetree: Allow .dtb to be carried in the zImage payload Grant Likely
2010-02-19 19:29 ` [PATCH 7/7] arm/boot/hack: set uImage load address to 0x81000000 Grant Likely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).