[PATCH 03/10] stm32mp: stm32prog: add support of initrd in flashlayout

Patrice CHOTARD patrice.chotard at foss.st.com
Fri May 28 14:53:30 CEST 2021


HI Patrick

On 5/18/21 3:12 PM, Patrick Delaunay wrote:
> Add the support in command stm32prog of kernel load and start
> with initrd file, identify by the partition Type "Binary" in
> the flashlayout.tsv, for example:
> 
> - 0x01 fsbl	Binary none 0x0 tfa.stm32
> - 0x03 fip	Binary none 0x0 fip.bin
> P 0x10 kernel System ram0 0xC2000000 uImage.bin
> P 0x11 dtb FileSystem ram0 0xC4000000 board.dtb
> P 0x12 initrd Binary ram0 0xC4400000 <initrd>
> 
> The <initrd> file can be a legacy image "uInitrd", generated
> with mkimage, or a RAW initrd image "initrd.gz".
> 
> After a DFU detach the bootm command with be executed
> with the associated address, for example:
> 
> $> bootm 0xC2000000 0xC4400000:<size> 0xC4000000
> 
> When the "Binary" partition type is absent, the 'bootm'
> command starts the kernel without ramdisk, for example:
> 
> $> bootm 0xC2000000 - 0xC4000000
> 
> With this paths, it is no more mandatory to generate FIT
> including the kernel, DT and initrd:
> 
> - 0x01 fsbl Binary none 0x0 tfa.stm32
> - 0x03 fip Binary none 0x0 fip.bin
> P 0x10 fit System ram0 0xC2000000 fit.bin
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay at foss.st.com>
> ---
> 
>  .../cmd_stm32prog/cmd_stm32prog.c             | 22 +++++++++++++------
>  .../mach-stm32mp/cmd_stm32prog/stm32prog.c    | 10 ++++++---
>  .../mach-stm32mp/cmd_stm32prog/stm32prog.h    |  2 ++
>  3 files changed, 24 insertions(+), 10 deletions(-)
> 
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
> index e36501a86b..e584bb52bd 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/cmd_stm32prog.c
> @@ -45,7 +45,6 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
>  	bool reset = false;
>  	struct image_header_s header;
>  	struct stm32prog_data *data;
> -	u32 uimage, dtb;
>  
>  	if (argc < 3 ||  argc > 5)
>  		return CMD_RET_USAGE;
> @@ -119,21 +118,23 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
>  		goto cleanup;
>  	}
>  
> -	uimage = data->uimage;
> -	dtb = data->dtb;
> -
>  	stm32prog_clean(data);
>  	free(stm32prog_data);
>  	stm32prog_data = NULL;
>  
>  	puts("Download done\n");
>  
> -	if (uimage) {
> +	if (data->uimage) {
>  		char boot_addr_start[20];
>  		char dtb_addr[20];
> +		char initrd_addr[40];
>  		char *bootm_argv[5] = {
>  			"bootm", boot_addr_start, "-", dtb_addr, NULL
>  		};
> +		u32 uimage = data->uimage;
> +		u32 dtb = data->dtb;
> +		u32 initrd = data->initrd;
> +
>  		if (!dtb)
>  			bootm_argv[3] = env_get("fdtcontroladdr");
>  		else
> @@ -142,8 +143,15 @@ static int do_stm32prog(struct cmd_tbl *cmdtp, int flag, int argc,
>  
>  		snprintf(boot_addr_start, sizeof(boot_addr_start) - 1,
>  			 "0x%x", uimage);
> -		printf("Booting kernel at %s - %s...\n\n\n",
> -		       boot_addr_start, bootm_argv[3]);
> +
> +		if (initrd) {
> +			snprintf(initrd_addr, sizeof(initrd_addr) - 1, "0x%x:0x%x",
> +				 initrd, data->initrd_size);
> +			bootm_argv[2] = initrd_addr;
> +		}
> +
> +		printf("Booting kernel at %s %s %s...\n\n\n",
> +		       boot_addr_start, bootm_argv[2], bootm_argv[3]);
>  		/* Try bootm for legacy and FIT format image */
>  		if (genimg_get_format((void *)uimage) != IMAGE_FORMAT_INVALID)
>  			do_bootm(cmdtp, 0, 4, bootm_argv);
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
> index 84b880261a..ea69d5dd16 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c
> @@ -1473,7 +1473,7 @@ error:
>  	return ret;
>  }
>  
> -static void stm32prog_end_phase(struct stm32prog_data *data)
> +static void stm32prog_end_phase(struct stm32prog_data *data, u64 offset)
>  {
>  	if (data->phase == PHASE_FLASHLAYOUT) {
>  		if (parse_flash_layout(data, STM32_DDR_BASE, 0))
> @@ -1489,6 +1489,10 @@ static void stm32prog_end_phase(struct stm32prog_data *data)
>  			data->uimage = data->cur_part->addr;
>  		if (data->cur_part->part_type == PART_FILESYSTEM)
>  			data->dtb = data->cur_part->addr;
> +		if (data->cur_part->part_type == PART_BINARY) {
> +			data->initrd = data->cur_part->addr;
> +			data->initrd_size = offset;
> +		}
>  	}
>  
>  	if (CONFIG_IS_ENABLED(MMC) &&
> @@ -1747,7 +1751,7 @@ void dfu_flush_callback(struct dfu_entity *dfu)
>  	if (dfu->dev_type == DFU_DEV_RAM) {
>  		if (dfu->alt == 0 &&
>  		    stm32prog_data->phase == PHASE_FLASHLAYOUT) {
> -			stm32prog_end_phase(stm32prog_data);
> +			stm32prog_end_phase(stm32prog_data, dfu->offset);
>  			/* waiting DFU DETACH for reenumeration */
>  		}
>  	}
> @@ -1756,7 +1760,7 @@ void dfu_flush_callback(struct dfu_entity *dfu)
>  		return;
>  
>  	if (dfu->alt == stm32prog_data->cur_part->alt_id) {
> -		stm32prog_end_phase(stm32prog_data);
> +		stm32prog_end_phase(stm32prog_data, dfu->offset);
>  		stm32prog_next_phase(stm32prog_data);
>  	}
>  }
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h
> index ad404879a7..efb51a3022 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h
> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.h
> @@ -142,6 +142,8 @@ struct stm32prog_data {
>  	/* bootm information */
>  	u32	uimage;
>  	u32	dtb;
> +	u32	initrd;
> +	u32	initrd_size;
>  };
>  
>  extern struct stm32prog_data *stm32prog_data;
> 

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

Thanks
Patrice


More information about the U-Boot mailing list