diff mbox series

Add functionality to read the bootpart register

Message ID AM9P122MB0281612AE803A7E6B5A5A153F2F42@AM9P122MB0281.EURP122.PROD.OUTLOOK.COM
State Superseded
Headers show
Series Add functionality to read the bootpart register | expand

Commit Message

Loureiro, Joao May 23, 2024, 1:20 p.m. UTC
Currently the only way to read the bootpart register
is to dump the whole extcsd register. This patch adds
the possibility to read the bootpart register directly
for situations where the whole extcsd is too verbose.

Signed-off-by: João Loureiro <joao.loureiro@philips.com>
---
 man/mmc.1  |  3 +++
 mmc.c      |  5 +++++
 mmc_cmds.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 mmc_cmds.h |  1 +
 4 files changed, 63 insertions(+)

--
2.34.1

Comments

Avri Altman May 23, 2024, 2:30 p.m. UTC | #1
> Currently the only way to read the bootpart register is to dump the whole
> extcsd register. This patch adds the possibility to read the bootpart register
> directly for situations where the whole extcsd is too verbose.
> 
> Signed-off-by: João Loureiro <joao.loureiro@philips.com>
You forgot to mark your patch version.

> ---
>  man/mmc.1  |  3 +++
>  mmc.c      |  5 +++++
>  mmc_cmds.c | 54
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  mmc_cmds.h |  1 +
>  4 files changed, 63 insertions(+)
> 
> diff --git a/man/mmc.1 b/man/mmc.1
> index bccabf3..8aff106 100644
> --- a/man/mmc.1
> +++ b/man/mmc.1
> @@ -59,6 +59,9 @@ Disable the boot partition for the <device> with
> <boot_partition> set to 0.
>  To receive acknowledgment of boot from the card set <send_ack>  to 1, else
> set it to 0.
>  .TP
> +.BR "bootpart read <device>"
> +Read the boot partition information for the <device>.
> +.TP
>  .BR "bootbus set <boot_mode> <reset_boot_bus_conditions>
> <boot_bus_width> <device>"
>  Set Boot Bus Conditions.
>  <boot_mode> must be "single_backward|single_hs|dual"
> diff --git a/mmc.c b/mmc.c
> index bc8f74e..26c4f13 100644
> --- a/mmc.c
> +++ b/mmc.c
> @@ -126,6 +126,11 @@ static struct Command commands[] = {
>                 "Enable the boot partition for the <device>.\nDisable the boot
> partition for the <device> if <boot_partition> is set to 0.\nTo receive
> acknowledgment of boot from the card set <send_ack>\nto 1, else set it to
> 0.",
>           NULL
>         },
> +       { do_read_boot_en, -1,
> +         "bootpart read", "<device>\n"
> +               "Read the boot partition information for the <device>.",
> +         NULL
> +       },
>         { do_boot_bus_conditions_set, -4,
>           "bootbus set", "<boot_mode> " "<reset_boot_bus_conditions> "
> "<boot_bus_width> " "<device>\n"
>           "Set Boot Bus Conditions.\n"
> diff --git a/mmc_cmds.c b/mmc_cmds.c
> index 936e0c5..add9e56 100644
> --- a/mmc_cmds.c
> +++ b/mmc_cmds.c
> @@ -233,6 +233,29 @@ static void print_writeprotect_boot_status(__u8
> *ext_csd)
>         }
>  }
> 
> +static void print_boot_en_status(__u8 *ext_csd) {
> +       __u8 reg;
> +
> +       reg = ext_csd[EXT_CSD_BOOT_CFG];
> +       printf("Configuration bytes [PARTITION_CONFIG: 0x%02x]\n " \
> +                  "Boot partition: ", reg);
> +       switch ((reg & EXT_CSD_BOOT_CFG_EN)>>3) {
> +       case 0x0:
> +               printf("disabled\n");
> +               break;
> +       case 0x1:
> +               printf("1\n");
> +               break;
> +       case 0x2:
> +               printf("2\n");
> +               break;
> +       case 0x7:
> +               printf("user area\n");
> +               break;
> +       }
> +}
Maybe re-use print_boot_en_status in do_read_extcsd() as well?

Thanks,
Avri

> +
>  static int get_wp_group_size_in_blks(__u8 *ext_csd, __u32 *size)  {
>         __u8 ext_csd_rev = ext_csd[EXT_CSD_REV]; @@ -602,6 +625,37 @@ int
> do_disable_512B_emulation(int nargs, char **argv)
>         return ret;
>  }
> 
> +int do_read_boot_en(int nargs, char **argv) {
> +       __u8 ext_csd[512];
> +       int fd, ret;
> +       char *device;
> +
> +       if (nargs != 2) {
> +               fprintf(stderr, "Usage: mmc bootpart read </path/to/mmcblkX>\n");
> +               exit(1);
> +       }
> +
> +       device = argv[1];
> +
> +       fd = open(device, O_RDWR);
> +       if (fd < 0) {
> +               perror("open");
> +               exit(1);
> +       }
> +
> +       ret = read_extcsd(fd, ext_csd);
> +       if (ret) {
> +               fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
> +               exit(1);
> +       }
> +
> +       print_boot_en_status(ext_csd);
> +
> +       close(fd);
> +       return ret;
> +}
> +
>  int do_write_boot_en(int nargs, char **argv)  {
>         __u8 ext_csd[512];
> diff --git a/mmc_cmds.h b/mmc_cmds.h
> index 5f2bef1..12716b5 100644
> --- a/mmc_cmds.h
> +++ b/mmc_cmds.h
> @@ -25,6 +25,7 @@ int do_writeprotect_boot_set(int nargs, char **argv);
> int do_writeprotect_user_get(int nargs, char **argv);  int
> do_writeprotect_user_set(int nargs, char **argv);  int
> do_disable_512B_emulation(int nargs, char **argv);
> +int do_read_boot_en(int nargs, char **argv);
>  int do_write_boot_en(int nargs, char **argv);  int
> do_boot_bus_conditions_set(int nargs, char **argv);  int
> do_write_bkops_en(int nargs, char **argv);
> --
> 2.34.1
> 
> 
> ________________________________
> The information contained in this message may be confidential and legally
> protected under applicable law. The message is intended solely for the
> addressee(s). If you are not the intended recipient, you are hereby notified
> that any use, forwarding, dissemination, or reproduction of this message is
> strictly prohibited and may be unlawful. If you are not the intended recipient,
> please contact the sender by return e-mail and destroy all copies of the original
> message.
diff mbox series

Patch

diff --git a/man/mmc.1 b/man/mmc.1
index bccabf3..8aff106 100644
--- a/man/mmc.1
+++ b/man/mmc.1
@@ -59,6 +59,9 @@  Disable the boot partition for the <device> with <boot_partition> set to 0.
 To receive acknowledgment of boot from the card set <send_ack>
 to 1, else set it to 0.
 .TP
+.BR "bootpart read <device>"
+Read the boot partition information for the <device>.
+.TP
 .BR "bootbus set <boot_mode> <reset_boot_bus_conditions> <boot_bus_width> <device>"
 Set Boot Bus Conditions.
 <boot_mode> must be "single_backward|single_hs|dual"
diff --git a/mmc.c b/mmc.c
index bc8f74e..26c4f13 100644
--- a/mmc.c
+++ b/mmc.c
@@ -126,6 +126,11 @@  static struct Command commands[] = {
                "Enable the boot partition for the <device>.\nDisable the boot partition for the <device> if <boot_partition> is set to 0.\nTo receive acknowledgment of boot from the card set <send_ack>\nto 1, else set it to 0.",
          NULL
        },
+       { do_read_boot_en, -1,
+         "bootpart read", "<device>\n"
+               "Read the boot partition information for the <device>.",
+         NULL
+       },
        { do_boot_bus_conditions_set, -4,
          "bootbus set", "<boot_mode> " "<reset_boot_bus_conditions> " "<boot_bus_width> " "<device>\n"
          "Set Boot Bus Conditions.\n"
diff --git a/mmc_cmds.c b/mmc_cmds.c
index 936e0c5..add9e56 100644
--- a/mmc_cmds.c
+++ b/mmc_cmds.c
@@ -233,6 +233,29 @@  static void print_writeprotect_boot_status(__u8 *ext_csd)
        }
 }

+static void print_boot_en_status(__u8 *ext_csd)
+{
+       __u8 reg;
+
+       reg = ext_csd[EXT_CSD_BOOT_CFG];
+       printf("Configuration bytes [PARTITION_CONFIG: 0x%02x]\n " \
+                  "Boot partition: ", reg);
+       switch ((reg & EXT_CSD_BOOT_CFG_EN)>>3) {
+       case 0x0:
+               printf("disabled\n");
+               break;
+       case 0x1:
+               printf("1\n");
+               break;
+       case 0x2:
+               printf("2\n");
+               break;
+       case 0x7:
+               printf("user area\n");
+               break;
+       }
+}
+
 static int get_wp_group_size_in_blks(__u8 *ext_csd, __u32 *size)
 {
        __u8 ext_csd_rev = ext_csd[EXT_CSD_REV];
@@ -602,6 +625,37 @@  int do_disable_512B_emulation(int nargs, char **argv)
        return ret;
 }

+int do_read_boot_en(int nargs, char **argv)
+{
+       __u8 ext_csd[512];
+       int fd, ret;
+       char *device;
+
+       if (nargs != 2) {
+               fprintf(stderr, "Usage: mmc bootpart read </path/to/mmcblkX>\n");
+               exit(1);
+       }
+
+       device = argv[1];
+
+       fd = open(device, O_RDWR);
+       if (fd < 0) {
+               perror("open");
+               exit(1);
+       }
+
+       ret = read_extcsd(fd, ext_csd);
+       if (ret) {
+               fprintf(stderr, "Could not read EXT_CSD from %s\n", device);
+               exit(1);
+       }
+
+       print_boot_en_status(ext_csd);
+
+       close(fd);
+       return ret;
+}
+
 int do_write_boot_en(int nargs, char **argv)
 {
        __u8 ext_csd[512];
diff --git a/mmc_cmds.h b/mmc_cmds.h
index 5f2bef1..12716b5 100644
--- a/mmc_cmds.h
+++ b/mmc_cmds.h
@@ -25,6 +25,7 @@  int do_writeprotect_boot_set(int nargs, char **argv);
 int do_writeprotect_user_get(int nargs, char **argv);
 int do_writeprotect_user_set(int nargs, char **argv);
 int do_disable_512B_emulation(int nargs, char **argv);
+int do_read_boot_en(int nargs, char **argv);
 int do_write_boot_en(int nargs, char **argv);
 int do_boot_bus_conditions_set(int nargs, char **argv);
 int do_write_bkops_en(int nargs, char **argv);