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/Makefile b/Makefile index 0e19731..548b37d 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 ## @@ -357,6 +397,7 @@ ECHR ?= 1 ROOT ?= /dev/vda RW ?= rw KASLR ?= 0 +UBOOT ?= 0 QEMU_KERNEL_CMDLINE := selinux=0 @@ -371,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) @@ -416,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) 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