Parse ramdisk tar file
This commit is contained in:
3
Makefile
3
Makefile
@ -4,11 +4,12 @@ include build/make.help
|
|||||||
srctree := $(PWD)
|
srctree := $(PWD)
|
||||||
|
|
||||||
include platform/make.$(platform)
|
include platform/make.$(platform)
|
||||||
|
include distrib/make.distrib
|
||||||
|
|
||||||
kernel:
|
kernel:
|
||||||
$(make) -C $(srctree)/kernel srctree=$(srctree) all
|
$(make) -C $(srctree)/kernel srctree=$(srctree) all
|
||||||
|
|
||||||
clean: platform_clean
|
clean: platform_clean distrib_clean
|
||||||
$(make) -C $(srctree)/kernel srctree=$(srctree) clean
|
$(make) -C $(srctree)/kernel srctree=$(srctree) clean
|
||||||
|
|
||||||
.hidden:
|
.hidden:
|
||||||
|
|||||||
1
distrib/etc/file.txt
Normal file
1
distrib/etc/file.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Hello file
|
||||||
8
distrib/make.distrib
Normal file
8
distrib/make.distrib
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
distrib_prepare:
|
||||||
|
tar -cvf $(srctree)/out/ramdisk.tar -C $(srctree)/distrib .
|
||||||
|
|
||||||
|
distrib_clean:
|
||||||
|
rm -f $(srctree)/out/ramdisk.tar
|
||||||
|
|
||||||
|
.PHONY: distrib_prepare distrib_clean
|
||||||
@ -7,3 +7,4 @@ include libk/make.src
|
|||||||
include sync/make.src
|
include sync/make.src
|
||||||
include mm/make.src
|
include mm/make.src
|
||||||
include irq/make.src
|
include irq/make.src
|
||||||
|
include ramdisk/make.src
|
||||||
|
|||||||
@ -43,6 +43,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <mm/bba.h>
|
#include <mm/bba.h>
|
||||||
#include <mm/liballoc.h>
|
#include <mm/liballoc.h>
|
||||||
#include <mm/mregmap.h>
|
#include <mm/mregmap.h>
|
||||||
|
#include <ramdisk/tar.h>
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
extern byte_t __kernel_end;
|
extern byte_t __kernel_end;
|
||||||
@ -94,9 +95,17 @@ static void mregmap_init1(void) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pmm_init1(void) {
|
static void ramdisk_init(void) {
|
||||||
struct multiboot *mb = multiboot_get();
|
struct multiboot *mb = multiboot_get();
|
||||||
|
|
||||||
|
/* TODO: for now we assert that the first module is the ramdisk */
|
||||||
|
struct multiboot_mod_list *module = (struct multiboot_mod_list *)((uptr_t)mb->mods_addr + VIRT_BASE);
|
||||||
|
uptr_t module_start = (uptr_t)module->mod_start + VIRT_BASE;
|
||||||
|
usize_t total = tar_parse(module_start);
|
||||||
|
dbgf("ramdisk: total=%zu\n", total);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pmm_init1(void) {
|
||||||
struct mreg *avail_ram = mregmap_first_avail();
|
struct mreg *avail_ram = mregmap_first_avail();
|
||||||
|
|
||||||
usize_t usable_ram_bytes = avail_ram->size;
|
usize_t usable_ram_bytes = avail_ram->size;
|
||||||
@ -135,6 +144,7 @@ void bootmain(void *mbootptr) {
|
|||||||
pmm_init1();
|
pmm_init1();
|
||||||
bba_init();
|
bba_init();
|
||||||
mm_init();
|
mm_init();
|
||||||
|
ramdisk_init();
|
||||||
pit_init();
|
pit_init();
|
||||||
|
|
||||||
__asm__ volatile("sti");
|
__asm__ volatile("sti");
|
||||||
|
|||||||
1
kernel/ramdisk/.gitignore
vendored
Normal file
1
kernel/ramdisk/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
*.o
|
||||||
5
kernel/ramdisk/make.src
Normal file
5
kernel/ramdisk/make.src
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
dir_tar1 := $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))
|
||||||
|
|
||||||
|
c_files += $(dir_tar1)/tar.c
|
||||||
|
|
||||||
|
o_files += $(dir_tar1)/tar.o
|
||||||
68
kernel/ramdisk/tar.c
Normal file
68
kernel/ramdisk/tar.c
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2025 Kamil Kowalczyk
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or
|
||||||
|
without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
“AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libk/types.h>
|
||||||
|
#include <ramdisk/tar.h>
|
||||||
|
|
||||||
|
static struct tar_header *ramdisk_tar_headers[TAR_MAX];
|
||||||
|
|
||||||
|
usize_t tar_get_size(const byte_t *input) {
|
||||||
|
usize_t size = 0;
|
||||||
|
usize_t j;
|
||||||
|
usize_t count = 1;
|
||||||
|
|
||||||
|
for (j = 11; j > 0; j--, count *= 8)
|
||||||
|
size += ((input[j - 1] - '0') * count);
|
||||||
|
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
usize_t tar_parse(uptr_t addr) {
|
||||||
|
usize_t i;
|
||||||
|
|
||||||
|
for (i = 0; ; i++) {
|
||||||
|
struct tar_header *header = (struct tar_header *)addr;
|
||||||
|
|
||||||
|
if (header->filename[i] == '\0')
|
||||||
|
break;
|
||||||
|
|
||||||
|
usize_t size = tar_get_size(header->size);
|
||||||
|
|
||||||
|
ramdisk_tar_headers[i] = header;
|
||||||
|
|
||||||
|
addr += ((size / 512) + 1) * 512;
|
||||||
|
|
||||||
|
if (size % 512)
|
||||||
|
addr += 512;
|
||||||
|
}
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
53
kernel/ramdisk/tar.h
Normal file
53
kernel/ramdisk/tar.h
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2025 Kamil Kowalczyk
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or
|
||||||
|
without modification, are permitted provided that the following
|
||||||
|
conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
3. Neither the name of the copyright holder nor the names of its
|
||||||
|
contributors may be used to endorse or promote products derived from
|
||||||
|
this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
“AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
|
||||||
|
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _RAMDISK_TAR_H
|
||||||
|
#define _RAMDISK_TAR_H
|
||||||
|
|
||||||
|
#include <libk/types.h>
|
||||||
|
|
||||||
|
#define TAR_MAX 64
|
||||||
|
|
||||||
|
struct tar_header {
|
||||||
|
byte_t filename[100];
|
||||||
|
byte_t mode[8];
|
||||||
|
byte_t uid[8];
|
||||||
|
byte_t gid[8];
|
||||||
|
byte_t size[12];
|
||||||
|
byte_t mtime[12];
|
||||||
|
byte_t checksum[8];
|
||||||
|
byte_t typeflag[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
usize_t tar_get_size(const byte_t *input);
|
||||||
|
usize_t tar_parse(uptr_t addr);
|
||||||
|
|
||||||
|
#endif // _RAMDISK_TAR_H
|
||||||
@ -3,5 +3,6 @@ set default=0
|
|||||||
|
|
||||||
menuentry "mop3" {
|
menuentry "mop3" {
|
||||||
multiboot /boot/kernel.elf
|
multiboot /boot/kernel.elf
|
||||||
|
module /boot/ramdisk.tar
|
||||||
boot
|
boot
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
$(srctree)/out/i386_pc/mop3.iso: $(srctree)/out/kernel.elf
|
$(srctree)/out/i386_pc/mop3.iso: $(srctree)/out/kernel.elf
|
||||||
mkdir -p $(srctree)/out/i386_pc/tmp/iso/boot/grub
|
mkdir -p $(srctree)/out/i386_pc/tmp/iso/boot/grub
|
||||||
cp $(srctree)/out/kernel.elf $(srctree)/out/i386_pc/tmp/iso/boot
|
cp $(srctree)/out/kernel.elf $(srctree)/out/i386_pc/tmp/iso/boot
|
||||||
|
cp $(srctree)/out/ramdisk.tar $(srctree)/out/i386_pc/tmp/iso/boot
|
||||||
cp $(srctree)/platform/i386_pc/grub.cfg $(srctree)/out/i386_pc/tmp/iso/boot/grub
|
cp $(srctree)/platform/i386_pc/grub.cfg $(srctree)/out/i386_pc/tmp/iso/boot/grub
|
||||||
grub-mkrescue -o $(srctree)/out/i386_pc/mop3.iso $(srctree)/out/i386_pc/tmp/iso
|
grub-mkrescue -o $(srctree)/out/i386_pc/mop3.iso $(srctree)/out/i386_pc/tmp/iso
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user