kconfig: allow compiling out QEMU device tree code per target
Introduce a new Kconfig symbol, CONFIG_DEVICE_TREE, that specifies whether
to include the common device tree code in system/device_tree.c and to
link to libfdt. For now, include it unconditionally if libfdt is
available.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
diff --git a/Kconfig.host b/Kconfig.host
index f6a2a13..a0d4a52 100644
--- a/Kconfig.host
+++ b/Kconfig.host
@@ -23,6 +23,10 @@
config TPM
bool
+config FDT
+ bool
+ select DEVICE_TREE
+
config VHOST_USER
bool
diff --git a/hw/core/Kconfig b/hw/core/Kconfig
index 9397503..24411f5 100644
--- a/hw/core/Kconfig
+++ b/hw/core/Kconfig
@@ -4,8 +4,14 @@
config PTIMER
bool
+config DEVICE_TREE
+ bool
+ # fail the build if libfdt not found
+ depends on FDT
+
config FITLOADER
bool
+ depends on DEVICE_TREE
config GENERIC_LOADER
bool
@@ -14,13 +20,14 @@
config GUEST_LOADER
bool
default y
- depends on TCG
+ depends on TCG && DEVICE_TREE
config OR_IRQ
bool
config PLATFORM_BUS
bool
+ depends on DEVICE_TREE
config REGISTER
bool
diff --git a/hw/core/meson.build b/hw/core/meson.build
index f20d414..a3d9bab 100644
--- a/hw/core/meson.build
+++ b/hw/core/meson.build
@@ -16,7 +16,7 @@
common_ss.add(files('machine-smp.c'))
system_ss.add(when: 'CONFIG_FITLOADER', if_true: files('loader-fit.c'))
system_ss.add(when: 'CONFIG_GENERIC_LOADER', if_true: files('generic-loader.c'))
-system_ss.add(when: ['CONFIG_GUEST_LOADER', fdt], if_true: files('guest-loader.c'))
+system_ss.add(when: 'CONFIG_GUEST_LOADER', if_true: files('guest-loader.c'))
system_ss.add(when: 'CONFIG_OR_IRQ', if_true: files('or-irq.c'))
system_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('platform-bus.c'))
system_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c'))
diff --git a/include/monitor/hmp.h b/include/monitor/hmp.h
index f4cf8f6..954f3c8 100644
--- a/include/monitor/hmp.h
+++ b/include/monitor/hmp.h
@@ -180,5 +180,6 @@
void hmp_boot_set(Monitor *mon, const QDict *qdict);
void hmp_info_mtree(Monitor *mon, const QDict *qdict);
void hmp_info_cryptodev(Monitor *mon, const QDict *qdict);
+void hmp_dumpdtb(Monitor *mon, const QDict *qdict);
#endif
diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index 8eab395..eb60152 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -134,7 +134,6 @@
} while (0)
void qemu_fdt_dumpdtb(void *fdt, int size);
-void hmp_dumpdtb(Monitor *mon, const QDict *qdict);
/**
* qemu_fdt_setprop_sized_cells_from_array:
diff --git a/meson.build b/meson.build
index dd4a28f..8b90ea6 100644
--- a/meson.build
+++ b/meson.build
@@ -2989,6 +2989,7 @@
(have_ivshmem ? ['CONFIG_IVSHMEM=y'] : []) + \
(opengl.found() ? ['CONFIG_OPENGL=y'] : []) + \
(x11.found() ? ['CONFIG_X11=y'] : []) + \
+ (fdt.found() ? ['CONFIG_FDT=y'] : []) + \
(have_vhost_user ? ['CONFIG_VHOST_USER=y'] : []) + \
(have_vhost_vdpa ? ['CONFIG_VHOST_VDPA=y'] : []) + \
(have_vhost_kernel ? ['CONFIG_VHOST_KERNEL=y'] : []) + \
diff --git a/monitor/hmp-cmds.c b/monitor/hmp-cmds.c
index 871898a..ea79148 100644
--- a/monitor/hmp-cmds.c
+++ b/monitor/hmp-cmds.c
@@ -22,6 +22,7 @@
#include "monitor/monitor-internal.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-control.h"
+#include "qapi/qapi-commands-machine.h"
#include "qapi/qapi-commands-misc.h"
#include "qapi/qmp/qdict.h"
#include "qemu/cutils.h"
@@ -443,3 +444,19 @@
mtree_info(flatview, dispatch_tree, owner, disabled);
}
+
+#if defined(CONFIG_FDT)
+void hmp_dumpdtb(Monitor *mon, const QDict *qdict)
+{
+ const char *filename = qdict_get_str(qdict, "filename");
+ Error *local_err = NULL;
+
+ qmp_dumpdtb(filename, &local_err);
+
+ if (hmp_handle_error(mon, local_err)) {
+ return;
+ }
+
+ monitor_printf(mon, "dtb dumped to %s", filename);
+}
+#endif
diff --git a/system/device_tree-stub.c b/system/device_tree-stub.c
new file mode 100644
index 0000000..bddda6f
--- /dev/null
+++ b/system/device_tree-stub.c
@@ -0,0 +1,10 @@
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qapi/qapi-commands-machine.h"
+
+#ifdef CONFIG_FDT
+void qmp_dumpdtb(const char *filename, Error **errp)
+{
+ error_setg(errp, "This machine doesn't have a FDT");
+}
+#endif
diff --git a/system/device_tree.c b/system/device_tree.c
index eb5166c..2e38259 100644
--- a/system/device_tree.c
+++ b/system/device_tree.c
@@ -668,20 +668,6 @@
}
}
-void hmp_dumpdtb(Monitor *mon, const QDict *qdict)
-{
- const char *filename = qdict_get_str(qdict, "filename");
- Error *local_err = NULL;
-
- qmp_dumpdtb(filename, &local_err);
-
- if (hmp_handle_error(mon, local_err)) {
- return;
- }
-
- info_report("dtb dumped to %s", filename);
-}
-
void qemu_fdt_randomize_seeds(void *fdt)
{
int noffset, poffset, len;
diff --git a/system/meson.build b/system/meson.build
index 25e2117..a296270 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -32,7 +32,9 @@
endif
system_ss.add(when: seccomp, if_true: files('qemu-seccomp.c'))
-system_ss.add(when: fdt, if_true: files('device_tree.c'))
+system_ss.add(when: 'CONFIG_DEVICE_TREE',
+ if_true: [fdt, files('device_tree.c')],
+ if_false: files('device_tree-stub.c'))
if host_os == 'linux'
system_ss.add(files('async-teardown.c'))
endif