"Das U-Boot" Source Tree
at pomera-dm250 841 lines 31 kB view raw
1# SPDX-License-Identifier: GPL-2.0 2# Backward compatibility 3asflags-y += $(EXTRA_AFLAGS) 4ccflags-y += $(EXTRA_CFLAGS) 5cppflags-y += $(EXTRA_CPPFLAGS) 6ldflags-y += $(EXTRA_LDFLAGS) 7 8# flags that take effect in current and sub directories 9KBUILD_AFLAGS += $(subdir-asflags-y) 10KBUILD_CFLAGS += $(subdir-ccflags-y) 11 12# Figure out what we need to build from the various variables 13# =========================================================================== 14 15# When an object is listed to be built compiled-in and modular, 16# only build the compiled-in version 17obj-m := $(filter-out $(obj-y),$(obj-m)) 18 19# Libraries are always collected in one lib file. 20# Filter out objects already built-in 21lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m))) 22 23# Subdirectories we need to descend into 24subdir-ym := $(sort $(subdir-y) $(subdir-m) \ 25 $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m)))) 26 27# Handle objects in subdirs: 28# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and 29# foo/modules.order 30# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order 31# 32# Generate modules.order to determine modorder. Unfortunately, we don't have 33# information about ordering between -y and -m subdirs. Just put -y's first. 34 35ifdef need-modorder 36obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m)) 37else 38obj-m := $(filter-out %/, $(obj-m)) 39endif 40 41ifdef need-builtin 42obj-y := $(patsubst %/, %/built-in.a, $(obj-y)) 43else 44obj-y := $(filter-out %/, $(obj-y)) 45endif 46 47# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals 48suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s)))) 49# List composite targets that are constructed by combining other targets 50multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m))) 51# List primitive targets that are compiled from source files 52real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m)) 53 54# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object 55multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y) 56multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m) 57multi-obj-ym := $(multi-obj-y) $(multi-obj-m) 58 59# Replace multi-part objects by their individual parts, 60# including built-in.a from subdirectories 61real-obj-y := $(call real-search, $(obj-y), .o, -objs -y) 62real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m) 63 64always-y += $(always-m) 65 66# hostprogs-always-y += foo 67# ... is a shorthand for 68# hostprogs += foo 69# always-y += foo 70hostprogs += $(hostprogs-always-y) $(hostprogs-always-m) 71always-y += $(hostprogs-always-y) $(hostprogs-always-m) 72 73# userprogs-always-y is likewise. 74userprogs += $(userprogs-always-y) $(userprogs-always-m) 75always-y += $(userprogs-always-y) $(userprogs-always-m) 76 77# Composite DTB (i.e. DTB constructed by overlay) 78multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs) 79# Primitive DTB compiled from *.dts 80real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs) 81# Base DTB that overlay is applied onto (each first word of $(*-dtbs) expansion) 82base-dtb-y := $(foreach m, $(multi-dtb-y), $(firstword $(call suffix-search, $m, .dtb, -dtbs))) 83 84# DTB 85# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built 86extra-y += $(dtb-y) 87extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-) 88 89# U-Boot specific 90ifneq ($(CHECK_DTBS),) 91extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y)) 92extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-)) 93endif 94 95# Add subdir path 96 97extra-y := $(addprefix $(obj)/,$(extra-y)) 98always-y := $(addprefix $(obj)/,$(always-y)) 99targets := $(addprefix $(obj)/,$(targets)) 100obj-m := $(addprefix $(obj)/,$(obj-m)) 101lib-y := $(addprefix $(obj)/,$(lib-y)) 102real-obj-y := $(addprefix $(obj)/,$(real-obj-y)) 103real-obj-m := $(addprefix $(obj)/,$(real-obj-m)) 104multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m)) 105multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y)) 106real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y)) 107subdir-ym := $(addprefix $(obj)/,$(subdir-ym)) 108 109# Finds the multi-part object the current object will be linked into. 110# If the object belongs to two or more multi-part objects, list them all. 111modname-multi = $(sort $(foreach m,$(multi-obj-ym),\ 112 $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=)))) 113 114__modname = $(or $(modname-multi),$(basetarget)) 115 116modname = $(subst $(space),:,$(__modname)) 117modfile = $(addprefix $(obj)/,$(__modname)) 118 119# target with $(obj)/ and its suffix stripped 120target-stem = $(basename $(patsubst $(obj)/%,%,$@)) 121 122# These flags are needed for modversions and compiling, so we define them here 123# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will 124# end up in (or would, if it gets compiled in) 125name-fix-token = $(subst $(comma),_,$(subst -,_,$1)) 126name-fix = $(call stringify,$(call name-fix-token,$1)) 127basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget)) 128modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \ 129 -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname)) 130modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile)) 131 132_c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \ 133 $(filter-out $(ccflags-remove-y), \ 134 $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \ 135 $(CFLAGS_$(target-stem).o)) 136_a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \ 137 $(filter-out $(asflags-remove-y), \ 138 $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \ 139 $(AFLAGS_$(target-stem).o)) 140_cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds) 141 142# 143# Enable gcov profiling flags for a file, directory or for all files depending 144# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL 145# (in this order) 146# 147ifeq ($(CONFIG_GCOV_KERNEL),y) 148_c_flags += $(if $(patsubst n%,, \ 149 $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \ 150 $(CFLAGS_GCOV)) 151endif 152 153# 154# Enable address sanitizer flags for kernel except some files or directories 155# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE) 156# 157ifeq ($(CONFIG_KASAN),y) 158ifneq ($(CONFIG_KASAN_HW_TAGS),y) 159_c_flags += $(if $(patsubst n%,, \ 160 $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \ 161 $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE)) 162endif 163endif 164 165ifeq ($(CONFIG_UBSAN),y) 166_c_flags += $(if $(patsubst n%,, \ 167 $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \ 168 $(CFLAGS_UBSAN)) 169endif 170 171ifeq ($(CONFIG_KCOV),y) 172_c_flags += $(if $(patsubst n%,, \ 173 $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \ 174 $(CFLAGS_KCOV)) 175endif 176 177# 178# Enable KCSAN flags except some files or directories we don't want to check 179# (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE) 180# 181ifeq ($(CONFIG_KCSAN),y) 182_c_flags += $(if $(patsubst n%,, \ 183 $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \ 184 $(CFLAGS_KCSAN)) 185# Some uninstrumented files provide implied barriers required to avoid false 186# positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only. 187_c_flags += $(if $(patsubst n%,, \ 188 $(KCSAN_INSTRUMENT_BARRIERS_$(basetarget).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \ 189 -D__KCSAN_INSTRUMENT_BARRIERS__) 190endif 191 192# $(srctree)/$(src) for including checkin headers from generated source files 193# $(objtree)/$(obj) for including generated headers from checkin source files 194ifeq ($(KBUILD_EXTMOD),) 195ifdef building_out_of_srctree 196_c_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj) 197_a_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj) 198_cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj) 199endif 200endif 201 202part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y) 203quiet_modtag = $(if $(part-of-module),[M], ) 204 205modkern_cflags = \ 206 $(if $(part-of-module), \ 207 $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \ 208 $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags)) 209 210modkern_aflags = $(if $(part-of-module), \ 211 $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \ 212 $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL)) 213 214 215# Modified for U-Boot: LINUXINCLUDE -> UBOOTINCLUDE 216# removed the inclusion of compiler_types.h for sandbox build 217c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE) \ 218 $(_c_flags) $(modkern_cflags) \ 219 $(basename_flags) $(modname_flags) 220 221a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE) \ 222 $(_a_flags) $(modkern_aflags) 223 224cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(UBOOTINCLUDE) \ 225 $(_cpp_flags) 226 227ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F)) 228 229# Try these files in order to find the U-Boot-specific .dtsi include file 230u_boot_dtsi_loc = $(srctree)/arch/$(ARCH)/dts/ 231 232u_boot_dtsi_options = $(strip $(wildcard $(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi) \ 233 $(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi) \ 234 $(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi) \ 235 $(wildcard $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi) \ 236 $(wildcard $(u_boot_dtsi_loc)u-boot.dtsi)) 237 238u_boot_dtsi_options_raw = $(warning Automatic .dtsi inclusion: options: \ 239 $(u_boot_dtsi_loc)$(basename $(notdir $<))-u-boot.dtsi \ 240 $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_SOC))-u-boot.dtsi \ 241 $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_CPU))-u-boot.dtsi \ 242 $(u_boot_dtsi_loc)$(subst $\",,$(CONFIG_SYS_VENDOR))-u-boot.dtsi \ 243 $(u_boot_dtsi_loc)u-boot.dtsi ... \ 244 found: $(if $(u_boot_dtsi_options),"$(u_boot_dtsi_options)",nothing!)) 245 246# Uncomment for debugging 247# This shows all the files that were considered and the one that we chose. 248ifdef DEVICE_TREE_DEBUG 249u_boot_dtsi_options_debug = $(warning $(u_boot_dtsi_options_raw)) 250endif 251 252# We use the first match to be included 253dtsi_include_list = $(strip $(u_boot_dtsi_options_debug) \ 254 $(notdir $(firstword $(u_boot_dtsi_options)))) 255 256# Modified for U-Boot 257upstream_dtsi_include = $(addprefix -I, $(srctree)/dts/upstream/src/ \ 258 $(sort $(dir $(wildcard $(srctree)/dts/upstream/src/$(ARCH)/*/*))) \ 259 $(sort $(dir $(wildcard $(srctree)/dts/upstream/src/$(ARCH)/*/*/*))) \ 260 $(if (CONFIG_ARM64), \ 261 $(sort $(dir $(wildcard $(srctree)/dts/upstream/src/arm64/*/*))) \ 262 $(sort $(dir $(wildcard $(srctree)/dts/upstream/src/arm64/*/*/*))))) 263dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ 264 $(UBOOTINCLUDE) \ 265 -I$(dir $<) \ 266 -I$(u_boot_dtsi_loc) \ 267 -I$(srctree)/arch/$(ARCH)/dts/include \ 268 -I$(srctree)/include \ 269 $(upstream_dtsi_include) \ 270 -D__ASSEMBLY__ \ 271 -undef -D__DTS__ 272 273ifdef CONFIG_OBJTOOL 274 275objtool := $(objtree)/tools/objtool/objtool 276 277objtool_args = \ 278 $(if $(CONFIG_HAVE_JUMP_LABEL_HACK), --hacks=jump_label) \ 279 $(if $(CONFIG_HAVE_NOINSTR_HACK), --hacks=noinstr) \ 280 $(if $(CONFIG_X86_KERNEL_IBT), --ibt) \ 281 $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount) \ 282 $(if $(CONFIG_UNWINDER_ORC), --orc) \ 283 $(if $(CONFIG_RETPOLINE), --retpoline) \ 284 $(if $(CONFIG_RETHUNK), --rethunk) \ 285 $(if $(CONFIG_SLS), --sls) \ 286 $(if $(CONFIG_STACK_VALIDATION), --stackval) \ 287 $(if $(CONFIG_HAVE_STATIC_CALL_INLINE), --static-call) \ 288 $(if $(CONFIG_HAVE_UACCESS_VALIDATION), --uaccess) \ 289 $(if $(delay-objtool), --link) \ 290 $(if $(part-of-module), --module) \ 291 $(if $(CONFIG_GCOV_KERNEL), --no-unreachable) 292 293delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT)) 294 295cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool_args) $@) 296cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd) 297 298endif # CONFIG_OBJTOOL 299 300# Useful for describing the dependency of composite objects 301# Usage: 302# $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add) 303define multi_depend 304$(foreach m, $1, \ 305 $(eval $m: \ 306 $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3)))) 307endef 308 309# Copy a file 310# =========================================================================== 311# 'cp' preserves permissions. If you use it to copy a file in read-only srctree, 312# the copy would be read-only as well, leading to an error when executing the 313# rule next time. Use 'cat' instead in order to generate a writable file. 314quiet_cmd_copy = COPY $@ 315 cmd_copy = cat $< > $@ 316 317$(obj)/%: $(src)/%_shipped 318 $(call cmd,copy) 319 320# Commands useful for building a boot image 321# =========================================================================== 322# 323# Use as following: 324# 325# target: source(s) FORCE 326# $(if_changed,ld/objcopy/gzip) 327# 328# and add target to 'targets' so that we know we have to 329# read in the saved command line 330 331# Linking 332# --------------------------------------------------------------------------- 333 334quiet_cmd_ld = LD $@ 335 cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@ 336 337# Archive 338# --------------------------------------------------------------------------- 339 340quiet_cmd_ar = AR $@ 341 cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs) 342 343# Objcopy 344# --------------------------------------------------------------------------- 345 346quiet_cmd_objcopy = OBJCOPY $@ 347cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@ 348 349# Gzip 350# --------------------------------------------------------------------------- 351 352quiet_cmd_gzip = GZIP $@ 353 cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@ 354 355# DTC 356# --------------------------------------------------------------------------- 357DTC ?= $(objtree)/scripts/dtc/dtc 358DTC_FLAGS += -Wno-interrupt_provider 359 360# Disable noisy checks by default 361ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),) 362DTC_FLAGS += -Wno-unit_address_vs_reg \ 363 -Wno-unit_address_format \ 364 -Wno-avoid_unnecessary_addr_size \ 365 -Wno-alias_paths \ 366 -Wno-graph_child_address \ 367 -Wno-simple_bus_reg \ 368 -Wno-unique_unit_address \ 369 -Wno-pci_device_reg 370 371# U-Boot specific disables 372DTC_FLAGS += -Wno-pci_bridge \ 373 -Wno-pci_device_bus_num 374endif 375 376ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),) 377DTC_FLAGS += -Wnode_name_chars_strict \ 378 -Wproperty_name_chars_strict \ 379 -Winterrupt_provider 380endif 381 382DTC_FLAGS += $(DTC_FLAGS_$(basetarget)) 383 384# Set -@ if the target is a base DTB that overlay is applied onto 385DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@) 386 387# Generate an assembly file to wrap the output of the device tree compiler 388quiet_cmd_dt_S_dtb= DTBS $@ 389# Modified for U-Boot 390cmd_dt_S_dtb= \ 391{ \ 392 echo '.section .dtb.init.rodata,"a"'; \ 393 echo '.balign 16'; \ 394 echo '.global __dtb_$(subst -,_,$(*F))_begin'; \ 395 echo '__dtb_$(subst -,_,$(*F))_begin:'; \ 396 echo '.incbin "$<" '; \ 397 echo '__dtb_$(subst -,_,$(*F))_end:'; \ 398 echo '.global __dtb_$(subst -,_,$(*F))_end'; \ 399 echo '.balign 16'; \ 400} > $@ 401 402$(obj)/%.dtb.S: $(obj)/%.dtb FORCE 403 $(call if_changed,dt_S_dtb) 404 405# Generate an assembly file to wrap the output of the device tree compiler 406quiet_cmd_dt_S_dtbo= DTBOS $@ 407# Modified for U-Boot 408cmd_dt_S_dtbo= \ 409{ \ 410 echo '.section .dtb.init.rodata,"a"'; \ 411 echo '.balign 16'; \ 412 echo '.global __dtbo_$(subst -,_,$(*F))_begin'; \ 413 echo '__dtbo_$(subst -,_,$(*F))_begin:'; \ 414 echo '.incbin "$<" '; \ 415 echo '__dtbo_$(subst -,_,$(*F))_end:'; \ 416 echo '.global __dtbo_$(subst -,_,$(*F))_end'; \ 417 echo '.balign 16'; \ 418} > $@ 419 420$(obj)/%.dtbo.S: $(obj)/%.dtbo 421 $(call cmd,dt_S_dtbo) 422 423ifeq ($(CONFIG_OF_LIBFDT_OVERLAY),y) 424DTC_FLAGS += -@ 425endif 426 427# In case DEVICE_TREE_DEBUG is set, produce a diff between the base DT and 428# DT with U-Boot extras, to show how much does the U-Boot DT differ from 429# the base DT. This is particularly useful together with OF_UPSTREAM, to 430# minimize the diff between upstream DTs and U-Boot DTs. 431ifdef DEVICE_TREE_DEBUG 432cmd_dtc_diff = \ 433 $(HOSTCC) -E $(dtc_cpp_flags) -I$(obj) -x assembler-with-cpp -o $(dtn-tmp) $< ; \ 434 $(DTC) -s -O dts -o $@.clean.dts -b 0 \ 435 -i $(dir $<) $(DTC_FLAGS) $(dtn-tmp) || \ 436 (echo "Check $(shell pwd)/$< for errors" && false); \ 437 $(DTC) -s -O dts -o $@.full.dts -b 0 \ 438 -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) $(dtc-tmp) || \ 439 (echo "Check $(shell pwd)/$(pre-tmp) for errors" && false); \ 440 sed -i '/\<phandle\> = <0x[0-9a-f]\+>;/ d' $@.clean.dts; \ 441 sed -i '/\<phandle\> = <0x[0-9a-f]\+>;/ d' $@.full.dts; \ 442 (diff -Naru $@.clean.dts $@.full.dts > $@.diff || true) 443 444dtn-tmp = $(subst $(comma),_,$(dot-target).dtn.tmp) 445else 446cmd_dtc_diff = true 447endif 448 449quiet_cmd_dtc = DTC $@ 450# Modified for U-Boot 451# Bring in any U-Boot-specific include at the end of the file 452# And finally any custom .dtsi fragments specified with CONFIG_DEVICE_TREE_INCLUDES 453cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \ 454 (cat $< > $(pre-tmp)); \ 455 $(foreach f,$(subst $(quote),,$(dtsi_include_list) $(CONFIG_DEVICE_TREE_INCLUDES)), \ 456 echo '$(pound)include "$(f)"' >> $(pre-tmp);) \ 457 $(HOSTCC) -E $(dtc_cpp_flags) -I$(obj) -x assembler-with-cpp -o $(dtc-tmp) $(pre-tmp) ; \ 458 $(DTC) -O dtb -o $@ -b 0 \ 459 -i $(dir $<) -i $(u_boot_dtsi_loc) $(DTC_FLAGS) \ 460 -d $(depfile).dtc.tmp $(dtc-tmp) || \ 461 (echo "Check $(shell pwd)/$(pre-tmp) for errors" && false) \ 462 ; \ 463 sed "s:$(pre-tmp):$(<):" $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) ; \ 464 $(cmd_dtc_diff) 465 466dtsi_include_list_deps := $(addprefix $(u_boot_dtsi_loc),$(subst $(quote),,$(dtsi_include_list))) 467 468ifneq ($(CHECK_DTBS),) 469DT_CHECKER ?= dt-validate 470DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m) 471DT_BINDING_DIR := dts/upstream/Bindings 472DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json 473 474quiet_cmd_dtb = DTC_CHK $@ 475 cmd_dtb = $(cmd_dtc) ; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true 476else 477quiet_cmd_dtb = $(quiet_cmd_dtc) 478 cmd_dtb = $(cmd_dtc) 479endif 480 481$(obj)/%.dtb: $(src)/%.dts $(DTC) $(dtsi_include_list_deps) $(DT_TMP_SCHEMA) FORCE 482# $(call if_changed_dep,dtb) 483 484pre-tmp = $(subst $(comma),_,$(dot-target).pre.tmp) 485dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp) 486 487# DTCO 488# --------------------------------------------------------------------------- 489 490quiet_cmd_dtco = DTCO $@ 491# Rule for objects only; does not put specific u-boot include at the end 492# No generation of assembly file either 493# Modified for U-Boot 494cmd_dtco = mkdir -p $(dir ${dtc-tmp}) ; \ 495 $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \ 496 $(DTC) -@ -O dtb -o $@ -b 0 \ 497 -i $(dir $<) $(DTC_FLAGS) \ 498 -d $(depfile).dtc.tmp $(dtc-tmp) ; \ 499 cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile) 500 501$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE 502 $(call if_changed_dep,dtco) 503 504quiet_cmd_fdtoverlay = DTOVL $@ 505 cmd_fdtoverlay = fdtoverlay -o $@ -i $(real-prereqs) 506 507$(multi-dtb-y): FORCE 508 $(call if_changed,fdtoverlay) 509$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs) 510 511# Fonts 512# --------------------------------------------------------------------------- 513 514# Generate an assembly file to wrap the font data 515quiet_cmd_S_ttf= TTF $@ 516# Modified for U-Boot 517cmd_S_ttf= \ 518( \ 519 echo '.section .rodata.ttf.init,"a"'; \ 520 echo '.balign 16'; \ 521 echo '.global __ttf_$(*F)_begin'; \ 522 echo '__ttf_$(*F)_begin:'; \ 523 echo '.incbin "$<" '; \ 524 echo '__ttf_$(*F)_end:'; \ 525 echo '.global __ttf_$(*F)_end'; \ 526 echo '.balign 16'; \ 527) > $@ 528 529$(obj)/%.S: $(src)/%.ttf 530 $(call cmd,S_ttf) 531 532# Splash logos 533# --------------------------------------------------------------------------- 534 535# Generate an assembly file to wrap the splash data 536quiet_cmd_S_splash= TTF $@ 537# Modified for U-Boot 538cmd_S_splash= \ 539( \ 540 echo '.section .rodata.splash.init,"a"'; \ 541 echo '.balign 16'; \ 542 echo '.global __splash_$(*F)_begin'; \ 543 echo '__splash_$(*F)_begin:'; \ 544 echo '.incbin "$<" '; \ 545 echo '__splash_$(*F)_end:'; \ 546 echo '.global __splash_$(*F)_end'; \ 547 echo '.balign 16'; \ 548) > $@ 549 550$(obj)/%.S: $(src)/%.bmp 551 $(call cmd,S_splash) 552 553# EFI applications 554# A Makefile target *.efi is built as EFI application. 555# A Makefile target *_efi.S wraps *.efi as built-in EFI application. 556# --------------------------------------------------------------------------- 557 558# Generate an assembly file to wrap the EFI app 559cmd_S_efi= \ 560( \ 561 echo '.section .rodata.$*.init,"a"'; \ 562 echo '.balign 16'; \ 563 echo '.global __efi_$*_begin'; \ 564 echo '__efi_$*_begin:'; \ 565 echo '.incbin "$<" '; \ 566 echo '__efi_$*_end:'; \ 567 echo '.global __efi_$*_end'; \ 568 echo '.balign 16'; \ 569) > $@ 570 571$(obj)/%_efi.S: $(obj)/%.efi 572 $(call cmd,S_efi) 573 574quiet_cmd_efi_objcopy = OBJCOPY $@ 575cmd_efi_objcopy = $(OBJCOPY) -j .header -j .text -j .sdata -j .data \ 576 -j .dynamic -j .dynstr -j .dynsym -j .rel* -j .reloc \ 577 $(if $(EFI_TARGET),$(EFI_TARGET),-O binary) $^ $@ 578 579$(obj)/%.efi: $(obj)/%_efi.so 580 $(call cmd,efi_objcopy) 581 582KBUILD_EFILDFLAGS = -nostdlib -zexecstack -znocombreloc -znorelro 583KBUILD_EFILDFLAGS += $(call ld-option,--no-warn-rwx-segments) 584quiet_cmd_efi_ld = LD $@ 585cmd_efi_ld = $(LD) $(KBUILD_EFILDFLAGS) -L $(srctree) -T $(EFI_LDS_PATH) \ 586 -shared -Bsymbolic -s $^ $(PLATFORM_LIBGCC) -o $@ 587 588EFI_LDS_PATH = arch/$(ARCH)/lib/$(EFI_LDS) 589 590$(obj)/efi_crt0.o: $(srctree)/arch/$(ARCH)/lib/$(EFI_CRT0:.o=.S) FORCE 591 $(call if_changed_dep,as_o_S) 592 593$(obj)/efi_reloc.o: $(srctree)/arch/$(ARCH)/lib/$(EFI_RELOC:.o=.c) $(recordmcount_source) FORCE 594 $(call cmd,force_checksrc) 595 $(call if_changed_rule,cc_o_c) 596 597$(obj)/%_efi.so: $(obj)/%.o $(obj)/efi_crt0.o $(obj)/efi_reloc.o $(obj)/efi_freestanding.o 598 $(call cmd,efi_ld) 599 600targets += $(obj)/efi_crt0.o $(obj)/efi_reloc.o $(obj)/efi_freestanding.o 601 602CFLAGS_REMOVE_efi_reloc.o := $(LTO_CFLAGS) 603CFLAGS_REMOVE_efi_freestanding.o := $(LTO_CFLAGS) 604 605# ACPI 606# --------------------------------------------------------------------------- 607# 608# This first sends the file (typically dsdt.asl) through the preprocessor 609# resolve includes and any CONFIG options used. This produces dsdt.asl.tmp 610# which is pure ASL code. The Intel ASL (ACPI (Advanced Configuration and Power 611# Interface) Source Language compiler (iasl) then converts this ASL code into a 612# C file containing the hex data to build into U-Boot. This file is called 613# dsdt_generated.hex (despite us setting the prefix to .../dsdt_generated.asl.tmp) 614# so must be renamed to dsdt_generated.c for consumption by the build system. 615ASL_TMP = $(patsubst %.c,%.asl.tmp,$@) 616 617quiet_cmd_acpi_c_asl= ASL $< 618cmd_acpi_c_asl= \ 619 $(CPP) -x assembler-with-cpp -D__ASSEMBLY__ -D__ACPI__ \ 620 -P $(UBOOTINCLUDE) -o $(ASL_TMP) $< && \ 621 iasl -p $@ -I $(srctree)/board/$(BOARDDIR) -tc $(ASL_TMP) \ 622 $(if $(KBUILD_VERBOSE:1=), >/dev/null) && \ 623 mv $(patsubst %.c,%.hex,$@) $@ 624 625$(obj)/dsdt_generated.c: $(src)/dsdt.asl 626 $(call cmd,acpi_c_asl) 627 $(Q)sed -i -e "s,dsdt_generated_aml_code,AmlCode," $@ 628 629# Bzip2 630# --------------------------------------------------------------------------- 631 632# Bzip2 and LZMA do not include size in file... so we have to fake that; 633# append the size as a 32-bit littleendian number as gzip does. 634size_append = printf $(shell \ 635dec_size=0; \ 636for F in $(real-prereqs); do \ 637 fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \ 638 dec_size=$$(expr $$dec_size + $$fsize); \ 639done; \ 640printf "%08x\n" $$dec_size | \ 641 sed 's/\(..\)/\1 /g' | { \ 642 read ch0 ch1 ch2 ch3; \ 643 for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \ 644 printf '%s%03o' '\\' $$((0x$$ch)); \ 645 done; \ 646 } \ 647) 648 649quiet_cmd_file_size = GEN $@ 650 cmd_file_size = $(size_append) > $@ 651 652quiet_cmd_bzip2 = BZIP2 $@ 653 cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@ 654 655quiet_cmd_bzip2_with_size = BZIP2 $@ 656 cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@ 657 658# Lzma 659# --------------------------------------------------------------------------- 660 661quiet_cmd_lzma = LZMA $@ 662 cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@ 663 664quiet_cmd_lzma_with_size = LZMA $@ 665 cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@ 666 667quiet_cmd_lzo = LZO $@ 668 cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@ 669 670quiet_cmd_lzo_with_size = LZO $@ 671 cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@ 672 673quiet_cmd_lz4 = LZ4 $@ 674 cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout > $@ 675 676quiet_cmd_lz4_with_size = LZ4 $@ 677 cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \ 678 $(size_append); } > $@ 679 680# U-Boot mkimage 681# --------------------------------------------------------------------------- 682 683MKIMAGE := $(srctree)/scripts/mkuboot.sh 684 685# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces 686# the number of overrides in arch makefiles 687UIMAGE_ARCH ?= $(SRCARCH) 688UIMAGE_COMPRESSION ?= $(or $(2),none) 689UIMAGE_OPTS-y ?= 690UIMAGE_TYPE ?= kernel 691UIMAGE_LOADADDR ?= arch_must_set_this 692UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR) 693UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)' 694 695quiet_cmd_uimage = UIMAGE $@ 696 cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \ 697 -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \ 698 -T $(UIMAGE_TYPE) \ 699 -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \ 700 -n $(UIMAGE_NAME) -d $< $@ 701 702# XZ 703# --------------------------------------------------------------------------- 704# Use xzkern to compress the kernel image and xzmisc to compress other things. 705# 706# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage 707# of the kernel decompressor. A BCJ filter is used if it is available for 708# the target architecture. xzkern also appends uncompressed size of the data 709# using size_append. The .xz format has the size information available at 710# the end of the file too, but it's in more complex format and it's good to 711# avoid changing the part of the boot code that reads the uncompressed size. 712# Note that the bytes added by size_append will make the xz tool think that 713# the file is corrupt. This is expected. 714# 715# xzmisc doesn't use size_append, so it can be used to create normal .xz 716# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very 717# big dictionary would increase the memory usage too much in the multi-call 718# decompression mode. A BCJ filter isn't used either. 719quiet_cmd_xzkern = XZKERN $@ 720 cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@ 721 722quiet_cmd_xzkern_with_size = XZKERN $@ 723 cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \ 724 $(size_append); } > $@ 725 726quiet_cmd_xzmisc = XZMISC $@ 727 cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@ 728 729# ZSTD 730# --------------------------------------------------------------------------- 731# Appends the uncompressed size of the data using size_append. The .zst 732# format has the size information available at the beginning of the file too, 733# but it's in a more complex format and it's good to avoid changing the part 734# of the boot code that reads the uncompressed size. 735# 736# Note that the bytes added by size_append will make the zstd tool think that 737# the file is corrupt. This is expected. 738# 739# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of 740# 128 MB. zstd22 is used for kernel compression because it is decompressed in a 741# single pass, so zstd doesn't need to allocate a window buffer. When streaming 742# decompression is used, like initramfs decompression, zstd22 should likely not 743# be used because it would require zstd to allocate a 128 MB buffer. 744 745quiet_cmd_zstd = ZSTD $@ 746 cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@ 747 748quiet_cmd_zstd22 = ZSTD22 $@ 749 cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@ 750 751quiet_cmd_zstd22_with_size = ZSTD22 $@ 752 cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@ 753 754# Additional commands for U-Boot 755# 756# bin2c 757# --------------------------------------------------------------------------- 758quiet_cmd_bin2c = BIN2C $@ 759 cmd_bin2c = $(objtree)/scripts/bin2c $2 < $< > $@ 760 761# mkimage 762# --------------------------------------------------------------------------- 763MKIMAGEOUTPUT ?= /dev/null 764quiet_cmd_mkimage = MKIMAGE $@ 765cmd_mkimage = $(objtree)/tools/mkimage $(MKIMAGEFLAGS_$(@F)) -d $< $@ \ 766 >$(MKIMAGEOUTPUT) $(if $(KBUILD_VERBOSE:0=), && cat $(MKIMAGEOUTPUT)) 767 768# fdtgrep 769# --------------------------------------------------------------------------- 770# Pass the original device tree file through fdtgrep twice. The first pass 771# removes any unwanted nodes (i.e. those which don't have the 772# 'bootph-all' property and thus are not needed by SPL. The second 773# pass removes various unused properties from the remaining nodes. 774# The output is typically a much smaller device tree file. 775 776ifeq ($(CONFIG_VPL_BUILD),y) 777fdtgrep_props := -b bootph-all -b bootph-verify $(migrate_vpl) 778else 779ifeq ($(CONFIG_TPL_BUILD),y) 780fdtgrep_props := -b bootph-all -b bootph-pre-sram $(migrate_tpl) 781else 782fdtgrep_props := -b bootph-all -b bootph-pre-ram $(migrate_spl) 783endif 784endif 785 786# This rule produces the .dtb for an SPL build. 787# 788# The first fdtgrep keeps nodes with the above properties (with -u ensuring that 789# the properties are implied in all parents of a matching node). The root node 790# is always included, along with /chosen and /config nodes. Referenced aliases 791# (i.e. properties in /aliases which point to an incldued node) are also 792# included. 793# 794# The second fdtgrep removes all bootph properties along with unused strings 795# and any properties in CONFIG_OF_SPL_REMOVE_PROPS 796quiet_cmd_fdtgrep = FDTGREP $@ 797 cmd_fdtgrep = $(objtree)/tools/fdtgrep $(fdtgrep_props) -u -RT $< \ 798 -n /chosen -n /config -O dtb | \ 799 $(objtree)/tools/fdtgrep -r -O dtb - -o $@ \ 800 -P bootph-all -P bootph-pre-ram -P bootph-pre-sram \ 801 -P bootph-verify -P bootph-some-ram \ 802 $(migrate_all) \ 803 $(addprefix -P ,$(subst $\",,$(CONFIG_OF_SPL_REMOVE_PROPS))) 804 805# fdt_rm_props 806# --------------------------------------------------------------------------- 807# Pass the original device tree file through fdtgrep. This removes various 808# unused properties. The output is typically a smaller device tree file. 809quiet_cmd_fdt_rm_props = FDTGREP $@ 810 cmd_fdt_rm_props = cat $< | $(objtree)/tools/fdtgrep -r -O dtb - -o $@ \ 811 $(addprefix -P ,$(subst $\",,$(CONFIG_OF_REMOVE_PROPS))) 812 813# ASM offsets 814# --------------------------------------------------------------------------- 815 816# Default sed regexp - multiline due to syntax constraints 817# 818# Use [:space:] because LLVM's integrated assembler inserts <tab> around 819# the .ascii directive whereas GCC keeps the <space> as-is. 820define sed-offsets 821 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \ 822 /^->/{s:->#\(.*\):/* \1 */:; \ 823 s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \ 824 s:->::; p;}' 825endef 826 827# Use filechk to avoid rebuilds when a header changes, but the resulting file 828# does not 829define filechk_offsets 830 echo "#ifndef $2"; \ 831 echo "#define $2"; \ 832 echo "/*"; \ 833 echo " * DO NOT MODIFY."; \ 834 echo " *"; \ 835 echo " * This file was generated by Kbuild"; \ 836 echo " */"; \ 837 echo ""; \ 838 sed -ne $(sed-offsets) < $<; \ 839 echo ""; \ 840 echo "#endif" 841endef