From patchwork Mon Feb 27 20:52:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 143271 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 7A10EB6FE1 for ; Tue, 28 Feb 2012 07:53:55 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2377128345; Mon, 27 Feb 2012 21:53:47 +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 EmrcwGHx9uW0; Mon, 27 Feb 2012 21:53:46 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DCE5E28351; Mon, 27 Feb 2012 21:53:28 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 112422833B for ; Mon, 27 Feb 2012 21:53:25 +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 V9qoHfxggrCB for ; Mon, 27 Feb 2012 21:53:24 +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-yx0-f202.google.com (mail-yx0-f202.google.com [209.85.213.202]) by theia.denx.de (Postfix) with ESMTPS id 7A0F828320 for ; Mon, 27 Feb 2012 21:53:21 +0100 (CET) Received: by yenq2 with SMTP id q2so118118yen.3 for ; Mon, 27 Feb 2012 12:53:20 -0800 (PST) Received-SPF: pass (google.com: domain of sjg@google.com designates 10.236.146.106 as permitted sender) client-ip=10.236.146.106; Authentication-Results: mr.google.com; spf=pass (google.com: domain of sjg@google.com designates 10.236.146.106 as permitted sender) smtp.mail=sjg@google.com Received: from mr.google.com ([10.236.146.106]) by 10.236.146.106 with SMTP id q70mr29633838yhj.0.1330376000711 (num_hops = 1); Mon, 27 Feb 2012 12:53:20 -0800 (PST) Received: by 10.236.146.106 with SMTP id q70mr19701365yhj.0.1330376000700; Mon, 27 Feb 2012 12:53:20 -0800 (PST) MIME-Version: 1.0 Received: by 10.236.146.106 with SMTP id q70mr19701334yhj.0.1330376000621; Mon, 27 Feb 2012 12:53:20 -0800 (PST) Received: from wpzn3.hot.corp.google.com (216-239-44-65.google.com [216.239.44.65]) by gmr-mx.google.com with ESMTPS id d20si9016623yhj.1.2012.02.27.12.53.20 (version=TLSv1/SSLv3 cipher=AES128-SHA); Mon, 27 Feb 2012 12:53:20 -0800 (PST) Received: from sglass.mtv.corp.google.com (sglass.mtv.corp.google.com [172.22.72.144]) by wpzn3.hot.corp.google.com (Postfix) with ESMTP id 7168010005D; Mon, 27 Feb 2012 12:53:20 -0800 (PST) Received: by sglass.mtv.corp.google.com (Postfix, from userid 121222) id 300B1140EB8; Mon, 27 Feb 2012 12:53:20 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Date: Mon, 27 Feb 2012 12:52:34 -0800 Message-Id: <1330375973-10681-2-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.7.7.3 In-Reply-To: <1330375973-10681-1-git-send-email-sjg@chromium.org> References: <1330375973-10681-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlsS1Sdi3L7NyjKvmShIrYyM5a6z1jMQgOVNtMk/vuziGQ1Fln7+BR35C9iwP/xEsjzhnR2AVcFPdDYkMAa7X9o0sXkSgbjDXbAlw9Oj4S64FBiPDiPScMG5K8HGkQ33UBPxsnzy4lHEw7LAImjS6ufLPMYeYoVUodBqX9MKS6i7GAVoH4= Cc: Devicetree Discuss , Tom Warren , Jerry Van Baren Subject: [U-Boot] [PATCH v6 01/20] fdt: Tidy up a few fdtdec problems 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: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de This fixes five trivial issues in fdtdec.c: 1. fdtdec_get_is_enabled() doesn't really need a default value 2. The fdt must be word-aligned, since otherwise it will fail on ARM 3. The compat_names[] array is missing its first element. This is needed only because the first fdt_compat_id is defined to be invalid. 4. Added a header prototype for fdtdec_next_compatible() 5. Change fdtdec_next_alias() to only increment its 'upto' parameter on success, to make the display error messages in the caller easier. Signed-off-by: Simon Glass Acked-by: Gerald Van Baren Acked-by: Stephen Warren --- include/fdtdec.h | 23 +++++++++++++++++++---- lib/fdtdec.c | 22 ++++++++++++++++------ 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/fdtdec.h b/include/fdtdec.h index 3a15f55..01badd4 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -82,6 +82,21 @@ int fdtdec_next_alias(const void *blob, const char *name, enum fdt_compat_id id, int *upto); /** + * Find the next compatible node for a peripheral. + * + * Do the first call with node = 0. This function will return a pointer to + * the next compatible node. Next time you call this function, pass the + * value returned, and the next node will be provided. + * + * @param blob FDT blob to use + * @param node Start node for search + * @param id Compatible ID to look for (enum fdt_compat_id) + * @return offset of next compatible node, or -FDT_ERR_NOTFOUND if no more + */ +int fdtdec_next_compatible(const void *blob, int node, + enum fdt_compat_id id); + +/** * Look up an address property in a node and return it as an address. * The property must hold either one address with no trailing data or * one address with a length. This is only tested on 32-bit machines. @@ -112,14 +127,14 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name, * Checks whether a node is enabled. * This looks for a 'status' property. If this exists, then returns 1 if * the status is 'ok' and 0 otherwise. If there is no status property, - * it returns the default value. + * it returns 1 on the assumption that anything mentioned should be enabled + * by default. * * @param blob FDT blob * @param node node to examine - * @param default_val default value to return if no 'status' property exists - * @return integer value 0/1, if found, or default_val if not + * @return integer value 0 (not enabled) or 1 (enabled) */ -int fdtdec_get_is_enabled(const void *blob, int node, int default_val); +int fdtdec_get_is_enabled(const void *blob, int node); /** * Checks whether we have a valid fdt available to control U-Boot, and panic diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 3852038..846ec3f 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -33,6 +33,7 @@ DECLARE_GLOBAL_DATA_PTR; */ #define COMPAT(id, name) name static const char * const compat_names[COMPAT_COUNT] = { + COMPAT(UNKNOWN, ""), }; const char *fdtdec_get_compatible(enum fdt_compat_id id) @@ -89,14 +90,21 @@ s32 fdtdec_get_int(const void *blob, int node, const char *prop_name, return default_val; } -int fdtdec_get_is_enabled(const void *blob, int node, int default_val) +int fdtdec_get_is_enabled(const void *blob, int node) { const char *cell; + /* + * It should say "okay", so only allow that. Some fdts use "ok" but + * this is a bug. Please fix your device tree source file. See here + * for discussion: + * + * http://www.mail-archive.com/u-boot@lists.denx.de/msg71598.html + */ cell = fdt_getprop(blob, node, "status", NULL); if (cell) - return 0 == strcmp(cell, "ok"); - return default_val; + return 0 == strcmp(cell, "okay"); + return 1; } enum fdt_compat_id fd_dec_lookup(const void *blob, int node) @@ -127,14 +135,16 @@ int fdtdec_next_alias(const void *blob, const char *name, /* snprintf() is not available */ assert(strlen(name) < MAX_STR_LEN); sprintf(str, "%.*s%d", MAX_STR_LEN, name, *upto); - (*upto)++; node = find_alias_node(blob, str); if (node < 0) return node; err = fdt_node_check_compatible(blob, node, compat_names[id]); if (err < 0) return err; - return err ? -FDT_ERR_NOTFOUND : node; + if (err) + return -FDT_ERR_NOTFOUND; + (*upto)++; + return node; } /* TODO: Can we tighten this code up a little? */ @@ -254,7 +264,7 @@ int fdtdec_find_aliases_for_id(const void *blob, const char *name, int fdtdec_check_fdt(void) { /* We must have an fdt */ - if (fdt_check_header(gd->fdt_blob)) + if (((uintptr_t)gd->fdt_blob & 3) || fdt_check_header(gd->fdt_blob)) panic("No valid fdt found - please append one to U-Boot\n" "binary or define CONFIG_OF_EMBED\n"); return 0;