diff options
Diffstat (limited to 'dev/boot/modules/BootNet/BootNet.cc')
| -rw-r--r-- | dev/boot/modules/BootNet/BootNet.cc | 53 |
1 files changed, 40 insertions, 13 deletions
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 <FirmwareKit/EFI/API.h> #include <modules/BootNet/BootNet.h> #include <BootKit/BootKit.h> #include <BootKit/BootThread.h> -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 |
