From patchwork Tue May 3 18:24:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timur Tabi X-Patchwork-Id: 93874 X-Patchwork-Delegate: vanbaren@cideas.com 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 3EF15B6F14 for ; Wed, 4 May 2011 04:24:32 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id F03FE280D2; Tue, 3 May 2011 20:24:28 +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 4r4KfLK5QnaE; Tue, 3 May 2011 20:24:28 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C3BC428169; Tue, 3 May 2011 20:24:25 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 5D68028169 for ; Tue, 3 May 2011 20:24:23 +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 4G86+HuHN-gT for ; Tue, 3 May 2011 20:24:21 +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 TX2EHSOBE004.bigfish.com (tx2ehsobe002.messaging.microsoft.com [65.55.88.12]) by theia.denx.de (Postfix) with ESMTPS id 10292280D2 for ; Tue, 3 May 2011 20:24:19 +0200 (CEST) Received: from mail134-tx2-R.bigfish.com (10.9.14.254) by TX2EHSOBE004.bigfish.com (10.9.40.24) with Microsoft SMTP Server id 14.1.225.8; Tue, 3 May 2011 18:24:15 +0000 Received: from mail134-tx2 (localhost.localdomain [127.0.0.1]) by mail134-tx2-R.bigfish.com (Postfix) with ESMTP id D29D7AE8948; Tue, 3 May 2011 18:24:15 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h839h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI Received: from mail134-tx2 (localhost.localdomain [127.0.0.1]) by mail134-tx2 (MessageSwitch) id 1304447055654751_2100; Tue, 3 May 2011 18:24:15 +0000 (UTC) Received: from TX2EHSMHS015.bigfish.com (unknown [10.9.14.244]) by mail134-tx2.bigfish.com (Postfix) with ESMTP id 91B9C1518053; Tue, 3 May 2011 18:24:15 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by TX2EHSMHS015.bigfish.com (10.9.99.115) with Microsoft SMTP Server (TLS) id 14.1.225.8; Tue, 3 May 2011 18:24:10 +0000 Received: from az33smr02.freescale.net (10.64.34.200) by 039-SN1MMR1-001.039d.mgd.msft.net (10.84.1.13) with Microsoft SMTP Server id 14.1.270.2; Tue, 3 May 2011 13:24:09 -0500 Received: from efes.am.freescale.net (efes.am.freescale.net [10.82.123.3]) by az33smr02.freescale.net (8.13.1/8.13.0) with ESMTP id p43IO8j3009988; Tue, 3 May 2011 13:24:09 -0500 (CDT) From: Timur Tabi To: , , Date: Tue, 3 May 2011 13:24:07 -0500 Message-ID: <1304447048-14026-1-git-send-email-timur@freescale.com> X-Mailer: git-send-email 1.7.3.4 MIME-Version: 1.0 X-OriginatorOrg: freescale.com Subject: [U-Boot] [PATCH 1/2] [v2] fdt: introduce fdt_verify_alias_address() and fdt_get_base_address() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 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 Introduce two functions, fdt_verify_alias_address() and fdt_get_base_address(), which can be used to verify the physical address of a device in a device tree. fdt_get_base_address() returns the base address of an SOC or PCI node. fdt_verify_alias_address() prints a message if the address of a node specified by an alias does not match the given physical address. Signed-off-by: Timur Tabi --- common/fdt_support.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ include/fdt_support.h | 4 +++ 2 files changed, 71 insertions(+), 0 deletions(-) diff --git a/common/fdt_support.c b/common/fdt_support.c index 496040b..150a3c5 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1223,3 +1223,70 @@ err_size: return ret; } #endif + +/* + * Verify the physical address of device tree node for a given alias + * + * This function locates the device tree node of a given alias, and then + * verifies that the physical address of that device matches the given + * parameter. It displays a message if there is a mismatch. + * + * Returns 1 on success, 0 on failure + */ +int fdt_verify_alias_address(void *fdt, int anode, const char *alias, u64 addr) +{ + const char *path; + const u32 *reg; + int node, len; + u64 dt_addr; + + path = fdt_getprop(fdt, anode, alias, NULL); + if (!path) { + /* If there's no such alias, then it's not a failure */ + return 1; + } + + node = fdt_path_offset(fdt, path); + if (node < 0) { + printf("Warning: device tree alias '%s' points to invalid " + "node %s.\n", alias, path); + return 0; + } + + reg = fdt_getprop(fdt, node, "reg", &len); + if (!reg) { + printf("Warning: device tree node '%s' has no address.\n", + path); + return 0; + } + + dt_addr = fdt_translate_address(fdt, node, reg); + if (addr != dt_addr) { + printf("Warning: U-Boot configured device %s at address %llx,\n" + " but the device tree has it address %llx.\n", + alias, addr, dt_addr); + return 0; + } + + return 1; +} + +/* + * Returns the base address of an SOC or PCI node + */ +u64 fdt_get_base_address(void *fdt, int node) +{ + int size; + u32 naddr; + const u32 *prop; + + prop = fdt_getprop(fdt, node, "#address-cells", &size); + if (prop && size == 4) + naddr = *prop; + else + naddr = 2; + + prop = fdt_getprop(fdt, node, "ranges", &size); + + return prop ? fdt_translate_address(fdt, node, prop + naddr) : 0; +} diff --git a/include/fdt_support.h b/include/fdt_support.h index ce6817b..cefc990 100644 --- a/include/fdt_support.h +++ b/include/fdt_support.h @@ -90,5 +90,9 @@ int fdt_node_offset_by_compat_reg(void *blob, const char *compat, int fdt_alloc_phandle(void *blob); int fdt_add_edid(void *blob, const char *compat, unsigned char *buf); +int fdt_verify_alias_address(void *fdt, int anode, const char *alias, + u64 addr); +u64 fdt_get_base_address(void *fdt, int node); + #endif /* ifdef CONFIG_OF_LIBFDT */ #endif /* ifndef __FDT_SUPPORT_H */