Boot is not jumping from UEFI to kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
trilobite
Posts: 2
Joined: Mon Nov 11, 2024 10:06 pm

Boot is not jumping from UEFI to kernel

Post by trilobite »

Hi all -
I'm developing a DOS-like OS based on queso-fuego's uefi-dev code.
( Oh, by the way - that project uses the Limine bootloader but I removed that from my fork as it is MIT-licensed and I wanted the code to be 100% public-domain.
It shouldn't be needed anyway - the UEFI spec doesn't mandate it... :) )

Anyway - the build is succeeding and the boot process starts but the process drops to the UEFI shell.

I'm developing on Linux Mint and using clang compiler.

Here is what the UEFI environment looks like -

Code: Select all

 
UEFI Interactive Shell v2.2
EDK II
UEFI v2.70 (Ubuntu distribution of EDK II, 0x00010000)
Mapping table
     BLK0: Alias(s):
          PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)
     BLK2: Alias(s):
          PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x2,0xFFFF,0x0)
     BLK1: Alias(s):
          PciRoot(0x0)/Pci(0x1F,0x2)/Sata(0x0,0xFFFF,0x0)/HD(1,GPT,00000000-0000-0000-0000-000000000000,0x800,0x1F800)

Press ESC in 1 seconds to skip startup.nsh or any other key to continue.
Shell> 


BLK1 looks to be my HD image but the boot process isn't jumping to it.
My makefile is here -

Code: Select all

 
# ---------------------------------------------------------------------------
#  Sea‑DOS build system  –  Linux + clang, x86‑64, public domain (Unlicense)
# ---------------------------------------------------------------------------

ARCH ?= x86_64
ARCH := $(strip $(ARCH))

# ---- arch guard -----------------------------------------------------------
ifeq ($(filter x86_64 amd64,$(ARCH)),)
$(error Only x86‑64 builds supported; invoke  make ARCH=x86_64)
endif

# ---- locate OVMF firmware -------------------------------------------------
OVMF ?= $(firstword \
        $(wildcard /usr/share/OVMF/OVMF_CODE.fd) \
        $(wildcard /usr/share/ovmf/OVMF.fd) \
        $(wildcard /usr/share/qemu/OVMF.fd))

ifeq ($(OVMF),)
$(warning *** No OVMF firmware image found – pass OVMF=/path/to/OVMF.fd)
endif

# ---- toolchain triples ----------------------------------------------------
EFI_TRIPLE := $(ARCH)-pc-windows-msvc    # PE/COFF
ELF_TRIPLE := $(ARCH)-pc-elf             # freestanding ELF

EFICC       := clang -target $(EFI_TRIPLE)
EFI_LDFLAGS := -nostdlib -fuse-ld=lld-link \
               -Wl,-subsystem:efi_application \
               -Wl,-entry:efi_main

ELFCC       := clang -target $(ELF_TRIPLE)
ELFLD       := ld.lld

CC ?= clang                               # host compiler for helpers

# ---- directories ----------------------------------------------------------
SEA_IMG_DIR := ../sea_img
BUILD_DIR   := ../build
QEMU_SCRIPT := ./qemu_$(ARCH).sh

# -------- create helper dirs (phony, silent) -------------------------------
.PHONY: $(SEA_IMG_DIR) $(BUILD_DIR)
$(SEA_IMG_DIR) $(BUILD_DIR):
	@mkdir -p $@

# ---- disk‑image generator -------------------------------------------------
IMG_SIZE_MIB ?= 64
DISK_IMG_PGM := $(SEA_IMG_DIR)/mkseaimg
SEA_DISK     := $(BUILD_DIR)/sea-dos.img

$(DISK_IMG_PGM): $(SEA_IMG_DIR)/mkseaimg.c | $(SEA_IMG_DIR)
	$(CC) -O2 -static -s -o $@ $<

# ---- sources --------------------------------------------------------------
EFISRC  := efi.c
EFIOBJ  := $(EFISRC:%.c=%_$(ARCH).o)
EFI_APP := BOOTX64.EFI                    # PE32+ output

KERNEL_SRC := kernel.c
KERNEL      := kernel.elf                # ELF64 PIE

FONT := ter-132n.psf                     # bitmap font

# ---- compiler flags -------------------------------------------------------
COMMON_CFLAGS := -std=c17 -Wall -Wextra -Wpedantic -ffreestanding \
                 -mno-red-zone -fno-stack-protector -I include \
                 -DARCH=$(ARCH)

KERNEL_CFLAGS  := $(COMMON_CFLAGS) -fPIE
KERNEL_LDFLAGS := -nostdlib -pie -e kmain

DEPENDS := $(EFIOBJ:.o=.d) $(KERNEL_SRC:.c=.d)

# ---- targets --------------------------------------------------------------
all: $(SEA_DISK)                          # default build

# ----- UEFI application (PE32+)
$(EFI_APP): $(EFIOBJ)
	$(EFICC) $(EFI_LDFLAGS) -o $@ $<

$(EFIOBJ): $(EFISRC)
	$(EFICC) $(COMMON_CFLAGS) -c -o $@ $<

# ----- Kernel (ELF64 PIE)
$(KERNEL): $(KERNEL_SRC)
	$(ELFCC) $(KERNEL_CFLAGS) $(KERNEL_LDFLAGS) -o $@ $<

# ----- Disk image (GPT + FAT32)
$(SEA_DISK): $(DISK_IMG_PGM) $(EFI_APP) $(KERNEL) $(FONT) | $(BUILD_DIR)
	$(DISK_IMG_PGM) -o $@ -s $(IMG_SIZE_MIB) \
	    -ae /EFI/BOOT/$(EFI_APP) $(EFI_APP) \
	    -ad $(KERNEL)   kernel.elf \
	    -ad $(FONT)     $(FONT)
	@echo "Disk image created: $@"

# ----- Launch QEMU
.PHONY: run
run: $(SEA_DISK)
	@if [ -z "$(OVMF)" ]; then \
	    echo "ERROR: OVMF firmware not found.  Pass OVMF=<file>"; exit 1; fi
	$(QEMU_SCRIPT) $(SEA_DISK) $(OVMF)

# ----- clean
.PHONY: clean
clean:
	rm -f $(EFI_APP) $(EFIOBJ) $(KERNEL) *.o *.d *.elf *.EFI *.efi
	rm -f $(SEA_DISK) $(DISK_IMG_PGM)

-include $(DEPENDS)


If anyone wants to try to fix the problem directly, the project is here -
https://github.com/mooseman/Sea-DOS

If you clone that, go into the /Sea-DOS/efi_c directory and run this command -
make run OVMF=/usr/share/OVMF/OVMF_CODE_4M.fd

It just seems that I'm *so close* to getting things to boot so if anyone is able to help out with this problem, that'd be hugely appreciated!
Many thanks in advance -
- trilobite
Last edited by xenos on Sat May 03, 2025 10:42 pm, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5805
Joined: Mon Mar 25, 2013 7:01 pm

Re: Boot is not jumping from UEFI to kernel

Post by Octocontrabass »

trilobite wrote: Sat May 03, 2025 4:36 pmHere is what the UEFI environment looks like -
It looks like OVMF can't find any filesystems on your disk image.

Try using QEMU's built-in disk image generator and see if it makes a difference.
User avatar
zaval
Member
Member
Posts: 673
Joined: Fri Feb 17, 2017 4:01 pm
Location: Ukraine, Bachmut
Contact:

Re: Boot is not jumping from UEFI to kernel

Post by zaval »

Octocontrabas is as always correct, you don't have any FAT volume on your disks you attached to your VM. Plus, look at the GUID of your blk1 partition, it's "invalid GUID", all 0s. Make a virtual disk of your liking, partition it with either MBR or GPT scheme and create at least one partition on it. Format the partition as FAT and put there your .efi image(s). Preferably under efi\<YourOrganizationName>\<YourLoaderNane>.efi After having done so, you'll get an fs0 volume, in that list and you could be able to launch your executable e.g. from the shell by typing:

fs0:\efi\<YourOrganizationName>\<YourLoaderName>.efi

Or via a script or from UEFI Boot Manager's "Boot from file" special load option.
ANT - NT-like OS for x64 and arm64.
efify - UEFI for a couple of boards (mips and arm). suspended due to lost of all the target park boards (russians destroyed our town).
trilobite
Posts: 2
Joined: Mon Nov 11, 2024 10:06 pm

Re: Boot is not jumping from UEFI to kernel

Post by trilobite »

Hi Octocontabass and Zaval - thanks for your replies!

Sounds good! Many thanks for the fix that you've given!
I'll try that out and will go from there!

Cheers - thanks again -
trilobite
Post Reply