From patchwork Fri Nov 16 01:44:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 998697 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=chromium.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 42x1Wj389Fz9s47 for ; Fri, 16 Nov 2018 12:54:57 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 20112C22261; Fri, 16 Nov 2018 01:48:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 8A5FCC2225D; Fri, 16 Nov 2018 01:45:44 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 9DA84C22247; Fri, 16 Nov 2018 01:44:58 +0000 (UTC) Received: from mail-io1-f74.google.com (mail-io1-f74.google.com [209.85.166.74]) by lists.denx.de (Postfix) with ESMTPS id 79CB0C2223C for ; Fri, 16 Nov 2018 01:44:54 +0000 (UTC) Received: by mail-io1-f74.google.com with SMTP id e144-v6so21621122iof.13 for ; Thu, 15 Nov 2018 17:44:54 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=+t+7aJnDAofyPzBXZ2ZFDb/StJX2hzQtPGxhc+R5dac=; b=clfOLvwlrRow9jkfhets0Rm4fgxe3KLCF4P2Ev1s2dw63k2VcgJZYQQKkltsV60hHa gf1xKiymHAKqi39c/vShrl/ybf1iB/mw3Et6V/aUo5uaTXnj3m58aUus+exkpK0pkrgz j5MUeG5GwZCHWssMzreIeRRZYyBwFoNI9DUZ9Fj5BHI36ULWc1d6WLhJyOoejhTqLsbC cxa1abQvNIVsZwQamTHZGlpUb+Sq5GyC5KGcK6jECrv4wT9HNOPjrIsIh97AGqqZOBZF TxlBYV4ixaHeqcEzftOUe/uDaDyHslJJ9g0p2uawyEThPTNaCXGDKTR6sCi8sYiFRcj0 enyQ== X-Gm-Message-State: AGRZ1gLFJs/PHd/0nMPaUxCvr0QQ0a4NfmT1UT1t9nOdhU7uLaDz9iyY uwY7qy3uDQcPtjQMwvHUcVaBBl0= X-Google-Smtp-Source: AJdET5fzP/dCUtpqjeFvyo/PcleOOBfTZ1F2WV7K+J9DdukIJTLK4Aj4Rrg/wSJc1J7AaWa7Jdc34bc= X-Received: by 2002:a24:7a4b:: with SMTP id a72-v6mr2076945itc.8.1542332693539; Thu, 15 Nov 2018 17:44:53 -0800 (PST) Date: Thu, 15 Nov 2018 18:44:07 -0700 In-Reply-To: <20181116014409.147279-1-sjg@chromium.org> Message-Id: <20181116014409.147279-20-sjg@chromium.org> Mime-Version: 1.0 References: <20181116014409.147279-1-sjg@chromium.org> X-Mailer: git-send-email 2.19.1.1215.g8438c0b245-goog From: Simon Glass To: U-Boot Mailing List Subject: [U-Boot] [PATCH v3 19/21] sandbox: Filter arguments when starting U-Boot X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 --- Changes in v3: None Changes in v2: None 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 d3dc74db4b1..5e55d31be9d 100644 --- a/arch/sandbox/cpu/os.c +++ b/arch/sandbox/cpu/os.c @@ -538,10 +538,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 *)); @@ -549,7 +549,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; @@ -573,6 +590,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 @@ -592,11 +610,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++)