After the device tree is generated, it can be packed, significantly reducing its size. This is particularly important with the upcoming support for the device tree via IGVM, which can have stricter memory constraints.
Signed-off-by: Luigi Leonardi <[email protected]> --- hw/i386/microvm-dt.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hw/i386/microvm-dt.c b/hw/i386/microvm-dt.c index 45fbb5bbd1..9de2abf92c 100644 --- a/hw/i386/microvm-dt.c +++ b/hw/i386/microvm-dt.c @@ -43,6 +43,8 @@ #include "microvm-dt.h" +#include <libfdt.h> + static bool debug; static void dt_add_microvm_irq(MicrovmMachineState *mms, @@ -326,6 +328,7 @@ void dt_setup_microvm(MicrovmMachineState *mms) X86MachineState *x86ms = X86_MACHINE(mms); MachineState *ms = MACHINE(mms); int size = 0; + int ret; ms->fdt = create_device_tree(&size); @@ -337,6 +340,12 @@ void dt_setup_microvm(MicrovmMachineState *mms) qemu_fdt_add_subnode(ms->fdt, "/chosen"); dt_setup_sys_bus(mms); + ret = fdt_pack(ms->fdt); + /* Should only fail if we've built a corrupted tree */ + g_assert(ret == 0); + + size = fdt_totalsize(ms->fdt); + /* add to fw_cfg */ if (debug) { fprintf(stderr, "%s: add etc/fdt to fw_cfg\n", __func__); -- 2.54.0
