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 2/2] commands: go: add -m option to keep MMU on
Date: Wed, 28 Aug 2019 14:51:19 +0200	[thread overview]
Message-ID: <20190828125119.10431-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20190828125119.10431-1-a.fatoum@pengutronix.de>

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

      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 [PATCH 1/2] ARM: allow booting with MMU enabled Ahmad Fatoum
2019-08-28 12:51 ` Ahmad Fatoum [this message]

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-2-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