From patchwork Thu Nov 5 17:51:41 2020 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: 319872 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=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT 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 D8A1FC55178 for ; Thu, 5 Nov 2020 17:57:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (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 4D89620709 for ; Thu, 5 Nov 2020 17:57:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="dVUscYXc" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D89620709 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:55268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kajVP-0000sl-6O for qemu-devel@archiver.kernel.org; Thu, 05 Nov 2020 12:57:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kajQk-00045x-Iu for qemu-devel@nongnu.org; Thu, 05 Nov 2020 12:52:14 -0500 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]:38742) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kajQh-0004pg-Ka for qemu-devel@nongnu.org; Thu, 05 Nov 2020 12:52:14 -0500 Received: by mail-wm1-x342.google.com with SMTP id h62so2451122wme.3 for ; Thu, 05 Nov 2020 09:52:06 -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=zcFV6Xll5pLIvhje0/+HAUCHWUfL1ANISG1KEVhrpQY=; b=dVUscYXcxYw2NMb+WxL5zOqB9qL9P5IPnOYGUL5YzALT00le5Y2IPhN+S7MY6r2yxY GK8fffo+50H99/E7bOmW2xipPp6cuh47EM6S5pLEYCPaQ4DYCWZTaZImSfC5BPDNNAUY jR1stu8PBlgG8nSlP+ErvYgfNPjad8JLkh3qdne9r24Oerd+erFJcmGLH8aJHzqrdXzl V3xBEOvK3Ubmvi3Eor8BrqVa7kL+L1k6sGLmm8KJ9nKfwgH0rJv2IWhzIjbwOgj60M9B rX6fr1itlTm1I9K7rT6OojEEvLZmTd6eu393AmN4WkyF2H7NFr4C3c6axWjBpDkiQ17K JhLw== 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=zcFV6Xll5pLIvhje0/+HAUCHWUfL1ANISG1KEVhrpQY=; b=uds5mDHyaB4/NvQ6/RtUl8BAPTQb4Uz1aemZkC5t7Zk41vubQoOknII0X6pic44yR3 YIeThH6DFg67BMYe51sEy4Pr/ZxnhCtN96idd9l9QlQoRPCitZamA/DjvvMxXfhaPrPl QBnytlJwg6C5LlANzn6veWoGHwT+Ozll+ekuvzEEQ7Njs8Zm9+HxFi+ZZ8l8+CmLVIak g2fECc91niik2ZL/Aj9xJ+a2rJWXGWVaLUNb3DRd7Ikome2XnAWjB/nEKwTdumhU4iQI WIBQIAQsywJ8KVphCkf/5nmb1wzVuadNd3GhWLacC1ovA3+mOW4cCqWQnwG0nyvymK2h HXhg== X-Gm-Message-State: AOAM5302b5+jvVxtNIjYiGvIfT/9WzTJyACcRTeMHcnATkNc1r/oN4Ai MFLpnqSq3FvPq5cZiAEoaFSRfg== X-Google-Smtp-Source: ABdhPJz6xQd2xybrGSF5UcqgRTO8fMHqNKnQxJt1xL+tqJUVFj1uynTFSGTyFcJG1mDyBVfTfAn04g== X-Received: by 2002:a1c:7f95:: with SMTP id a143mr3786214wmd.167.1604598725814; Thu, 05 Nov 2020 09:52:05 -0800 (PST) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id h4sm3703390wrp.52.2020.11.05.09.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 09:51:58 -0800 (PST) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 04B361FF8F; Thu, 5 Nov 2020 17:51:54 +0000 (GMT) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 03/15] device_tree: add qemu_fdt_setprop_string_array helper Date: Thu, 5 Nov 2020 17:51:41 +0000 Message-Id: <20201105175153.30489-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201105175153.30489-1-alex.bennee@linaro.org> References: <20201105175153.30489-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::342; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x342.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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: julien@xen.org, masami.hiramatsu@linaro.org, andre.przywara@arm.com, stefano.stabellini@linaro.org, takahiro.akashi@linaro.org, Alistair Francis , David Gibson , stefano.stabellini@xilinx.com, =?utf-8?q?Alex_Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.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: <20201021170842.25762-4-alex.bennee@linaro.org> Signed-off-by: Alex Bennée --- include/sysemu/device_tree.h | 17 +++++++++++++++++ softmmu/device_tree.c | 26 ++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) 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 b335dae707..a19873316a 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) {