Re: [U-Boot] [U-Boot,v3] mmc: add mmc partconf read capability

2016-08-17 Thread Angelo Dureghello


Hi Jaehoon,

On 04/08/2016 07:09, Jaehoon Chung wrote:

Hi Angelo,

On 04/15/2016 03:51 AM, Angelo Dureghello wrote:

This patch allows to read back the EXT_CSD[179] partition_config
register, just specifying the dev param:

U-Boot> mmc partconf 0
EXT_CSD[179], PARTITION_CONFIG register:
BOOT_ACK: 0
BOOT_PARTITION_ENABLE: 0
PARTITION_ACCESS: 0


I don't know this patch's history..
Could you resend the patch on latest u-boot?

This code should be moved from drivers/mmc/mmc.c to drivers/mmc/mmc_boot.c.

Refer to "commit c40704f4b13a19a95aa13965c0f1f6a93b5574c0"
- mmc: Move MMC boot code into its own file

Otherwise, I will drop this patch.


sorry was away for some vacation time. Sure, i provide a new patch soon.

Regards,
angelo



Best Regards,
Jaehoon Chung



Signed-off-by: Angelo Dureghello 
---
Changes for v2:
- fixed commit message
- added white lines in cmd/mmc.c
- fixed help in cmd/mmc.c
Changes for v3:
- fixed command output to a single printf
- fixed return codes
- fixed macroes with parenthesis around parameter
---
 cmd/mmc.c | 35 +--
 drivers/mmc/mmc.c | 31 +++
 include/mmc.h |  6 ++
 3 files changed, 66 insertions(+), 6 deletions(-)

diff --git a/cmd/mmc.c b/cmd/mmc.c
index 39ef072..2bc7d42 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -697,6 +697,24 @@ static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
return CMD_RET_SUCCESS;
 }
+
+static int do_mmc_partconf_read(struct mmc *mmc)
+{
+   int err;
+   u8 ack, part_num, access;
+
+   err = mmc_get_part_conf(mmc, , _num, );
+   if (err)
+   return CMD_RET_FAILURE;
+
+   printf("EXT_CSD[179], PARTITION_CONFIG register:\n"
+   "BOOT_ACK: %d\n"
+   "BOOT_PARTITION_ENABLE: %d\n"
+   "PARTITION_ACCESS: %d\n", ack, part_num, access);
+
+   return CMD_RET_SUCCESS;
+}
+
 static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
   int argc, char * const argv[])
 {
@@ -704,13 +722,10 @@ static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
struct mmc *mmc;
u8 ack, part_num, access;

-   if (argc != 5)
+   if (argc != 2 && argc != 5)
return CMD_RET_USAGE;

dev = simple_strtoul(argv[1], NULL, 10);
-   ack = simple_strtoul(argv[2], NULL, 10);
-   part_num = simple_strtoul(argv[3], NULL, 10);
-   access = simple_strtoul(argv[4], NULL, 10);

mmc = init_mmc_device(dev, false);
if (!mmc)
@@ -721,9 +736,17 @@ static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
return CMD_RET_FAILURE;
}

+   if (argc == 2)
+   return do_mmc_partconf_read(mmc);
+
+   ack = simple_strtoul(argv[2], NULL, 10);
+   part_num = simple_strtoul(argv[3], NULL, 10);
+   access = simple_strtoul(argv[4], NULL, 10);
+
/* acknowledge to be sent during boot operation */
return mmc_set_part_conf(mmc, ack, part_num, access);
 }
+
 static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
   int argc, char * const argv[])
 {
@@ -858,8 +881,8 @@ U_BOOT_CMD(
" - Set the BOOT_BUS_WIDTH field of the specified device\n"
"mmc bootpart-resize   \n"
" - Change sizes of boot and RPMB partitions of specified device\n"
-   "mmc partconf dev boot_ack boot_partition partition_access\n"
-   " - Change the bits of the PARTITION_CONFIG field of the specified 
device\n"
+   "mmc partconf dev [boot_ack boot_partition partition_access]\n"
+   " - Show or change the bits of the PARTITION_CONFIG field of the specified 
device\n"
"mmc rst-function dev value\n"
" - Change the RST_n_FUNCTION field of the specified device\n"
"   WARNING: This is a write-once field and 0 / 1 / 2 are the only valid 
values.\n"
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index d3c22ab..e4a0130 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1954,6 +1954,37 @@ int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 
part_num, u8 access)
 }

 /*
+ * Read EXT_CSD[179] which is PARTITION_CONFIG (formerly BOOT_CONFIG)
+ * and returning the extracted fields BOOT_ACK, BOOT_PARTITION_ENABLE and
+ * PARTITION_ACCESS.
+ */
+int mmc_get_part_conf(struct mmc *mmc, u8 *ack, u8 *part_num, u8 *access)
+{
+   int err;
+   u8 part_conf;
+
+   ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+
+   mmc->erase_grp_size = 1;
+   mmc->part_config = MMCPART_NOAVAILABLE;
+
+   if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
+   return CMD_RET_FAILURE;
+
+   err = mmc_send_ext_csd(mmc, ext_csd);
+   if (err)
+   return err;
+
+   part_conf = ext_csd[EXT_CSD_PART_CONF];
+
+   *ack = EXT_CSD_EXTRACT_BOOT_ACK(part_conf);
+   *part_num = EXT_CSD_EXTRACT_BOOT_PART(part_conf);
+   *access = 

Re: [U-Boot] [U-Boot,v3] mmc: add mmc partconf read capability

2016-08-03 Thread Jaehoon Chung
Hi Angelo,

On 04/15/2016 03:51 AM, Angelo Dureghello wrote:
> This patch allows to read back the EXT_CSD[179] partition_config
> register, just specifying the dev param:
> 
> U-Boot> mmc partconf 0
> EXT_CSD[179], PARTITION_CONFIG register:
> BOOT_ACK: 0
> BOOT_PARTITION_ENABLE: 0
> PARTITION_ACCESS: 0

I don't know this patch's history..
Could you resend the patch on latest u-boot?

This code should be moved from drivers/mmc/mmc.c to drivers/mmc/mmc_boot.c.

Refer to "commit c40704f4b13a19a95aa13965c0f1f6a93b5574c0"
- mmc: Move MMC boot code into its own file

Otherwise, I will drop this patch.

Best Regards,
Jaehoon Chung

> 
> Signed-off-by: Angelo Dureghello 
> ---
> Changes for v2:
> - fixed commit message
> - added white lines in cmd/mmc.c
> - fixed help in cmd/mmc.c
> Changes for v3:
> - fixed command output to a single printf
> - fixed return codes
> - fixed macroes with parenthesis around parameter
> ---
>  cmd/mmc.c | 35 +--
>  drivers/mmc/mmc.c | 31 +++
>  include/mmc.h |  6 ++
>  3 files changed, 66 insertions(+), 6 deletions(-)
> 
> diff --git a/cmd/mmc.c b/cmd/mmc.c
> index 39ef072..2bc7d42 100644
> --- a/cmd/mmc.c
> +++ b/cmd/mmc.c
> @@ -697,6 +697,24 @@ static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
>   printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
>   return CMD_RET_SUCCESS;
>  }
> +
> +static int do_mmc_partconf_read(struct mmc *mmc)
> +{
> + int err;
> + u8 ack, part_num, access;
> +
> + err = mmc_get_part_conf(mmc, , _num, );
> + if (err)
> + return CMD_RET_FAILURE;
> +
> + printf("EXT_CSD[179], PARTITION_CONFIG register:\n"
> + "BOOT_ACK: %d\n"
> + "BOOT_PARTITION_ENABLE: %d\n"
> + "PARTITION_ACCESS: %d\n", ack, part_num, access);
> +
> + return CMD_RET_SUCCESS;
> +}
> +
>  static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
>  int argc, char * const argv[])
>  {
> @@ -704,13 +722,10 @@ static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
>   struct mmc *mmc;
>   u8 ack, part_num, access;
>  
> - if (argc != 5)
> + if (argc != 2 && argc != 5)
>   return CMD_RET_USAGE;
>  
>   dev = simple_strtoul(argv[1], NULL, 10);
> - ack = simple_strtoul(argv[2], NULL, 10);
> - part_num = simple_strtoul(argv[3], NULL, 10);
> - access = simple_strtoul(argv[4], NULL, 10);
>  
>   mmc = init_mmc_device(dev, false);
>   if (!mmc)
> @@ -721,9 +736,17 @@ static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
>   return CMD_RET_FAILURE;
>   }
>  
> + if (argc == 2)
> + return do_mmc_partconf_read(mmc);
> +
> + ack = simple_strtoul(argv[2], NULL, 10);
> + part_num = simple_strtoul(argv[3], NULL, 10);
> + access = simple_strtoul(argv[4], NULL, 10);
> +
>   /* acknowledge to be sent during boot operation */
>   return mmc_set_part_conf(mmc, ack, part_num, access);
>  }
> +
>  static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
>  int argc, char * const argv[])
>  {
> @@ -858,8 +881,8 @@ U_BOOT_CMD(
>   " - Set the BOOT_BUS_WIDTH field of the specified device\n"
>   "mmc bootpart-resize   \n"
>   " - Change sizes of boot and RPMB partitions of specified device\n"
> - "mmc partconf dev boot_ack boot_partition partition_access\n"
> - " - Change the bits of the PARTITION_CONFIG field of the specified 
> device\n"
> + "mmc partconf dev [boot_ack boot_partition partition_access]\n"
> + " - Show or change the bits of the PARTITION_CONFIG field of the 
> specified device\n"
>   "mmc rst-function dev value\n"
>   " - Change the RST_n_FUNCTION field of the specified device\n"
>   "   WARNING: This is a write-once field and 0 / 1 / 2 are the only 
> valid values.\n"
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index d3c22ab..e4a0130 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -1954,6 +1954,37 @@ int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 
> part_num, u8 access)
>  }
>  
>  /*
> + * Read EXT_CSD[179] which is PARTITION_CONFIG (formerly BOOT_CONFIG)
> + * and returning the extracted fields BOOT_ACK, BOOT_PARTITION_ENABLE and
> + * PARTITION_ACCESS.
> + */
> +int mmc_get_part_conf(struct mmc *mmc, u8 *ack, u8 *part_num, u8 *access)
> +{
> + int err;
> + u8 part_conf;
> +
> + ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
> +
> + mmc->erase_grp_size = 1;
> + mmc->part_config = MMCPART_NOAVAILABLE;
> +
> + if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
> + return CMD_RET_FAILURE;
> +
> + err = mmc_send_ext_csd(mmc, ext_csd);
> + if (err)
> + return err;
> +
> + part_conf = ext_csd[EXT_CSD_PART_CONF];
> +
> + *ack = EXT_CSD_EXTRACT_BOOT_ACK(part_conf);
> + *part_num = EXT_CSD_EXTRACT_BOOT_PART(part_conf);
> + *access =