diff options
author | Maximilian Brune <maximilian.brune@9elements.com> | 2023-06-26 20:04:47 +0200 |
---|---|---|
committer | Lean Sheng Tan <sheng.tan@9elements.com> | 2023-07-23 18:24:39 +0000 |
commit | c202be793fd483167ab25b60a3f4630137ca33ae (patch) | |
tree | fbf2a71b14847b5f33ebc81363511ccc2fbcd3eb /payloads/external/LinuxBoot/targets/linux.mk | |
parent | 449c6d981c216e05d5238056f03c7794e43600ec (diff) |
payloads/external/LinuxBoot: Clean up
There were some issues with the current Linuxboot Makefiles.
- multithreaded compilation didn't work, because some prerequisites
were missing
- initramfs wasn't added for x86 qemu boot.
- riscv support was incomplete
It began with separate patches, but resulted in a clean up patch, that
is hard to separate. The most important changes are the following:
- Instead of phony targets, actual files are now used as prerequisites
- riscv can now be used as target
- initramfs works now also for x86
- instead of querying the most recent version from the internet, I set a
known working version (because I tested it) that can be customized
and/or upgraded in the future. The reasons:
- querying the version from the internet requires a constant
connection to the internet even after linux kernel is already
build (aka subsequent builds).
- one usually wants to use a known working version, but optionally
still have the posibillity to choose a custom one. This patch
introduces this possibility in its most simple form.
- I removed as much ifeq statements as possible and moved that
responsibility to Kconfig, because they tend to make the
Makefile less readable.
Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: I25e757108e0dd473969fe5a192ad0733f1fe6286
Reviewed-on: https://review.coreboot.org/c/coreboot/+/76150
Reviewed-by: Lean Sheng Tan <sheng.tan@9elements.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'payloads/external/LinuxBoot/targets/linux.mk')
-rw-r--r-- | payloads/external/LinuxBoot/targets/linux.mk | 123 |
1 files changed, 28 insertions, 95 deletions
diff --git a/payloads/external/LinuxBoot/targets/linux.mk b/payloads/external/LinuxBoot/targets/linux.mk index 12f66f7049..4156e1ee74 100644 --- a/payloads/external/LinuxBoot/targets/linux.mk +++ b/payloads/external/LinuxBoot/targets/linux.mk @@ -1,41 +1,20 @@ ## SPDX-License-Identifier: GPL-2.0-only -SHELL := /bin/bash +SHELL := /bin/sh -ARCH-$(CONFIG_LINUXBOOT_X86_64)=x86_64 -ARCH-$(CONFIG_LINUXBOOT_X86)=x86 -ARCH-$(CONFIG_LINUXBOOT_ARM64)=arm64 - -TAG-$(CONFIG_LINUXBOOT_KERNEL_MAINLINE)=mainline -TAG-$(CONFIG_LINUXBOOT_KERNEL_STABLE)=stable -TAG-$(CONFIG_LINUXBOOT_KERNEL_LONGTERM)=longterm - -pwd:=$(shell pwd) -top:=../../.. -project_dir=linuxboot -tarball_dir:=$(project_dir)/tarball -decompress_flag=.done - -OBJCOPY:=$(LINUXBOOT_CROSS_COMPILE)objcopy +OBJCOPY:=$(CONFIG_LINUXBOOT_CROSS_COMPILE)objcopy KERNEL_MAKE_FLAGS = \ - ARCH=$(ARCH-y) \ + CROSS_COMPILE=$(CONFIG_LINUXBOOT_CROSS_COMPILE) \ + ARCH=$(LINUX_ARCH-y) \ KBUILD_BUILD_USER="coreboot" \ KBUILD_BUILD_HOST="reproducible" \ KBUILD_BUILD_TIMESTAMP="$(shell perl -e 'print scalar gmtime($(SOURCE_DATE_EPOCH))')" \ KBUILD_BUILD_VERSION="0" -ifeq ($(CONFIG_LINUXBOOT_KERNEL_CUSTOM),y) - kernel_version:=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION) -else - kernel_version:=$(shell curl -sS -k https://www.kernel.org/feeds/kdist.xml | \ - sed -n -e 's@.*<guid isPermaLink="false">\(.*\)</guid>.*@\1@p' | \ - awk -F ',' '/$(TAG-y)/{ print $$3 }' | \ - head -n 1) -endif - -kernel_dir=$(project_dir)/kernel-$(subst .,_,$(kernel_version)) -kernel_tarball=linux-$(kernel_version).tar -kernel_mirror=https://mirrors.edge.kernel.org/pub/linux/kernel +kernel_version = $(CONFIG_LINUXBOOT_KERNEL_VERSION) +kernel_dir = build/kernel-$(subst .,_,$(kernel_version)) +kernel_tarball = linux-$(kernel_version).tar +kernel_mirror = https://mirrors.edge.kernel.org/pub/linux/kernel ifeq ($(findstring x2.6.,x$(kernel_version)),x2.6.) kernel_mirror_path := $(kernel_mirror)/v2.6 @@ -49,81 +28,35 @@ else ifeq ($(findstring x6.,x$(kernel_version)),x6.) kernel_mirror_path := $(kernel_mirror)/v6.x endif -all: kernel - -lookup: -ifeq ($(kernel_version),) - $(error kernel version lookup failed for $(TAG-y) release) -endif - @echo " WWW Kernel [$(TAG-y)] $(kernel_version)" - -fetch: -ifneq ($(shell [[ -d "$(kernel_dir)" && -f "$(kernel_dir)/$(decompress_flag)" ]];echo $$?),0) - mkdir -p $(tarball_dir) - if [[ ! -f $(tarball_dir)/$(kernel_tarball).xz && ! -f $(tarball_dir)/$(kernel_tarball).xz ]]; then \ - echo " WWW $(kernel_tarball).xz"; \ - cd $(tarball_dir); \ - curl -OLSs "$(kernel_mirror_path)/$(kernel_tarball).xz"; \ - cd $(pwd); \ - fi -endif +build/$(kernel_tarball).xz: + echo " Test $(kernel_version)" + echo " WWW $(kernel_mirror_path)/$(kernel_tarball).xz"; + curl -OLSs --output-dir build "$(kernel_mirror_path)/$(kernel_tarball).xz"; -unpack: fetch - if [[ -d "$(kernel_dir)" && ! -f "$(kernel_dir)/$(decompress_flag)" ]]; then \ - rm -rf $(kernel_dir); \ - fi - if [[ ! -d "$(kernel_dir)" ]]; then \ - mkdir $(kernel_dir); \ - echo " XZ $(kernel_tarball).xz"; \ - tar xJf $(tarball_dir)/$(kernel_tarball).xz --strip 1 -C $(kernel_dir); \ - fi - touch $(kernel_dir)/$(decompress_flag) +$(kernel_dir): build/$(kernel_tarball).xz + echo " XZ $(kernel_tarball).xz"; + mkdir $(kernel_dir); + tar xJf build/$(kernel_tarball).xz --strip 1 -C $(kernel_dir); -$(kernel_dir)/.config: unpack +$(kernel_dir)/.config: $(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) | $(kernel_dir) @echo " CONFIG Linux $(kernel_version)" -ifeq ($(CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG),y) cp $(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) $(kernel_dir)/.config -else - cp $(ARCH-y)/defconfig $(kernel_dir)/.config -endif $(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) olddefconfig -build: $(kernel_dir)/.config +$(kernel_dir)/vmlinux : $(kernel_dir)/.config | $(kernel_dir) @echo " MAKE Linux $(kernel_version)" -ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y) - $(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) CROSS_COMPILE=$(LINUXBOOT_CROSS_COMPILE) bzImage -else -ifeq ($(CONFIG_LINUXBOOT_KERNEL_UIMAGE),y) - $(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) CROSS_COMPILE=$(LINUXBOOT_CROSS_COMPILE) vmlinux -endif -endif + echo "$(MAKE) -j 4 -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) vmlinux" + $(MAKE) -j 4 -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) vmlinux -ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y) -$(top)/$(CONFIG_LINUXBOOT_KERNEL): build - @echo " CP bzImage" - cp $(kernel_dir)/arch/x86/boot/bzImage $@ -else -ifeq ($(CONFIG_LINUXBOOT_KERNEL_UIMAGE),y) -$(project_dir)/target.dtb: $(top)/$(CONFIG_LINUXBOOT_DTB_FILE) - cp $< $@ -$(project_dir)/vmlinux.bin: $(kernel_dir)/vmlinux +build/vmlinux.bin: $(kernel_dir)/vmlinux | build $(OBJCOPY) -O binary $< $@ -$(project_dir)/vmlinux.bin.lzma: $(project_dir)/vmlinux.bin + +build/vmlinux.bin.lzma: build/vmlinux.bin xz -c -k -f --format=lzma --lzma1=dict=1MiB,lc=3,lp=0,pb=3 $< > $@ -$(top)/$(CONFIG_LINUXBOOT_KERNEL): build $(project_dir)/vmlinux.bin.lzma $(project_dir)/target.dtb - cp $(project_dir)/../arm64/kernel_fdt_lzma.its $(project_dir) - cp $(top)/$(CONFIG_LINUXBOOT_INITRAMFS)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) $(project_dir)/initramfs - mkimage -f $(project_dir)/kernel_fdt_lzma.its $@ -else - $(error Kernel image format not found) - exit 1 -endif -endif -ifneq ($(TAG-y),) -kernel: lookup $(top)/$(CONFIG_LINUXBOOT_KERNEL) -else -kernel: $(top)/$(CONFIG_LINUXBOOT_KERNEL) -endif +$(kernel_dir)/arch/x86/boot/bzImage: $(kernel_dir)/.config + @echo " MAKE Linux $(kernel_version)" + echo "$(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) bzImage" + $(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) bzImage -.PHONY: all kernel build unpack fetch check +.PHONY: kernel |