From: Daniel Henrique Barboza <danielhb413@gmail.com>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, clg@kaod.org, david@gibson.dropbear.id.au,
alistair.francis@wdc.com,
Daniel Henrique Barboza <danielhb413@gmail.com>
Subject: [PATCH for-7.2 v4 16/21] device_tree.c: support string array prop in fdt_format_node()
Date: Fri, 26 Aug 2022 11:11:45 -0300 [thread overview]
Message-ID: <20220826141150.7201-17-danielhb413@gmail.com> (raw)
In-Reply-To: <20220826141150.7201-1-danielhb413@gmail.com>
To support printing string properties in 'info fdt' we need to determine
whether a void data might contain a string array.
We do that by casting the void data to a string array and:
- check if the array finishes with a null character
- check if there's no empty string in the middle of the array (i.e.
consecutive \0\0 characters)
- check if all characters of each substring are printable
If all conditions are met, we'll consider it to be a string array data
type and print it accordingly. After this change, 'info fdt' is now able
to print string arrays. Here's an example of string arrays we're able to
print in the /rtas node of the ppc64 pSeries machine:
(qemu) info fdt /rtas
rtas {
(...)
qemu,hypertas-functions = "hcall-memop1";
ibm,hypertas-functions = "hcall-pft", "hcall-term", "hcall-dabr", "hcall-interrupt", "hcall-tce", "hcall-vio", "hcall-splpar", "hcall-join", "hcall-bulk", "hcall-set-mode", "hcall-sprg0", "hcall-copy", "hcall-debug", "hcall-vphn", "hcall-multi-tce", "hcall-hpt-resize", "hcall-watchdog";
};
'qemu,hypertas-functions' is a property with a single string while
'ibm,hypertas-functions' is a string array.
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
---
softmmu/device_tree.c | 64 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 63 insertions(+), 1 deletion(-)
diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c
index 6b15f6ace2..3e38d9ddad 100644
--- a/softmmu/device_tree.c
+++ b/softmmu/device_tree.c
@@ -663,6 +663,63 @@ void qemu_fdt_qmp_dumpdtb(const char *filename, Error **errp)
error_setg(errp, "Error when saving machine FDT to file %s", filename);
}
+static bool fdt_prop_is_string_array(const void *data, int size)
+{
+ const char *str_arr, *str;
+ int i, str_len;
+
+ str_arr = str = data;
+
+ if (size <= 0 || str_arr[size - 1] != '\0') {
+ return false;
+ }
+
+ while (str < str_arr + size) {
+ str_len = strlen(str);
+
+ /*
+ * Do not consider empty strings (consecutives \0\0)
+ * as valid.
+ */
+ if (str_len == 0) {
+ return false;
+ }
+
+ for (i = 0; i < str_len; i++) {
+ if (!g_ascii_isprint(str[i])) {
+ return false;
+ }
+ }
+
+ str += str_len + 1;
+ }
+
+ return true;
+}
+
+static void fdt_prop_format_string_array(GString *buf,
+ const char *propname,
+ const char *data,
+ int prop_size, int padding)
+{
+ const char *str = data;
+
+ g_string_append_printf(buf, "%*s%s = ", padding, "", propname);
+
+ while (str < data + prop_size) {
+ /* appends up to the next '\0' */
+ g_string_append_printf(buf, "\"%s\"", str);
+
+ str += strlen(str) + 1;
+ if (str < data + prop_size) {
+ /* add a comma separator for the next string */
+ g_string_append_printf(buf, ", ");
+ }
+ }
+
+ g_string_append_printf(buf, ";\n");
+}
+
static void fdt_format_node(GString *buf, int node, int depth)
{
const struct fdt_property *prop = NULL;
@@ -681,7 +738,12 @@ 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));
- g_string_append_printf(buf, "%*s%s;\n", padding, "", propname);
+ if (fdt_prop_is_string_array(prop->data, prop_size)) {
+ fdt_prop_format_string_array(buf, propname, prop->data,
+ prop_size, padding);
+ } else {
+ g_string_append_printf(buf, "%*s%s;\n", padding, "", propname);
+ }
}
padding -= 4;
--
2.37.2
next prev parent reply other threads:[~2022-08-26 14:22 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-26 14:11 [PATCH for-7.2 v4 00/21] QMP/HMP: add 'dumpdtb' and 'info fdt' commands Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 01/21] hw/arm: do not free machine->fdt in arm_load_dtb() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 02/21] hw/microblaze: set machine->fdt in microblaze_load_dtb() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 03/21] hw/nios2: set machine->fdt in nios2_load_dtb() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 04/21] hw/ppc: set machine->fdt in ppce500_load_device_tree() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 05/21] hw/ppc: set machine->fdt in bamboo_load_device_tree() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 06/21] hw/ppc: set machine->fdt in sam460ex_load_device_tree() Daniel Henrique Barboza
2022-08-26 18:56 ` BALATON Zoltan
2022-08-26 20:34 ` Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 07/21] hw/ppc: set machine->fdt in xilinx_load_device_tree() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 08/21] hw/ppc: set machine->fdt in pegasos2_machine_reset() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 09/21] hw/ppc: set machine->fdt in pnv_reset() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 10/21] hw/ppc: set machine->fdt in spapr machine Daniel Henrique Barboza
2022-08-29 3:29 ` David Gibson
2022-08-26 14:11 ` [PATCH for-7.2 v4 11/21] hw/riscv: set machine->fdt in sifive_u_machine_init() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 12/21] hw/riscv: set machine->fdt in spike_board_init() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 13/21] hw/xtensa: set machine->fdt in xtfpga_init() Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 14/21] qmp/hmp, device_tree.c: introduce dumpdtb Daniel Henrique Barboza
2022-08-30 10:40 ` Markus Armbruster
2022-08-26 14:11 ` [PATCH for-7.2 v4 15/21] qmp/hmp, device_tree.c: introduce 'info fdt' command Daniel Henrique Barboza
2022-08-29 3:34 ` David Gibson
2022-08-29 22:00 ` Daniel Henrique Barboza
2022-08-30 1:50 ` David Gibson
2022-08-30 9:59 ` Daniel Henrique Barboza
2022-08-30 10:43 ` Markus Armbruster
2022-09-01 2:10 ` David Gibson
2022-08-30 10:41 ` Markus Armbruster
2022-08-26 14:11 ` Daniel Henrique Barboza [this message]
2022-08-26 14:11 ` [PATCH for-7.2 v4 17/21] device_tree.c: support remaining FDT prop types Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 18/21] device_node.c: enable 'info fdt' to print subnodes Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 19/21] device_tree.c: add fdt_format_property() helper Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 20/21] hmp, device_tree.c: add 'info fdt <property>' support Daniel Henrique Barboza
2022-08-26 14:11 ` [PATCH for-7.2 v4 21/21] qmp/hmp, device_tree.c: add textformat dumpdtb option Daniel Henrique Barboza
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220826141150.7201-17-danielhb413@gmail.com \
--to=danielhb413@gmail.com \
--cc=alistair.francis@wdc.com \
--cc=clg@kaod.org \
--cc=david@gibson.dropbear.id.au \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.