All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 20/22] sandbox: Filter arguments when starting U-Boot
Date: Wed, 26 Sep 2018 15:55:18 -0600	[thread overview]
Message-ID: <20180926215520.87168-21-sjg@chromium.org> (raw)
In-Reply-To: <20180926215520.87168-1-sjg@chromium.org>

The current method of starting U-Boot from U-Boot adds arguments to pass
the memory file through, so that memory is preserved. This is fine for a
single call, but if we call from TPL -> SPL -> U-Boot the arguments build
up and we have several memory files in the argument list.

Adjust the implementation to filter out arguments that we want to replace
with new ones. Also print a useful error if the exec() call fails.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 arch/sandbox/cpu/os.c | 32 ++++++++++++++++++++++++++------
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/arch/sandbox/cpu/os.c b/arch/sandbox/cpu/os.c
index c1c5d6b0a37..4a879eb902f 100644
--- a/arch/sandbox/cpu/os.c
+++ b/arch/sandbox/cpu/os.c
@@ -502,10 +502,10 @@ static int make_exec(char *fname, const void *data, int size)
  */
 static int add_args(char ***argvp, char *add_args[], int count)
 {
-	char **argv;
+	char **argv, **ap;
 	int argc;
 
-	for (argv = *argvp, argc = 0; (*argvp)[argc]; argc++)
+	for (argc = 0; (*argvp)[argc]; argc++)
 		;
 
 	argv = os_malloc((argc + count + 1) * sizeof(char *));
@@ -513,7 +513,24 @@ static int add_args(char ***argvp, char *add_args[], int count)
 		printf("Out of memory for %d argv\n", count);
 		return -ENOMEM;
 	}
-	memcpy(argv, *argvp, argc * sizeof(char *));
+	for (ap = *argvp, argc = 0; *ap; ap++) {
+		char *arg = *ap;
+
+		/* Drop args that we don't want to propagate */
+		if (*arg == '-' && strlen(arg) == 2) {
+			switch (arg[1]) {
+			case 'j':
+			case 'm':
+				ap++;
+				continue;
+			}
+		} else if (!strcmp(arg, "--rm_memory")) {
+			ap++;
+			continue;
+		}
+		argv[argc++] = arg;
+	}
+
 	memcpy(argv + argc, add_args, count * sizeof(char *));
 	argv[argc + count] = NULL;
 
@@ -537,6 +554,7 @@ static int os_jump_to_file(const char *fname)
 	int fd, err;
 	char *extra_args[5];
 	char **argv = state->argv;
+	int argc;
 #ifdef DEBUG
 	int i;
 #endif
@@ -556,11 +574,13 @@ static int os_jump_to_file(const char *fname)
 	extra_args[1] = (char *)fname;
 	extra_args[2] = "-m";
 	extra_args[3] = mem_fname;
-	extra_args[4] = "--rm_memory";
-	err = add_args(&argv, extra_args,
-		       sizeof(extra_args) / sizeof(extra_args[0]));
+	argc = 4;
+	if (state->ram_buf_rm)
+		extra_args[argc++] = "--rm_memory";
+	err = add_args(&argv, extra_args, argc);
 	if (err)
 		return err;
+	argv[0] = (char *)fname;
 
 #ifdef DEBUG
 	for (i = 0; argv[i]; i++)
-- 
2.19.0.605.g01d371f741-goog

  parent reply	other threads:[~2018-09-26 21:55 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-26 21:54 [U-Boot] [PATCH 00/22] spl: Add features for passing info from SPL to U-Boot proper Simon Glass
2018-09-26 21:54 ` [U-Boot] [PATCH 01/22] log: Correct definition of log_msg_ret() Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 02/22] spl: Add support for logging in SPL and TPL Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 03/22] Add core support for a bloblist to convey data from SPL Simon Glass
2018-09-27  4:54   ` Andreas Dannenberg
2018-10-02 11:21     ` Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 04/22] spl: Set up the bloblist in SPL Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 05/22] bloblist: Locate bloblist in U-Boot Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 06/22] test: Add a simple test for bloblist Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 07/22] Add bloblist documentation Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 08/22] spl: Support hash, input, pch, pci, rtc, tpm in SPL Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 09/22] spl: Add a define for SPL_TPL_PROMPT Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 10/22] spl: Make SPL_DISABLE_BANNER_PRINT a positive option Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 11/22] spl: Add a comment to spl_set_bd() Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 12/22] spl: Print a message if we are unable to load an image Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 13/22] sandbox: Add a memory map to the sandbox README Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 14/22] test/py: Add a way to pass flags to sandbox Simon Glass
2018-10-01 15:59   ` Stephen Warren
2018-09-26 21:55 ` [U-Boot] [PATCH 15/22] sandbox: Add an option to display of-platdata in SPL Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 16/22] sandbox: Add a new 'sb' command Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 17/22] sandbox: Allow puts() output before global_data is set up Simon Glass
2018-09-26 22:24   ` Joe Hershberger
2018-09-26 21:55 ` [U-Boot] [PATCH 18/22] sandbox: Refactor code to create os_jump_to_file() Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 19/22] sandbox: Use malloc() and free() from os layer Simon Glass
2018-09-26 22:22   ` Joe Hershberger
2018-09-26 21:55 ` Simon Glass [this message]
2018-09-26 21:55 ` [U-Boot] [PATCH 21/22] sandbox: Boot in U-Boot through the standard call Simon Glass
2018-09-26 21:55 ` [U-Boot] [PATCH 22/22] spl: Add support for passing handoff info to U-Boot proper Simon Glass
2018-10-01 13:06 ` [U-Boot] [PATCH 00/22] spl: Add features for passing info from SPL " Lukasz Majewski
2018-10-01 17:32   ` Simon Glass
2018-10-08  2:30 ` Kever Yang
2018-10-09  3:40   ` Simon Glass

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=20180926215520.87168-21-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.