réplica de
https://github.com/Arnau478/quark.git
synced 2024-11-23 04:48:06 +01:00
Initrd multiboot module
This commit is contained in:
pare
b3bdd7a2e3
commit
f23e5e8ced
S'han modificat 13 arxius amb 48 adicions i 97 eliminacions
3
Makefile
3
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
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
menuentry "Quark" {
|
||||
echo "Booting quark..."
|
||||
multiboot /boot/kernel.bin
|
||||
module /boot/initrd.tar
|
||||
}
|
||||
|
|
|
@ -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 |
|
3
scripts/initrd.mk
Normal file
3
scripts/initrd.mk
Normal file
|
@ -0,0 +1,3 @@
|
|||
.PHONY: initrd
|
||||
initrd:
|
||||
@tar -cf $(BUILD_DIR)/initrd.tar -C src/initrd .
|
|
@ -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
|
||||
|
|
1
src/initrd/trumpet.txt
Normal file
1
src/initrd/trumpet.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Toot toot
|
13
src/kernel/drivers/initrd.c
Normal file
13
src/kernel/drivers/initrd.c
Normal file
|
@ -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;
|
||||
}
|
6
src/kernel/drivers/initrd.h
Normal file
6
src/kernel/drivers/initrd.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void initrd_set_addr(uint8_t *addr);
|
||||
uint8_t *initrd_get_addr();
|
|
@ -1,3 +0,0 @@
|
|||
#include "qrofs.h"
|
||||
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#define QROFS_FILE 0x01
|
||||
#define QROFS_DIRECTORY 0x02
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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]} <command>")
|
||||
print("Commands:")
|
||||
print(" create <file> <directory> | create a QROFS disk image file from a directory")
|
||||
print(" extract <file> <directory> | extract the QROFS disk image file contents into a directory")
|
||||
elif sys.argv[1] == "create":
|
||||
if len(sys.argv) != 4:
|
||||
print("Usage: create <file> <directory>")
|
||||
else:
|
||||
create(sys.argv[2], sys.argv[3])
|
||||
|
||||
if(__name__ == "__main__"):
|
||||
main()
|
Loading…
Referencia en una nova incidència