From patchwork Tue Aug 26 15:33:51 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 383123 X-Patchwork-Delegate: sjg@chromium.org 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 2ECDB1400AA for ; Wed, 27 Aug 2014 01:35:28 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 64B59B37E5; Tue, 26 Aug 2014 17:35:26 +0200 (CEST) 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 sjx684FYY19Z; Tue, 26 Aug 2014 17:35:26 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C7C7FB37B4; Tue, 26 Aug 2014 17:34:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AF86DA7447 for ; Tue, 26 Aug 2014 17:34:43 +0200 (CEST) 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 bOSPBXYc55a7 for ; Tue, 26 Aug 2014 17:34:40 +0200 (CEST) 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-wi0-f171.google.com (mail-wi0-f171.google.com [209.85.212.171]) by theia.denx.de (Postfix) with ESMTPS id 03EF2AB57A for ; Tue, 26 Aug 2014 17:34:35 +0200 (CEST) Received: by mail-wi0-f171.google.com with SMTP id hi2so4411552wib.10 for ; Tue, 26 Aug 2014 08:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=q+cMP+uTmFzcPDB67yok2oTdIWR1hVVjXC+p2BJ2dac=; b=Z+gi9c9kShrB5x7TYYeTgkMdJWHQO4804cosdXmNHDkxxQSZmBaNK6NQ6ZbIAaf7H/ MYvuyW+HhInReioYsG8dw+V+eOwXrH1AI1NkY1ZeRgcUdp2Q8NGOxL2Bwx2dt2/M+4b5 hn45Y0M637IlDqhGd8+MEbsXOYfzuzxGL2lDpqxPeZ9i54lrUxlvlHY3o4JQkHmuyVfK b08QQ3wymaCrnwbm1T5IRyjIz65aSdms1ip+DDJsqPVX1TSJSj09KBWTF6NRL0oQ5DRT V3AnjXKmeKTon5bOl9RcojLX5ESvA14iBB8jQlnazcZ3oQXLf3MTLPLTEOC+R1h/4/mK exLA== X-Received: by 10.180.95.135 with SMTP id dk7mr22242420wib.68.1409067275723; Tue, 26 Aug 2014 08:34:35 -0700 (PDT) Received: from localhost (port-7111.pppoe.wtnet.de. [84.46.27.226]) by mx.google.com with ESMTPSA id mv14sm13241860wic.20.2014.08.26.08.34.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Aug 2014 08:34:35 -0700 (PDT) From: Thierry Reding To: Tom Warren , Simon Glass Date: Tue, 26 Aug 2014 17:33:51 +0200 Message-Id: <1409067268-956-4-git-send-email-thierry.reding@gmail.com> X-Mailer: git-send-email 2.0.4 In-Reply-To: <1409067268-956-1-git-send-email-thierry.reding@gmail.com> References: <1409067268-956-1-git-send-email-thierry.reding@gmail.com> Cc: u-boot@lists.denx.de, Stephen Warren Subject: [U-Boot] [PATCH v2 03/40] fdt: Add a function to get the index of a string 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: Thierry Reding Given a device tree node and a property name, the new fdt_find_string() function will look up a given string in the string list contained in the property's value and return its index. Signed-off-by: Thierry Reding Acked-by: Simon Glass --- Changes in v2: - rename to fdt_find_string() to remove naming conflicts with other new functions - correctly increment string list pointer include/libfdt.h | 11 +++++++++++ lib/libfdt/fdt_ro.c | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/include/libfdt.h b/include/libfdt.h index cf97bf0b3b52..d0dea668eea2 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -866,6 +866,17 @@ int fdt_stringlist_contains(const char *strlist, int listlen, const char *str); */ int fdt_count_strings(const void *fdt, int node, const char *property); +/** + * fdt_find_string - find a string in a string list and return its index + * @fdt: pointer to the device tree blob + * @node: offset of the node + * @property: name of the property containing the string list + * @string: string to look up in the string list + * @return: the index of the string or negative on error + */ +int fdt_find_string(const void *fdt, int node, const char *property, + const char *string); + /**********************************************************************/ /* Read-only functions (addressing related) */ /**********************************************************************/ diff --git a/lib/libfdt/fdt_ro.c b/lib/libfdt/fdt_ro.c index cb06a9b50d85..fec4a0a141fd 100644 --- a/lib/libfdt/fdt_ro.c +++ b/lib/libfdt/fdt_ro.c @@ -511,6 +511,32 @@ int fdt_count_strings(const void *fdt, int node, const char *property) return count; } +int fdt_find_string(const void *fdt, int node, const char *property, + const char *string) +{ + const char *list, *end; + int len, index = 0; + + list = fdt_getprop(fdt, node, property, &len); + if (!list) + return len; + + end = list + len; + len = strlen(string); + + while (list < end) { + int l = strlen(list); + + if (l == len && memcmp(list, string, len) == 0) + return index; + + list += l + 1; + index++; + } + + return -FDT_ERR_NOTFOUND; +} + int fdt_node_check_compatible(const void *fdt, int nodeoffset, const char *compatible) {