3.3 KiB
3.3 KiB
UEFI Boot Process and Disk Layout
Disk Layout with ESP (EFI System Partition)
Sector 0 (MBR/GPT):
+-----------------------------------+ 0x000
| Protective MBR |
| (For BIOS compatibility) |
+-----------------------------------+ 0x200
EFI System Partition (FAT32):
+-----------------------------------+ Sector 2048
| FAT32 Filesystem |
| /EFI/ |
| /BOOT/ |
| BOOTX64.EFI |
+-----------------------------------+
Main Partition (FAT32):
+-----------------------------------+
| FAT32 Filesystem |
| (Kernel and other files) |
+-----------------------------------+
UEFI Boot Process
-
System Startup
- Firmware initializes hardware
- Loads UEFI runtime services
- Sets up initial page tables and long mode
- CPU already in 64-bit mode
-
Boot Manager
- Scans for bootable devices
- Looks for EFI System Partition (ESP)
- Searches for bootloader at
/EFI/BOOT/BOOTX64.EFI
-
UEFI Bootloader
- Already in long mode (64-bit)
- Has access to UEFI services:
- File operations
- Memory management
- Video output
- ACPI tables
- Tasks:
- Load kernel from main partition
- Set up memory map
- Exit boot services
- Jump to kernel
-
Kernel Load
- Bootloader passes:
- Memory map
- Framebuffer info
- ACPI tables
- Kernel takes control
- Bootloader passes:
Key Differences from BIOS
-
Initial State
- BIOS: 16-bit real mode
- UEFI: 64-bit long mode
-
Services
- BIOS: Limited interrupt-based services
- UEFI: Rich API for system services
-
Memory Management
- BIOS: Manual memory detection needed
- UEFI: Provides memory map and allocation services
-
File Access
- BIOS: Manual disk I/O and filesystem parsing
- UEFI: Built-in filesystem support
-
Graphics
- BIOS: VGA/VBE modes
- UEFI: GOP (Graphics Output Protocol)
UEFI Boot Services
Available until ExitBootServices() is called:
- Memory allocation
- File system access
- Graphics output
- Timer services
- Environment variables
Runtime Services (available after boot):
- Time services
- Variable services
- Reset system
- Virtual memory services
Memory Map Example
Type Physical Address Range
EfiLoaderCode 0x0000000000000000-0x0000000000100000
EfiLoaderData 0x0000000000100000-0x0000000000200000
EfiBootServicesCode 0x0000000000200000-0x0000000000300000
EfiBootServicesData 0x0000000000300000-0x0000000000400000
EfiConventionalMemory 0x0000000000400000-...
EfiACPIReclaimMemory ...
EfiACPIMemoryNVS ...
EfiReservedMemoryType ...
Required UEFI Protocols
- EFI_LOADED_IMAGE_PROTOCOL: Access to bootloader image info
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL: File operations
- EFI_GRAPHICS_OUTPUT_PROTOCOL: Display output
- EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL: Text output
Boot Flow Control
UEFI Firmware
│
▼
Boot Manager
│
▼
BOOTX64.EFI
│
├── Get System Info
│ ├── Memory Map
│ ├── ACPI Tables
│ └── GOP Info
│
├── Load Kernel
│ └── Parse FAT32
│
├── ExitBootServices()
│
└── Jump to Kernel
└── Pass Boot Info