From patchwork Mon Jan 9 15:08:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Andreas_F=C3=A4rber?= X-Patchwork-Id: 712791 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 3txzTJ1NFsz9t14 for ; Tue, 10 Jan 2017 02:24:03 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AECC9A7675; Mon, 9 Jan 2017 16:23:58 +0100 (CET) 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 l0PbgMNR-64d; Mon, 9 Jan 2017 16:23:58 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EE15CA75FD; Mon, 9 Jan 2017 16:23:57 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4A7B8A75FD for ; Mon, 9 Jan 2017 16:23:53 +0100 (CET) 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 gHLx13XaCmqu for ; Mon, 9 Jan 2017 16:23:53 +0100 (CET) X-Greylist: delayed 942 seconds by postgrey-1.34 at theia; Mon, 09 Jan 2017 16:23:50 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 mx2.suse.de (mx2.suse.de [195.135.220.15]) by theia.denx.de (Postfix) with ESMTPS id 18D5FA75E9 for ; Mon, 9 Jan 2017 16:23:50 +0100 (CET) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 08CB1AC6A; Mon, 9 Jan 2017 15:08:08 +0000 (UTC) From: =?UTF-8?q?Andreas=20F=C3=A4rber?= To: u-boot@lists.denx.de Date: Mon, 9 Jan 2017 16:08:02 +0100 Message-Id: <20170109150803.6582-1-afaerber@suse.de> X-Mailer: git-send-email 2.10.2 MIME-Version: 1.0 Cc: Joe Hershberger , =?UTF-8?q?Andreas=20F=C3=A4rber?= , Gerald Van Baren Subject: [U-Boot] [PATCH v2] cmd/fdt: Make fdt get value endian-safe for single-cell properties X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" On a Raspberry Pi 2 disagreements on cell endianness can be observed: U-Boot> fdt print /soc/gpio@7e200000 phandle phandle = <0x0000000d> U-Boot> fdt get value myvar /soc/gpio@7e200000 phandle; printenv myvar myvar=0x0D000000 Fix this by always treating the pointer as BE and converting it in fdt_value_setenv(), like its counterpart fdt_parse_prop() already does. Consistently use fdt32_t, fdt32_to_cpu() and cpu_to_fdt32(). Fixes: bc80295 ("fdt: Add get commands to fdt") Cc: Joe Hershberger Cc: Gerald Van Baren Signed-off-by: Andreas Färber Acked-by: Simon Glass --- cmd/fdt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/fdt.c b/cmd/fdt.c index 8bd345a..42397d1 100644 --- a/cmd/fdt.c +++ b/cmd/fdt.c @@ -58,7 +58,7 @@ static int fdt_value_setenv(const void *nodep, int len, const char *var) else if (len == 4) { char buf[11]; - sprintf(buf, "0x%08X", *(uint32_t *)nodep); + sprintf(buf, "0x%08X", fdt32_to_cpu(*(fdt32_t *)nodep)); setenv(var, buf); } else if (len%4 == 0 && len <= 20) { /* Needed to print things like sha1 hashes. */ @@ -764,7 +764,7 @@ static int fdt_parse_prop(char * const *newval, int count, char *data, int *len) cp = newp; tmp = simple_strtoul(cp, &newp, 0); - *(__be32 *)data = __cpu_to_be32(tmp); + *(fdt32_t *)data = cpu_to_fdt32(tmp); data += 4; *len += 4;