linux-mmc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avri Altman <Avri.Altman@wdc.com>
To: Enrico Jorns <ejo@pengutronix.de>,
	"linux-mmc@vger.kernel.org" <linux-mmc@vger.kernel.org>
Cc: Ulf Hansson <ulf.hansson@linaro.org>
Subject: RE: [PATCH 1/2] mmc-utils: introduce optional --verify argument for 'extcsd write'
Date: Wed, 24 May 2023 07:29:00 +0000	[thread overview]
Message-ID: <DM6PR04MB65758F2FDA9209F713F9546EFC419@DM6PR04MB6575.namprd04.prod.outlook.com> (raw)
In-Reply-To: <20230522215310.2038669-1-ejo@pengutronix.de>

 
> Registers can be write-once but ioctl does not necessarily return with an
> error. Thus it is a good idea to allow verifying the data written.
Yeah - I find this approach more practical, than e.g. analyze the R1b response.

> 
> Signed-off-by: Enrico Jorns <ejo@pengutronix.de>
Aked-by: Avri Altman <avri.altman@wdc.com>

> ---
>  mmc.c      |  7 ++++---
>  mmc_cmds.c | 28 ++++++++++++++++++++++++++--
>  2 files changed, 30 insertions(+), 5 deletions(-)
> 
> diff --git a/mmc.c b/mmc.c
> index 795b4e3..3f813b4 100644
> --- a/mmc.c
> +++ b/mmc.c
> @@ -56,9 +56,10 @@ static struct Command commands[] = {
>                 "Print extcsd data from <device>.",
>           NULL
>         },
> -       { do_write_extcsd, 3,
> -         "extcsd write", "<offset> <value> <device>\n"
> -                 "Write <value> at offset <offset> to <device>'s extcsd.",
> +       { do_write_extcsd, -3,
> +         "extcsd write", "<offset> <value> <device> [--verify]\n"
> +                 "Write <value> at offset <offset> to <device>'s extcsd.\n"
> +                 "  --verify  Verify data written",
>           NULL
>         },
>         { do_writeprotect_boot_get, -1,
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index df66986..154020e 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -1986,9 +1986,10 @@ int do_write_extcsd(int nargs, char **argv)
>         int fd, ret;
>         int offset, value;
>         char *device;
> +       int verify = 0;
> 
> -       if (nargs != 4) {
> -               fprintf(stderr, "Usage: mmc extcsd write <offset> <value>
> </path/to/mmcblkX>\n");
> +       if (nargs != 4 && nargs != 5) {
> +               fprintf(stderr, "Usage: mmc extcsd write <offset>
> + <value> </path/to/mmcblkX> [--verify]\n");
>                 exit(1);
>         }
> 
> @@ -1996,6 +1997,14 @@ int do_write_extcsd(int nargs, char **argv)
>         value  = strtol(argv[2], NULL, 0);
>         device = argv[3];
> 
> +       if (nargs == 5) {
> +               if (strcmp(argv[4], "--verify") == 0) {
> +                       verify = 1;
> +               } else {
> +                       fprintf(stderr, "Unknown argument: '%s'\n", argv[4]);
> +               }
> +       }
> +
>         fd = open(device, O_RDWR);
>         if (fd < 0) {
>                 perror("open");
> @@ -2010,6 +2019,21 @@ int do_write_extcsd(int nargs, char **argv)
>                 exit(1);
>         }
> 
> +       if (verify) {
> +               __u8 ext_csd[512];
> +
> +               ret = read_extcsd(fd, ext_csd);
> +               if (ret) {
> +                       fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
> +                       exit(1);
> +               }
> +
> +               if (ext_csd[offset] != value) {
> +                       fprintf(stderr, "Verification failed: expected 0x%x, got 0x%x\n",
> value, ext_csd[offset]);
> +                       exit(1);
> +               }
> +       }
> +
>         return ret;
>  }
> 
> --
> 2.39.2


      parent reply	other threads:[~2023-05-24  7:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-22 21:53 [PATCH 1/2] mmc-utils: introduce optional --verify argument for 'extcsd write' Enrico Jorns
2023-05-22 21:53 ` [PATCH 2/2] mmc-utils: add error handling to 'extcsd write' input value parsing Enrico Jorns
2023-05-24  7:40   ` Avri Altman
2023-05-23 11:46 ` [PATCH 1/2] mmc-utils: introduce optional --verify argument for 'extcsd write' Christian Loehle
2023-05-24  7:29 ` Avri Altman [this message]

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=DM6PR04MB65758F2FDA9209F713F9546EFC419@DM6PR04MB6575.namprd04.prod.outlook.com \
    --to=avri.altman@wdc.com \
    --cc=ejo@pengutronix.de \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ulf.hansson@linaro.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).