From 65e428a5a2b4eac24cccf5defe64d52faba8304d Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sun, 23 Jun 2024 00:59:10 +0200 Subject: Kernel: See below. MHR-35: Implement it. Kernel: Write EPM header at sector 0. Signed-off-by: Amlal El Mahrouss --- Boot/BootKit/BootKit.hxx | 33 ++++++++++++++++++++++++++++----- Boot/BootKit/Vendor/Support.hxx | 2 -- 2 files changed, 28 insertions(+), 7 deletions(-) (limited to 'Boot/BootKit') diff --git a/Boot/BootKit/BootKit.hxx b/Boot/BootKit/BootKit.hxx index 77943a10..3eeb8633 100644 --- a/Boot/BootKit/BootKit.hxx +++ b/Boot/BootKit/BootKit.hxx @@ -12,12 +12,13 @@ #pragma once #include +#include #include /// include NewFS header and Support header as well. -#include #include +#include #include /***********************************************************************************/ @@ -215,7 +216,7 @@ public: /// @brief check if partition is good. Bool IsPartitionValid() noexcept { - fDiskDev.Leak().mBase = (kNewFSAddressAsLba); + fDiskDev.Leak().mBase = (kNewFSStartLba); fDiskDev.Leak().mSize = BootDev::kSectorSize; Char buf[BootDev::kSectorSize] = {0}; @@ -284,7 +285,7 @@ private: EFI::ThrowError(L"Developer-Error", L"This is caused by the developer of the bootloader."); } - writer.Write((catalogKind->Kind == kNewFSCatalogKindFile) ? L"newosldr: Write-File: " : L"newosldr: Write-Directory: ").Write(blob->fFileName).Write(L"\r"); + writer.Write(L"newosldr: root directory: ").Write(blob->fFileName).Write(L"\r"); memcpy(catalogKind->Name, blob->fFileName, strlen(blob->fFileName)); @@ -354,13 +355,35 @@ inline Boolean BDiskFormatFactory::Format(const char* partName, /// if we can write a root catalog, then write the partition block. if (this->WriteRootCatalog(fileBlobs, blobCount, *partBlock)) { - fDiskDev.Leak().mBase = kNewFSAddressAsLba; + fDiskDev.Leak().mBase = kNewFSStartLba; fDiskDev.Leak().mSize = sectorSz; fDiskDev.Write(buf, sectorSz); + /// Reset buffer. + SetMem(buf, 0, sectorSz); + + BootBlockType* epmBoot = (BootBlockType*)buf; + + constexpr auto cFsName = "NewFS"; + + CopyMem(reinterpret_cast(const_cast(cFsName)), epmBoot->Fs, StrLen(cFsName)); + + epmBoot->FsVersion = kNewFSVersionInteger; + epmBoot->LbaStart = kNewFSStartLba; + epmBoot->SectorSz = partBlock->SectorSize; + epmBoot->NumBlocks = partBlock->CatalogCount; + + CopyMem(reinterpret_cast(const_cast("BOOT:")), epmBoot->Name, StrLen("BOOT:")); + CopyMem(reinterpret_cast(const_cast(kEPMMagic)), epmBoot->Magic, StrLen(kEPMMagic)); + BTextWriter writer; - writer.Write(L"newosldr: Write-Partition: OK.\r"); + writer.Write(L"newosldr: wrote parition.\r"); + + fDiskDev.Leak().mBase = kEpmBase; + fDiskDev.Leak().mSize = sectorSz; + + fDiskDev.Write(buf, sectorSz); return true; } diff --git a/Boot/BootKit/Vendor/Support.hxx b/Boot/BootKit/Vendor/Support.hxx index eed59424..54183558 100644 --- a/Boot/BootKit/Vendor/Support.hxx +++ b/Boot/BootKit/Vendor/Support.hxx @@ -9,8 +9,6 @@ /// @file Support.hxx /// @brief Purpose of this file is to help port libs into the bootloader. -#include - #define cLongMax ((long)(~0UL >> 1)) #define cLongMin (~cLongMax) -- cgit v1.2.3