Skip to content

Commit aab9433

Browse files
dirk-brandewieglikely
authored andcommitted
of: Add support for linking device tree blobs into vmlinux
This patch adds support for linking device tree blob(s) into vmlinux. Modifies asm-generic/vmlinux.lds.h to add linking .dtb sections into vmlinux. To maintain compatiblity with the of/fdt driver code platforms MUST copy the blob to a non-init memory location before the kernel frees the .init.* sections in the image. Modifies scripts/Makefile.lib to add a kbuild command to compile DTS files to device tree blobs and a rule to create objects to wrap the blobs for linking. STRUCT_ALIGNMENT is defined in vmlinux.lds.h for use in the rule to create wrapper objects for the dtb in Makefile.lib. The STRUCT_ALIGN() macro in vmlinux.lds.h is modified to use the STRUCT_ALIGNMENT definition. The DTB's are placed on 32 byte boundries to allow parsing the blob with driver/of/fdt.c during early boot without having to copy the blob to get the structure alignment GCC expects. A DTB is linked in by adding the DTB object to the list of objects to be linked into vmlinux in the archtecture specific Makefile using obj-y += foo.dtb.o Signed-off-by: Dirk Brandewie <dirk.brandewie@gmail.com> Acked-by: Michal Marek <mmarek@suse.cz> [grant.likely@secretlab.ca: cleaned up whitespace inconsistencies] Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
1 parent cfb13c5 commit aab9433

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

‎Documentation/kbuild/makefiles.txt‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,21 @@ When kbuild executes, the following steps are followed (roughly):
11361136
resulting in the target file being recompiled for no
11371137
obvious reason.
11381138

1139+
dtc
1140+
Create flattend device tree blob object suitable for linking
1141+
into vmlinux. Device tree blobs linked into vmlinux are placed
1142+
in an init section in the image. Platform code *must* copy the
1143+
blob to non-init memory prior to calling unflatten_device_tree().
1144+
1145+
Example:
1146+
#arch/x86/platform/ce4100/Makefile
1147+
clean-files := *dtb.S
1148+
1149+
DTC_FLAGS := -p 1024
1150+
obj-y += foo.dtb.o
1151+
1152+
$(obj)/%.dtb: $(src)/%.dts
1153+
$(call cmd,dtc)
11391154

11401155
--- 6.7 Custom kbuild commands
11411156

‎include/asm-generic/vmlinux.lds.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
* Align to a 32 byte boundary equal to the
6868
* alignment gcc 4.5 uses for a struct
6969
*/
70-
#define STRUCT_ALIGN() . = ALIGN(32)
70+
#define STRUCT_ALIGNMENT 32
71+
#define STRUCT_ALIGN() . = ALIGN(STRUCT_ALIGNMENT)
7172

7273
/* The actual configuration determine if the init/exit sections
7374
* are handled as text/data or they can be discarded (which
@@ -146,6 +147,13 @@
146147
#define TRACE_SYSCALLS()
147148
#endif
148149

150+
151+
#define KERNEL_DTB() \
152+
STRUCT_ALIGN(); \
153+
VMLINUX_SYMBOL(__dtb_start) = .; \
154+
*(.dtb.init.rodata) \
155+
VMLINUX_SYMBOL(__dtb_end) = .;
156+
149157
/* .data section */
150158
#define DATA_DATA \
151159
*(.data) \
@@ -468,7 +476,8 @@
468476
MCOUNT_REC() \
469477
DEV_DISCARD(init.rodata) \
470478
CPU_DISCARD(init.rodata) \
471-
MEM_DISCARD(init.rodata)
479+
MEM_DISCARD(init.rodata) \
480+
KERNEL_DTB()
472481

473482
#define INIT_TEXT \
474483
*(.init.text) \

‎scripts/Makefile.lib‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,29 @@ quiet_cmd_gzip = GZIP $@
200200
cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -f -9 > $@) || \
201201
(rm -f $@ ; false)
202202

203+
# DTC
204+
# ---------------------------------------------------------------------------
205+
206+
# Generate an assembly file to wrap the output of the device tree compiler
207+
quiet_cmd_dt_S_dtb= DTB $@
208+
cmd_dt_S_dtb= \
209+
( \
210+
echo '\#include <asm-generic/vmlinux.lds.h>'; \
211+
echo '.section .dtb.init.rodata,"a"'; \
212+
echo '.balign STRUCT_ALIGNMENT'; \
213+
echo '.global __dtb_$(*F)_begin'; \
214+
echo '__dtb_$(*F)_begin:'; \
215+
echo '.incbin "$<" '; \
216+
echo '__dtb_$(*F)_end:'; \
217+
echo '.global __dtb_$(*F)_end'; \
218+
echo '.balign STRUCT_ALIGNMENT'; \
219+
) > $@
220+
221+
$(obj)/%.dtb.S: $(obj)/%.dtb
222+
$(call cmd,dt_S_dtb)
223+
224+
quiet_cmd_dtc = DTC $@
225+
cmd_dtc = $(objtree)/scripts/dtc/dtc -O dtb -o $@ -b 0 $(DTC_FLAGS) $<
203226

204227
# Bzip2
205228
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)