diff mbox series

[PULL,02/17] hw/loongarch: Add load initrd

Message ID 20240428085117.2422473-3-gaosong@loongson.cn
State New
Headers show
Series [PULL,01/17] hw/loongarch: Move boot functions to boot.c | expand

Commit Message

Song Gao April 28, 2024, 8:51 a.m. UTC
we load initrd ramdisk after kernel_high address

Signed-off-by: Song Gao <gaosong@loongson.cn>
Reviewed-by: Bibo Mao <maobibo@loongson.cn>
Message-Id: <20240426091551.2397867-3-gaosong@loongson.cn>
---
 hw/loongarch/boot.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

Comments

Richard Henderson April 28, 2024, 6:59 p.m. UTC | #1
On 4/28/24 01:51, Song Gao wrote:
> we load initrd ramdisk after kernel_high address
> 
> Signed-off-by: Song Gao <gaosong@loongson.cn>
> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
> Message-Id: <20240426091551.2397867-3-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 9feed17db3..a9522d6912 100644
> --- a/hw/loongarch/boot.c
> +++ b/hw/loongarch/boot.c
> @@ -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,
> @@ -37,6 +38,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 + 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 {
> +        error_report("Need initrd!");
> +        exit(1);
> +    }
> +
>       return kernel_entry;
>   }
>   

This doesn't simply allow initrd, it requires an initrd.
This causes make check-tcg to fail:

>   TEST    interrupt on loongarch64
> qemu-system-loongarch64: Need initrd!

https://gitlab.com/qemu-project/qemu/-/jobs/6733983794


r~
Song Gao April 29, 2024, 2:44 a.m. UTC | #2
在 2024/4/29 上午2:59, Richard Henderson 写道:
> On 4/28/24 01:51, Song Gao wrote:
>> we load initrd ramdisk after kernel_high address
>>
>> Signed-off-by: Song Gao <gaosong@loongson.cn>
>> Reviewed-by: Bibo Mao <maobibo@loongson.cn>
>> Message-Id: <20240426091551.2397867-3-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 9feed17db3..a9522d6912 100644
>> --- a/hw/loongarch/boot.c
>> +++ b/hw/loongarch/boot.c
>> @@ -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,
>> @@ -37,6 +38,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 + 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 {
>> +        error_report("Need initrd!");
>> +        exit(1);
>> +    }
>> +
>>       return kernel_entry;
>>   }
>
> This doesn't simply allow initrd, it requires an initrd.
> This causes make check-tcg to fail:
>
>>   TEST    interrupt on loongarch64
>> qemu-system-loongarch64: Need initrd!
>
> https://gitlab.com/qemu-project/qemu/-/jobs/6733983794
I'm sorry I missed this test.  I will send v2 fix this problem and the 
job [1] failed

[1] https://gitlab.com/qemu-project/qemu/-/jobs/6733983763

Thanks.
Song gao
diff mbox series

Patch

diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 9feed17db3..a9522d6912 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -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,
@@ -37,6 +38,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 + 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 {
+        error_report("Need initrd!");
+        exit(1);
+    }
+
     return kernel_entry;
 }