summaryrefslogtreecommitdiffhomepage
path: root/dev/boot/src
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-04-14 09:42:28 +0200
committerAmlal El Mahrouss <amlal@nekernel.org>2025-04-14 09:42:28 +0200
commita01ba7acb4786a6354349408b3bcc4c2d007b274 (patch)
tree7b1e4e4a95910391242b3c3a50b853db6e433aaa /dev/boot/src
parent2eb25a0e70bdd0be91f1f03033fc64ccbb91b54a (diff)
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 <amlal@nekernel.org>
Diffstat (limited to 'dev/boot/src')
-rw-r--r--dev/boot/src/HEL/AMD64/BootEFI.cc25
-rw-r--r--dev/boot/src/HEL/ARM64/BootEFI.cc71
2 files changed, 65 insertions, 31 deletions
diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc
index 4220c6cb..a818fcd6 100644
--- a/dev/boot/src/HEL/AMD64/BootEFI.cc
+++ b/dev/boot/src/HEL/AMD64/BootEFI.cc
@@ -73,19 +73,19 @@ STATIC Bool boot_init_fb() noexcept
EfiGUID kEfiGlobalNamespaceVarGUID = {
0x8BE4DF61, 0x93CA, 0x11D2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C}};
-/// @brief ModuleMain EFI entrypoint.
+/// @brief BootloaderMain EFI entrypoint.
/// @param image_handle Handle of this image.
/// @param sys_table The system table of it.
/// @return nothing, never returns.
-EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
- EfiSystemTable* sys_table)
+EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle,
+ EfiSystemTable* sys_table)
{
- InitEFI(sys_table); ///! Init the EFI library.
+ fw_init_efi(sys_table); ///! Init the EFI library.
HEL::BootInfoHeader* handover_hdr =
new HEL::BootInfoHeader();
- UInt32 map_key = 0;
+ UInt32 map_key = 0;
#ifdef ZBA_USE_FB
if (!boot_init_fb())
@@ -163,12 +163,10 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
Boot::BootTextWriter writer;
- //-------------------------------------------------------------//
- // Update handover file specific table and phyiscal start field.
- //-------------------------------------------------------------//
+ handover_hdr->f_BitMapStart = nullptr; /* Start of bitmap. */
+ handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */
- handover_hdr->f_BitMapSize = gib_cast(4); /* Size of bitmap in bytes. */
- Int32 trials = 5 * 10000000;
+ Int32 trials = 5 * 10000000;
while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk)
{
@@ -180,7 +178,7 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
trials = 3 * 10000000;
- handover_hdr->f_BitMapSize = gib_cast(2); /* Size of bitmap in bytes. */
+ handover_hdr->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */
while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk)
{
@@ -221,8 +219,6 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
FBDrawBitMapInRegion(zka_no_disk, NE_NO_DISK_WIDTH, NE_NO_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_NO_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_NO_DISK_HEIGHT) / 2);
fb_clear();
-
- Boot::Stop();
}
}
@@ -288,6 +284,7 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
kernel_thread->SetName("BootZ: Kernel");
handover_hdr->f_KernelImage = reader_kernel.Blob();
+ handover_hdr->f_KernelSz = reader_kernel.Size();
}
else
{
@@ -297,6 +294,8 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
Boot::Stop();
}
+ // Fallback to bootnet, if not PXE.
+
Boot::BootFileReader reader_netboot(L"net.efi", image_handle);
reader_netboot.ReadAll(0);
diff --git a/dev/boot/src/HEL/ARM64/BootEFI.cc b/dev/boot/src/HEL/ARM64/BootEFI.cc
index b6f28351..72ac310b 100644
--- a/dev/boot/src/HEL/ARM64/BootEFI.cc
+++ b/dev/boot/src/HEL/ARM64/BootEFI.cc
@@ -18,11 +18,6 @@
#include <BootKit/BootThread.h>
#include <modules/CoreGfx/CoreGfx.h>
-// Makes the compiler shut up.
-#ifndef kMachineModel
-#define kMachineModel "NeKernel"
-#endif // !kMachineModel
-
#ifndef kExpectedWidth
#define kExpectedWidth (1920)
#endif
@@ -74,14 +69,14 @@ STATIC Bool boot_init_fb() noexcept
EXTERN EfiBootServices* BS;
-/// @brief ModuleMain EFI entrypoint.
+/// @brief BootloaderMain EFI entrypoint.
/// @param image_handle Handle of this image.
/// @param sys_table The system table of it.
/// @return nothing, never returns.
-EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
- EfiSystemTable* sys_table)
+EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle,
+ EfiSystemTable* sys_table)
{
- InitEFI(sys_table); ///! Init the EFI library.
+ fw_init_efi(sys_table); ///! Init the EFI library.
HEL::BootInfoHeader* handover_hdr =
new HEL::BootInfoHeader();
@@ -133,9 +128,9 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
EfiMpServicesProtocol* mp = nullptr;
BS->LocateProtocol(&guid_mp, nullptr, reinterpret_cast<VoidPtr*>(&mp));
-
handover_hdr->f_HardwareTables.f_MpPtr = reinterpret_cast<VoidPtr>(mp);
+ // Assign to global 'kHandoverHeader'.
kHandoverHeader = handover_hdr;
fb_init();
@@ -160,18 +155,59 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
}
//-------------------------------------------------------------//
- // Update handover file specific table and phyiscal start field.
+ // Allocate heap.
//-------------------------------------------------------------//
+ Boot::BootTextWriter writer;
+
handover_hdr->f_BitMapStart = nullptr; /* Start of bitmap. */
- handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap. */
+ handover_hdr->f_BitMapSize = kHandoverBitMapSz; /* Size of bitmap in bytes. */
+ Int32 trials = 5 * 10000000;
while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk)
{
- if (handover_hdr->f_BitMapStart)
+ --trials;
+
+ if (!trials)
+ {
+ writer.Write("BootZ: Unable to allocate sufficent memory, trying again with 2GB...\r");
+
+ trials = 3 * 10000000;
+
+ handover_hdr->f_BitMapSize = kHandoverBitMapSz / 2; /* Size of bitmap in bytes. */
+
+ while (BS->AllocatePool(EfiLoaderData, handover_hdr->f_BitMapSize, &handover_hdr->f_BitMapStart) != kEfiOk)
+ {
+ --trials;
+
+ if (!trials)
+ {
+ writer.Write("BootZ: Unable to allocate sufficent memory, aborting...\r");
+ Boot::Stop();
+ }
+ }
+ }
+ }
+
+ Boot::BootFileReader reader_syschk(L"chk.efi", image_handle);
+ reader_syschk.ReadAll(0);
+
+ Boot::BootThread* syschk_thread = nullptr;
+
+ if (reader_syschk.Blob())
+ {
+ syschk_thread = new Boot::BootThread(reader_syschk.Blob());
+ syschk_thread->SetName("BootZ: System Check");
+
+ if (syschk_thread->Start(handover_hdr, NO) != kEfiOk)
{
- BS->FreePool(handover_hdr->f_BitMapStart);
- handover_hdr->f_BitMapStart = nullptr;
+ fb_init();
+
+ FB::fb_clear_video();
+
+ FBDrawBitMapInRegion(zka_no_disk, NE_NO_DISK_WIDTH, NE_NO_DISK_HEIGHT, (kHandoverHeader->f_GOP.f_Width - NE_NO_DISK_WIDTH) / 2, (kHandoverHeader->f_GOP.f_Height - NE_NO_DISK_HEIGHT) / 2);
+
+ fb_clear();
}
}
@@ -194,8 +230,6 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
handover_hdr->f_FirmwareVendorLen = Boot::BStrLen(sys_table->FirmwareVendor);
- // Assign to global 'kHandoverHeader'.
-
Boot::BootFileReader reader_kernel(L"vmkrnl.efi", image_handle);
reader_kernel.ReadAll(0);
@@ -207,9 +241,10 @@ EFI_EXTERN_C EFI_API Int32 ModuleMain(EfiHandlePtr image_handle,
if (reader_kernel.Blob())
{
auto kernel_thread = Boot::BootThread(reader_kernel.Blob());
- kernel_thread.SetName("BootZ: MicroKernel.");
+ kernel_thread.SetName("BootZ: Kernel.");
handover_hdr->f_KernelImage = reader_kernel.Blob();
+ handover_hdr->f_KernelSz = reader_kernel.Size();
Boot::ExitBootServices(map_key, image_handle);