Message ID | 20231218090059.2678224-3-gaosong@loongson.cn |
---|---|
State | New |
Headers | show |
Series | Add boot LoongArch elf kernel with FDT | expand |
On 2023/12/18 下午5:00, Song Gao wrote: > we load initrd ramdisk after kernel_high address > > Signed-off-by: Song Gao <gaosong@loongson.cn> > --- > hw/loongarch/boot.c | 29 ++++++++++++++++++++++++++++- > 1 file changed, 28 insertions(+), 1 deletion(-) > > diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c > index 9f25ea5847..2be6dfb037 100644 > --- a/hw/loongarch/boot.c > +++ b/hw/loongarch/boot.c > @@ -21,7 +21,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, > @@ -36,6 +37,32 @@ 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, 64 * KiB); Do you test self-compressed vmlinuz elf load? I think that offset of initrd had better be 4 * kernel_size from kernel_high, else uncompressed kernel may overwrite INITRD image. such as: initrd_offset = ROUND_UP(kernel_high + 4 * kernel_size, 64 * KiB); Regards Bibo Mao > + > + 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 { > + error_report("Need initrd!"); > + exit(1); > + } > + > return kernel_entry; > } > >
在 2023/12/21 下午3:09, maobibo 写道: > > > On 2023/12/18 下午5:00, Song Gao wrote: >> we load initrd ramdisk after kernel_high address >> >> Signed-off-by: Song Gao <gaosong@loongson.cn> >> --- >> hw/loongarch/boot.c | 29 ++++++++++++++++++++++++++++- >> 1 file changed, 28 insertions(+), 1 deletion(-) >> >> diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c >> index 9f25ea5847..2be6dfb037 100644 >> --- a/hw/loongarch/boot.c >> +++ b/hw/loongarch/boot.c >> @@ -21,7 +21,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, >> @@ -36,6 +37,32 @@ 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, 64 * KiB); > Do you test self-compressed vmlinuz elf load? > The LoongArch kenrel not support build bzimage. > I think that offset of initrd had better be 4 * kernel_size from > kernel_high, else uncompressed kernel may overwrite INITRD image. > such as: > initrd_offset = ROUND_UP(kernel_high + 4 * kernel_size, 64 * KiB); > but I think we can do this. Thanks. Song Gao > Regards > Bibo Mao >> + >> + 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 { >> + error_report("Need initrd!"); >> + exit(1); >> + } >> + >> return kernel_entry; >> } >>
diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c index 9f25ea5847..2be6dfb037 100644 --- a/hw/loongarch/boot.c +++ b/hw/loongarch/boot.c @@ -21,7 +21,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, @@ -36,6 +37,32 @@ 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, 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 { + error_report("Need initrd!"); + exit(1); + } + return kernel_entry; }
we load initrd ramdisk after kernel_high address Signed-off-by: Song Gao <gaosong@loongson.cn> --- hw/loongarch/boot.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-)