hw/arm/boot: Report error msg if loading elf/dtb failed
PATCH v2 1/1 hw/arm/boot: Report error msg if loading elf/dtb failed
Print errors before exit. Do not exit silently.
---
v2: remove msg for arm_load_dtb.
--- hw/arm/boot.c | 1 + 1 file changed, 1 insertion(+)
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 ); }
Signature · 1 line
2.34.1
Hi Changbin,
Quoted 15 lines · Changbin Du via
Print errors before exit. Do not exit silently.
Signed-off-by Changbin Du <[email protected]>---
v2: remove msg forarm_load_dtb.--- hw/arm/boot.c | 1 + 1 file changed, 1 insertion(+)hw/arm/boot.c +0
-0
hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 842
Quoted 4 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);
"Could ..." (caps)
"hw/loader.h" is not well documented, but it seems load_elf*() returns:
#define ELF_LOAD_FAILED -1 #define ELF_LOAD_NOT_ELF -2 #define ELF_LOAD_WRONG_ARCH -3
#define ELF_LOAD_WRONG_ENDIAN -4
#define ELF_LOAD_TOO_BIG -5
And we can display this error calling:
const char *load_elf_strerror(ssize_t error);
So we can be more precise here using:
error_report("Could not load elf '%s'", info->kernel_filename,
load_elf_strerror(ret));
hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 845
Quoted 3 lines
hw/arm/boot.c +0
-0exit (1 ); }
Better (but out of scope of this patch) could be to pass an Error *errp argument to the load_elf*() family of functions, and fill it with the appropriate error message.
Regards,
Phil.
Quoted 13 lines · Philippe Mathieu-Daudé
Hi Changbin,
Quoted 10 lines · Changbin Du via
Print errors before exit. Do not exit silently.
Signed-off-by Changbin Du <[email protected]>---
v2: remove msg forarm_load_dtb.
---
hw/arm/boot.c| 1 +1 file changed, 1 insertion(+)
Quoted 5 lines
hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info
Quoted 5 lines
hw/arm/boot.c +0
-0@@ -839,6 +839,7 @@ static ssize_t arm_load_elf(struct arm_boot_info
Note that header error is also silently ignored and could be logged:
load_elf_hdr(info->kernel_filename, &elf_header, &elf_is64, &err);
if (err) {
- error_free(err);
+ error_report_err(err);
return ret;
}(untested)
Quoted 33 lines
hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 842
Quoted 3 lines
hw/arm/boot.c +1
-0if (ret <= 0) { /* The header loaded but the image didn't */ + error_report("could not load elf '%s'", info->kernel_filename);"Could ..." (caps)
"
hw/loader.h" is not well documented, but it seems load_elf*() returns:#define ELF_LOAD_FAILED -1
#define ELF_LOAD_NOT_ELF -2
#define ELF_LOAD_WRONG_ARCH -3
#defineELF_LOAD_WRONG_ENDIAN-4
#define ELF_LOAD_TOO_BIG -5And we can display this error calling:
const char *load_elf_strerror(ssize_t error);
So we can be more precise here using:
error_report("Could not load elf '%s'", info->kernel_filename, load_elf_strerror(ret));hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 844
Quoted 2 lines
hw/arm/boot.c +0
-0exit(1); }Better (but out of scope of this patch) could be to pass an Error *errp argument to the load_elf*() family of functions, and fill it with the appropriate error message.
Regards,
Phil.
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé
Hi Changbin,
Quoted 10 lines · Changbin Du via
Print errors before exit. Do not exit silently.
Signed-off-by Changbin Du <[email protected]>---
v2: remove msg forarm_load_dtb.--- hw/arm/boot.c | 1 + 1 file changed, 1 insertion(+)Quoted 5 lines
hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info
Quoted 5 lines
hw/arm/boot.c +0
-0@@ -839,6 +839,7 @@ static ssize_t arm_load_elf(struct arm_boot_infoNote that header error is also silently ignored and could be logged:
load_elf_hdr(info->kernel_filename, &elf_header, &elf_is64, &err); if (err) {(quoted diff) +1
-1- error_free(err); + error_report_err(err); return ret; }
Quoted 1 line
(untested)
This one is deliberate -- if the file is not an ELF file we want to silently fall back to trying it as a uimage or an AArch64 Image file or as last resort a bare raw binary.
-- PMM
Quoted 31 lines · Peter Maydell
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 13 lines · Philippe Mathieu-Daudé
Hi Changbin,
Quoted 10 lines · Changbin Du via
Print errors before exit. Do not exit silently.
Signed-off-by Changbin Du <[email protected]>---
v2: remove msg forarm_load_dtb.--- hw/arm/boot.c | 1 + 1 file changed, 1 insertion(+)Quoted 5 lines
hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info
Quoted 5 lines
hw/arm/boot.c +0
-0@@ -839,6 +839,7 @@ static ssize_t arm_load_elf(struct arm_boot_infoNote that header error is also silently ignored and could be logged:
load_elf_hdr(info->kernel_filename, &elf_header, &elf_is64, &err); if (err) {(quoted diff) +1
-1- error_free(err); + error_report_err(err); return ret; }
Quoted 5 lines
Quoted 1 line
(untested)
This one is deliberate -- if the file is not an ELF file we want to silently fall back to trying it as a uimage or an AArch64 Image file or as last resort a bare raw binary.
Oh right. I'll add a comment about it to clarify, thanks.
Quoted 40 lines · Philippe Mathieu-Daudé
Hi Changbin,
Quoted 15 lines · Changbin Du via
Print errors before exit. Do not exit silently.
Signed-off-by Changbin Du <[email protected]>---
v2: remove msg forarm_load_dtb.--- hw/arm/boot.c | 1 + 1 file changed, 1 insertion(+)hw/arm/boot.c +0
-0hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 842
Quoted 4 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);"Could ..." (caps)
"
hw/loader.h" is not well documented, but it seems load_elf*() returns:#define ELF_LOAD_FAILED -1 #define ELF_LOAD_NOT_ELF -2 #define ELF_LOAD_WRONG_ARCH -3#define
ELF_LOAD_WRONG_ENDIAN-4
#defineELF_LOAD_TOO_BIG-5And we can display this error calling:
const char *load_elf_strerror(ssize_t error);So we can be more precise here using:
error_report("Could not load elf '%s'",
info->kernel_filename,
Quoted 9 lines
load_elf_strerror(ret));hw/arm/boot.c static ssize_t arm_load_elf(struct arm_boot_info *info, uint64_t *pentry, · line 844
Quoted 2 lines
hw/arm/boot.c +0
-0exit (1 ); }Better (but out of scope of this patch) could be to pass an Error *errp argument to the load_elf*() family of functions, and fill it with the appropriate error message.
Thanks for your suggestion. I changed it as below:
+ error_report("Couldn't load elf '%s': %s",
+ info->kernel_filename, load_elf_strerror(ret));
$ qemu-system-aarch64 -M virt -kernel /work/linux/vmlinux qemu-system-aarch64: Couldn't load elf '/work/linux/vmlinux': The image is from incompatible architecture
Quoted 3 lines
Regards,
Phil.
Signature · 2 lines
Cheers, Changbin Du