From: David Gibson <david@gibson.dropbear.id.au>
To: Daniel Henrique Barboza <danielhb413@gmail.com>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org, clg@kaod.org,
alistair.francis@wdc.com
Subject: Re: [PATCH for-7.2 v3 16/20] device_tree.c: support string array prop in fdt_format_node()
Date: Thu, 18 Aug 2022 11:31:43 +1000 [thread overview]
Message-ID: <Yv2Wf3LxLQf8LfP1@yekko> (raw)
In-Reply-To: <20220816173428.157304-17-danielhb413@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4542 bytes --]
On Tue, Aug 16, 2022 at 02:34:24PM -0300, Daniel Henrique Barboza wrote:
> 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";
nit: typical dts style would have extra spaces:
prop = "foo", "bar";
i.e. separated by ", " not just ",".
> }
>
> '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 3fb07b537f..d32d6856da 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;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2022-08-18 6:27 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-16 17:34 [PATCH for-7.2 v3 00/20] QMP/HMP: add 'dumpdtb' and 'info fdt' commands Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 01/20] hw/arm: do not free machine->fdt in arm_load_dtb() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 02/20] hw/microblaze: set machine->fdt in microblaze_load_dtb() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 03/20] hw/nios2: set machine->fdt in nios2_load_dtb() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 04/20] hw/ppc: set machine->fdt in ppce500_load_device_tree() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 05/20] hw/ppc: set machine->fdt in bamboo_load_device_tree() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 06/20] hw/ppc: set machine->fdt in sam460ex_load_device_tree() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 07/20] hw/ppc: set machine->fdt in xilinx_load_device_tree() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 08/20] hw/ppc: set machine->fdt in pegasos2_machine_reset() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 09/20] hw/ppc: set machine->fdt in pnv_reset() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 10/20] hw/ppc: set machine->fdt in spapr machine Daniel Henrique Barboza
2022-08-18 2:07 ` David Gibson
2022-08-19 17:40 ` Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 11/20] hw/riscv: set machine->fdt in sifive_u_machine_init() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 12/20] hw/riscv: set machine->fdt in spike_board_init() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 13/20] hw/xtensa: set machine->fdt in xtfpga_init() Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 14/20] qmp/hmp, device_tree.c: introduce dumpdtb Daniel Henrique Barboza
2022-08-18 9:30 ` Dr. David Alan Gilbert
2022-08-16 17:34 ` [PATCH for-7.2 v3 15/20] qmp/hmp, device_tree.c: introduce 'info fdt' command Daniel Henrique Barboza
2022-08-18 9:45 ` Dr. David Alan Gilbert
2022-08-16 17:34 ` [PATCH for-7.2 v3 16/20] device_tree.c: support string array prop in fdt_format_node() Daniel Henrique Barboza
2022-08-18 1:31 ` David Gibson [this message]
2022-08-16 17:34 ` [PATCH for-7.2 v3 17/20] device_tree.c: support remaining FDT prop types Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 18/20] device_node.c: enable 'info fdt' to print subnodes Daniel Henrique Barboza
2022-08-18 1:33 ` David Gibson
2022-08-16 17:34 ` [PATCH for-7.2 v3 19/20] device_tree.c: add fdt_format_property() helper Daniel Henrique Barboza
2022-08-16 17:34 ` [PATCH for-7.2 v3 20/20] hmp, device_tree.c: add 'info fdt <property>' support Daniel Henrique Barboza
2022-08-18 1:34 ` David Gibson
2022-08-19 20:44 ` 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=Yv2Wf3LxLQf8LfP1@yekko \
--to=david@gibson.dropbear.id.au \
--cc=alistair.francis@wdc.com \
--cc=clg@kaod.org \
--cc=danielhb413@gmail.com \
--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.