From d6743abcc4ed125e8a05225d8806cc92c8e6d094 Mon Sep 17 00:00:00 2001 From: Jean-Marie Verdun Date: Mon, 12 Mar 2018 10:26:23 +0100 Subject: [PATCH 1/6] Refactor config directory content as to add extension capabilities for inserting init script within generated ramfs. Each init script are board file dependant (think kernel drivers auto insertion) --- Makefile | 2 +- boards/{ => kgpe-d16}/kgpe-d16.config | 0 boards/{ => librem13v2}/librem13v2.config | 0 boards/{ => qemu-coreboot}/qemu-coreboot.config | 0 boards/{ => qemu-linuxboot}/qemu-linuxboot.config | 0 boards/{ => r630}/r630.config | 0 boards/{ => s2600wf}/s2600wf.config | 0 boards/{ => winterfell}/winterfell.config | 0 boards/{ => x220}/x220.config | 0 boards/{ => x230-flash}/x230-flash.config | 0 boards/{ => x230}/x230.config | 0 11 files changed, 1 insertion(+), 1 deletion(-) rename boards/{ => kgpe-d16}/kgpe-d16.config (100%) rename boards/{ => librem13v2}/librem13v2.config (100%) rename boards/{ => qemu-coreboot}/qemu-coreboot.config (100%) rename boards/{ => qemu-linuxboot}/qemu-linuxboot.config (100%) rename boards/{ => r630}/r630.config (100%) rename boards/{ => s2600wf}/s2600wf.config (100%) rename boards/{ => winterfell}/winterfell.config (100%) rename boards/{ => x220}/x220.config (100%) rename boards/{ => x230-flash}/x230-flash.config (100%) rename boards/{ => x230}/x230.config (100%) diff --git a/Makefile b/Makefile index e71959c8..6fa3b489 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ INSTALL := $(pwd)/install log_dir := $(build)/log BOARD ?= qemu-coreboot -CONFIG := $(pwd)/boards/$(BOARD).config +CONFIG := $(pwd)/boards/$(BOARD)/$(BOARD).config ifneq "y" "$(shell [ -r '$(CONFIG)' ] && echo y)" $(error $(CONFIG): board configuration does not exist) diff --git a/boards/kgpe-d16.config b/boards/kgpe-d16/kgpe-d16.config similarity index 100% rename from boards/kgpe-d16.config rename to boards/kgpe-d16/kgpe-d16.config diff --git a/boards/librem13v2.config b/boards/librem13v2/librem13v2.config similarity index 100% rename from boards/librem13v2.config rename to boards/librem13v2/librem13v2.config diff --git a/boards/qemu-coreboot.config b/boards/qemu-coreboot/qemu-coreboot.config similarity index 100% rename from boards/qemu-coreboot.config rename to boards/qemu-coreboot/qemu-coreboot.config diff --git a/boards/qemu-linuxboot.config b/boards/qemu-linuxboot/qemu-linuxboot.config similarity index 100% rename from boards/qemu-linuxboot.config rename to boards/qemu-linuxboot/qemu-linuxboot.config diff --git a/boards/r630.config b/boards/r630/r630.config similarity index 100% rename from boards/r630.config rename to boards/r630/r630.config diff --git a/boards/s2600wf.config b/boards/s2600wf/s2600wf.config similarity index 100% rename from boards/s2600wf.config rename to boards/s2600wf/s2600wf.config diff --git a/boards/winterfell.config b/boards/winterfell/winterfell.config similarity index 100% rename from boards/winterfell.config rename to boards/winterfell/winterfell.config diff --git a/boards/x220.config b/boards/x220/x220.config similarity index 100% rename from boards/x220.config rename to boards/x220/x220.config diff --git a/boards/x230-flash.config b/boards/x230-flash/x230-flash.config similarity index 100% rename from boards/x230-flash.config rename to boards/x230-flash/x230-flash.config diff --git a/boards/x230.config b/boards/x230/x230.config similarity index 100% rename from boards/x230.config rename to boards/x230/x230.config From 8e69f8cdbfb35b8947792e037d528bce136680f7 Mon Sep 17 00:00:00 2001 From: Jean-Marie Verdun Date: Mon, 12 Mar 2018 10:28:35 +0100 Subject: [PATCH 2/6] Automatically remove u-root.cpio before compilation. u-root doesn't do that and if the file is soon created, it will dropped the creation of a new initramfs --- modules/u-root | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/u-root b/modules/u-root index 0720a640..73936f22 100644 --- a/modules/u-root +++ b/modules/u-root @@ -7,6 +7,9 @@ u-root_url := github.com/u-root/u-root u-root_output := $(build)/$(BOARD)/u-root.cpio +ifeq ($(shell test -e build/$(BOARD)/u-root.cpio && echo -n yes),yes) +$(shell rm $(build)/$(BOARD)/u-root.cpio) +endif export GOPATH=$(build)/go From 87ae9072b23fb3770a55fd57dec23f1c0bb8b488 Mon Sep 17 00:00:00 2001 From: Jean-Marie Verdun Date: Mon, 12 Mar 2018 14:27:43 +0100 Subject: [PATCH 3/6] Add uinit.go init script for winterfell board. This is setting up the basic storage drivers to boot locally (ATA and NVME) and kick the RSDP --- boards/winterfell/uinit.go | 44 ++++++++++++++++++++++++++++++++++++++ modules/u-root | 11 +++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 boards/winterfell/uinit.go diff --git a/boards/winterfell/uinit.go b/boards/winterfell/uinit.go new file mode 100644 index 00000000..bf1d0767 --- /dev/null +++ b/boards/winterfell/uinit.go @@ -0,0 +1,44 @@ +// Copyright 2012-2017 the u-root Authors. All rights reserved +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This is winterfell init script +package main + +import ( + "log" + "os" + "os/exec" + "strings" +) + +var ( + commands = []string{ + "/bbin/insmod /lib/modules/nvme-core.ko", + "/bbin/insmod /lib/modules/nvme.ko", + "/bbin/insmod /lib/modules/libata.ko", + "/bbin/insmod /lib/modules/libahci.ko", + "/bbin/insmod /lib/modules/ahci.ko", + "/bbin/rsdp", + } +) + +func main() { + for _, line := range commands { + log.Printf("Executing Command: %v", line) + cmdSplit := strings.Split(line, " ") + if len(cmdSplit) == 0 { + continue + } + + cmd := exec.Command(cmdSplit[0], cmdSplit[1:]...) + cmd.Stdin = os.Stdin + cmd.Stderr = os.Stderr + cmd.Stdout = os.Stdout + if err := cmd.Run(); err != nil { + log.Print(err) + } + + } + log.Print("Uinit Done!") +} diff --git a/modules/u-root b/modules/u-root index 73936f22..fc21131b 100644 --- a/modules/u-root +++ b/modules/u-root @@ -7,11 +7,13 @@ u-root_url := github.com/u-root/u-root u-root_output := $(build)/$(BOARD)/u-root.cpio +UROOT_CMDS ?= ifeq ($(shell test -e build/$(BOARD)/u-root.cpio && echo -n yes),yes) $(shell rm $(build)/$(BOARD)/u-root.cpio) endif export GOPATH=$(build)/go +src_cmds := $(foreach cmd,$(UROOT_CMDS),github.com/u-root/u-root/cmds/$(cmd)) $(GOPATH): $(call do,GO GET,$(u-root_url),\ @@ -19,11 +21,18 @@ $(GOPATH): ) $(u-root_output): $(GOPATH) +ifeq ($(shell test -e boards/$(BOARD)/uinit.go && echo -n yes),yes) +ifeq ($(shell (test -d $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit || echo -n yes)),yes) + mkdir $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit +endif + cp boards/$(BOARD)/uinit.go $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit +endif $(call do,U-ROOT,$@,\ $(GOPATH)/bin/u-root \ -build=bb \ -format=cpio \ - -o $@ \ + -o $@ \ + $(src_cmds)\ ) # Override the initrd inputs and add in the kernel modules From 5bad1cc59515e3df17039c4fb8446cd0aaefd1f8 Mon Sep 17 00:00:00 2001 From: Jean-Marie Verdun Date: Mon, 12 Mar 2018 21:31:58 +0100 Subject: [PATCH 4/6] Move u-root.cpio pre-deletion from a global make definition to a "clean" rule --- modules/u-root | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/u-root b/modules/u-root index fc21131b..1c936373 100644 --- a/modules/u-root +++ b/modules/u-root @@ -8,9 +8,6 @@ u-root_url := github.com/u-root/u-root u-root_output := $(build)/$(BOARD)/u-root.cpio UROOT_CMDS ?= -ifeq ($(shell test -e build/$(BOARD)/u-root.cpio && echo -n yes),yes) -$(shell rm $(build)/$(BOARD)/u-root.cpio) -endif export GOPATH=$(build)/go src_cmds := $(foreach cmd,$(UROOT_CMDS),github.com/u-root/u-root/cmds/$(cmd)) @@ -20,7 +17,10 @@ $(GOPATH): go get $(u-root_url) \ ) -$(u-root_output): $(GOPATH) +clean: + rm -f $(build)/$(BOARD)/u-root.cpio + +$(u-root_output): $(GOPATH) clean ifeq ($(shell test -e boards/$(BOARD)/uinit.go && echo -n yes),yes) ifeq ($(shell (test -d $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit || echo -n yes)),yes) mkdir $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit From 6c041ad8458882902ef2029184f558e6db21bf52 Mon Sep 17 00:00:00 2001 From: Trammell hudson Date: Thu, 15 Mar 2018 15:29:36 -0400 Subject: [PATCH 5/6] use the Makefile dependencies to setup the per-board uinit.go file (#358) --- modules/u-root | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/modules/u-root b/modules/u-root index 1c936373..d9d9a695 100644 --- a/modules/u-root +++ b/modules/u-root @@ -4,42 +4,51 @@ # This is not a normal Heads module, since it builds all of its # own dependencies. # - u-root_url := github.com/u-root/u-root u-root_output := $(build)/$(BOARD)/u-root.cpio UROOT_CMDS ?= export GOPATH=$(build)/go -src_cmds := $(foreach cmd,$(UROOT_CMDS),github.com/u-root/u-root/cmds/$(cmd)) +u-root_src_cmds := $(foreach cmd,$(UROOT_CMDS),github.com/u-root/u-root/cmds/$(cmd)) $(GOPATH): $(call do,GO GET,$(u-root_url),\ go get $(u-root_url) \ ) -clean: - rm -f $(build)/$(BOARD)/u-root.cpio +# +# If the board directory has its own go commands, copy them +# into the u-root tree so that they will be bundled into the go initrd +# TODO: generalize this to support more commands +# TODO: fix this sort that it doesn't leave commands lying around +# +ifeq "y" "$(shell [ -r 'boards/$(BOARD)/uinit.go' ] && echo y)" +u-root_uinit := $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit/uinit.go +$(u-root_uinit): boards/$(BOARD)/uinit.go + $(call install,$<,$@) +endif -$(u-root_output): $(GOPATH) clean -ifeq ($(shell test -e boards/$(BOARD)/uinit.go && echo -n yes),yes) -ifeq ($(shell (test -d $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit || echo -n yes)),yes) - mkdir $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit -endif - cp boards/$(BOARD)/uinit.go $(GOPATH)/src/github.com/u-root/u-root/cmds/uinit -endif +$(u-root_output): $(GOPATH) $(u-root_uinit) $(call do,U-ROOT,$@,\ $(GOPATH)/bin/u-root \ -build=bb \ -format=cpio \ -o $@ \ - $(src_cmds)\ + $(u-root_src_cmds)\ ) # Override the initrd inputs and add in the kernel modules initrd-$(CONFIG_UROOT) += $(u-root_output) -# If we are building for u-root, disable the default CONFIG_HEADS ifeq "$(CONFIG_UROOT)" "y" +# If we are building for u-root, disable the default CONFIG_HEADS +# so that the heads/initrd/etc directories will not be included CONFIG_HEADS=n + +# Since we do not include u-root in modules-y, we have to define our +# own intermediate and clean targets here +u-root.intermediate: $(u-root_output) +u-root.clean: + $(RM) $(u-root_output) endif From 514ec6bb29f8866e89a486c82eb5eae01c4fde83 Mon Sep 17 00:00:00 2001 From: Trammell hudson Date: Thu, 15 Mar 2018 15:30:05 -0400 Subject: [PATCH 6/6] reduce the number of tools include in a qemu-linuxboot u-root build so that it fits --- boards/qemu-linuxboot/qemu-linuxboot.config | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/boards/qemu-linuxboot/qemu-linuxboot.config b/boards/qemu-linuxboot/qemu-linuxboot.config index 6c648b7b..09b0ac73 100644 --- a/boards/qemu-linuxboot/qemu-linuxboot.config +++ b/boards/qemu-linuxboot/qemu-linuxboot.config @@ -6,20 +6,21 @@ CONFIG_LINUX_CONFIG=config/linux-linuxboot.config ifeq "$(CONFIG_UROOT)" "y" CONFIG_BUSYBOX=n -endif - +else CONFIG_CRYPTSETUP=y -#CONFIG_FLASHROM=y -CONFIG_FLASHTOOLS=y -CONFIG_GPG=y -CONFIG_KEXEC=y -CONFIG_UTIL_LINUX=y CONFIG_LVM2=y CONFIG_MBEDTLS=y CONFIG_PCIUTILS=y CONFIG_POPT=y CONFIG_QRENCODE=y CONFIG_TPMTOTP=y +endif + +#CONFIG_FLASHROM=y +CONFIG_FLASHTOOLS=y +CONFIG_GPG=y +CONFIG_KEXEC=y +CONFIG_UTIL_LINUX=y CONFIG_DROPBEAR=y #CONFIG_FROTZ=y