From patchwork Tue Oct 22 08:05:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 1181129 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="ucDh02aR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 46y5qx4Tsfz9sNx for ; Tue, 22 Oct 2019 19:13:49 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4DC7BC21E77; Tue, 22 Oct 2019 08:13:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 16D91C21DFA; Tue, 22 Oct 2019 08:06:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id D4620C21E0F; Tue, 22 Oct 2019 08:06:20 +0000 (UTC) Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lists.denx.de (Postfix) with ESMTPS id 150ACC21EA2 for ; Tue, 22 Oct 2019 08:05:41 +0000 (UTC) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id x9M85eQg095590; Tue, 22 Oct 2019 03:05:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1571731540; bh=0JCx34NMZZIXJ1HiQlTJMEm661XD4N6M0YGYn73N1QM=; h=From:To:CC:Subject:Date; b=ucDh02aR00U5137sRFGFosIu8jlZWbA45c4JTxhGDDlGFBZ0sf3dTJdziLckFjfA2 49NNhIUWd9x/as0WCzvH6VSKc5cV3cdMwhGXpZdCH8v8gffgQ6+TCGvuXyyOM1sCKX ToZ5Re2p5/4m7LmC0xemtwOJ3iOaZErmGuEDMQdc= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x9M85PAT071013 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 22 Oct 2019 03:05:25 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5; Tue, 22 Oct 2019 03:05:15 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1713.5 via Frontend Transport; Tue, 22 Oct 2019 03:05:15 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id x9M85OCp090108; Tue, 22 Oct 2019 03:05:24 -0500 From: Jean-Jacques Hiblot To: Date: Tue, 22 Oct 2019 10:05:22 +0200 Message-ID: <20191022080522.2113-1-jjhiblot@ti.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2] fdt: Fix alignment issue when reading 64-bits properties from fdt X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" The FDT specification [0] gives a requirement of aligning properties on 32-bits. Make sure that the compiler is aware of this constraint when accessing 64-bits properties. [0]: https://github.com/devicetree-org/devicetree-specification/blob/master/source/flattened-format.rst Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Simon Glass Reviewed-by: Simon Glass --- Here is a portion of the disassembly of ofnode_read_u64(). It show the effect of the patch on ARM64. with the classic fdt64_t type. GCC emits LDR (load register) 34: 54000109 b.ls 54 // b.plast 38: f9400000 ldr x0, [x0] 3c: dac00c00 rev x0, x0 with the unaligned_fdt64_t type. GCC emits LDP (Load Pair of registers) 34: 54000129 b.ls 58 // b.plast 38: 29400001 ldp w1, w0, [x0] 3c: aa008020 orr x0, x1, x0, lsl #32 40: dac00c00 rev x0, x0 common/fdt_support.c | 2 +- drivers/core/ofnode.c | 2 +- include/linux/libfdt_env.h | 1 + lib/fdtdec.c | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/common/fdt_support.c b/common/fdt_support.c index baf7924ff6..6834399039 100644 --- a/common/fdt_support.c +++ b/common/fdt_support.c @@ -1566,7 +1566,7 @@ static int fdt_read_prop(const fdt32_t *prop, int prop_len, int cell_off, uint64_t *val, int cells) { const fdt32_t *prop32 = &prop[cell_off]; - const fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off]; + const unaligned_fdt64_t *prop64 = (const fdt64_t *)&prop[cell_off]; if ((cell_off + cells) > prop_len) return -FDT_ERR_NOSPACE; diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 297f0a0c7c..8f0eab2ca6 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -57,7 +57,7 @@ int ofnode_read_s32_default(ofnode node, const char *propname, s32 def) int ofnode_read_u64(ofnode node, const char *propname, u64 *outp) { - const fdt64_t *cell; + const unaligned_fdt64_t *cell; int len; assert(ofnode_valid(node)); diff --git a/include/linux/libfdt_env.h b/include/linux/libfdt_env.h index e2bf79c7ee..e49fcd72bd 100644 --- a/include/linux/libfdt_env.h +++ b/include/linux/libfdt_env.h @@ -16,6 +16,7 @@ typedef __be16 fdt16_t; typedef __be32 fdt32_t; typedef __be64 fdt64_t; +typedef __be64 unaligned_fdt64_t __aligned(4); #define fdt32_to_cpu(x) be32_to_cpu(x) #define cpu_to_fdt32(x) cpu_to_be32(x) diff --git a/lib/fdtdec.c b/lib/fdtdec.c index 17736ce665..125d9dbf26 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -242,7 +242,7 @@ int fdtdec_get_pci_bar32(struct udevice *dev, struct fdt_pci_addr *addr, uint64_t fdtdec_get_uint64(const void *blob, int node, const char *prop_name, uint64_t default_val) { - const uint64_t *cell64; + const unaligned_fdt64_t *cell64; int length; cell64 = fdt_getprop(blob, node, prop_name, &length);