mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] ARM: allow booting with MMU enabled
@ 2019-08-28 12:51 Ahmad Fatoum
  2019-08-28 12:51 ` [PATCH 2/2] commands: go: add -m option to keep MMU on Ahmad Fatoum
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2019-08-28 12:51 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 2/2] commands: go: add -m option to keep MMU on
  2019-08-28 12:51 [PATCH 1/2] ARM: allow booting with MMU enabled Ahmad Fatoum
@ 2019-08-28 12:51 ` Ahmad Fatoum
  0 siblings, 0 replies; 2+ messages in thread
From: Ahmad Fatoum @ 2019-08-28 12:51 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

For testing or for running bare metal applications while the caches are
on, it can be beneficial to have barebox do the memory setup and handing
over control with the MMU still on. Extend go by a -m parameter that
does this. Other parts of barebox (e.g. DMA) are still shut down.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/go.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/commands/go.c b/commands/go.c
index ecc2ceb6e422..c3fe24a7137d 100644
--- a/commands/go.c
+++ b/commands/go.c
@@ -24,8 +24,10 @@
 #include <complete.h>
 #include <fs.h>
 #include <fcntl.h>
+#include <getopt.h>
 #include <linux/ctype.h>
 #include <errno.h>
+#include <mmu.h>
 
 static int do_go(int argc, char *argv[])
 {
@@ -33,12 +35,23 @@ static int do_go(int argc, char *argv[])
 	int     rcode = 1;
 	int	fd = -1;
 	int	(*func)(int argc, char *argv[]);
+	int	opt;
 
-	if (argc < 2)
+	while ((opt = getopt(argc, argv, "m")) > 0) {
+		switch (opt) {
+		case 'm':
+			mmu_boot_enabled();
+			break;
+		default:
+			return COMMAND_ERROR_USAGE;
+		}
+	}
+
+	if (optind == argc)
 		return COMMAND_ERROR_USAGE;
 
-	if (!isdigit(*argv[1])) {
-		fd = open(argv[1], O_RDONLY);
+	if (!isdigit(*argv[optind])) {
+		fd = open(argv[optind], O_RDONLY);
 		if (fd < 0) {
 			perror("open");
 			goto out;
@@ -50,7 +63,7 @@ static int do_go(int argc, char *argv[])
 			goto out;
 		}
 	} else
-		addr = (void *)simple_strtoul(argv[1], NULL, 16);
+		addr = (void *)simple_strtoul(argv[optind], NULL, 16);
 
 	printf("## Starting application at 0x%p ...\n", addr);
 
@@ -60,7 +73,7 @@ static int do_go(int argc, char *argv[])
 
 	shutdown_barebox();
 
-	func(argc - 1, &argv[1]);
+	func(argc - 1, &argv[optind]);
 
 	/*
 	 * The application returned. Since we have shutdown barebox and
@@ -80,12 +93,14 @@ BAREBOX_CMD_HELP_TEXT("Start application at ADDR passing ARG as arguments.")
 BAREBOX_CMD_HELP_TEXT("")
 BAREBOX_CMD_HELP_TEXT("If addr does not start with a digit it is interpreted as a filename")
 BAREBOX_CMD_HELP_TEXT("in which case the file is memmapped and executed")
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-m", "don't disable MMU if enabled. Only for debugging purposes!")
 BAREBOX_CMD_HELP_END
 
 BAREBOX_CMD_START(go)
 	.cmd		= do_go,
 	BAREBOX_CMD_DESC("start application at address or file")
-	BAREBOX_CMD_OPTS("ADDR [ARG...]")
+	BAREBOX_CMD_OPTS("[-m] ADDR [ARG...]")
 	BAREBOX_CMD_GROUP(CMD_GRP_BOOT)
 	BAREBOX_CMD_HELP(cmd_go_help)
 	BAREBOX_CMD_COMPLETE(command_var_complete)
-- 
2.23.0


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-08-28 12:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-28 12:51 [PATCH 1/2] ARM: allow booting with MMU enabled Ahmad Fatoum
2019-08-28 12:51 ` [PATCH 2/2] commands: go: add -m option to keep MMU on Ahmad Fatoum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox