[PATCH 2/3] hw/arm: Pack the QEMU generated device tree

Bin Meng posted 3 patches 10 months ago
Maintainers: Peter Maydell <peter.maydell@linaro.org>, Radoslaw Biernacki <rad@semihalf.com>, Leif Lindholm <quic_llindhol@quicinc.com>, Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>, Alistair Francis <alistair@alistair23.me>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>
[PATCH 2/3] hw/arm: Pack the QEMU generated device tree
Posted by Bin Meng 10 months ago
By default QEMU generates a 1 MiB sized device tree. Let's pack it
to save some room.

Signed-off-by: Bin Meng <bin.meng@windriver.com>
---

 hw/arm/boot.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index ff1173299f..511ec10ed0 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -662,6 +662,17 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
         binfo->modify_dtb(binfo, fdt);
     }
 
+    /*
+     * By default QEMU generates a 1 MiB sized device tree.
+     * Let's pack it to save some room.
+     */
+    if (binfo->get_dtb) {
+        rc = fdt_pack(fdt);
+        /* Should only fail if we've built a corrupted tree */
+        g_assert(rc == 0);
+        size = fdt_totalsize(fdt);
+    }
+
     qemu_fdt_dumpdtb(fdt, size);
 
     /* Put the DTB into the memory map as a ROM image: this will ensure
-- 
2.34.1
Re: [PATCH 2/3] hw/arm: Pack the QEMU generated device tree
Posted by Peter Maydell 9 months, 4 weeks ago
On Mon, 15 Jan 2024 at 04:34, Bin Meng <bin.meng@windriver.com> wrote:
>
> By default QEMU generates a 1 MiB sized device tree. Let's pack it
> to save some room.
>
> Signed-off-by: Bin Meng <bin.meng@windriver.com>
> ---
>
>  hw/arm/boot.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
>
> diff --git a/hw/arm/boot.c b/hw/arm/boot.c
> index ff1173299f..511ec10ed0 100644
> --- a/hw/arm/boot.c
> +++ b/hw/arm/boot.c
> @@ -662,6 +662,17 @@ int arm_load_dtb(hwaddr addr, const struct arm_boot_info *binfo,
>          binfo->modify_dtb(binfo, fdt);
>      }
>
> +    /*
> +     * By default QEMU generates a 1 MiB sized device tree.
> +     * Let's pack it to save some room.
> +     */
> +    if (binfo->get_dtb) {
> +        rc = fdt_pack(fdt);
> +        /* Should only fail if we've built a corrupted tree */
> +        g_assert(rc == 0);

We generally use plain old assert(), not g_assert().

> +        size = fdt_totalsize(fdt);
> +    }
> +
>      qemu_fdt_dumpdtb(fdt, size);

Otherwise
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

thanks
-- PMM