From patchwork Tue Aug 2 09:23:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 3224 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id E788723F3F for ; Tue, 2 Aug 2011 16:24:29 +0000 (UTC) Received: from mail-qw0-f52.google.com (mail-qw0-f52.google.com [209.85.216.52]) by fiordland.canonical.com (Postfix) with ESMTP id B65D9A18529 for ; Tue, 2 Aug 2011 16:24:29 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so5003071qwb.11 for ; Tue, 02 Aug 2011 09:24:29 -0700 (PDT) Received: by 10.229.183.84 with SMTP id cf20mr1849851qcb.121.1312302269498; Tue, 02 Aug 2011 09:24:29 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.229.6.73 with SMTP id 9cs128902qcy; Tue, 2 Aug 2011 09:24:29 -0700 (PDT) Received: by 10.68.63.37 with SMTP id d5mr112497pbs.128.1312302268626; Tue, 02 Aug 2011 09:24:28 -0700 (PDT) Received: from VA3EHSOBE010.bigfish.com (va3ehsobe010.messaging.microsoft.com [216.32.180.30]) by mx.google.com with ESMTPS id h6si11462682pbc.20.2011.08.02.09.24.27 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 02 Aug 2011 09:24:28 -0700 (PDT) Received-SPF: neutral (google.com: 216.32.180.30 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) client-ip=216.32.180.30; Authentication-Results: mx.google.com; spf=neutral (google.com: 216.32.180.30 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) smtp.mail=shawn.guo@linaro.org Received: from mail190-va3-R.bigfish.com (10.7.14.240) by VA3EHSOBE010.bigfish.com (10.7.40.12) with Microsoft SMTP Server id 14.1.225.22; Tue, 2 Aug 2011 16:24:27 +0000 Received: from mail190-va3 (localhost.localdomain [127.0.0.1]) by mail190-va3-R.bigfish.com (Postfix) with ESMTP id EDE0A2B82D3; Tue, 2 Aug 2011 16:24:26 +0000 (UTC) X-SpamScore: 4 X-BigFish: VS4(z37d4lzzz1202hzz8275bh8275dhz2dh87h2a8h668h839h64h) X-Spam-TCS-SCL: 3:0 X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPVD:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-FB-DOMAIN-IP-MATCH: fail Received: from mail190-va3 (localhost.localdomain [127.0.0.1]) by mail190-va3 (MessageSwitch) id 1312302266668082_12038; Tue, 2 Aug 2011 16:24:26 +0000 (UTC) Received: from VA3EHSMHS030.bigfish.com (unknown [10.7.14.239]) by mail190-va3.bigfish.com (Postfix) with ESMTP id 9D89711E0050; Tue, 2 Aug 2011 16:24:26 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by VA3EHSMHS030.bigfish.com (10.7.99.40) with Microsoft SMTP Server (TLS) id 14.1.225.22; Tue, 2 Aug 2011 16:24:24 +0000 Received: from az33smr01.freescale.net (10.64.34.199) by 039-SN1MMR1-003.039d.mgd.msft.net (10.84.1.16) with Microsoft SMTP Server id 14.1.289.8; Tue, 2 Aug 2011 11:24:24 -0500 Received: from ubuntu.ea.freescale.net ([10.214.137.140]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id p72GOIt2006784; Tue, 2 Aug 2011 11:24:22 -0500 (CDT) From: Shawn Guo To: CC: , Nicolas Pitre Subject: [PATCH 3/4] ARM: zImage: make sure appended DTB doesn't get overwritten by kernel .bss Date: Tue, 2 Aug 2011 17:23:45 +0800 Message-ID: <1312277026-25782-3-git-send-email-shawn.guo@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1312277026-25782-1-git-send-email-shawn.guo@linaro.org> References: <1312277026-25782-1-git-send-email-shawn.guo@linaro.org> MIME-Version: 1.0 X-OriginatorOrg: sigmatel.com From: Nicolas Pitre The appended DTB gets relocated with the decompressor code to get out of the way of the decompressed kernel. However the kernel's .bss section may be larger than the relocated code and data, and then the DTB gets overwritten. Let's make sure the relocation takes care of moving zImage far enough so no such conflict with .bss occurs. Thanks to Tony Lindgren for figuring out this issue. While at it, let's clean up the code a bit so that the wont_overwrite symbol is used while determining if a conflict exists, making the above change more precise as well as eliminating some ARM/THUMB alternates. Signed-off-by: Nicolas Pitre Acked-by: Tony Lindgren --- arch/arm/boot/compressed/Makefile | 3 +++ arch/arm/boot/compressed/head.S | 19 +++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/arch/arm/boot/compressed/Makefile b/arch/arm/boot/compressed/Makefile index 0c74a6f..4867647 100644 --- a/arch/arm/boot/compressed/Makefile +++ b/arch/arm/boot/compressed/Makefile @@ -104,6 +104,9 @@ endif ccflags-y := -fpic -fno-builtin asflags-y := -Wa,-march=all +# Supply kernel BSS size to the decompressor via a linker symbol. +KBSS_SZ = $(shell size $(obj)/../../../../vmlinux | awk 'END{print $$3}') +LDFLAGS_vmlinux = --defsym _kernel_bss_size=$(KBSS_SZ) # Supply ZRELADDR to the decompressor via a linker symbol. ifneq ($(CONFIG_AUTO_ZRELADDR),y) LDFLAGS_vmlinux += --defsym zreladdr=$(ZRELADDR) diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 3ce5738..ba5c552 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -248,6 +248,18 @@ restart: adr r0, LC0 mov r8, r6 @ use the appended device tree + /* + * Make sure that the DTB doesn't end up in the final + * kernel's .bss area. To do so, we adjust the decompressed + * kernel size to compensate if that .bss size is larger + * than the relocated code. + */ + ldr r5, =_kernel_bss_size + adr r1, wont_overwrite + sub r1, r6, r1 + subs r1, r5, r1 + addhi r9, r9, r1 + /* Get the dtb's size */ ldr r5, [r6, #4] #ifndef __ARMEB__ @@ -276,15 +288,14 @@ dtb_check_done: * r10 = end of this image, including bss/stack/malloc space if non XIP * We basically want: * r4 - 16k page directory >= r10 -> OK - * r4 + image length <= current position (pc) -> OK + * r4 + image length <= address of wont_overwrite -> OK */ add r10, r10, #16384 cmp r4, r10 bhs wont_overwrite add r10, r4, r9 - ARM( cmp r10, pc ) - THUMB( mov lr, pc ) - THUMB( cmp r10, lr ) + adr r9, wont_overwrite + cmp r10, r9 bls wont_overwrite /*