Skip to contentSkip to conversation

hw/arm/boot: Report error msg if loading elf/dtb failed

PATCH Superseded Changbin Du via 2 participants 3 messages Aug 30, 2024

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/arm/boot: Report error msg if loading elf/dtb failed

Print errors before exit. Do not exit silently.

---
 hw/arm/boot.c | 2 ++
 1 file changed, 2 insertions(+)
hw/arm/boot.c +2 -0
index d480a7da02cf..17c01f299831 100644
@@ -839,6 +839,7 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
                       1, data_swab, as);
     if (ret <= 0) {
         /* The header loaded but the image didn't */
+        error_report("could not load elf '%s'", info->kernel_filename);
         exit(1);
     }
 
@@ -1322,6 +1323,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info)
      */
     if (!info->skip_dtb_autoload && have_dtb(info)) {
         if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms) < 0) {
+            error_report("could not load dtb '%s'", info->dtb_filename);
             exit(1);
         }
     }
Signature · 1 line
2.34.1
#1 lore raw
Quoted 13 lines · Changbin Du

Print errors before exit. Do not exit silently.

---
 hw/arm/boot.c | 2 ++
 1 file changed, 2 insertions(+)
hw/arm/boot.c +0 -0
index d480a7da02cf..17c01f299831 100644

hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 843

Quoted 5 lines
hw/arm/boot.c +1 -0
@@ -839,6 +839,7 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
                       1, data_swab, as);
     if (ret <= 0) {
         /* The header loaded but the image didn't */
+        error_report("could not load elf '%s'", info->kernel_filename);
         exit(1);

I agree we should print a message here.

hw/arm/boot.c void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) · line 1327

Quoted 8 lines
hw/arm/boot.c +1 -0
     }
 
@@ -1322,6 +1323,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info)
      */
     if (!info->skip_dtb_autoload && have_dtb(info)) {
         if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms) < 0) {
+            error_report("could not load dtb '%s'", info->dtb_filename);
             exit(1);

But for this case, arm_load_dtb() should be printing the error message itself (which lets it be more precise about what went wrong). Is there a code path where it fails to print an error?

thanks
-- PMM

#2 lore raw
Quoted 24 lines · Peter Maydell
Quoted 13 lines · Changbin Du

Print errors before exit. Do not exit silently.

---
 hw/arm/boot.c | 2 ++
 1 file changed, 2 insertions(+)
hw/arm/boot.c +0 -0
index d480a7da02cf..17c01f299831 100644

hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 843

Quoted 5 lines
hw/arm/boot.c +1 -0
@@ -839,6 +839,7 @@ static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry,
                       1, data_swab, as);
     if (ret <= 0) {
         /* The header loaded but the image didn't */
+        error_report("could not load elf '%s'", info->kernel_filename);
         exit(1);

I agree we should print a message here.

Quoted 2 lines
hw/arm/boot.c +0 -0
     }
 
Quoted 11 lines

hw/arm/boot.c void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info) · line 1327

Quoted 6 lines
hw/arm/boot.c +1 -0
@@ -1322,6 +1323,7 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info)
      */
     if (!info->skip_dtb_autoload && have_dtb(info)) {
         if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms) < 0) {
+            error_report("could not load dtb '%s'", info->dtb_filename);
             exit(1);

But for this case, arm_load_dtb() should be printing the error message itself (which lets it be more precise about what went wrong). Is there a code path where it fails to print an error?

Seems not. arm_load_dtb() prints errors on all of its failure paths. So this change should be removed.

Quoted 2 lines

thanks
-- PMM

Signature · 2 lines
Cheers,
Changbin Du