From 92e86a036219d31c56d12ba41adab51d62a26ecc Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Fri, 27 Feb 2026 05:41:16 +0100 Subject: chore: kernel, boot: updated sources copyright year and improve stability. Signed-off-by: Amlal El Mahrouss --- src/boot/modules/BootNet/BootNet.cc | 129 ---------------------------- src/boot/modules/BootNet/BootNet.cpp | 129 ++++++++++++++++++++++++++++ src/boot/modules/BootNet/amd64.json | 6 +- src/boot/modules/SysChk/SysChk.cc | 36 -------- src/boot/modules/SysChk/SysChk.cpp | 36 ++++++++ src/boot/modules/SysChk/amd64-ahci-epm.json | 12 +-- src/boot/modules/SysChk/amd64-ahci-gpt.json | 12 +-- src/boot/modules/SysChk/amd64-pio-epm.json | 14 +-- src/boot/modules/SysChk/amd64-pio-gpt.json | 14 +-- src/boot/modules/SysChk/arm64.json | 2 +- 10 files changed, 195 insertions(+), 195 deletions(-) delete mode 100644 src/boot/modules/BootNet/BootNet.cc create mode 100644 src/boot/modules/BootNet/BootNet.cpp delete mode 100644 src/boot/modules/SysChk/SysChk.cc create mode 100644 src/boot/modules/SysChk/SysChk.cpp (limited to 'src/boot/modules') diff --git a/src/boot/modules/BootNet/BootNet.cc b/src/boot/modules/BootNet/BootNet.cc deleted file mode 100644 index 353f5497..00000000 --- a/src/boot/modules/BootNet/BootNet.cc +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include -#include - -STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; -STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; - -STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, - BOOTNET_INTERNET_HEADER** inet_out); - -EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) { - fw_init_efi((EfiSystemTable*) handover->f_FirmwareCustomTables[Kernel::HEL::kHandoverTableST]); - - Boot::BootTextWriter writer; - - writer.Write("BootNet: Init BootNet...\r"); - - if (BS->LocateProtocol(&kEfiSimpleProtoGUID, nullptr, (VoidPtr*) &kEfiProtocol) != kEfiOk) { - writer.Write("BootNet: Not supported by firmware.\r"); - return kEfiFail; - } - - 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, &inet_out); - - if (!inet_out) { - writer.Write("BootNet: Not a packet, aborting.\r"); - return kEfiFail; - } - - if (inet_out->NB1 != 'O' || inet_out->NB1 != 'N' || inet_out->NB1 != 'E' || - inet_out->NB1 != 'T') { - writer.Write("BootNet: Not a packet, aborting.\r"); - return kEfiFail; - } - - if (inet_out->Length < 1) { - writer.Write("BootNet: No executable attached to the packet, aborting.\r"); - return kEfiFail; - } - - if (inet_out->Version != kBootNetVersion) { - writer.Write("BootNet: The version clashes, not good.\r"); - return kEfiFail; - } - - if (!inet_out->ImpliesProgram) { - Boot::BootThread thread(inet_out->Data); - - if (thread.IsValid()) { - writer.Write("BootNet: Running NeKernel...\r"); - return thread.Start(handover, YES); - } - - return kEfiFail; - } else { - constexpr auto kROMSize = 0x200; - - if (inet_out->Length > kROMSize) { - writer.Write("BootNet: Not within 512K, won't flash EEPROM.\r"); - return kEfiFail; - } - - writer.Write("BootNet: Programming the flash...\r"); - - /// TODO: Program new firmware to EEPROM (if crc and size matches) - - 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, - BOOTNET_INTERNET_HEADER** inet_out) { - NE_UNUSED(inet); - - kEfiProtocol->Start(kEfiProtocol); - - UInt32 size_inet = sizeof(inet); - - /// Connect to the local BootNet server. - - auto len = inet.Length; - - /// And receive the handshake packet. - if (kEfiProtocol->Receive(kEfiProtocol, &size_inet, (UInt32*) &len, (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); -} diff --git a/src/boot/modules/BootNet/BootNet.cpp b/src/boot/modules/BootNet/BootNet.cpp new file mode 100644 index 00000000..28c72110 --- /dev/null +++ b/src/boot/modules/BootNet/BootNet.cpp @@ -0,0 +1,129 @@ +// Copyright 2024-2026, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include +#include + +STATIC EFI_GUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID; +STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr; + +STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, + BOOTNET_INTERNET_HEADER** inet_out); + +EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) { + fw_init_efi((EfiSystemTable*) handover->f_FirmwareCustomTables[Kernel::HEL::kHandoverTableST]); + + Boot::BootTextWriter writer; + + writer.Write("Net: Init BootNet...\r"); + + if (BS->LocateProtocol(&kEfiSimpleProtoGUID, nullptr, (VoidPtr*) &kEfiProtocol) != kEfiOk) { + writer.Write("Net: Not supported by the current firmware.\r"); + return kEfiFail; + } + + BOOTNET_INTERNET_HEADER inet{}; + BOOTNET_INTERNET_HEADER* inet_out = nullptr; + + SetMem(&inet, 0, sizeof(BOOTNET_INTERNET_HEADER)); + + writer.Write("Net: Downloading image...\r"); + + bootnet_read_ip_packet(inet, &inet_out); + + if (!inet_out) { + writer.Write("Net: Not a packet, aborting.\r"); + return kEfiFail; + } + + if (inet_out->NB1 != 'O' || inet_out->NB1 != 'N' || inet_out->NB1 != 'E' || + inet_out->NB1 != 'T') { + writer.Write("Net: Not a packet, aborting.\r"); + return kEfiFail; + } + + if (inet_out->Length < 1) { + writer.Write("Net: No executable attached to the packet, aborting.\r"); + return kEfiFail; + } + + if (inet_out->Version != kBootNetVersion) { + writer.Write("Net: The version clashes, not good.\r"); + return kEfiFail; + } + + if (!inet_out->ImpliesProgram) { + Boot::BootThread thread(inet_out->Data); + + if (thread.IsValid()) { + writer.Write("Net: Running image...\r"); + return thread.Start(handover, YES); + } + + return kEfiFail; + } else { + constexpr auto kROMSize = 0x200; + + if (inet_out->Length > kROMSize) { + writer.Write("Net: Not an image within 512K, we won't flash the EEPROM.\r"); + return kEfiFail; + } + + writer.Write("Net: Programming the EEPROM...\r"); + + /// TODO: Program new firmware to EEPROM (if crc and size matches) + + 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, + BOOTNET_INTERNET_HEADER** inet_out) { + NE_UNUSED(inet); + + kEfiProtocol->Start(kEfiProtocol); + + UInt32 size_inet = sizeof(inet); + + /// Connect to the local BootNet server. + + auto len = inet.Length; + + /// And receive the handshake packet. + if (kEfiProtocol->Receive(kEfiProtocol, &size_inet, (UInt32*) &len, (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); +} diff --git a/src/boot/modules/BootNet/amd64.json b/src/boot/modules/BootNet/amd64.json index 1f28e837..41ce26e1 100644 --- a/src/boot/modules/BootNet/amd64.json +++ b/src/boot/modules/BootNet/amd64.json @@ -9,11 +9,11 @@ "./" ], "sources_path": [ - "*.cc", + "*.cpp", "*.S", - "../../src/HEL/AMD64/*.cc", + "../../src/HEL/AMD64/*.cpp", "../../src/HEL/AMD64/*.S", - "../../src/*.cc" + "../../src/*.cpp" ], "output_name": "net.efi", "compiler_flags": [ diff --git a/src/boot/modules/SysChk/SysChk.cc b/src/boot/modules/SysChk/SysChk.cc deleted file mode 100644 index ebc2be68..00000000 --- a/src/boot/modules/SysChk/SysChk.cc +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) -// Licensed under the Apache License, Version 2.0 (see LICENSE file) -// Official repository: https://github.com/nekernel-org/nekernel - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// Makes the compiler shut up. -#ifndef kMachineModel -#define kMachineModel "OS" -#endif // !kMachineModel - -EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover) { - fw_init_efi((EfiSystemTable*) handover->f_FirmwareCustomTables[Kernel::HEL::kHandoverTableST]); - -#if defined(__ATA_PIO__) - Boot::BDiskFormatFactory partition_factory; -#elif defined(__AHCI__) - Boot::BDiskFormatFactory partition_factory; -#endif - - if (partition_factory.IsPartitionValid()) return kEfiOk; - - return partition_factory.Format(kMachineModel); -} diff --git a/src/boot/modules/SysChk/SysChk.cpp b/src/boot/modules/SysChk/SysChk.cpp new file mode 100644 index 00000000..ebc2be68 --- /dev/null +++ b/src/boot/modules/SysChk/SysChk.cpp @@ -0,0 +1,36 @@ +// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org) +// Licensed under the Apache License, Version 2.0 (see LICENSE file) +// Official repository: https://github.com/nekernel-org/nekernel + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// Makes the compiler shut up. +#ifndef kMachineModel +#define kMachineModel "OS" +#endif // !kMachineModel + +EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover) { + fw_init_efi((EfiSystemTable*) handover->f_FirmwareCustomTables[Kernel::HEL::kHandoverTableST]); + +#if defined(__ATA_PIO__) + Boot::BDiskFormatFactory partition_factory; +#elif defined(__AHCI__) + Boot::BDiskFormatFactory partition_factory; +#endif + + if (partition_factory.IsPartitionValid()) return kEfiOk; + + return partition_factory.Format(kMachineModel); +} diff --git a/src/boot/modules/SysChk/amd64-ahci-epm.json b/src/boot/modules/SysChk/amd64-ahci-epm.json index 83282c3f..444003cf 100644 --- a/src/boot/modules/SysChk/amd64-ahci-epm.json +++ b/src/boot/modules/SysChk/amd64-ahci-epm.json @@ -3,14 +3,14 @@ "compiler_std": "c++20", "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], "sources_path": [ - "*.cc", + "*.cpp", "*.S", - "../../src/HEL/AMD64/BootSATA.cc", - "../../src/HEL/AMD64/BootPlatform.cc", + "../../src/HEL/AMD64/BootSATA.cpp", + "../../src/HEL/AMD64/BootPlatform.cpp", "../../src/HEL/AMD64/BootAPI.S", - "../../src/BootTextWriter.cc", - "../../src/BootSupport.cc", - "../../src/New+Delete.cc", + "../../src/BootTextWriter.cpp", + "../../src/BootSupport.cpp", + "../../src/New+Delete.cpp", "../../../kernel/HALKit/AMD64/PCI/*.cpp", "../../../kernel/HALKit/AMD64/Storage/*.cpp", "../../../kernel/src/Storage/*.cpp", diff --git a/src/boot/modules/SysChk/amd64-ahci-gpt.json b/src/boot/modules/SysChk/amd64-ahci-gpt.json index 8fcf2a57..9b0f4546 100644 --- a/src/boot/modules/SysChk/amd64-ahci-gpt.json +++ b/src/boot/modules/SysChk/amd64-ahci-gpt.json @@ -3,14 +3,14 @@ "compiler_std": "c++20", "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], "sources_path": [ - "*.cc", + "*.cpp", "*.S", - "../../src/HEL/AMD64/BootSATA.cc", - "../../src/HEL/AMD64/BootPlatform.cc", + "../../src/HEL/AMD64/BootSATA.cpp", + "../../src/HEL/AMD64/BootPlatform.cpp", "../../src/HEL/AMD64/BootAPI.S", - "../../src/BootTextWriter.cc", - "../../src/BootSupport.cc", - "../../src/New+Delete.cc", + "../../src/BootTextWriter.cpp", + "../../src/BootSupport.cpp", + "../../src/New+Delete.cpp", "../../../kernel/HALKit/AMD64/PCI/*.cpp", "../../../kernel/HALKit/AMD64/Storage/*.cpp", "../../../kernel/src/Storage/*.cpp", diff --git a/src/boot/modules/SysChk/amd64-pio-epm.json b/src/boot/modules/SysChk/amd64-pio-epm.json index 12d47119..0c4a1c59 100644 --- a/src/boot/modules/SysChk/amd64-pio-epm.json +++ b/src/boot/modules/SysChk/amd64-pio-epm.json @@ -9,14 +9,14 @@ "./" ], "sources_path": [ - "*.cc", + "*.cpp", "*.S", - "../../src/HEL/AMD64/BootATA.cc", - "../../src/HEL/AMD64/BootPlatform.cc", + "../../src/HEL/AMD64/BootATA.cpp", + "../../src/HEL/AMD64/BootPlatform.cpp", "../../src/HEL/AMD64/BootAPI.S", - "../../src/BootTextWriter.cc", - "../../src/BootSupport.cc", - "../../src/New+Delete.cc" + "../../src/BootTextWriter.cpp", + "../../src/BootSupport.cpp", + "../../src/New+Delete.cpp" ], "output_name": "chk.efi", "compiler_flags": [ @@ -42,4 +42,4 @@ "kChkVersionLowest=0x0100", "kChkVersion=0x0100" ] -} \ No newline at end of file +} diff --git a/src/boot/modules/SysChk/amd64-pio-gpt.json b/src/boot/modules/SysChk/amd64-pio-gpt.json index f68d5d36..ca564067 100644 --- a/src/boot/modules/SysChk/amd64-pio-gpt.json +++ b/src/boot/modules/SysChk/amd64-pio-gpt.json @@ -9,14 +9,14 @@ "./" ], "sources_path": [ - "*.cc", + "*.cpp", "*.S", - "../../src/HEL/AMD64/BootATA.cc", - "../../src/HEL/AMD64/BootPlatform.cc", + "../../src/HEL/AMD64/BootATA.cpp", + "../../src/HEL/AMD64/BootPlatform.cpp", "../../src/HEL/AMD64/BootAPI.S", - "../../src/BootTextWriter.cc", - "../../src/BootSupport.cc", - "../../src/New+Delete.cc" + "../../src/BootTextWriter.cpp", + "../../src/BootSupport.cpp", + "../../src/New+Delete.cpp" ], "output_name": "chk.efi", "compiler_flags": [ @@ -42,4 +42,4 @@ "kChkVersionLowest=0x0100", "kChkVersion=0x0100" ] -} \ No newline at end of file +} diff --git a/src/boot/modules/SysChk/arm64.json b/src/boot/modules/SysChk/arm64.json index ad5fde6e..2a04c772 100644 --- a/src/boot/modules/SysChk/arm64.json +++ b/src/boot/modules/SysChk/arm64.json @@ -2,7 +2,7 @@ "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], - "sources_path": ["*.cc", "*.S", "../../src/HEL/ARM64/*.cc", "../../src/HEL/ARM64/*.S", "../../src/*.cc"], + "sources_path": ["*.cpp", "*.S", "../../src/HEL/ARM64/*.cpp", "../../src/HEL/ARM64/*.S", "../../src/*.cpp"], "output_name": "chk.efi", "compiler_flags": [ "-ffreestanding", -- cgit v1.2.3