17b453719SMasahiro Yamada# SPDX-License-Identifier: GPL-2.0-only 27b453719SMasahiro Yamada 35d4aeffbSMasahiro YamadaPHONY := __default 45d4aeffbSMasahiro Yamada__default: vmlinux 55d4aeffbSMasahiro Yamada 67b453719SMasahiro Yamadainclude include/config/auto.conf 77b453719SMasahiro Yamadainclude $(srctree)/scripts/Kbuild.include 87b453719SMasahiro Yamadainclude $(srctree)/scripts/Makefile.lib 97b453719SMasahiro Yamada 105d4aeffbSMasahiro Yamadatargets := 115d4aeffbSMasahiro Yamada 127b453719SMasahiro Yamada%.o: %.c FORCE 13bede1696SMasahiro Yamada $(call if_changed_rule,cc_o_c) 147b453719SMasahiro Yamada 15654102dfSMasahiro Yamada%.o: %.S FORCE 16bede1696SMasahiro Yamada $(call if_changed_rule,as_o_S) 17654102dfSMasahiro Yamada 18654102dfSMasahiro Yamada# Built-in dtb 19654102dfSMasahiro Yamada# --------------------------------------------------------------------------- 20654102dfSMasahiro Yamada 21654102dfSMasahiro Yamadaquiet_cmd_wrap_dtbs = WRAP $@ 22654102dfSMasahiro Yamada cmd_wrap_dtbs = { \ 23654102dfSMasahiro Yamada echo '\#include <asm-generic/vmlinux.lds.h>'; \ 24654102dfSMasahiro Yamada echo '.section .dtb.init.rodata,"a"'; \ 25654102dfSMasahiro Yamada while read dtb; do \ 26654102dfSMasahiro Yamada symbase=__dtb_$$(basename -s .dtb "$${dtb}" | tr - _); \ 27654102dfSMasahiro Yamada echo '.balign STRUCT_ALIGNMENT'; \ 28654102dfSMasahiro Yamada echo ".global $${symbase}_begin"; \ 29654102dfSMasahiro Yamada echo "$${symbase}_begin:"; \ 30654102dfSMasahiro Yamada echo '.incbin "'$$dtb'" '; \ 31654102dfSMasahiro Yamada echo ".global $${symbase}_end"; \ 32654102dfSMasahiro Yamada echo "$${symbase}_end:"; \ 33654102dfSMasahiro Yamada done < $<; \ 34654102dfSMasahiro Yamada } > $@ 35654102dfSMasahiro Yamada 36654102dfSMasahiro Yamada.builtin-dtbs.S: .builtin-dtbs-list FORCE 37654102dfSMasahiro Yamada $(call if_changed,wrap_dtbs) 38654102dfSMasahiro Yamada 39654102dfSMasahiro Yamadaquiet_cmd_gen_dtbs_list = GEN $@ 40654102dfSMasahiro Yamada cmd_gen_dtbs_list = \ 41654102dfSMasahiro Yamada $(if $(CONFIG_BUILTIN_DTB_NAME), echo "arch/$(SRCARCH)/boot/dts/$(CONFIG_BUILTIN_DTB_NAME).dtb",:) > $@ 42654102dfSMasahiro Yamada 43654102dfSMasahiro Yamada.builtin-dtbs-list: arch/$(SRCARCH)/boot/dts/dtbs-list FORCE 44654102dfSMasahiro Yamada $(call if_changed,$(if $(CONFIG_BUILTIN_DTB_ALL),copy,gen_dtbs_list)) 45654102dfSMasahiro Yamada 46654102dfSMasahiro Yamadatargets += .builtin-dtbs-list 47654102dfSMasahiro Yamada 48654102dfSMasahiro Yamadaifdef CONFIG_GENERIC_BUILTIN_DTB 49654102dfSMasahiro Yamadatargets += .builtin-dtbs.S .builtin-dtbs.o 500ce5139fSMasahiro Yamadavmlinux.unstripped: .builtin-dtbs.o 51654102dfSMasahiro Yamadaendif 52654102dfSMasahiro Yamada 530ce5139fSMasahiro Yamada# vmlinux.unstripped 54654102dfSMasahiro Yamada# --------------------------------------------------------------------------- 557b453719SMasahiro Yamada 565d4aeffbSMasahiro Yamadaifdef CONFIG_MODULES 575d4aeffbSMasahiro Yamadatargets += .vmlinux.export.o 580ce5139fSMasahiro Yamadavmlinux.unstripped: .vmlinux.export.o 595d4aeffbSMasahiro Yamadaendif 605d4aeffbSMasahiro Yamada 611198c9c6SNaveen N Raoifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX 620ce5139fSMasahiro Yamadavmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o 631198c9c6SNaveen N Rao 641198c9c6SNaveen N Raoarch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE 651198c9c6SNaveen N Rao $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ 661198c9c6SNaveen N Raoendif 671198c9c6SNaveen N Rao 685d4aeffbSMasahiro YamadaARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) 695d4aeffbSMasahiro Yamada 705d4aeffbSMasahiro Yamada# Final link of vmlinux with optional arch pass after final link 715d4aeffbSMasahiro Yamadacmd_link_vmlinux = \ 72e22bbb8eSArd Biesheuvel $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ 735d4aeffbSMasahiro Yamada $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 745d4aeffbSMasahiro Yamada 750ce5139fSMasahiro Yamadatargets += vmlinux.unstripped 760ce5139fSMasahiro Yamadavmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o $(KBUILD_LDS) FORCE 775d4aeffbSMasahiro Yamada +$(call if_changed_dep,link_vmlinux) 7818e9944eSThomas Weißschuhifdef CONFIG_DEBUG_INFO_BTF 790ce5139fSMasahiro Yamadavmlinux.unstripped: $(RESOLVE_BTFIDS) 8018e9944eSThomas Weißschuhendif 817b453719SMasahiro Yamada 8282c09de2SXi Ruoyaoifdef CONFIG_BUILDTIME_TABLE_SORT 830ce5139fSMasahiro Yamadavmlinux.unstripped: scripts/sorttable 8482c09de2SXi Ruoyaoendif 8582c09de2SXi Ruoyao 860ce5139fSMasahiro Yamada# vmlinux 870ce5139fSMasahiro Yamada# --------------------------------------------------------------------------- 880ce5139fSMasahiro Yamada 893e86e4d7SMasahiro Yamadaremove-section-y := .modinfo 900ce5139fSMasahiro Yamadaremove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' 910ce5139fSMasahiro Yamada 923e86e4d7SMasahiro Yamada# To avoid warnings: "empty loadable segment detected at ..." from GNU objcopy, 933e86e4d7SMasahiro Yamada# it is necessary to remove the PT_LOAD flag from the segment. 940ce5139fSMasahiro Yamadaquiet_cmd_strip_relocs = OBJCOPY $@ 953e86e4d7SMasahiro Yamada cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \ 963e86e4d7SMasahiro Yamada $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $@ 970ce5139fSMasahiro Yamada 980ce5139fSMasahiro Yamadatargets += vmlinux 990ce5139fSMasahiro Yamadavmlinux: vmlinux.unstripped FORCE 1000ce5139fSMasahiro Yamada $(call if_changed,strip_relocs) 1010ce5139fSMasahiro Yamada 102*39cfd5b1SMasahiro Yamada# modules.builtin.modinfo 103*39cfd5b1SMasahiro Yamada# --------------------------------------------------------------------------- 104*39cfd5b1SMasahiro Yamada 105*39cfd5b1SMasahiro YamadaOBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary 106*39cfd5b1SMasahiro Yamada 107*39cfd5b1SMasahiro Yamadatargets += modules.builtin.modinfo 108*39cfd5b1SMasahiro Yamadamodules.builtin.modinfo: vmlinux.unstripped FORCE 109*39cfd5b1SMasahiro Yamada $(call if_changed,objcopy) 110*39cfd5b1SMasahiro Yamada 111*39cfd5b1SMasahiro Yamada# modules.builtin 112*39cfd5b1SMasahiro Yamada# --------------------------------------------------------------------------- 113*39cfd5b1SMasahiro Yamada 114*39cfd5b1SMasahiro Yamada__default: modules.builtin 115*39cfd5b1SMasahiro Yamada 116*39cfd5b1SMasahiro Yamada# The second line aids cases where multiple modules share the same object. 117*39cfd5b1SMasahiro Yamada 118*39cfd5b1SMasahiro Yamadaquiet_cmd_modules_builtin = GEN $@ 119*39cfd5b1SMasahiro Yamada cmd_modules_builtin = \ 120*39cfd5b1SMasahiro Yamada tr '\0' '\n' < $< | \ 121*39cfd5b1SMasahiro Yamada sed -n 's/^[[:alnum:]:_]*\.file=//p' | \ 122*39cfd5b1SMasahiro Yamada tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ 123*39cfd5b1SMasahiro Yamada 124*39cfd5b1SMasahiro Yamadatargets += modules.builtin 125*39cfd5b1SMasahiro Yamadamodules.builtin: modules.builtin.modinfo FORCE 126*39cfd5b1SMasahiro Yamada $(call if_changed,modules_builtin) 127*39cfd5b1SMasahiro Yamada 128e0cd396dSMasahiro Yamada# modules.builtin.ranges 1295f5e7344SKris Van Hees# --------------------------------------------------------------------------- 1305f5e7344SKris Van Heesifdef CONFIG_BUILTIN_MODULE_RANGES 1315f5e7344SKris Van Hees__default: modules.builtin.ranges 1325f5e7344SKris Van Hees 1335f5e7344SKris Van Heesquiet_cmd_modules_builtin_ranges = GEN $@ 1345f5e7344SKris Van Hees cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ 1355f5e7344SKris Van Hees 1365f5e7344SKris Van Heestargets += modules.builtin.ranges 1375f5e7344SKris Van Heesmodules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ 1385f5e7344SKris Van Hees modules.builtin vmlinux.map vmlinux.o.map FORCE 1395f5e7344SKris Van Hees $(call if_changed,modules_builtin_ranges) 1405f5e7344SKris Van Hees 1410ce5139fSMasahiro Yamadavmlinux.map: vmlinux.unstripped 1425f5e7344SKris Van Hees @: 1435f5e7344SKris Van Hees 1445f5e7344SKris Van Heesendif 1455f5e7344SKris Van Hees 1468fb4ac1cSMasahiro Yamada# Add FORCE to the prerequisites of a target to force it to be always rebuilt. 1477b453719SMasahiro Yamada# --------------------------------------------------------------------------- 1487b453719SMasahiro Yamada 1497b453719SMasahiro YamadaPHONY += FORCE 1507b453719SMasahiro YamadaFORCE: 1517b453719SMasahiro Yamada 1527b453719SMasahiro Yamada# Read all saved command lines and dependencies for the $(targets) we 1537b453719SMasahiro Yamada# may be building above, using $(if_changed{,_dep}). As an 1547b453719SMasahiro Yamada# optimization, we don't need to read them if the target does not 1557b453719SMasahiro Yamada# exist, we will rebuild anyway in that case. 1567b453719SMasahiro Yamada 1577b453719SMasahiro Yamadaexisting-targets := $(wildcard $(sort $(targets))) 1587b453719SMasahiro Yamada 1597b453719SMasahiro Yamada-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 1607b453719SMasahiro Yamada 1617b453719SMasahiro Yamada.PHONY: $(PHONY) 162