mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 1/2] ARM: allow booting with MMU enabled
Date: Wed, 28 Aug 2019 14:51:18 +0200	[thread overview]
Message-ID: <20190828125119.10431-1-a.fatoum@pengutronix.de> (raw)

Linux expects the MMU to be off on boot as does barebox, when being
chainloaded. However for running executables or for testing things,
booting with the MMU (and thus the caches) on can be nice.

Support this, by having architectures define HAVE_MMU_OFF_FOR_BOOT,
if they are turning off the MMU. These architectures are then supposed
to implement mmu_boot_enabled(), which should disable turning off
the MMU on barebox shutdown. A follow-up commit will add a new -m
flag to the go command that calls this function.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---

This is similiar to the U-Boot go command, but safer. Devices are shut
down and cache maintenance is done correctly. The command might not
be of much generic use at the moment, but I occasionly found it useful.

---
 arch/arm/Kconfig   |  1 +
 arch/arm/cpu/cpu.c | 13 +++++++++++--
 common/Kconfig     |  3 +++
 include/mmu.h      |  9 +++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 480c6f011797..b312aabacb72 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -4,6 +4,7 @@ config ARM
 	select HAS_CACHE
 	select HAVE_CONFIGURABLE_TEXT_BASE if !RELOCATABLE
 	select HAVE_IMAGE_COMPRESSION
+	select HAVE_MMU_OFF_FOR_BOOT
 	default y
 
 config ARM_LINUX
diff --git a/arch/arm/cpu/cpu.c b/arch/arm/cpu/cpu.c
index c5daf6c60efe..65566006693e 100644
--- a/arch/arm/cpu/cpu.c
+++ b/arch/arm/cpu/cpu.c
@@ -25,6 +25,7 @@
 #include <init.h>
 #include <command.h>
 #include <cache.h>
+#include <mmu.h>
 #include <asm/mmu.h>
 #include <asm/system.h>
 #include <asm/memory.h>
@@ -90,6 +91,12 @@ static void disable_interrupts(void)
 #endif
 }
 
+static bool _mmu_boot_enabled;
+void mmu_boot_enabled(void)
+{
+	_mmu_boot_enabled = true;
+}
+
 /**
  * Disable MMU and D-cache, flush caches
  * @return 0 (always)
@@ -99,9 +106,11 @@ static void disable_interrupts(void)
  */
 static void arch_shutdown(void)
 {
-
 #ifdef CONFIG_MMU
-	mmu_disable();
+	if (!_mmu_boot_enabled)
+		mmu_disable();
+	else
+		arm_early_mmu_cache_flush();
 #endif
 	icache_invalidate();
 
diff --git a/common/Kconfig b/common/Kconfig
index f5777a304cf5..4628e72c0e3f 100644
--- a/common/Kconfig
+++ b/common/Kconfig
@@ -209,6 +209,9 @@ config MMU_EARLY
 	  This enables the MMU during early startup. This speeds up things during startup
 	  of barebox, but may lead to harder to debug code. If unsure say yes here.
 
+config HAVE_MMU_OFF_FOR_BOOT
+	bool
+
 config HAVE_CONFIGURABLE_TEXT_BASE
 	bool
 
diff --git a/include/mmu.h b/include/mmu.h
index 66b246f6d270..06939ab97175 100644
--- a/include/mmu.h
+++ b/include/mmu.h
@@ -38,4 +38,13 @@ static inline int remap_range(void *start, size_t size, unsigned flags)
 	return arch_remap_range(start, size, flags);
 }
 
+#ifdef CONFIG_HAVE_MMU_OFF_FOR_BOOT
+void mmu_boot_enabled(void);
+#else
+static inline void mmu_boot_enabled(void)
+{
+}
+#endif
+
+
 #endif
-- 
2.23.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2019-08-28 12:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-28 12:51 Ahmad Fatoum [this message]
2019-08-28 12:51 ` [PATCH 2/2] commands: go: add -m option to keep MMU on Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190828125119.10431-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox