From patchwork Wed Mar 10 15:59:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 396769 Delivered-To: patch@linaro.org Received: by 2002:a02:8562:0:0:0:0:0 with SMTP id g89csp517878jai; Wed, 10 Mar 2021 08:31:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3AuOwRemacnMLRFc1eFB/fhxdgTvY9sc7iyHwBcJWx2hZvNIdedfw2HIarbQpfyMBzebM X-Received: by 2002:a67:c80e:: with SMTP id u14mr2220766vsk.39.1615393906311; Wed, 10 Mar 2021 08:31:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615393906; cv=none; d=google.com; s=arc-20160816; b=d+YiuKisqVTTabsMiJCOXJIQXHrzHRNC4u6gOKg7I00RFKMHebR4a0GWy7xqOgJ1Pb H7wec6x2IXJfsaIwH3+oMx3452+a5TaHIGLsZW7NvrRy92Lj0pDieXL/7rulGVVqpoJH Z1v8rGOLVT2dexyI/A8a9oGoLfH16tOrJf7Sp5SNPvHJvm1amDn5NnR5WW9SmbRAvKCZ lzG12rd8kDEUUfEO5plprYsc6iM4JhHlEvNpoqL0uDZ6XlaH6yn2xiJ36JPx23nRZ71h wtoP5AbM9f6QWpgP804ormbpkvIO1xzRWYp8KIzNkiZ/7ax3NZxPYiYaFiJg+ZExGc7v jtew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=qdRJRL3+3BE/JH14YpiGu383dDrAlP7VpAQihL8OqOE=; b=kf9eHZ9xmQJWUTwflglhKdwv2UxU0NwFrLTW0QvoXz5lmeNsawkc/P82Nw+ImP0w9D uBwHA1hg/iFShJNAEE2C7w1saK1ceIbl+B+e3Nni8i7iXZ2PkEQso8Fq56nwrLLl1XdN xF0dG6fY7lplAA+PSBmU3Fd9pfO9AAvNCk8ekLVVUMAMv4Get0LaNRbmbFmBk5hjDMsp Jwo9wfBWmNU3Cv1UAOJKwv9g6mdgwu8gigH5N76WWWAFwRPXBWtCAH7z9VZ62P3sNoPz /v16jB1cC+SDSHn2RjEjmaFvZXGwfbJXQSWDm2L/d/Y+RHy6Vu64xfc9LOdeCeIwyAHB 4ToQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LFK799t9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id h203si3186956vkh.16.2021.03.10.08.31.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 10 Mar 2021 08:31:46 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LFK799t9; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:36276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lK1kP-0001Ue-FP for patch@linaro.org; Wed, 10 Mar 2021 11:31:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:37230) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lK1NP-0001li-QN for qemu-devel@nongnu.org; Wed, 10 Mar 2021 11:08:00 -0500 Received: from mail-ej1-x633.google.com ([2a00:1450:4864:20::633]:42374) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lK1NN-0006Rv-PU for qemu-devel@nongnu.org; Wed, 10 Mar 2021 11:07:59 -0500 Received: by mail-ej1-x633.google.com with SMTP id c10so39685315ejx.9 for ; Wed, 10 Mar 2021 08:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qdRJRL3+3BE/JH14YpiGu383dDrAlP7VpAQihL8OqOE=; b=LFK799t9OUVqJTmgr0NxCRH06m+pOQ2WGKcfwcGPqJWlC2USG4niI7oxd7PnmVgMiH KelHXgSUDeHu2307CpSvdMV+AUD7ErKezEum4T9mnsafPiBc9umQ+Rxi66LfhDjEG9sd QRiaSK36ueE2xbwtZ6mwVQfe88UYZmS5HAAQ0L/z1BsKjwzDnbExkrwxqwpwUC1PoFo4 yfetP8xIVBumzHcatPC9SZnHoktu+hnUvmkxBI6PAAsXHVh+4vYzG50aVMDfUU0DP3xf d92w1RGXro75SrAzqkRa27DMKEQ9U0LlU/9/8URSWTlbk3Y84KzdlpnAuXabYU7KMTDD r1Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qdRJRL3+3BE/JH14YpiGu383dDrAlP7VpAQihL8OqOE=; b=NQtsvq8pg3UkI4y6togsbFSNveeDIPEIklXgNdkXEikWITWZQ/SMPT3PaGaHFdr7NX H1u+PDGRfqE9aiCLUJZYz0uvzroVXUmRVWWalqRNp0z7xAH97PLFkNh303jaga+iDYww cJifQ95sZixek/+guhYm+skfPTdQeKrcgLCoC2Hb9gz3+CZP10FS9/3EzgCq5J2TEfQg HJzW+xIN2woFxjuxXWxWfhkpHNjjO8mioAZ4znjsK1P3vQtqNAU2VDWhld2F6ZV4N/2f vgMlcYnllvZKWE2S+wDqq6vR7lr5eS6otO7g1f8IGmR2Jn3IQlJe3m5rS5DnLUpjTdGE Lwpg== X-Gm-Message-State: AOAM531LGl06GjikSzic/POS5IU0+EAF6Ygemq1dTL1RLLPdaQwGV2I8 zxQR4AfySI+Mmk55Pau8ss8E7g== X-Received: by 2002:a17:906:1444:: with SMTP id q4mr4474861ejc.343.1615392476168; Wed, 10 Mar 2021 08:07:56 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id q1sm10101442ejt.65.2021.03.10.08.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Mar 2021 08:07:55 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 6C9D11FF98; Wed, 10 Mar 2021 16:00:03 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL v2 09/15] device_tree: add qemu_fdt_setprop_string_array helper Date: Wed, 10 Mar 2021 15:59:56 +0000 Message-Id: <20210310160002.11659-10-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210310160002.11659-1-alex.bennee@linaro.org> References: <20210310160002.11659-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::633; envelope-from=alex.bennee@linaro.org; helo=mail-ej1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alistair Francis , =?utf-8?q?Alex_Benn=C3=A9?= =?utf-8?q?e?= , qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" 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. Signed-off-by: Alex Bennée Reviewed-by: Alistair Francis Message-Id: <20210303173642.3805-4-alex.bennee@linaro.org> -- 2.20.1 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_path, 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 len); + 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 *node_path, return r; } +/* + * 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 len) +{ + int ret, i, total_len = 0; + char *str, *p; + for (i = 0; i < len; i++) { + total_len += strlen(array[i]) + 1; + } + p = str = g_malloc0(total_len); + for (i = 0; i < len; i++) { + int len = strlen(array[i]) + 1; + pstrcpy(p, len, array[i]); + p += len; + } + + ret = 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 **errp) {