summaryrefslogtreecommitdiffhomepage
path: root/dev/boot/modules/BootNet/BootNet.cc
diff options
context:
space:
mode:
authorAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
committerAmlal <amlal@nekernel.org>2025-04-25 13:08:33 +0200
commitfb790b07aeba8e22e4190cf3e1834d11ecde6c96 (patch)
tree4cec7d1b321307b1d5935577631dae116a658a37 /dev/boot/modules/BootNet/BootNet.cc
parent63a2d92c5dfe976175cda024ec01905d11b43738 (diff)
dev: better .clang-format, ran format command.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/boot/modules/BootNet/BootNet.cc')
-rw-r--r--dev/boot/modules/BootNet/BootNet.cc147
1 files changed, 70 insertions, 77 deletions
diff --git a/dev/boot/modules/BootNet/BootNet.cc b/dev/boot/modules/BootNet/BootNet.cc
index 3e025949..840aabd5 100644
--- a/dev/boot/modules/BootNet/BootNet.cc
+++ b/dev/boot/modules/BootNet/BootNet.cc
@@ -7,117 +7,110 @@
* ========================================================
*/
-#include <FirmwareKit/EFI/API.h>
-#include <modules/BootNet/BootNet.h>
#include <BootKit/BootKit.h>
#include <BootKit/BootThread.h>
+#include <FirmwareKit/EFI/API.h>
+#include <modules/BootNet/BootNet.h>
-STATIC EfiGUID kEfiSimpleProtoGUID = EFI_SIMPLE_NETWORK_PROTOCOL_GUID;
-STATIC EFI_SIMPLE_NETWORK_PROTOCOL* kEfiProtocol = nullptr;
+STATIC EfiGUID 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);
+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[1]);
+EXTERN_C Int32 BootNetModuleMain(Kernel::HEL::BootInfoHeader* handover) {
+ fw_init_efi((EfiSystemTable*) handover->f_FirmwareCustomTables[1]);
- Boot::BootTextWriter writer;
+ Boot::BootTextWriter writer;
- writer.Write("BootNet: Init BootNet...\r");
+ writer.Write("BootNet: Init BootNet...\r");
- if (BS->LocateProtocol(&kEfiSimpleProtoGUID, nullptr, (VoidPtr*)&kEfiProtocol) != kEfiOk)
- {
- writer.Write("BootNet: Not supported by firmware.\r");
- return kEfiFail;
- }
+ 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;
+ BOOTNET_INTERNET_HEADER inet{};
+ BOOTNET_INTERNET_HEADER* inet_out = nullptr;
- SetMem(&inet, 0, sizeof(BOOTNET_INTERNET_HEADER));
+ SetMem(&inet, 0, sizeof(BOOTNET_INTERNET_HEADER));
- writer.Write("BootNet: Downloading kernel...\r");
+ writer.Write("BootNet: Downloading kernel...\r");
- bootnet_read_ip_packet(inet, &inet_out);
+ bootnet_read_ip_packet(inet, &inet_out);
- if (inet_out->Length < 1)
- {
- writer.Write("BootNet: No executable attached to the 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->ImpliesProgram)
- {
- Boot::BootThread thread(inet_out->Data);
+ if (!inet_out->ImpliesProgram) {
+ Boot::BootThread thread(inet_out->Data);
- if (thread.IsValid())
- {
- writer.Write("BootNet: Running kernel...\r");
- return thread.Start(handover, YES);
- }
+ if (thread.IsValid()) {
+ writer.Write("BootNet: Running kernel...\r");
+ return thread.Start(handover, YES);
+ }
- return kEfiFail;
- }
- else
- {
- constexpr auto kROMSize = 0x200;
+ return kEfiFail;
+ } else {
+ constexpr auto kROMSize = 0x200;
- if (inet_out->Length > kROMSize)
- {
- writer.Write("BootNet: Not within 512K.\r");
- return kEfiFail;
- }
+ if (inet_out->Length > kROMSize) {
+ writer.Write("BootNet: Not within 512K.\r");
+ return kEfiFail;
+ }
- writer.Write("BootNet: Programming the flash...\r");
+ writer.Write("BootNet: Programming the flash...\r");
- /// TODO: Program new firmware to EEPROM (if crc and size matches)
+ /// 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;
+ const ATTRIBUTE(unused) UIntPtr kEEPROMStartAddress = 0;
+ const ATTRIBUTE(unused) UInt16 kEEPROMSize = inet_out->Length;
- return kEfiFail;
- }
+ return kEfiFail;
+ }
- return kEfiFail;
+ return kEfiFail;
}
-STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet, BOOTNET_INTERNET_HEADER** inet_out)
-{
- NE_UNUSED(inet);
+STATIC Void bootnet_read_ip_packet(BOOTNET_INTERNET_HEADER inet,
+ BOOTNET_INTERNET_HEADER** inet_out) {
+ NE_UNUSED(inet);
- kEfiProtocol->Start(kEfiProtocol);
+ kEfiProtocol->Start(kEfiProtocol);
- UInt32 size_inet = sizeof(inet);
+ UInt32 size_inet = sizeof(inet);
- /// Connect to the local BootNet server.
+ /// 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;
+ /// 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);
+ BS->AllocatePool(EfiLoaderData, sizeof(BOOTNET_INTERNET_HEADER) + inet.Length, (VoidPtr*) &out);
- if (out == nullptr)
- {
- kEfiProtocol->Stop(kEfiProtocol);
- kEfiProtocol->Shutdown(kEfiProtocol);
- return;
- }
+ if (out == nullptr) {
+ kEfiProtocol->Stop(kEfiProtocol);
+ kEfiProtocol->Shutdown(kEfiProtocol);
+ return;
+ }
- SetMem(out, 0, sizeof(BOOTNET_INTERNET_HEADER));
- SetMem(out->Data, 0, inet.Length);
+ SetMem(out, 0, sizeof(BOOTNET_INTERNET_HEADER));
+ SetMem(out->Data, 0, inet.Length);
- size_inet = sizeof(BOOTNET_INTERNET_HEADER);
+ size_inet = sizeof(BOOTNET_INTERNET_HEADER);
- auto full_size = size_inet + inet.Length;
+ 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);
+ /// 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;
- }
+ *inet_out = out;
+ }
- kEfiProtocol->Stop(kEfiProtocol);
- kEfiProtocol->Shutdown(kEfiProtocol);
+ kEfiProtocol->Stop(kEfiProtocol);
+ kEfiProtocol->Shutdown(kEfiProtocol);
} \ No newline at end of file