From patchwork Tue Aug 2 09:23:44 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Guo X-Patchwork-Id: 3223 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 939E323F3F for ; Tue, 2 Aug 2011 16:24:28 +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 62AE2A18529 for ; Tue, 2 Aug 2011 16:24:28 +0000 (UTC) Received: by mail-qw0-f52.google.com with SMTP id 8so5003071qwb.11 for ; Tue, 02 Aug 2011 09:24:28 -0700 (PDT) Received: by 10.229.44.195 with SMTP id b3mr1993180qcf.7.1312302268147; Tue, 02 Aug 2011 09:24:28 -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 9cs128901qcy; Tue, 2 Aug 2011 09:24:27 -0700 (PDT) Received: by 10.142.11.19 with SMTP id 19mr62744wfk.146.1312302266912; Tue, 02 Aug 2011 09:24:26 -0700 (PDT) Received: from VA3EHSOBE002.bigfish.com (va3ehsobe002.messaging.microsoft.com [216.32.180.12]) by mx.google.com with ESMTPS id w4si19145640wfk.113.2011.08.02.09.24.25 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 02 Aug 2011 09:24:25 -0700 (PDT) Received-SPF: neutral (google.com: 216.32.180.12 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) client-ip=216.32.180.12; Authentication-Results: mx.google.com; spf=neutral (google.com: 216.32.180.12 is neither permitted nor denied by best guess record for domain of shawn.guo@linaro.org) smtp.mail=shawn.guo@linaro.org Received: from mail35-va3-R.bigfish.com (10.7.14.247) by VA3EHSOBE002.bigfish.com (10.7.40.22) with Microsoft SMTP Server id 14.1.225.22; Tue, 2 Aug 2011 16:24:24 +0000 Received: from mail35-va3 (localhost.localdomain [127.0.0.1]) by mail35-va3-R.bigfish.com (Postfix) with ESMTP id 728A72D01A1; Tue, 2 Aug 2011 16:24:24 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bh8275dhz2dh87h2a8h668h839h) 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 mail35-va3 (localhost.localdomain [127.0.0.1]) by mail35-va3 (MessageSwitch) id 1312302264101774_25167; Tue, 2 Aug 2011 16:24:24 +0000 (UTC) Received: from VA3EHSMHS032.bigfish.com (unknown [10.7.14.246]) by mail35-va3.bigfish.com (Postfix) with ESMTP id 0D8781418051; Tue, 2 Aug 2011 16:24:24 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by VA3EHSMHS032.bigfish.com (10.7.99.42) with Microsoft SMTP Server (TLS) id 14.1.225.22; Tue, 2 Aug 2011 16:24:23 +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:22 -0500 Received: from ubuntu.ea.freescale.net ([10.214.137.140]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id p72GOIt1006784; Tue, 2 Aug 2011 11:24:20 -0500 (CDT) From: Shawn Guo To: CC: , John Bonesio , Nicolas Pitre Subject: [PATCH 2/4] ARM: zImage: Allow the appending of a device tree binary Date: Tue, 2 Aug 2011 17:23:44 +0800 Message-ID: <1312277026-25782-2-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: John Bonesio This patch provides the ability to boot using a device tree that is appended to the raw binary zImage (e.g. cat zImage .dtb > zImage_w_dtb). Signed-off-by: John Bonesio [nico: adjusted to latest zImage changes plus additional cleanups] Signed-off-by: Nicolas Pitre Acked-by: Grant Likely Acked-by: Tony Lindgren --- arch/arm/Kconfig | 8 ++++ arch/arm/boot/compressed/head.S | 70 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig index 2c71a8f..199722b 100644 --- a/arch/arm/Kconfig +++ b/arch/arm/Kconfig @@ -1782,6 +1782,14 @@ config ZBOOT_ROM_SH_MOBILE_SDHI endchoice +config ARM_APPENDED_DTB + bool "Use appended device tree blob to zImage" + depends on OF && !ZBOOT_ROM + help + With this option, the boot code will look for a device tree binary + (dtb) appended to zImage + (e.g. cat zImage .dtb > zImage_w_dtb). + config CMDLINE string "Default kernel command string" default "" diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index e95a598..3ce5738 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -216,6 +216,59 @@ restart: adr r0, LC0 mov r10, r6 #endif + mov r5, #0 @ init dtb size to 0 +#ifdef CONFIG_ARM_APPENDED_DTB +/* + * r0 = delta + * r2 = BSS start + * r3 = BSS end + * r4 = final kernel address + * r5 = appended dtb size (still unknown) + * r6 = _edata + * r7 = architecture ID + * r8 = atags/device tree pointer + * r9 = size of decompressed image + * r10 = end of this image, including bss/stack/malloc space if non XIP + * r11 = GOT start + * r12 = GOT end + * sp = stack pointer + * + * if there are device trees (dtb) appended to zImage, advance r10 so that the + * dtb data will get relocated along with the kernel if necessary. + */ + + ldr lr, [r6, #0] +#ifndef __ARMEB__ + ldr r1, =0xedfe0dd0 @ sig is 0xd00dfeed big endian +#else + ldr r1, =0xd00dfeed +#endif + cmp lr, r1 + bne dtb_check_done @ not found + + mov r8, r6 @ use the appended device tree + + /* Get the dtb's size */ + ldr r5, [r6, #4] +#ifndef __ARMEB__ + /* convert r5 (dtb size) to little endian */ + eor r1, r5, r5, ror #16 + bic r1, r1, #0x00ff0000 + mov r5, r5, ror #8 + eor r5, r5, r1, lsr #8 +#endif + + /* preserve 64-bit alignment */ + add r5, r5, #7 + bic r5, r5, #7 + + /* relocate some pointers past the appended dtb */ + add r6, r6, r5 + add r10, r10, r5 + add sp, sp, r5 +dtb_check_done: +#endif + /* * Check to see if we will overwrite ourselves. * r4 = final kernel address @@ -285,14 +338,16 @@ wont_overwrite: * r2 = BSS start * r3 = BSS end * r4 = kernel execution address + * r5 = appended dtb size (0 if not present) * r7 = architecture ID * r8 = atags pointer * r11 = GOT start * r12 = GOT end * sp = stack pointer */ - teq r0, #0 + orrs r1, r0, r5 beq not_relocated + add r11, r11, r0 add r12, r12, r0 @@ -307,12 +362,21 @@ wont_overwrite: /* * Relocate all entries in the GOT table. + * Bump bss entries to _edata + dtb size */ 1: ldr r1, [r11, #0] @ relocate entries in the GOT - add r1, r1, r0 @ table. This fixes up the - str r1, [r11], #4 @ C references. + add r1, r1, r0 @ This fixes up C references + cmp r1, r2 @ if entry >= bss_start && + cmphs r3, r1 @ bss_end > entry + addhi r1, r1, r5 @ entry += dtb size + str r1, [r11], #4 @ next entry cmp r11, r12 blo 1b + + /* bump our bss pointers too */ + add r2, r2, r5 + add r3, r3, r5 + #else /*