From patchwork Sun Feb 28 23:47:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1445369 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=a/qTuU+t; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dpg7F13nKz9sRR for ; Mon, 1 Mar 2021 10:47:53 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DD76481F8F; Mon, 1 Mar 2021 00:47:41 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="a/qTuU+t"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B128081FB7; Mon, 1 Mar 2021 00:47:35 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x82a.google.com (mail-qt1-x82a.google.com [IPv6:2607:f8b0:4864:20::82a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E26E481C7C for ; Mon, 1 Mar 2021 00:47:31 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x82a.google.com with SMTP id 18so8203087qty.3 for ; Sun, 28 Feb 2021 15:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uscSA0O0kwYxpMg/tN3yVzw8ePMfxQQLAHTE4fi65nA=; b=a/qTuU+tPxch/u4ZSBWVb7wsFM0Gi646XVkMZUDfboazqDHfog1Z0LWkmBxmSnH/qf AYCIRMxg9e1HJ/erUbxNlbMD20qh22n0Uxjtdg7oRvOkCsWAdBMOdyC8541h8vQ7ITF7 hELG/008EYAXwwh/sH1s2wHCb/5xD4kFunmDBb9fskaX2rDyxz7sTwFnebxq5Ls9zLrp dcKoUP6xJ+h65Xye3MG7nalumuAl08Eps1ne6lzydKOVwnVC1dcfvKDACSQgb5Kpe6xK iU3ePDy88fgiwkHI8UjBKiIHZQRn8WfwEypmyL280gU64wR6Wy5vkNVwfSd6NMgL/Usx QqxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uscSA0O0kwYxpMg/tN3yVzw8ePMfxQQLAHTE4fi65nA=; b=FwSm+b2NBWMrNK2gO6NWBS09VL85utIhuu7A52ObzMolIK7K0ftiRD2nXPjl0p40OZ OaovmwhamuboPQkiNaQp05ytoXXAjDFwkAfMvL6eb4sbtrBP5JHeiVUf99OMVHRpvRy/ Qz4W+c7SlTlQS/BdI2xhJ07u15F6/RJ6BNN3cqje7NIxDaFGk9VcujINnqszqzY8ohtC 8zkCrnSfPgPh76CrFf4bDTY7chX0vLtPyQLVQpjiAXrB3WCLqyfzSyvexd/Y/LHJWOlG JVytS8gR2vudW+QqkHo1OtPcFR+AEN6+N1Pw3JE2mGxhudR+v+oTxYwJ6nqbQs57ecGu pGrA== X-Gm-Message-State: AOAM530Ko5ldjzeWJWPb10h3o4BxFK5arQbkmDMsf6VNDBOZBz7keUXw 31abQ2LmVAgII2kkzEaGTJvFZ8+2BNDL1Q== X-Google-Smtp-Source: ABdhPJx4TZhQgg2XQ55tr+ZgF1LiwrrEERPeoD4IkZqb8m3NHE4+dN6wZmFT41k8/QpzijCie7MuUQ== X-Received: by 2002:ac8:5987:: with SMTP id e7mr7881373qte.168.1614556050622; Sun, 28 Feb 2021 15:47:30 -0800 (PST) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id n136sm7424527qke.123.2021.02.28.15.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 15:47:30 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de, Tom Rini Cc: Simon Glass , Heinrich Schuchardt , Sean Anderson , Patrick Delaunay , Rasmus Villemoes Subject: [PATCH 1/5] hush: Print syntax error line with DEBUG_SHELL Date: Sun, 28 Feb 2021 18:47:14 -0500 Message-Id: <20210228234718.1208376-2-seanga2@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210228234718.1208376-1-seanga2@gmail.com> References: <20210228234718.1208376-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean This prints the filename (rather useless) and line (very useful) whenever a syntax error occurs if DEBUG_SHELL is enabled. Signed-off-by: Sean Anderson --- common/cli_hush.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/common/cli_hush.c b/common/cli_hush.c index 1b9bef64b6..83329763c6 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -372,15 +372,17 @@ static inline void debug_printf(const char *format, ...) { } #endif #define final_printf debug_printf -#ifdef __U_BOOT__ +#ifdef DEBUG_SHELL +static void __syntax(char *file, int line) +{ + error_msg("syntax error %s:%d\n", file, line); +} + +#define syntax_err() __syntax(__FILE__, __LINE__) +#else static void syntax_err(void) { printf("syntax error\n"); } -#else -static void __syntax(char *file, int line) { - error_msg("syntax error %s:%d", file, line); -} -#define syntax() __syntax(__FILE__, __LINE__) #endif #ifdef __U_BOOT__ From patchwork Sun Feb 28 23:47:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1445373 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=ePXS0kne; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dpg811vGzz9sRR for ; Mon, 1 Mar 2021 10:48:33 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7F0D282656; Mon, 1 Mar 2021 00:47:57 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ePXS0kne"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BE80A81F9E; Mon, 1 Mar 2021 00:47:40 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id BA8E881F66 for ; Mon, 1 Mar 2021 00:47:32 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qv1-xf36.google.com with SMTP id 2so7365384qvd.0 for ; Sun, 28 Feb 2021 15:47:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vWYTWoEhqngSM6zo2iZcuXcTQFNkuQvUqqu9fDlmoIY=; b=ePXS0kneiAqA8aF+QKe+JXR27ledoMqDoadK1SAt46WrpBWQ8SKLj4GNs5e6xPrJ5A QAbqhX8+diEFo39WOVjy0Zu5Yi9I6MP++t/trDJI9I1hl6RVLQNUSqe/OxqhK0vY8E48 /mwb4ACkGYFHmSHQv9e0eE+In8qwzncV1iqfzWPkKx+qv1Z16drpIQ1GXnDomatve4FM SbvF8vX90Y2TEKglq/SSinvO6u7dklXNyw9IvTVr4RczKD7l8bk3WTwy71wNJzWsNuWX bGwx17AuwWJ41UeuIER7+Wkzyk64uh6nTAhHmbcXI0DcNPGbI7MEdBF2hMW+lO69nAxN xRNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vWYTWoEhqngSM6zo2iZcuXcTQFNkuQvUqqu9fDlmoIY=; b=euXBqEfGGzVJJreG95HfhD2943IibTDYidLk+dvV5TJHfNK7kPfoIC5d2Pgv2M1mf4 9y+vtNkli/5bEOiDnhsJPgN20f1LRoF4qkzRVAszN5AELXL17HbJCOSYZ1pRnPWme843 m6jnVFbzjrSfdOY5Yx6/Fz3A+Pwqw/37jyM1VPeO3jVYZ/7bUy5ZFQtUypN3CpxuBo3r kGfOe68Gq+jzZTQJqeyC7b954QzajfKFBV6m6noxP4z+4iKgu8hj+mQC+EF+k/v0Xm7Z hVW0/jOvFz0ksCfiFpTTchmBTPdSG1m+gUVqYhmHgJljO5Lzp9Mvxr4E9j4Cf645VGKQ DO1g== X-Gm-Message-State: AOAM531DFgE74n3G7/oTkWroQdtXCzRPBYFUdRh8a5RGGfYckyckx3SJ 12veTGjXtylNNE7TUlKOZCtvfzqoU9ui8g== X-Google-Smtp-Source: ABdhPJwRWtrlaqTjIA9qT0Qdae8cS3LE9lCY6n8k6jsnyRUJLXQkAxogAOfg5WIJYJFZ/DKBv9vAAg== X-Received: by 2002:a05:6214:1424:: with SMTP id o4mr12657887qvx.34.1614556051437; Sun, 28 Feb 2021 15:47:31 -0800 (PST) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id n136sm7424527qke.123.2021.02.28.15.47.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 15:47:31 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de, Tom Rini Cc: Simon Glass , Heinrich Schuchardt , Sean Anderson , Bin Meng , Dario Binacchi , Ovidiu Panait , Patrick Delaunay , Peng Fan , Rasmus Villemoes , Stefan Roese Subject: [PATCH 2/5] cmd: Add support for (limited) command substitution Date: Sun, 28 Feb 2021 18:47:15 -0500 Message-Id: <20210228234718.1208376-3-seanga2@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210228234718.1208376-1-seanga2@gmail.com> References: <20210228234718.1208376-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean The traditional way to grab the output from a shell script is to use command substitution. Unfortunately, we don't really have the concept of pipes in U-Boot (at least not without console recording). Even if we did, stdout is severely polluted by informational printfs. Instead of redirecting stdout, instead use a special global variable. This lets commands set a result without having to modify the function signature of every command, and everything that calls commands. This is a bit of a hack, but seemed like the least-invasive of all options. Currently, the value of cmd_result is printed if it is set. This makes sense for things like echo, where you can do something like => echo a b c d e a b c d e => var=c => echo a $(echo b $var d) e a b c d e but it makes less sense for some other commands All callers of cmd_process must 1. Print cmd_result (unless it is being "redirected") 2. free() cmd_result 3. set cmd_result to NULL Calling cmd_process with a non-NULL value in cmd_result is a bug. Signed-off-by: Sean Anderson --- common/cli_hush.c | 39 ++++++++++++++++++++++++++++--- common/cli_simple.c | 8 ++++++- common/command.c | 3 +++ include/asm-generic/global_data.h | 4 ++++ 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/common/cli_hush.c b/common/cli_hush.c index 83329763c6..8fed7eb14e 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -475,6 +475,8 @@ static char *make_string(char **inp, int *nonnull); static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *input); #ifndef __U_BOOT__ static int parse_string(o_string *dest, struct p_context *ctx, const char *src); +#else +static void update_ifs_map(void); #endif static int parse_stream(o_string *dest, struct p_context *ctx, struct in_str *input0, int end_trigger); /* setup: */ @@ -1673,6 +1675,10 @@ static int run_pipe_real(struct pipe *pi) "'run' command\n", child->argv[i]); return -1; } + if (gd->cmd_result) + puts(gd->cmd_result); + free(gd->cmd_result); + gd->cmd_result = NULL; /* Process the command */ return cmd_process(flag, child->argc - i, child->argv + i, &flag_repeat, NULL); @@ -2683,6 +2689,7 @@ FILE *generate_stream_from_list(struct pipe *head) #endif return pf; } +#endif /* __U_BOOT__ */ /* this version hacked for testing purposes */ /* return code is exit status of the process that is run. */ @@ -2691,7 +2698,11 @@ static int process_command_subs(o_string *dest, struct p_context *ctx, struct in int retcode; o_string result=NULL_O_STRING; struct p_context inner; +#ifdef __U_BOOT__ + int list_retcode; +#else FILE *p; +#endif struct in_str pipe_str; initialize_context(&inner); @@ -2702,13 +2713,21 @@ static int process_command_subs(o_string *dest, struct p_context *ctx, struct in done_pipe(&inner, PIPE_SEQ); b_free(&result); +#ifdef __U_BOOT__ + list_retcode = run_list_real(inner.list_head); + setup_string_in_str(&pipe_str, gd->cmd_result ?: ""); + /* Restore the original map as best we can */ + update_ifs_map(); +#else p=generate_stream_from_list(inner.list_head); if (p==NULL) return 1; mark_open(fileno(p)); setup_file_in_str(&pipe_str, p); +#endif /* now send results of command back into original context */ retcode = parse_stream(dest, ctx, &pipe_str, '\0'); +#ifndef __U_BOOT__ /* XXX In case of a syntax error, should we try to kill the child? * That would be tough to do right, so just read until EOF. */ if (retcode == 1) { @@ -2723,12 +2742,18 @@ static int process_command_subs(o_string *dest, struct p_context *ctx, struct in * to the KISS philosophy of this program. */ mark_closed(fileno(p)); retcode=pclose(p); +#else + free(gd->cmd_result); + gd->cmd_result = NULL; + retcode = list_retcode; +#endif free_pipe_list(inner.list_head,0); debug_printf("pclosed, retcode=%d\n",retcode); /* XXX this process fails to trim a single trailing newline */ return retcode; } +#ifndef __U_BOOT__ static int parse_group(o_string *dest, struct p_context *ctx, struct in_str *input, int ch) { @@ -2896,11 +2921,11 @@ static int handle_dollar(o_string *dest, struct p_context *ctx, struct in_str *i } b_addchr(dest, SPECIAL_VAR_SYMBOL); break; -#ifndef __U_BOOT__ case '(': b_getch(input); process_command_subs(dest, ctx, input, ')'); break; +#ifndef __U_BOOT__ case '*': sep[0]=ifs[0]; for (i=1; ipromptmode=1; rcode = parse_stream(&temp, &ctx, inp, flag & FLAG_CONT_ON_NEWLINE ? -1 : '\n'); @@ -3205,6 +3231,13 @@ static int parse_stream_outer(struct in_str *inp, int flag) run_list(ctx.list_head); #else code = run_list(ctx.list_head); + + if (!(flag & FLAG_REPARSING) && gd->cmd_result) { + puts(gd->cmd_result); + free(gd->cmd_result); + gd->cmd_result = NULL; + } + if (code == -2) { /* exit */ b_free(&temp); code = 0; diff --git a/common/cli_simple.c b/common/cli_simple.c index e80ba488a5..5df30d964f 100644 --- a/common/cli_simple.c +++ b/common/cli_simple.c @@ -15,14 +15,16 @@ #include #include #include +#include #include +DECLARE_GLOBAL_DATA_PTR; + #define DEBUG_PARSER 0 /* set to 1 to debug */ #define debug_parser(fmt, args...) \ debug_cond(DEBUG_PARSER, fmt, ##args) - int cli_simple_parse_line(char *line, char *argv[]) { int nargs = 0; @@ -257,6 +259,10 @@ int cli_simple_run_command(const char *cmd, int flag) if (cmd_process(flag, argc, argv, &repeatable, NULL)) rc = -1; + if (gd->cmd_result) + puts(gd->cmd_result); + free(gd->cmd_result); + gd->cmd_result = NULL; /* Did the user stop this? */ if (had_ctrlc()) diff --git a/common/command.c b/common/command.c index 3fe6791eda..952a8f00eb 100644 --- a/common/command.c +++ b/common/command.c @@ -588,6 +588,9 @@ enum command_ret_t cmd_process(int flag, int argc, char *const argv[], enum command_ret_t rc = CMD_RET_SUCCESS; struct cmd_tbl *cmdtp; + /* Clear previous result */ + assert(!gd->cmd_result); + #if defined(CONFIG_SYS_XTRACE) char *xtrace; diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h index b6a9991fc9..85262d9566 100644 --- a/include/asm-generic/global_data.h +++ b/include/asm-generic/global_data.h @@ -453,6 +453,10 @@ struct global_data { */ char *smbios_version; #endif + /** + * @cmd_result: Result of the current command + */ + char *cmd_result; }; /** From patchwork Sun Feb 28 23:47:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1445371 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=TR5v4xM1; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dpg7b6bnqz9sRR for ; Mon, 1 Mar 2021 10:48:11 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B53B581FD5; Mon, 1 Mar 2021 00:47:49 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TR5v4xM1"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id E3C1281FDD; Mon, 1 Mar 2021 00:47:39 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 4870381F8F for ; Mon, 1 Mar 2021 00:47:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x832.google.com with SMTP id w1so10856886qto.2 for ; Sun, 28 Feb 2021 15:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jSrBs+U9kdml+zAq6lNkzDwju75zg1nI5GH2+piKQWs=; b=TR5v4xM1aof1hFGAwU1N0aKcmY7C56VlhHK6AkLrUMnXiWkAosr6OCTE9S54xMF0sP 7L/xCX25/h5K+SPVO6QrlwGHsMbrt5zCr+HvU0ZlmbJN6tk5NzAP8CU59nfNuqhvqdGB irM1awuQ3n5zUBHtPPwyZPhfWNMcIOzhQXVoDv9umdqhASR3bh1f3X+j2atH7JJKFdCL 6Q+XOW2YSTSWPhxrF2DRTrQSF0yYqtwyPjRVpiqs2WhRQG/X/5tbCphhxdcGjUg3oW3a xy/s/wtUX0jk5Hh72RAcBUGVc7HtK7AkFf3PZD3gBvPHhD8ECcIggdz7ubTxbaTJ5vKu vRuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jSrBs+U9kdml+zAq6lNkzDwju75zg1nI5GH2+piKQWs=; b=GzGD3o2Kk6hidWnUfzNlN5WHrfactcLhWE6B47xB2lcTf/JZaYZsYle84GvTnyd/rV hNa4diQyYZAZ3ftEvCmP2aPyI2kuhhx/P+sKMiT9ch1RmY5YX2wRThGTda4X+B399/H4 LHaBNg8ncd2jiU8xs1284j7gSRypRD9kJEBfZVdA97hjmEChXMSHBe77D15ODWeujIlb /0fE6my9JOhcpAoen+EIrR2qee3UHTtHUob7SbmJ130rNbvrWrhZ5YE5ZMe5iaXM7Xlo in3GDdvt3eIjgTAd+MQUWE7lgQOlmyDlkf9In9o6kcKj34jxLgRldO3zFnxuYYq9kQs9 Uf/w== X-Gm-Message-State: AOAM531VS89MDs4mkd/jrPvWgV4R83dkyYF18cEsfff8iIP0Whtrxh0e SLKt97eWs3gdhjsUC0QMa/r49eGIZ7zxRQ== X-Google-Smtp-Source: ABdhPJxIu1g1k9/uITSmFhLae1AMWIDU8hh8YGHF1F7x0o2N9FyqTdBWodoCp5Q7qbbgy6gsn9Hhpw== X-Received: by 2002:ac8:74c9:: with SMTP id j9mr11366738qtr.369.1614556052115; Sun, 28 Feb 2021 15:47:32 -0800 (PST) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id n136sm7424527qke.123.2021.02.28.15.47.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 15:47:31 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de, Tom Rini Cc: Simon Glass , Heinrich Schuchardt , Sean Anderson Subject: [PATCH 3/5] cmd: Convert echo to use cmd_result Date: Sun, 28 Feb 2021 18:47:16 -0500 Message-Id: <20210228234718.1208376-4-seanga2@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210228234718.1208376-1-seanga2@gmail.com> References: <20210228234718.1208376-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean This adds some complexity, since we need to know how big the arguments are ahead of time instead of finding out when we print them. Signed-off-by: Sean Anderson --- cmd/echo.c | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/cmd/echo.c b/cmd/echo.c index fda844ee9d..8f20e635ce 100644 --- a/cmd/echo.c +++ b/cmd/echo.c @@ -6,11 +6,16 @@ #include #include +#include + +DECLARE_GLOBAL_DATA_PTR; static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { - int i = 1; + char *result; + int j, i = 1; + size_t result_size, arglens[CONFIG_SYS_MAXARGS]; bool space = false; bool newline = true; @@ -21,18 +26,32 @@ static int do_echo(struct cmd_tbl *cmdtp, int flag, int argc, } } + result_size = 1 + newline; /* \0 + \n */ + result_size += argc - i - 1; /* spaces */ + for (j = i; j < argc; ++j) { + arglens[j] = strlen(argv[j]); + result_size += arglens[j]; + } + + result = malloc(result_size); + if (!result) + return CMD_RET_FAILURE; + gd->cmd_result = result; + for (; i < argc; ++i) { - if (space) { - putc(' '); - } - puts(argv[i]); + if (space) + *result++ = ' '; + + memcpy(result, argv[i], arglens[i]); + result += arglens[i]; space = true; } if (newline) - putc('\n'); + *result++ = '\n'; + *result = '\0'; - return 0; + return CMD_RET_SUCCESS; } U_BOOT_CMD( From patchwork Sun Feb 28 23:47:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1445372 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=NWHjh6NG; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dpg7p30cZz9sRR for ; Mon, 1 Mar 2021 10:48:22 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 458BE8206F; Mon, 1 Mar 2021 00:47:53 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="NWHjh6NG"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2A05081FC3; Mon, 1 Mar 2021 00:47:40 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x82b.google.com (mail-qt1-x82b.google.com [IPv6:2607:f8b0:4864:20::82b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id ECE0681F9E for ; Mon, 1 Mar 2021 00:47:33 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x82b.google.com with SMTP id w6so10845609qti.6 for ; Sun, 28 Feb 2021 15:47:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XXvJbtgf0zZ53ewiTNcUV4EAIj4f1TUGhnvr7bix0xU=; b=NWHjh6NGaXsB3idQOWDbhk0gxfsMGiokswOrBBiRPAFvm2DHI8PYdbLTqI5UHxi5eo oE0aoL9AtV0RsWWzFWCL4BZaLXKUA5bqe5Jncp1DPqrE9yq321fB3SV1FfPt0mY0x2QK tjqA2/Zequr2v8SMI1sZTcSAYVeveouNGhywBXqlUp9E3H5e7ckDytHn5bKgjt31bSop xsGOLlMnEHLZCErMsQ639XrUcgUjvVipyVvus9mFGFYS31FCmEXvkkQ47qIJhAwbedGf KAYacD+JY677e2pPgSYYe2Z4Df7sq0fUxWpiUyggqrVWkoNjRNXnkM2youLaLbs/G+6s qzWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XXvJbtgf0zZ53ewiTNcUV4EAIj4f1TUGhnvr7bix0xU=; b=UBeS3ofcsgnrvx2RYWDdg8mhTcMI4i8KqihUkMNH3i3t6joTr7xqBx1rR95aBLo6n3 e4DtbyOOl3hJLbV5tbbVgdunBDx76paOzNiI2sM2joT4gLpmIqPosxrGeyoK7Tb2FvLg 6w5kTcjLK+/JIRjMGEYGmiYt+l2vNs7baZH1tdLkzAyn7CTqLJvKe51O3pdHmT1Qwr1E rAK+U5MqxkSxtKQdZq1nBK+7+N8BO7mC1yu65Cm/q2s6tsTsXeNxG2pDgJ8j/FAYaGZz 6XoZ7iGTu89JMf8Br74hSpYOSXrJKacsLcK6yBggt5vXeJx0Q2BNmiHC4F4AqL/liRMQ CvSQ== X-Gm-Message-State: AOAM533J5vDST+jMC6TqrdUYt37sRsFaF/g4aPPq8YU99mmmZp8NHc7X rs+8wpeuwijuAURJVlxu2BY/vZamJ1Pc8A== X-Google-Smtp-Source: ABdhPJx1RCP35wLdkBFFE+Ts9BCBmWbjW9oWXHHeQpgxYtNI7q3/iA+XYiNbPQveY7uXvxQKTgJ4yA== X-Received: by 2002:ac8:5a15:: with SMTP id n21mr376942qta.85.1614556052765; Sun, 28 Feb 2021 15:47:32 -0800 (PST) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id n136sm7424527qke.123.2021.02.28.15.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 15:47:32 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de, Tom Rini Cc: Simon Glass , Heinrich Schuchardt , Sean Anderson Subject: [PATCH 4/5] test: hush: Add test for command substitution Date: Sun, 28 Feb 2021 18:47:17 -0500 Message-Id: <20210228234718.1208376-5-seanga2@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210228234718.1208376-1-seanga2@gmail.com> References: <20210228234718.1208376-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean This adds a basic test for command substitution. A more advanced test currently fails, and is left commented-out for now. A basic example of the difference is that in bash $ a=b; echo a=$(echo $a) b but in hush => a=b; echo a=$(echo $a) a= This is because command substitution takes place during parsing, before any of the rest of the command has been executed. Signed-off-by: Sean Anderson --- test/cmd/test_echo.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/test/cmd/test_echo.c b/test/cmd/test_echo.c index 13e1fb7c82..f3d44d840d 100644 --- a/test/cmd/test_echo.c +++ b/test/cmd/test_echo.c @@ -31,13 +31,21 @@ static struct test_data echo_data[] = { * j, q, x are among the least frequent letters in English. * Hence no collision for the variable name jQx is expected. */ - {"setenv jQx X; echo \"a)\" ${jQx} 'b)' '${jQx}' c) ${jQx}; setenv jQx", + {"setenv jQx X; echo \"a)\" ${jQx} 'b)' '${jQx}' c\\) ${jQx}; setenv jQx", "a) X b) ${jQx} c) X"}, /* Test shell variable assignments without substitutions */ {"foo=bar echo baz", "baz"}, /* Test handling of shell variables. */ {"setenv jQx; for jQx in 1 2 3; do echo -n \"${jQx}, \"; done; echo;", "1, 2, 3, "}, + /* Test basic command substitution */ + {"jQx=3 echo 1 $(echo 2) $jQx", "1 2 3"}, + /* + * The following test fails because the subshell is evaluated before + * anything else, but the jQx2 assignment should happen beforehand + */ + //{"jQx2=2; echo 1 $(echo ${jQx2}) 3", + //"1 2 3"}, }; static int lib_test_hush_echo(struct unit_test_state *uts) From patchwork Sun Feb 28 23:47:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 1445370 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=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=KQxSvDlc; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Dpg7Q1vxsz9sRR for ; Mon, 1 Mar 2021 10:48:02 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 18E3582047; Mon, 1 Mar 2021 00:47:46 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KQxSvDlc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2CA1B81FC1; Mon, 1 Mar 2021 00:47:39 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,SPF_HELO_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9E31681FC1 for ; Mon, 1 Mar 2021 00:47:34 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=seanga2@gmail.com Received: by mail-qt1-x832.google.com with SMTP id o1so6410442qta.13 for ; Sun, 28 Feb 2021 15:47:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SQuPIa1G/R5KPLSFAD/Ca64bQVyg5nfX/+xYHwCBMZI=; b=KQxSvDlcuExiFAV+gI2PSuLYGmm9IDm/sVOziQFCCasM54XaiOSfHsl4e/6+NmWVZX 4GJUkq07B2u9tiU9JrrfwXf5iMd9zZDJHpxzH3d8X0K6igEk8AUDNoKVabYIvxkj4MPd rP4nvBApqHQe6TxCFQ3qQuRrVUaBlc6c9qW97u9qM8uKAAb41tUp+FoVGz6jV5RW/ng9 D4aCqU+2lMLeTR1ARcgqDorct0ku192bQ7X9/0O5h8jLEk5VFxYiPA8l8hLk+lfy5kV3 T8FhHgKCeOAOPUHxEbS+99gg1BbZsiT+TvahF/PlAj5LiozbecRQWcjlP42PwBlADte6 CRaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SQuPIa1G/R5KPLSFAD/Ca64bQVyg5nfX/+xYHwCBMZI=; b=jLKzpVkeP5XRjmxnx623z/xJyx8XTqy0FNE/eB24qtzMyJk/5Dl1B3iur2WoXgWWxQ Z4jAZIkWesthD2aLpFtuDNaHe3FCc9dW+6bbpBJsxmuckjj519/qNzTul9axj2qbmhFo 6vIHpI5p/V//Sr3I6yxpPvviB3MUZqkD+TUmH42wqzrSynVjZL7UAKHCgVYm3KdqzVcX BxgKpnTaFFmq1Pvayadjk9VkUYWz2T3urtHIsCUctctWx5QNlKoIrKwo+QlXvci23MpD BLxEDMuG9V/6Crgam38J8Jj6Nw1RiF4req2EsO3OtddZsZ/PRdhN2GMqj7WWN4Y2Dn/c 62Ow== X-Gm-Message-State: AOAM531BfWm4e3J0dGGjI+I1UXn/f9TkhJ4KFE/wRANRP3D1pLc1rVRP kCnMJuajao/7LIYo4kH7BBo9n95U3g567A== X-Google-Smtp-Source: ABdhPJwKn2+dchSRKXUEFHAhCsdmRL8gs0S8jTXhinZ1+MVwe30gSNNGE1JaQg7D1Rhh/ScBMBvVrg== X-Received: by 2002:ac8:4e12:: with SMTP id c18mr11737485qtw.384.1614556053418; Sun, 28 Feb 2021 15:47:33 -0800 (PST) Received: from godwin.fios-router.home (pool-108-51-35-162.washdc.fios.verizon.net. [108.51.35.162]) by smtp.gmail.com with ESMTPSA id n136sm7424527qke.123.2021.02.28.15.47.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Feb 2021 15:47:33 -0800 (PST) From: Sean Anderson To: u-boot@lists.denx.de, Tom Rini Cc: Simon Glass , Heinrich Schuchardt , Sean Anderson , Niel Fourie Subject: [PATCH 5/5] cmd: Convert part uuid to use cmd_result Date: Sun, 28 Feb 2021 18:47:18 -0500 Message-Id: <20210228234718.1208376-6-seanga2@gmail.com> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210228234718.1208376-1-seanga2@gmail.com> References: <20210228234718.1208376-1-seanga2@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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" X-Virus-Scanned: clamav-milter 0.102.4 at phobos.denx.de X-Virus-Status: Clean This is fairly straightforward. This allows part uuid mmc 0 foo To be rewritten as env set foo $(part uuid mmc 0) or even (if the variable is not required to be environmental) foo=$(part uuid mmc 0) Signed-off-by: Sean Anderson --- cmd/part.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/cmd/part.c b/cmd/part.c index 3395c17b89..97e70d79ff 100644 --- a/cmd/part.c +++ b/cmd/part.c @@ -19,9 +19,12 @@ #include #include #include +#include #include #include +DECLARE_GLOBAL_DATA_PTR; + enum cmd_part_info { CMD_PART_INFO_START = 0, CMD_PART_INFO_SIZE, @@ -43,12 +46,19 @@ static int do_part_uuid(int argc, char *const argv[]) if (part < 0) return 1; - if (argc > 2) + if (argc > 2) { env_set(argv[2], info.uuid); - else - printf("%s\n", info.uuid); + } else { + size_t result_size = sizeof(info.uuid) + 1; - return 0; + gd->cmd_result = malloc(result_size); + if (!gd->cmd_result) + return CMD_RET_FAILURE; + + snprintf(gd->cmd_result, result_size, "%s\n", info.uuid); + } + + return CMD_RET_SUCCESS; } static int do_part_list(int argc, char *const argv[])