[Uboot-stm32] [PATCH 03/11] stm32mp1: dynamically build DFU_ALT_INFO

Patrice CHOTARD patrice.chotard at st.com
Tue Apr 14 11:26:55 CEST 2020


Hi

On 3/18/20 9:22 AM, Patrick Delaunay wrote:
> This patch reduces the stm32mp1 environment size and
> builds dynamically the DFU board configuration with gpt
> and mtd partitions and information from defconfig
> (CONFIG_DFU_ALT_RAM0).
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay at st.com>
> ---


Reviewed-by: Patrice Chotard <patrice.chotard at st.com>

Patrice

>
>  board/dhelectronics/dh_stm32mp1/Kconfig |   1 +
>  board/st/common/Kconfig                 |   7 ++
>  board/st/common/stm32mp_dfu.c           | 130 +++++++++++++++++++-----
>  include/configs/stm32mp1.h              |  33 ------
>  4 files changed, 110 insertions(+), 61 deletions(-)
>
> diff --git a/board/dhelectronics/dh_stm32mp1/Kconfig b/board/dhelectronics/dh_stm32mp1/Kconfig
> index 8eab986640..69cc48f120 100644
> --- a/board/dhelectronics/dh_stm32mp1/Kconfig
> +++ b/board/dhelectronics/dh_stm32mp1/Kconfig
> @@ -18,4 +18,5 @@ config ENV_OFFSET
>  config ENV_OFFSET_REDUND
>  	default 0x1F0000 if ENV_IS_IN_SPI_FLASH
>  
> +source "board/st/common/Kconfig"
>  endif
> diff --git a/board/st/common/Kconfig b/board/st/common/Kconfig
> index af01ca4891..08df845982 100644
> --- a/board/st/common/Kconfig
> +++ b/board/st/common/Kconfig
> @@ -5,3 +5,10 @@ config CMD_STBOARD
>  	help
>  	  This compile the stboard command to
>  	  read and write the board in the OTP.
> +
> +config DFU_ALT_RAM0
> +	string "dfu for ram0"
> +	default "uImage ram 0xc2000000 0x2000000;devicetree.dtb ram 0xc4000000 0x100000;uramdisk.image.gz ram 0xc4400000 0x10000000"
> +	depends on ARCH_STM32MP && SET_DFU_ALT_INFO
> +	help
> +	  This defines the partitions of ram used to build dfu dynamically.
> diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c
> index 99ea21ce15..e129f8c8b5 100644
> --- a/board/st/common/stm32mp_dfu.c
> +++ b/board/st/common/stm32mp_dfu.c
> @@ -4,6 +4,7 @@
>   */
>  
>  #include <common.h>
> +#include <blk.h>
>  #include <dfu.h>
>  #include <env.h>
>  #include <memalign.h>
> @@ -13,20 +14,86 @@
>  
>  #define DFU_ALT_BUF_LEN SZ_1K
>  
> -static void board_get_alt_info(const char *dev, char *buff)
> +static void board_get_alt_info_mmc(struct udevice *dev, char *buf)
>  {
> -	char var_name[32] = "dfu_alt_info_";
> -	int ret;
> +	disk_partition_t info;
> +	int p, len, devnum;
> +	bool first = true;
> +	const char *name;
> +	struct mmc *mmc;
> +	struct blk_desc *desc;
> +
> +	mmc = mmc_get_mmc_dev(dev);
> +	if (!mmc)
> +		return;
> +
> +	if (mmc_init(mmc))
> +		return;
> +
> +	desc = mmc_get_blk_desc(mmc);
> +	if (!desc)
> +		return;
> +
> +	name = blk_get_if_type_name(desc->if_type);
> +	devnum = desc->devnum;
> +	len = strlen(buf);
> +
> +	if (buf[0] != '\0')
> +		len += snprintf(buf + len,
> +				DFU_ALT_BUF_LEN - len, "&");
> +	len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
> +			 "%s %d=", name, devnum);
> +
> +	if (IS_MMC(mmc) && mmc->capacity_boot) {
> +		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
> +				"%s%d_boot1 raw 0x0 0x%llx mmcpart 1;",
> +				name, devnum, mmc->capacity_boot);
> +		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
> +				"%s%d_boot2 raw 0x0 0x%llx mmcpart 2",
> +				name, devnum, mmc->capacity_boot);
> +		first = false;
> +	}
>  
> -	ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN);
> +	for (p = 1; p < MAX_SEARCH_PARTITIONS; p++) {
> +		if (part_get_info(desc, p, &info))
> +			continue;
> +		if (!first)
> +			len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, ";");
> +		first = false;
> +		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
> +				"%s%d_%s part %d %d",
> +				name, devnum, info.name, devnum, p);
> +	}
> +}
>  
> -	/* name of env variable to read = dfu_alt_info_<dev> */
> -	strcat(var_name, dev);
> -	ret = env_get_f(var_name, tmp_alt, DFU_ALT_BUF_LEN);
> -	if (ret) {
> -		if (buff[0] != '\0')
> -			strcat(buff, "&");
> -		strncat(buff, tmp_alt, DFU_ALT_BUF_LEN);
> +static void board_get_alt_info_mtd(struct mtd_info *mtd, char *buf)
> +{
> +	struct mtd_info *part;
> +	bool first = true;
> +	const char *name;
> +	int len, partnum = 0;
> +
> +	name = mtd->name;
> +	len = strlen(buf);
> +
> +	if (buf[0] != '\0')
> +		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, "&");
> +	len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
> +			"mtd %s=", name);
> +
> +	len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
> +			"%s raw 0x0 0x%llx ",
> +			name, mtd->size);
> +
> +	list_for_each_entry(part, &mtd->partitions, node) {
> +		partnum++;
> +		if (!first)
> +			len += snprintf(buf + len, DFU_ALT_BUF_LEN - len, ";");
> +		first = false;
> +
> +		len += snprintf(buf + len, DFU_ALT_BUF_LEN - len,
> +				"%s_%s part %d",
> +				name, part->name, partnum);
>  	}
>  }
>  
> @@ -42,27 +109,34 @@ void set_dfu_alt_info(char *interface, char *devstr)
>  
>  	memset(buf, 0, sizeof(buf));
>  
> -	/* probe all MTD devices */
> -	mtd_probe_devices();
> -
> -	board_get_alt_info("ram", buf);
> +	snprintf(buf, DFU_ALT_BUF_LEN,
> +		 "ram 0=%s", CONFIG_DFU_ALT_RAM0);
>  
>  	if (!uclass_get_device(UCLASS_MMC, 0, &dev))
> -		board_get_alt_info("mmc0", buf);
> +		board_get_alt_info_mmc(dev, buf);
>  
>  	if (!uclass_get_device(UCLASS_MMC, 1, &dev))
> -		board_get_alt_info("mmc1", buf);
> -
> -	if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
> -		board_get_alt_info("nor0", buf);
> -
> -	mtd = get_mtd_device_nm("nand0");
> -	if (!IS_ERR_OR_NULL(mtd))
> -		board_get_alt_info("nand0", buf);
> -
> -	mtd = get_mtd_device_nm("spi-nand0");
> -	if (!IS_ERR_OR_NULL(mtd))
> -		board_get_alt_info("spi-nand0", buf);
> +		board_get_alt_info_mmc(dev, buf);
> +
> +	if (CONFIG_IS_ENABLED(MTD)) {
> +		/* probe all MTD devices */
> +		mtd_probe_devices();
> +
> +		/* probe SPI flash device on a bus */
> +		if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) {
> +			mtd = get_mtd_device_nm("nor0");
> +			if (!IS_ERR_OR_NULL(mtd))
> +				board_get_alt_info_mtd(mtd, buf);
> +		}
> +
> +		mtd = get_mtd_device_nm("nand0");
> +		if (!IS_ERR_OR_NULL(mtd))
> +			board_get_alt_info_mtd(mtd, buf);
> +
> +		mtd = get_mtd_device_nm("spi-nand0");
> +		if (!IS_ERR_OR_NULL(mtd))
> +			board_get_alt_info_mtd(mtd, buf);
> +	}
>  
>  #ifdef CONFIG_DFU_VIRT
>  	strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN);
> diff --git a/include/configs/stm32mp1.h b/include/configs/stm32mp1.h
> index f451edad36..a9631d2a92 100644
> --- a/include/configs/stm32mp1.h
> +++ b/include/configs/stm32mp1.h
> @@ -170,37 +170,6 @@
>  #define STM32MP_MTDPARTS
>  #endif
>  
> -#define STM32MP_DFU_ALT_RAM \
> -	"dfu_alt_info_ram=ram 0=" \
> -		"uImage ram ${kernel_addr_r} 0x2000000;" \
> -		"devicetree.dtb ram ${fdt_addr_r} 0x100000;" \
> -		"uramdisk.image.gz ram ${ramdisk_addr_r} 0x10000000\0"
> -
> -#ifdef CONFIG_SET_DFU_ALT_INFO
> -#define STM32MP_DFU_ALT_INFO \
> -	"dfu_alt_info_nor0=mtd nor0=" \
> -		"nor_fsbl1 part 1;nor_fsbl2 part 2;" \
> -		"nor_ssbl part 3;nor_env part 4\0" \
> -	"dfu_alt_info_nand0=mtd nand0="\
> -		"nand_fsbl part 1;nand_ssbl1 part 2;" \
> -		"nand_ssbl2 part 3;nand_UBI partubi 4\0" \
> -	"dfu_alt_info_spi-nand0=mtd spi-nand0="\
> -		"spi-nand_fsbl part 1;spi-nand_ssbl1 part 2;" \
> -		"spi-nand_ssbl2 part 3;spi-nand_UBI partubi 4\0" \
> -	"dfu_alt_info_mmc0=mmc 0=" \
> -		"sdcard_fsbl1 part 0 1;sdcard_fsbl2 part 0 2;" \
> -		"sdcard_ssbl part 0 3;sdcard_bootfs part 0 4;" \
> -		"sdcard_vendorfs part 0 5;sdcard_rootfs part 0 6;" \
> -		"sdcard_userfs part 0 7\0" \
> -	"dfu_alt_info_mmc1=mmc 1=" \
> -		"emmc_fsbl1 raw 0x0 0x200 mmcpart 1;" \
> -		"emmc_fsbl2 raw 0x0 0x200 mmcpart 2;emmc_ssbl part 1 1;" \
> -		"emmc_bootfs part 1 2;emmc_vendorfs part 1 3;" \
> -		"emmc_rootfs part 1 4;emmc_userfs part 1 5\0"
> -#else
> -#define STM32MP_DFU_ALT_INFO
> -#endif
> -
>  /*
>   * memory layout for 32M uncompressed/compressed kernel,
>   * 1M fdt, 1M script, 1M pxe and 1M for splashimage
> @@ -220,8 +189,6 @@
>  		" then env set env_default 0;env save;fi\0" \
>  	STM32MP_BOOTCMD \
>  	STM32MP_MTDPARTS \
> -	STM32MP_DFU_ALT_RAM \
> -	STM32MP_DFU_ALT_INFO \
>  	BOOTENV \
>  	"boot_net_usb_start=true\0"
>  


More information about the U-Boot mailing list