From patchwork Sat Jun 11 17:54:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Leach X-Patchwork-Id: 9171099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F71C604DB for ; Sat, 11 Jun 2016 17:59:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 244D11FFBD for ; Sat, 11 Jun 2016 17:59:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16E6D25D91; Sat, 11 Jun 2016 17:59:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C44E1FFBD for ; Sat, 11 Jun 2016 17:59:52 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bBnAh-0003zA-Nu; Sat, 11 Jun 2016 17:58:11 +0000 Received: from mx0.mattleach.net ([176.58.118.143]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1bBnAe-0003j9-HM for linux-arm-kernel@lists.infradead.org; Sat, 11 Jun 2016 17:58:09 +0000 Received: by mx0.mattleach.net (Postfix, from userid 99) id E98A76222F; Sat, 11 Jun 2016 18:57:45 +0100 (BST) Received: from localhost.localdomain (host109-154-191-76.range109-154.btcentralplus.com [109.154.191.76]) by mx0.mattleach.net (Postfix) with ESMTPSA id 44EBC6222B; Sat, 11 Jun 2016 18:57:45 +0100 (BST) From: Matthew Leach To: Russell King Subject: [PATCH] ARM: zImage: fix ATAG DTB conversion on big-endian Date: Sat, 11 Jun 2016 18:54:59 +0100 Message-Id: <20160611175459.5080-1-matthew@mattleach.net> X-Mailer: git-send-email 2.8.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160611_105808_896235_76C46FA5 X-CRM114-Status: GOOD ( 13.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Matthew Leach , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Since ATAGs are written out by the boot-loader before branching to the kernel, they will be written as little-endian; if the kernel has been built for big-endian, parsing of the ATAGs will fail. When reading from the ATAGs structure, swap the endianness (when required), allowing the DTB to be supplemented by the ATAG data. Signed-off-by: Matthew Leach --- arch/arm/boot/compressed/atags_to_fdt.c | 30 +++++++++++++++++------------- arch/arm/include/uapi/asm/setup.h | 6 ++++-- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/arch/arm/boot/compressed/atags_to_fdt.c b/arch/arm/boot/compressed/atags_to_fdt.c index 9448aa0..c7d3e74 100644 --- a/arch/arm/boot/compressed/atags_to_fdt.c +++ b/arch/arm/boot/compressed/atags_to_fdt.c @@ -123,9 +123,9 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) return 0; /* validate the ATAG */ - if (atag->hdr.tag != ATAG_CORE || - (atag->hdr.size != tag_size(tag_core) && - atag->hdr.size != 2)) + if (le32_to_cpu(atag->hdr.tag) != ATAG_CORE || + (le32_to_cpu(atag->hdr.size) != tag_size(tag_core) && + le32_to_cpu(atag->hdr.size) != 2)) return 1; /* let's give it all the room it could need */ @@ -134,7 +134,7 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) return ret; for_each_tag(atag, atag_list) { - if (atag->hdr.tag == ATAG_CMDLINE) { + if (le32_to_cpu(atag->hdr.tag) == ATAG_CMDLINE) { /* Append the ATAGS command line to the device tree * command line. * NB: This means that if the same parameter is set in @@ -147,10 +147,10 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) else setprop_string(fdt, "/chosen", "bootargs", atag->u.cmdline.cmdline); - } else if (atag->hdr.tag == ATAG_MEM) { + } else if (le32_to_cpu(atag->hdr.tag) == ATAG_MEM) { if (memcount >= sizeof(mem_reg_property)/4) continue; - if (!atag->u.mem.size) + if (!le32_to_cpu(atag->u.mem.size)) continue; memsize = get_cell_size(fdt); @@ -161,20 +161,24 @@ int atags_to_fdt(void *atag_list, void *fdt, int total_space) uint64_t *mem_reg_prop64 = (uint64_t *)mem_reg_property; mem_reg_prop64[memcount++] = - cpu_to_fdt64(atag->u.mem.start); + cpu_to_fdt64( + le32_to_cpu(atag->u.mem.start)); mem_reg_prop64[memcount++] = - cpu_to_fdt64(atag->u.mem.size); + cpu_to_fdt64( + le32_to_cpu(atag->u.mem.size)); } else { mem_reg_property[memcount++] = - cpu_to_fdt32(atag->u.mem.start); + cpu_to_fdt32( + le32_to_cpu(atag->u.mem.start)); mem_reg_property[memcount++] = - cpu_to_fdt32(atag->u.mem.size); + cpu_to_fdt32( + le32_to_cpu(atag->u.mem.size)); } - } else if (atag->hdr.tag == ATAG_INITRD2) { + } else if (le32_to_cpu(atag->hdr.tag) == ATAG_INITRD2) { uint32_t initrd_start, initrd_size; - initrd_start = atag->u.initrd.start; - initrd_size = atag->u.initrd.size; + initrd_start = le32_to_cpu(atag->u.initrd.start); + initrd_size = le32_to_cpu(atag->u.initrd.size); setprop_cell(fdt, "/chosen", "linux,initrd-start", initrd_start); setprop_cell(fdt, "/chosen", "linux,initrd-end", diff --git a/arch/arm/include/uapi/asm/setup.h b/arch/arm/include/uapi/asm/setup.h index 979ff40..00df12a 100644 --- a/arch/arm/include/uapi/asm/setup.h +++ b/arch/arm/include/uapi/asm/setup.h @@ -177,11 +177,13 @@ struct tagtable { ((unsigned long)(&((struct tag *)0L)->member + 1) \ <= (tag)->hdr.size * 4) -#define tag_next(t) ((struct tag *)((__u32 *)(t) + (t)->hdr.size)) +#define tag_next(t) ((struct tag *)((__u32 *)(t) + \ + le32_to_cpu((t)->hdr.size))) + #define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2) #define for_each_tag(t,base) \ - for (t = base; t->hdr.size; t = tag_next(t)) + for (t = base; le32_to_cpu(t->hdr.size); t = tag_next(t)) #endif /* _UAPI__ASMARM_SETUP_H */