From patchwork Mon Oct 26 01:27:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ezequiel Garcia X-Patchwork-Id: 7484581 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 4D1619F36A for ; Mon, 26 Oct 2015 01:33:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4EBA820600 for ; Mon, 26 Oct 2015 01:33:33 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 2FD29205B9 for ; Mon, 26 Oct 2015 01:33:32 +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 1ZqWdN-0006d4-44; Mon, 26 Oct 2015 01:31:37 +0000 Received: from mail-qg0-x236.google.com ([2607:f8b0:400d:c04::236]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZqWdI-0006S7-NB for linux-arm-kernel@lists.infradead.org; Mon, 26 Oct 2015 01:31:34 +0000 Received: by qgad10 with SMTP id d10so108600504qga.3 for ; Sun, 25 Oct 2015 18:31:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur_com_ar.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; bh=Z9R67M4HTuOyz4UZLvKJ9hdS9pqW7NicbX/ialVw3fU=; b=wPFxCCtOU+Tos37iY0vEiqbPAI3RViAOm6+5uM5BaehtcdzSgYnBgkAAf7WHCpWkhZ oiRg0RbywSOdr/Z8wdh1RRuKpmKJWO3Y+BxaYFMapqXa6SU69hofT7VXldxBBBx6bbyc lxHyFelk0aL07JiWTfWeZnYDn2DAmN9Y0WJGGoWqxXM+UXrEq46i2IR0BsGK5efQQMyG 4kOCWuvQG+Bz4nfjanlOukHOPivnogsCrowYAFtCdSXYvpbeAv6QdUa3V6lP5yv88+sy FGsKXOzC1DOe4leE2dTY2b/JqA2XnIAgjoBpWCl9oVgllh7ocJN1uNNY0X+RyLOVjZHR 3rJA== 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:message-id:mime-version :content-type:content-disposition:user-agent; bh=Z9R67M4HTuOyz4UZLvKJ9hdS9pqW7NicbX/ialVw3fU=; b=a+Y8N+orQmQrva93tZOA+WAbfy5cQQez2uipxvI1C0+ll+Q3bJGIaM7MkqWVZ6j2b0 3YkuKcWMFalS4olL+Aqmzq245b24+kSITIFupBgrTuJKWusAdqcxQec54CFoWcPSTwy3 y44ko5jFSFLWFOiYc4n/d0oszLH1fjo18itvPh6DkCiKl/HU+F/1NaCVn1EYqkz29419 /KC6/EI6S9XQMkNQYdOayfMpM14CSe/No1PPv1YeSixN4/9gIlMveDoQJogf4mgSWtM6 PRrRSqpa7sBC02ZRdfzK2OWZ3lhgeuAAMW6t12jzKmXSpx4qYieOQVvpXXTcLNAVZt02 xO9g== X-Gm-Message-State: ALoCoQlpff5XhvP+R5wum3LpSGyGPx+cvwp+10BXy/EhDDuupUKgU3L6Z13mE/RkveFZIQrQvwM5 X-Received: by 10.140.238.3 with SMTP id j3mr41138135qhc.88.1445823071324; Sun, 25 Oct 2015 18:31:11 -0700 (PDT) Received: from localhost ([190.2.108.156]) by smtp.gmail.com with ESMTPSA id 83sm6092705qhw.27.2015.10.25.18.31.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Oct 2015 18:31:10 -0700 (PDT) Date: Sun, 25 Oct 2015 22:27:10 -0300 From: Ezequiel Garcia To: linux-arm-kernel@lists.infradead.org Subject: v7-M: Fixing XIP when the kernel is in ROM Message-ID: <20151026012710.GA17365@laptop> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151025_183132_980333_499AC869 X-CRM114-Status: GOOD ( 16.43 ) X-Spam-Score: -2.6 (--) 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: catalin.marinas@arm.com, Russell King , u.kleine-koenig@pengutronix.de Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham 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 I've been trying to make my ARM v7-M LPC43xx board boot a XIP kernel from flash. Currently, this seems to be broken in mainline due to this: arch/arm/mm/proc-v7m.S [..] @ SVC to run the kernel in this mode badr r1, 1f ldr r5, [r12, #11 * 4] @ read the SVC vector entry str r1, [r12, #11 * 4] @ write the temporary SVC vector entry mov r6, lr @ save LR mov r7, sp @ save SP ldr sp, =__v7m_setup_stack_top @ <<< Breaks XIP! cpsie i svc #0 1: cpsid i str r5, [r12, #11 * 4] @ restore the original SVC vector entry mov lr, r6 @ restore LR mov sp, r7 @ restore SP Here, a temporary stack is prepared before making a supervisor call (SVC) to switch to handler mode. The temporary stack is allocated in the .text.init section and so this doesn't work when the kernel is executing from ROM. A similar problem has been reported for v7: http://lists.infradead.org/pipermail/linux-arm-kernel/2015-July/357106.html While trying to come up with a proper fix, I've noticed how the stack doesn't seem to be used. So, I've been trying to understand why the need for the temporary stack at all, but I still can't get it. The below patch seems to work just fine, and allows to boot a LPC43xx kernel either as XIP from ROM or non-XIP from RAM. However, I'm still wondering if the stack is really unused or not, so any lights that can be shed here will be appreciated. Thanks! From a7c880c73b8ad2e4c4b07f4d11809ea541a65e1d Mon Sep 17 00:00:00 2001 From: Ezequiel Garcia Date: Sat, 24 Oct 2015 13:27:27 -0300 Subject: [PATCH] ARM: Don't prepare any temporary stack in __v7m_setup Since __v7m_setup() is implemented as the PROCINFO_INITFUNC called in head-nommu.S it's called at the very beggining to do some very basic setup. The function prepares a temporary stack in the .text.init section before calling SVC. However, this stack seems to be completely unused and hence is not needed. Moreover, this breaks on XIP kernels, when the text is in ROM. Hence, this commit simply removes the temporary stack setup. Signed-off-by: Ezequiel Garcia --- arch/arm/mm/proc-v7m.S | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arch/arm/mm/proc-v7m.S b/arch/arm/mm/proc-v7m.S index 67d9209077c6..6a383e619a0c 100644 --- a/arch/arm/mm/proc-v7m.S +++ b/arch/arm/mm/proc-v7m.S @@ -103,7 +103,6 @@ __v7m_setup: str r1, [r12, #11 * 4] @ write the temporary SVC vector entry mov r6, lr @ save LR mov r7, sp @ save SP - ldr sp, =__v7m_setup_stack_top cpsie i svc #0 1: cpsid i @@ -123,11 +122,6 @@ __v7m_setup: ret lr ENDPROC(__v7m_setup) - .align 2 -__v7m_setup_stack: - .space 4 * 8 @ 8 registers -__v7m_setup_stack_top: - define_processor_functions v7m, dabort=nommu_early_abort, pabort=legacy_pabort, nommu=1 .section ".rodata"