LinuxBoot/targets/linux.mk: refactor kernel compilation

Refactor the linux kernel compilation.

Change-Id: Iea2e2c8a22a91bdd2e3f83cd3058426acec3eaba
Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/30053
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Philipp Deppenwiese <zaolin.daisuki@gmail.com>
This commit is contained in:
Marcello Sylvester Bauer 2018-12-05 08:45:26 +01:00 committed by Philipp Deppenwiese
parent 59a407349b
commit 79f92910eb
6 changed files with 185 additions and 80 deletions

View File

@ -41,18 +41,16 @@ config LINUXBOOT_ARM64
endchoice endchoice
config LINUXBOOT_ARCH
string
default "amd64" if LINUXBOOT_X86_64
default "i386" if LINUXBOOT_X86
default "arm64" if LINUXBOOT_ARM64
comment "Linux kernel" comment "Linux kernel"
config LINUXBOOT_COMPILE_KERNEL config LINUXBOOT_COMPILE_KERNEL
bool "Compile kernel" bool "Compile kernel"
default n default n
if LINUXBOOT_COMPILE_KERNEL
comment "parse linux crosscompiler with: LINUXBOOT_CROSS_COMPILE"
endif
config LINUXBOOT_KERNEL_PATH config LINUXBOOT_KERNEL_PATH
string "Path to kernel" string "Path to kernel"
default "Image" default "Image"
@ -61,32 +59,85 @@ config LINUXBOOT_KERNEL_PATH
if LINUXBOOT_COMPILE_KERNEL if LINUXBOOT_COMPILE_KERNEL
choice choice
prompt "Kernel version" prompt "Kernel release"
default LINUXBOOT_KERNEL_STABLE default LINUXBOOT_KERNEL_STABLE
help
Choose the kernel release.
Select 'custom' if your want to define the kernel version.
For more information about the current 'mainline', 'stable' or 'longterm'
version, visit: https://www.kernel.org/
config LINUXBOOT_KERNEL_MAINLINE
bool "mainline"
help
Mainline kernel version
config LINUXBOOT_KERNEL_STABLE config LINUXBOOT_KERNEL_STABLE
bool "4.14.67" bool "stable"
help help
Stable kernel version Stable kernel version
config LINUXBOOT_KERNEL_LATEST config LINUXBOOT_KERNEL_LONGTERM
bool "4.18.5" bool "longterm"
help help
Latest kernel version Longterm (LTS) kernel version
config LINUXBOOT_KERNEL_CUSTOM
bool "custom"
help
Custom kernel version
endchoice endchoice
config LINUXBOOT_KERNEL_VERSION config LINUXBOOT_KERNEL_CUSTOM_VERSION
string string "kernel version"
default "4.18.5" if LINUXBOOT_KERNEL_LATEST default ""
default "4.14.67" if LINUXBOOT_KERNEL_STABLE depends on LINUXBOOT_KERNEL_CUSTOM
help
Choose the Linux kernel version number. (x.x.x)
Release candidate kernels (rc) are currently are not supported.
choice
prompt "Kernel configuration"
default LINUXBOOT_KERNEL_ARCH_DEFAULT_CONFIG
config LINUXBOOT_KERNEL_ARCH_DEFAULT_CONFIG
bool "Default architecture configuration"
help
This option will use the default configuration for the
selected architecture.
config LINUXBOOT_KERNEL_CUSTOM_CONFIG
bool "Custom (def)config file"
help
endchoice
config LINUXBOOT_KERNEL_CONFIGFILE config LINUXBOOT_KERNEL_CONFIGFILE
string "Kernel config file" string "Config file path"
default "" default "defconfig"
depends on LINUXBOOT_KERNEL_CUSTOM_CONFIG
help help
Add your own kernel configuration file. Otherwise a default Path to the kernel configuration file.
minimal defconfig is used.
Note: this can be a defconfig file or a complete .config file.
choice LINUXBOOT_KERNEL_FORMAT
prompt "Kernel binary format"
default LINUXBOOT_KERNEL_BZIMAGE if LINUXBOOT_X86 || LINUXBOOT_X86_64
default LINUXBOOT_KERNEL_UIMAGE if LINUXBOOT_ARM64
config LINUXBOOT_KERNEL_BZIMAGE
bool "bzImage"
depends on LINUXBOOT_X86 || LINUXBOOT_X86_64
config LINUXBOOT_KERNEL_UIMAGE
bool "uImage"
depends on LINUXBOOT_ARM64
endchoice
config LINUXBOOT_DTB_FILE config LINUXBOOT_DTB_FILE
string "Compiled devicetree file" string "Compiled devicetree file"

View File

@ -45,6 +45,10 @@ endif
ifeq ($(CONFIG_LINUXBOOT_COMPILE_KERNEL),y) ifeq ($(CONFIG_LINUXBOOT_COMPILE_KERNEL),y)
ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64) ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
kernel: initramfs kernel: initramfs
if [[ ! -f "$(top)/$(CONFIG_LINUXBOOT_DTB_FILE)" ]]; then \
echo "<< Linux kernel devicetree is missing. >>"; \
exit 1; \
fi
$(MAKE) -f targets/linux.mk $(MAKE) -f targets/linux.mk
else else
kernel: kernel:

View File

@ -46,7 +46,7 @@
}; };
ramdisk-1 { ramdisk-1 {
description = "Compressed Initramfs"; description = "Compressed Initramfs";
data = /incbin/("u-initramfs"); data = /incbin/("initramfs");
type = "ramdisk"; type = "ramdisk";
arch = "arm64"; arch = "arm64";
os = "linux"; os = "linux";

View File

@ -13,83 +13,120 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
kernel_tarball=https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-$(CONFIG_LINUXBOOT_KERNEL_VERSION).tar.xz ARCH-$(CONFIG_LINUXBOOT_X86_64)=x86_64
project_dir=linuxboot ARCH-$(CONFIG_LINUXBOOT_X86)=x86
kernel_dir=$(project_dir)/kernel ARCH-$(CONFIG_LINUXBOOT_ARM64)=arm64
XGCCPATH?=$(PWD)/util/crossgcc/xgcc/bin TAG-$(CONFIG_LINUXBOOT_KERNEL_MAINLINE)=mainline
ifeq ($(CONFIG_LINUXBOOT_ARCH),i386) TAG-$(CONFIG_LINUXBOOT_KERNEL_STABLE)=stable
LINUXBOOT_COMPILE?=$(XGCCPATH)/i386-linux- TAG-$(CONFIG_LINUXBOOT_KERNEL_LONGTERM)=longterm
ARCH?=x86
else ifeq ($(CONFIG_LINUXBOOT_ARCH),amd64) pwd:=$(shell pwd)
LINUXBOOT_COMPILE?=$(XGCCPATH)/x86_64-linux- top:=../../..
ARCH?=x86_64 project_dir=linuxboot
else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64) tarball_dir:=$(project_dir)/tarball
LINUXBOOT_COMPILE?=$(XGCCPATH)/aarch64-linux- decompress_flag=.done
ARCH?=arm64
OBJCOPY:=$(LINUXBOOT_CROSS_COMPILE)objcopy
ifeq ($(CONFIG_LINUXBOOT_KERNEL_CUSTOM),y)
kernel_version:=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION)
else
kernel_version:=$(shell curl -s -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 endif
OBJCOPY:=$(LINUXBOOT_COMPILE)objcopy kernel_dir=$(project_dir)/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
else ifeq ($(findstring x3.,x$(kernel_version)),x3.)
kernel_mirror_path := $(kernel_mirror)/v3.x
else ifeq ($(findstring x4.,x$(kernel_version)),x4.)
kernel_mirror_path := $(kernel_mirror)/v4.x
else ifeq ($(findstring x5.,x$(kernel_version)),x5.)
kernel_mirror_path := $(kernel_mirror)/v5.x
endif
all: kernel all: kernel
toolchain: lookup:
if [[ ! -x "$(LINUXBOOT_COMPILE)gcc" ]]; then \ ifeq ($(kernel_version),)
echo "Toolchain '$(LINUXBOOT_COMPILE)*' is missing."; \ $(error kernel version lookup failed for $(TAG-y) release)
exit 1; \ 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 -OLs "$(kernel_mirror_path)/$(kernel_tarball).xz"; \
cd $(pwd); \
fi fi
$(kernel_dir)/.config:
echo " WWW Download Linux $(CONFIG_LINUXBOOT_KERNEL_VERSION)"
mkdir -p $(kernel_dir)
ifeq ("$(wildcard $(kernel_dir)/README)","")
curl -s $(kernel_tarball) | tar xJ -C $(kernel_dir) --strip 1
endif endif
config: $(kernel_dir)/.config unpack: fetch
echo " CONFIG Linux $(CONFIG_LINUXBOOT_KERNEL_VERSION)" if [[ -d "$(kernel_dir)" && ! -f "$(kernel_dir)/$(decompress_flag)" ]]; then \
ifneq ($(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE),) 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)/.config: unpack
@echo " CONFIG Linux $(kernel_version)"
ifeq ($(CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG),y)
cp $(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) $(kernel_dir)/.config cp $(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) $(kernel_dir)/.config
else ifeq ($(CONFIG_LINUXBOOT_ARCH),i386) else
cp x86/defconfig $(kernel_dir)/.config cp $(ARCH-y)/defconfig $(kernel_dir)/.config
else ifeq ($(CONFIG_LINUXBOOT_ARCH),amd64) endif
cp x86_64/defconfig $(kernel_dir)/.config $(MAKE) -C $(kernel_dir) olddefconfig ARCH=$(ARCH-y)
else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
cp arm64/defconfig $(kernel_dir)/.config build: $(kernel_dir)/.config
@echo " MAKE Linux $(kernel_version)"
ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y)
$(MAKE) -C $(kernel_dir) CROSS_COMPILE=$(LINUXBOOT_CROSS_COMPILE) ARCH=$(ARCH-y) bzImage
else
ifeq ($(CONFIG_LINUXBOOT_KERNEL_UIMAGE),y)
$(MAKE) -C $(kernel_dir) CROSS_COMPILE=$(LINUXBOOT_CROSS_COMPILE) ARCH=$(ARCH-y) vmlinux
endif
endif endif
ifneq (,$(filter $(CONFIG_LINUXBOOT_ARCH),i386 amd64)) ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y)
$(kernel_dir)/arch/x86/boot/bzImage: config toolchain $(top)/$(CONFIG_LINUXBOOT_KERNEL): build
else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64) @echo " CP bzImage"
$(kernel_dir)/vmlinux: config toolchain cp $(kernel_dir)/arch/x86/boot/bzImage $@
endif else
echo " MAKE Kernel $(CONFIG_LINUXBOOT_KERNEL_VERSION)" ifeq ($(CONFIG_LINUXBOOT_KERNEL_UIMAGE),y)
$(MAKE) -C $(kernel_dir) olddefconfig CROSS_COMPILE=$(LINUXBOOT_COMPILE) ARCH=$(ARCH) $(project_dir)/target.dtb: $(top)/$(CONFIG_LINUXBOOT_DTB_FILE)
$(MAKE) -C $(kernel_dir) -j $(CPUS) CROSS_COMPILE=$(LINUXBOOT_COMPILE) ARCH=$(ARCH)
ifneq (,$(filter $(CONFIG_LINUXBOOT_ARCH),i386 amd64))
$(project_dir)/bzImage: $(kernel_dir)/arch/x86/boot/bzImage
cp $< $@ cp $< $@
else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
$(project_dir)/vmlinux.bin: $(kernel_dir)/vmlinux $(project_dir)/vmlinux.bin: $(kernel_dir)/vmlinux
$(OBJCOPY) -O binary $< $@ $(OBJCOPY) -O binary $< $@
$(project_dir)/target.dtb: $(PWD)/$(CONFIG_LINUXBOOT_DTB_FILE)
cp $< $@
$(project_dir)/vmlinux.bin.lzma: $(project_dir)/vmlinux.bin $(project_dir)/vmlinux.bin.lzma: $(project_dir)/vmlinux.bin
xz -c -k -f --format=lzma --lzma1=dict=1MiB,lc=3,lp=0,pb=3 $< > $@ 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
$(project_dir)/uImage: $(project_dir)/vmlinux.bin.lzma $(project_dir)/../arm64/kernel_fdt_lzma.its $(project_dir)/target.dtb
cp $(project_dir)/../arm64/kernel_fdt_lzma.its $(project_dir) cp $(project_dir)/../arm64/kernel_fdt_lzma.its $(project_dir)
cp $(PWD)/$(CONFIG_LINUXBOOT_INITRAMFS)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) $(project_dir)/u-initramfs cp $(top)/$(CONFIG_LINUXBOOT_INITRAMFS)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) $(project_dir)/initramfs
mkimage -f $(project_dir)/kernel_fdt_lzma.its $@ mkimage -f $(project_dir)/kernel_fdt_lzma.its $@
else
$(error Kernel image format not found)
exit 1
endif
endif endif
ifneq (,$(filter $(CONFIG_LINUXBOOT_ARCH),i386 amd64)) ifneq ($(TAG-y),)
kernel: $(project_dir)/bzImage kernel: lookup $(top)/$(CONFIG_LINUXBOOT_KERNEL)
else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64) else
kernel: $(project_dir)/uImage kernel: $(top)/$(CONFIG_LINUXBOOT_KERNEL)
endif endif
.PHONY: kernel config toolchain .PHONY: all kernel build unpack fetch check

View File

@ -18,6 +18,10 @@ go_path_dir=$(project_dir)/go
uroot_bin=$(project_dir)/u-root uroot_bin=$(project_dir)/u-root
uroot_package=github.com/u-root/u-root uroot_package=github.com/u-root/u-root
ARCH-$(CONFIG_LIBUXBOOT_X86_64)=amd64
ARCH-$(CONFIG_LINUXBOOT_X86)=i386
ARCH-$(CONFIG_LINUXBOOT_ARM64)=arm64
go_version=$(shell go version | sed -nr 's/.*go([0-9]+\.[0-9]+.?[0-9]?).*/\1/p' ) go_version=$(shell go version | sed -nr 's/.*go([0-9]+\.[0-9]+.?[0-9]?).*/\1/p' )
go_version_major=$(shell echo $(go_version) | sed -nr 's/^([0-9]+)\.([0-9]+)\.?([0-9]*)$$/\1/p') go_version_major=$(shell echo $(go_version) | sed -nr 's/^([0-9]+)\.([0-9]+)\.?([0-9]*)$$/\1/p')
go_version_minor=$(shell echo $(go_version) | sed -nr 's/^([0-9]+)\.([0-9]+)\.?([0-9]*)$$/\2/p') go_version_minor=$(shell echo $(go_version) | sed -nr 's/^([0-9]+)\.([0-9]+)\.?([0-9]*)$$/\2/p')
@ -64,7 +68,7 @@ build: checkout
GOPATH=$(go_path_dir) go build -o $(uroot_bin) $(uroot_package) GOPATH=$(go_path_dir) go build -o $(uroot_bin) $(uroot_package)
u-root: build u-root: build
GOARCH=$(CONFIG_LINUXBOOT_ARCH) GOPATH=$(go_path_dir) $(uroot_bin) \ GOARCH=$(ARCH-y) GOPATH=$(go_path_dir) $(uroot_bin) \
$(uroot_args) -o $(project_dir)/initramfs_u-root.cpio $(uroot_cmds) $(uroot_args) -o $(project_dir)/initramfs_u-root.cpio $(uroot_cmds)
.PHONY: all u-root build checkout get version .PHONY: all u-root build checkout get version

View File

@ -260,13 +260,22 @@ payloads/external/iPXE/ipxe/ipxe.rom ipxe: $(DOTCONFIG)
linuxboot: linuxboot:
$(MAKE) -C payloads/external/LinuxBoot \ $(MAKE) -C payloads/external/LinuxBoot \
CPUS=$(CPUS) \ CPUS=$(CPUS) \
CONFIG_LINUXBOOT_ARCH=$(CONFIG_LINUXBOOT_ARCH) \ CONFIG_LINUXBOOT_X86_64=$(CONFIG_LINUXBOOT_X86_64) \
CONFIG_LINUXBOOT_X86=$(CONFIG_LINUXBOOT_X86) \
CONFIG_LINUXBOOT_ARM64=$(CONFIG_LINUXBOOT_ARM64) \
CONFIG_LINUXBOOT_KERNEL=$(CONFIG_PAYLOAD_FILE) \ CONFIG_LINUXBOOT_KERNEL=$(CONFIG_PAYLOAD_FILE) \
CONFIG_LINUXBOOT_INITRAMFS=$(CONFIG_LINUX_INITRD) \ CONFIG_LINUXBOOT_INITRAMFS=$(CONFIG_LINUX_INITRD) \
CONFIG_LINUXBOOT_INITRAMFS_SUFFIX=$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) \ CONFIG_LINUXBOOT_INITRAMFS_SUFFIX=$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) \
CONFIG_LINUXBOOT_COMPILE_KERNEL=$(CONFIG_LINUXBOOT_COMPILE_KERNEL) \ CONFIG_LINUXBOOT_COMPILE_KERNEL=$(CONFIG_LINUXBOOT_COMPILE_KERNEL) \
CONFIG_LINUXBOOT_BUILD_INITRAMFS=$(CONFIG_LINUXBOOT_BUILD_INITRAMFS) \ CONFIG_LINUXBOOT_BUILD_INITRAMFS=$(CONFIG_LINUXBOOT_BUILD_INITRAMFS) \
CONFIG_LINUXBOOT_KERNEL_VERSION=$(CONFIG_LINUXBOOT_KERNEL_VERSION) \ CONFIG_LINUXBOOT_KERNEL_MAINLINE=$(CONFIG_LINUXBOOT_KERNEL_MAINLINE) \
CONFIG_LINUXBOOT_KERNEL_STABLE=$(CONFIG_LINUXBOOT_KERNEL_STABLE) \
CONFIG_LINUXBOOT_KERNEL_LONGTERM=$(CONFIG_LINUXBOOT_KERNEL_LONGTERM) \
CONFIG_LINUXBOOT_KERNEL_CUSTOM=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM) \
CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION) \
CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG) \
CONFIG_LINUXBOOT_KERNEL_BZIMAGE=$(CONFIG_LINUXBOOT_KERNEL_BZIMAGE) \
CONFIG_LINUXBOOT_KERNEL_UIMAGE=$(CONFIG_LINUXBOOT_KERNEL_UIMAGE) \
CONFIG_LINUXBOOT_KERNEL_CONFIGFILE=$(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) \ CONFIG_LINUXBOOT_KERNEL_CONFIGFILE=$(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) \
CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ=$(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ) \ CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ=$(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ) \
CONFIG_LINUXBOOT_UROOT=$(CONFIG_LINUXBOOT_UROOT) \ CONFIG_LINUXBOOT_UROOT=$(CONFIG_LINUXBOOT_UROOT) \