From nobody Thu Nov 14 17:08:54 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1602263824; cv=none; d=zohomail.com; s=zohoarc; b=OLPsWkVnu8eybi0EPvRJo+oZ1hSyjgYLKVrZhG0uCT37nk1fB2imdEYiWqnZU32Oum+6lYVQS3j1Jz0Bxf8CHHkH38Oqq1QmEM/en85uFGwxK+hAEWxTV3lX5wp2g4yxrX6SQ2G6Joq0Tfx1Z4AMXoaxSWsdB7q0sriRiqY/wtQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1602263824; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ZdPHbQWRDkMxBC6O5/k+6hitBUPm7MDCOKjfSyNLevM=; b=VCiZFKXCoO9QGzcPyRAS66kV0lKhZl0ro76///HngzY/+zkc38Qong10uhqgVyIDlNyqQnvmREtczj/LAPRxH4rdWX5Upj/AGc2jH4yoLOTXcWOnl3GtOhn1MdStphh7xChWTyfdlBw63rh8ZHqiWnieBzl1GM1e2QOu18ykF6M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1602263824573144.03036649973717; Fri, 9 Oct 2020 10:17:04 -0700 (PDT) Received: from localhost ([::1]:48930 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kQw0s-0006z6-Ue for importer@patchew.org; Fri, 09 Oct 2020 13:17:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46682) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kQvs4-0004am-Ri for qemu-devel@nongnu.org; Fri, 09 Oct 2020 13:07:56 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40736) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kQvs1-0001Je-1Q for qemu-devel@nongnu.org; Fri, 09 Oct 2020 13:07:56 -0400 Received: by mail-wr1-x444.google.com with SMTP id h5so977613wrv.7 for ; Fri, 09 Oct 2020 10:07:52 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id n9sm12345629wrq.72.2020.10.09.10.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Oct 2020 10:07:45 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 57A231FF8F; Fri, 9 Oct 2020 18:07:43 +0100 (BST) 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=ZdPHbQWRDkMxBC6O5/k+6hitBUPm7MDCOKjfSyNLevM=; b=QxJ8VjkOoFEw2blUOaL6YrmJYKFr72+rBo+ePvs8Q+7ts+IZdW24CKmosMAaP+DIzp 13qs66HVHwI3w348BC+87IO2Q9kwrog6OuO6O2F5WwRhI3ULVNUWBcHjpD9qffBwsC2A GySUQP0ArfaaCZEyRP23tIxRANgrNCLF1PAKWXcLN2VdbauTMSupSJzDc68JE61dDrZ3 XXNjrMIPWRlEMJ3wLLBoN6HElc+M2UtyVufb83/F0MGb3siQXOFUk0IQXN+4XQ5ttIVg Dkq3KUduwiCR14ZIr8lpZ33m+IS1tPnkYBaP6JwOdrZY3KvPM8gKR1cA16IuxlzMAdly zlMA== 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=ZdPHbQWRDkMxBC6O5/k+6hitBUPm7MDCOKjfSyNLevM=; b=TAPBTAG25JWh8MG0hP3VqD22tC7OV8VcD5rXmRTd0Twu2PKsQ12PFu1cllWeUZDV9p is3CW0jY+gZYNjUXF14yYEhZgAupo75i/UQRtIgoyUZG8bwj0i+QJmsUrsrJvTajzTu7 siiyIzZoRaVz9PL+XLPHDB33tsaIax69YQ0kyhPunoII0Wu98YdkRPq79RYXPmEMqE+Y qO3uqniy3k6eU11DA3RA8xkdnvNzeGx5tALlmIErN+6KD8L/c0rfja3qzEQGUrlVA4hZ A6CRQq7W9EuPg7WW2qTpMNtCndM+lbfE3ZI9Rp69b14SbFn5BEaW0mczsaT5YtHFrQIv Zb8g== X-Gm-Message-State: AOAM531C6k1SOF188KFt358ZC6FR7RgRawi2A0I40Z29LXaBS5JNRq4X 9HQ8bh/ZdAaR9LWSc71vx/y0Fj5iKn/b4Q== X-Google-Smtp-Source: ABdhPJzBTG8S2iDQv3fYepAE31HOUZQZmfqUfnAmzKqE2VuZs4KUujdBtI985biN7gAxGTvEVk0wAA== X-Received: by 2002:a5d:5449:: with SMTP id w9mr17032286wrv.182.1602263271620; Fri, 09 Oct 2020 10:07:51 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH 3/4] device_tree: add qemu_fdt_setprop_string_array helper Date: Fri, 9 Oct 2020 18:07:41 +0100 Message-Id: <20201009170742.23695-4-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201009170742.23695-1-alex.bennee@linaro.org> References: <20201009170742.23695-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::444; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x444.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=20Benn=C3=A9e?= , stratos-dev@op-lists.linaro.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) 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=C3=A9e --- include/sysemu/device_tree.h | 17 +++++++++++++++++ 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_pat= h, 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/device_tree.c b/device_tree.c index b335dae707..a19873316a 100644 --- a/device_tree.c +++ b/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 *nod= e_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 len) +{ + 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 **errp) { --=20 2.20.1