summaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile259
1 files changed, 175 insertions, 84 deletions
diff --git a/Makefile b/Makefile
index d483302fe1..67bfec4475 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-2.0
-VERSION = 2020
-PATCHLEVEL = 06
+VERSION = 2024
+PATCHLEVEL = 03
SUBLEVEL = 0
EXTRAVERSION =
NAME = None
@@ -90,9 +90,16 @@ endif
# If the user is running make -s (silent mode), suppress echoing of
# commands
+# make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS.
-ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
- quiet=silent_
+ifeq ($(filter 3.%,$(MAKE_VERSION)),)
+silence:=$(findstring s,$(firstword -$(MAKEFLAGS)))
+else
+silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS)))
+endif
+
+ifeq ($(silence),s)
+quiet=silent_
endif
export quiet Q KBUILD_VERBOSE
@@ -247,7 +254,7 @@ version_h := include/generated/version.h
clean-targets := %clean mrproper cleandocs
no-dot-config-targets := $(clean-targets) \
cscope gtags TAGS tags help% %docs \
- $(version_h) kernelversion outputmakefile
+ $(version_h) bareboxversion outputmakefile
no-sync-config-targets := $(no-dot-config-targets) install %install \
kernelrelease
@@ -311,7 +318,8 @@ include scripts/Kbuild.include
# Read KERNELRELEASE from include/config/kernel.release (if it exists)
KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
-export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
+BUILDSYSTEM_VERSION =
+export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION BUILDSYSTEM_VERSION
# Cross compiling and selecting different set of gcc/bin-utils
# ---------------------------------------------------------------------------
@@ -342,15 +350,29 @@ ifeq ($(ARCH),arm64)
SRCARCH := arm
endif
+ifeq ($(ARCH),i386)
+ SRCARCH := x86
+endif
+
+ifeq ($(ARCH),x86_64)
+ SRCARCH := x86
+endif
+
# Support ARCH=ppc for backward compatibility
ifeq ($(ARCH),ppc)
SRCARCH := powerpc
endif
+ifeq ($(ARCH),um)
+ SRCARCH := sandbox
+endif
+
KCONFIG_CONFIG ?= .config
-# Default file for 'make defconfig'. This may be overridden by arch-Makefile.
-export KBUILD_DEFCONFIG := defconfig
+PKG_CONFIG ?= pkg-config
+CROSS_PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
+
+export KCONFIG_CONFIG CROSS_PKG_CONFIG PKG_CONFIG
# SHELL used by kbuild
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
@@ -363,16 +385,19 @@ HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
HOSTCC = gcc
HOSTCXX = g++
-KBUILD_HOSTCFLAGS := -Wall -Wstrict-prototypes -O2 \
- -fomit-frame-pointer $(HOST_LFS_CFLAGS) \
- $(HOSTCFLAGS)
+
+KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
+ -O2 -fomit-frame-pointer -std=gnu11
+KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
+KBUILD_USERLDFLAGS := $(USERLDFLAGS)
+
+KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
# Make variables (CC, etc...)
-AS = $(CROSS_COMPILE)as
LD = $(CROSS_COMPILE)ld
CC = $(CROSS_COMPILE)gcc
CPP = $(CC) -E
@@ -395,6 +420,8 @@ BASH = bash
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
CFLAGS_KERNEL =
AFLAGS_KERNEL =
+CFLAGS_MODULE =
+AFLAGS_MODULE =
LDFLAGS_MODULE = -T common/module.lds
@@ -403,41 +430,64 @@ LDFLAGS_MODULE = -T common/module.lds
# even be read-only.
export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
+# Use USERINCLUDE when you must reference the UAPI directories only.
+USERINCLUDE := \
+ -I$(srctree)/arch/$(SRCARCH)/include/uapi \
+ -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
+ -I$(srctree)/include/uapi \
+ -I$(objtree)/include/generated/uapi \
+ -include $(srctree)/include/linux/kconfig.h
+
# Use LINUXINCLUDE when you must reference the include/ directory.
# Needed to be compatible with the O= option
-LINUXINCLUDE := -Iinclude -I$(srctree)/dts/include \
+LINUXINCLUDE := -Iinclude \
$(if $(building_out_of_srctree), -I$(srctree)/include) \
+ -I$(srctree)/dts/include \
-I$(srctree)/arch/$(SRCARCH)/include \
-I$(objtree)/arch/$(SRCARCH)/include \
- -include $(srctree)/include/linux/kconfig.h
+ $(USERINCLUDE)
KBUILD_CPPFLAGS := -D__KERNEL__ -D__BAREBOX__ $(LINUXINCLUDE) -fno-builtin -ffreestanding
KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
- -fno-strict-aliasing -fno-common \
+ -fno-strict-aliasing -fno-common -fshort-wchar \
-Werror=implicit-function-declaration -Werror=implicit-int \
- -Os -pipe -Wmissing-prototypes -std=gnu89
+ -Os -pipe -Wmissing-prototypes -std=gnu11
KBUILD_AFLAGS := -D__ASSEMBLY__
+KBUILD_AFLAGS_KERNEL :=
+KBUILD_CFLAGS_KERNEL :=
+KBUILD_AFLAGS_MODULE := -DMODULE
+KBUILD_CFLAGS_MODULE := -DMODULE
LDFLAGS_barebox := -Map barebox.map
# Avoid 'Not enough room for program headers' error on binutils 2.28 onwards.
-LDFLAGS_barebox += $(call ld-option, --no-dynamic-linker)
-LDFLAGS_pbl += $(call ld-option, --no-dynamic-linker)
+LDFLAGS_common += $(call ld-option, --no-dynamic-linker)
+# Avoid 'missing .note.GNU-stack section implies executable stack' warnings on binutils 2.39+
+LDFLAGS_common += -z noexecstack
+# Avoid '... has a LOAD segment with RWX permissions' warnings on binutils 2.39+
+LDFLAGS_common += $(call ld-option,--no-warn-rwx-segments)
+
+LDFLAGS_barebox += $(LDFLAGS_common)
+LDFLAGS_pbl += $(LDFLAGS_common)
+LDFLAGS_elf += $(LDFLAGS_common) --nmagic -s
-export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
+export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
export CPP AR NM STRIP OBJCOPY OBJDUMP MAKE AWK GENKSYMS PERL PYTHON3 UTS_MACHINE
export LEX YACC
export HOSTCXX CHECK CHECKFLAGS
export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
+export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
-export KBUILD_CFLAGS CFLAGS_KERNEL
-export KBUILD_AFLAGS AFLAGS_KERNEL
-export LDFLAGS_barebox
-export LDFLAGS_pbl
+export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
+export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
+export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE
+export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
+export LDFLAGS_barebox LDFLAGS_pbl LDFLAGS_elf
export CFLAGS_UBSAN
+export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE
# Files to ignore in find ... statements
@@ -529,7 +579,7 @@ endif
# in addition to whatever we do anyway.
# Just "make" or "make all" shall build modules as well
-ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
+ifneq ($(filter all _all modules %compile_commands.json,$(MAKECMDGOALS)),)
KBUILD_MODULES := 1
endif
@@ -551,6 +601,9 @@ common-y := common/ drivers/ commands/ lib/ crypto/ net/ fs/ firmware/
include $(srctree)/arch/$(SRCARCH)/Makefile
+common-$(CONFIG_EFI) += efi/
+common-y += test/
+
ifdef need-config
ifdef may-sync-config
# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
@@ -574,8 +627,11 @@ $(KCONFIG_CONFIG):
# This exploits the 'multi-target pattern rule' trick.
# The syncconfig should be executed only once to make all the targets.
# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
-%/auto.conf %/auto.conf.cmd: $(KCONFIG_CONFIG)
- $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
+quiet_cmd_syncconfig = SYNC $@
+ cmd_syncconfig = $(MAKE) -f $(srctree)/Makefile syncconfig
+
+%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG)
+ +$(call cmd,syncconfig)
else # !may-sync-config
# External modules and some install targets need include/generated/autoconf.h
# and include/config/auto.conf but do not care if they are up-to-date.
@@ -596,8 +652,12 @@ endif # need-config
KBUILD_CFLAGS += -ggdb3
-# Force gcc to behave correct even for buggy distributions
-KBUILD_CFLAGS += $(call cc-option, -fno-stack-protector)
+ifdef CONFIG_FRAME_POINTER
+KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
+KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
+endif
+
+KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
# This warning generated too much noise in a regular build.
# Use make W=1 to enable this warning (see scripts/Makefile.build)
@@ -607,8 +667,26 @@ KBUILD_CFLAGS += $(call cc-disable-warning, trampolines)
KBUILD_CFLAGS += $(call cc-option, -fno-delete-null-pointer-checks,)
+# disable invalid "can't wrap" optimizations for signed / pointers
+KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
+
+# Make sure -fstack-check isn't enabled (like gentoo apparently did)
+KBUILD_CFLAGS += $(call cc-option,-fno-stack-check)
+
+# ensure -fcf-protection is disabled as it is incompatible with our sjlj
+# Platforms that have their setjmp appropriately implemented may override this
+KBUILD_CFLAGS += $(call cc-option,-fcf-protection=none)
+
+# We don't have the necessary infrastructure to benefit from ARMv8.3+ pointer
+# authentication. On older CPUs, they are interpreted as NOPs bloating the code
+KBUILD_CFLAGS += $(call cc-option,-mbranch-protection=none)
+
KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
+# Align the bit size of userspace programs with the kernel
+KBUILD_USERCFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
+KBUILD_USERLDFLAGS += $(filter -m32 -m64, $(KBUILD_CFLAGS))
+
# arch Makefile may override CC so keep this after arch Makefile is included
NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
CHECKFLAGS += $(NOSTDINC_FLAGS)
@@ -616,13 +694,21 @@ CHECKFLAGS += $(NOSTDINC_FLAGS)
# warn about C99 declaration after statement
KBUILD_CFLAGS += $(call cc-option,-Wdeclaration-after-statement,)
+# warn about e.g. (unsigned)x < 0
+KBUILD_CFLAGS += $(call cc-option,-Wtype-limits)
+
# disable pointer signed / unsigned warnings in gcc 4.0
KBUILD_CFLAGS += $(call cc-option,-Wno-pointer-sign,)
# change __FILE__ to the relative path from the srctree
KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
-include $(srctree)/scripts/Makefile.ubsan
+KBUILD_CFLAGS += $(KBUILD_CFLAGS-y)
+
+include-y +=scripts/Makefile.ubsan
+include-$(CONFIG_KASAN) += scripts/Makefile.kasan
+
+include $(addprefix $(srctree)/, $(include-y))
# KBUILD_IMAGE: Default barebox image to build
# Depending on the architecture, this can be either compressed or not.
@@ -648,7 +734,11 @@ images: barebox.bin FORCE
images/%.s: barebox.bin FORCE
$(Q)$(MAKE) $(build)=images $@
-ifdef CONFIG_PBL_IMAGE
+ifdef CONFIG_EFI_STUB
+all: barebox.bin images barebox.efi
+barebox.efi: FORCE
+ $(Q)ln -fsn images/barebox-dt-2nd.img $@
+else ifdef CONFIG_PBL_IMAGE
all: barebox.bin images
else
all: barebox-flash-image barebox-flash-images
@@ -746,6 +836,7 @@ define rule_barebox__
$(if $(CONFIG_KALLSYMS),,+$(call cmd,barebox_version))
$(call cmd,barebox__)
$(Q)echo 'cmd_$@ := $(cmd_barebox__)' > $(@D)/.$(@F).cmd
+ $(call cmd,prelink__)
$(call cmd,sysmap)
endef
@@ -837,49 +928,20 @@ ifndef CONFIG_PBL_IMAGE
$(call cmd,check_file_size,$@,$(CONFIG_BAREBOX_MAX_IMAGE_SIZE))
endif
-# By default the uImage load address is 2MB below CONFIG_TEXT_BASE,
-# leaving space for the compressed PBL image at 1MB below CONFIG_TEXT_BASE.
-UIMAGE_BASE ?= $(shell printf "0x%08x" $$(($(CONFIG_TEXT_BASE) - 0x200000)))
-
-# For development provide a target which makes barebox loadable by an
-# unmodified u-boot
-quiet_cmd_barebox_mkimage = MKIMAGE $@
- cmd_barebox_mkimage = $(srctree)/scripts/mkimage -A $(SRCARCH) -T firmware -C none \
- -O barebox -a $(UIMAGE_BASE) -e $(UIMAGE_BASE) \
- -n "barebox $(KERNELRELEASE)" -d $< $@
-
-# barebox.uimage is build from the raw barebox binary, without any other
-# headers.
-barebox.uimage: $(KBUILD_BINARY) FORCE
- $(call if_changed,barebox_mkimage)
-
-ifdef CONFIG_X86
-barebox.S barebox.s: barebox
-ifdef CONFIG_X86_HDBOOT
- @echo "-------------------------------------------------" > barebox.S
- @echo " * MBR content" >> barebox.S
- $(Q)$(OBJDUMP) -j .bootsector -mi8086 -d barebox >> barebox.S
- @echo "-------------------------------------------------" >> barebox.S
- @echo " * Boot loader content" >> barebox.S
- $(Q)$(OBJDUMP) -j .bootstrapping -mi8086 -d barebox >> barebox.S
+install:
+ifeq ($(INSTALL_PATH),)
+ @echo 'error: INSTALL_PATH undefined' >&2
+ @exit 1
endif
- @echo "-------------------------------------------------" >> barebox.S
- @echo " * Regular Text content" >> barebox.S
- $(Q)$(OBJDUMP) -j .text -d barebox >> barebox.S
- @echo "-------------------------------------------------" >> barebox.S
- @echo " * Regular Data content" >> barebox.S
- $(Q)$(OBJDUMP) -j .data -d barebox >> barebox.S
- @echo "-------------------------------------------------" >> barebox.S
- @echo " * Commands content" >> barebox.S
- $(Q)$(OBJDUMP) -j .barebox_cmd -d barebox >> barebox.S
- @echo "-------------------------------------------------" >> barebox.S
- @echo " * Init Calls content" >> barebox.S
- $(Q)$(OBJDUMP) -j .barebox_initcalls -d barebox >> barebox.S
+ifdef CONFIG_PBL_IMAGE
+ $(Q)$(MAKE) $(build)=images __images_install
+ @install -t "$(INSTALL_PATH)" barebox.bin
else
-barebox.S barebox.s: barebox FORCE
- $(call if_changed,disasm)
+ @install -t "$(INSTALL_PATH)" $(KBUILD_IMAGE)
endif
+PHONY += install
+
# barebox image
barebox: $(BAREBOX_LDS) $(BAREBOX_OBJS) $(kallsyms.o) FORCE
$(call if_changed_rule,barebox__)
@@ -912,7 +974,7 @@ include/config/kernel.release: FORCE
# Carefully list dependencies so we do not try to build scripts twice
# in parallel
PHONY += scripts
-scripts: scripts_basic
+scripts: scripts_basic include/generated/utsrelease.h
$(Q)$(MAKE) $(build)=$(@)
# Things we need to do before we recursively start building the kernel
@@ -925,7 +987,8 @@ scripts: scripts_basic
PHONY += prepare archprepare prepare0
archprepare: outputmakefile scripts_basic include/config/kernel.release \
- $(version_h) include/generated/utsrelease.h include/config.h
+ $(version_h) include/generated/utsrelease.h include/config.h \
+ include/generated/autoconf.h
prepare0: archprepare FORCE
ifneq ($(KBUILD_MODULES),)
@@ -985,6 +1048,22 @@ include/generated/utsrelease.h: include/config/kernel.release FORCE
$(call filechk,utsrelease.h)
# ---------------------------------------------------------------------------
+# Devicetree files
+
+ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/dts/),)
+dtstree := arch/$(SRCARCH)/dts
+endif
+
+ifneq ($(dtstree),)
+
+PHONY += dtbs
+all_dtbs += $(patsubst $(srctree)/%.dts,$(objtree)/%.dtb,$(wildcard $(srctree)/$(dtstree)/*.dts))
+targets += $(all_dtbs)
+dtbs: $(all_dtbs)
+
+endif
+
+# ---------------------------------------------------------------------------
# Modules
ifdef CONFIG_MODULES
@@ -1065,13 +1144,18 @@ endif # CONFIG_MODULES
# Directories & files removed with 'make clean'
CLEAN_DIRS += $(MODVERDIR)
CLEAN_FILES += barebox System.map include/generated/barebox_default_env.h \
- .tmp_version .tmp_barebox* barebox.bin barebox.map barebox.S \
- .tmp_kallsyms* barebox.ldr \
- scripts/bareboxenv-target barebox-flash-image \
- barebox.srec barebox.s5p barebox.ubl barebox.zynq \
- barebox.uimage barebox.spi barebox.kwb barebox.kwbuart \
+ .tmp_version .tmp_barebox* barebox.bin barebox.map \
+ .tmp_kallsyms* barebox.ldr compile_commands.json \
+ barebox-flash-image \
+ barebox.srec barebox.s5p barebox.ubl \
+ barebox.uimage \
barebox.efi barebox.canon-a1100.bin
+CLEAN_FILES += scripts/bareboxenv-target scripts/kernel-install-target \
+ scripts/bareboxcrc32-target scripts/bareboximd-target \
+ scripts/omap3-usb-loader-target scripts/omap4_usbboot-target \
+ scripts/imx-usb-loader-target scripts/kwboot-target
+
# Directories & files removed with 'make mrproper'
MRPROPER_DIRS += include/config usr/include include/generated Documentation/commands
MRPROPER_FILES += .config .config.old .version .old_version \
@@ -1124,17 +1208,17 @@ distclean: mrproper
-o -name 'core' \) \
-type f -print | xargs rm -f
-
-# Packaging of the kernel to various formats
+# Clang Tooling
# ---------------------------------------------------------------------------
-# rpm target kept for backward compatibility
-package-dir := $(srctree)/scripts/package
-%pkg: include/config/kernel.release FORCE
- $(Q)$(MAKE) $(build)=$(package-dir) $@
-rpm: include/config/kernel.release FORCE
- $(Q)$(MAKE) $(build)=$(package-dir) $@
+quiet_cmd_gen_compile_commands = GEN $@
+ cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
+
+compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
+ $(BAREBOX_OBJS) $(if $(CONFIG_PBL_IMAGE),$(BAREBOX_PBL_OBJS),) FORCE
+ $(call if_changed,gen_compile_commands)
+PHONY += compile_commands.json
# Brief documentation of the typical targets used
# ---------------------------------------------------------------------------
@@ -1171,6 +1255,10 @@ help:
@$(if $(archhelp),$(archhelp),\
echo ' No architecture specific help defined for $(SRCARCH)')
@echo ''
+ @$(if $(dtstree), \
+ echo ' Devicetree:'; \
+ echo ' * dtbs - Build device tree blobs for all boards'; \
+ echo '')
@$(if $(boards), \
$(foreach b, $(boards), \
printf " %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
@@ -1202,6 +1290,9 @@ docs: FORCE
@$(SPHINXBUILD) -b html -d $(objtree)/doctrees $(srctree)/Documentation \
$(objtree)/Documentation/html
+bareboxversion:
+ @echo $(KERNELVERSION)
+
# Single targets
# ---------------------------------------------------------------------------
# Single targets are compatible with: