summaryrefslogtreecommitdiffhomepage
path: root/src/boot
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2026-03-11 05:51:25 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2026-03-11 05:51:25 +0100
commit342e27527797d5dd6f0ba3baa23c0bbc786892e1 (patch)
treeb8c86fefc71b9d4c400429a3c1e723beeae6f766 /src/boot
parent7cee4def2634d3c4aed59c3ab66b65bbbf1ec751 (diff)
[CHORE] ARM64 port improvements, POSIXKit additions, and SysChk/BootNet improvements.kernel-bootkit-posix-additions
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/boot')
-rw-r--r--src/boot/BootKit/BootKit.h8
-rw-r--r--src/boot/README.md11
-rw-r--r--src/boot/amd64-ci.make2
-rw-r--r--src/boot/amd64-desktop.make2
-rw-r--r--src/boot/arm64-desktop.make2
-rw-r--r--src/boot/modules/BootNet/.hgkeep0
-rw-r--r--src/boot/modules/BootNet/README.md5
-rw-r--r--src/boot/modules/BootNet/arm64.json35
-rw-r--r--src/boot/modules/SysChk/.hgkeep0
-rw-r--r--src/boot/modules/SysChk/README.md5
-rw-r--r--src/boot/modules/SysChk/SysChk.cpp6
-rw-r--r--src/boot/modules/SysChk/arm64-ahci-epm.json49
-rw-r--r--src/boot/modules/SysChk/arm64.json26
-rw-r--r--src/boot/src/HEL/AMD64/BootPlatform.cpp20
-rw-r--r--src/boot/src/HEL/ARM64/BootEFI.cpp27
-rw-r--r--src/boot/src/HEL/ARM64/BootPlatform.cpp6
16 files changed, 126 insertions, 78 deletions
diff --git a/src/boot/BootKit/BootKit.h b/src/boot/BootKit/BootKit.h
index 1d0686ae..980588e5 100644
--- a/src/boot/BootKit/BootKit.h
+++ b/src/boot/BootKit/BootKit.h
@@ -276,12 +276,12 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) {
StrLen(kEPMMagic));
fDiskDev.Leak().mBase = kEPMBootBlockLba; // always always resies at zero block.
- fDiskDev.Leak().mSize = sizeof(EPM_PART_BLOCK);
+ fDiskDev.Leak().mSize = sizeof(EPM_PART_BLOCK);
fDiskDev.Write((Char*) epm_boot, sizeof(EPM_PART_BLOCK));
BootTextWriter writer;
- writer.Write(L"BootZ: Drive is EPM formatted.\r");
+ writer.Write(L"BootZ: Drive is now EPM formatted.\r");
#elif defined(BOOTZ_GPT_SUPPORT)
NE_UNUSED(part_name);
@@ -317,12 +317,12 @@ inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) {
SetMem(gpt_part->Reserved2, 0, kSectorAlignGPT_PartTbl);
fDiskDev.Leak().mBase = kGPTPartitionTableLBA; // always always resies at zero block.
+
fDiskDev.Leak().mSize = sizeof(GPT_PARTITION_TABLE);
-
fDiskDev.Write((Char*) gpt_part, sizeof(GPT_PARTITION_TABLE));
BootTextWriter writer;
- writer.Write(L"BootZ: Drive is GPT formatted.\r");
+ writer.Write(L"BootZ: Drive is now GPT formatted.\r");
#else
NE_UNUSED(part_name);
#endif
diff --git a/src/boot/README.md b/src/boot/README.md
new file mode 100644
index 00000000..2468efe6
--- /dev/null
+++ b/src/boot/README.md
@@ -0,0 +1,11 @@
+# The BootZ Bootloader
+
+A multi-platform bootloader written in C++ with modules support.
+
+## Design Rationale:
+
+BootZ like NeKernel is designed to be modular and production-ready.
+
+BootZ reads a `kernel` image before trying to run it. If it fails to find one, it will summon a `bootnet` module.
+
+Error Handling is very important as well, that's why we try before commiting (see BootKit.h)
diff --git a/src/boot/amd64-ci.make b/src/boot/amd64-ci.make
index 845892fd..28017bf3 100644
--- a/src/boot/amd64-ci.make
+++ b/src/boot/amd64-ci.make
@@ -67,7 +67,7 @@ REM_FLAG=-f
FLAG_ASM=-f win64
FLAG_GNU=-fshort-wchar -Wall -Wpedantic -Wextra -Werror -D__EFI_x86_64__ -mno-red-zone -D__NEKERNEL__ -D__BOOTZ__ \
-DEFI_FUNCTION_WRAPPER -I./ -I../kernel $(DEBUG_MACRO) $(DISK_DRV) -I../ -c -nostdlib -fno-rtti -fno-exceptions \
- -std=c++20 -DBOOTZ_GPT_SUPPORT -DBOOTZ_EPM_SUPPORT -D__HAVE_NE_API__ -DZBA_USE_FB -D__NE_AMD64__ -D__NE__ -DNE_AUTO_FORMAT
+ -std=c++20 -DBOOTZ_GPT_SUPPORT -DBOOTZ_EPM_SUPPORT -D__HAVE_NE_API__ -DBOOTZ_USE_FB -D__NE_AMD64__ -D__NE__ -DNE_AUTO_FORMAT
BOOTLOADER=ne_bootz
KERNEL=ne_kernel
diff --git a/src/boot/amd64-desktop.make b/src/boot/amd64-desktop.make
index 658ef516..0854db60 100644
--- a/src/boot/amd64-desktop.make
+++ b/src/boot/amd64-desktop.make
@@ -69,7 +69,7 @@ REM_FLAG=-f
FLAG_ASM=-f win64
FLAG_GNU=-fshort-wchar -D__EFI_x86_64__ -D__nekernel_allow_non_nekernel_pe -Wall -Wpedantic -Wextra -mno-red-zone -D__NEKERNEL__ -D__BOOTZ__ -DBOOTZ_VEPM_SUPPORT \
-DEFI_FUNCTION_WRAPPER -I./ -I../kernel $(DISK_DRV) -I../ -c -nostdlib -fno-rtti -fno-exceptions \
- -std=c++20 -DBOOTZ_GPT_SUPPORT -D__HAVE_NE_API__ -DZBA_USE_FB -D__NE_AMD64__ -D__NE__ -DNE_AUTO_FORMAT -Wl,--disable-reloc-section
+ -std=c++20 -DBOOTZ_GPT_SUPPORT -D__HAVE_NE_API__ -DBOOTZ_USE_FB -D__NE_AMD64__ -D__NE__ -DNE_AUTO_FORMAT -Wl,--disable-reloc-section
BOOTLOADER=ne_bootz
KERNEL=ne_kernel
diff --git a/src/boot/arm64-desktop.make b/src/boot/arm64-desktop.make
index bd380327..55004175 100644
--- a/src/boot/arm64-desktop.make
+++ b/src/boot/arm64-desktop.make
@@ -45,7 +45,7 @@ REM_FLAG=-f
FLAG_ASM=-f win64
FLAG_GNU=-fshort-wchar -c -ffreestanding -MMD -mno-red-zone -D__NE_ARM64__ -fno-rtti -fno-exceptions -I./ \
-target aarch64-unknown-windows \
- -std=c++20 -DBOOTZ_EPM_SUPPORT -D__nekernel_allow_non_nekernel_pe -DZBA_USE_FB -D__FSKIT_USE_NEFS__ -D__BOOTZ_STANDALONE__ -D__NEKERNEL__ -D__BOOTZ__ -D__HAVE_NE_API__ -D__NE__ -I../ -I../kernel
+ -std=c++20 -DBOOTZ_EPM_SUPPORT -D__nekernel_allow_non_nekernel_pe -DBOOTZ_USE_FB -D__FSKIT_USE_NEFS__ -D__BOOTZ_STANDALONE__ -D__NEKERNEL__ -D__BOOTZ__ -D__HAVE_NE_API__ -D__NE__ -I../ -I../kernel
BOOT_LOADER=ne_bootz
KERNEL=ne_kernel
diff --git a/src/boot/modules/BootNet/.hgkeep b/src/boot/modules/BootNet/.hgkeep
deleted file mode 100644
index e69de29b..00000000
--- a/src/boot/modules/BootNet/.hgkeep
+++ /dev/null
diff --git a/src/boot/modules/BootNet/README.md b/src/boot/modules/BootNet/README.md
new file mode 100644
index 00000000..9c013d6f
--- /dev/null
+++ b/src/boot/modules/BootNet/README.md
@@ -0,0 +1,5 @@
+# BootNet
+
+This module network boots a copy of `ne_kernel` via its NetBoot protocol.
+
+This is for EFI modules only, as the NeBoot firmware already supports it.
diff --git a/src/boot/modules/BootNet/arm64.json b/src/boot/modules/BootNet/arm64.json
new file mode 100644
index 00000000..f939083e
--- /dev/null
+++ b/src/boot/modules/BootNet/arm64.json
@@ -0,0 +1,35 @@
+{
+ "compiler_path": "x86_64-w64-mingw32-g++",
+ "compiler_std": "c++20",
+ "headers_path": [
+ "../",
+ "../../",
+ "../../../kernel",
+ "../../../",
+ "./"
+ ],
+ "sources_path": [
+ "*.cpp",
+ "*.S",
+ "../../src/HEL/ARM64/*.cpp",
+ "../../src/HEL/ARM64/*.S",
+ "../../src/*.cpp"
+ ],
+ "output_name": "net.efi",
+ "compiler_flags": [
+ "-nostdlib",
+ "-std=c++20",
+ "-fno-rtti",
+ "-fno-exceptions",
+ "-Wl,--subsystem=17,--image-base,0x10000000,-e,BootNetModuleMain"
+ ],
+ "cpp_macros": [
+ "__BOOTZ__",
+ "__BOOTZ_STANDALONE__",
+ "__NE_ARM64__",
+ "__nekernel_max_cores=8 ",
+ "kBootNetVersionHighest=0x0100",
+ "kBootNetVersionLowest=0x0100",
+ "kBootNetEFIVersion=0x0100"
+ ]
+}
diff --git a/src/boot/modules/SysChk/.hgkeep b/src/boot/modules/SysChk/.hgkeep
deleted file mode 100644
index e69de29b..00000000
--- a/src/boot/modules/SysChk/.hgkeep
+++ /dev/null
diff --git a/src/boot/modules/SysChk/README.md b/src/boot/modules/SysChk/README.md
new file mode 100644
index 00000000..9c5a25e2
--- /dev/null
+++ b/src/boot/modules/SysChk/README.md
@@ -0,0 +1,5 @@
+# SysChk
+
+This module repairs an EPM or GPT partition after it's been damaged by tampering.
+
+This is for EFI only, as NeBoot support is not planned yet.
diff --git a/src/boot/modules/SysChk/SysChk.cpp b/src/boot/modules/SysChk/SysChk.cpp
index c7217504..09522b98 100644
--- a/src/boot/modules/SysChk/SysChk.cpp
+++ b/src/boot/modules/SysChk/SysChk.cpp
@@ -1,4 +1,4 @@
-// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
+// 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/ne-foss-org/nekernel
@@ -28,9 +28,11 @@ EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover) {
Boot::BDiskFormatFactory<Boot::BootDeviceATA> partition_factory;
#elif defined(__AHCI__)
Boot::BDiskFormatFactory<Boot::BootDeviceSATA> partition_factory;
+#elif defined(__NVME__)
+ Boot::BDiskFormatFactory<Boot::BootDeviceNVME> partition_factory;
#endif
- if (!partition_factory.IsPartitionValid()) return kEfiFail;
+ if (partition_factory.IsPartitionValid()) return kEfiOk;
return partition_factory.Format(kMachineModel);
}
diff --git a/src/boot/modules/SysChk/arm64-ahci-epm.json b/src/boot/modules/SysChk/arm64-ahci-epm.json
new file mode 100644
index 00000000..d73f90c3
--- /dev/null
+++ b/src/boot/modules/SysChk/arm64-ahci-epm.json
@@ -0,0 +1,49 @@
+{
+ "compiler_path": "clang++",
+ "compiler_std": "c++20",
+ "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"],
+ "sources_path": [
+ "*.cpp",
+ "*.S",
+ "../../src/HEL/ARM64/BootSATA.cpp",
+ "../../src/HEL/ARM64/BootPlatform.cpp",
+ "../../src/HEL/ARM64/BootAPI.S",
+ "../../src/BootTextWriter.cpp",
+ "../../src/BootSupport.cpp",
+ "../../src/New+Delete.cpp",
+ "../../../kernel/HALKit/ARM64/PCI/*.cpp",
+ "../../../kernel/HALKit/ARM64/Storage/*.cpp",
+ "../../../kernel/src/Storage/*.cpp",
+ "../../../kernel/src/Network/*.cpp",
+ "../../../kernel/HALKit/ARM64/*.cpp",
+ "../../../kernel/HALKit/ARM64/*.s",
+ "../../../kernel/src/*.cpp"
+ ],
+ "output_name": "chk.efi",
+ "compiler_flags": [
+ "-ffreestanding",
+ "-nostdlib",
+ "-std=c++20",
+ "-fno-rtti",
+ "-fno-exceptions",
+ "-fuse-ld=lld",
+ "-Wl,-subsystem:efi_application,-entry:BootloaderMain",
+ "-target aarch64-unknown-windows"
+ ],
+ "cpp_macros": [
+ "__NEOSKRNL__",
+ "__BOOTZ__",
+ "__BOOTZ_STANDALONE__",
+ "__NE_ARM64__",
+ "__SYSCHK__",
+ "BOOTZ_EPM_SUPPORT",
+ "__nekernel_max_cores=8",
+ "__nekernel_dma_best_align=8",
+ "__nekernel_dma_pool_start=0x1000000",
+ "__nekernel_dma_pool_size=0x1000000",
+ "__nekernel_halkit_include_processor=\"<HALKit/ARM64/Processor.h>\"",
+ "kChkVersionHighest=0x0100",
+ "kChkVersionLowest=0x0100",
+ "kChkVersion=0x0100"
+ ]
+}
diff --git a/src/boot/modules/SysChk/arm64.json b/src/boot/modules/SysChk/arm64.json
deleted file mode 100644
index 2a04c772..00000000
--- a/src/boot/modules/SysChk/arm64.json
+++ /dev/null
@@ -1,26 +0,0 @@
-{
- "compiler_path": "clang++",
- "compiler_std": "c++20",
- "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"],
- "sources_path": ["*.cpp", "*.S", "../../src/HEL/ARM64/*.cpp", "../../src/HEL/ARM64/*.S", "../../src/*.cpp"],
- "output_name": "chk.efi",
- "compiler_flags": [
- "-ffreestanding",
- "-nostdlib",
- "-std=c++20",
- "-fno-rtti",
- "-fno-exceptions",
- "-fuse-ld=lld",
- "-Wl,-subsystem:efi_application,-entry:BootloaderMain",
- "-target aarch64-unknown-windows"
- ],
- "cpp_macros": [
- "__NEOSKRNL__",
- "__BOOTZ__",
- "__BOOTZ_STANDALONE__",
- "__NE_ARM64__",
- "kChkVersionHighest=0x0100",
- "kChkVersionLowest=0x0100",
- "kChkVersion=0x0100"
- ]
-}
diff --git a/src/boot/src/HEL/AMD64/BootPlatform.cpp b/src/boot/src/HEL/AMD64/BootPlatform.cpp
index ea55625b..b8cdea2b 100644
--- a/src/boot/src/HEL/AMD64/BootPlatform.cpp
+++ b/src/boot/src/HEL/AMD64/BootPlatform.cpp
@@ -12,24 +12,14 @@
using namespace Boot;
-EXTERN_C void rt_halt() {
- asm volatile("hlt");
-}
+EXTERN_C void rt_halt() { asm volatile("hlt"); }
-EXTERN_C void rt_cli() {
- asm volatile("cli");
-}
+EXTERN_C void rt_cli() { asm volatile("cli"); }
-EXTERN_C void rt_sti() {
- asm volatile("sti");
-}
+EXTERN_C void rt_sti() { asm volatile("sti"); }
-EXTERN_C void rt_cld() {
- asm volatile("cld");
-}
+EXTERN_C void rt_cld() { asm volatile("cld"); }
-EXTERN_C void rt_std() {
- asm volatile("std");
-}
+EXTERN_C void rt_std() { asm volatile("std"); }
#endif // __BOOTZ_STANDALONE__
diff --git a/src/boot/src/HEL/ARM64/BootEFI.cpp b/src/boot/src/HEL/ARM64/BootEFI.cpp
index 872ddbab..cf27287f 100644
--- a/src/boot/src/HEL/ARM64/BootEFI.cpp
+++ b/src/boot/src/HEL/ARM64/BootEFI.cpp
@@ -15,14 +15,6 @@
#include <modules/CoreGfx/CoreGfx.h>
#include <modules/CoreGfx/TextGfx.h>
-#ifndef kExpectedWidth
-#define kExpectedWidth (800)
-#endif
-
-#ifndef kExpectedHeight
-#define kExpectedHeight (600)
-#endif
-
/** Graphics related. */
STATIC EfiGraphicsOutputProtocol* kGop = nullptr;
@@ -44,20 +36,7 @@ STATIC Bool boot_init_fb() {
kGopStride = 4;
- for (SizeT i = 0; i < kGop->Mode->MaxMode; ++i) {
- EfiGraphicsOutputProtocolModeInformation* infoPtr = nullptr;
- UInt32 sz = 0U;
-
- kGop->QueryMode(kGop, i, &sz, &infoPtr);
-
- if (infoPtr->HorizontalResolution == kExpectedWidth &&
- infoPtr->VerticalResolution == kExpectedHeight) {
- kGop->SetMode(kGop, i);
- return Yes;
- }
- }
-
- return No;
+ return Yes;
}
EXTERN EfiBootServices* BS;
@@ -71,7 +50,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa
kHandoverHeader = new HEL::BootInfoHeader();
-#ifdef ZBA_USE_FB
+#ifdef BOOTZ_USE_FB
if (!boot_init_fb()) return kEfiFail; ///! Init the GOP.
for (SizeT index_vt = 0; index_vt < sys_table->NumberOfTableEntries; ++index_vt) {
@@ -97,7 +76,7 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa
kHandoverHeader->f_GOP.f_PixelPerLine = kGop->Mode->Info->PixelsPerScanLine;
kHandoverHeader->f_GOP.f_PixelFormat = kGop->Mode->Info->PixelFormat;
kHandoverHeader->f_GOP.f_Size = kGop->Mode->FrameBufferSize;
-#endif // ZBA_USE_FB
+#endif // BOOTZ_USE_FB
// ------------------------------------------- //
// Grab MP services, extended to runtime. //
diff --git a/src/boot/src/HEL/ARM64/BootPlatform.cpp b/src/boot/src/HEL/ARM64/BootPlatform.cpp
index 0d1fb9d5..a6d619de 100644
--- a/src/boot/src/HEL/ARM64/BootPlatform.cpp
+++ b/src/boot/src/HEL/ARM64/BootPlatform.cpp
@@ -1,4 +1,4 @@
-// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
+// 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/ne-foss-org/nekernel
@@ -10,9 +10,7 @@
using namespace Boot;
-EXTERN_C void rt_halt() {
- while (Yes);
-}
+EXTERN_C void rt_halt() { while (Yes); }
EXTERN_C void rt_cli() {}