All of lore.kernel.org
 help / color / mirror / Atom feed
From: Patrice CHOTARD <patrice.chotard@foss.st.com>
To: Patrick Delaunay <patrick.delaunay@foss.st.com>, <u-boot@lists.denx.de>
Cc: U-Boot STM32 <uboot-stm32@st-md-mailman.stormreply.com>
Subject: Re: [PATCH 2/7] stm32mp: cmd_stm32key: use sub command
Date: Thu, 1 Jul 2021 09:35:32 +0200	[thread overview]
Message-ID: <9266b9c2-b8c4-c526-acea-24a677953d52@foss.st.com> (raw)
In-Reply-To: <20210628145519.2.I55399cf019408c6f6d4f86aa8783c8187b090280@changeid>

Hi Patrick

On 6/28/21 2:55 PM, Patrick Delaunay wrote:
> Simplify parsing the command argument by using
> the macro U_BOOT_CMD_WITH_SUBCMDS.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  arch/arm/mach-stm32mp/cmd_stm32key.c | 55 ++++++++++++++++++----------
>  1 file changed, 36 insertions(+), 19 deletions(-)
> 
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32key.c b/arch/arm/mach-stm32mp/cmd_stm32key.c
> index 42fdc11238..d2045a5983 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32key.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32key.c
> @@ -67,36 +67,53 @@ static int confirm_prog(void)
>  	return 0;
>  }
>  
> -static int do_stm32key(struct cmd_tbl *cmdtp, int flag, int argc,
> -		       char *const argv[])
> +static int do_stm32key_read(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
>  {
>  	u32 addr;
> -	const char *op = argc >= 2 ? argv[1] : NULL;
> -	int confirmed = argc > 3 && !strcmp(argv[2], "-y");
>  
> -	argc -= 2 + confirmed;
> -	argv += 2 + confirmed;
> -
> -	if (argc < 1)
> +	if (argc == 1)
>  		return CMD_RET_USAGE;
>  
> -	addr = simple_strtoul(argv[0], NULL, 16);
> +	addr = simple_strtoul(argv[1], NULL, 16);
>  	if (!addr)
>  		return CMD_RET_USAGE;
>  
> -	if (!strcmp(op, "read"))
> -		read_hash_value(addr);
> +	read_hash_value(addr);
> +
> +	return CMD_RET_SUCCESS;
> +}
> +
> +static int do_stm32key_fuse(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
> +{
> +	u32 addr;
> +	bool yes = false;
>  
> -	if (!strcmp(op, "fuse")) {
> -		if (!confirmed && !confirm_prog())
> -			return CMD_RET_FAILURE;
> -		fuse_hash_value(addr, !confirmed);
> +	if (argc < 2)
> +		return CMD_RET_USAGE;
> +
> +	if (argc == 3) {
> +		if (strcmp(argv[1], "-y"))
> +			return CMD_RET_USAGE;
> +		yes = true;
>  	}
>  
> +	addr = simple_strtoul(argv[argc - 1], NULL, 16);
> +	if (!addr)
> +		return CMD_RET_USAGE;
> +
> +	if (!yes && !confirm_prog())
> +		return CMD_RET_FAILURE;
> +
> +	fuse_hash_value(addr, !yes);
> +	printf("Hash key updated !\n");
> +
>  	return CMD_RET_SUCCESS;
>  }
>  
> -U_BOOT_CMD(stm32key, 4, 1, do_stm32key,
> -	   "Fuse ST Hash key",
> -	   "read <addr>: Read the hash store at addr in memory\n"
> -	   "stm32key fuse [-y] <addr> : Fuse hash store at addr in otp\n");
> +static char stm32key_help_text[] =
> +	"read <addr>: Read the hash stored at addr in memory\n"
> +	"stm32key fuse [-y] <addr> : Fuse hash stored at addr in OTP\n";
> +
> +U_BOOT_CMD_WITH_SUBCMDS(stm32key, "Fuse ST Hash key", stm32key_help_text,
> +	U_BOOT_SUBCMD_MKENT(read, 2, 0, do_stm32key_read),
> +	U_BOOT_SUBCMD_MKENT(fuse, 3, 0, do_stm32key_fuse));
> 
Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice

  reply	other threads:[~2021-07-01  7:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-28 12:55 [PATCH 0/7] stm32mp: cmd_stm32key: updates Patrick Delaunay
2021-06-28 12:55 ` [PATCH 1/7] stm32mp: configs: activate the command stm32key only for ST boards Patrick Delaunay
2021-07-01  7:35   ` Patrice CHOTARD
2021-07-16  8:27   ` Patrick DELAUNAY
2021-06-28 12:55 ` [PATCH 2/7] stm32mp: cmd_stm32key: use sub command Patrick Delaunay
2021-07-01  7:35   ` Patrice CHOTARD [this message]
2021-07-16  8:27   ` Patrick DELAUNAY
2021-06-28 12:55 ` [PATCH 3/7] stm32mp: cmd_stm32key: handle error in fuse_hash_value Patrick Delaunay
2021-07-01  7:35   ` Patrice CHOTARD
2021-07-16  8:28   ` Patrick DELAUNAY
2021-06-28 12:56 ` [PATCH 4/7] stm32mp: cmd_stm32key: lock of PKH OTP after fuse Patrick Delaunay
2021-07-01  7:35   ` Patrice CHOTARD
2021-07-16  8:28   ` Patrick DELAUNAY
2021-06-28 12:56 ` [PATCH 5/7] stm32mp: cmd_stm32key: add get_misc_dev function Patrick Delaunay
2021-07-01  7:36   ` Patrice CHOTARD
2021-07-16  8:28   ` Patrick DELAUNAY
2021-06-28 12:56 ` [PATCH 6/7] stm32mp: cmd_stm32key: add read OTP subcommand Patrick Delaunay
2021-07-01  7:36   ` Patrice CHOTARD
2021-07-16  8:28   ` Patrick DELAUNAY
2021-06-28 12:56 ` [PATCH 7/7] stm32mp: cmd_stm32key: add subcommand close Patrick Delaunay
2021-07-01  7:36   ` Patrice CHOTARD
2021-07-16  8:28   ` Patrick DELAUNAY

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=9266b9c2-b8c4-c526-acea-24a677953d52@foss.st.com \
    --to=patrice.chotard@foss.st.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-stm32@st-md-mailman.stormreply.com \
    /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.