From patchwork Mon Jan 26 18:57:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicolas Pitre X-Patchwork-Id: 5712041 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7BEFCC058D for ; Mon, 26 Jan 2015 18:57:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8805620165 for ; Mon, 26 Jan 2015 18:57:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E768520149 for ; Mon, 26 Jan 2015 18:57:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752460AbbAZS5O (ORCPT ); Mon, 26 Jan 2015 13:57:14 -0500 Received: from mail-qg0-f44.google.com ([209.85.192.44]:61700 "EHLO mail-qg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753521AbbAZS5M (ORCPT ); Mon, 26 Jan 2015 13:57:12 -0500 Received: by mail-qg0-f44.google.com with SMTP id l89so8316414qgf.3 for ; Mon, 26 Jan 2015 10:57:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version:content-type; bh=+Huzz8quuieSAsNCiVcp7uWuUFepAbOHCEV87FhLd4M=; b=KAIDhF7I3mIcr/TFvb0EKtFATkqmQ7TBEBPu6MkrCx0FQvIGOW+vasMWZPnW/Sn5Sh 8mjVqtjGt+YsYbvjAFN4EwazKgam0WdxD9GsiJaUIfPEUSYPDLl/RPtQqEZbPX45kfDD xOkprl4IGjLJvmzfrdBEPi2ehhMNfXFw5wHJQTEAufoP7lBGuA3Eyc6t+k8vF1z9H/5h pO27W46RFvhI4nr4vstF+vg2Qre3jDaoT1ga58iQaLz+OkjuyGmPLMW5OMdo/AKqCbQR T+2C4NVsdiTrj/DUs94qzkss/vrCHjcme4Rz1/OQ1LkT0ZFF1Dt/s4gFgRuWlkapI4js y16w== X-Gm-Message-State: ALoCoQkLN4tcdi6fmKXt5ptZlM3bH6Kn70GXQWpqJbqoVpk+w+AudJKIjrc4SoLcZDjuskct3cPi X-Received: by 10.224.4.196 with SMTP id 4mr6768268qas.10.1422298631260; Mon, 26 Jan 2015 10:57:11 -0800 (PST) Received: from xanadu.home (modemcable142.180-131-66.mc.videotron.ca. [66.131.180.142]) by mx.google.com with ESMTPSA id 17sm10771479qgk.8.2015.01.26.10.57.09 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 26 Jan 2015 10:57:10 -0800 (PST) Date: Mon, 26 Jan 2015 13:57:08 -0500 (EST) From: Nicolas Pitre To: Tony Lindgren cc: =?ISO-8859-15?Q?Pali_Roh=E1r?= , linux-omap , Linux Kernel Mailing List , Aaro Koskinen , Sebastian Reichel , Ivaylo Dimitrov , Pavel Machek , Russell King , linux-arm-kernel@lists.infradead.org, Laura Abbott Subject: Re: N900 v3.19-rc5 arm atags_to_fdt.c is broken In-Reply-To: <20150126170323.GF28663@atomide.com> Message-ID: References: <201501232239.55801@pali> <201501232336.36187@pali> <20150126161454.GE28663@atomide.com> <201501261723.10505@pali> <20150126170323.GF28663@atomide.com> User-Agent: Alpine 2.11 (LFD 23 2013-08-11) MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, T_TVD_MIME_EPI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 26 Jan 2015, Tony Lindgren wrote: > * Pali Rohár [150126 08:26]: > > On Monday 26 January 2015 17:14:55 Tony Lindgren wrote: > > > * Pali Rohár [150123 14:39]: > > > > On Friday 23 January 2015 22:39:55 Pali Rohár wrote: > > > > > Hello, > > > > > > > > > > when I boot zImage with appended DT n900 in qemu > > > > > fdt_open_into() function called from file > > > > > arch/arm/boot/compressed/atags_to_fdt.c (in function > > > > > atags_to_fdt) always returns -FDT_ERR_NOSPACE. > > > > > > > > > > It means that all ATAGS (including cmdline arguments) > > > > > passed by bootloader are ignored. > > > > > > > > > > On real n900 device I see that booted DT version also > > > > > ignore cmdline arguments from bootloader. I cannot debug > > > > > decompress code on real device, but I think it is same > > > > > problem as in qemu. > > > > > > > > Looks like this quick patch is fixing above problem: > > > > > > > > diff --git a/arch/arm/boot/compressed/head.S > > > > b/arch/arm/boot/compressed/head.S index 68be901..4a7d75b > > > > 100644 > > > > --- a/arch/arm/boot/compressed/head.S > > > > +++ b/arch/arm/boot/compressed/head.S > > > > @@ -268,7 +268,7 @@ restart: adr r0, LC0 > > > > > > > > * area. No GOT fixup has occurred yet, but none of > > the > > > > * code we're about to call uses any global variable. > > > > > > > > */ > > > > > > > > - add sp, sp, #0x10000 > > > > + add sp, sp, #0x20000 > > > > > > > > stmfd sp!, {r0-r3, ip, lr} > > > > mov r0, r8 > > > > mov r1, r6 > > > > > > > > @@ -289,7 +289,7 @@ restart: adr r0, LC0 > > > > > > > > bleq atags_to_fdt > > > > > > > > ldmfd sp!, {r0-r3, ip, lr} > > > > > > > > - sub sp, sp, #0x10000 > > > > + sub sp, sp, #0x20000 > > > > > > > > #endif > > > > > > > > mov r8, r6 @ use the appended device tree > > > > > > Nico, got any ideas about this one? This seems like a > > > regression somewhere.. > > > > > > Regards, > > > > > > Tony > > > > $ du -b arch/arm/boot/dts/omap3-n900.dtb > > 70212 arch/arm/boot/dts/omap3-n900.dtb > > > > $ echo $((0x10000)) > > 65536 > > > > I would say, problem is because omap3-n900 binary DT is too large I agree. > OK if that's the case, then your patch makes sense to me. It also > seems we can have the temporary stack be larger than the initial > stack just for atags_to_fdt. The stack size isn't the issue, but rather its location. We need to position it away from the DT data. The DT size is known and we could use that, plus some room for the insertion of new data coming from the ATAG conversion. Something like the following would be a more robust solution: Tested-by: Pavel Machek Tested-by: Pali Rohár diff --git a/arch/arm/boot/compressed/head.S b/arch/arm/boot/compressed/head.S index 68be901759..89718de9dd 100644 --- a/arch/arm/boot/compressed/head.S +++ b/arch/arm/boot/compressed/head.S @@ -263,16 +263,37 @@ restart: adr r0, LC0 * OK... Let's do some funky business here. * If we do have a DTB appended to zImage, and we do have * an ATAG list around, we want the later to be translated - * and folded into the former here. To be on the safe side, - * let's temporarily move the stack away into the malloc - * area. No GOT fixup has occurred yet, but none of the - * code we're about to call uses any global variable. + * and folded into the former here. No GOT fixup has occurred + * yet, but none of the code we're about to call uses any + * global variable. */ - add sp, sp, #0x10000 + + /* Get the initial DTB size */ + ldr r5, [r6, #4] +#ifndef __ARMEB__ + /* convert 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 + /* 50% DTB growth should be good enough */ + add r5, r5, r5, lsr #1 + /* preserve 64-bit alignment */ + add r5, r5, #7 + bic r5, r5, #7 + /* clamp to 32KB min and 1MB max */ + movs r1, r5, lsr #15 + moveq r5, #(1 << 15) + movs r1, r5, lsr #20 + movne r5, #(1 << 20) + + /* Temporarily relocate the stack past the DTB work space */ + add sp, sp, r5 stmfd sp!, {r0-r3, ip, lr} mov r0, r8 mov r1, r6 - sub r2, sp, r6 + mov r2, r5 bl atags_to_fdt /* @@ -285,11 +306,11 @@ restart: adr r0, LC0 bic r0, r0, #1 add r0, r0, #0x100 mov r1, r6 - sub r2, sp, r6 + mov r2, r5 bleq atags_to_fdt ldmfd sp!, {r0-r3, ip, lr} - sub sp, sp, #0x10000 + sub sp, sp, r5 #endif mov r8, r6 @ use the appended device tree @@ -306,7 +327,7 @@ restart: adr r0, LC0 subs r1, r5, r1 addhi r9, r9, r1 - /* Get the dtb's size */ + /* Get the current DTB size */ ldr r5, [r6, #4] #ifndef __ARMEB__ /* convert r5 (dtb size) to little endian */