diff options
author | Marcello Sylvester Bauer <info@marcellobauer.com> | 2018-12-05 08:45:26 +0100 |
---|---|---|
committer | Philipp Deppenwiese <zaolin.daisuki@gmail.com> | 2019-04-15 23:23:52 +0000 |
commit | 79f92910ebb1a281b87cd2586cff9c5d06478d6c (patch) | |
tree | 0fe8cb46aaa0c85930a5ed9a47801f46796340b7 /payloads/external/LinuxBoot/targets | |
parent | 59a407349b6ed15fd83023b96ee559b7771c52f8 (diff) |
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>
Diffstat (limited to 'payloads/external/LinuxBoot/targets')
-rw-r--r-- | payloads/external/LinuxBoot/targets/linux.mk | 147 | ||||
-rw-r--r-- | payloads/external/LinuxBoot/targets/u-root.mk | 6 |
2 files changed, 97 insertions, 56 deletions
diff --git a/payloads/external/LinuxBoot/targets/linux.mk b/payloads/external/LinuxBoot/targets/linux.mk index 91118d4496..5632a0b923 100644 --- a/payloads/external/LinuxBoot/targets/linux.mk +++ b/payloads/external/LinuxBoot/targets/linux.mk @@ -13,83 +13,120 @@ ## 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 +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 -kernel_dir=$(project_dir)/kernel - -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 +tarball_dir:=$(project_dir)/tarball +decompress_flag=.done + +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 -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 -toolchain: - if [[ ! -x "$(LINUXBOOT_COMPILE)gcc" ]]; then \ - echo "Toolchain '$(LINUXBOOT_COMPILE)*' is missing."; \ - exit 1; \ - fi +lookup: +ifeq ($(kernel_version),) + $(error kernel version lookup failed for $(TAG-y) release) +endif + @echo " WWW Kernel [$(TAG-y)] $(kernel_version)" -$(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 +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 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) -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 +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 - 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 +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 $< $@ -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 +$(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 $(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 $@ +else + $(error Kernel image format not found) + exit 1 +endif endif -ifneq (,$(filter $(CONFIG_LINUXBOOT_ARCH),i386 amd64)) -kernel: $(project_dir)/bzImage -else ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64) -kernel: $(project_dir)/uImage +ifneq ($(TAG-y),) +kernel: lookup $(top)/$(CONFIG_LINUXBOOT_KERNEL) +else +kernel: $(top)/$(CONFIG_LINUXBOOT_KERNEL) 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 86c9019dce..28d7dbbb33 100644 --- a/payloads/external/LinuxBoot/targets/u-root.mk +++ b/payloads/external/LinuxBoot/targets/u-root.mk @@ -18,6 +18,10 @@ go_path_dir=$(project_dir)/go 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 @@ build: checkout 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 |