diff mbox

[U-Boot,v2,6/8] cmd_mmc.c: Add 'partconf' command to mmc

Message ID 1391117520-21868-6-git-send-email-trini@ti.com
State Superseded
Delegated to: Pantelis Antoniou
Headers show

Commit Message

Tom Rini Jan. 30, 2014, 9:31 p.m. UTC
Add a partconf sub-command to the mmc command to allow for setting
the boot_ack, boot_partition and partition_access fields of
PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]).  Part of this
requires changing the check for 'part' from an strncmp to a strcmp, like
the rest of the sub-commands.

Cc: Andy Fleming <afleming@gmail.com>
Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
Signed-off-by: Tom Rini <trini@ti.com>
---
 common/cmd_mmc.c  |   30 +++++++++++++++++++++++++++++-
 drivers/mmc/mmc.c |   21 +++++++++++++++++++++
 include/mmc.h     |    2 ++
 3 files changed, 52 insertions(+), 1 deletion(-)

Comments

Jaehoon Chung Feb. 4, 2014, 12:58 a.m. UTC | #1
On 01/31/2014 06:31 AM, Tom Rini wrote:
> Add a partconf sub-command to the mmc command to allow for setting
> the boot_ack, boot_partition and partition_access fields of
> PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]).  Part of this
> requires changing the check for 'part' from an strncmp to a strcmp, like
> the rest of the sub-commands.
> 
> Cc: Andy Fleming <afleming@gmail.com>
> Cc: Pantelis Antoniou <panto@antoniou-consulting.com>
> Signed-off-by: Tom Rini <trini@ti.com>
> ---
>  common/cmd_mmc.c  |   30 +++++++++++++++++++++++++++++-
>  drivers/mmc/mmc.c |   21 +++++++++++++++++++++
>  include/mmc.h     |    2 ++
>  3 files changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
> index a322063..5842e85 100644
> --- a/common/cmd_mmc.c
> +++ b/common/cmd_mmc.c
> @@ -195,7 +195,7 @@ static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  			return 1;
>  		else
>  			return 0;
> -	} else if (strncmp(argv[1], "part", 4) == 0) {
> +	} else if (strcmp(argv[1], "part") == 0) {
>  		block_dev_desc_t *mmc_dev;
>  		struct mmc *mmc;
>  
> @@ -311,7 +311,33 @@ static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
>  
>  		/* acknowledge to be sent during boot operation */
>  		return boot_part_access(mmc, 1, part_num, access);
> +	} else if (strcmp(argv[1], "partconf") == 0) {
> +		int dev;
> +		struct mmc *mmc;
> +		u8 ack, part_num, access;
> +
> +		if (argc == 6) {
> +			dev = simple_strtoul(argv[2], NULL, 10);
> +			ack = simple_strtoul(argv[3], NULL, 10);
> +			part_num = simple_strtoul(argv[4], NULL, 10);
> +			access = simple_strtoul(argv[5], NULL, 10);
> +		} else {
> +			return CMD_RET_USAGE;
> +		}
> +
> +		mmc = find_mmc_device(dev);
> +		if (!mmc) {
> +			printf("no mmc device at slot %x\n", dev);
> +			return 1;
> +		}
>  
> +		if (IS_SD(mmc)) {
> +			puts("PARTITION_CONFIG only exists on eMMC\n");
> +			return 1;
> +		}
> +
> +		/* acknowledge to be sent during boot operation */
> +		return mmc_set_part_conf(mmc, ack, part_num, access);
>  	} else if (strcmp(argv[1], "bootpart-resize") == 0) {
>  		int dev;
>  		struct mmc *mmc;
> @@ -451,6 +477,8 @@ U_BOOT_CMD(
>  	" - Enable boot_part for booting and disable access to boot_part\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"

How about using bracket("< >") for more readable?
mmc partconf <dev> <boot_ack> <boot_partition> <partition_access>

Anyway, looks good to me.
Acked-by: Jaehoon Chung <jh80.chung@samsung.com>

> +	" - Change the bits of the PARTITION_CONFIG field of the specified device\n"
>  #endif
>  	"mmc setdsr - set DSR register value\n"
>  	);
> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
> index c6a1c23..1591fce 100644
> --- a/drivers/mmc/mmc.c
> +++ b/drivers/mmc/mmc.c
> @@ -1505,4 +1505,25 @@ int mmc_boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
>  	}
>  	return 0;
>  }
> +
> +/*
> + * Modify EXT_CSD[179] which is PARTITION_CONFIG (formerly BOOT_CONFIG)
> + * based on the passed in values for BOOT_ACK, BOOT_PARTITION_ENABLE and
> + * PARTITION_ACCESS.
> + *
> + * Returns 0 on success.
> + */
> +int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
> +{
> +	int err;
> +
> +	err = 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));
> +
> +	if (err)
> +		return err;
> +	return 0;
> +}
>  #endif
> diff --git a/include/mmc.h b/include/mmc.h
> index e1060b9..7e026da 100644
> --- a/include/mmc.h
> +++ b/include/mmc.h
> @@ -312,6 +312,8 @@ int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
>  					unsigned long rpmbsize);
>  /* Function to send commands to open/close the specified boot partition */
>  int mmc_boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access);
> +/* Function to modify the PARTITION_CONFIG field of EXT_CSD */
> +int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access);
>  
>  /**
>   * Start device initialization and return immediately; it does not block on
>
Tom Rini Feb. 5, 2014, 1:03 p.m. UTC | #2
On Tue, Feb 04, 2014 at 09:58:06AM +0900, Jaehoon Chung wrote:
> On 01/31/2014 06:31 AM, Tom Rini wrote:
> > Add a partconf sub-command to the mmc command to allow for setting
> > the boot_ack, boot_partition and partition_access fields of
> > PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]).  Part of this
> > requires changing the check for 'part' from an strncmp to a strcmp, like
> > the rest of the sub-commands.
[snip]
> > @@ -451,6 +477,8 @@ U_BOOT_CMD(
> >  	" - Enable boot_part for booting and disable access to boot_part\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"
> 
> How about using bracket("< >") for more readable?
> mmc partconf <dev> <boot_ack> <boot_partition> <partition_access>

Except for bootpart-resize the rest of the mmc commands (and most in
general) don't use "< >" around required parameters unless it's part of
some sub-choices (such as spl export <img=atags|fdt> ...).

> Anyway, looks good to me.

Thanks!
Jaehoon Chung Feb. 6, 2014, 4:48 a.m. UTC | #3
Dear, Tom.

On 02/05/2014 10:03 PM, Tom Rini wrote:
> On Tue, Feb 04, 2014 at 09:58:06AM +0900, Jaehoon Chung wrote:
>> On 01/31/2014 06:31 AM, Tom Rini wrote:
>>> Add a partconf sub-command to the mmc command to allow for setting
>>> the boot_ack, boot_partition and partition_access fields of
>>> PARTITION_CONFIG (formerly BOOT_CONFIG, EXT_CSD[179]).  Part of this
>>> requires changing the check for 'part' from an strncmp to a strcmp, like
>>> the rest of the sub-commands.
> [snip]
>>> @@ -451,6 +477,8 @@ U_BOOT_CMD(
>>>  	" - Enable boot_part for booting and disable access to boot_part\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"
>>
>> How about using bracket("< >") for more readable?
>> mmc partconf <dev> <boot_ack> <boot_partition> <partition_access>
> 
> Except for bootpart-resize the rest of the mmc commands (and most in
> general) don't use "< >" around required parameters unless it's part of
> some sub-choices (such as spl export <img=atags|fdt> ...).
Thanks for explanation.

Best Regards,
Jaehoon Chung.
> 
>> Anyway, looks good to me.
> 
> Thanks!
>
diff mbox

Patch

diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c
index a322063..5842e85 100644
--- a/common/cmd_mmc.c
+++ b/common/cmd_mmc.c
@@ -195,7 +195,7 @@  static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			return 1;
 		else
 			return 0;
-	} else if (strncmp(argv[1], "part", 4) == 0) {
+	} else if (strcmp(argv[1], "part") == 0) {
 		block_dev_desc_t *mmc_dev;
 		struct mmc *mmc;
 
@@ -311,7 +311,33 @@  static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 
 		/* acknowledge to be sent during boot operation */
 		return boot_part_access(mmc, 1, part_num, access);
+	} else if (strcmp(argv[1], "partconf") == 0) {
+		int dev;
+		struct mmc *mmc;
+		u8 ack, part_num, access;
+
+		if (argc == 6) {
+			dev = simple_strtoul(argv[2], NULL, 10);
+			ack = simple_strtoul(argv[3], NULL, 10);
+			part_num = simple_strtoul(argv[4], NULL, 10);
+			access = simple_strtoul(argv[5], NULL, 10);
+		} else {
+			return CMD_RET_USAGE;
+		}
+
+		mmc = find_mmc_device(dev);
+		if (!mmc) {
+			printf("no mmc device at slot %x\n", dev);
+			return 1;
+		}
 
+		if (IS_SD(mmc)) {
+			puts("PARTITION_CONFIG only exists on eMMC\n");
+			return 1;
+		}
+
+		/* acknowledge to be sent during boot operation */
+		return mmc_set_part_conf(mmc, ack, part_num, access);
 	} else if (strcmp(argv[1], "bootpart-resize") == 0) {
 		int dev;
 		struct mmc *mmc;
@@ -451,6 +477,8 @@  U_BOOT_CMD(
 	" - Enable boot_part for booting and disable access to boot_part\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"
 #endif
 	"mmc setdsr - set DSR register value\n"
 	);
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index c6a1c23..1591fce 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1505,4 +1505,25 @@  int mmc_boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
 	}
 	return 0;
 }
+
+/*
+ * Modify EXT_CSD[179] which is PARTITION_CONFIG (formerly BOOT_CONFIG)
+ * based on the passed in values for BOOT_ACK, BOOT_PARTITION_ENABLE and
+ * PARTITION_ACCESS.
+ *
+ * Returns 0 on success.
+ */
+int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access)
+{
+	int err;
+
+	err = 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));
+
+	if (err)
+		return err;
+	return 0;
+}
 #endif
diff --git a/include/mmc.h b/include/mmc.h
index e1060b9..7e026da 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -312,6 +312,8 @@  int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize,
 					unsigned long rpmbsize);
 /* Function to send commands to open/close the specified boot partition */
 int mmc_boot_part_access(struct mmc *mmc, u8 ack, u8 part_num, u8 access);
+/* Function to modify the PARTITION_CONFIG field of EXT_CSD */
+int mmc_set_part_conf(struct mmc *mmc, u8 ack, u8 part_num, u8 access);
 
 /**
  * Start device initialization and return immediately; it does not block on