From a01ba7acb4786a6354349408b3bcc4c2d007b274 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 14 Apr 2025 09:42:28 +0200 Subject: bootloader, netboot: integrate EFI_SIMPLE_NETWORK_PROTOCOL for HTTP-based kernel fetching - Added BootNet module to support network boot using EFI_SIMPLE_NETWORK_PROTOCOL - Replaced ModuleMain with BootloaderMain as unified entry point - Implemented EFI protocol discovery, startup, and logging for netboot - Updated linker scripts, GDB configs, and build targets accordingly - Laid groundwork for full HTTP/TCP/IP bootloader logic - Improved kernel handoff logic and memory allocation fallback handling Signed-off-by: Amlal El Mahrouss --- dev/boot/modules/BootNet/BootNet.cc | 53 ++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 13 deletions(-) (limited to 'dev/boot/modules/BootNet/BootNet.cc') diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index 8ee08929..28d96cb2 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -7,29 +7,40 @@ * ======================================================== */ +#include #include #include #include -STATIC EfiGUID kEfiIP4ProtoGUID = {}; +STATIC EfiGUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; +STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; -STATIC Void bootnet_read_udp_packet(BOOTNET_INTERNET_HEADER&); +STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER&); EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) { + fw_init_efi((EfiSystemTable*)handover->f_FirmwareCustomTables[0]); + + + Boot::BootTextWriter writer; + + if (BS->LocateProtocol(&kEfiSimpleProtoGUID, nullptr, (VoidPtr*)&kEfiProtocol) != kEfiOk) + { + writer.Write("[BOOT] BootNet: Not supported by firmware.\r"); + return kEfiFail; + } + BOOTNET_INTERNET_HEADER inet{}; - memset(&inet, 0, sizeof(BOOTNET_INTERNET_HEADER)); - - bootnet_read_udp_packet(inet); + SetMem(&inet, 0, sizeof(BOOTNET_INTERNET_HEADER)); - /// TODO: Read address from JSON file 'bootnet.json' + writer.Write("[BOOT] BootNet: Downloading kernel...\r"); + + bootnet_read_ip_packet(inet); if (inet.Length < 1) { - Boot::BootTextWriter writer; - writer.Write("BootNet: No executable attached to the packet, aborting.\r"); - + writer.Write("[BOOT] BootNet: No executable attached to the packet, aborting.\r"); return kEfiFail; } @@ -38,23 +49,39 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) Boot::BootThread thread(inet.Data); if (thread.IsValid()) + { + writer.Write("[BOOT] BootNet: Running kernel...\r"); return thread.Start(handover, YES); + } return kEfiFail; } else { - Boot::BootTextWriter writer; - writer.Write("BootNetLauncher: EEPROM flash is not available as of right now.\r"); + constexpr auto kROMSize = 0x200; + + if (inet.Length != kROMSize) + { + writer.Write("[BOOT] BootNet: Not within 512K.\r"); + return kEfiFail; + } + + writer.Write("[BOOT] BootNet: Programming the flash is not available as of right now.\r"); /// TODO: Program new firmware to EEPROM (if crc and size matches) - return kEfiFail; // TODO: Add support for EEPROM firmware update. + const UIntPtr kEEPROMAddress = 0; + const UInt16 kEEPROMSize = inet.Length; } return kEfiFail; } -STATIC Void bootnet_read_udp_packet(BOOTNET_INTERNET_HEADER&) +STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER& inet) { + kEfiProtocol->Start(kEfiProtocol); + + NE_UNUSED(inet); + + kEfiProtocol->Stop(kEfiProtocol); } \ No newline at end of file -- cgit v1.2.3