diff mbox series

cmd: mmc: Consider GP partitions in mmc hwpartition user enh start -

Message ID 20220117215429.88037-1-marex@denx.de
State Accepted
Commit 1d4b3b2fcb8584a531626684782778cd792f072f
Delegated to: Jaehoon Chung
Headers show
Series cmd: mmc: Consider GP partitions in mmc hwpartition user enh start - | expand

Commit Message

Marek Vasut Jan. 17, 2022, 9:54 p.m. UTC
In case the eMMC contains any GP partitions or user sets up new GP
partitions, the size of these GP partitions reduce the size of the
USER partition. Subtract the size of those GP partitions from the
calculated size of USER partition when using `user enh start -`.

The following test used to fail before:
```
u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
Partition configuration:
        User Enhanced Start: 0 Bytes
        User Enhanced Size: 1.8 GiB
        User partition write reliability: on
        GP1 Capacity: 256 MiB ENH
        No GP2 partition
        No GP3 partition
        No GP4 partition
Total enhanced size exceeds maximum (261 > 229)
Failed!
```
The test now passes:
```
u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
Partition configuration:
        User Enhanced Start: 0 Bytes
        User Enhanced Size: 1.5 GiB
        User partition write reliability: on
        GP1 Capacity: 256 MiB ENH
        No GP2 partition
        No GP3 partition
        No GP4 partition
```

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Jaehoon Chung <jh80.chung@samsung.com>
Cc: Peng Fan <peng.fan@nxp.com>
Cc: Stefano Babic <sbabic@denx.de>
---
 cmd/mmc.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

Comments

Fabio Estevam Jan. 20, 2022, 11:14 a.m. UTC | #1
Hi Marek,

On Mon, Jan 17, 2022 at 6:54 PM Marek Vasut <marex@denx.de> wrote:
>
> In case the eMMC contains any GP partitions or user sets up new GP
> partitions, the size of these GP partitions reduce the size of the
> USER partition. Subtract the size of those GP partitions from the
> calculated size of USER partition when using `user enh start -`.
>
> The following test used to fail before:
> ```
> u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
> Partition configuration:
>         User Enhanced Start: 0 Bytes
>         User Enhanced Size: 1.8 GiB
>         User partition write reliability: on
>         GP1 Capacity: 256 MiB ENH
>         No GP2 partition
>         No GP3 partition
>         No GP4 partition
> Total enhanced size exceeds maximum (261 > 229)
> Failed!
> ```
> The test now passes:
> ```
> u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
> Partition configuration:
>         User Enhanced Start: 0 Bytes
>         User Enhanced Size: 1.5 GiB
>         User partition write reliability: on
>         GP1 Capacity: 256 MiB ENH
>         No GP2 partition
>         No GP3 partition
>         No GP4 partition
> ```
>
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Stefano Babic <sbabic@denx.de>

Reviewed-by: Fabio Estevam <festevam@gmail.com>
Jaehoon Chung Jan. 26, 2022, 11:16 p.m. UTC | #2
On 1/18/22 06:54, Marek Vasut wrote:
> In case the eMMC contains any GP partitions or user sets up new GP
> partitions, the size of these GP partitions reduce the size of the
> USER partition. Subtract the size of those GP partitions from the
> calculated size of USER partition when using `user enh start -`.
> 
> The following test used to fail before:
> ```
> u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
> Partition configuration:
>         User Enhanced Start: 0 Bytes
>         User Enhanced Size: 1.8 GiB
>         User partition write reliability: on
>         GP1 Capacity: 256 MiB ENH
>         No GP2 partition
>         No GP3 partition
>         No GP4 partition
> Total enhanced size exceeds maximum (261 > 229)
> Failed!
> ```
> The test now passes:
> ```
> u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
> Partition configuration:
>         User Enhanced Start: 0 Bytes
>         User Enhanced Size: 1.5 GiB
>         User partition write reliability: on
>         GP1 Capacity: 256 MiB ENH
>         No GP2 partition
>         No GP3 partition
>         No GP4 partition
> ```
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Jaehoon Chung <jh80.chung@samsung.com>
> Cc: Peng Fan <peng.fan@nxp.com>
> Cc: Stefano Babic <sbabic@denx.de>

Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

Best Regards,
Jaehoon Chung

> ---
>  cmd/mmc.c | 22 ++++++++++++++++++++--
>  1 file changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/cmd/mmc.c b/cmd/mmc.c
> index 96d81ffdf36..503dbb6199c 100644
> --- a/cmd/mmc.c
> +++ b/cmd/mmc.c
> @@ -597,7 +597,7 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc,
>  				       struct mmc_hwpart_conf *pconf,
>  				       char *argv)
>  {
> -	int ret;
> +	int i, ret;
>  
>  	pconf->user.enh_size = 0;
>  
> @@ -606,7 +606,7 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc,
>  		ret = mmc_send_ext_csd(mmc, ext_csd);
>  		if (ret)
>  			return;
> -		/* This value is in 512B block units */
> +		/* The enh_size value is in 512B block units */
>  		pconf->user.enh_size =
>  			((ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16) +
>  			(ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) +
> @@ -614,6 +614,24 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc,
>  			ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] *
>  			ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>  		pconf->user.enh_size -= pconf->user.enh_start;
> +		for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
> +			/*
> +			 * If the eMMC already has GP partitions set,
> +			 * subtract their size from the maximum USER
> +			 * partition size.
> +			 *
> +			 * Else, if the command was used to configure new
> +			 * GP partitions, subtract their size from maximum
> +			 * USER partition size.
> +			 */
> +			if (mmc->capacity_gp[i]) {
> +				/* The capacity_gp is in 1B units */
> +				pconf->user.enh_size -= mmc->capacity_gp[i] >> 9;
> +			} else if (pconf->gp_part[i].size) {
> +				/* The gp_part[].size is in 512B units */
> +				pconf->user.enh_size -= pconf->gp_part[i].size;
> +			}
> +		}
>  	} else {
>  		pconf->user.enh_size = dectoul(argv, NULL);
>  	}
Jaehoon Chung Feb. 8, 2022, 11:38 p.m. UTC | #3
On 1/27/22 08:16, Jaehoon Chung wrote:
> On 1/18/22 06:54, Marek Vasut wrote:
>> In case the eMMC contains any GP partitions or user sets up new GP
>> partitions, the size of these GP partitions reduce the size of the
>> USER partition. Subtract the size of those GP partitions from the
>> calculated size of USER partition when using `user enh start -`.
>>
>> The following test used to fail before:
>> ```
>> u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
>> Partition configuration:
>>         User Enhanced Start: 0 Bytes
>>         User Enhanced Size: 1.8 GiB
>>         User partition write reliability: on
>>         GP1 Capacity: 256 MiB ENH
>>         No GP2 partition
>>         No GP3 partition
>>         No GP4 partition
>> Total enhanced size exceeds maximum (261 > 229)
>> Failed!
>> ```
>> The test now passes:
>> ```
>> u-boot=> mmc hwpartition gp1 524288 enh user enh 0 - wrrel on check
>> Partition configuration:
>>         User Enhanced Start: 0 Bytes
>>         User Enhanced Size: 1.5 GiB
>>         User partition write reliability: on
>>         GP1 Capacity: 256 MiB ENH
>>         No GP2 partition
>>         No GP3 partition
>>         No GP4 partition
>> ```
>>
>> Signed-off-by: Marek Vasut <marex@denx.de>
>> Cc: Fabio Estevam <festevam@gmail.com>
>> Cc: Jaehoon Chung <jh80.chung@samsung.com>
>> Cc: Peng Fan <peng.fan@nxp.com>
>> Cc: Stefano Babic <sbabic@denx.de>
> 
> Reviewed-by: Jaehoon Chung <jh80.chung@samsung.com>

Applied on u-boot-mmc/master.

Thanks!

Best Regards,
Jaehoon Chung

> 
> Best Regards,
> Jaehoon Chung
> 
>> ---
>>  cmd/mmc.c | 22 ++++++++++++++++++++--
>>  1 file changed, 20 insertions(+), 2 deletions(-)
>>
>> diff --git a/cmd/mmc.c b/cmd/mmc.c
>> index 96d81ffdf36..503dbb6199c 100644
>> --- a/cmd/mmc.c
>> +++ b/cmd/mmc.c
>> @@ -597,7 +597,7 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc,
>>  				       struct mmc_hwpart_conf *pconf,
>>  				       char *argv)
>>  {
>> -	int ret;
>> +	int i, ret;
>>  
>>  	pconf->user.enh_size = 0;
>>  
>> @@ -606,7 +606,7 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc,
>>  		ret = mmc_send_ext_csd(mmc, ext_csd);
>>  		if (ret)
>>  			return;
>> -		/* This value is in 512B block units */
>> +		/* The enh_size value is in 512B block units */
>>  		pconf->user.enh_size =
>>  			((ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16) +
>>  			(ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) +
>> @@ -614,6 +614,24 @@ static void parse_hwpart_user_enh_size(struct mmc *mmc,
>>  			ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] *
>>  			ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>  		pconf->user.enh_size -= pconf->user.enh_start;
>> +		for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
>> +			/*
>> +			 * If the eMMC already has GP partitions set,
>> +			 * subtract their size from the maximum USER
>> +			 * partition size.
>> +			 *
>> +			 * Else, if the command was used to configure new
>> +			 * GP partitions, subtract their size from maximum
>> +			 * USER partition size.
>> +			 */
>> +			if (mmc->capacity_gp[i]) {
>> +				/* The capacity_gp is in 1B units */
>> +				pconf->user.enh_size -= mmc->capacity_gp[i] >> 9;
>> +			} else if (pconf->gp_part[i].size) {
>> +				/* The gp_part[].size is in 512B units */
>> +				pconf->user.enh_size -= pconf->gp_part[i].size;
>> +			}
>> +		}
>>  	} else {
>>  		pconf->user.enh_size = dectoul(argv, NULL);
>>  	}
> 
>
diff mbox series

Patch

diff --git a/cmd/mmc.c b/cmd/mmc.c
index 96d81ffdf36..503dbb6199c 100644
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
@@ -597,7 +597,7 @@  static void parse_hwpart_user_enh_size(struct mmc *mmc,
 				       struct mmc_hwpart_conf *pconf,
 				       char *argv)
 {
-	int ret;
+	int i, ret;
 
 	pconf->user.enh_size = 0;
 
@@ -606,7 +606,7 @@  static void parse_hwpart_user_enh_size(struct mmc *mmc,
 		ret = mmc_send_ext_csd(mmc, ext_csd);
 		if (ret)
 			return;
-		/* This value is in 512B block units */
+		/* The enh_size value is in 512B block units */
 		pconf->user.enh_size =
 			((ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16) +
 			(ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) +
@@ -614,6 +614,24 @@  static void parse_hwpart_user_enh_size(struct mmc *mmc,
 			ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] *
 			ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
 		pconf->user.enh_size -= pconf->user.enh_start;
+		for (i = 0; i < ARRAY_SIZE(mmc->capacity_gp); i++) {
+			/*
+			 * If the eMMC already has GP partitions set,
+			 * subtract their size from the maximum USER
+			 * partition size.
+			 *
+			 * Else, if the command was used to configure new
+			 * GP partitions, subtract their size from maximum
+			 * USER partition size.
+			 */
+			if (mmc->capacity_gp[i]) {
+				/* The capacity_gp is in 1B units */
+				pconf->user.enh_size -= mmc->capacity_gp[i] >> 9;
+			} else if (pconf->gp_part[i].size) {
+				/* The gp_part[].size is in 512B units */
+				pconf->user.enh_size -= pconf->gp_part[i].size;
+			}
+		}
 	} else {
 		pconf->user.enh_size = dectoul(argv, NULL);
 	}