diff mbox

[U-Boot] cmd: mmc: add mmc partconf read capability

Message ID 1501590430-23770-1-git-send-email-agust@denx.de
State Accepted
Commit bdb6099666933491ce393e52132e05604da91b1a
Delegated to: Jaehoon Chung
Headers show

Commit Message

Anatolij Gustschin Aug. 1, 2017, 12:27 p.m. UTC
From: Angelo Dureghello <angelo@sysam.it>

This patch allows to show the EXT_CSD[179] partition_config
register info, just by specifying the dev param:

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

Signed-off-by: Angelo Dureghello <angelo@sysam.it>
Signed-off-by: Anatolij Gustschin <agust@denx.de>
---
Changes for v4:
- rebase on v2017.09-rc1
- don't read the PARTITION_CONFIG register again, show the
  PARTITION_CONFIG info as saved during mmc device initialisation
- update the part_config field of the mmc device when the partconf
  setting command succeeded
- output values in hex format, as these are register bit fields

Changes for v3:
- fixed command output to a single printf
- fixed return codes
- fixed macroes with parenthesis around parameter
Changes for v2:
- fixed commit message
- added white lines in cmd/mmc.c
- fixed help in cmd/mmc.c

 cmd/mmc.c              | 38 ++++++++++++++++++++++++++++++++------
 drivers/mmc/mmc_boot.c | 17 +++++++++++++----
 include/mmc.h          |  4 ++++
 3 files changed, 49 insertions(+), 10 deletions(-)

Comments

Jaehoon Chung Aug. 17, 2017, 7:51 a.m. UTC | #1
On 08/01/2017 09:27 PM, Anatolij Gustschin wrote:
> From: Angelo Dureghello <angelo@sysam.it>
> 
> This patch allows to show the EXT_CSD[179] partition_config
> register info, just by specifying the dev param:
> 
>   U-Boot> mmc partconf 0
>   EXT_CSD[179], PARTITION_CONFIG:
>   BOOT_ACK: 0x0
>   BOOT_PARTITION_ENABLE: 0x0
>   PARTITION_ACCESS: 0x0
> 
> Signed-off-by: Angelo Dureghello <angelo@sysam.it>
> Signed-off-by: Anatolij Gustschin <agust@denx.de>

Sorry for late. Applied to u-boot-mmc. Thanks!

Best Regards,
Jaehoon Chung

> ---
> Changes for v4:
> - rebase on v2017.09-rc1
> - don't read the PARTITION_CONFIG register again, show the
>   PARTITION_CONFIG info as saved during mmc device initialisation
> - update the part_config field of the mmc device when the partconf
>   setting command succeeded
> - output values in hex format, as these are register bit fields
> 
> Changes for v3:
> - fixed command output to a single printf
> - fixed return codes
> - fixed macroes with parenthesis around parameter
> Changes for v2:
> - fixed commit message
> - added white lines in cmd/mmc.c
> - fixed help in cmd/mmc.c
> 
>  cmd/mmc.c              | 38 ++++++++++++++++++++++++++++++++------
>  drivers/mmc/mmc_boot.c | 17 +++++++++++++----
>  include/mmc.h          |  4 ++++
>  3 files changed, 49 insertions(+), 10 deletions(-)
> 
> diff --git a/cmd/mmc.c b/cmd/mmc.c
> index f7b7568..00697fc 100644
> --- a/cmd/mmc.c
> +++ b/cmd/mmc.c
> @@ -643,6 +643,28 @@ 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 mmc_partconf_print(struct mmc *mmc)
> +{
> +	u8 ack, access, part;
> +
> +	if (mmc->part_config == MMCPART_NOAVAILABLE) {
> +		printf("No part_config info for ver. 0x%x\n", mmc->version);
> +		return CMD_RET_FAILURE;
> +	}
> +
> +	access = EXT_CSD_EXTRACT_PARTITION_ACCESS(mmc->part_config);
> +	ack = EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config);
> +	part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
> +
> +	printf("EXT_CSD[179], PARTITION_CONFIG:\n"
> +		"BOOT_ACK: 0x%x\n"
> +		"BOOT_PARTITION_ENABLE: 0x%x\n"
> +		"PARTITION_ACCESS: 0x%x\n", ack, part, access);
> +
> +	return CMD_RET_SUCCESS;
> +}
> +
>  static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
>  			   int argc, char * const argv[])
>  {
> @@ -650,13 +672,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)
> @@ -667,6 +686,13 @@ static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
>  		return CMD_RET_FAILURE;
>  	}
>  
> +	if (argc == 2)
> +		return mmc_partconf_print(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);
>  }
> @@ -832,8 +858,8 @@ U_BOOT_CMD(
>  	" - Set the BOOT_BUS_WIDTH field of the specified device\n"
>  	"mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\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_boot.c b/drivers/mmc/mmc_boot.c
> index ac6f56f..6d77ce9 100644
> --- a/drivers/mmc/mmc_boot.c
> +++ b/drivers/mmc/mmc_boot.c
> @@ -100,10 +100,19 @@ int mmc_set_boot_bus_width(struct mmc *mmc, u8 width, u8 reset, u8 mode)
>   */
>  int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
>  {
> -	return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
> -			  EXT_CSD_BOOT_ACK(ack) |
> -			  EXT_CSD_BOOT_PART_NUM(part_num) |
> -			  EXT_CSD_PARTITION_ACCESS(access));
> +	int ret;
> +	u8 part_conf;
> +
> +	part_conf = EXT_CSD_BOOT_ACK(ack) |
> +		    EXT_CSD_BOOT_PART_NUM(part_num) |
> +		    EXT_CSD_PARTITION_ACCESS(access);
> +
> +	ret = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
> +			 part_conf);
> +	if (!ret)
> +		mmc->part_config = part_conf;
> +
> +	return ret;
>  }
>  
>  /*
> diff --git a/include/mmc.h b/include/mmc.h
> index 00576fa..4277cb0 100644
> --- a/include/mmc.h
> +++ b/include/mmc.h
> @@ -221,6 +221,10 @@
>  #define EXT_CSD_BOOT_PART_NUM(x)	(x << 3)
>  #define EXT_CSD_PARTITION_ACCESS(x)	(x << 0)
>  
> +#define EXT_CSD_EXTRACT_BOOT_ACK(x)		(((x) >> 6) & 0x1)
> +#define EXT_CSD_EXTRACT_BOOT_PART(x)		(((x) >> 3) & 0x7)
> +#define EXT_CSD_EXTRACT_PARTITION_ACCESS(x)	((x) & 0x7)
> +
>  #define EXT_CSD_BOOT_BUS_WIDTH_MODE(x)	(x << 3)
>  #define EXT_CSD_BOOT_BUS_WIDTH_RESET(x)	(x << 2)
>  #define EXT_CSD_BOOT_BUS_WIDTH_WIDTH(x)	(x)
>
diff mbox

Patch

diff --git a/cmd/mmc.c b/cmd/mmc.c
index f7b7568..00697fc 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -643,6 +643,28 @@  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 mmc_partconf_print(struct mmc *mmc)
+{
+	u8 ack, access, part;
+
+	if (mmc->part_config == MMCPART_NOAVAILABLE) {
+		printf("No part_config info for ver. 0x%x\n", mmc->version);
+		return CMD_RET_FAILURE;
+	}
+
+	access = EXT_CSD_EXTRACT_PARTITION_ACCESS(mmc->part_config);
+	ack = EXT_CSD_EXTRACT_BOOT_ACK(mmc->part_config);
+	part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
+
+	printf("EXT_CSD[179], PARTITION_CONFIG:\n"
+		"BOOT_ACK: 0x%x\n"
+		"BOOT_PARTITION_ENABLE: 0x%x\n"
+		"PARTITION_ACCESS: 0x%x\n", ack, part, access);
+
+	return CMD_RET_SUCCESS;
+}
+
 static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
 			   int argc, char * const argv[])
 {
@@ -650,13 +672,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)
@@ -667,6 +686,13 @@  static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
 		return CMD_RET_FAILURE;
 	}
 
+	if (argc == 2)
+		return mmc_partconf_print(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);
 }
@@ -832,8 +858,8 @@  U_BOOT_CMD(
 	" - Set the BOOT_BUS_WIDTH field of the specified device\n"
 	"mmc bootpart-resize <dev> <boot part size MB> <RPMB part size MB>\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_boot.c b/drivers/mmc/mmc_boot.c
index ac6f56f..6d77ce9 100644
--- a/drivers/mmc/mmc_boot.c
+++ b/drivers/mmc/mmc_boot.c
@@ -100,10 +100,19 @@  int mmc_set_boot_bus_width(struct mmc *mmc, u8 width, u8 reset, u8 mode)
  */
 int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
 {
-	return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
-			  EXT_CSD_BOOT_ACK(ack) |
-			  EXT_CSD_BOOT_PART_NUM(part_num) |
-			  EXT_CSD_PARTITION_ACCESS(access));
+	int ret;
+	u8 part_conf;
+
+	part_conf = EXT_CSD_BOOT_ACK(ack) |
+		    EXT_CSD_BOOT_PART_NUM(part_num) |
+		    EXT_CSD_PARTITION_ACCESS(access);
+
+	ret = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
+			 part_conf);
+	if (!ret)
+		mmc->part_config = part_conf;
+
+	return ret;
 }
 
 /*
diff --git a/include/mmc.h b/include/mmc.h
index 00576fa..4277cb0 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -221,6 +221,10 @@ 
 #define EXT_CSD_BOOT_PART_NUM(x)	(x << 3)
 #define EXT_CSD_PARTITION_ACCESS(x)	(x << 0)
 
+#define EXT_CSD_EXTRACT_BOOT_ACK(x)		(((x) >> 6) & 0x1)
+#define EXT_CSD_EXTRACT_BOOT_PART(x)		(((x) >> 3) & 0x7)
+#define EXT_CSD_EXTRACT_PARTITION_ACCESS(x)	((x) & 0x7)
+
 #define EXT_CSD_BOOT_BUS_WIDTH_MODE(x)	(x << 3)
 #define EXT_CSD_BOOT_BUS_WIDTH_RESET(x)	(x << 2)
 #define EXT_CSD_BOOT_BUS_WIDTH_WIDTH(x)	(x)