From: "Alex Bennée" <alex.bennee@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
qemu-arm@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>
Subject: [PATCH 4/4] hw/arm: expose Error * to arm_load_dtb
Date: Mon, 1 Sep 2025 13:53:04 +0100 [thread overview]
Message-ID: <20250901125304.1047624-5-alex.bennee@linaro.org> (raw)
In-Reply-To: <20250901125304.1047624-1-alex.bennee@linaro.org>
Currently all calls to arm_load_dtb will result in an exit if we fail.
By passing Error * we can use &error_fatal and properly set the error
report.
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
---
include/hw/arm/boot.h | 3 ++-
hw/arm/boot.c | 35 +++++++++++++++--------------------
hw/arm/virt.c | 6 +++---
3 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/include/hw/arm/boot.h b/include/hw/arm/boot.h
index a2e22bda8a5..fdb99c0c1ee 100644
--- a/include/hw/arm/boot.h
+++ b/include/hw/arm/boot.h
@@ -164,6 +164,7 @@ AddressSpace *arm_boot_address_space(ARMCPU *cpu,
* @addr_limit: upper limit of the available memory area at @addr
* @as: address space to load image to
* @cpu: ARM CPU object
+ * @errp: Error object, often &error_fatal
*
* Load a device tree supplied by the machine or by the user with the
* '-dtb' command line option, and put it at offset @addr in target
@@ -181,7 +182,7 @@ AddressSpace *arm_boot_address_space(ARMCPU *cpu,
*/
int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
hwaddr addr_limit, AddressSpace *as, MachineState *ms,
- ARMCPU *cpu);
+ ARMCPU *cpu, Error **errp);
/* Write a secure board setup routine with a dummy handler for SMCs */
void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu,
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index f9d0bc7011e..d28ae8b86ab 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -517,7 +517,7 @@ static void fdt_add_psci_node(void *fdt, ARMCPU *armcpu)
int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
hwaddr addr_limit, AddressSpace *as, MachineState *ms,
- ARMCPU *cpu)
+ ARMCPU *cpu, Error **errp)
{
g_autofree void *fdt = NULL;
g_auto(GStrv) node_path = NULL;
@@ -525,25 +525,24 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
uint32_t acells, scells;
unsigned int i;
hwaddr mem_base, mem_len;
- Error *err = NULL;
if (binfo->dtb_filename) {
g_autofree char *filename = qemu_find_file(QEMU_FILE_TYPE_DTB,
binfo->dtb_filename);
if (!filename) {
- fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
+ error_setg(errp, "Couldn't open dtb file %s", binfo->dtb_filename);
return -1;
}
fdt = load_device_tree(filename, &size);
if (!fdt) {
- fprintf(stderr, "Couldn't open dtb file %s\n", filename);
+ error_setg(errp, "Couldn't open dtb file %s", filename);
return -1;
}
} else {
fdt = binfo->get_dtb(binfo, &size);
if (!fdt) {
- fprintf(stderr, "Board was unable to create a dtb blob\n");
+ error_setg(errp, "Board was unable to create a dtb blob");
return -1;
}
}
@@ -561,7 +560,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
scells = qemu_fdt_getprop_cell(fdt, "/", "#size-cells",
NULL, &error_fatal);
if (acells == 0 || scells == 0) {
- fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");
+ error_setg(errp, "dtb file invalid (#address-cells or #size-cells 0)");
return -1;
}
@@ -569,15 +568,13 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
/* This is user error so deserves a friendlier error message
* than the failure of setprop_sized_cells would provide
*/
- fprintf(stderr, "qemu: dtb file not compatible with "
- "RAM size > 4GB\n");
+ error_setg(errp, "qemu: dtb file not compatible with RAM size > 4GB");
return -1;
}
/* nop all root nodes matching /memory or /memory@unit-address */
- node_path = qemu_fdt_node_unit_path(fdt, "memory", &err);
- if (err) {
- error_report_err(err);
+ node_path = qemu_fdt_node_unit_path(fdt, "memory", errp);
+ if (!node_path) {
return -1;
}
while (node_path[n]) {
@@ -607,7 +604,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
rc = fdt_add_memory_node(fdt, acells, mem_base,
scells, mem_len, i);
if (rc < 0) {
- fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n",
+ error_setg(errp, "couldn't add /memory@%"PRIx64" node",
mem_base);
return -1;
}
@@ -618,7 +615,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
rc = fdt_add_memory_node(fdt, acells, binfo->loader_start,
scells, binfo->ram_size, -1);
if (rc < 0) {
- fprintf(stderr, "couldn't add /memory@%"PRIx64" node\n",
+ error_setg(errp, "couldn't add /memory@%"PRIx64" node",
binfo->loader_start);
return -1;
}
@@ -633,7 +630,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
rc = qemu_fdt_setprop_string(fdt, "/chosen", "bootargs",
ms->kernel_cmdline);
if (rc < 0) {
- fprintf(stderr, "couldn't set /chosen/bootargs\n");
+ error_setg(errp, "couldn't set /chosen/bootargs");
return -1;
}
}
@@ -642,7 +639,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
rc = qemu_fdt_setprop_sized_cells(fdt, "/chosen", "linux,initrd-start",
acells, binfo->initrd_start);
if (rc < 0) {
- fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
+ error_setg(errp, "couldn't set /chosen/linux,initrd-start");
return -1;
}
@@ -651,7 +648,7 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
binfo->initrd_start +
binfo->initrd_size);
if (rc < 0) {
- fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
+ error_setg(errp, "couldn't set /chosen/linux,initrd-end");
return -1;
}
}
@@ -1321,10 +1318,8 @@ void arm_load_kernel(ARMCPU *cpu, MachineState *ms, struct arm_boot_info *info)
* decided whether to enable PSCI and set the psci-conduit CPU properties.
*/
if (!info->skip_dtb_autoload && have_dtb(info)) {
- if (arm_load_dtb(info->dtb_start, info, info->dtb_limit,
- as, ms, cpu) < 0) {
- exit(1);
- }
+ arm_load_dtb(info->dtb_start, info, info->dtb_limit,
+ as, ms, cpu, &error_fatal);
}
}
diff --git a/hw/arm/virt.c b/hw/arm/virt.c
index 9326cfc895f..6061e0ddb50 100644
--- a/hw/arm/virt.c
+++ b/hw/arm/virt.c
@@ -1803,9 +1803,9 @@ void virt_machine_done(Notifier *notifier, void *data)
vms->memmap[VIRT_PLATFORM_BUS].size,
vms->irqmap[VIRT_PLATFORM_BUS]);
}
- if (arm_load_dtb(info->dtb_start, info, info->dtb_limit, as, ms, cpu) < 0) {
- exit(1);
- }
+
+ arm_load_dtb(info->dtb_start, info, info->dtb_limit,
+ as, ms, cpu, &error_fatal);
pci_bus_add_fw_cfg_extra_pci_roots(vms->fw_cfg, vms->bus,
&error_abort);
--
2.47.2
next prev parent reply other threads:[~2025-09-01 12:54 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-01 12:53 [PATCH 0/4] arm_load_dtb cleanups Alex Bennée
2025-09-01 12:53 ` [PATCH 1/4] hw/arm: use g_autofree for filename in arm_load_dtb Alex Bennée
2025-09-01 13:04 ` Manos Pitsidianakis
2025-09-03 3:53 ` Richard Henderson
2025-09-01 12:53 ` [PATCH 2/4] hw/arm: use g_autofree for fdt " Alex Bennée
2025-09-01 13:01 ` Manos Pitsidianakis
2025-09-02 9:36 ` Peter Maydell
2025-09-03 8:16 ` Alex Bennée
2025-09-03 10:04 ` Peter Maydell
2025-09-03 10:05 ` Alex Bennée
2025-09-01 12:53 ` [PATCH 3/4] hw/arm: use g_auto(GStrv) for node_path " Alex Bennée
2025-09-01 13:05 ` Manos Pitsidianakis
2025-09-03 3:59 ` Richard Henderson
2025-09-01 12:53 ` Alex Bennée [this message]
2025-09-01 13:03 ` [PATCH 4/4] hw/arm: expose Error * to arm_load_dtb Manos Pitsidianakis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250901125304.1047624-5-alex.bennee@linaro.org \
--to=alex.bennee@linaro.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).