From 228b68ce5b7405b3bda609645a90da309e465798 Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Sun, 25 Feb 2024 19:52:13 -0800 Subject: [PATCH 1/4] Added u-boot submodule --- .gitmodules | 3 +++ u-boot | 1 + 2 files changed, 4 insertions(+) create mode 160000 u-boot diff --git a/.gitmodules b/.gitmodules index 7eab220..7159958 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ path = linux url = https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ branch = master +[submodule "u-boot"] + path = u-boot + url = https://github.com/u-boot/u-boot diff --git a/u-boot b/u-boot new file mode 160000 index 0000000..1a66a77 --- /dev/null +++ b/u-boot @@ -0,0 +1 @@ +Subproject commit 1a66a7768af7e8106c2cd93a19f4013877fb85ae From e282e27cce03682c7fd22f6128572bee06d7f402 Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Sun, 25 Feb 2024 19:52:46 -0800 Subject: [PATCH 2/4] Add u-boot build targets --- Makefile | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Makefile b/Makefile index 0e19731..1a16217 100644 --- a/Makefile +++ b/Makefile @@ -341,6 +341,46 @@ rootfs_clean: $(SUDO) rm -f $(CPIO_FILE) $(SUDO) rm -f $(ROOTFS) +## +## U-Boot +## + +# Note: We're reusing the TARGET variable from the Linux build section + +UBOOT_SRC := $(ROOT_DIR)/u-boot +UBOOT_OUT := $(OUT_DIR)/uboot/$(ARCH) +UBOOT_CONFIG := $(UBOOT_OUT)/.config +UBOOT_BIN := $(UBOOT_OUT)/u-boot.bin + +ifeq ($(ARCH),x86_64) + UBOOT_DEFCONFIG=qemu-x86_64_defconfig +else ifeq ($(ARCH),i386) + UBOOT_DEFCONFIG=qemu-x86_defconfig +else ifeq ($(ARCH),arm64) + UBOOT_DEFCONFIG=qemu_arm64_defconfig +endif + +UBOOT_MAKE := \ + PATH=$(CLANG_DIR)/bin:$(PATH) \ + $(MAKE) \ + -C $(UBOOT_SRC) \ + HOSTCC=clang \ + O=$(UBOOT_OUT) \ + -j `nproc` + +.PHONY: uboot_defconfig +uboot_defconfig $(UBOOT_CONFIG): | $(CLANG_DIR) + + $(UBOOT_MAKE) $(UBOOT_DEFCONFIG) + +.PHONY: uboot +uboot $(UBOOT_BIN): $(UBOOT_CONFIG) | $(CLANG_DIR) + + $(UBOOT_MAKE) CROSS_COMPILE=$(TARGET)- CC=clang + cd $(UBOOT_SRC) && ./scripts/gen_compile_commands.py -d $(UBOOT_OUT) + +.PHONY: uboot_clean +uboot_clean: + + $(UBOOT_MAKE) mrproper + ## ## Run QEMU ## From 7bdb8ef1c2c27c866b04f83e81be5f015c1aa423 Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Sun, 25 Feb 2024 19:53:42 -0800 Subject: [PATCH 3/4] Run qemu with u-boot depending on UBOOT flag --- Makefile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Makefile b/Makefile index 1a16217..d62fa03 100644 --- a/Makefile +++ b/Makefile @@ -397,6 +397,7 @@ ECHR ?= 1 ROOT ?= /dev/vda RW ?= rw KASLR ?= 0 +UBOOT ?= 0 QEMU_KERNEL_CMDLINE := selinux=0 @@ -411,6 +412,10 @@ QEMU_ARGS := \ -echr $(ECHR) \ $(QEMU_EXTRA_ARGS) +ifeq ($(UBOOT),1) + QEMU_ARGS += -bios $(UBOOT_BIN) +endif + ifneq ($(INITRD),) ifeq ($(INITRD),1) INITRD := $(CPIO_FILE) @@ -456,6 +461,9 @@ endif QEMU_ARGS += -append "$(QEMU_KERNEL_CMDLINE) $(QEMU_EXTRA_KERNEL_CMDLINE)" RUN_DEPS := $(QEMU_KERNEL_IMAGE) +ifeq ($(UBOOT),1) + RUN_DEPS += $(UBOOT_BIN) +endif .PHONY: run run: $(RUN_DEPS) | $(SHARED_DIR) From 01131da4ce08de65d2e1009c8aa57a412c75c07c Mon Sep 17 00:00:00 2001 From: Gulshan Singh Date: Sun, 25 Feb 2024 19:55:20 -0800 Subject: [PATCH 4/4] Make some u-boot variables configurable --- Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index d62fa03..548b37d 100644 --- a/Makefile +++ b/Makefile @@ -347,17 +347,17 @@ rootfs_clean: # Note: We're reusing the TARGET variable from the Linux build section -UBOOT_SRC := $(ROOT_DIR)/u-boot -UBOOT_OUT := $(OUT_DIR)/uboot/$(ARCH) +UBOOT_SRC ?= $(ROOT_DIR)/u-boot +UBOOT_OUT ?= $(OUT_DIR)/uboot/$(ARCH) UBOOT_CONFIG := $(UBOOT_OUT)/.config UBOOT_BIN := $(UBOOT_OUT)/u-boot.bin ifeq ($(ARCH),x86_64) - UBOOT_DEFCONFIG=qemu-x86_64_defconfig + UBOOT_DEFCONFIG ?= qemu-x86_64_defconfig else ifeq ($(ARCH),i386) - UBOOT_DEFCONFIG=qemu-x86_defconfig + UBOOT_DEFCONFIG ?= qemu-x86_defconfig else ifeq ($(ARCH),arm64) - UBOOT_DEFCONFIG=qemu_arm64_defconfig + UBOOT_DEFCONFIG ?= qemu_arm64_defconfig endif UBOOT_MAKE := \