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>
This commit is contained in:
Maximilian Brune 2023-06-26 20:04:47 +02:00 committed by Lean Sheng Tan
parent 449c6d981c
commit c202be793f
11 changed files with 244 additions and 277 deletions

View File

@ -19,6 +19,13 @@ config LINUXBOOT_X86
help help
X86 kernel and initramfs X86 kernel and initramfs
config LINUXBOOT_ARM
bool "arm64"
depends on ARCH_ARM
select PAYLOAD_FIT_SUPPORT
help
arm kernel and initramfs
config LINUXBOOT_ARM64 config LINUXBOOT_ARM64
bool "arm64" bool "arm64"
depends on ARCH_ARM64 depends on ARCH_ARM64
@ -26,9 +33,16 @@ config LINUXBOOT_ARM64
help help
AARCH64 kernel and initramfs AARCH64 kernel and initramfs
config LINUXBOOT_RISCV config LINUXBOOT_RISCV_RV32
bool "RISC-V" bool "RISC-V"
depends on ARCH_RISCV depends on ARCH_RISCV_RV32
select PAYLOAD_FIT_SUPPORT
help
RISC-V kernel and initramfs
config LINUXBOOT_RISCV_RV64
bool "RISC-V"
depends on ARCH_RISCV_RV64
select PAYLOAD_FIT_SUPPORT select PAYLOAD_FIT_SUPPORT
help help
RISC-V kernel and initramfs RISC-V kernel and initramfs
@ -41,76 +55,38 @@ 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 "build/uImage" if LINUXBOOT_KERNEL_UIMAGE
depends on !LINUXBOOT_COMPILE_KERNEL default "build/bzImage" if LINUXBOOT_KERNEL_BZIMAGE
help
The kernel path is either and absolute path or relative to the
LinuxBoot directory
if LINUXBOOT_COMPILE_KERNEL if LINUXBOOT_COMPILE_KERNEL
choice config LINUXBOOT_CROSS_COMPILE
prompt "Kernel release" string "cross compiler"
default LINUXBOOT_KERNEL_STABLE default "" # e.g. "aarch64-linux-gnu-"
help help
Choose the kernel release. Choose a custom cross compiler toolchain to use.
It can be useful if you don't want to use the coreboot toolchain
or experience problems using it.
Select 'custom' if your want to define the kernel version. config LINUXBOOT_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 "stable"
help
Stable kernel version
config LINUXBOOT_KERNEL_LONGTERM
bool "longterm"
help
Longterm (LTS) kernel version
config LINUXBOOT_KERNEL_CUSTOM
bool "custom"
help
Custom kernel version
endchoice
config LINUXBOOT_KERNEL_CUSTOM_VERSION
string "kernel version" string "kernel version"
default "" default "6.3"
depends on LINUXBOOT_KERNEL_CUSTOM
help help
Choose the Linux kernel version number. (x.x.x) Choose the Linux kernel version number. (x.x.x)
Release candidate kernels (rc) are currently are not supported. 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"
endchoice
config LINUXBOOT_KERNEL_CONFIGFILE config LINUXBOOT_KERNEL_CONFIGFILE
string "Config file path" string "Config file path"
default "defconfig" default "i386/defconfig" if LINUXBOOT_X86
depends on LINUXBOOT_KERNEL_CUSTOM_CONFIG default "x86_64/defconfig" if LINUXBOOT_X86_64
default "arm64/defconfig" if LINUXBOOT_ARM64
default "riscv/defconfig-32" if LINUXBOOT_RISCV_RV32
default "riscv/defconfig-64" if LINUXBOOT_RISCV_RV64
help help
Path to the kernel configuration file. Path to the kernel configuration file.
@ -119,7 +95,7 @@ config LINUXBOOT_KERNEL_CONFIGFILE
choice choice
prompt "Kernel binary format" prompt "Kernel binary format"
default LINUXBOOT_KERNEL_BZIMAGE if LINUXBOOT_X86 || LINUXBOOT_X86_64 default LINUXBOOT_KERNEL_BZIMAGE if LINUXBOOT_X86 || LINUXBOOT_X86_64
default LINUXBOOT_KERNEL_UIMAGE if LINUXBOOT_ARM64 || LINUXBOOT_RISCV default LINUXBOOT_KERNEL_UIMAGE if LINUXBOOT_ARM64 || LINUXBOOT_RISCV_RV32 || LINUXBOOT_RISCV_RV64
config LINUXBOOT_KERNEL_BZIMAGE config LINUXBOOT_KERNEL_BZIMAGE
bool "bzImage" bool "bzImage"
@ -127,14 +103,14 @@ config LINUXBOOT_KERNEL_BZIMAGE
config LINUXBOOT_KERNEL_UIMAGE config LINUXBOOT_KERNEL_UIMAGE
bool "uImage" bool "uImage"
depends on LINUXBOOT_ARM64 || LINUXBOOT_RISCV depends on LINUXBOOT_ARM64 || LINUXBOOT_RISCV_RV32 || LINUXBOOT_RISCV_RV64
endchoice endchoice
config LINUXBOOT_DTB_FILE config LINUXBOOT_DTS_FILE
string "Compiled devicetree file" string "Compiled devicetree file"
depends on LINUXBOOT_ARM64 || LINUXBOOT_RISCV depends on LINUXBOOT_ARM64 || LINUXBOOT_RISCV_RV32 || LINUXBOOT_RISCV_RV64
default "" default "empty.dts"
endif #LINUXBOOT_COMPILE_KERNEL endif #LINUXBOOT_COMPILE_KERNEL
@ -145,9 +121,7 @@ config LINUX_COMMAND_LINE
Add your own kernel command-line arguments. Add your own kernel command-line arguments.
config PAYLOAD_FILE config PAYLOAD_FILE
default "payloads/external/LinuxBoot/linuxboot/bzImage" if LINUXBOOT_COMPILE_KERNEL && ( LINUXBOOT_X86 || LINUXBOOT_X86_64 ) default "payloads/external/LinuxBoot/build/Image"
default "payloads/external/LinuxBoot/linuxboot/uImage" if LINUXBOOT_COMPILE_KERNEL && (LINUXBOOT_ARM64 || LINUXBOOT_RISCV)
default LINUXBOOT_KERNEL_PATH if !LINUXBOOT_COMPILE_KERNEL
comment "Linux initramfs" comment "Linux initramfs"
@ -157,16 +131,17 @@ config LINUXBOOT_BUILD_INITRAMFS
config LINUXBOOT_INITRAMFS_PATH config LINUXBOOT_INITRAMFS_PATH
string "Path to initramfs" string "Path to initramfs"
depends on !LINUXBOOT_BUILD_INITRAMFS default "build/initramfs_u-root.cpio" if LINUXBOOT_UROOT
if LINUXBOOT_BUILD_INITRAMFS if LINUXBOOT_BUILD_INITRAMFS
choice choice
prompt "Payload Mode" prompt "Initramfs"
default LINUXBOOT_UROOT default LINUXBOOT_UROOT
config LINUXBOOT_UROOT config LINUXBOOT_UROOT
bool "u-root" bool "u-root"
depends on !LINUXBOOT_RISCV_RV32 # not supported by u-root
help help
Enable u-root linuxboot mode. Enable u-root linuxboot mode.
See http://u-root.tk/ for more information. See http://u-root.tk/ for more information.
@ -345,11 +320,6 @@ config LINUXBOOT_INITRAMFS_COMPRESSION_XZ
endchoice endchoice
config LINUX_INITRD
string
default "payloads/external/LinuxBoot/linuxboot/initramfs_u-root.cpio" if LINUXBOOT_UROOT
default LINUXBOOT_INITRAMFS_PATH if !LINUXBOOT_BUILD_INITRAMFS
config LINUXBOOT_INITRAMFS_SUFFIX config LINUXBOOT_INITRAMFS_SUFFIX
string string
default "" if LINUXBOOT_INITRAMFS_COMPRESSION_NONE default "" if LINUXBOOT_INITRAMFS_COMPRESSION_NONE

View File

@ -1,62 +1,51 @@
## SPDX-License-Identifier: GPL-2.0-only ## SPDX-License-Identifier: GPL-2.0-only
project_dir=linuxboot
unexport $(COREBOOT_EXPORTS) unexport $(COREBOOT_EXPORTS)
all: linuxboot DTC ?= dtc
u-root: LINUX_ARCH-$(CONFIG_LINUXBOOT_X86_64) = x86_64
$(MAKE) -f targets/u-root.mk LINUX_ARCH-$(CONFIG_LINUXBOOT_X86) = i386
LINUX_ARCH-$(CONFIG_LINUXBOOT_ARM64) = arm64
LINUX_ARCH-$(CONFIG_LINUXBOOT_RISCV_RV32) = riscv
LINUX_ARCH-$(CONFIG_LINUXBOOT_RISCV_RV64) = riscv
ifeq ($(CONFIG_LINUXBOOT_BUILD_INITRAMFS),y) build/Image: $(CONFIG_LINUXBOOT_KERNEL_PATH)
ifeq ($(CONFIG_LINUXBOOT_UROOT),y) ln -s -r $< $@
initramfs: u-root
endif
else
ifneq ($(CONFIG_LINUXBOOT_INITRAMFS),)
initramfs:
if [[ ! -f "$(top)/$(CONFIG_LINUXBOOT_INITRAMFS)" ]]; then \
echo "<< Linux initramfs '$(CONFIG_LINUXBOOT_INITRAMFS)' is missing. >>"; \
exit 1; \
fi
endif
endif
initramfs_compressed: initramfs include targets/linux.mk targets/u-root.mk
build/initramfs: $(CONFIG_LINUXBOOT_INITRAMFS_PATH)
ifeq ($(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ),y) ifeq ($(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ),y)
xz --keep --force --check=crc32 --lzma2=dict=1MiB $(top)/$(CONFIG_LINUXBOOT_INITRAMFS) xz --keep --force --check=crc32 --lzma2=dict=1MiB $(CONFIG_LINUXBOOT_INITRAMFS_PATH)
endif endif
cp $(CONFIG_LINUXBOOT_INITRAMFS_PATH)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) $@
ifeq ($(CONFIG_LINUXBOOT_COMPILE_KERNEL),y) ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y)
ifeq ($(CONFIG_LINUXBOOT_ARCH),arm64)
kernel: initramfs
if [[ ! -f "$(top)/$(CONFIG_LINUXBOOT_DTB_FILE)" ]]; then \
echo "<< Linux kernel devicetree is missing. >>"; \
exit 1; \
fi
$(MAKE) -f targets/linux.mk
else
kernel:
$(MAKE) -f targets/linux.mk
endif
else
kernel:
if [[ ! -f "$(top)/$(CONFIG_LINUXBOOT_KERNEL)" ]]; then \
echo "<< Linux kernel '$(CONFIG_LINUXBOOT_KERNEL)' is missing. >>"; \
exit 1; \
fi
endif
linuxboot: kernel initramfs_compressed build/bzImage: $(kernel_dir)/arch/x86/boot/bzImage | build
cp $< $@
else ifeq ($(CONFIG_LINUXBOOT_KERNEL_UIMAGE),y)
build/target.dtb: $(CONFIG_LINUXBOOT_DTS_FILE)
$(DTC) -o $@ $<
build/uImage: build/vmlinux.bin.lzma build/initramfs build/target.dtb $(LINUX_ARCH-y)/kernel_fdt_lzma.its | build
mkimage -f $(LINUX_ARCH-y)/kernel_fdt_lzma.its $@
endif # CONFIG_LINUXBOOT_KERNEL_BZIMAGE
build:
mkdir build
clean: clean:
rm -rf $(project_dir)/kernel* rm -rf build/kernel*
rm -f $(project_dir)/u-root rm -f build/u-root
rm -f $(project_dir)/initramfs* rm -f build/initramfs*
rm -f $(project_dir)/bzImage rm -f build/bzImage
distclean: distclean:
rm -rf $(project_dir) rm -rf build
.PHONY: linuxboot kernel initramfs_compressed initramfs u-root clean distclean .PHONY: linuxboot clean distclean

View File

@ -11,7 +11,7 @@
images { images {
kernel { kernel {
description = "Vanilla Linux kernel"; description = "Vanilla Linux kernel";
data = /incbin/("vmlinux.bin.lzma"); data = /incbin/("../build/vmlinux.bin.lzma");
type = "kernel"; type = "kernel";
arch = "arm64"; arch = "arm64";
os = "linux"; os = "linux";
@ -30,7 +30,7 @@
}; };
fdt-1 { fdt-1 {
description = "Flattened Device Tree blob"; description = "Flattened Device Tree blob";
data = /incbin/("target.dtb"); data = /incbin/("../build/target.dtb");
type = "flat_dt"; type = "flat_dt";
arch = "arm64"; arch = "arm64";
compression = "none"; compression = "none";
@ -46,7 +46,7 @@
}; };
ramdisk-1 { ramdisk-1 {
description = "Compressed Initramfs"; description = "Compressed Initramfs";
data = /incbin/("initramfs"); data = /incbin/("../build/initramfs");
type = "ramdisk"; type = "ramdisk";
arch = "arm64"; arch = "arm64";
os = "linux"; os = "linux";
@ -65,6 +65,7 @@
configurations { configurations {
default = "conf-1"; default = "conf-1";
conf-1 { conf-1 {
compatible = "linuxboot";
description = "Boot Linux kernel with FDT blob"; description = "Boot Linux kernel with FDT blob";
kernel = "kernel"; kernel = "kernel";
fdt = "fdt-1"; fdt = "fdt-1";

4
payloads/external/LinuxBoot/empty.dts vendored Normal file
View File

@ -0,0 +1,4 @@
/dts-v1/;
/ {
};

View File

@ -0,0 +1,4 @@
CONFIG_ARCH_RV32I=y
CONFIG_32BIT=y
# CONFIG_PORTABLE is not set
CONFIG_NONPORTABLE=y

View File

@ -0,0 +1,2 @@
CONFIG_ARCH_RV64I=y
CONFIG_64BIT=y

View File

@ -0,0 +1,74 @@
/*
* Simple U-Boot uImage source file containing a single kernel and FDT blob
*/
/dts-v1/;
/ {
description = "Simple image with single Linux kernel and FDT blob";
#address-cells = <1>;
images {
kernel {
description = "Vanilla Linux kernel";
data = /incbin/("../build/vmlinux.bin.lzma");
type = "kernel";
arch = "riscv64";
os = "linux";
compression = "lzma";
load = <0x80000>;
entry = <0x80000>;
hash-1 {
algo = "crc32";
};
hash-2 {
algo = "sha1";
};
hash-3 {
algo = "sha256";
};
};
fdt-1 {
description = "Flattened Device Tree blob";
data = /incbin/("../build/target.dtb");
type = "flat_dt";
arch = "riscv64";
compression = "none";
hash-1 {
algo = "crc32";
};
hash-2 {
algo = "sha1";
};
hash-3 {
algo = "sha256";
};
};
ramdisk-1 {
description = "Compressed Initramfs";
data = /incbin/("../build/initramfs");
type = "ramdisk";
arch = "riscv64";
os = "linux";
compression = "none";
load = <00000000>;
entry = <00000000>;
hash-1 {
algo = "sha1";
};
hash-2 {
algo = "sha256";
};
};
};
configurations {
default = "conf-1";
conf-1 {
description = "Boot Linux kernel with FDT blob";
kernel = "kernel";
fdt = "fdt-1";
ramdisk = "ramdisk-1";
};
};
};

View File

@ -1,41 +1,20 @@
## SPDX-License-Identifier: GPL-2.0-only ## SPDX-License-Identifier: GPL-2.0-only
SHELL := /bin/bash SHELL := /bin/sh
ARCH-$(CONFIG_LINUXBOOT_X86_64)=x86_64 OBJCOPY:=$(CONFIG_LINUXBOOT_CROSS_COMPILE)objcopy
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
KERNEL_MAKE_FLAGS = \ KERNEL_MAKE_FLAGS = \
ARCH=$(ARCH-y) \ CROSS_COMPILE=$(CONFIG_LINUXBOOT_CROSS_COMPILE) \
ARCH=$(LINUX_ARCH-y) \
KBUILD_BUILD_USER="coreboot" \ KBUILD_BUILD_USER="coreboot" \
KBUILD_BUILD_HOST="reproducible" \ KBUILD_BUILD_HOST="reproducible" \
KBUILD_BUILD_TIMESTAMP="$(shell perl -e 'print scalar gmtime($(SOURCE_DATE_EPOCH))')" \ KBUILD_BUILD_TIMESTAMP="$(shell perl -e 'print scalar gmtime($(SOURCE_DATE_EPOCH))')" \
KBUILD_BUILD_VERSION="0" KBUILD_BUILD_VERSION="0"
ifeq ($(CONFIG_LINUXBOOT_KERNEL_CUSTOM),y) kernel_version = $(CONFIG_LINUXBOOT_KERNEL_VERSION)
kernel_version:=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION) kernel_dir = build/kernel-$(subst .,_,$(kernel_version))
else kernel_tarball = linux-$(kernel_version).tar
kernel_version:=$(shell curl -sS -k https://www.kernel.org/feeds/kdist.xml | \ kernel_mirror = https://mirrors.edge.kernel.org/pub/linux/kernel
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
ifeq ($(findstring x2.6.,x$(kernel_version)),x2.6.) ifeq ($(findstring x2.6.,x$(kernel_version)),x2.6.)
kernel_mirror_path := $(kernel_mirror)/v2.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 kernel_mirror_path := $(kernel_mirror)/v6.x
endif endif
all: kernel 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";
lookup: $(kernel_dir): build/$(kernel_tarball).xz
ifeq ($(kernel_version),) echo " XZ $(kernel_tarball).xz";
$(error kernel version lookup failed for $(TAG-y) release) mkdir $(kernel_dir);
endif tar xJf build/$(kernel_tarball).xz --strip 1 -C $(kernel_dir);
@echo " WWW Kernel [$(TAG-y)] $(kernel_version)"
fetch: $(kernel_dir)/.config: $(CONFIG_LINUXBOOT_KERNEL_CONFIGFILE) | $(kernel_dir)
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
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)" @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
cp $(ARCH-y)/defconfig $(kernel_dir)/.config
endif
$(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) olddefconfig $(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)" @echo " MAKE Linux $(kernel_version)"
ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y) echo "$(MAKE) -j 4 -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) vmlinux"
$(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) CROSS_COMPILE=$(LINUXBOOT_CROSS_COMPILE) bzImage $(MAKE) -j 4 -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) vmlinux
else
ifeq ($(CONFIG_LINUXBOOT_KERNEL_UIMAGE),y)
$(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) CROSS_COMPILE=$(LINUXBOOT_CROSS_COMPILE) vmlinux
endif
endif
ifeq ($(CONFIG_LINUXBOOT_KERNEL_BZIMAGE),y) build/vmlinux.bin: $(kernel_dir)/vmlinux | build
$(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
$(OBJCOPY) -O binary $< $@ $(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 $< > $@ 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_dir)/arch/x86/boot/bzImage: $(kernel_dir)/.config
kernel: lookup $(top)/$(CONFIG_LINUXBOOT_KERNEL) @echo " MAKE Linux $(kernel_version)"
else echo "$(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) bzImage"
kernel: $(top)/$(CONFIG_LINUXBOOT_KERNEL) $(MAKE) -C $(kernel_dir) $(KERNEL_MAKE_FLAGS) bzImage
endif
.PHONY: all kernel build unpack fetch check .PHONY: kernel

View File

@ -1,29 +1,26 @@
## SPDX-License-Identifier: GPL-2.0-only ## SPDX-License-Identifier: GPL-2.0-only
project_dir=$(shell pwd)/linuxboot uroot_package = github.com/u-root/u-root
go_path_dir=$(project_dir)/go uroot_build = build/go/src/$(uroot_package)
uroot_bin=$(project_dir)/u-root
uroot_package=github.com/u-root/u-root
ARCH-$(CONFIG_LIBUXBOOT_X86_64)=amd64 UROOT_ARCH-$(CONFIG_LIBUXBOOT_X86_64) = amd64
ARCH-$(CONFIG_LINUXBOOT_X86)=i386 UROOT_ARCH-$(CONFIG_LINUXBOOT_X86) = 386
ARCH-$(CONFIG_LINUXBOOT_ARM64)=arm64 UROOT_ARCH-$(CONFIG_LINUXBOOT_ARM64) = arm64
UROOT_ARCH-$(CONFIG_LINUXBOOT_RISCV_RV64) = riscv64
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')
uroot_args+=-build=$(CONFIG_LINUXBOOT_UROOT_FORMAT) uroot_args += -build=$(CONFIG_LINUXBOOT_UROOT_FORMAT)
uroot_args+=-initcmd $(CONFIG_LINUXBOOT_UROOT_INITCMD) uroot_args += -initcmd $(CONFIG_LINUXBOOT_UROOT_INITCMD)
uroot_args+=-uinitcmd=$(CONFIG_LINUXBOOT_UROOT_UINITCMD) uroot_args += -uinitcmd=$(CONFIG_LINUXBOOT_UROOT_UINITCMD)
uroot_args+=-defaultsh $(CONFIG_LINUXBOOT_UROOT_SHELL) uroot_args += -defaultsh $(CONFIG_LINUXBOOT_UROOT_SHELL)
ifneq (CONFIG_LINUXBOOT_UROOT_FILES,) ifneq (CONFIG_LINUXBOOT_UROOT_FILES,)
uroot_args+=$(foreach file,$(CONFIG_LINUXBOOT_UROOT_FILES),-files $(PWD)/$(file)) uroot_args += $(foreach file,$(CONFIG_LINUXBOOT_UROOT_FILES),-files $(PWD)/$(file))
endif endif
uroot_cmds=$(CONFIG_LINUXBOOT_UROOT_COMMANDS) uroot_cmds = $(CONFIG_LINUXBOOT_UROOT_COMMANDS)
all: u-root
version: version:
ifeq ("$(go_version)","") ifeq ("$(go_version)","")
@ -38,27 +35,16 @@ ifeq ($(shell if [ $(go_version_minor) -lt 9 ]; then echo y; fi),y)
endif endif
endif endif
get: version $(uroot_build):
if [ -d "$(go_path_dir)/src/$(uroot_package)" ]; then \ git clone https://$(uroot_package) $(uroot_build)
git -C $(go_path_dir)/src/$(uroot_package) checkout --quiet main; \ git -C $(uroot_build) checkout --quiet $(CONFIG_LINUXBOOT_UROOT_VERSION)
git -C $(go_path_dir)/src/$(uroot_package) pull || \
echo -e "\n<<Pulling u-root package from GitHub failed>>\n"; \
else \
git clone https://${uroot_package} ${go_path_dir}/src/${uroot_package} || \
(echo -e "\n<<Failed to clone u-root package. Please check your internet access>>\n" && \
exit 1); \
fi
checkout: get $(uroot_build)/u-root: $(uroot_build)
git -C $(go_path_dir)/src/$(uroot_package) checkout --quiet $(CONFIG_LINUXBOOT_UROOT_VERSION) cd $(uroot_build); \
go build -o u-root .
build: checkout #$(CONFIG_LINUXBOOT_INITRAMFS_PATH)
cd ${go_path_dir}/src/${uroot_package}; \ build/initramfs_u-root.cpio: $(uroot_build)/u-root
go build -o ${uroot_bin} . GOARCH=$(UROOT_ARCH-y) $(uroot_build)/u-root \
-uroot-source $(uroot_build) \
u-root: build $(uroot_args) -o build/initramfs_u-root.cpio $(uroot_cmds)
GOARCH=$(ARCH-y) $(uroot_bin) \
-uroot-source ${go_path_dir}/src/${uroot_package} \
$(uroot_args) -o $(project_dir)/initramfs_u-root.cpio $(uroot_cmds)
.PHONY: all u-root build checkout get version

View File

@ -26,8 +26,8 @@ ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_COMMAND_LINE))),)
endif endif
ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),) ifneq ($(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))),)
ifneq ($(CONFIG_LINUXBOOT_ARM64),y) ifneq ($(CONFIG_LINUXBOOT_ARM64),y)
ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)$(CONFIG_LINUXBOOT_INITRAMFS)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX)
prebuilt-files += $(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))) prebuilt-files += $(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD)$(CONFIG_LINUXBOOT_INITRAMFS)))
endif endif
endif endif
endif endif
@ -367,41 +367,45 @@ payloads/external/iPXE/ipxe/ipxe.rom ipxe: $(DOTCONFIG) $(PXE_CONFIG_SCRIPT)
MFLAGS= MAKEFLAGS= MFLAGS= MAKEFLAGS=
# LinuxBoot # LinuxBoot
LINUXBOOT_CROSS_COMPILE_ARCH-$(CONFIG_LINUXBOOT_X86) = x86_32
LINUXBOOT_CROSS_COMPILE_ARCH-$(CONFIG_LINUXBOOT_X86_64) = x86_64
LINUXBOOT_CROSS_COMPILE_ARCH-$(CONFIG_LINUXBOOT_ARM) = arm
LINUXBOOT_CROSS_COMPILE_ARCH-$(CONFIG_LINUXBOOT_ARM64) = arm64
LINUXBOOT_CROSS_COMPILE_ARCH-$(CONFIG_LINUXBOOT_RISCV_RV32) = riscv
LINUXBOOT_CROSS_COMPILE_ARCH-$(CONFIG_LINUXBOOT_RISCV_RV64) = riscv
ifeq ($(CONFIG_LINUXBOOT_CROSS_COMPILE),)
CONFIG_LINUXBOOT_CROSS_COMPILE=$(CROSS_COMPILE_$(LINUXBOOT_CROSS_COMPILE_ARCH-y))
endif
.PHONY: linuxboot .PHONY: linuxboot
linuxboot: payloads/external/LinuxBoot/build/Image linuxboot:
$(MAKE) -C payloads/external/LinuxBoot \ $(MAKE) -C payloads/external/LinuxBoot \
CPUS=$(CPUS) \ CPUS=$(CPUS) \
CONFIG_LINUXBOOT_X86_64=$(CONFIG_LINUXBOOT_X86_64) \ CONFIG_LINUXBOOT_X86_64=$(CONFIG_LINUXBOOT_X86_64) \
CONFIG_LINUXBOOT_X86=$(CONFIG_LINUXBOOT_X86) \ CONFIG_LINUXBOOT_X86=$(CONFIG_LINUXBOOT_X86) \
CONFIG_LINUXBOOT_ARM=$(CONFIG_LINUXBOOT_ARM) \
CONFIG_LINUXBOOT_ARM64=$(CONFIG_LINUXBOOT_ARM64) \ CONFIG_LINUXBOOT_ARM64=$(CONFIG_LINUXBOOT_ARM64) \
CONFIG_LINUXBOOT_KERNEL=$(CONFIG_PAYLOAD_FILE) \ CONFIG_LINUXBOOT_RISCV_RV32=$(CONFIG_LINUXBOOT_RISCV_RV32) \
CONFIG_LINUXBOOT_INITRAMFS=$(CONFIG_LINUX_INITRD) \ CONFIG_LINUXBOOT_RISCV_RV64=$(CONFIG_LINUXBOOT_RISCV_RV64) \
CONFIG_LINUXBOOT_INITRAMFS_SUFFIX=$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) \ CONFIG_LINUXBOOT_CROSS_COMPILE=$(CONFIG_LINUXBOOT_CROSS_COMPILE) \
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_MAINLINE=$(CONFIG_LINUXBOOT_KERNEL_MAINLINE) \ CONFIG_LINUXBOOT_INITRAMFS_PATH=$(CONFIG_LINUXBOOT_INITRAMFS_PATH) \
CONFIG_LINUXBOOT_KERNEL_STABLE=$(CONFIG_LINUXBOOT_KERNEL_STABLE) \ CONFIG_LINUXBOOT_INITRAMFS_SUFFIX=$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) \
CONFIG_LINUXBOOT_KERNEL_LONGTERM=$(CONFIG_LINUXBOOT_KERNEL_LONGTERM) \ CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ=$(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ) \
CONFIG_LINUXBOOT_KERNEL_CUSTOM=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM) \ CONFIG_LINUXBOOT_COMPILE_KERNEL=$(CONFIG_LINUXBOOT_COMPILE_KERNEL) \
CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_VERSION) \ CONFIG_LINUXBOOT_KERNEL_PATH=$(CONFIG_LINUXBOOT_KERNEL_PATH) \
CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG=$(CONFIG_LINUXBOOT_KERNEL_CUSTOM_CONFIG) \ CONFIG_LINUXBOOT_KERNEL_VERSION=$(CONFIG_LINUXBOOT_KERNEL_VERSION) \
CONFIG_LINUXBOOT_KERNEL_BZIMAGE=$(CONFIG_LINUXBOOT_KERNEL_BZIMAGE) \ CONFIG_LINUXBOOT_KERNEL_BZIMAGE=$(CONFIG_LINUXBOOT_KERNEL_BZIMAGE) \
CONFIG_LINUXBOOT_KERNEL_UIMAGE=$(CONFIG_LINUXBOOT_KERNEL_UIMAGE) \ 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_UROOT=$(CONFIG_LINUXBOOT_UROOT) \ CONFIG_LINUXBOOT_UROOT=$(CONFIG_LINUXBOOT_UROOT) \
CONFIG_LINUXBOOT_UROOT_VERSION=$(CONFIG_LINUXBOOT_UROOT_VERSION) \ CONFIG_LINUXBOOT_UROOT_VERSION=$(CONFIG_LINUXBOOT_UROOT_VERSION) \
CONFIG_LINUXBOOT_UROOT_FORMAT=$(CONFIG_LINUXBOOT_UROOT_FORMAT) \ CONFIG_LINUXBOOT_UROOT_FORMAT=$(CONFIG_LINUXBOOT_UROOT_FORMAT) \
CONFIG_LINUXBOOT_UROOT_INITCMD=$(CONFIG_LINUXBOOT_UROOT_INITCMD) \ CONFIG_LINUXBOOT_UROOT_INITCMD=$(CONFIG_LINUXBOOT_UROOT_INITCMD) \
CONFIG_LINUXBOOT_UROOT_UINITCMD=$(CONFIG_LINUXBOOT_UROOT_UINITCMD)\ CONFIG_LINUXBOOT_UROOT_UINITCMD=$(CONFIG_LINUXBOOT_UROOT_UINITCMD) \
CONFIG_LINUXBOOT_UROOT_SHELL=$(CONFIG_LINUXBOOT_UROOT_SHELL) \ CONFIG_LINUXBOOT_UROOT_SHELL=$(CONFIG_LINUXBOOT_UROOT_SHELL) \
CONFIG_LINUXBOOT_UROOT_COMMANDS=$(CONFIG_LINUXBOOT_UROOT_COMMANDS) \ CONFIG_LINUXBOOT_UROOT_COMMANDS=$(CONFIG_LINUXBOOT_UROOT_COMMANDS) \
CONFIG_LINUXBOOT_UROOT_FILES=$(CONFIG_LINUXBOOT_UROOT_FILES) \ CONFIG_LINUXBOOT_UROOT_FILES=$(CONFIG_LINUXBOOT_UROOT_FILES) \
CONFIG_LINUXBOOT_DTB_FILE=$(CONFIG_LINUXBOOT_DTB_FILE) CONFIG_LINUXBOOT_DTS_FILE=$(CONFIG_LINUXBOOT_DTS_FILE)
payloads/external/LinuxBoot/linuxboot/bzImage: linuxboot
payloads/external/LinuxBoot/linuxboot/uImage: linuxboot
payloads/external/LinuxBoot/linuxboot/initramfs_u-root.cpio: linuxboot
# BOOTBOOT # BOOTBOOT