summaryrefslogtreecommitdiffhomepage
path: root/dev
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-04-24 07:30:49 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-04-24 07:30:49 +0200
commit0e5217d1a7af44a88341c5551fe79b8983bb7433 (patch)
tree4a6beb52fc3a463261b67b9f5bddd09b3a1ffa87 /dev
parentb55d3ac738b40677c579221b4f0dbf294dc3b017 (diff)
dev, BootNet: improved the protocol headers and implementation.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev')
-rw-r--r--dev/boot/modules/BootNet/BootNet.cc65
-rw-r--r--dev/boot/modules/BootNet/BootNet.h23
-rw-r--r--dev/kernel/FirmwareKit/CoreBoot/BootNet.h8
3 files changed, 58 insertions, 38 deletions
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 <NewKit/Defines.h>
-
-#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 <FirmwareKit/CoreBoot/BootNet.h>
diff --git a/dev/kernel/FirmwareKit/CoreBoot/BootNet.h b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h
index c2bfe161..b692c774 100644
--- a/dev/kernel/FirmwareKit/CoreBoot/BootNet.h
+++ b/dev/kernel/FirmwareKit/CoreBoot/BootNet.h
@@ -13,7 +13,9 @@
#define kBootNetNameLen (256U)
-/// @brief the internet header is used to download updates OTA.
+/// @brief Netboot Internet Header
+/// Consists of 4 magic characters, and a set of fields describing the current patch that's being sent (if m_preflight = 0)
+/// @note Can be used to patch ROMs too (if ImpliesProgram = 1)
typedef struct BOOTNET_INTERNET_HEADER
{
Kernel::Char NB1; /// magic char 1 'N'
@@ -24,7 +26,7 @@ typedef struct BOOTNET_INTERNET_HEADER
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 program?
+ Kernel::Boolean ImpliesProgram : 1; /// does it imply reprogramming?
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;
+} BOOTNET_INTERNET_HEADER;