diff options
| author | Amlal <amlal@nekernel.org> | 2025-04-25 08:37:12 +0200 |
|---|---|---|
| committer | Amlal <amlal@nekernel.org> | 2025-04-25 08:37:12 +0200 |
| commit | 97f5407670a796ba41e107175f8242abba0c81cc (patch) | |
| tree | 931e6e6dc703485129769b71f4dafa5e0bfcbb2a /dev/boot | |
| parent | 2a34afdf04a5ec24d091469fa50a09882c898881 (diff) | |
dev, boot, kernel: improvements, and fixing the VEPM formatter.
Signed-off-by: Amlal <amlal@nekernel.org>
Diffstat (limited to 'dev/boot')
| -rw-r--r-- | dev/boot/BootKit/BootKit.h | 207 | ||||
| -rw-r--r-- | dev/boot/BootKit/HW/ATA.h | 2 | ||||
| -rw-r--r-- | dev/boot/modules/SysChk/SysChk.cc | 17 | ||||
| -rw-r--r-- | dev/boot/modules/SysChk/amd64-pio-epm.json | 10 | ||||
| -rw-r--r-- | dev/boot/src/BootThread.cc | 16 |
5 files changed, 71 insertions, 181 deletions
diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index 6299e27b..7b2a4f0a 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -32,6 +32,9 @@ #include <FirmwareKit/GPT.h> #include <FirmwareKit/EFI.h> +#define kBKBootFileMime "boot-x/file" +#define kBKBootDirMime "boot-x/dir" + /***********************************************************************************/ /// Framebuffer helpers. /***********************************************************************************/ @@ -184,15 +187,6 @@ namespace Boot #endif // __EFI_x86_64__ - static inline const UInt32 kRgbRed = 0x000000FF; - static inline const UInt32 kRgbGreen = 0x0000FF00; - static inline const UInt32 kRgbBlue = 0x00FF0000; - static inline const UInt32 kRgbBlack = 0x00000000; - static inline const UInt32 kRgbWhite = 0x00FFFFFF; - -#define kBKBootFileMime "boot-x/file" -#define kBKBootDirMime "boot-x/dir" - /// @brief BootKit Drive Formatter. template <typename BootDev> class BDiskFormatFactory final @@ -207,11 +201,6 @@ namespace Boot public: explicit BDiskFormatFactory() = default; - explicit BDiskFormatFactory(BootDev dev) - : fDiskDev(dev) - { - } - ~BDiskFormatFactory() = default; NE_COPY_DELETE(BDiskFormatFactory) @@ -222,18 +211,35 @@ namespace Boot /// @param blob_sz blobs array count. /// @retval True disk has been formatted. /// @retval False failed to format. - Boolean Format(const Char* part_name, BFileDescriptor* blob, SizeT blob_sz); + Boolean Format(const Char* part_name); /// @brief check if partition is good. Bool IsPartitionValid() noexcept { #if defined(BOOTZ_EPM_SUPPORT) + fDiskDev.Leak().mBase = (kEPMBootBlockLba); + fDiskDev.Leak().mSize = sizeof(EPM_PART_BLOCK); + + EPM_PART_BLOCK buf_epm = {}; + + fDiskDev.Read((Char*)&buf_epm, sizeof(EPM_PART_BLOCK)); + + if (StrCmp(buf_epm.Magic, kEPMMagic)) + { + return false; + } + + if (buf_epm.Version != kEPMRevisionBcd) + { + return false; + } + fDiskDev.Leak().mBase = (kNeFSRootCatalogStartAddress); - fDiskDev.Leak().mSize = BootDev::kSectorSize; + fDiskDev.Leak().mSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - Char buf[BootDev::kSectorSize] = {0}; + Char buf[sizeof(NEFS_ROOT_PARTITION_BLOCK)] = {0}; - fDiskDev.Read(buf, BootDev::kSectorSize); + fDiskDev.Read(buf, sizeof(NEFS_ROOT_PARTITION_BLOCK)); NEFS_ROOT_PARTITION_BLOCK* blockPart = reinterpret_cast<NEFS_ROOT_PARTITION_BLOCK*>(buf); @@ -258,55 +264,29 @@ namespace Boot return false; } - writer.Write(L"BootZ: Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); + writer.Write(L"BootZ: NeFS Partition: ").Write(blockPart->PartitionName).Write(L" is healthy.\r"); return true; #else - return false; -#endif - } + GPT_PARTITION_TABLE gpt_part{}; - private: - /// @brief Write all of the requested catalogs into the filesystem. - /// @param blob the blobs. - /// @param blob_sz the number of blobs to write (n * sizeof(blob_struct)). - /// @param part the NeFS partition block. - Boolean WriteCatalogList(BFileDescriptor* blob, SizeT blob_sz, NEFS_ROOT_PARTITION_BLOCK& part) - { - if (blob_sz < sizeof(NEFS_CATALOG_STRUCT)) - return NO; + fDiskDev.Leak().mBase = (kGPTPartitionTableLBA); + fDiskDev.Leak().mSize = sizeof(GPT_PARTITION_TABLE); - if (!blob) - return NO; + fDiskDev.Read((Char*)&gpt_part, sizeof(GPT_PARTITION_TABLE)); - Lba startLba = part.StartCatalog; BootTextWriter writer; - NEFS_CATALOG_STRUCT catalogKind{0}; - - constexpr auto cNeFSCatalogPadding = 4; - - catalogKind.PrevSibling = startLba; - catalogKind.NextSibling = (startLba + sizeof(NEFS_CATALOG_STRUCT) * cNeFSCatalogPadding); - - /// Fill catalog kind. - catalogKind.Kind = blob->fKind; - catalogKind.Flags |= kNeFSFlagCreated; - catalogKind.CatalogFlags = kNeFSStatusUnlocked; - - --part.FreeCatalog; - --part.FreeSectors; - - CopyMem(catalogKind.Name, blob->fFileName, StrLen(blob->fFileName)); - - fDiskDev.Leak().mBase = startLba; - fDiskDev.Leak().mSize = sizeof(NEFS_CATALOG_STRUCT); - - fDiskDev.Write((Char*)&catalogKind, sizeof(NEFS_CATALOG_STRUCT)); + if (StrCmp(gpt_part.Signature, kMagicGPT) == 0) + { + writer.Write("BootZ: GPT Partition found.\r"); + return true; + } - writer.Write(L"BootZ: wrote root directory: ").Write(blob->fFileName).Write(L"\r"); + writer.Write("BootZ: No Partition found.\r"); - return true; + return false; +#endif } private: @@ -320,13 +300,9 @@ namespace Boot /// @retval True disk has been formatted. /// @retval False failed to format. template <typename BootDev> - inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name, - BDiskFormatFactory::BFileDescriptor* blob, - SizeT blob_sz) + inline Boolean BDiskFormatFactory<BootDev>::Format(const Char* part_name) { - if (!blob || !blob_sz) - return false; /// sanity check - +#if defined(BOOTZ_EPM_SUPPORT) /// @note A catalog roughly equal to a sector in NeFS terms. constexpr auto kMinimumDiskSize = kNeFSMinimumDiskSize; // at minimum. @@ -344,7 +320,7 @@ namespace Boot CopyMem(part.PartitionName, part_name, StrLen(part_name)); part.Version = kNeFSVersionInteger; - part.CatalogCount = blob_sz / sizeof(NEFS_CATALOG_STRUCT); + part.CatalogCount = blob_sz; part.Kind = BootDev::kSectorSize; part.SectorSize = kATASectorSize; part.FreeCatalog = fDiskDev.GetSectorsCount() / sizeof(NEFS_CATALOG_STRUCT); @@ -363,7 +339,6 @@ namespace Boot writer << "BootZ: Free sectors: " << part.FreeSectors << "\r"; writer << "BootZ: Sector size: " << part.SectorSize << "\r"; -#if defined(BOOTZ_EPM_SUPPORT) EPM_PART_BLOCK epm_boot{}; const auto kFsName = "NeFS"; @@ -393,38 +368,36 @@ namespace Boot fDiskDev.Write((Char*)&part, sizeof(NEFS_ROOT_PARTITION_BLOCK)); writer.Write(L"BootZ: Drive is EPM formatted.\r"); -#elif defined(BOOTZ_GPT_SUPPORT) || defined(BOOTZ_VEPM_SUPPORT) +#elif defined(BOOTZ_VEPM_SUPPORT) + NE_UNUSED(part_name); + GPT_PARTITION_TABLE gpt_part{}; CopyMem(gpt_part.Signature, reinterpret_cast<VoidPtr>(const_cast<Char*>(kMagicGPT)), StrLen(kMagicGPT)); - gpt_part.Revision = 0x00010000; + gpt_part.Revision = 0x00010000; gpt_part.HeaderSize = sizeof(GPT_PARTITION_TABLE); gpt_part.CRC32 = 0x00000000; - gpt_part.Reserved1 = 0x00000000; - gpt_part.LBAHeader = 0x00000000; - gpt_part.LBAAltHeader = 0x00000000; + gpt_part.Reserved1 = 0x00000000; + gpt_part.LBAHeader = 0x00000000; + gpt_part.LBAAltHeader = 0x00000000; gpt_part.FirstGPTEntry = 0x00000000; - gpt_part.LastGPTEntry = 0x00000000; + gpt_part.LastGPTEntry = 0x00000000; -#if defined(BOOTZ_GPT_SUPPORT) gpt_part.Guid.Data1 = 0x00000000; gpt_part.Guid.Data2 = 0x0000; gpt_part.Guid.Data3 = 0x0000; SetMem(gpt_part.Guid.Data4, 0, 8); -#else - gpt_part.Guid = kVEPMGuidEFI; -#endif gpt_part.Revision = 0x00010000; - gpt_part.StartingLBA = 0x00000000; + gpt_part.StartingLBA = 0x00000000; gpt_part.NumPartitionEntries = 0x00000000; - gpt_part.SizeOfEntries = 0x00000000; - gpt_part.CRC32PartEntry = 0x00000000; + gpt_part.SizeOfEntries = 0x00000000; + gpt_part.CRC32PartEntry = 0x00000000; SetMem(gpt_part.Reserved2, 0, kSectorAlignGPT_PartTbl); @@ -433,84 +406,8 @@ namespace Boot fDiskDev.Write((Char*)&gpt_part, sizeof(GPT_PARTITION_TABLE)); -#if defined(BOOTZ_VEPM_SUPPORT) - const auto kBlockName = "OS (VEPM)"; - - GPT_PARTITION_ENTRY gpt_part_entry{}; - - gpt_part_entry.StartLBA = kNeFSRootCatalogStartAddress; - gpt_part_entry.EndLBA = fDiskDev.GetDiskSize(); - gpt_part_entry.Attributes = 0x00000000; - - gpt_part_entry.PartitionTypeGUID.Data1 = 0x00000000; - gpt_part_entry.PartitionTypeGUID.Data2 = 0x0000; - gpt_part_entry.PartitionTypeGUID.Data3 = 0x0000; - - CopyMem(gpt_part_entry.Name, reinterpret_cast<VoidPtr>(const_cast<Char*>(kBlockName)), StrLen(kBlockName)); - - SetMem(gpt_part_entry.PartitionTypeGUID.Data4, 0, 8); - - EPM_PART_BLOCK epm_boot{}; - - const auto kFsName = "NeFS"; - - epm_boot.FsVersion = kNeFSVersionInteger; - epm_boot.LbaStart = kNeFSRootCatalogStartAddress; - epm_boot.LbaEnd = fDiskDev.GetDiskSize(); - epm_boot.SectorSz = part.SectorSize; - epm_boot.Kind = kEPMNeKernel; - epm_boot.NumBlocks = part.CatalogCount; - - epm_boot.Guid = kEPMNilGuid; - - CopyMem(epm_boot.Fs, reinterpret_cast<VoidPtr>(const_cast<Char*>(kFsName)), StrLen(kFsName)); - CopyMem(epm_boot.Name, reinterpret_cast<VoidPtr>(const_cast<Char*>(kBlockName)), StrLen(kBlockName)); - CopyMem(epm_boot.Magic, reinterpret_cast<VoidPtr>(const_cast<Char*>(kEPMMagic)), StrLen(kEPMMagic)); - - fDiskDev.Leak().mBase = kGPTPartitionTableLBA + sizeof(GPT_PARTITION_TABLE); - fDiskDev.Leak().mSize = sizeof(GPT_PARTITION_ENTRY); - - fDiskDev.Write((Char*)&gpt_part_entry, sizeof(GPT_PARTITION_ENTRY)); - - fDiskDev.Leak().mBase = gpt_part_entry.StartLBA; - fDiskDev.Leak().mSize = sizeof(EPM_PART_BLOCK); - - fDiskDev.Write((Char*)&epm_boot, sizeof(EPM_PART_BLOCK)); - - fDiskDev.Leak().mBase = gpt_part_entry.StartLBA + kNeFSRootCatalogStartAddress; - fDiskDev.Leak().mSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - - fDiskDev.Write((Char*)&part, sizeof(NEFS_ROOT_PARTITION_BLOCK)); - - writer.Write(L"BootZ: Drive is vEPM formatted.\r"); -#else - const auto kBlockName = "OS (GPT)"; - - GPT_PARTITION_ENTRY gpt_part_entry{0}; - - gpt_part_entry.StartLBA = kNeFSRootCatalogStartAddress; - gpt_part_entry.EndLBA = fDiskDev.GetDiskSize(); - gpt_part_entry.Attributes = 0x00000000; - - gpt_part_entry.PartitionTypeGUID.Data1 = 0x00000000; - gpt_part_entry.PartitionTypeGUID.Data2 = 0x0000; - gpt_part_entry.PartitionTypeGUID.Data3 = 0x0000; - - CopyMem(gpt_part_entry.Name, reinterpret_cast<VoidPtr>(const_cast<Char*>(kBlockName)), StrLen(kBlockName)); - - SetMem(gpt_part_entry.PartitionTypeGUID.Data4, 0, 8); - - fDiskDev.Leak().mBase = kGPTPartitionTableLBA + sizeof(GPT_PARTITION_TABLE); - fDiskDev.Leak().mSize = sizeof(GPT_PARTITION_ENTRY); - fDiskDev.Write((Char*)&gpt_part_entry, sizeof(GPT_PARTITION_ENTRY)); - - fDiskDev.Leak().mBase = gpt_part_entry.StartLBA; - fDiskDev.Leak().mSize = sizeof(NEFS_ROOT_PARTITION_BLOCK); - - fDiskDev.Write((Char*)&part, sizeof(NEFS_ROOT_PARTITION_BLOCK)); - + BootTextWriter writer; writer.Write(L"BootZ: Drive is GPT formatted.\r"); -#endif /// defined(BOOTZ_VEPM_SUPPORT) #endif return YES; diff --git a/dev/boot/BootKit/HW/ATA.h b/dev/boot/BootKit/HW/ATA.h index cc5e1166..56393125 100644 --- a/dev/boot/BootKit/HW/ATA.h +++ b/dev/boot/BootKit/HW/ATA.h @@ -23,8 +23,6 @@ public: explicit BootDeviceATA() noexcept; ~BootDeviceATA() = default; - NE_COPY_DELETE(BootDeviceATA) - enum { kSectorSize = kATASectorSize diff --git a/dev/boot/modules/SysChk/SysChk.cc b/dev/boot/modules/SysChk/SysChk.cc index 16684666..032c031d 100644 --- a/dev/boot/modules/SysChk/SysChk.cc +++ b/dev/boot/modules/SysChk/SysChk.cc @@ -28,29 +28,18 @@ EXTERN_C Int32 SysChkModuleMain(Kernel::HEL::BootInfoHeader* handover) { - NE_UNUSED(handover); - #if defined(__ATA_PIO__) fw_init_efi((EfiSystemTable*)handover->f_FirmwareCustomTables[1]); Boot::BDiskFormatFactory<BootDeviceATA> partition_factory; if (partition_factory.IsPartitionValid()) - return kEfiFail; - - Boot::BDiskFormatFactory<BootDeviceATA>::BFileDescriptor desc{}; - - desc.fFileName[0] = '/'; - desc.fFileName[1] = 0; - desc.fKind = kNeFSCatalogKindDir; - - partition_factory.Format(kMachineModel, &desc, 1); - - if (partition_factory.IsPartitionValid()) return kEfiOk; - return kEfiFail; + return partition_factory.Format(kMachineModel) == YES; #else + NE_UNUSED(handover); + return kEfiOk; #endif } diff --git a/dev/boot/modules/SysChk/amd64-pio-epm.json b/dev/boot/modules/SysChk/amd64-pio-epm.json index ccbb7d04..14a804d0 100644 --- a/dev/boot/modules/SysChk/amd64-pio-epm.json +++ b/dev/boot/modules/SysChk/amd64-pio-epm.json @@ -1,7 +1,13 @@ { "compiler_path": "x86_64-w64-mingw32-g++", "compiler_std": "c++20", - "headers_path": ["../", "../../", "../../../kernel", "../../../", "./"], + "headers_path": [ + "../", + "../../", + "../../../kernel", + "../../../", + "./" + ], "sources_path": [ "*.cc", "*.S", @@ -31,4 +37,4 @@ "kChkVersionLowest=0x0100", "kChkVersion=0x0100" ] -} +}
\ No newline at end of file diff --git a/dev/boot/src/BootThread.cc b/dev/boot/src/BootThread.cc index efbacc32..b6236df8 100644 --- a/dev/boot/src/BootThread.cc +++ b/dev/boot/src/BootThread.cc @@ -190,22 +190,22 @@ namespace Boot if (own_stack) { - writer.Write("BootZ: Using own stack.\r"); + writer.Write("BootZ: Using it's own stack.\r"); writer.Write("BootZ: Stack address: ").Write((UIntPtr)&fStack[mib_cast(16) - 1]).Write("\r"); writer.Write("BootZ: Stack size: ").Write(mib_cast(16)).Write("\r"); auto ret = rt_jump_to_address(fStartAddress, fHandover, &fStack[mib_cast(16) - 1]); + + // we don't need the stack anymore. + + delete[] fStack; + fStack = nullptr; + return ret; } else { - delete[] fStack; - fStack = nullptr; - // we don't need the stack anymore. - - BootTextWriter writer; - - writer.Write("BootZ: Using EFI stack.\r"); + writer.Write("BootZ: Using Bootloader's stack.\r"); return reinterpret_cast<HEL::HandoverProc>(fStartAddress)(fHandover); } |
