Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions docs/CLEANUP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Cleanup and migration notes for efi-rework branch

This branch (efi-rework) is the start of the migration from a GRUB/Multiboot2
boot model to a UEFI/EFI-based boot model, and a platform cleanup to focus on
64-bit, EFI-capable architectures.

What has been done in this commit set (cleanups are incremental):
- Replaced the active grub.cfg with a note indicating GRUB is removed on this branch.
- Converted qemu run scripts to call qemu-system-x86_64 with OVMF (UEFI) firmware.
- Added this CLEANUP.md to summarise the planned migration steps in the branch.

Planned follow-up steps (next commits on this branch):
1) Remove multiboot-specific boot sources or move them to a legacy area.
2) Add an EFI loader (small UEFI PE/COFF stub) and build rules to produce BOOTX64.EFI,
BOOTAA64.EFI, and (best-effort) BOOTRISCV64.EFI.
3) Remove 32-bit platform build targets and scripts (i386, arm, riscv32).
4) Remove PowerPC platform sources and references entirely (per your instruction).
5) Update Makefile and CI to build and test x86_64, aarch64, and riscv64 only.
6) Update README and Getting Started with EFI build/run instructions.

Notes about deletion of PowerPC sources:
- You chose to delete PowerPC sources. To avoid accidental data loss during
the migration, I will remove them in a dedicated commit so the change is
reviewable and reversible via Git history if necessary. Expect that commit
next.

Security & tooling:
- EFI binaries created here will be unsigned — Secure Boot will need to be
disabled on test hardware or VMs.
- Later we can integrate GNU-EFI or EDK2 if you want a more full-featured UEFI
build chain; for now the plan is a minimal custom EFI stub to get booting.

If anything above needs to be adjusted (for example you change your mind about
keeping PPC in legacy/, or you want EDK2 integration immediately), tell me and
I will adapt the plan.
37 changes: 37 additions & 0 deletions docs/EFI_GETTING_STARTED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# EFI Quick Start (branch: efi-rework)

This is a short, temporary getting-started guide for the efi-rework branch.
The repo is being migrated to EFI boot images and 64-bit-only targets. Use
this guide to run the tree once the EFI image is available.

Prerequisites (development machine):
- GCC/clang for building the kernel for the target architecture(s)
- QEMU with support for the required architectures: qemu-system-x86_64,
qemu-system-aarch64, qemu-system-riscv64 (as applicable)
- OVMF (UEFI firmware for QEMU) installed (package usually named 'ovmf')

Testing with QEMU (x86_64 example):
1) Build the kernel for x86_64 (TBD: new Makefile entries will be added on this branch).
2) Create an EFI FAT image with an EFI payload at EFI/BOOT/BOOTX64.EFI.
Example (local testing):

# Create an empty 32M image and format as FAT
dd if=/dev/zero of=efiboot.img bs=1M count=32
mkfs.vfat efiboot.img

# Mount and copy EFI payload (requires root)
mkdir -p /mnt/efi
sudo mount -o loop efiboot.img /mnt/efi
sudo mkdir -p /mnt/efi/EFI/BOOT
sudo cp BOOTX64.EFI /mnt/efi/EFI/BOOT/
sudo umount /mnt/efi

3) Boot with QEMU + OVMF:
qemu-system-x86_64 -bios /usr/share/ovmf/OVMF_CODE.fd -drive file=efiboot.img,format=raw -m 1024 -serial stdio

Notes:
- Secure Boot: unsigned EFI apps will not load with Secure Boot enabled. Disable
Secure Boot in the VM/firmware for testing.
- Kernel integration: the tree currently expects multiboot entry points in a
few locations; I will add a compatibility shim so the kernel can be launched
from the EFI loader. That work will be added in a follow-up commit.
94 changes: 94 additions & 0 deletions docs/HANDOFF_DEEPSEEK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
HANDOFF for Deepseek

Repository: kramlat/LazarusOS
Branch: efi-rework

Context / Goal
- Implement EFI loader + toolkit ROM plumbing so the emulated legacy toolkits (PPC, 68k) and modern LE toolkits (x86_64, aarch64, riscv64) are loaded from the ESP and exposed to the kernel/emulator via a BootInfo handoff.
- PRAM persistence: chosen strategy A — kernel writes PRAM to UEFI variable on shutdown. Loader reads UEFI variable LazarusOS:PRAM if present, otherwise falls back to PRAM.BIN on ESP and exposes pram_addr/pram_size in BootInfo.

What’s already done (on efi-rework)
- UTF-8 name groundwork and OSType helpers: src/FS/ostype_utils.c, include/FS/ostype_utils.h
- VFS + CatEntry change to store printable creator/type strings (include/FS/hfs_types.h and vfs changes)
- EFI loader: blessed-folder heuristics with icon detection and Finder scan: src/Platform/efi/efi_loader.c
- Placeholder clean-room toolkit sources for PPC and 68k: src/Toolkit/ppc/toolkit.c and src/Toolkit/68k/toolkit.c
- Build & ESP scripts to create placeholder ROM blobs and FAT image: scripts/build_toolkits.sh and scripts/make_esp_with_toolkits.sh
- Toolkit placeholder blobs are output to out/toolkits via the build scripts (not tracked as large binaries in repo)

Key files / pointers
- Loader: src/Platform/efi/efi_loader.c
- HFS / VFS types + name handling: include/FS/hfs_types.h, include/FS/vfs.h, src/FS/vfs.c
- OSType helpers: include/FS/ostype_utils.h, src/FS/ostype_utils.c
- Toolkits (placeholders): src/Toolkit/ppc/toolkit.c, src/Toolkit/68k/toolkit.c
- Scripts to reproduce: scripts/build_toolkits.sh, scripts/make_esp_with_toolkits.sh
- Toolkits output (after running build scripts): out/toolkits/

Commands to reproduce locally (smoke test)
1) Build placeholder toolkits (may require cross compilers):
./scripts/build_toolkits.sh

2) Create FAT ESP image with placeholders:
./scripts/make_esp_with_toolkits.sh

3) Boot in QEMU (example x86_64):
qemu-system-x86_64 -bios OVMF.fd -drive file=out/esp.img,format=raw -serial stdio

4) Observe EFI loader serial output: look for messages like "Blessed check passed" and which toolkit file was loaded.

Remaining prioritized tasks for Deepseek (highest -> lowest)
1) Produce LE toolkit ROM blobs and source stubs
- Add clean-room LE toolkit sources (x86_64, aarch64, riscv64) exposing a small Gestalt surface.
- Add build rules to create TOOLKIT_X86_64.ROM, TOOLKIT_AARCH64.ROM, TOOLKIT_RISCV64.ROM and place them under out/toolkits.
- Update scripts/build_toolkits.sh to build these when cross toolchains are present.
Estimated: 1–3 hours.

2) BootInfo wiring & per-arch mapping
- Ensure loader maps chosen toolkit into page-aligned memory and fills BootInfo with per-arch toolkit_addr/toolkit_size, pram_addr/pram_size, and flags.
- Pass BootInfo pointer in the ABI entry register per arch:
x86_64: RDI
aarch64: X0
riscv64: a0
ppc: r3
68k emulation: A0 (emulator reads it)
- Document BootInfo struct layout in include/Platform/bootinfo.h.
Estimated: 2–4 hours.

3) PRAM persistence handoff (kernel-side)
- Provide a small example kernel stub showing how to read BootInfo and write PRAM via UEFI RuntimeServices->SetVariable prior to ExitBootServices. The loader will only read PRAM; kernel handles write-back on shutdown.
Estimated: 1–2 hours.

4) Kernel/emulator consumer
- Integrate a BootInfo consumer in the kernel/emulator to map the toolkit region and expose trap/Gestalt dispatch to legacy apps.
- Implement minimal PRAM accessors and register the toolkit base for trap table lookups.
Estimated: variable; initial example stub 1–2 hours; fuller integration more.

5) Tests & validation
- Add QEMU smoke tests and unit tests for BootInfo parsing and toolkit mapping.
- Attempt to run a small legacy test program in the emulator against the clean-room toolkit to validate basic Gestalt/trap behavior.

Notes, constraints, and caveats
- No Apple proprietary code: toolkits must be clean-room; do NOT add any Apple ROMs to the repo. Placeholders are included for development; replace with your own lawful binaries if you have them.
- Endianness: PPC and 68k toolkits are BE. x86_64, aarch64, riscv64 toolkits are LE.
- PRAM variable name: LazarusOS:PRAM (UEFI variable). The loader reads it (if present); kernel writes it on shutdown.
- BootInfo ABI: prefer register-based pointer handoff (clean per-ABI). If you need a fixed address, we can change later.

Useful quick checklist for Deepseek
- [ ] Add LE toolkit sources + build rules
- [ ] Extend scripts to build LE blobs and include them in ESP image
- [ ] Implement BootInfo struct header and fill/hand off in efi_loader.c
- [ ] Add small kernel example demonstrating PRAM write via SetVariable
- [ ] Run smoke test in QEMU and verify loader output

Troubleshooting tips
- If the loader doesn't find toolkits, check the FAT image contents (mount or unzip esp_contents/ before image creation).
- Cross-compilers: building PPC/68k toolkits requires powerpc/68k cross-toolchains; scripts will produce zero-filled placeholders if compilers are absent.
- EFI runtime variables may be restricted by the environment; in QEMU+OVMF SetVariable should work by default.

If you want, I will now:
- push this HANDOFF file to efi-rework (done),
- implement step #1 (LE toolkits) and #2 (BootInfo wiring) immediately and open a PR, or
- wait and let Deepseek pick up the tasks.

Contact & context
- I pushed the earlier placeholder commits (toolkits + scripts) on branch efi-rework. Deepseek should start from that branch and follow the checklist above.

13 changes: 13 additions & 0 deletions docs/TOOLKIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
TOOLKIT design doc

We include placeholder, clean-room toolkit ROMs for PPC and 68k to provide a legacy Toolbox surface for emulation. These are NOT Apple code and are intended for compatibility testing only.

Files added:
- src/Toolkit/ppc/toolkit.c : PPC placeholder toolkit source
- src/Toolkit/68k/toolkit.c : 68k placeholder toolkit source
- scripts/build_toolkits.sh : build placeholders / attempt cross-compile
- scripts/make_esp_with_toolkits.sh: create an ESP FAT image containing toolkits + PRAM

Next steps:
- I will wire the loader to load the correct per-arch toolkit and pass BootInfo in the entry register.
- Add kernel-side BootInfo consumer to map and use the toolkit region.
34 changes: 4 additions & 30 deletions grub.cfg
Original file line number Diff line number Diff line change
@@ -1,31 +1,5 @@
# Auto-boot after 5s. Do NOT set this to -1: that waits forever for a keypress,
# which hangs headless/serial-only machines and unattended boots entirely.
set timeout=5
set default=0
# GRUB removed in efi-rework branch
# This repository is moving to UEFI/EFI boot. The legacy GRUB configuration has been removed from active use.
# This file is retained only for history and diagnostics; do not attempt to boot from this GRUB configuration on the efi-rework branch.

# Load video modules first
insmod all_video
insmod vbe
insmod vga
insmod video_bochs
insmod video_cirrus

# Mirror the menu to COM1 so the boot is visible/controllable on machines with
# no usable display. 38400 baud matches the kernel's UART divisor (see serial_init).
insmod serial
serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1

# Graphics mode configuration
# The kernel automatically detects and adapts to whatever resolution is provided
set gfxmode=1024x768x32,1024x768,800x600x32,auto
set gfxpayload=keep

# Switch to graphical terminal, keeping serial as a parallel console
terminal_output gfxterm serial
terminal_input console serial

menuentry "System 7.1" {
set gfxpayload=keep
multiboot2 /boot/kernel.elf
boot
}
# Former grub.cfg contents removed in favor of EFI boot images.
Loading