[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 1/3] device_tree: Add a helper function for string arrays
From: |
Peter Maydell |
Subject: |
Re: [PATCH v2 1/3] device_tree: Add a helper function for string arrays |
Date: |
Sat, 9 Nov 2019 15:59:24 +0000 |
On Fri, 8 Nov 2019 at 19:48, Palmer Dabbelt <address@hidden> wrote:
>
> The device tree format allows for arrays of strings, which are encoded
> with '\0's inside regular strings. These are ugly to represent in C, so
> the helper function represents them as strings with internal '\0's that
> are terminated with a double '\0'. In other words, the array
> ["string1", "string2"] is represeted as "string1\0string2\0".
>
> The DTB generated by this function is accepted by DTC and produces an
> array of strings, but I can't find any explicit line in the DT
> specification that defines how these are encoded.
> +/*
> + * This uses a particularly odd encoding: "strings" is a list of strings that
> + * must be terminated by two back-to-back '\0' characters.
> + */
> +int qemu_fdt_setprop_strings(void *fdt, const char *node_path,
> + const char *property, const char *strings);
The clean API for this would be to use varargs so you could write
qemu_fdt_setprop_stringlist(fdt, node, prop, "arm,armv8-timer",
"arm,armv7-timer");
and have it do the assembly into the encoding that fdt expects.
That would require us to do a bit of allocation-and-freeing
to assemble the string, of course, but then we only do fdt
creation at startup.
NB: I think that this is a good idea but not-for-4.2 material,
so if you wanted your sifive board change to go into 4.2 you
should probably start with the simple approach and leave the
refactoring for the next release cycle.
thanks
-- PMM