From e09edb5d54e39bd9509a1dc450df5ab320759f97 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Fri, 5 Jul 2024 19:38:11 +0300 Subject: allow booting with Qemu's -kernel flag directly + Took some fairly significant changes, for one the kernel is no longer relocated at the start of a boot, instead it sits wherever the user decides the kernel should sit. Similarly, the initial kernel stack and page table are stored within the binary, slightly bloating the size but making it much safer to boot since there's really no chance of us overwriting the fdt or initrd in memory. --- scripts/makefile | 29 +++++------------------------ 1 file changed, 5 insertions(+), 24 deletions(-) (limited to 'scripts/makefile') diff --git a/scripts/makefile b/scripts/makefile index 8c0b5a4..26b33ad 100644 --- a/scripts/makefile +++ b/scripts/makefile @@ -30,7 +30,6 @@ LDFLAGS != [ "$(LLVM)" = "0" ] \ BUILD = build ARCH_KERN_BUILD = $(BUILD)/kernel/arch/$(ARCH) -ARCH_INIT_BUILD = $(BUILD)/init/arch/$(ARCH) ARCH_SOURCE = arch/$(ARCH) all: kmi.bin @@ -80,47 +79,29 @@ KERN_SIZE = wc -c kernel.bin | awk '{print $$1}' KERN_INFO = sed "s//$$($(KERN_SIZE))/" KERNEL_LINK = arch/$(ARCH)/conf/kernel-link.S -INIT_LINK = arch/$(ARCH)/conf/init-link.S KERNEL_LD = build/kernel-link.ld -INIT_LD = build/init-link.ld UBSAN ?= 0 KERN_FLAGS != [ "$(UBSAN)" != "0" ] \ && echo -fsanitize=undefined \ || echo -INIT_FLAGS := -fpic - COMPILE_KERNEL = $(COMPILE) $(KERN_FLAGS) COMPILE_INIT = $(COMPILE) $(INIT_FLAGS) -include deps.mk --include $(KERNEL_LD).d -$(INIT_LD): kernel.bin -$(INIT_LD): $(INIT_LINK) - $(GENLINK) $(INIT_LINK) | $(STRIPLINK) | $(KERN_INFO) > $(INIT_LD) - -include $(KERNEL_LD).d $(KERNEL_LD): $(KERNEL_LINK) $(GENLINK) $(KERNEL_LINK) | $(STRIPLINK) > $(KERNEL_LD) -init.elf: $(INIT_OBJS) $(INIT_LD) - $(GENELF) $(INIT_FLAGS) -T $(INIT_LD) $(INIT_OBJS) -o init.elf $(LINK_FLAGS) - -kernel.elf: $(KERNEL_OBJS) $(KERNEL_LD) - $(GENELF) $(KERNEL_FLAGS) -T $(KERNEL_LD) $(KERNEL_OBJS) -o kernel.elf $(LINK_FLAGS) - -init.bin: init.elf - $(OBJCOPY) $(OBJCOPY_FLAGS) init.elf init.bin - -kernel.bin: kernel.elf - $(OBJCOPY) $(OBJCOPY_FLAGS) kernel.elf kernel.bin +kmi.elf: $(KERNEL_OBJS) $(KERNEL_LD) + $(GENELF) $(KERNEL_FLAGS) -T $(KERNEL_LD) $(KERNEL_OBJS) -o kmi.elf $(LINK_FLAGS) -kmi.bin: init.bin kernel.bin - cat init.bin kernel.bin > kmi.bin +kmi.bin: kmi.elf + $(OBJCOPY) $(OBJCOPY_FLAGS) kmi.elf kmi.bin # might lint some common things twice .PHONY: -lint: $(INIT_LINTS) $(KERNEL_LINTS) +lint: $(KERNEL_LINTS) -- cgit v1.3