LinuxBoot: refactor u-root.mk

Clean the u-root initramfs integration and add essential flags as options.
Now u-root automatically fetch updates and rebuilts itself to apply changes.

Change-Id: Id978ed2ebeff96c5be4f74ae07df9be76e106a1b
Signed-off-by: Marcello Sylvester Bauer <info@marcellobauer.com>
Reviewed-on: https://review.coreboot.org/c/29778
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-11-21 17:45:43 +01:00 committed by Philipp Deppenwiese
parent 78d0256f1d
commit e102c5d54b
5 changed files with 130 additions and 72 deletions

View File

@ -127,6 +127,7 @@ config LINUXBOOT_UROOT
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.
endchoice endchoice
if LINUXBOOT_UROOT if LINUXBOOT_UROOT
@ -135,37 +136,109 @@ choice
prompt "U-root version" prompt "U-root version"
default LINUXBOOT_UROOT_MASTER default LINUXBOOT_UROOT_MASTER
config LINUXBOOT_UROOT_CUSTOM
bool "custom"
help
choose a custom u-root branch
config LINUXBOOT_UROOT_MASTER config LINUXBOOT_UROOT_MASTER
bool "master" bool "master"
help help
Latest u-root version Latest u-root version
config LINUXBOOT_UROOT_V3_0_0
bool "v3.0.0"
config LINUXBOOT_UROOT_V2_0_0
bool "v2.0.0"
config LINUXBOOT_UROOT_V1_0_0
bool "v1.0.0"
endchoice endchoice
config LINUXBOOT_UROOT_CHECKOUT
string "U-root custom branch"
depends on LINUXBOOT_UROOT_CUSTOM
config LINUXBOOT_UROOT_VERSION config LINUXBOOT_UROOT_VERSION
string string
default LINUXBOOT_UROOT_CHECKOUT if LINUXBOOT_UROOT_CUSTOM
default "master" if LINUXBOOT_UROOT_MASTER default "master" if LINUXBOOT_UROOT_MASTER
default "v3.0.0" if LINUXBOOT_UROOT_V3_0_0
default "v2.0.0" if LINUXBOOT_UROOT_V2_0_0
default "v1.0.0" if LINUXBOOT_UROOT_V1_0_0
config LINUXBOOT_UROOT_COMMANDS choice
string "Select u-root commands" prompt "Build format"
default "" default LINUXBOOT_UROOT_BB
help help
List of additional modules to include, separated by space. Otherwise u-root build format (e.g. bb or source). (default "bb")
all modules of u-root are included.
config LINUXBOOT_UROOT_BB
bool "bb"
config LINUXBOOT_UROOT_SOURCE
bool "source (experimental)"
endchoice
config LINUXBOOT_UROOT_FORMAT
string
default "bb" if LINUXBOOT_UROOT_BB
default "source" if LINUXBOOT_UROOT_SOURCE
config LINUXBOOT_UROOT_FILES config LINUXBOOT_UROOT_FILES
string "Add files to u-root base" string "Add files to u-root base"
default ""
help help
Path to directory containing root structure for embedding into the Additional files, directories, and binaries (with their ldd dependencies) to add to archive.
initramfs. Can be speficified multiple times.
config LINUXBOOT_UROOT_INITCMD
string "Init target"
default "init"
help
Symlink target for /init.
Can be an absolute path or a u-root command name. (default "init")
config LINUXBOOT_UROOT_SHELL
string "default shell"
default "elvish"
help
Default shell.
Can be an absolute path or a u-root command name. (default "elvish")
config LINUXBOOT_UROOT_COMMANDS
string "U-root commands"
default "coreboot-app"
help
List of additional modules to include,
separated by space. (default "coreboot-app")
endif #LINUXBOOT_UROOT endif #LINUXBOOT_UROOT
endif #LINUXBOOT_BUILD_INITRAMFS endif #LINUXBOOT_BUILD_INITRAMFS
choice LINUXBOOT_INITRAMFS_COMPRESSION
prompt "Initramfs compression format"
default LINUXBOOT_INITRAMFS_COMPRESSION_XZ
config LINUXBOOT_INITRAMFS_COMPRESSION_NONE
bool "none"
config LINUXBOOT_INITRAMFS_COMPRESSION_XZ
bool "xz compression"
endchoice
config LINUX_INITRD config LINUX_INITRD
string string
default "payloads/external/LinuxBoot/linuxboot/initramfs_u-root.cpio.xz" if LINUXBOOT_UROOT default "payloads/external/LinuxBoot/linuxboot/initramfs_u-root.cpio" if LINUXBOOT_UROOT
default LINUXBOOT_INITRAMFS_PATH if !LINUXBOOT_BUILD_INITRAMFS default LINUXBOOT_INITRAMFS_PATH if !LINUXBOOT_BUILD_INITRAMFS
config LINUXBOOT_INITRAMFS_SUFFIX
string
default "" if LINUXBOOT_INITRAMFS_COMPRESSION_NONE
default ".xz" if LINUXBOOT_INITRAMFS_COMPRESSION_XZ
endif #PAYLOAD_LINUXBOOT endif #PAYLOAD_LINUXBOOT

View File

@ -17,7 +17,6 @@ project_dir=linuxboot
kernel_dir=$(project_dir)/kernel kernel_dir=$(project_dir)/kernel
unexport $(COREBOOT_EXPORTS) unexport $(COREBOOT_EXPORTS)
unexport MAKEFLAGS
all: linuxboot all: linuxboot
@ -38,6 +37,11 @@ initramfs:
endif endif
endif endif
initramfs_compressed: initramfs
ifeq ($(CONFIG_LINUXBOOT_INITRAMFS_COMPRESSION_XZ),y)
xz --keep --force --lzma2=dict=1MiB $(top)/$(CONFIG_LINUXBOOT_INITRAMFS)
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
@ -54,13 +58,14 @@ kernel:
fi fi
endif endif
linuxboot: kernel initramfs linuxboot: kernel initramfs_compressed
clean: clean:
if [ -d "$(kernel_dir)" ]; then rm -rf $(kernel_dir); fi if [ -d "$(kernel_dir)" ]; then rm -rf $(kernel_dir); fi
rm -f $(project_dir)/initramfs.cpio.xz rm -f $(project_dir)/u-root
rm -f $(project_dir)/initramfs*
distclean: distclean:
rm -rf $(project_dir) rm -rf $(project_dir)
.PHONY: linuxboot kernel initramfs u-root clean distclean .PHONY: linuxboot kernel initramfs_compressed initramfs u-root clean distclean

View File

@ -82,7 +82,7 @@ $(project_dir)/vmlinux.bin.lzma: $(project_dir)/vmlinux.bin
$(project_dir)/uImage: $(project_dir)/vmlinux.bin.lzma $(project_dir)/../arm64/kernel_fdt_lzma.its $(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) $(project_dir)/u-initramfs cp $(PWD)/$(CONFIG_LINUXBOOT_INITRAMFS)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX) $(project_dir)/u-initramfs
mkimage -f $(project_dir)/kernel_fdt_lzma.its $@ mkimage -f $(project_dir)/kernel_fdt_lzma.its $@
endif endif

View File

@ -13,19 +13,27 @@
## GNU General Public License for more details. ## GNU General Public License for more details.
## ##
uroot_git_repo=https://github.com/u-root/u-root.git project_dir=$(shell pwd)/linuxboot
uroot_dir=$(project_dir)/go/src/github.com/u-root/u-root go_path_dir=$(project_dir)/go
uroot_bin=$(project_dir)/u-root
uroot_package=github.com/u-root/u-root
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')
project_dir=$(shell pwd)/linuxboot uroot_args+=-build=$(CONFIG_LINUXBOOT_UROOT_FORMAT)
project_name=u-root uroot_args+=-initcmd $(CONFIG_LINUXBOOT_UROOT_INITCMD)
go_path_dir=$(shell pwd)/linuxboot/go uroot_args+=-defaultsh $(CONFIG_LINUXBOOT_UROOT_SHELL)
ifneq (CONFIG_LINUXBOOT_UROOT_FILES,)
uroot_args+=$(foreach file,$(CONFIG_LINUXBOOT_UROOT_FILES),-files $(PWD)/$(file))
endif
uroot_cmds=$(CONFIG_LINUXBOOT_UROOT_COMMANDS)
all: u-root all: u-root
check: version:
ifeq ("$(go_version)","") ifeq ("$(go_version)","")
printf "\n<<Please install Golang >= 1.9 for u-root mode>>\n\n" printf "\n<<Please install Golang >= 1.9 for u-root mode>>\n\n"
exit 1 exit 1
@ -37,59 +45,26 @@ ifeq ($(shell if [ $(go_version_minor) -lt 9 ]; then echo y; fi),y)
exit 1 exit 1
endif endif
endif endif
mkdir -p $(project_dir)/go/src/github.com/u-root
$(uroot_dir)/.git: get: version
echo " Git Cloning u-root $(CONFIG_LINUXBOOT_UROOT_VERSION)" if [ -d "$(go_path_dir)/src/$(uroot_package)" ]; then \
git clone $(uroot_git_repo) $(uroot_dir) git -C $(go_path_dir)/src/$(uroot_package) checkout --quiet master; \
GOPATH=$(go_path_dir) go get -d -u -v $(uroot_package) || \
fetch: check $(uroot_dir)/.git echo -e "\n<<u-root package update failed>>\n"; \
-cd "$(uroot_dir)" && git fetch origin else \
GOPATH=$(go_path_dir) go get -d -u -v $(uroot_package) || \
checkout: fetch (echo -e "\n<<failed to get u-root package. Please check your internet access>>\n" && \
cd "$(uroot_dir)" && \ exit 1); \
if ! git diff --quiet _cb_checkout "$(CONFIG_LINUXBOOT_UROOT_VERSION)" -- 2>/dev/null; \
then \
printf " CHECKOUT $(project_name) [$(CONFIG_LINUXBOOT_UROOT_VERSION)]\n"; \
git checkout $$(git rev-parse HEAD) >/dev/null 2>&1; \
git branch -f _cb_checkout "$(CONFIG_LINUXBOOT_UROOT_VERSION)" && \
git checkout _cb_checkout && \
$(if $(project_patches), \
for patch in $(project_patches); do \
printf " PATCH $$patch\n"; \
git am --keep-cr "$$patch" || \
( printf "Error when applying patches.\n"; \
git am --abort; exit 1; ); \
done;,true;) \
fi fi
$(uroot_dir)/u-root: $(uroot_dir)/u-root.go checkout: get
echo " GO u-root" git -C $(go_path_dir)/src/$(uroot_package) checkout --quiet $(CONFIG_LINUXBOOT_UROOT_VERSION)
cd $(uroot_dir); GOPATH=$(go_path_dir) go build u-root.go
$(project_dir)/initramfs_u-root.cpio.xz: checkout $(uroot_dir)/u-root build: checkout
echo " MAKE u-root $(CONFIG_LINUXBOOT_UROOT_VERSION)" GOPATH=$(go_path_dir) go build -o $(uroot_bin) $(uroot_package)
ifneq ($(CONFIG_LINUXBOOT_UROOT_COMMANDS),)
ifneq ($(CONFIG_LINUXBOOT_UROOT_FILES),)
cd $(uroot_dir); GOARCH=$(CONFIG_LINUXBOOT_ARCH) GOPATH=$(go_path_dir) ./u-root \
-build=bb -files $(CONFIG_LINUXBOOT_UROOT_FILES) -o $(project_dir)/initramfs_u-root.cpio \
$(patsubst %,cmds/%,$(CONFIG_LINUXBOOT_UROOT_COMMANDS))
else
cd $(uroot_dir); GOARCH=$(CONFIG_LINUXBOOT_ARCH) GOPATH=$(go_path_dir) ./u-root \
-build=bb -o $(project_dir)/initramfs_u-root.cpio \
$(patsubst %,cmds/%,$(CONFIG_LINUXBOOT_UROOT_COMMANDS))
endif
else
ifneq ($(CONFIG_LINUXBOOT_UROOT_FILES),)
cd $(uroot_dir); GOARCH=$(CONFIG_LINUXBOOT_ARCH) GOPATH=$(go_path_dir) ./u-root \
-build=bb -files $(CONFIG_LINUXBOOT_UROOT_FILES) -o $(project_dir)/initramfs_u-root.cpio coreboot-app
else
cd $(uroot_dir); GOARCH=$(CONFIG_LINUXBOOT_ARCH) GOPATH=$(go_path_dir) ./u-root \
-build=bb -o $(project_dir)/initramfs_u-root.cpio coreboot-app
endif
endif
xz -f --check=crc32 -9 --lzma2=dict=1MiB --threads=$(CPUS) $(project_dir)/initramfs_u-root.cpio
u-root: $(project_dir)/initramfs_u-root.cpio.xz u-root: build
GOARCH=$(CONFIG_LINUXBOOT_ARCH) GOPATH=$(go_path_dir) $(uroot_bin) \
$(uroot_args) -o $(project_dir)/initramfs_u-root.cpio $(uroot_cmds)
.PHONY: u-root checkout fetch all check .PHONY: all u-root build checkout get version

View File

@ -38,7 +38,7 @@ 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) ADDITIONAL_PAYLOAD_CONFIG+=-I $(CONFIG_LINUX_INITRD)$(CONFIG_LINUXBOOT_INITRAMFS_SUFFIX)
prebuilt-files += $(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD))) prebuilt-files += $(strip $(call strip_quotes,$(CONFIG_LINUX_INITRD)))
endif endif
endif endif
@ -262,19 +262,24 @@ linuxboot:
CONFIG_LINUXBOOT_ARCH=$(CONFIG_LINUXBOOT_ARCH) \ CONFIG_LINUXBOOT_ARCH=$(CONFIG_LINUXBOOT_ARCH) \
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_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_VERSION=$(CONFIG_LINUXBOOT_KERNEL_VERSION) \
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_INITCMD=$(CONFIG_LINUXBOOT_UROOT_INITCMD) \
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_DTB_FILE=$(CONFIG_LINUXBOOT_DTB_FILE)
payloads/external/LinuxBoot/linuxboot/bzImage: linuxboot payloads/external/LinuxBoot/linuxboot/bzImage: linuxboot
payloads/external/LinuxBoot/linuxboot/uImage: linuxboot payloads/external/LinuxBoot/linuxboot/uImage: linuxboot
payloads/external/LinuxBoot/linuxboot/initramfs_u-root.cpio.xz: linuxboot payloads/external/LinuxBoot/linuxboot/initramfs_u-root.cpio: linuxboot
# Yabits # Yabits