diff --git a/Makefile b/Makefile index 946a0e5..fff465f 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,8 @@ .PHONY: quark -quark: build-dir kernel iso +quark: build-dir initrd kernel iso include config/.conf +include scripts/initrd.mk include scripts/toolchain.mk include scripts/kernel.mk include scripts/run.mk diff --git a/config/grub.cfg b/config/grub.cfg index cf33aa5..fd81578 100644 --- a/config/grub.cfg +++ b/config/grub.cfg @@ -1,3 +1,5 @@ menuentry "Quark" { + echo "Booting quark..." multiboot /boot/kernel.bin + module /boot/initrd.tar } diff --git a/docs/qrofs.md b/docs/qrofs.md deleted file mode 100644 index 12b5a3d..0000000 --- a/docs/qrofs.md +++ /dev/null @@ -1,35 +0,0 @@ -# QROFS - Quark Read-Only File System - -QROFS is the FS used by Quark's ramdisk VFS - - - Read-only (cannot write/delete/create/rename files) - - Subdirectory support - - File size limit: 2^32 bytes - - File name limit: 255 characters - - File name validation: ASCII only - - File name case sensitivity: case-sensitive - - Maximum files per directory: 255 - -## At a byte level - -NOTE: Everything is stored in little-endian format, unless otherwise noted - -### QROFS directory - -| Bits | Description | -|-|-| -| 8 | Header (`0x02` for directories) | -| 8 | Name length | -| 8*n | The directory name itself - n is the name length | -| 8 | Number of child nodes | -| ? | Child nodes | - -### QROFS file - -| Bits | Description | -|-|-| -| 8 | Header (`0x01` for files) | -| 8 | Name length | -| 8*n | The file name itself - n is the name length | -| 32 | File size | -| 8*n | File data | diff --git a/scripts/initrd.mk b/scripts/initrd.mk new file mode 100644 index 0000000..d773b23 --- /dev/null +++ b/scripts/initrd.mk @@ -0,0 +1,3 @@ +.PHONY: initrd +initrd: + @tar -cf $(BUILD_DIR)/initrd.tar -C src/initrd . diff --git a/scripts/iso.mk b/scripts/iso.mk index e4c12b6..52f2239 100644 --- a/scripts/iso.mk +++ b/scripts/iso.mk @@ -3,4 +3,5 @@ iso: @mkdir -p build/iso/boot/grub @cp build/kernel.bin build/iso/boot/kernel.bin @cp config/grub.cfg build/iso/boot/grub/grub.cfg + @cp build/initrd.tar build/iso/boot/initrd.tar @grub-mkrescue -o build/quark.iso build/iso diff --git a/src/initrd/trumpet.txt b/src/initrd/trumpet.txt new file mode 100644 index 0000000..c76d2ac --- /dev/null +++ b/src/initrd/trumpet.txt @@ -0,0 +1 @@ +Toot toot diff --git a/src/kernel/drivers/initrd.c b/src/kernel/drivers/initrd.c new file mode 100644 index 0000000..4d22f91 --- /dev/null +++ b/src/kernel/drivers/initrd.c @@ -0,0 +1,13 @@ +#include "../lib/debug.h" +#include "initrd.h" + +static uint8_t *_initrd_addr; + +void initrd_set_addr(uint8_t *addr){ + debug_printf("Initrd addr set to %x\n", addr); + _initrd_addr = addr; +} + +uint8_t *initrd_get_addr(){ + return _initrd_addr; +} diff --git a/src/kernel/drivers/initrd.h b/src/kernel/drivers/initrd.h new file mode 100644 index 0000000..0913481 --- /dev/null +++ b/src/kernel/drivers/initrd.h @@ -0,0 +1,6 @@ +#pragma once + +#include + +void initrd_set_addr(uint8_t *addr); +uint8_t *initrd_get_addr(); diff --git a/src/kernel/fs/qrofs.c b/src/kernel/fs/qrofs.c deleted file mode 100644 index d0fe829..0000000 --- a/src/kernel/fs/qrofs.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "qrofs.h" - - diff --git a/src/kernel/fs/qrofs.h b/src/kernel/fs/qrofs.h deleted file mode 100644 index e6c6187..0000000 --- a/src/kernel/fs/qrofs.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -#define QROFS_FILE 0x01 -#define QROFS_DIRECTORY 0x02 diff --git a/src/kernel/main.c b/src/kernel/main.c index e41e353..bb3e1e3 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -3,6 +3,7 @@ #include "hal/hal.h" #include "drivers/keyboard.h" #include "drivers/uart.h" +#include "drivers/initrd.h" #include "fs/vfs.h" #include "arch/i686/mm/pmm.h" #include "arch/i686/mm/vmm.h" @@ -51,6 +52,18 @@ void __attribute__((cdecl)) kmain(multiboot_info_t *multiboot_info){ i686_fdc_set_working_drive(0); i686_fdc_initialize(); + debug_printf("Multiboot modules: (%d)\n", multiboot_info->mods_count); + if(multiboot_info->mods_count == 1){ + debug_printf("Loading initrd...\n"); + multiboot_module_t *module; + module = (multiboot_module_t *)multiboot_info->mods_addr; + debug_printf("Initrd module structure: start=0x%x end=0x%x cmdline=%s\n", module->start, module->end, module->cmdline); + debug_printf("%d\n", module->start); + } + else{ + debug_printf("WARNING: mods_count is not 1, not loading the initrd"); + } + // Initialize FS vfs_initialize(); diff --git a/src/kernel/multiboot.h b/src/kernel/multiboot.h index c988051..0755925 100644 --- a/src/kernel/multiboot.h +++ b/src/kernel/multiboot.h @@ -25,6 +25,13 @@ typedef struct{ uint32_t shndx; } multiboot_elf_section_header_table_t; +typedef struct{ + uint32_t start; + uint32_t end; + uint32_t cmdline; + uint32_t pad; // Padding, alwys zero +} multiboot_module_t; + typedef struct{ /* Multiboot info version number */ uint32_t flags; diff --git a/tools/qrofs-util.py b/tools/qrofs-util.py deleted file mode 100755 index 8564089..0000000 --- a/tools/qrofs-util.py +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env python3 - -import sys -import os -import struct - -def create(file_name, dir_name): - if not os.path.exists(dir_name): - print(f"ERROR: {dir_name} does not exist") - exit(1) - - out_fd = open(file_name, "wb+") - - def create_file(name, path): - out_fd.write(bytes([0x01])) # file - out_fd.write(bytes([len(name)])) # name length - out_fd.write(name.encode("ascii")) # name - fd = open(path, "rb") - file_content = fd.read() - fd.close() - out_fd.write(struct.pack("I", len(file_content))) # file size - out_fd.write(file_content) # file data - - def create_directory(name, path): - out_fd.write(bytes([0x02])) # directory - out_fd.write(bytes([len(name)])) # name length - out_fd.write(name.encode("ascii")) # name - child_nodes = os.listdir(path) - out_fd.write(bytes([len(child_nodes)])) # child count - for child in child_nodes: - if(os.path.isdir(os.path.join(path, child))): - create_directory(child, os.path.join(path, child)) - else: - create_file(child, os.path.join(path, child)) - - create_directory("", dir_name) # root directory has no name - - out_fd.close() - - -def main(): - if len(sys.argv) <= 1: - print(f"Usage: {sys.argv[0]} ") - print("Commands:") - print(" create | create a QROFS disk image file from a directory") - print(" extract | extract the QROFS disk image file contents into a directory") - elif sys.argv[1] == "create": - if len(sys.argv) != 4: - print("Usage: create ") - else: - create(sys.argv[2], sys.argv[3]) - -if(__name__ == "__main__"): - main()