[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH for-7.2 v2 19/20] device_tree.c: add fdt_format_property() helper
From: |
Daniel Henrique Barboza |
Subject: |
[PATCH for-7.2 v2 19/20] device_tree.c: add fdt_format_property() helper |
Date: |
Fri, 5 Aug 2022 06:39:47 -0300 |
We want to be able to also print properties with 'info fdt'.
Create a helper to format properties based on the already existing code
from fdt_format_node().
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
softmmu/device_tree.c | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index 99d95c1cb9..902a7f680b 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -728,6 +728,25 @@ static void fdt_prop_format_val(GString *buf, const char
*propname,
g_string_append_printf(buf, "]\n");
}
+static void fdt_format_property(GString *buf, const char *propname,
+ const void *data, int prop_size,
+ int padding)
+{
+ if (prop_size == 0) {
+ g_string_append_printf(buf, "%*s%s;\n", padding, "", propname);
+ return;
+ }
+
+ if (fdt_prop_is_string(data, prop_size)) {
+ g_string_append_printf(buf, "%*s%s = '%s'\n", padding, "",
+ propname, (char *)data);
+ } else if (fdt_prop_is_uint32_array(prop_size)) {
+ fdt_prop_format_uint32_array(buf, propname, data, prop_size,
+ padding);
+ } else {
+ fdt_prop_format_val(buf, propname, data, prop_size, padding);
+ }
+}
static void fdt_format_node(GString *buf, int node, int depth,
const char *fullpath)
@@ -755,21 +774,7 @@ static void fdt_format_node(GString *buf, int node, int
depth,
prop = fdt_get_property_by_offset(fdt, property, &prop_size);
propname = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
- if (prop_size == 0) {
- g_string_append_printf(buf, "%*s%s;\n", padding, "", propname);
- continue;
- }
-
- if (fdt_prop_is_string(prop->data, prop_size)) {
- g_string_append_printf(buf, "%*s%s = '%s'\n",
- padding, "", propname, prop->data);
- } else if (fdt_prop_is_uint32_array(prop_size)) {
- fdt_prop_format_uint32_array(buf, propname, prop->data, prop_size,
- padding);
- } else {
- fdt_prop_format_val(buf, propname, prop->data,
- prop_size, padding);
- }
+ fdt_format_property(buf, propname, prop->data, prop_size, padding);
}
fdt_for_each_subnode(node, fdt, parent) {
--
2.36.1
- [PATCH for-7.2 v2 14/20] qmp/hmp, device_tree.c: introduce dumpdtb, (continued)
[PATCH for-7.2 v2 16/20] device_tree.c: support string props in fdt_format_node(), Daniel Henrique Barboza, 2022/08/05
[PATCH for-7.2 v2 19/20] device_tree.c: add fdt_format_property() helper,
Daniel Henrique Barboza <=
[PATCH for-7.2 v2 20/20] hmp, device_tree.c: add 'info fdt <property>' support, Daniel Henrique Barboza, 2022/08/05