[EXT] [PATCH 2/2] arm: mvebu: Espressobin: Setup MTD partitions when booting kernel

Kostya Porotchkin kostap at marvell.com
Wed Aug 19 20:01:02 CEST 2020



> -----Original Message-----
> From: Pali Rohár <pali at kernel.org>
> Sent: Wednesday, August 19, 2020 17:24
> To: Stefan Roese <sr at denx.de>; Kostya Porotchkin <kostap at marvell.com>
> Cc: u-boot at lists.denx.de
> Subject: [EXT] [PATCH 2/2] arm: mvebu: Espressobin: Setup MTD partitions
> when booting kernel
> 
> External Email
> 
> ----------------------------------------------------------------------
> Due to different partition layouts in different U-Boot versions, DTS for
> Espressobin in Linux does not contain any definition of MTD partitions.
> See commit https://urldefense.proofpoint.com/v2/url?u=https-
> 3A__git.kernel.org_stable_c_00954566464a4&d=DwIDaQ&c=nKjWec2b6R0m
> OyPaz7xtfQ&r=-
> N9sN4p5NSr0JGQoQ_2UCOgAqajG99W1EbSOww0WU8o&m=EH2hF8LOBbgZ
> NUxvBwhhmIe2uzWWEa_eJ3vAmWPxqmo&s=ei6YI15fI5FM73Z6537XKz_p9
> p3nx9nT7qiUvg2o_tU&e=  for more details.
> 
> This patch via ft_board_setup() hook fills current partition layout used by U-
> Boot, so booted kernel would see correct MTD partitions layout.
> 
> U-Boot env partition is calculated from CONFIG_ENV_OFFSET option.
> 
> First partition contains secure firmware, ARM trusted firmware and U-Boot
> with checksums. So it is not possible to replace just one image (e.g.
> U-Boot) without updating other parts where is stored checksum of U-Boot.
> Therefore there is no extra partition defined for U-Boot and first partition is
> called just 'firmware'.
> 
> Signed-off-by: Pali Rohár <pali at kernel.org>
Reviewed-by: Konstantin Porotchkin <kostap at marvell.com>

> ---
>  board/Marvell/mvebu_armada-37xx/board.c     | 100
> ++++++++++++++++++++
>  configs/mvebu_espressobin-88f3720_defconfig |   1 +
>  2 files changed, 101 insertions(+)
> 
> diff --git a/board/Marvell/mvebu_armada-37xx/board.c
> b/board/Marvell/mvebu_armada-37xx/board.c
> index 031de318c6..7b9c3223ed 100644
> --- a/board/Marvell/mvebu_armada-37xx/board.c
> +++ b/board/Marvell/mvebu_armada-37xx/board.c
> @@ -243,3 +243,103 @@ int board_network_enable(struct mii_dev *bus)
> 
>  	return 0;
>  }
> +
> +#if defined(CONFIG_OF_BOARD_SETUP) &&
> +defined(CONFIG_ENV_IS_IN_SPI_FLASH)
> +int ft_board_setup(void *blob, struct bd_info *bd) {
> +	int ret;
> +	int spi_off;
> +	int parts_off;
> +	int part_off;
> +
> +	/* Fill SPI MTD partitions for Linux kernel on Espressobin */
> +	if (!of_machine_is_compatible("marvell,armada-3720-espressobin"))
> +		return 0;
> +
> +	spi_off = fdt_node_offset_by_compatible(blob, -1, "jedec,spi-nor");
> +	if (spi_off < 0)
> +		return 0;
> +
> +	/* Do not touch partitions if they are already defined */
> +	if (fdt_subnode_offset(blob, spi_off, "partitions") >= 0)
> +		return 0;
> +
> +	parts_off = fdt_add_subnode(blob, spi_off, "partitions");
> +	if (parts_off < 0) {
> +		printf("Can't add partitions node: %s\n",
> fdt_strerror(parts_off));
> +		return 0;
> +	}
> +
> +	ret = fdt_setprop_string(blob, parts_off, "compatible", "fixed-
> partitions");
> +	if (ret < 0) {
> +		printf("Can't set compatible property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	ret = fdt_setprop_u32(blob, parts_off, "#address-cells", 1);
> +	if (ret < 0) {
> +		printf("Can't set #address-cells property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	ret = fdt_setprop_u32(blob, parts_off, "#size-cells", 1);
> +	if (ret < 0) {
> +		printf("Can't set #size-cells property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	/* Add u-boot-env partition */
> +
> +	part_off = fdt_add_subnode(blob, parts_off, "partition at u-boot-
> env");
> +	if (part_off < 0) {
> +		printf("Can't add partition at u-boot-env node: %s\n",
> fdt_strerror(part_off));
> +		return 0;
> +	}
> +
> +	ret = fdt_setprop_u32(blob, part_off, "reg", CONFIG_ENV_OFFSET);
> +	if (ret < 0) {
> +		printf("Can't set partition at u-boot-env reg property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	ret = fdt_appendprop_u32(blob, part_off, "reg",
> CONFIG_ENV_SIZE);
> +	if (ret < 0) {
> +		printf("Can't set partition at u-boot-env reg property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	ret = fdt_setprop_string(blob, part_off, "label", "u-boot-env");
> +	if (ret < 0) {
> +		printf("Can't set partition at u-boot-env label property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	/* Add firmware partition */
> +
> +	part_off = fdt_add_subnode(blob, parts_off, "partition at firmware");
> +	if (part_off < 0) {
> +		printf("Can't add partition at firmware node: %s\n",
> fdt_strerror(part_off));
> +		return 0;
> +	}
> +
> +	ret = fdt_setprop_u32(blob, part_off, "reg", 0);
> +	if (ret < 0) {
> +		printf("Can't set partition at firmware reg property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	ret = fdt_appendprop_u32(blob, part_off, "reg",
> CONFIG_ENV_OFFSET);
> +	if (ret < 0) {
> +		printf("Can't set partition at firmware reg property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	ret = fdt_setprop_string(blob, part_off, "label", "firmware");
> +	if (ret < 0) {
> +		printf("Can't set partition at firmware label property: %s\n",
> fdt_strerror(ret));
> +		return 0;
> +	}
> +
> +	return 0;
> +}
> +#endif
> diff --git a/configs/mvebu_espressobin-88f3720_defconfig
> b/configs/mvebu_espressobin-88f3720_defconfig
> index afcdd947c1..0c1c92d4ff 100644
> --- a/configs/mvebu_espressobin-88f3720_defconfig
> +++ b/configs/mvebu_espressobin-88f3720_defconfig
> @@ -82,3 +82,4 @@ CONFIG_SHA1=y
>  CONFIG_SHA256=y
>  CONFIG_MVNETA=y
>  CONFIG_DM_REGULATOR_GPIO=y
> +CONFIG_OF_BOARD_SETUP=y
> --
> 2.20.1



More information about the U-Boot mailing list