aboutsummaryrefslogtreecommitdiff
path: root/src/initrd.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-07-05 19:38:11 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-07-05 19:38:11 +0300
commite09edb5d54e39bd9509a1dc450df5ab320759f97 (patch)
tree78e050b0db87df3a3ddfbb6570d44513ac34e02a /src/initrd.c
parent98f21e694a6b0964d6d08196cb6bfbc1c2ae2ff4 (diff)
downloadkmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.tar.gz
kmi-e09edb5d54e39bd9509a1dc450df5ab320759f97.zip
allow booting with Qemu's -kernel flag directly
+ Took some fairly significant changes, for one the kernel is no longer relocated at the start of a boot, instead it sits wherever the user decides the kernel should sit. Similarly, the initial kernel stack and page table are stored within the binary, slightly bloating the size but making it much safer to boot since there's really no chance of us overwriting the fdt or initrd in memory.
Diffstat (limited to 'src/initrd.c')
-rw-r--r--src/initrd.c40
1 files changed, 13 insertions, 27 deletions
diff --git a/src/initrd.c b/src/initrd.c
index caff8b3..242e373 100644
--- a/src/initrd.c
+++ b/src/initrd.c
@@ -115,53 +115,39 @@ static size_t init_nlen = ARRAY_SIZE(init_n) - 1; /* ignore trailing NULL */
pm_t get_initrdtop(const void *fdt)
{
int chosen_offset = fdt_path_offset(fdt, "/chosen");
- struct cell_info ci = get_cellinfo(fdt, chosen_offset);
+ int len = 0;
void *initrd_end_ptr = (void *)fdt_getprop(fdt, chosen_offset,
- "linux,initrd-end", NULL);
+ "linux,initrd-end", &len);
- /* fdt is only aware of physical memory pointers */
- return (pm_t)__va(fdt_load_int_ptr(ci.addr_cells, initrd_end_ptr));
+ catastrophic_assert(initrd_end_ptr);
+ return (pm_t)fdt_load_int_ptr(len / 4, initrd_end_ptr);
}
pm_t get_initrdbase(const void *fdt)
{
const int chosen_offset = fdt_path_offset(fdt, "/chosen");
- const struct cell_info ci = get_cellinfo(fdt, chosen_offset);
+ int len = 0;
void *initrd_base_ptr = (void *)fdt_getprop(fdt, chosen_offset,
- "linux,initrd-start", NULL);
+ "linux,initrd-start", &len);
- return (pm_t)__va(fdt_load_int_ptr(ci.addr_cells, initrd_base_ptr));
+ catastrophic_assert(initrd_base_ptr);
+ return (pm_t)fdt_load_int_ptr(len / 4, initrd_base_ptr);
}
-
-size_t get_init_size(const void *fdt)
+size_t get_initrdsize(const void *fdt)
{
- char *c = (char *)get_initrdbase(fdt);
- struct cpio_header *cp = __find_file(c, init_n, init_nlen);
- return convnum(cp->c_filesize, 8, 16);
+ pm_t start = get_initrdbase(fdt);
+ pm_t end = get_initrdtop(fdt);
+ return end - start;
}
vm_t get_init_base(const void *fdt)
{
char *c = (char *)get_initrdbase(fdt);
+ c = __va(c);
struct cpio_header *cp = __find_file(c, init_n, init_nlen);
size_t name_len = convnum(cp->c_namesize, 8, 16);
return ((vm_t)cp) + align_up(sizeof(struct cpio_header) + name_len, 4);
}
-
-stat_t move_init(const void *fdt, void *target)
-{
- const char *c = (const char *)get_initrdbase(fdt);
-
- const struct cpio_header *cp = __find_file(c, init_n, init_nlen);
- size_t name_len = convnum(cp->c_namesize, 8, 16);
- size_t file_len = convnum(cp->c_filesize, 8, 16);
-
- char *fp = (char *)cp;
- fp += align_up(sizeof(struct cpio_header) + name_len, 4);
-
- memmove(target, fp, file_len);
- return OK;
-}