Skip to content

Commit ad0888f

Browse files
committed
fixup! BCM2708: Add core Device Tree support
Signed-off-by: Phil Elwell <[email protected]>
1 parent 28ae262 commit ad0888f

File tree

4 files changed

+132
-249
lines changed

4 files changed

+132
-249
lines changed

scripts/Makefile.build

Lines changed: 101 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,88 @@ include $(srctree)/scripts/Makefile.compiler
3737
include $(kbuild-file)
3838
include $(srctree)/scripts/Makefile.lib
3939

40-
# Do not include hostprogs rules unless needed.
41-
# $(sort ...) is used here to remove duplicated words and excessive spaces.
42-
hostprogs := $(sort $(hostprogs))
43-
ifneq ($(hostprogs),)
44-
include $(srctree)/scripts/Makefile.host
40+
# flags that take effect in current and sub directories
41+
KBUILD_AFLAGS += $(subdir-asflags-y)
42+
KBUILD_CFLAGS += $(subdir-ccflags-y)
43+
KBUILD_RUSTFLAGS += $(subdir-rustflags-y)
44+
45+
# Figure out what we need to build from the various variables
46+
# ===========================================================================
47+
48+
# When an object is listed to be built compiled-in and modular,
49+
# only build the compiled-in version
50+
obj-m := $(filter-out $(obj-y),$(obj-m))
51+
52+
# Libraries are always collected in one lib file.
53+
# Filter out objects already built-in
54+
lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
55+
56+
# Subdirectories we need to descend into
57+
subdir-ym := $(sort $(subdir-y) $(subdir-m) \
58+
$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
59+
60+
# Handle objects in subdirs:
61+
# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
62+
# foo/modules.order
63+
# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
64+
#
65+
# Generate modules.order to determine modorder. Unfortunately, we don't have
66+
# information about ordering between -y and -m subdirs. Just put -y's first.
67+
68+
ifdef need-modorder
69+
obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
70+
else
71+
obj-m := $(filter-out %/, $(obj-m))
4572
endif
4673

47-
# Do not include userprogs rules unless needed.
48-
# $(sort ...) is used here to remove duplicated words and excessive spaces.
49-
userprogs := $(sort $(userprogs))
50-
ifneq ($(userprogs),)
51-
include $(srctree)/scripts/Makefile.userprogs
74+
ifdef need-builtin
75+
obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
76+
else
77+
obj-y := $(filter-out %/, $(obj-y))
78+
endif
79+
80+
# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
81+
suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
82+
# List composite targets that are constructed by combining other targets
83+
multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
84+
# List primitive targets that are compiled from source files
85+
real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
86+
87+
# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
88+
multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
89+
multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
90+
multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
91+
92+
# Replace multi-part objects by their individual parts,
93+
# including built-in.a from subdirectories
94+
real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
95+
real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
96+
97+
always-y += $(always-m)
98+
99+
# hostprogs-always-y += foo
100+
# ... is a shorthand for
101+
# hostprogs += foo
102+
# always-y += foo
103+
hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
104+
always-y += $(hostprogs-always-y) $(hostprogs-always-m)
105+
106+
# userprogs-always-y is likewise.
107+
userprogs += $(userprogs-always-y) $(userprogs-always-m)
108+
always-y += $(userprogs-always-y) $(userprogs-always-m)
109+
110+
# Add subdir path
111+
112+
ifneq ($(obj),.)
113+
extra-y := $(addprefix $(obj)/, $(extra-y))
114+
always-y := $(addprefix $(obj)/, $(always-y))
115+
targets := $(addprefix $(obj)/, $(targets))
116+
obj-m := $(addprefix $(obj)/, $(obj-m))
117+
lib-y := $(addprefix $(obj)/, $(lib-y))
118+
real-obj-y := $(addprefix $(obj)/, $(real-obj-y))
119+
real-obj-m := $(addprefix $(obj)/, $(real-obj-m))
120+
multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
121+
subdir-ym := $(addprefix $(obj)/, $(subdir-ym))
52122
endif
53123

54124
ifndef obj
@@ -67,7 +137,6 @@ endif
67137
# subdir-builtin and subdir-modorder may contain duplications. Use $(sort ...)
68138
subdir-builtin := $(sort $(filter %/built-in.a, $(real-obj-y)))
69139
subdir-modorder := $(sort $(filter %/modules.order, $(obj-m)))
70-
subdir-dtbslist := $(sort $(filter %/dtbs-list, $(dtb-y)))
71140

72141
targets-for-builtin := $(extra-y)
73142

@@ -360,7 +429,7 @@ $(obj)/%.o: $(obj)/%.S FORCE
360429

361430
targets += $(filter-out $(subdir-builtin), $(real-obj-y))
362431
targets += $(filter-out $(subdir-modorder), $(real-obj-m))
363-
targets += $(real-dtb-y) $(lib-y) $(always-y)
432+
targets += $(lib-y) $(always-y)
364433

365434
# Linker scripts preprocessor (.lds.S -> .lds)
366435
# ---------------------------------------------------------------------------
@@ -386,7 +455,6 @@ $(obj)/%.asn1.c $(obj)/%.asn1.h: $(src)/%.asn1 $(objtree)/scripts/asn1_compiler
386455
# To build objects in subdirs, we need to descend into the directories
387456
$(subdir-builtin): $(obj)/%/built-in.a: $(obj)/% ;
388457
$(subdir-modorder): $(obj)/%/modules.order: $(obj)/% ;
389-
$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ;
390458

391459
#
392460
# Rule to compile a set of .o files into one .a file (without symbol table)
@@ -412,9 +480,6 @@ cmd_gen_order = { $(foreach m, $(real-prereqs), \
412480
$(obj)/modules.order: $(obj-m) FORCE
413481
$(call if_changed,gen_order)
414482

415-
$(obj)/dtbs-list: $(dtb-y) $(dtbo-y) FORCE
416-
$(call if_changed,gen_order)
417-
418483
#
419484
# Rule to compile a set of .o files into one .a file (with symbol table)
420485
#
@@ -443,15 +508,26 @@ intermediate_targets = $(foreach sfx, $(2), \
443508
$(patsubst %$(strip $(1)),%$(sfx), \
444509
$(filter %$(strip $(1)), $(targets))))
445510
# %.asn1.o <- %.asn1.[ch] <- %.asn1
446-
# %.dtb.o <- %.dtb.S <- %.dtb <- %.dts
447-
# %.dtbo.o <- %.dtbo.S <- %.dtbo <- %.dtso
448-
# %.lex.o <- %.lex.c <- %.l
449-
# %.tab.o <- %.tab.[ch] <- %.y
450-
targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h) \
451-
$(call intermediate_targets, .dtb.o, .dtb.S .dtb) \
452-
$(call intermediate_targets, .dtbo.o, .dtbo.S .dtbo) \
453-
$(call intermediate_targets, .lex.o, .lex.c) \
454-
$(call intermediate_targets, .tab.o, .tab.c .tab.h)
511+
targets += $(call intermediate_targets, .asn1.o, .asn1.c .asn1.h)
512+
513+
# Include additional build rules when necessary
514+
# ---------------------------------------------------------------------------
515+
516+
# $(sort ...) is used here to remove duplicated words and excessive spaces.
517+
hostprogs := $(sort $(hostprogs))
518+
ifneq ($(hostprogs),)
519+
include $(srctree)/scripts/Makefile.host
520+
endif
521+
522+
# $(sort ...) is used here to remove duplicated words and excessive spaces.
523+
userprogs := $(sort $(userprogs))
524+
ifneq ($(userprogs),)
525+
include $(srctree)/scripts/Makefile.userprogs
526+
endif
527+
528+
ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),)
529+
include $(srctree)/scripts/Makefile.dtbs
530+
endif
455531

456532
# Build
457533
# ---------------------------------------------------------------------------

scripts/Makefile.dtbinst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ $(dst)/%: $(obj)/$(1)%
3131
$$(call cmd,dtb_install)
3232
endef
3333

34-
$(foreach d, $(sort $(dir $(dtbs))), $(eval $(call gen_install_rules,$(d))))
34+
define overlays_install_rules
35+
$(dst)/overlays/%: $(obj)/$(1)%
36+
$$(call cmd,dtb_install)
37+
endef
38+
39+
$(foreach d, $(sort $(dir $(dtbs))), $(if $(findstring "overlays/","$(d)"),$(eval $(call overlays_install_rules,$(d))),$(eval $(call gen_install_rules,$(d)))))
3540

36-
dtbs := $(notdir $(dtbs))
41+
dtbs := $(foreach d, $(dtbs), $(if $(findstring overlays/,$(d)),$(d),$(notdir $(d))))
3742

3843
endif # CONFIG_ARCH_WANT_FLAT_DTB_INSTALL
3944

scripts/Makefile.dtbs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ base-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs))
1313
dtb-y := $(addprefix $(obj)/, $(dtb-y))
1414
multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
1515
real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
16+
dtbo-y := $(addprefix $(obj)/, $(dtbo-y))
1617

1718
always-y += $(dtb-y)
1819
targets += $(real-dtb-y)
@@ -28,7 +29,7 @@ endif
2829

2930
$(subdir-dtbslist): $(obj)/%/dtbs-list: $(obj)/% ;
3031

31-
$(obj)/dtbs-list: $(dtb-y) FORCE
32+
$(obj)/dtbs-list: $(dtb-y) $(dtbo-y) FORCE
3233
$(call if_changed,gen_order)
3334

3435
# Assembly file to wrap dtb(o)
@@ -119,11 +120,32 @@ dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc -I $(DTC_INCLUDE) -undef -
119120

120121
dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
121122

123+
quiet_cmd_dtco = DTCO $(quiet_dtb_check_tag) $@
124+
cmd_dtco = \
125+
$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
126+
$(DTC) -@ -H epapr -O dtb -o $@ -b 0 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) \
127+
$(DTC_FLAGS) $(DTC_FLAGS_$(target-stem)) \
128+
-Wno-avoid_default_addr_size \
129+
-Wno-gpios_property \
130+
-Wno-i2c_bus_reg \
131+
-Wno-interrupt_provider \
132+
-Wno-interrupts_property \
133+
-Wno-label_is_string \
134+
-Wno-pci_device_bus_num \
135+
-Wno-reg_format \
136+
-Wno-spi_bus_reg \
137+
-d $(depfile).dtc.tmp $(dtc-tmp) ; \
138+
cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
139+
140+
$(obj)/%.dtbo: $(src)/%-overlay.dts $(DTC) FORCE
141+
$(call if_changed_dep,dtco)
142+
122143
quiet_cmd_dtc = DTC $(quiet_dtb_check_tag) $@
123144
cmd_dtc = \
124145
$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
125146
$(DTC) -o $@ -b 0 $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) \
126-
$(DTC_FLAGS) -d $(depfile).dtc.tmp $(dtc-tmp) ; \
147+
$(DTC_FLAGS) $(DTC_FLAGS_$(target-stem)) \
148+
-d $(depfile).dtc.tmp $(dtc-tmp); \
127149
cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) \
128150
$(cmd_dtb_check)
129151

0 commit comments

Comments
 (0)