Skip to content

Commit

Permalink
hw/loongarch: Add load initrd
Browse files Browse the repository at this point in the history
we load initrd ramdisk after kernel_high address

Signed-off-by: Song Gao <[email protected]>
Reviewed-by: Bibo Mao <[email protected]>
Message-Id: <[email protected]>
  • Loading branch information
gaosong-loongson committed Apr 29, 2024
1 parent d771ca1 commit 02307a6
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion hw/loongarch/boot.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ static uint64_t cpu_loongarch_virt_to_phys(void *opaque, uint64_t addr)

static int64_t load_kernel_info(struct loongarch_boot_info *info)
{
uint64_t kernel_entry, kernel_low, kernel_high;
uint64_t kernel_entry, kernel_low, kernel_high, initrd_size;
ram_addr_t initrd_offset;
ssize_t kernel_size;

kernel_size = load_elf(info->kernel_filename, NULL,
Expand All @@ -37,6 +38,31 @@ static int64_t load_kernel_info(struct loongarch_boot_info *info)
load_elf_strerror(kernel_size));
exit(1);
}

if (info->initrd_filename) {
initrd_size = get_image_size(info->initrd_filename);
if (initrd_size > 0) {
initrd_offset = ROUND_UP(kernel_high + 4 * kernel_size, 64 * KiB);

if (initrd_offset + initrd_size > info->ram_size) {
error_report("memory too small for initial ram disk '%s'",
info->initrd_filename);
exit(1);
}

initrd_size = load_image_targphys(info->initrd_filename, initrd_offset,
info->ram_size - initrd_offset);
}

if (initrd_size == (target_ulong)-1) {
error_report("could not load initial ram disk '%s'",
info->initrd_filename);
exit(1);
}
} else {
initrd_size = 0;
}

return kernel_entry;
}

Expand Down

0 comments on commit 02307a6

Please sign in to comment.