Skip to contentSkip to conversation

Adding DTB to architecture independent vmlinux

RFC PATCH Superseded [email protected] 2 participants 2 messages Nov 11, 2010 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v4 cover Adding DTB to architecture independent vmlinux

From: Dirk Brandewie <[email protected]>

The following series implements the ability to link device tree blob(s) into the kernel image.

Changes since V3:
Added kernel command line option to pass a "compatible" string to select the DTB for the platform.

Added function to find the compatible DTB in the kernel image if any

Added code to dtc to force the DTB to be modulo 32 bytes in size

Changed the alignment of the .dtb section

---

Dirk Brandewie (4):
x86/of: Support building device tree blob(s) into image.
of: Add support for linking device tree blobs into vmlinux of/dtc: force dtb size to modulo 32 bytes
of/fdt: add kernel command line option for dtb_compat string

 arch/x86/Kconfig                  |    6 ++++
 arch/x86/boot/dts/Kconfig         |    8 ++++++
 arch/x86/kernel/Makefile          |   11 ++++++++
 drivers/of/fdt.c                  |   52 +++++++++++++++++++++++++++++++++++++
 include/asm-generic/vmlinux.lds.h |   13 +++++++++
 include/linux/of_fdt.h            |    9 ++++++
 init/Kconfig                      |    7 +++++
 scripts/Makefile.lib              |   14 ++++++++++
 scripts/dtc/flattree.c            |    6 ++++
 9 files changed, 123 insertions(+), 3 deletions(-)
 create mode 100644 arch/x86/boot/dts/Kconfig
Signature · 1 line
Signature
Quoted 1 line

From nobody Thu Nov 11 15:42:58 2010

Subject: [PATCH 1/4] x86/of: Support building device tree blob(s) into image.
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.98317.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

This patch adds support for linking device tree blobs into vmlinux. The blobs linked into the image is controlled via kernel config variables

---
 arch/x86/Kconfig          |    6 +++++-
 arch/x86/boot/dts/Kconfig |    8 ++++++++
 arch/x86/kernel/Makefile  |   11 +++++++++++
 3 files changed, 24 insertions(+), 1 deletions(-)
 create mode 100644 arch/x86/boot/dts/Kconfig
arch/x86/Kconfig +5 -1
index 5904f38..62c195d 100644
@@ -299,13 +299,17 @@ config X86_BIGSMP
 	---help---
 	  This option is needed for the systems that have more than 8 CPUs
 
-config X86_OF
+menuconfig X86_OF
 	bool "Support for device tree"
 	select OF
 	select OF_FLATTREE
 	---help---
 	  Device tree support on X86.
 
+if X86_OF
+source "arch/x86/boot/dts/Kconfig
+endif
+
 if X86_32
 config X86_EXTENDED_PLATFORM
 	bool "Support for extended (non-PC) x86 platforms"
arch/x86/boot/dts/Kconfig new file +8 -0
new file mode 100644
index 0000000..5380b6b
@@ -0,0 +1,8 @@
+config CE4100_DTB
+       bool "Intel CE4100"
+       depends on X86_OF && KERNEL_DTB
+
+config TEST_DTB
+       bool "Test DTS"
+       depends on  X86_OF && KERNEL_DTB
+
arch/x86/kernel/Makefile +11 -0
index 586df14..cf15e8c 100644
@@ -113,6 +113,17 @@ obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 obj-$(CONFIG_SWIOTLB)			+= pci-swiotlb.o
 obj-$(CONFIG_X86_OF)			+= prom.o
 
+ifeq ($(CONFIG_KERNEL_DTB),y)
+obj-$(CONFIG_CE4100_DTB) += ce4100.dtb.o
+obj-$(CONFIG_TEST_DTB) += test.dtb.o
+endif
+
+dtstree	:= $(srctree)/arch/x86/boot/dts
+
+$(obj)/%.dtb: $(dtstree)/%.dts
+	$(call if_changed,dtc)
+
+
 ###
 # 64 bit specific files
 ifeq ($(CONFIG_X86_64),y)
Quoted 1 line

From nobody Thu Nov 11 15:42:58 2010

Subject: [PATCH 2/4] of: Add support for linking device tree blobs into vmlinux
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.42704.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

This patch adds support for linking device tree blobs into vmlinux. The device tree blobs are placed in the init.data section.

---
 include/asm-generic/vmlinux.lds.h |   13 ++++++++++++-
 init/Kconfig                      |    7 +++++++
 scripts/Makefile.lib              |   14 ++++++++++++++
 3 files changed, 33 insertions(+), 1 deletions(-)
include/asm-generic/vmlinux.lds.h +12 -1
index bd69d79..c8f600e 100644
@@ -146,6 +146,16 @@
 #define TRACE_SYSCALLS()
 #endif
 
+#ifdef CONFIG_KERNEL_DTB
+#define KERNEL_DTB							\
+	. = ALIGN(32);							\
+	VMLINUX_SYMBOL(__dtb_start) = .;				\
+	*(.dtb)			       					\
+	VMLINUX_SYMBOL(__dtb_end) = .;
+#else
+#define KERNEL_DTB
+#endif
+
 /* .data section */
 #define DATA_DATA							\
 	*(.data)							\
@@ -468,7 +478,8 @@
 	MCOUNT_REC()							\
 	DEV_DISCARD(init.rodata)					\
 	CPU_DISCARD(init.rodata)					\
-	MEM_DISCARD(init.rodata)
+	MEM_DISCARD(init.rodata)					\
+	KERNEL_DTB
 
 #define INIT_TEXT							\
 	*(.init.text)							\
init/Kconfig +7 -0
index 88c1046..fddfc0f 100644
@@ -1083,6 +1083,13 @@ config PCI_QUIRKS
           bugs/quirks. Disable this only if your target machine is
           unaffected by PCI quirks.
 
+config KERNEL_DTB
+       bool "Support linking a device tree blob into vmlinux"
+       default n
+       help
+         This option provides support for adding a device tree blob(s)
+	 directly to vmlinux
+
 config SLUB_DEBUG
 	default y
 	bool "Enable SLUB debugging support" if EMBEDDED
scripts/Makefile.lib +14 -0
index 4c72c11..c4487b2 100644
@@ -200,6 +200,20 @@ quiet_cmd_gzip = GZIP    $@
 cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \
 	(rm -f $@ ; false)
 
+# DTC
+#  ---------------------------------------------------------------------------
+$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
+	@echo '.section .dtb,"a"' > $@
+	@echo '.global __dtb_$(*F)_begin' >> $@
+	@echo '__dtb_$(*F)_begin:' >> $@
+	@echo '.incbin "$<" ' >> $@
+	@echo '__dtb_$(*F)_end:' >> $@
+	@echo '.global __dtb_$(*F)_end' >> $@
+
+DTC = $(objtree)/scripts/dtc/dtc
+
+quiet_cmd_dtc = DTC	$@
+      cmd_dtc = $(DTC) -O dtb -o $(obj)/$*.dtb -b 0  $(dtstree)/$*.dts
 
 # Bzip2
 # ---------------------------------------------------------------------------
Quoted 1 line

From nobody Thu Nov 11 15:42:58 2010

Subject: [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.25714.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

This patch forces the size of the DTB to be modulo 32 bytes. This is needed to support linking multiple DTB's into a single section in the image. GCC wants structures to be 32 byte aligned without this change DTB's after the first in the section may not be properly aligned so the flat tree parsing code will fall over.

---
 scripts/dtc/flattree.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
scripts/dtc/flattree.c +5 -1
index 76acd28..ccca797 100644
@@ -358,6 +358,7 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
 	struct data strbuf     = empty_data;
 	struct fdt_header fdt;
 	int padlen = 0;
+	int align_size;
 
 	for (i = 0; i < ARRAY_SIZE(version_table); i++) {
 		if (version_table[i].version == version)
@@ -395,6 +396,9 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
 		fdt.totalsize = cpu_to_fdt32(tsize);
 	}
 
+	align_size = ALIGN(fdt32_to_cpu(fdt.totalsize), 32);
+	fdt.totalsize = cpu_to_fdt32(align_size);
+
 	/*
 	 * Assemble the blob: start with the header, add with alignment
 	 * the reserve buffer, add the reserve map terminating zeroes,
@@ -412,7 +416,7 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
 	 */
 	if (padlen > 0)
 		blob = data_append_zeroes(blob, padlen);
-
+	blob = data_append_align(blob, 32);
 	fwrite(blob.val, blob.len, 1, f);
 
 	if (ferror(f))
Quoted 1 line

From nobody Thu Nov 11 15:42:58 2010

Subject: [PATCH 4/4] of/fdt: add kernel command line option for dtb_compat
string
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.25736.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

Add support for specifying a "compatible" string from the kernel command line and functions for the platform to find the compatible blob present in the kernel image if any.

---
 drivers/of/fdt.c       |   52 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_fdt.h |    9 ++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
drivers/of/fdt.c +52 -0

55 lines not on this page · raw message

include/linux/of_fdt.h +9 -0
index 7bbf5b3..181e413 100644
@@ -58,6 +58,8 @@ struct boot_param_header {
 };
 
 #if defined(CONFIG_OF_FLATTREE)
+#define MAX_DTB_COMPAT_STR 64
+
 /* TBD: Temporary export of fdt globals - remove when code fully merged */
 extern int __initdata dt_root_addr_cells;
 extern int __initdata dt_root_size_cells;
@@ -82,6 +84,13 @@ extern void early_init_dt_add_memory_arch(u64 base, u64 size);
 extern u64 early_init_dt_alloc_memory_arch(u64 size, u64 align);
 extern u64 dt_mem_next_cell(int s, __be32 **cellp);
 
+extern char *of_get_dtb_compatible_string(void);
+#ifdef CONFIG_KERNEL_DTB
+extern void *of_find_compatible_dtb(char *name);
+#else
+static inline void *of_find_compatible_dtb(char *name) {return 0;}
+
+#endif 
 /*
  * If BLK_DEV_INITRD, the fdt early init code will call this function,
  * to be provided by the arch code. start and end are specified as
#2 lore raw
In reply to a message not in the archive

Sorry for the poor formatting I will resend as discreet patches to make commenting easier
--Dirk

Quoted 403 lines · On Thu, 2010-11-11 at 15:45 -0800, dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public…

From: Dirk Brandewie <[email protected]>

The following series implements the ability to link device tree blob(s) into the kernel image.

Changes since V3:
Added kernel command line option to pass a "compatible" string to select the DTB for the platform.

Added function to find the compatible DTB in the kernel image if any

Added code to dtc to force the DTB to be modulo 32 bytes in size

Changed the alignment of the .dtb section

---

Dirk Brandewie (4):
x86/of: Support building device tree blob(s) into image.
of: Add support for linking device tree blobs into vmlinux of/dtc: force dtb size to modulo 32 bytes
of/fdt: add kernel command line option for dtb_compat string

 arch/x86/Kconfig                  |    6 ++++
 arch/x86/boot/dts/Kconfig         |    8 ++++++
 arch/x86/kernel/Makefile          |   11 ++++++++
 drivers/of/fdt.c                  |   52 +++++++++++++++++++++++++++++++++++++
 include/asm-generic/vmlinux.lds.h |   13 +++++++++
 include/linux/of_fdt.h            |    9 ++++++
 init/Kconfig                      |    7 +++++
 scripts/Makefile.lib              |   14 ++++++++++
 scripts/dtc/flattree.c            |    6 ++++
 9 files changed, 123 insertions(+), 3 deletions(-)
 create mode 100644 arch/x86/boot/dts/Kconfig

--
Signature

From nobody Thu Nov 11 15:42:58 2010
Subject: [PATCH 1/4] x86/of: Support building device tree blob(s) into image.
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.98317.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

This patch adds support for linking device tree blobs into vmlinux. The blobs linked into the image is controlled via kernel config variables

---
 arch/x86/Kconfig          |    6 +++++-
 arch/x86/boot/dts/Kconfig |    8 ++++++++
 arch/x86/kernel/Makefile  |   11 +++++++++++
 3 files changed, 24 insertions(+), 1 deletions(-)
 create mode 100644 arch/x86/boot/dts/Kconfig
arch/x86/Kconfig +5 -1
index 5904f38..62c195d 100644
@@ -299,13 +299,17 @@ config X86_BIGSMP
        ---help---
          This option is needed for the systems that have more than 8 CPUs
 
-config X86_OF
+menuconfig X86_OF
        bool "Support for device tree"
        select OF
        select OF_FLATTREE
        ---help---
          Device tree support on X86.
 
+if X86_OF
+source "arch/x86/boot/dts/Kconfig
+endif
+
 if X86_32
 config X86_EXTENDED_PLATFORM
        bool "Support for extended (non-PC) x86 platforms"
arch/x86/boot/dts/Kconfig new file +8 -0
new file mode 100644
index 0000000..5380b6b
@@ -0,0 +1,8 @@
+config CE4100_DTB
+       bool "Intel CE4100"
+       depends on X86_OF && KERNEL_DTB
+
+config TEST_DTB
+       bool "Test DTS"
+       depends on  X86_OF && KERNEL_DTB
+
arch/x86/kernel/Makefile +11 -0
index 586df14..cf15e8c 100644
@@ -113,6 +113,17 @@ obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o
 obj-$(CONFIG_SWIOTLB)                  += pci-swiotlb.o
 obj-$(CONFIG_X86_OF)                   += prom.o
 
+ifeq ($(CONFIG_KERNEL_DTB),y)
+obj-$(CONFIG_CE4100_DTB) += ce4100.dtb.o
+obj-$(CONFIG_TEST_DTB) += test.dtb.o
+endif
+
+dtstree        := $(srctree)/arch/x86/boot/dts
+
+$(obj)/%.dtb: $(dtstree)/%.dts
+       $(call if_changed,dtc)
+
+
 ###
 # 64 bit specific files
 ifeq ($(CONFIG_X86_64),y)

From nobody Thu Nov 11 15:42:58 2010
Subject: [PATCH 2/4] of: Add support for linking device tree blobs into vmlinux
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.42704.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

This patch adds support for linking device tree blobs into vmlinux. The device tree blobs are placed in the init.data section.

---
 include/asm-generic/vmlinux.lds.h |   13 ++++++++++++-
 init/Kconfig                      |    7 +++++++
 scripts/Makefile.lib              |   14 ++++++++++++++
 3 files changed, 33 insertions(+), 1 deletions(-)
include/asm-generic/vmlinux.lds.h +12 -1
index bd69d79..c8f600e 100644
@@ -146,6 +146,16 @@
 #define TRACE_SYSCALLS()
 #endif
 
+#ifdef CONFIG_KERNEL_DTB
+#define KERNEL_DTB                                                     \
+       . = ALIGN(32);                                                  \
+       VMLINUX_SYMBOL(__dtb_start) = .;                                \
+       *(.dtb)                                                         \
+       VMLINUX_SYMBOL(__dtb_end) = .;
+#else
+#define KERNEL_DTB
+#endif
+
 /* .data section */
 #define DATA_DATA                                                      \
        *(.data)                                                        \
@@ -468,7 +478,8 @@
        MCOUNT_REC()                                                    \
        DEV_DISCARD(init.rodata)                                        \
        CPU_DISCARD(init.rodata)                                        \
-       MEM_DISCARD(init.rodata)
+       MEM_DISCARD(init.rodata)                                        \
+       KERNEL_DTB
 
 #define INIT_TEXT                                                      \
        *(.init.text)                                                   \
init/Kconfig +7 -0
index 88c1046..fddfc0f 100644
@@ -1083,6 +1083,13 @@ config PCI_QUIRKS
           bugs/quirks. Disable this only if your target machine is
           unaffected by PCI quirks.
 
+config KERNEL_DTB
+       bool "Support linking a device tree blob into vmlinux"
+       default n
+       help
+         This option provides support for adding a device tree blob(s)
+        directly to vmlinux
+
 config SLUB_DEBUG
        default y
        bool "Enable SLUB debugging support" if EMBEDDED
scripts/Makefile.lib +14 -0
index 4c72c11..c4487b2 100644
@@ -200,6 +200,20 @@ quiet_cmd_gzip = GZIP    $@
 cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \
        (rm -f $@ ; false)
 
+# DTC
+#  ---------------------------------------------------------------------------
+$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
+       @echo '.section .dtb,"a"' > $@
+       @echo '.global __dtb_$(*F)_begin' >> $@
+       @echo '__dtb_$(*F)_begin:' >> $@
+       @echo '.incbin "$<" ' >> $@
+       @echo '__dtb_$(*F)_end:' >> $@
+       @echo '.global __dtb_$(*F)_end' >> $@
+
+DTC = $(objtree)/scripts/dtc/dtc
+
+quiet_cmd_dtc = DTC    $@
+      cmd_dtc = $(DTC) -O dtb -o $(obj)/$*.dtb -b 0  $(dtstree)/$*.dts
 
 # Bzip2
 # ---------------------------------------------------------------------------

From nobody Thu Nov 11 15:42:58 2010
Subject: [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.25714.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

This patch forces the size of the DTB to be modulo 32 bytes. This is needed to support linking multiple DTB's into a single section in the image. GCC wants structures to be 32 byte aligned without this change DTB's after the first in the section may not be properly aligned so the flat tree parsing code will fall over.

---
 scripts/dtc/flattree.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
scripts/dtc/flattree.c +5 -1
index 76acd28..ccca797 100644
@@ -358,6 +358,7 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
        struct data strbuf     = empty_data;
        struct fdt_header fdt;
        int padlen = 0;
+       int align_size;
 
        for (i = 0; i < ARRAY_SIZE(version_table); i++) {
                if (version_table[i].version == version)
@@ -395,6 +396,9 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
                fdt.totalsize = cpu_to_fdt32(tsize);
        }
 
+       align_size = ALIGN(fdt32_to_cpu(fdt.totalsize), 32);
+       fdt.totalsize = cpu_to_fdt32(align_size);
+
        /*
         * Assemble the blob: start with the header, add with alignment
         * the reserve buffer, add the reserve map terminating zeroes,
@@ -412,7 +416,7 @@ void dt_to_blob(FILE *f, struct boot_info *bi, int version)
         */
        if (padlen > 0)
                blob = data_append_zeroes(blob, padlen);
-
+       blob = data_append_align(blob, 32);
        fwrite(blob.val, blob.len, 1, f);
 
        if (ferror(f))

From nobody Thu Nov 11 15:42:58 2010
Subject: [PATCH 4/4] of/fdt: add kernel command line option for dtb_compat
string
Bcc: [email protected]
From: Dirk Brandewie <[email protected]>
Date: Thu, 11 Nov 2010 15:42:58 -0800
Message-ID: <20101111234258.16185.25736.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
In-Reply-To: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
References: <20101111234257.16185.6076.stgit-bi+AKbBUZKagILUCTcTcHdKyNwTtLsGr@public.gmane.org>
User-Agent: StGit/0.15
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit

From: Dirk Brandewie <[email protected]>

Add support for specifying a "compatible" string from the kernel command line and functions for the platform to find the compatible blob present in the kernel image if any.

---
 drivers/of/fdt.c       |   52 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_fdt.h |    9 ++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)
drivers/of/fdt.c +52 -0
index c1360e0..07fe4c6 100644
@@ -604,3 +604,55 @@ void __init unflatten_device_tree(void)
 
        pr_debug(" <- unflatten_device_tree()\n");
 }
+
+#ifndef MODULE
+#ifdef CONFIG_OF_FLATTREE
+static char dtb_compat_name[MAX_DTB_COMPAT_STR] = "";
+
+char __init *of_get_dtb_compatible_string(void)
+{
+       return dtb_compat_name;
+}
+
+#ifdef CONFIG_KERNEL_DTB
+extern char __dtb_start[];
+extern char __dtb_end[];
+
+void *of_find_compatible_dtb(char *name)
+{
+       void *rc = NULL;
+       char *hdr;
+       unsigned long node, root;
+       struct boot_param_header *blob, *orig_initial_boot_params;
+
+       orig_initial_boot_params = initial_boot_params;
+
+       if (__dtb_start != __dtb_end){
+               blob = (struct boot_param_header *)__dtb_start;
+               do{
+                       node = ((unsigned long)blob) +
+                               be32_to_cpu(blob->off_dt_struct);
+                       initial_boot_params = blob;
+                       root = of_get_flat_dt_root();
+                       if (of_flat_dt_is_compatible(root, name) > 0) {
+                               rc = (void*) blob;
+                               break;
+                       }
+                       blob = (unsigned long)blob+be32_to_cpu(blob->totalsize);
+               }while (blob < (struct boot_param_header *)__dtb_end);
+       }
+       if (rc == NULL)
+               initial_boot_params = orig_initial_boot_params;
+       return rc;
+}
+#endif
+
+static int __init dtb_compat_setup(char *line)
+{
+       strncpy(dtb_compat_name, line, MAX_DTB_COMPAT_STR);
+       return 1;
+}
+
+__setup("dtb_compat=", dtb_compat_setup);
+#endif
+#endif
include/linux/of_fdt.h +9 -0
index 7bbf5b3..181e413 100644
@@ -58,6 +58,8 @@ struct boot_param_header {
 };
 
 #if defined(CONFIG_OF_FLATTREE)
+#define MAX_DTB_COMPAT_STR 64
+
 /* TBD: Temporary export of fdt globals - remove when code fully merged */
 extern int __initdata dt_root_addr_cells;
 extern int __initdata dt_root_size_cells;
@@ -82,6 +84,13 @@ extern void early_init_dt_add_memory_arch(u64 base, u64 size);
 extern u64 early_init_dt_alloc_memory_arch(u64 size, u64 align);
 extern u64 dt_mem_next_cell(int s, __be32 **cellp);
 
+extern char *of_get_dtb_compatible_string(void);
+#ifdef CONFIG_KERNEL_DTB
+extern void *of_find_compatible_dtb(char *name);
+#else
+static inline void *of_find_compatible_dtb(char *name) {return 0;}
+
+#endif
 /*
  * If BLK_DEV_INITRD, the fdt early init code will call this function,
  * to be provided by the arch code. start and end are specified as