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 561198c9c6SNaveen N Raoifdef CONFIG_ARCH_WANTS_PRE_LINK_VMLINUX 570ce5139fSMasahiro Yamadavmlinux.unstripped: arch/$(SRCARCH)/tools/vmlinux.arch.o 581198c9c6SNaveen N Rao 591198c9c6SNaveen N Raoarch/$(SRCARCH)/tools/vmlinux.arch.o: vmlinux.o FORCE 601198c9c6SNaveen N Rao $(Q)$(MAKE) $(build)=arch/$(SRCARCH)/tools $@ 611198c9c6SNaveen N Raoendif 621198c9c6SNaveen N Rao 635d4aeffbSMasahiro YamadaARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink) 645d4aeffbSMasahiro Yamada 655d4aeffbSMasahiro Yamada# Final link of vmlinux with optional arch pass after final link 665d4aeffbSMasahiro Yamadacmd_link_vmlinux = \ 67e22bbb8eSArd Biesheuvel $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)" "$@"; \ 685d4aeffbSMasahiro Yamada $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true) 695d4aeffbSMasahiro Yamada 703328d39aSAlexey Gladkovtargets += vmlinux.unstripped .vmlinux.export.o 713328d39aSAlexey Gladkovvmlinux.unstripped: scripts/link-vmlinux.sh vmlinux.o .vmlinux.export.o $(KBUILD_LDS) FORCE 725d4aeffbSMasahiro Yamada +$(call if_changed_dep,link_vmlinux) 7318e9944eSThomas Weißschuhifdef CONFIG_DEBUG_INFO_BTF 740ce5139fSMasahiro Yamadavmlinux.unstripped: $(RESOLVE_BTFIDS) 7518e9944eSThomas Weißschuhendif 767b453719SMasahiro Yamada 7782c09de2SXi Ruoyaoifdef CONFIG_BUILDTIME_TABLE_SORT 780ce5139fSMasahiro Yamadavmlinux.unstripped: scripts/sorttable 7982c09de2SXi Ruoyaoendif 8082c09de2SXi Ruoyao 810ce5139fSMasahiro Yamada# vmlinux 820ce5139fSMasahiro Yamada# --------------------------------------------------------------------------- 830ce5139fSMasahiro Yamada 843e86e4d7SMasahiro Yamadaremove-section-y := .modinfo 854b47a3aeSNathan Chancellorremove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*' '!.rel*.dyn' 868ec3af91SNathan Chancellor# for compatibility with binutils < 2.32 878ec3af91SNathan Chancellor# https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=c12d9fa2afe7abcbe407a00e15719e1a1350c2a7 888ec3af91SNathan Chancellorremove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel.*' 890ce5139fSMasahiro Yamada 90b0f2942aSNathan Chancellorremove-symbols := -w --strip-unneeded-symbol='__mod_device_table__*' 915ab23c79SAlexey Gladkov 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)) $< $@; \ 965ab23c79SAlexey Gladkov $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $(remove-symbols) $@ 970ce5139fSMasahiro Yamada 980ce5139fSMasahiro Yamadatargets += vmlinux 990ce5139fSMasahiro Yamadavmlinux: vmlinux.unstripped FORCE 1000ce5139fSMasahiro Yamada $(call if_changed,strip_relocs) 1010ce5139fSMasahiro Yamada 10239cfd5b1SMasahiro Yamada# modules.builtin.modinfo 10339cfd5b1SMasahiro Yamada# --------------------------------------------------------------------------- 10439cfd5b1SMasahiro Yamada 105*a26a6c93SNathan Chancellor# .modinfo in vmlinux.unstripped is aligned to 8 bytes for compatibility with 106*a26a6c93SNathan Chancellor# tools that expect vmlinux to have sufficiently aligned sections but the 107*a26a6c93SNathan Chancellor# additional bytes used for padding .modinfo to satisfy this requirement break 108*a26a6c93SNathan Chancellor# certain versions of kmod with 109*a26a6c93SNathan Chancellor# 110*a26a6c93SNathan Chancellor# depmod: ERROR: kmod_builtin_iter_next: unexpected string without modname prefix 111*a26a6c93SNathan Chancellor# 112*a26a6c93SNathan Chancellor# Strip the trailing padding bytes after extracting .modinfo to comply with 113*a26a6c93SNathan Chancellor# what kmod expects to parse. 114*a26a6c93SNathan Chancellorquiet_cmd_modules_builtin_modinfo = GEN $@ 115*a26a6c93SNathan Chancellor cmd_modules_builtin_modinfo = $(cmd_objcopy); \ 116*a26a6c93SNathan Chancellor sed -i 's/\x00\+$$/\x00/g' $@ 117*a26a6c93SNathan Chancellor 11839cfd5b1SMasahiro YamadaOBJCOPYFLAGS_modules.builtin.modinfo := -j .modinfo -O binary 11939cfd5b1SMasahiro Yamada 12039cfd5b1SMasahiro Yamadatargets += modules.builtin.modinfo 12139cfd5b1SMasahiro Yamadamodules.builtin.modinfo: vmlinux.unstripped FORCE 122*a26a6c93SNathan Chancellor $(call if_changed,modules_builtin_modinfo) 12339cfd5b1SMasahiro Yamada 12439cfd5b1SMasahiro Yamada# modules.builtin 12539cfd5b1SMasahiro Yamada# --------------------------------------------------------------------------- 12639cfd5b1SMasahiro Yamada 12739cfd5b1SMasahiro Yamada__default: modules.builtin 12839cfd5b1SMasahiro Yamada 12939cfd5b1SMasahiro Yamada# The second line aids cases where multiple modules share the same object. 13039cfd5b1SMasahiro Yamada 13139cfd5b1SMasahiro Yamadaquiet_cmd_modules_builtin = GEN $@ 13239cfd5b1SMasahiro Yamada cmd_modules_builtin = \ 13339cfd5b1SMasahiro Yamada tr '\0' '\n' < $< | \ 13439cfd5b1SMasahiro Yamada sed -n 's/^[[:alnum:]:_]*\.file=//p' | \ 13539cfd5b1SMasahiro Yamada tr ' ' '\n' | uniq | sed -e 's:^:kernel/:' -e 's/$$/.ko/' > $@ 13639cfd5b1SMasahiro Yamada 13739cfd5b1SMasahiro Yamadatargets += modules.builtin 13839cfd5b1SMasahiro Yamadamodules.builtin: modules.builtin.modinfo FORCE 13939cfd5b1SMasahiro Yamada $(call if_changed,modules_builtin) 14039cfd5b1SMasahiro Yamada 141e0cd396dSMasahiro Yamada# modules.builtin.ranges 1425f5e7344SKris Van Hees# --------------------------------------------------------------------------- 1435f5e7344SKris Van Heesifdef CONFIG_BUILTIN_MODULE_RANGES 1445f5e7344SKris Van Hees__default: modules.builtin.ranges 1455f5e7344SKris Van Hees 1465f5e7344SKris Van Heesquiet_cmd_modules_builtin_ranges = GEN $@ 1475f5e7344SKris Van Hees cmd_modules_builtin_ranges = gawk -f $(real-prereqs) > $@ 1485f5e7344SKris Van Hees 1495f5e7344SKris Van Heestargets += modules.builtin.ranges 1505f5e7344SKris Van Heesmodules.builtin.ranges: $(srctree)/scripts/generate_builtin_ranges.awk \ 1515f5e7344SKris Van Hees modules.builtin vmlinux.map vmlinux.o.map FORCE 1525f5e7344SKris Van Hees $(call if_changed,modules_builtin_ranges) 1535f5e7344SKris Van Hees 1540ce5139fSMasahiro Yamadavmlinux.map: vmlinux.unstripped 1555f5e7344SKris Van Hees @: 1565f5e7344SKris Van Hees 1575f5e7344SKris Van Heesendif 1585f5e7344SKris Van Hees 1598fb4ac1cSMasahiro Yamada# Add FORCE to the prerequisites of a target to force it to be always rebuilt. 1607b453719SMasahiro Yamada# --------------------------------------------------------------------------- 1617b453719SMasahiro Yamada 1627b453719SMasahiro YamadaPHONY += FORCE 1637b453719SMasahiro YamadaFORCE: 1647b453719SMasahiro Yamada 1657b453719SMasahiro Yamada# Read all saved command lines and dependencies for the $(targets) we 1667b453719SMasahiro Yamada# may be building above, using $(if_changed{,_dep}). As an 1677b453719SMasahiro Yamada# optimization, we don't need to read them if the target does not 1687b453719SMasahiro Yamada# exist, we will rebuild anyway in that case. 1697b453719SMasahiro Yamada 1707b453719SMasahiro Yamadaexisting-targets := $(wildcard $(sort $(targets))) 1717b453719SMasahiro Yamada 1727b453719SMasahiro Yamada-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 1737b453719SMasahiro Yamada 1747b453719SMasahiro Yamada.PHONY: $(PHONY) 175