From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F2F99C433DB for ; Wed, 17 Feb 2021 01:24:07 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4166A64E2F for ; Wed, 17 Feb 2021 01:24:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4166A64E2F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.86085.161203 (Exim 4.92) (envelope-from ) id 1lCBZG-00052B-Tt; Wed, 17 Feb 2021 01:23:50 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 86085.161203; Wed, 17 Feb 2021 01:23:50 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lCBZG-000524-Qe; Wed, 17 Feb 2021 01:23:50 +0000 Received: by outflank-mailman (input) for mailman id 86085; Wed, 17 Feb 2021 01:23:49 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lCBZE-00051z-R2 for xen-devel@lists.xenproject.org; Wed, 17 Feb 2021 01:23:49 +0000 Received: from ozlabs.org (unknown [203.11.71.1]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d1540d77-9901-44cf-a17e-1308f2308352; Wed, 17 Feb 2021 01:23:46 +0000 (UTC) Received: by ozlabs.org (Postfix, from userid 1007) id 4DgKqL3R2Nz9sBy; Wed, 17 Feb 2021 12:23:42 +1100 (AEDT) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: d1540d77-9901-44cf-a17e-1308f2308352 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gibson.dropbear.id.au; s=201602; t=1613525022; bh=i5csGyCZLyAc9i3KKGsKbSkGDjy55sFRwjE1x4+/oxY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Ff/K0Qzt0Q0AP2MItzycNnHmFdzI6mf9iC+lPlww1oKVeZmInviIjsR7ruUoYr7V9 ymzTMv9Yst0C5F2rAOX9Zn3/plSkuqmotvRNBmq1cTFoofq3So1dLvfeGPXrDZbUFn J7yiV4TKbyfDnYdtPavRMb1n0MclRaE4K6TOf7zY= Date: Wed, 17 Feb 2021 11:44:41 +1100 From: David Gibson To: Alex =?iso-8859-1?Q?Benn=E9e?= Cc: qemu-devel@nongnu.org, julien@xen.org, stefano.stabellini@linaro.org, stefano.stabellini@xilinx.com, andre.przywara@arm.com, stratos-dev@op-lists.linaro.org, xen-devel@lists.xenproject.org, Alistair Francis Subject: Re: [PATCH v2 3/7] device_tree: add qemu_fdt_setprop_string_array helper Message-ID: References: <20210211171945.18313-1-alex.bennee@linaro.org> <20210211171945.18313-4-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="TO/drffHYp5rg2K/" Content-Disposition: inline In-Reply-To: <20210211171945.18313-4-alex.bennee@linaro.org> --TO/drffHYp5rg2K/ Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 11, 2021 at 05:19:41PM +0000, Alex Benn=E9e wrote: > A string array in device tree is simply a series of \0 terminated > strings next to each other. As libfdt doesn't support that directly > we need to build it ourselves. Hm, that might not make a bad extension to libfdt... >=20 > Signed-off-by: Alex Benn=E9e > Reviewed-by: Alistair Francis > Message-Id: <20201105175153.30489-4-alex.bennee@linaro.org> >=20 > --- > v2 > - checkpatch long line fix > --- > include/sysemu/device_tree.h | 17 +++++++++++++++++ > softmmu/device_tree.c | 26 ++++++++++++++++++++++++++ > 2 files changed, 43 insertions(+) >=20 > diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h > index 982c89345f..8a2fe55622 100644 > --- a/include/sysemu/device_tree.h > +++ b/include/sysemu/device_tree.h > @@ -70,6 +70,23 @@ int qemu_fdt_setprop_u64(void *fdt, const char *node_p= ath, > const char *property, uint64_t val); > int qemu_fdt_setprop_string(void *fdt, const char *node_path, > const char *property, const char *string); > + > +/** > + * qemu_fdt_setprop_string_array: set a string array property > + * > + * @fdt: pointer to the dt blob > + * @name: node name > + * @prop: property array > + * @array: pointer to an array of string pointers > + * @len: length of array > + * > + * assigns a string array to a property. This function converts and > + * array of strings to a sequential string with \0 separators before > + * setting the property. > + */ > +int qemu_fdt_setprop_string_array(void *fdt, const char *node_path, > + const char *prop, char **array, int le= n); > + > int qemu_fdt_setprop_phandle(void *fdt, const char *node_path, > const char *property, > const char *target_node_path); > diff --git a/softmmu/device_tree.c b/softmmu/device_tree.c > index b9a3ddc518..2691c58cf6 100644 > --- a/softmmu/device_tree.c > +++ b/softmmu/device_tree.c > @@ -21,6 +21,7 @@ > #include "qemu/error-report.h" > #include "qemu/option.h" > #include "qemu/bswap.h" > +#include "qemu/cutils.h" > #include "sysemu/device_tree.h" > #include "sysemu/sysemu.h" > #include "hw/loader.h" > @@ -397,6 +398,31 @@ int qemu_fdt_setprop_string(void *fdt, const char *n= ode_path, > return r; > } > =20 > +/* > + * libfdt doesn't allow us to add string arrays directly but they are > + * test a series of null terminated strings with a length. We build > + * the string up here so we can calculate the final length. > + */ > +int qemu_fdt_setprop_string_array(void *fdt, const char *node_path, > + const char *prop, char **array, int le= n) > +{ > + int ret, i, total_len =3D 0; > + char *str, *p; > + for (i =3D 0; i < len; i++) { > + total_len +=3D strlen(array[i]) + 1; > + } > + p =3D str =3D g_malloc0(total_len); > + for (i =3D 0; i < len; i++) { > + int len =3D strlen(array[i]) + 1; > + pstrcpy(p, len, array[i]); > + p +=3D len; > + } > + > + ret =3D qemu_fdt_setprop(fdt, node_path, prop, str, total_len); > + g_free(str); > + return ret; > +} > + > const void *qemu_fdt_getprop(void *fdt, const char *node_path, > const char *property, int *lenp, Error **er= rp) > { --=20 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 --TO/drffHYp5rg2K/ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEdfRlhq5hpmzETofcbDjKyiDZs5IFAmAsZvkACgkQbDjKyiDZ s5JkeBAAh1nq//jzuoFXH1RTHHchSWcXwSOQwwoKtEgNymV0OYnJvVeI87h02Ryf Q4AkWX0TRNC7xTP7fk9rJpYlIvDu+3M3fEQKu9Paz9taWc3lat8lHdRN+qoBaDuG 91smdKfWYGI1RHSj0C+pjDPa73He3JaNE4ooyJcpcAJEP38/jdVTBx1g82ZrksJQ iKBSapz/RBX5e7LSfm5NIB7OMDXWo8vORFopz+pUKIKDKNHTWGsf29zQchuNj7v9 n62ahTYFfN7CvOsEkwccA0sqaHEKSptUFeZ9YApO9zMj/FVlyjw73RCMGFbaWTlm m5dzj+wS+2n8iriX2pjbDp2bpREI3AJM23D5qArXfeH4ArmXNEc98canOD4/Y5zO KrnErOnvghtt7CXfjYYyKoWixTCMw0StbSnXsWJBnF0NXhtRr2DXKLbI2mPFRzac AnNXXAEs8CKtvWt/xPAwCTEMCTw9PkaUk18USAx2edDm+8lOWwzvRgMfDvvMRl7L ZJxr5MXP6ZWflZCY3tLXd4nD2DT+okaxNiKv8ZuNW0HEo4pYdwni0IVc8m8ZWlIB kEvPySjaxF5s38NoxB0ryAsuCEMnuJR8KP2cz3bYyVJ/tLE86+gevg1ztqCQzkyz sw23wgg9Ze5ypekPbLZJ/fpVNr5/bOs3tEAvLoc14qPVaJ4PpaQ= =OXJn -----END PGP SIGNATURE----- --TO/drffHYp5rg2K/--