From patchwork Sat Dec 3 02:57:48 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 129037 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id A32B5B6FF5 for ; Sat, 3 Dec 2011 13:58:31 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 0760128297; Sat, 3 Dec 2011 03:58:27 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LzLgV31X+H-2; Sat, 3 Dec 2011 03:58:26 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 6091E28298; Sat, 3 Dec 2011 03:58:12 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2F5D42826C for ; Sat, 3 Dec 2011 03:58:08 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PtbLT6tbHnM4 for ; Sat, 3 Dec 2011 03:58:06 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ee0-f74.google.com (mail-ee0-f74.google.com [74.125.83.74]) by theia.denx.de (Postfix) with ESMTPS id B93EF28272 for ; Sat, 3 Dec 2011 03:58:06 +0100 (CET) Received: by eekd41 with SMTP id d41so53121eek.3 for ; Fri, 02 Dec 2011 18:58:06 -0800 (PST) Received: by 10.14.17.75 with SMTP id i51mr1053270eei.1.1322881086159; Fri, 02 Dec 2011 18:58:06 -0800 (PST) Received: by 10.14.17.75 with SMTP id i51mr1053252eei.1.1322881085915; Fri, 02 Dec 2011 18:58:05 -0800 (PST) Received: from hpza9.eem.corp.google.com ([74.125.121.33]) by gmr-mx.google.com with ESMTPS id n13si6864041eef.2.2011.12.02.18.58.05 (version=TLSv1/SSLv3 cipher=AES128-SHA); Fri, 02 Dec 2011 18:58:05 -0800 (PST) Received: from wpaz5.hot.corp.google.com (wpaz5.hot.corp.google.com [172.24.198.69]) by hpza9.eem.corp.google.com (Postfix) with ESMTPS id 7A94F5C0050; Fri, 2 Dec 2011 18:58:05 -0800 (PST) Received: from sglass.mtv.corp.google.com (sglass.mtv.corp.google.com [172.22.72.144]) by wpaz5.hot.corp.google.com with ESMTP id pB32w3WO020749; Fri, 2 Dec 2011 18:58:03 -0800 Received: by sglass.mtv.corp.google.com (Postfix, from userid 121222) id CDB80140ADD; Fri, 2 Dec 2011 18:58:02 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Fri, 2 Dec 2011 18:57:48 -0800 Message-Id: <1322881071-11148-4-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.3.1 In-Reply-To: <1322881071-11148-1-git-send-email-sjg@chromium.org> References: <1322881071-11148-1-git-send-email-sjg@chromium.org> X-System-Of-Record: true Cc: Anton Staff , Jerry Van Baren , Tom Warren , Devicetree Discuss Subject: [U-Boot] [PATCH 3/6] fdt: Add fdtdec functions to read byte array X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Anton Staff Sometimes we don't need a full cell for each value. This provides a simple function to read a byte array, both with and without copying it. Signed-off-by: Simon Glass --- include/fdtdec.h | 32 ++++++++++++++++++++++++++++++++ lib/fdtdec.c | 24 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 0 deletions(-) diff --git a/include/fdtdec.h b/include/fdtdec.h index 9871b81..f72d219 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -231,3 +231,35 @@ int fdtdec_decode_gpio(const void *blob, int node, const char *prop_name, * @return 0 if all ok or gpio was FDT_GPIO_NONE; -1 on error */ int fdtdec_setup_gpio(struct fdt_gpio_state *gpio); + +/** + * Look up a property in a node and return its contents in a byte + * array of given length. The property must have at least enough data for + * the array (count bytes). It may have more, but this will be ignored. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @param array array to fill with data + * @param count number of array elements + * @return 0 if ok, or -FDT_ERR_MISSING if the property is not found, + * or -FDT_ERR_BADLAYOUT if not enough data + */ +int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, + u8 *array, int count); + +/** + * Look up a property in a node and return a pointer to its contents as a + * byte array of given length. The property must have at least enough data + * for the array (count bytes). It may have more, but this will be ignored. + * The data is not copied. + * + * @param blob FDT blob + * @param node node to examine + * @param prop_name name of property to find + * @param count number of array elements + * @return pointer to byte array if found, or NULL if the property is not + * found or there is not enough data + */ +const u8 *fdtdec_locate_byte_array(const void *blob, int node, + const char *prop_name, int count); diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 509b81f..90db53c 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -315,3 +315,27 @@ int fdtdec_setup_gpio(struct fdt_gpio_state *gpio) return gpio_direction_input(gpio->gpio); } } + +int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name, + u8 *array, int count) +{ + const u8 *cell; + int err; + + cell = get_prop_len(blob, node, prop_name, count, &err); + if (!err) + memcpy(array, cell, count); + return err; +} + +const u8 *fdtdec_locate_byte_array(const void *blob, int node, + const char *prop_name, int count) +{ + const u8 *cell; + int err; + + cell = get_prop_len(blob, node, prop_name, count, &err); + if (err) + return NULL; + return cell; +}