Adding DTB to architecture independent vmlinux
Subsystems (5)
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
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): cover.1289520079.git.dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
PATCH v4 1/4 x86/of: Support building device tree blob(s) into image.
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
@@ -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
@@ -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
@@ -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)
Signature · 1 line
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): 1b004c685c67c07a5a0b2b16b3a00dd016e2b759.1289520079.git.dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 1/4] x86/of: Support building device tree blob(s) into image.
Quoted 43 lines · On Thu, Nov 11, 2010 at 04:03:47PM -0800…
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
Signed-off-by Dirk Brandewie <[email protected]>--- 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/Kconfigarch/x86/Kconfig +5
-1@@ -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 +0
-0
arch/x86/boot/dts/Kconfig line 8
Quoted 8 lines
arch/x86/boot/dts/Kconfig new file +8
-0@@ -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 +
Rather than explicitly adding a Kconfig entry for each and every .dts file that you'll ever want to embed; I suggest a single Kconfig that allows the users to input a list of .dtb filenames. PowerPC already does this (sort of) for specifying a list of additional dtbimage.% targets.
See config EXTRA_TARGETS in arch/powerpc/Kconfig and in arch/powerp/boot/Makefile.
You can still /also/ link in specific .dtb files when other config symbols are chosen (ie, if some specific board support is chosen that is known to require it), but it doesn't seem to make a lot of sense to me to have entirely separate Kconfig symbols for each and every .dtb file.
arch/x86/kernel/Makefile obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o · line 119
Quoted 12 lines
arch/x86/kernel/Makefile +4
-0@@ -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
The rule that actually generates the .dtb.o files seems to be in patch #2, which makes this series non-bisectable (it will break if patch 1 is applied without patch 2). The changes need to be ordered so that the kernel still builds at any point in the series.
... hmmm, maybe I should dig deeper....
Okay, I see now that it requires CONFIG_KERNEL_DTB to be set which is also defined in patch #2, so the series does appear to be bisectable, but it isn't entirely logical. I would expect to see all the required rules and linker script additions to be applied before adding the dts files to the kernel and adding the Kconfig/Makefile changes that use them.
heh, and I've also just realized that it still isn't bisectable because none of these patches add ce4100.dts or test.dts to the kernel. :-)
I imagine this series should be something like:
1) add %.dtb:%.dts rule (ideally to scripts/Makefile.lib; see below)
2) add %.dtb.S:%.dtb rule (ideally to scripts/Makefile.lib; see below) 3+) add x86 Kconfig and Makefile changes to enable dtb linking and to add the .dts files.
arch/x86/kernel/Makefile obj-$(CONFIG_X86_CHECK_BIOS_CORRUPTION) += check.o · line 124
Quoted 5 lines
arch/x86/kernel/Makefile +5
-0+ +dtstree := $(srctree)/arch/x86/boot/dts + +$(obj)/%.dtb: $(dtstree)/%.dts + $(call if_changed,dtc)
I know this is what we've done in powerpc, but I suspect it would make a lot more sense to make this rule generic and arch independent so that .dts files can live in any subdirectory.
Perhaps this works (completely untested):
$(obj)/%.dtb: $(src)/%.dts
$(call if_changed,dtc)
And I think that would belong in scripts/Makefile.lib. I don't see any reason why PowerPC and Microblaze couldn't use a common definition for this rule.
g.
PATCH v4 2/4 of: Add support for linking device tree blobs into vmlinux
In reply to a message not in the archiveFrom: 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
@@ -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
@@ -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
@@ -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 # ---------------------------------------------------------------------------
Signature · 1 line
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): 7d0a9d70f1616340115c187547006c76b0135ca7.1289520079.git.dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 2/4] of: Add support for linking device tree blobs into vmlinux
Quoted 18 lines · On Thu, Nov 11, 2010 at 04:03:48PM -0800…
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.
Signed-off-by Dirk Brandewie <[email protected]>--- 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 +0
-0
include/asm-generic/vmlinux.lds.h line 150
Quoted 5 lines
include/asm-generic/vmlinux.lds.h +2
-0@@ -146,6 +146,16 @@#define TRACE_SYSCALLS ()#endif +#ifdef CONFIG_KERNEL_DTB +#define KERNEL_DTB \
To match other definitions in this file, this should be defined with
parentheses: #define KERNEL_DTB()
include/asm-generic/vmlinux.lds.h line 153
Quoted 3 lines
include/asm-generic/vmlinux.lds.h +3
-0+ . = ALIGN(32); \ + VMLINUX_SYMBOL(__dtb_start) = .; \ + *(.dtb) \
I wonder if .meminit.rodata.dtb be a better section name. Could use some input from more experienced kernel hackers here. hpa, what say you?
Also, inconsistent indentation (mixed tabs and spaces).
include/asm-generic/vmlinux.lds.h line 158
Quoted 5 lines
include/asm-generic/vmlinux.lds.h +5
-0+ VMLINUX_SYMBOL(__dtb_end) = .; +#else +#define KERNEL_DTB +#endif +
Does this need to be wrapped with CONFIG_KERNEL_DTB? Is there any downside to including these sections unconditionally?
Quoted 18 lines
include/asm-generic/vmlinux.lds.h +2
-1/* .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 +0
-0
init/Kconfig config PCI_QUIRKS · line 1091
Quoted 9 lines
init/Kconfig +6
-0@@ -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
Inconsistent indentation. I'm also not convinced that this Kconfig symbol is really needed (as commented on above).
Quoted 16 lines
init/Kconfig +1
-0+ config SLUB_DEBUG default y bool "Enable SLUB debugging support" if EMBEDDEDscripts/Makefile.lib +4
-0@@ -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"' > $@
scripts/Makefile.lib quiet_cmd_gzip = GZIP $@ · line 216
Quoted 10 lines
scripts/Makefile.lib +10
-0+ @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
As already mentioned; need to rationalized these rule additions with the changes made in patch #1.
g.
A message that is not in the archive (sent off-list or not yet received): 20101114052525.GC2355-MrY2KI0G/OVr83L8+7iqerDks+cytr/[email protected]
Re: [PATCH 2/4] of: Add support for linking device tree blobs into vmlinux
Quoted 28 lines · Grant Likely
Quoted 18 lines · On Thu, Nov 11, 2010 at 04:03:48PM -0800…
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.
Signed-off-by Dirk Brandewie<[email protected]>--- 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 +0
-0include/asm-generic/vmlinux.lds.h line 150
Quoted 5 lines
include/asm-generic/vmlinux.lds.h +2
-0@@ -146,6 +146,16 @@#define TRACE_SYSCALLS ()#endif +#ifdef CONFIG_KERNEL_DTB +#define KERNEL_DTB \To match other definitions in this file, this should be defined with
parentheses: #defineKERNEL_DTB()
Quoted 7 lines
include/asm-generic/vmlinux.lds.h line 153
Quoted 3 lines
include/asm-generic/vmlinux.lds.h +3
-0+ . = ALIGN(32); \ + VMLINUX_SYMBOL(__dtb_start) = .; \ + *(.dtb) \I wonder if .meminit.rodata.dtb be a better section name. Could use some input from more experienced kernel hackers here. hpa, what say you?
I will use what ever name seems reasonable, It turns out that the sections that are named *.init.rodata are really in a R/W section :-( so that name is really a misnomer. I will check with HPA on name again.
Quoted 3 lines
Also, inconsistent indentation (mixed tabs and spaces).
will fix
Quoted 9 lines
include/asm-generic/vmlinux.lds.h line 158
Quoted 5 lines
include/asm-generic/vmlinux.lds.h +5
-0+ VMLINUX_SYMBOL(__dtb_end) = .; +#else +#define KERNEL_DTB +#endif +Does this need to be wrapped with
CONFIG_KERNEL_DTB? Is there any downside to including these sections unconditionally?
Not sure I was just following the convention set by TRACE_SYSCALLS(), BRANCH_PROFILE(), ...
Quoted 63 lines
Quoted 18 lines
include/asm-generic/vmlinux.lds.h +2
-1/* .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 +0
-0init/Kconfig config PCI_QUIRKS · line 1091
Quoted 9 lines
init/Kconfig +6
-0@@ -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 vmlinuxInconsistent indentation. I'm also not convinced that this
Kconfigsymbol is really needed (as commented on above).Quoted 16 lines
init/Kconfig +1
-0+ config SLUB_DEBUG default y bool "Enable SLUB debugging support" if EMBEDDEDscripts/Makefile.lib +4
-0@@ -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"'> $@scripts/Makefile.lib quiet_cmd_gzip = GZIP $@ · line 216
Quoted 10 lines
scripts/Makefile.lib +10
-0+ @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)/$*.dtsAs already mentioned; need to rationalized these rule additions with the changes made in patch #1.
g.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [sodaville] [PATCH 2/4] of: Add support for linking device tree blobs into vmlinux
Quoted 12 lines · Dirk Brandewie
Quoted 11 lines
To match other definitions in this file, this should be defined with
parentheses: #defineKERNEL_DTB()include/asm-generic/vmlinux.lds.h line 153
Quoted 3 lines
include/asm-generic/vmlinux.lds.h +3
-0+ . = ALIGN(32); \ + VMLINUX_SYMBOL(__dtb_start) = .; \ + *(.dtb) \I wonder if .meminit.rodata.dtb be a better section name. Could use some input from more experienced kernel hackers here. hpa, what say you?
Quoted 4 lines
I will use what ever name seems reasonable, It turns out that the sections that are named *.init.rodata are really in a R/W section :-( so that name is really a misnomer. I will check with HPA on name again.
I think they should be named *rodata* just to indicate that they should eventually be moved to a readonly section.
-hpa
PATCH v4 3/4 of/dtc: force dtb size to modulo 32 bytes
In reply to a message not in the archiveFrom: 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
@@ -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))
Signature · 1 line
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): a7e6885535e6c930560f3d79a8a55ae922499752.1289520079.git.dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Quoted 9 lines · On 11/11/2010 04:03 PM, [email protected]…
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.
Signed-off-by Dirk Brandewie <[email protected]>
I don't think 32 is a universal number; it should depend on the ABI. On x86, for one thing, I'm pretty sure that there is no particular alignment requirements beyond the natural alignment of the data items, for example.
Although 32 is probably conservative on any platform, please flag the origin of this with a comment, or make it a constant defined in a header file... otherwise, if this breaks for whatever reason it'll be near impossible to find.
-hpa
A message that is not in the archive (sent off-list or not yet received): 4CDC8EA3.6080608-VuQAYsv1563Yd54FQh9/[email protected]
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Quoted 16 lines · H. Peter Anvin
Quoted 9 lines · On 11/11/2010 04:03 PM, [email protected]…
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.
Signed-off-by Dirk Brandewie<[email protected]>I don't think 32 is a universal number; it should depend on the ABI. On x86, for one thing, I'm pretty sure that there is no particular alignment requirements beyond the natural alignment of the data items, for example.
Quoted 5 lines
Although 32 is probably conservative on any platform, please flag the origin of this with a comment, or make it a constant defined in a header file... otherwise, if this breaks for whatever reason it'll be near impossible to find.
I will change . = ALIGN(32); to STRUCT_ALIGN();
from vmlinux.lds.h:
/*
* Align to a 32 byte boundary equal to the
* alignment gcc 4.5 uses for a struct
*/
#define STRUCT_ALIGN() . = ALIGN(32)
--Dirk
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Quoted 23 lines · Dirk Brandewie
Quoted 16 lines · H. Peter Anvin
Quoted 9 lines · On 11/11/2010 04:03 PM, [email protected]…
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.
Signed-off-by Dirk Brandewie<[email protected]>I don't think 32 is a universal number; it should depend on the ABI. On x86, for one thing, I'm pretty sure that there is no particular alignment requirements beyond the natural alignment of the data items, for example.
Quoted 5 lines
Although 32 is probably conservative on any platform, please flag the origin of this with a comment, or make it a constant defined in a header file... otherwise, if this breaks for whatever reason it'll be near impossible to find.
Quoted 8 lines
I will change . = ALIGN(32); to
STRUCT_ALIGN();from
vmlinux.lds.h:
/*
* Align to a 32 byte boundary equal to the
* alignment gcc 4.5 uses for a struct
*/
#defineSTRUCT_ALIGN(). = ALIGN(32)
I also think this is the wrong place to do this. scripts/dtc is a mirror of copy of upstream dtc, designed for making dtb images for general purposes. I think the alignment should instead go into the linker script fragments you generate to incbin the dtbs.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Hi David,
Quoted 33 lines · David Gibson
Quoted 23 lines · Dirk Brandewie
Quoted 16 lines · H. Peter Anvin
Quoted 9 lines · On 11/11/2010 04:03 PM, [email protected]…
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.
Signed-off-by Dirk Brandewie<[email protected]>I don't think 32 is a universal number; it should depend on the ABI. On x86, for one thing, I'm pretty sure that there is no particular alignment requirements beyond the natural alignment of the data items, for example.
Quoted 5 lines
Although 32 is probably conservative on any platform, please flag the origin of this with a comment, or make it a constant defined in a header file... otherwise, if this breaks for whatever reason it'll be near impossible to find.
Quoted 8 lines
I will change . = ALIGN(32); to
STRUCT_ALIGN();from
vmlinux.lds.h:
/*
* Align to a 32 byte boundary equal to the
* alignment gcc 4.5 uses for a struct
*/
#defineSTRUCT_ALIGN(). = ALIGN(32)
Quoted 5 lines
I also think this is the wrong place to do this.
scripts/dtcis a mirror of copy of upstream dtc, designed for making dtb images for general purposes. I think the alignment should instead go into the linker script fragments you generate to incbin the dtbs.
I was sleep deprived when I responded to HPA I thought he had replied to the patch modifying vmlinux.lds.h since we had talked about that file a fair amount. So my first response had little bearing on patch in question.
I am trying to solve two issues with this change.
The structure needs to be 32 byte aligned for the code in fdt.c to be able parse the blob. You are right I can force this alignment in the assembly fragment.
The second issue is being able to parse the section in the kernel image to find each of the blobs that have been concatenated together. If the DTB size is modulo 32 bytes I can use blob = blob+be32_to_cpu(blob->totalsize) to find the next blob in the section and use that address directly to have fdt.c parse the blob. Otherwise I would need to search for the signature of the next blob somewhere past the end of the current blob which is knid of messy IMHO.
I have two questions,
Do you think this acceptable if I made forcing the alignment a command line argument?
Where is the DTC git tree I should be delivering patches against? is git://www.jdl.com/software/dtc.git the correct tree?
Thanks
--Dirk
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Quoted 8 lines · Dirk Brandewie
The second issue is being able to parse the section in the kernel image to find each of the blobs that have been concatenated together. If the DTB size is modulo 32 bytes I can use blob = blob+be32_to_cpu(blob->totalsize) to find the next blob in the section and use that address directly to have
fdt.cparse the blob. Otherwise I would need to search for the signature of the next blob somewhere past the end of the current blob which is knid of messy IMHO.
Not if you know it is aligned mod <whatever> bytes, then you just do:
blob = ALIGN_UP(blob + be32_to_cpu(blob->totalsize), DTB_ALIGNMENT);
This, of course, makes it even more important that DTB_ALIGNMENT is a common constant across the kernel build. The nice part is that you can just add:
.balign DTB_ALIGNMENT
... into your generated .S files and all is good.
-hpa
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
In reply to a message not in the archiveQuoted 3 lines
Where is the DTC git tree I should be delivering patches against? is
git://www.jdl.com/software/dtc.gitthe correct tree?
Yep. On this list.
Thanks!
jdl
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
In reply to a message not in the archiveQuoted 3 lines · Dirk Brandewie
Hi David,
Quoted 1 line · David Gibson
On Thu, Nov 11, 2010 at 05:01:16PM -0800, Dirk Brandewie wrote:
[snip]
Quoted 16 lines
Quoted 4 lines
I also think this is the wrong place to do this.
scripts/dtcis a mirror of copy of upstream dtc, designed for making dtb images for general purposes. I think the alignment should instead go into the linker script fragments you generate to incbin the dtbs.I was sleep deprived when I responded to HPA I thought he had replied to the patch modifying
vmlinux.lds.hsince we had talked about that file a fair amount. So my first response had little bearing on patch in question.I am trying to solve two issues with this change.
The structure needs to be 32 byte aligned for the code in
fdt.cto be able parse the blob. You are right I can force this alignment in the assembly fragment.
Quoted 8 lines
The second issue is being able to parse the section in the kernel image to find each of the blobs that have been concatenated together. If the DTB size is modulo 32 bytes I can use blob = blob+be32_to_cpu(blob->totalsize) to find the next blob in the section and use that address directly to have
fdt.cparse the blob. Otherwise I would need to search for the signature of the next blob somewhere past the end of the current blob which is knid of messy IMHO.
As hpa says you can just align your increment too, to find the next blob.
Quoted 3 lines
I have two questions,
Do you think this acceptable if I made forcing the alignment a command line argument?
Um, sure. It's not actually necessary for what you're doing here, but it might have some use, I guess, and it's pretty non-invasive. Your posted patch for this, however, is broken, see my comments in reply,
Quoted 2 lines
Where is the DTC git tree I should be delivering patches against? is
git://www.jdl.com/software/dtc.gitthe correct tree?
That's right.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [sodaville] [PATCH 3/4] of/dtc: force dtb size to modulo 32 bytes
Quoted 1 line · David Gibson
On Fri, Nov 12, 2010 at 08:24:53AM -0800, Dirk Brandewie wrote:
[snip]
Quoted 15 lines
Quoted 6 lines
I am trying to solve two issues with this change.
The structure needs to be 32 byte aligned for the code in
fdt.cto be able parse the blob. You are right I can force this alignment in the assembly fragment.Quoted 8 lines
The second issue is being able to parse the section in the kernel image to find each of the blobs that have been concatenated together. If the DTB size is modulo 32 bytes I can use blob = blob+be32_to_cpu(blob->totalsize) to find the next blob in the section and use that address directly to have
fdt.cparse the blob. Otherwise I would need to search for the signature of the next blob somewhere past the end of the current blob which is knid of messy IMHO.
Quoted 2 lines
As hpa says you can just align your increment too, to find the next blob.
+1
I agree, handle the alignment issues entirely within the kernel. You don't need to modify dtc to get the behaviour you want.
Quoted 8 lines
Quoted 4 lines
I have two questions,
Do you think this acceptable if I made forcing the alignment a command line argument?Um, sure. It's not actually necessary for what you're doing here, but it might have some use, I guess, and it's pretty non-invasive. Your posted patch for this, however, is broken, see my comments in reply,
I disagree here. True it is non-invasive, but I'd rather not be adding yet another command line option unless there was a real use-case for doing so.
g.
PATCH v4 4/4 of/fdt: add kernel command line option for dtb_compat string
In reply to a message not in the archiveFrom: 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
@@ -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
@@ -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
Signature · 1 line
1.7.2.3
A message that is not in the archive (sent off-list or not yet received): 855a5a11d04a7c1883675b6a77992c4af85222fd.1289520079.git.dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Re: [PATCH 4/4] of/fdt: add kernel command line option for dtb_compat string
Quoted 23 lines · On Thu, Nov 11, 2010 at 04:03:50PM -0800…
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.
Signed-off-by Dirk Brandewie <[email protected]>--- drivers/of/fdt.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_fdt.h | 9 ++++++++ 2 files changed, 61 insertions(+), 0 deletions(-)drivers/of/fdt.c +3
-0@@ -604,3 +604,55 @@ void __init unflatten_device_tree(void)pr_debug (" <- unflatten_device_tree()\n" ); } + +#ifndef MODULE +#ifdef CONFIG_OF_FLATTREE
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 619
Quoted 10 lines
drivers/of/fdt.c +10
-0+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[];
'char' is completely bogus in this context. Either void or struct boot_param_header would be more accurate and useful. I believe you can do:
extern void __dtb_start; extern_void __dtb_end;
And then reference the addresses with &__dtb_start and &__dtb_end. That would eliminate a lot of the casting below.
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 630
Quoted 11 lines
drivers/of/fdt.c +11
-0+ +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){
Don't bother with this if(); the empty condition can be handled in the while (blob < __dtb_end){...} block. That way a level of indentation can be removed.
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 634
Quoted 4 lines
drivers/of/fdt.c +4
-0+ blob = (struct boot_param_header *)__dtb_start; + do{ + node = ((unsigned long)blob) + + be32_to_cpu(blob->off_dt_struct);
Ugly casting. I would work with everything as pointers (make node and blob void*) and only cast when necessary....
wait....
'node' isn't actually used anywhere. Why is this here?
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 635
Quoted 1 line
drivers/of/fdt.c +1
-0+ initial_boot_params = blob;
Blech! I really need to get Stephen (cc'd) to respin his "of/fdt: Add unflatten_partial_device_tree" patch that decouples the flattree functions from initial_boot_params. Having to do it this way is just plain ugly.
Stephen: nudge, nudge.
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 638
Quoted 3 lines
drivers/of/fdt.c +3
-0+ root =of_get_flat_dt_root (); +if (of_flat_dt_is_compatible (root, name) >0 ) { + rc = (void *) blob;
Unnecessary cast. Any regular pointer can always be assigned to a void* variable without a cast..
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 642
Quoted 4 lines
drivers/of/fdt.c +4
-0+break ; + } + blob = (unsigned long )blob+be32_to_cpu (blob->totalsize); + }while (blob < (struct boot_param_header *)__dtb_end);
Minor coding convention violations. It is worth running it through checkpatch.pl before submitting. checkpatch may not proclaim the gospel, but it is a useful tool.
Quoted 4 lines
drivers/of/fdt.c +4
-0+ } +if (rc ==NULL ) + initial_boot_params = orig_initial_boot_params; +return rc;
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 656
Quoted 10 lines
drivers/of/fdt.c +10
-0+} +#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);
Could the searching of the linked-in dtbs be handled here at __setup time? That would eliminate the need for a fixed size dtb_compat_name variable.
Also need to add documentation for dtb_compat parameter to Documentation/kernel-parameters.txt
include/linux/of_fdt.h struct boot_param_header { · line 62
Quoted 12 lines
drivers/of/fdt.c +2
-0+#endif +#endif include/linux/of_fdt.h +2
-0@@ -58,6 +58,8 @@ struct boot_param_header { };#if defined(CONFIG_OF_FLATTREE ) +#define MAX_DTB_COMPAT_STR 64 +
Nothing outside fdt.c uses MAC_DTB_COMPAT_STR, so this define should also be in fdt.c
Quoted 24 lines
include/linux/of_fdt.h +7
-0/* 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 Signature · 6 lines
1.7.2.3 _______________________________________________ devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected] https://lists.ozlabs.org/listinfo/devicetree-discuss
RE: [PATCH 4/4] of/fdt: add kernel command line option for dtb_compat string
Quoted 10 lines
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 635
Quoted 3 lines
drivers/of/fdt.c +1
-0+ initial_boot_params = blob;Blech! I really need to get Stephen (cc'd) to respin his "of/fdt: Add
unflatten_partial_device_tree" patch that decouples the flattree functions frominitial_boot_params. Having to do it this way is just plain ugly.Stephen: nudge, nudge.
If things have settled down, I'll dust them off again. Don't know if it will happen this week: I'm called for jury duty.
Steve
This email and any attachments are intended for the sole use of the named recipient(s) and contain(s) confidential information that may be proprietary, privileged or copyrighted under applicable law. If you are not the intended recipient, do not read, copy, or forward this email message or any attachments. Delete this email message and any attachments immediately.
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
A message that is not in the archive (sent off-list or not yet received): 2573ead1-944d-4ba5-ace3-12936693d872-RaUQJvECHiv5op9OF0Koj7jjLBE8jN/[email protected]
Re: [PATCH 4/4] of/fdt: add kernel command line option for dtb_compat string
Quoted 9 lines · Stephen Neuendorffer
Quoted 8 lines
Quoted 3 lines
+
initial_boot_params= blob;Blech! I really need to get Stephen (cc'd) to respin his "of/fdt: Add
unflatten_partial_device_tree" patch that decouples the flattree functions from initial_boot_params. Having to do it this way is just plain ugly.
Quoted 4 lines
Quoted 1 line
Stephen: nudge, nudge.
If things have settled down, I'll dust them off again. Don't know if it will happen this week: I'm called for jury duty.
Ouch! Have fun.
g.
A message that is not in the archive (sent off-list or not yet received): 20101114062246.GD2355-MrY2KI0G/OVr83L8+7iqerDks+cytr/[email protected]
Re: [PATCH 4/4] of/fdt: add kernel command line option for dtb_compat string
Quoted 11 lines · Grant Likely
'char' is completely bogus in this context. Either void or struct
boot_param_headerwould be more accurate and useful. I believe you can do:extern void __dtb_start; extern_void __dtb_end;And then reference the addresses with
&__dtb_startand&__dtb_end. That would eliminate a lot of the casting below.
Except that doesn't work with gcc 4.5+; you really need to use an array type.
-hpa
A message that is not in the archive (sent off-list or not yet received): 4CE1CFDA.7030900-VuQAYsv1563Yd54FQh9/[email protected]
Re: [PATCH 4/4] of/fdt: add kernel command line option for dtb_compat string
Quoted 9 lines · H. Peter Anvin
Quoted 8 lines · Grant Likely
'char' is completely bogus in this context. Either void or struct
boot_param_headerwould be more accurate and useful. I believe you can do:extern void __dtb_start; extern_void __dtb_end;
Quoted 6 lines
Quoted 3 lines
And then reference the addresses with
&__dtb_startand&__dtb_end. That would eliminate a lot of the casting below.Except that doesn't work with gcc 4.5+; you really need to use an array type.
heh. Oh well, an array it must be then.
g.