From 1e8b22f34ce423b23d1b4c4ea59ed16aa29842d8 Mon Sep 17 00:00:00 2001 From: Amlal Date: Thu, 1 May 2025 11:59:48 +0200 Subject: tooling, fs: Improve tooling and clean up HeFS filesystem code. Signed-off-by: Amlal --- dev/boot/BootKit/BootKit.h | 1 + dev/boot/src/HEL/AMD64/BootEFI.cc | 17 +- dev/kernel/src/FS/HeFS.cc | 9 - tooling/mk_fwrk.py | 16 +- tooling/mk_img.py | 6 +- tooling/mkfs.h | 36 +++ tooling/mkfs.hefs.cc | 62 ++--- tooling/rang.h | 502 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 586 insertions(+), 63 deletions(-) create mode 100644 tooling/mkfs.h create mode 100644 tooling/rang.h diff --git a/dev/boot/BootKit/BootKit.h b/dev/boot/BootKit/BootKit.h index 5f4a65c4..3f871b9a 100644 --- a/dev/boot/BootKit/BootKit.h +++ b/dev/boot/BootKit/BootKit.h @@ -148,6 +148,7 @@ class BootFileReader final { typedef UInt8* BlobType; +/// @brief Bootloader Version String. class BVersionString final { public: static const CharacterTypeUTF8* The() { return BOOTLOADER_VERSION; } diff --git a/dev/boot/src/HEL/AMD64/BootEFI.cc b/dev/boot/src/HEL/AMD64/BootEFI.cc index ffc3c692..260d7c00 100644 --- a/dev/boot/src/HEL/AMD64/BootEFI.cc +++ b/dev/boot/src/HEL/AMD64/BootEFI.cc @@ -199,15 +199,15 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa // Assign to global 'kHandoverHeader'. WideChar kernel_path[256U] = L"krnl.efi"; - UInt32 kernel_path_sz = 256U; + UInt32 kernel_path_sz = StrLen("krnl.efi"); - if (ST->RuntimeServices->GetVariable(L"/props/boot_path", kEfiGlobalNamespaceVarGUID, nullptr, + if (ST->RuntimeServices->GetVariable(L"/props/kernel_path", kEfiGlobalNamespaceVarGUID, nullptr, &kernel_path_sz, kernel_path) != kEfiOk) { /// access attributes (in order) /// EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS UInt32 attr = 0x00000001 | 0x00000002 | 0x00000004; - ST->RuntimeServices->SetVariable(L"/props/boot_path", kEfiGlobalNamespaceVarGUID, &attr, + ST->RuntimeServices->SetVariable(L"/props/kernel_path", kEfiGlobalNamespaceVarGUID, &attr, &kernel_path_sz, kernel_path); } @@ -217,17 +217,18 @@ EFI_EXTERN_C EFI_API Int32 BootloaderMain(EfiHandlePtr image_handle, EfiSystemTa ST->RuntimeServices->GetVariable(L"/props/kern_ver", kEfiGlobalNamespaceVarGUID, nullptr, &sz_ver, &ver); - if (ver != KERNEL_VERSION_BCD) { + if (ver < KERNEL_VERSION_BCD) { ver = KERNEL_VERSION_BCD; ST->RuntimeServices->SetVariable(L"/props/kern_ver", kEfiGlobalNamespaceVarGUID, nullptr, &sz_ver, &ver); - writer.Write("BootZ: version has been updated: ").Write(ver).Write("\r"); - } - writer.Write("BootZ: version: ").Write(ver).Write("\r"); + writer.Write("BootZ: Version has been updated: ").Write(ver).Write("\r"); + } else { + writer.Write("BootZ: Version: ").Write(ver).Write("\r"); + } - // boot to kernel, if not netboot this. + // boot to kernel, if not bootnet this. Boot::BootFileReader reader_kernel(kernel_path, image_handle); diff --git a/dev/kernel/src/FS/HeFS.cc b/dev/kernel/src/FS/HeFS.cc index 2f5bb55d..89415ee5 100644 --- a/dev/kernel/src/FS/HeFS.cc +++ b/dev/kernel/src/FS/HeFS.cc @@ -825,8 +825,6 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu const Utf8Char* dir) { HEFS_BOOT_NODE* root = (HEFS_BOOT_NODE*) mm_new_heap(sizeof(HEFS_BOOT_NODE), Yes, No); - kout << "CreateDirectory...\r"; - rt_copy_memory((VoidPtr) "fs/hefs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/hefs-packet")); @@ -870,16 +868,9 @@ _Output Bool HeFileSystemParser::CreateDirectory(_Input DriveTrait* drive, _Inpu /// @return If it was sucessful, see err_local_get(). _Output Bool HeFileSystemParser::CreateFile(_Input DriveTrait* drive, _Input const Int32 flags, const Utf8Char* dir, const Utf8Char* name) { - NE_UNUSED(drive); - NE_UNUSED(flags); - NE_UNUSED(dir); - NE_UNUSED(name); - HEFS_INDEX_NODE* node = (HEFS_INDEX_NODE*) RTL_ALLOCA(sizeof(HEFS_INDEX_NODE)); HEFS_BOOT_NODE* root = (HEFS_BOOT_NODE*) RTL_ALLOCA(sizeof(HEFS_BOOT_NODE)); - kout << "CreateFile...\r"; - rt_copy_memory((VoidPtr) "fs/hefs-packet", drive->fPacket.fPacketMime, rt_string_len("fs/hefs-packet")); diff --git a/tooling/mk_fwrk.py b/tooling/mk_fwrk.py index 5f519237..e0302754 100755 --- a/tooling/mk_fwrk.py +++ b/tooling/mk_fwrk.py @@ -9,6 +9,9 @@ def create_directory_structure(base_path, project_name): # Define the directory structure structure = { project_name: { + "dist": { + ".keep": None + }, "src": { ".keep": None }, @@ -39,7 +42,7 @@ def create_directory_structure(base_path, project_name): # Create the JSON file diutil_json_path = os.path.join(base_path, project_name, f"{project_name}.json") manifest = { - "compiler_path": "g++", + "compiler_path": "clang++", "compiler_std": "c++20", "headers_path": ["./", "../../../dev/kernel", "../../../public/frameworks/", "../../../dev/", "./"], "sources_path": [ @@ -47,9 +50,9 @@ def create_directory_structure(base_path, project_name): ], "output_name": f"./dist/{project_name}", "cpp_macros": [ - "kSampleVersion=0x0100", - "kSampleVersionHighest=0x0100", - "kSampleVersionLowest=0x0100", + "kSampleFWVersion=0x0100", + "kSampleFWVersionHighest=0x0100", + "kSampleFWVersionLowest=0x0100", "__NE_SDK__" ] } @@ -60,8 +63,9 @@ def create_directory_structure(base_path, project_name): if __name__ == "__main__": if len(sys.argv) != 2: print("Usage: mk_fwrk.py ") - sys.exit(1) + sys.exit(os.EX_CONFIG) base_path = os.getcwd() # Use the current working directory as the base path create_directory_structure(base_path, sys.argv[1]) - print("Ne application created successfully.") \ No newline at end of file + + print("NeKernel framework created successfully.") diff --git a/tooling/mk_img.py b/tooling/mk_img.py index 4a663bc0..8227a217 100755 --- a/tooling/mk_img.py +++ b/tooling/mk_img.py @@ -33,7 +33,7 @@ def copy_to_fat(image_path, source_dir): print(f"Error: mcopy failed with error code {e.returncode}.") sys.exit(1) except Exception as e: - print(f"Error: mcopy: {e}") + print(f"Error: failed: {e}") sys.exit(1) if __name__ == "__main__": @@ -44,4 +44,6 @@ if __name__ == "__main__": image_path = sys.argv[1] source_dir = sys.argv[2] - copy_to_fat(image_path, source_dir) \ No newline at end of file + copy_to_fat(image_path, source_dir) + + print("NeKernel image created successfully.") diff --git a/tooling/mkfs.h b/tooling/mkfs.h new file mode 100644 index 00000000..650261db --- /dev/null +++ b/tooling/mkfs.h @@ -0,0 +1,36 @@ +/* ------------------------------------------- + + Copyright (C) 2025, Amlal El Mahrouss, all rights reserved. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include + +/// @internal +namespace mkfs { +/// @brief Helper function to get the option value from command line arguments. +template +inline std::basic_string get_option(const std::basic_string& args, + const std::basic_string& option) { + size_t pos = args.find(option + CharType('=')); + + if (pos != std::string::npos) { + size_t start = pos + option.length() + 1; + size_t end = args.find(' ', start); + return args.substr(start, end - start); + } + + return std::basic_string{}; +} + +inline auto console_out() -> std::ostream& { + std::ostream& conout = std::cout; + conout << rang::fg::red << "mkfs: " << rang::style::reset; + + return conout; +} +} // namespace mkfs \ No newline at end of file diff --git a/tooling/mkfs.hefs.cc b/tooling/mkfs.hefs.cc index f19f1571..d9928858 100644 --- a/tooling/mkfs.hefs.cc +++ b/tooling/mkfs.hefs.cc @@ -5,28 +5,9 @@ ------------------------------------------- */ #include +#include #include #include -#include -#include - -/// @internal -namespace mkfs::detail { -/// @brief Helper function to get the option value from command line arguments. -template -static std::basic_string get_option(const std::basic_string& args, - const std::basic_string& option) { - size_t pos = args.find(option + CharType('=')); - - if (pos != std::string::npos) { - size_t start = pos + option.length() + 1; - size_t end = args.find(' ', start); - return args.substr(start, end - start); - } - - return std::basic_string{}; -} -} // namespace mkfs::detail static size_t kDiskSize = 1024 * 1024 * 1024 * 4UL; static uint16_t kVersion = kHeFSVersion; @@ -35,10 +16,11 @@ static size_t kSectorSize = 512; int main(int argc, char** argv) { if (argc < 2) { - std::cerr << "mkfs.hefs: Error: Missing required arguments." << std::endl; - std::cerr << "mkfs.hefs: Usage: mkfs.hefs -L