[coreboot-gerrit] Change in ...coreboot[master]: LinuxBoot/targets/linux.mk: refactor Kernel compilation
Marcello Sylvester Bauer (Code Review)
gerrit at coreboot.org
Wed Dec 5 16:30:26 CET 2018
Marcello Sylvester Bauer has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/30053
Change subject: LinuxBoot/targets/linux.mk: refactor Kernel compilation
......................................................................
LinuxBoot/targets/linux.mk: refactor Kernel compilation
Refactor the linux kernel compilation.
TODO:
- parse crosscompiler
- support uImage (for arm64)
Change-Id: Iea2e2c8a22a91bdd2e3f83cd3058426acec3eaba
Signed-off-by: Marcello Sylvester Bauer <info at marcellobauer.com>
---
M payloads/external/LinuxBoot/Kconfig
M payloads/external/LinuxBoot/targets/linux.mk
M payloads/external/LinuxBoot/targets/u-root.mk
M payloads/external/Makefile.inc
4 files changed, 192 insertions(+), 88 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/53/30053/1
diff --git a/payloads/external/LinuxBoot/Kconfig b/payloads/external/LinuxBoot/Kconfig
index 3b8b70c..de289d7 100644
--- a/payloads/external/LinuxBoot/Kconfig
+++ b/payloads/external/LinuxBoot/Kconfig
@@ -41,12 +41,6 @@
endchoice
-config LINUXBOOT_ARCH
- string
- default "amd64" if LINUXBOOT_X86_64
- default "i386" if LINUXBOOT_X86
- default "arm64" if LINUXBOOT_ARM64
-
comment "Linux kernel"
config LINUXBOOT_COMPILE_KERNEL
@@ -61,32 +55,88 @@
if LINUXBOOT_COMPILE_KERNEL
choice
- prompt "Kernel version"
+ prompt "Kernel release"
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
- bool "4.14.67"
+ bool "stable"
help
Stable kernel version
-config LINUXBOOT_KERNEL_LATEST
- bool "4.18.5"
+config LINUXBOOT_KERNEL_LONGTERM
+ bool "longterm"
help
- Latest kernel version
+ Longterm (LTS) kernel version
+
+config LINUXBOOT_KERNEL_CUSTOM
+ bool "custom"
+ help
+ Custom kernel version
endchoice
-config LINUXBOOT_KERNEL_VERSION
- string
- default "4.18.5" if LINUXBOOT_KERNEL_LATEST
- default "4.14.67" if LINUXBOOT_KERNEL_STABLE
+config LINUXBOOT_KERNEL_CUSTOM_VERSION
+ string "kernel version"
+ default ""
+ 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
- string "Kernel config file"
- default ""
+ string "Config file path"
+ default "defconfig"
+ depends on LINUXBOOT_KERNEL_CUSTOM_CONFIG
help
- Add your own kernel configuration file. Otherwise a default
- minimal defconfig is used.
+ Path to the kernel configuration file.
+
+ 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
+
+#config LINUXBOOT_KERNEL_VMLINUX
+# bool "vmlinux"
+
+endchoice
+
config LINUXBOOT_DTB_FILE
string "Compiled devicetree file"
diff --git a/payloads/external/LinuxBoot/targets/linux.mk b/payloads/external/LinuxBoot/targets/linux.mk
index 91118d4..8c1a4be 100644
--- a/payloads/external/LinuxBoot/targets/linux.mk
+++ b/payloads/external/LinuxBoot/targets/linux.mk
@@ -13,83 +13,125 @@
## 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
-project_dir=linuxboot
-kernel_dir=$(project_dir)/kernel
+ARCH-$(CONFIG_LINUXBOOT_X86_64)=x86_64
+ARCH-$(CONFIG_LINUXBOOT_X86)=x86
+ARCH-$(CONFIG_LINUXBOOT_ARM64)=arm64
-XGCCPATH?=$(PWD)/util/crossgcc/xgcc/bin
-ifeq ($(CONFIG_LINUXBOOT_ARCH),i386)
-LINUXBOOT_COMPILE?=$(XGCCPATH)/i386-linux-
-ARCH?=x86
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),amd64)
-LINUXBOOT_COMPILE?=$(XGCCPATH)/x86_64-linux-
-ARCH?=x86_64
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
-LINUXBOOT_COMPILE?=$(XGCCPATH)/aarch64-linux-
-ARCH?=arm64
+TAG-$(CONFIG_LINUXBOOT_KERNEL_MAINLINE)=mainline
+TAG-$(CONFIG_LINUXBOOT_KERNEL_STABLE)=stable
+TAG-$(CONFIG_LINUXBOOT_KERNEL_LONGTERM)=longterm
+
+GPG2:=$(shell which gpg)
+ifneq ($(GPG2),)
+verify_signature=y
endif
-OBJCOPY:=$(LINUXBOOT_COMPILE)objcopy
+pwd:=$(shell pwd)
+project_dir=linuxboot
+tarball_dir:=$(project_dir)/tarball
+decompress_flag=.done
+
+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 at .*<guid isPermaLink="false">\(.*\)</guid>.*@\1 at 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
+
+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
-toolchain:
- if [[ ! -x "$(LINUXBOOT_COMPILE)gcc" ]]; then \
- echo "Toolchain '$(LINUXBOOT_COMPILE)*' is missing."; \
- exit 1; \
+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)
+ifneq ($(verify_signature),y)
+ @echo " GPG gpg2 tool not found. Skipping signature check"
+else
+ if [[ -f $(tarball_dir)/$(kernel_tarball).xz && -f $(tarball_dir)/$(kernel_tarball).xz ]]; then \
+ echo " GPG $(kernel_tarball) check signature"; \
+ if ((xz -cd $(tarball_dir)/$(kernel_tarball).xz | $(GPG2) --verify $(tarball_dir)/$(kernel_tarball).sign - ) >/dev/null 2>&1); then \
+ echo " GPG $(kernel_tarball) signature valid"; \
+ else \
+ echo " GPG $(kernel_tarball) failed"; \
+ echo " RM $(kernel_tarball)"; \
+ rm -f $(tarball_dir)/$(kernel_tarball).{xz,sign}; \
+ 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
+ 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,sign}"; \
+ cd $(pwd); \
+ echo " GPG $(kernel_tarball) check signature"; \
+ if ((xz -cd $(tarball_dir)/$(kernel_tarball).xz | $(GPG2) --verify $(tarball_dir)/$(kernel_tarball).sign - ) >/dev/null 2>&1); then \
+ echo " GPG $(kernel_tarball) signature valid"; \
+ else \
+ echo " GPG $(kernel_tarball) failed"; \
+ echo " RM $(kernel_tarball)"; \
+ rm -f $(tarball_dir)/$(kernel_tarball).{xz,sign}; \
+ exit 1; \
+ fi; \
+ fi
endif
-config: $(kernel_dir)/.config
- echo " CONFIG Linux $(CONFIG_LINUXBOOT_KERNEL_VERSION)"
-ifneq ($(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE),)
+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)/.config: unpack
+ @echo " CONFIG Linux $(kernel_version)"
+ifeq ($(CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG),y)
cp $(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) $(kernel_dir)/.config
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),i386)
- cp x86/defconfig $(kernel_dir)/.config
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),amd64)
- cp x86_64/defconfig $(kernel_dir)/.config
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
- cp arm64/defconfig $(kernel_dir)/.config
+else
+ cp $(ARCH-y)/defconfig $(kernel_dir)/.config
+endif
+ $(MAKE) -C $(kernel_dir) olddefconfig ARCH=$(ARCH-y)
+
+build: $(kernel_dir)/.config
+ @echo " MAKE Linux $(kernel_version)"
+ $(MAKE) -C $(kernel_dir) CROSS_COMPILE=$(LINUXBOOT_COMPILE) ARCH=$(ARCH-y)
+
+$(project_dir)/$(LINUXBOOT_KERNEL_IMAGE): build
+ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y)
+ @echo " CP bzImage"
+ cp $(kernel_dir)/arch/x86/boot/bzImage $@
+else
+ $(error Kernel image format not found)
endif
-ifneq (,$(filter $(CONFIG_LINUXBOOT_ARCH),i386 amd64))
-$(kernel_dir)/arch/x86/boot/bzImage: config toolchain
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
-$(kernel_dir)/vmlinux: config toolchain
-endif
- echo " MAKE Kernel $(CONFIG_LINUXBOOT_KERNEL_VERSION)"
- $(MAKE) -C $(kernel_dir) olddefconfig CROSS_COMPILE=$(LINUXBOOT_COMPILE) ARCH=$(ARCH)
- $(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 $< $@
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
-$(project_dir)/vmlinux.bin: $(kernel_dir)/vmlinux
- $(OBJCOPY) -O binary $< $@
-
-$(project_dir)/target.dtb: $(PWD)/$(CONFIG_LINUXBOOT_DTB_FILE)
- cp $< $@
-
-$(project_dir)/vmlinux.bin.lzma: $(project_dir)/vmlinux.bin
- xz -c -k -f --format=lzma --lzma1=dict=1MiB,lc=3,lp=0,pb=3 $< > $@
-
-$(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 $(PWD)/$(CONFIG_LINUXBOOT_INITRAMFS)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) $(project_dir)/u-initramfs
- mkimage -f $(project_dir)/kernel_fdt_lzma.its $@
+ifneq ($(TAG-y),)
+kernel: lookup $(project_dir)/$(LINUXBOOT_KERNEL_IMAGE)
+else
+kernel: $(project_dir)/$(LINUXBOOT_KERNEL_IMAGE)
endif
-ifneq (,$(filter $(CONFIG_LINUXBOOT_ARCH),i386 amd64))
-kernel: $(project_dir)/bzImage
-else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
-kernel: $(project_dir)/uImage
-endif
-
-.PHONY: kernel config toolchain
+.PHONY: all kernel build unpack fetch check
diff --git a/payloads/external/LinuxBoot/targets/u-root.mk b/payloads/external/LinuxBoot/targets/u-root.mk
index 86c9019..28d7dbb 100644
--- a/payloads/external/LinuxBoot/targets/u-root.mk
+++ b/payloads/external/LinuxBoot/targets/u-root.mk
@@ -18,6 +18,10 @@
uroot_bin=$(project_dir)/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_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')
@@ -64,7 +68,7 @@
GOPATH=$(go_path_dir) go build -o $(uroot_bin) $(uroot_package)
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)
.PHONY: all u-root build checkout get version
diff --git a/payloads/external/Makefile.inc b/payloads/external/Makefile.inc
index 4fda725..1b5e20f 100644
--- a/payloads/external/Makefile.inc
+++ b/payloads/external/Makefile.inc
@@ -259,13 +259,21 @@
linuxboot:
$(MAKE) -C payloads/external/LinuxBoot \
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_INITRAMFS=$(CONFIG_LINUX_INITRD) \
CONFIG_LINUXBOOT_INITRAMFS_SUFFIX=$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) \
CONFIG_LINUXBOOT_COMPILE_KERNEL=$(CONFIG_LINUXBOOT_COMPILE_KERNEL) \
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_CONFIGFILE=$(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) \
CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ=$(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ) \
CONFIG_LINUXBOOT_UROOT=$(CONFIG_LINUXBOOT_UROOT) \
--
To view, visit https://review.coreboot.org/c/coreboot/+/30053
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings
Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: Iea2e2c8a22a91bdd2e3f83cd3058426acec3eaba
Gerrit-Change-Number: 30053
Gerrit-PatchSet: 1
Gerrit-Owner: Marcello Sylvester Bauer <sylvblck at sylv.io>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20181205/f5b94e14/attachment-0001.html>
More information about the coreboot-gerrit
mailing list