[PATCH u-boot 2/4] cmd: mvebu/bubt: Validate EXT_CSD[179] eMMC register in mmc_burn_image()

Pali Rohár pali at kernel.org
Mon Apr 17 09:05:20 CEST 2023


+ Martin

On Thursday 13 April 2023 23:10:55 Pali Rohár wrote:
> When determining eMMC boot partition for a bootloader, validate that
> EXT_CSD[179] eMMC register is set to recognized value.
> 
> This prevent situation that EXT_CSD[179] Boot Enable value is improperly
> parsed and passed into EXT_CSD[179] Partition Access.
> 
> Signed-off-by: Pali Rohár <pali at kernel.org>
> ---
>  cmd/mvebu/bubt.c | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
> 
> diff --git a/cmd/mvebu/bubt.c b/cmd/mvebu/bubt.c
> index ca24a5c1c4ba..b8fe7c7a1461 100644
> --- a/cmd/mvebu/bubt.c
> +++ b/cmd/mvebu/bubt.c
> @@ -223,9 +223,29 @@ static int mmc_burn_image(size_t image_size)
>  	orig_part = mmc->block_dev.hwpart;
>  #endif
>  
> -	part = EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config);
> -	if (part == 7)
> +	if (mmc->part_config == MMCPART_NOAVAILABLE) {
>  		part = 0;
> +	} else {
> +		switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
> +		case 0: /* Booting from this eMMC device is disabled */
> +			printf("Error - Booting from this eMMC device is disabled\n");
> +			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
> +			return -ENODEV;
> +		case 1: /* Boot partition 1 is used for booting */
> +			part = 1;
> +			break;
> +		case 2: /* Boot partition 2 is used for booting */
> +			part = 2;
> +			break;
> +		case 7: /* User area is used for booting */
> +			part = 0;
> +			break;
> +		default: /* Other values are reserved / unsupported */
> +			printf("Error - This eMMC device has configured Reserved boot option\n");
> +			printf("Hint: Use 'mmc partconf' command to choose boot partition\n");
> +			return -ENODEV;
> +		}
> +	}
>  
>  #ifdef CONFIG_BLK
>  	err = blk_dselect_hwpart(blk_desc, part);
> -- 
> 2.20.1
> 


More information about the U-Boot mailing list