All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] device_tree: Add qemu_fdt_totalsize function
@ 2018-05-04  1:19 Michael Clark
  2018-05-05 10:44 ` Peter Maydell
  0 siblings, 1 reply; 12+ messages in thread
From: Michael Clark @ 2018-05-04  1:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael Clark, Peter Crosthwaite, Alexander Graf,
	Alistair Francis, Peter Maydell

Currently the device-tree create_device_tree function
returns the size of the allocated device tree buffer
however there is no way to get the actual amount of
buffer space used by the device-tree.

14ec3cbd7c1e31dca4d23f028100c8f43e156573 increases
the FDT_MAX_SIZE to 1 MiB. This creates an issue
for boards that have less than 1 MiB in their ROM
for device tree. While cpu_physical_memory_write
will not write past the end of a buffer there is
and a board is aware of its ROM buffer size, so
can use min(fdt_size,rom_size); this provides no
indication as to whether the device-tree may be
truncated. qemu_fdt_totalsize allows a board to
check that a dynamically created device tree will
fit within its alloted ROM space.

Add qemu_fdt_totalsize which uses the logic and
public APIs from libfdt to calculate the device
size: struct_offset + struct_size + strings_size
+ terminator.

Cc: Peter Crosthwaite <crosthwaite.peter@gmail.com>
Cc: Alexander Graf <agraf@suse.de>
Cc: Alistair Francis <Alistair.Francis@wdc.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
---
 device_tree.c                | 6 ++++++
 include/sysemu/device_tree.h | 6 ++++++
 2 files changed, 12 insertions(+)

diff --git a/device_tree.c b/device_tree.c
index 52c3358a5583..3a2166d61f37 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -215,6 +215,12 @@ void *load_device_tree_from_sysfs(void)
 
 #endif /* CONFIG_LINUX */
 
+size_t qemu_fdt_totalsize(void *fdt)
+{
+    return fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt) +
+           fdt_size_dt_strings(fdt) + sizeof(uint32_t) /* terminator */;
+}
+
 static int findnode_nofail(void *fdt, const char *node_path)
 {
     int offset;
diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h
index e22e5bec9c3f..4af232dfdc65 100644
--- a/include/sysemu/device_tree.h
+++ b/include/sysemu/device_tree.h
@@ -26,6 +26,12 @@ void *load_device_tree_from_sysfs(void);
 #endif
 
 /**
+ * qemu_fdt_total_size: returns the size required to store the current
+ * device tree versus the buffer size returned by create_device_tree
+ */
+size_t qemu_fdt_totalsize(void *fdt);
+
+/**
  * qemu_fdt_node_path: return the paths of nodes matching a given
  * name and compat string
  * @fdt: pointer to the dt blob
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2018-06-18  2:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-04  1:19 [Qemu-devel] [PATCH] device_tree: Add qemu_fdt_totalsize function Michael Clark
2018-05-05 10:44 ` Peter Maydell
2018-05-05 11:48   ` David Gibson
2018-05-05 21:59     ` Michael Clark
2018-05-05 23:03       ` Michael Clark
2018-05-06 12:23       ` Peter Maydell
2018-05-06 13:39         ` David Gibson
2018-05-06 15:04           ` Peter Maydell
2018-05-09  5:32             ` David Gibson
2018-05-09 11:23               ` Peter Maydell
2018-06-18  2:58                 ` David Gibson
2018-05-06 13:53       ` David Gibson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.