From 0e5217d1a7af44a88341c5551fe79b8983bb7433 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Thu, 24 Apr 2025 07:30:49 +0200 Subject: dev, BootNet: improved the protocol headers and implementation. Signed-off-by: Amlal El Mahrouss --- dev/boot/modules/BootNet/BootNet.cc | 65 +++++++++++++++++++++++++++++-------- dev/boot/modules/BootNet/BootNet.h | 23 +------------ 2 files changed, 53 insertions(+), 35 deletions(-) (limited to 'dev/boot/modules/BootNet') diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc index 92f7aa7a..3e025949 100644 --- a/dev/boot/modules/BootNet/BootNet.cc +++ b/dev/boot/modules/BootNet/BootNet.cc @@ -15,15 +15,15 @@ STATIC EfiGUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; -STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER); +STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, BOOTNET_INTERNET_HEADER** inet_out); EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) { - Boot::BootTextWriter writer; + fw_init_efi((EfiSystemTable*)handover->f_FirmwareCustomTables[1]); - writer.Write("BootNet: Init EFI...\r"); + Boot::BootTextWriter writer; - fw_init_efi((EfiSystemTable*)handover->f_FirmwareCustomTables[1]); + writer.Write("BootNet: Init BootNet...\r"); if (BS->LocateProtocol(&kEfiSimpleProtoGUID, nullptr, (VoidPtr*)&kEfiProtocol) != kEfiOk) { @@ -32,22 +32,23 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) } BOOTNET_INTERNET_HEADER inet{}; + BOOTNET_INTERNET_HEADER* inet_out = nullptr; SetMem(&inet, 0, sizeof(BOOTNET_INTERNET_HEADER)); writer.Write("BootNet: Downloading kernel...\r"); - bootnet_read_ip_packet(inet); + bootnet_read_ip_packet(inet, &inet_out); - if (inet.Length < 1) + if (inet_out->Length < 1) { writer.Write("BootNet: No executable attached to the packet, aborting.\r"); return kEfiFail; } - if (!inet.ImpliesProgram) + if (!inet_out->ImpliesProgram) { - Boot::BootThread thread(inet.Data); + Boot::BootThread thread(inet_out->Data); if (thread.IsValid()) { @@ -61,24 +62,62 @@ EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) { constexpr auto kROMSize = 0x200; - if (inet.Length != kROMSize) + if (inet_out->Length > kROMSize) { writer.Write("BootNet: Not within 512K.\r"); return kEfiFail; } - writer.Write("BootNet: Programming the flash is not available as of right now.\r"); + writer.Write("BootNet: Programming the flash...\r"); /// TODO: Program new firmware to EEPROM (if crc and size matches) - const UIntPtr kEEPROMAddress = 0; - const UInt16 kEEPROMSize = inet.Length; + const ATTRIBUTE(unused) UIntPtr kEEPROMStartAddress = 0; + const ATTRIBUTE(unused) UInt16 kEEPROMSize = inet_out->Length; + + return kEfiFail; } return kEfiFail; } -STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet) +STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, BOOTNET_INTERNET_HEADER** inet_out) { NE_UNUSED(inet); + + kEfiProtocol->Start(kEfiProtocol); + + UInt32 size_inet = sizeof(inet); + + /// Connect to the local BootNet server. + + /// And receive the handshake packet. + if (kEfiProtocol->Receive(kEfiProtocol, &size_inet, (UInt32*)&inet.Length, (VoidPtr)&inet, nullptr, nullptr, nullptr) == kEfiOk) + { + BOOTNET_INTERNET_HEADER* out = nullptr; + + BS->AllocatePool(EfiLoaderData, sizeof(BOOTNET_INTERNET_HEADER) + inet.Length, (VoidPtr*)&out); + + if (out == nullptr) + { + kEfiProtocol->Stop(kEfiProtocol); + kEfiProtocol->Shutdown(kEfiProtocol); + return; + } + + SetMem(out, 0, sizeof(BOOTNET_INTERNET_HEADER)); + SetMem(out->Data, 0, inet.Length); + + size_inet = sizeof(BOOTNET_INTERNET_HEADER); + + auto full_size = size_inet + inet.Length; + + /// Ask for it again since we know the full_size variable now. + kEfiProtocol->Receive(kEfiProtocol, &size_inet, (UInt32*)&full_size, (VoidPtr)out, nullptr, nullptr, nullptr); + + *inet_out = out; + } + + kEfiProtocol->Stop(kEfiProtocol); + kEfiProtocol->Shutdown(kEfiProtocol); } \ No newline at end of file diff --git a/dev/boot/modules/BootNet/BootNet.h b/dev/boot/modules/BootNet/BootNet.h index b38ed0e9..0b319387 100644 --- a/dev/boot/modules/BootNet/BootNet.h +++ b/dev/boot/modules/BootNet/BootNet.h @@ -9,25 +9,4 @@ #pragma once -#include - -#define kBootNetINetMagic "NETB" -#define kBootNetINetMagicLength (4) - -#define kBootNetNameLen (256U) - -/// @brief the internet header is used to download updates OTA. -typedef struct BOOTNET_INTERNET_HEADER -{ - Kernel::Char NB1; /// magic char 1 'N' - Kernel::Char NB2; /// magic char 2 'E' - Kernel::Char NB3; /// magic char 3 'T' - Kernel::Char NB4; /// magic char 4 'B' - - Kernel::Char Name[kBootNetNameLen]; /// example: Modjo - Kernel::Int32 Length; /// the patch length. - Kernel::Char Target[kBootNetNameLen]; /// the target file. - Kernel::Boolean ImpliesProgram : 1; /// does it imply an EEPROM reprogram? - Kernel::Boolean Preflight : 1; /// is it a preflight packet. - Kernel::Char Data[1]; /// non preflight packet has a patch blob for a **PatchTarget** -} ATTRIBUTE(packed) BOOTNET_INTERNET_HEADER; +#include -- cgit v1.2.3