Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 50C61C77B75 for ; Sat, 13 May 2023 01:18:49 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2D13B84D10; Sat, 13 May 2023 03:18:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de 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; secure) header.d=gmx.de header.i=xypron.glpk@gmx.de header.b="eiHNdfH3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 65CE186207; Sat, 13 May 2023 03:18:40 +0200 (CEST) Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3C237846F2 for ; Sat, 13 May 2023 03:18:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=xypron.glpk@gmx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1683940709; i=xypron.glpk@gmx.de; bh=xbptUbmZ/bPo8hj79r1zNUxfx/zOYqDS6RglVnuGLso=; h=X-UI-Sender-Class:Date:Subject:To:Cc:References:From:In-Reply-To; b=eiHNdfH3L6CjRMXVZDNSJ7x15E6I6fO6lK2SadR5va7lEnbooZ9zxdeq4gXujvz1L 2X8ZsFoozsTPHWgspK3Glqwad7oSLahSam3hEn0+J74ArQNwQoeO3LTZNW7kMbJNgf jI2Q2aKJ1DUUzSDmMr9TORLIt1EbR7NdW1qsLuqpEUYXayJaL00LVgk3p20Ln+B2C8 +NLxtqEf7UPYRJaAm4NA+3pz547OuAzpifINRJjuZ9XSLb9b5C3wnKZFUW7kkxcQZ+ uS7sOaiuiiPhmttlCY+mueokrfP68XhCs8a9WFsu5bLhE+CDGCID6syk2z+qu9rJT3 Szbzqs0yCcfcw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from [192.168.123.94] ([88.152.145.137]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1M3lc9-1pxMv81ImZ-000uSS; Sat, 13 May 2023 03:18:29 +0200 Message-ID: <9f6c140d-fe19-aaa7-e7cb-fef2a8c09f02@gmx.de> Date: Sat, 13 May 2023 03:18:27 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.1 Subject: Re: [RFC PATCH v8 11/23] cmd: Add new cli command Content-Language: en-US To: Francis Laniel Cc: Michael Nazzareno Trimarchi , Tom Rini , Simon Glass , Harald Seiler , Ilias Apalodimas , Neil Armstrong , Roger Knecht , Masahisa Kojima , Alexey Romanov , Dzmitry Sankouski , Evgeny Bachinin , Marek Vasut , Hector Palacios , Sughosh Ganu , Rasmus Villemoes , u-boot@lists.denx.de References: <20230512200331.51457-1-francis.laniel@amarulasolutions.com> <20230512200331.51457-12-francis.laniel@amarulasolutions.com> From: Heinrich Schuchardt In-Reply-To: <20230512200331.51457-12-francis.laniel@amarulasolutions.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:vIiTfWenM6/bTn05BwP6lTG8kiWKn+ldI3O4UX7uNyVKDyGi2m4 zx5557L+CBJPAuEnL1pI2WItD5H9K4YbEJVlzjlgrCvtBcGuRMiWrSYx8Nm6/fVphndinOe O9C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jdQOGyK25239/zaqLB2ohqhzxeqFK0XPUHT+3whMGM7rIEW FrxGIW57FZip7gwvtScb+mHf2HQ= X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.8 at phobos.denx.de X-Virus-Status: Clean On 5/12/23 22:03, Francis Laniel wrote: > This command can be used to print the current parser with 'cli print'. > It can also be used to set the current parser with 'cli set'. > For the moment, only one value is valid for set: old. What would be the benefit having multiple alternative parsers in one U-Boot instance? I would prefer the solution to stay simple and small meaning just one parser per U-Boot binary. > > Signed-off-by: Francis Laniel > --- > cmd/Makefile | 2 + > cmd/cli.c | 120 ++++++++++++++++++++++++++++++++++++++++++ > common/cli.c | 3 +- > doc/usage/cmd/cli.rst | 59 +++++++++++++++++++++ > doc/usage/index.rst | 1 + > 5 files changed, 184 insertions(+), 1 deletion(-) > create mode 100644 cmd/cli.c > create mode 100644 doc/usage/cmd/cli.rst > > diff --git a/cmd/Makefile b/cmd/Makefile > index 6c37521b4e..706e934836 100644 > --- a/cmd/Makefile > +++ b/cmd/Makefile > @@ -224,6 +224,8 @@ obj-$(CONFIG_CMD_AVB) +=3D avb.o > # Foundries.IO SCP03 > obj-$(CONFIG_CMD_SCP03) +=3D scp03.o > > +obj-$(CONFIG_HUSH_PARSER) +=3D cli.o > + > obj-$(CONFIG_ARM) +=3D arm/ > obj-$(CONFIG_RISCV) +=3D riscv/ > obj-$(CONFIG_SANDBOX) +=3D sandbox/ > diff --git a/cmd/cli.c b/cmd/cli.c > new file mode 100644 > index 0000000000..7671785b83 > --- /dev/null > +++ b/cmd/cli.c > @@ -0,0 +1,120 @@ > +// SPDX-License-Identifier: GPL-2.0+ > + > +#include > +#include > +#include > +#include > +#include > + > +DECLARE_GLOBAL_DATA_PTR; > + > +static const char *gd_flags_to_parser(void) > +{ > + if (gd->flags & GD_FLG_HUSH_OLD_PARSER) > + return "old"; > + return NULL; > +} > + > +static int do_cli_get(struct cmd_tbl *cmdtp, int flag, int argc, > + char *const argv[]) > +{ > + const char *current =3D gd_flags_to_parser(); > + > + if (!current) { > + printf("current cli value is not valid, this should not happen!\n"); Please, use log_err() for errors. We want to keep our code small. "this should not happen!" does not convey any additional information. > + return CMD_RET_FAILURE; > + } > + > + printf("%s\n", current); > + > + return CMD_RET_SUCCESS; > +} > + > +static int parser_string_to_gd_flags(const char *parser) > +{ > + if (!strcmp(parser, "old")) > + return GD_FLG_HUSH_OLD_PARSER; > + return -1; > +} > + > +static void reset_parser_gd_flags(void) > +{ > + gd->flags &=3D ~GD_FLG_HUSH_OLD_PARSER; > +} > + > +static int do_cli_set(struct cmd_tbl *cmdtp, int flag, int argc, > + char *const argv[]) > +{ > + char *parser_name; > + int parser_flag; > + > + if (argc < 2) > + return CMD_RET_USAGE; > + > + parser_name =3D argv[1]; > + > + parser_flag =3D parser_string_to_gd_flags(parser_name); > + if (parser_flag =3D=3D -1) { > + printf("Bad value for parser name: %s\n", parser_name); > + return CMD_RET_USAGE; > + } > + > + if (parser_flag =3D=3D GD_FLG_HUSH_OLD_PARSER && > + !CONFIG_IS_ENABLED(HUSH_OLD_PARSER)) { > + printf("Want to set current parser to old, but its code was not compi= led!\n"); > + return CMD_RET_FAILURE; > + } We want to keep the code small. We don't need different strings "Parser %d is not available" would be enough information. > +. > + if (parser_flag =3D=3D GD_FLG_HUSH_2021_PARSER && > + !CONFIG_IS_ENABLED(HUSH_2021_PARSER)) { > + printf("Want to set current parser to 2021, but its code was not comp= iled!\n"); > + return CMD_RET_FAILURE; > + } > + > + reset_parser_gd_flags(); > + gd->flags |=3D parser_flag; > + > + cli_init(); > + cli_loop(); > + > + /* cli_loop() should never return. */ > + return CMD_RET_FAILURE; > +} > + > +static struct cmd_tbl parser_sub[] =3D { > + U_BOOT_CMD_MKENT(get, 1, 1, do_cli_get, "", ""), > + U_BOOT_CMD_MKENT(set, 2, 1, do_cli_set, "", ""), > +}; > + > +static int do_cli(struct cmd_tbl *cmdtp, int flag, int argc, > + char *const argv[]) > +{ > + struct cmd_tbl *cp; > + > + if (argc < 2) > + return CMD_RET_USAGE; > + > + /* drop initial "parser" arg */ > + argc--; > + argv++; > + > + cp =3D find_cmd_tbl(argv[0], parser_sub, ARRAY_SIZE(parser_sub)); > + if (cp) > + return cp->cmd(cmdtp, flag, argc, argv); > + > + return CMD_RET_USAGE; > +} > + > +#if CONFIG_IS_ENABLED(SYS_LONGHELP) > +static char cli_help_text[] =3D > + "get - print current cli\n" > + "set - set the current cli, possible value is: old" > + ; > +#endif > + > +U_BOOT_CMD(cli, 3, 1, do_cli, > + "cli", > +#if CONFIG_IS_ENABLED(SYS_LONGHELP) > + cli_help_text > +#endif > +); > diff --git a/common/cli.c b/common/cli.c > index e5fe1060d0..d419671e8c 100644 > --- a/common/cli.c > +++ b/common/cli.c > @@ -268,7 +268,8 @@ void cli_loop(void) > void cli_init(void) > { > #ifdef CONFIG_HUSH_PARSER > - if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER)) > + if (!(gd->flags & GD_FLG_HUSH_OLD_PARSER) This constraint is superfluous. Best regards Heinrich > + && CONFIG_IS_ENABLED(HUSH_OLD_PARSER)) > gd->flags |=3D GD_FLG_HUSH_OLD_PARSER; > u_boot_hush_start(); > #endif > diff --git a/doc/usage/cmd/cli.rst b/doc/usage/cmd/cli.rst > new file mode 100644 > index 0000000000..89ece3203d > --- /dev/null > +++ b/doc/usage/cmd/cli.rst > @@ -0,0 +1,59 @@ > +.. SPDX-License-Identifier: GPL-2.0+ > + > +cli command > +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > + > +Synopis > +------- > + > +:: > + > + cli get > + cli set cli_flavor > + > +Description > +----------- > + > +The cli command permits getting and changing the current parser at runt= ime. > + > +cli get > +~~~~~~~ > + > +It shows the current value of the parser used by the CLI. > + > +cli set > +~~~~~~~ > + > +It permits setting the value of the parser used by the CLI. > + > +Possible values are old and 2021. > +Note that, to use a specific parser its code should have been compiled,= that > +is to say you need to enable the corresponding CONFIG_HUSH*. > +Otherwise, an error message is printed. > + > +Examples > +-------- > + > +Get the current parser:: > + > + =3D> cli get > + old > + > +Change the current parser:: > + > + =3D> cli set old > + > +Trying to set the current parser to an unknown value:: > + > + =3D> cli set foo > + Bad value for parser name: foo > + cli - cli > + > + Usage: > + cli get - print current cli > + set - set the current cli, possible value is: old > + > +Return value > +------------ > + > +The return value $? indicates whether the command succeeded. > diff --git a/doc/usage/index.rst b/doc/usage/index.rst > index 0fde130a54..d0e26d1aee 100644 > --- a/doc/usage/index.rst > +++ b/doc/usage/index.rst > @@ -37,6 +37,7 @@ Shell commands > cmd/bootz > cmd/cat > cmd/cbsysinfo > + cmd/cli > cmd/cls > cmd/cmp > cmd/coninfo