[PATCH 1/2] of: Add support for linking device tree blobs into vmlinux

Grant Likely grant.likely at secretlab.ca
Tue Nov 16 16:17:11 EST 2010


On Mon, Nov 15, 2010 at 10:06 PM, Dirk Brandewie
<dirk.brandewie at gmail.com> wrote:
> On 11/15/2010 08:41 PM, Grant Likely wrote:
>>
>> On Mon, Nov 15, 2010 at 08:01:20PM -0800, dirk.brandewie at gmail.com wrote:
>>>
>>> From: Dirk Brandewie<dirk.brandewie at gmail.com>
>>>
>>> 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<dirk.brandewie at gmail.com>
>>> ---
>>>  include/asm-generic/vmlinux.lds.h |   19 +++++++++++++++++--
>>>  scripts/Makefile.lib              |   17 +++++++++++++++++
>>>  2 files changed, 34 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/asm-generic/vmlinux.lds.h
>>> b/include/asm-generic/vmlinux.lds.h
>>> index bd69d79..ea671e7 100644
>>> --- a/include/asm-generic/vmlinux.lds.h
>>> +++ b/include/asm-generic/vmlinux.lds.h
>>> @@ -67,7 +67,14 @@
>>>   * Align to a 32 byte boundary equal to the
>>>   * alignment gcc 4.5 uses for a struct
>>>   */
>>> -#define STRUCT_ALIGN() . = ALIGN(32)
>>> +#define STRUCT_ALIGNMENT 32
>>> +#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
>>> +
>>> +/* Device tree blobs linked into the kernel need to have proper
>>> + * structure alignment to be parsed by the flat device tree library
>>> + * used in early boot
>>> +*/
>>> +#define DTB_ALIGNMENT STRUCT_ALIGNMENT
>>>
>>>  /* The actual configuration determine if the init/exit sections
>>>   * are handled as text/data or they can be discarded (which
>>> @@ -146,6 +153,13 @@
>>>  #define TRACE_SYSCALLS()
>>>  #endif
>>>
>>> +
>>> +#define KERNEL_DTB()                                                   \
>>> +       . = ALIGN(DTB_ALIGNMENT);                                       \
>>> +       VMLINUX_SYMBOL(__dtb_start) = .;                                \
>>> +       *(.dtb.init.rodata)                                             \
>>> +       VMLINUX_SYMBOL(__dtb_end) = .;
>>> +
>>>  /* .data section */
>>>  #define DATA_DATA                                                     \
>>>        *(.data)                                                        \
>>> @@ -468,7 +482,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)                                                   \
>>> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
>>> index 4c72c11..a8a4774 100644
>>> --- a/scripts/Makefile.lib
>>> +++ b/scripts/Makefile.lib
>>> @@ -200,6 +200,23 @@ quiet_cmd_gzip = GZIP    $@
>>>  cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9>  $@) || \
>>>        (rm -f $@ ; false)
>>>
>>> +# DTC
>>> +#
>>>  ---------------------------------------------------------------------------
>>> +$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
>>> +       @echo '#include<asm-generic/vmlinux.lds.h>'>  $@
>>> +       @echo '.section .dtb.init.rodata,"a"'>>  $@
>>> +       @echo '.balign DTB_ALIGNMENT'>>  $@
>>> +       @echo '.global __dtb_$(*F)_begin'>>  $@
>>> +       @echo '__dtb_$(*F)_begin:'>>  $@
>>> +       @echo '.incbin "$<" '>>  $@
>>> +       @echo '__dtb_$(*F)_end:'>>  $@
>>> +       @echo '.global __dtb_$(*F)_end'>>  $@
>>> +       @echo '.balign DTB_ALIGNMENT'>>  $@
>>> +
>>> +DTC = $(objtree)/scripts/dtc/dtc
>>> +
>>> +quiet_cmd_dtc = DTC    $@
>>> +      cmd_dtc = $(DTC) -O dtb -o $(obj)/$*.dtb -b 0  $(src)/$*.dts
>>
>> Missing the %.dtb: %.dts rule, but otherwise looks okay.  You will
>> need to make sure this doesn't break powerpc or microblaze when the
>> dts->dtb rule is added.
>>
> I have the rule
>  $(obj)/%.dtb: $(src)/%.dts
>          $(call if_changed,dtc)
> in the arch/x86/kernel/Makefile to prevent this sneaking into other other
> architectures.

This rule looks correct.  PowerPC and Microblaze need to be modified
to use it.  It should not be hard to do, give it a try.  Worst case,
your first attempt is wrong and the rest of us fix it up.  :-)

Hint: PowerPC currently puts the .dtb file in a different directory
from the source .dts file.  It doesn't need to do it that way.
arch/powerpc/boot/Makefile will need to be modified.

g.

>
> I need some more skilled in kbuild to help craft the more generic rule so we
> can have the dts files anywhere in the arch/<*>/ directory structure and be
> able to find the correct dts files.
>
> --Dirk
>



-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.


More information about the Linuxppc-dev mailing list