From ec1ee5a9272f1393caf5275309cd08cf48e49dd0 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 22 Apr 2020 13:18:09 +0200 Subject: ARM: stm32: Add default config for DHCOR Add default U-Boot configuration for the DHCOR SoM on AV96 board. Reviewed-by: Patrick Delaunay Signed-off-by: Marek Vasut Cc: Manivannan Sadhasivam Cc: Patrick Delaunay Cc: Patrice Chotard --- board/dhelectronics/dh_stm32mp1/MAINTAINERS | 1 + 1 file changed, 1 insertion(+) (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/MAINTAINERS b/board/dhelectronics/dh_stm32mp1/MAINTAINERS index 1511ecb65dc..fd70131f9e6 100644 --- a/board/dhelectronics/dh_stm32mp1/MAINTAINERS +++ b/board/dhelectronics/dh_stm32mp1/MAINTAINERS @@ -4,4 +4,5 @@ S: Maintained F: arch/arm/dts/stm32mp15xx-dhcom* F: board/dhelectronics/dh_stm32mp1/ F: configs/stm32mp15_dhcom_basic_defconfig +F: configs/stm32mp15_dhcor_basic_defconfig F: include/configs/stm32mp1.h -- cgit v1.2.3 From 731fd50e27fb3e9e55eb508cebebc7a111616a30 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 22 Apr 2020 13:18:11 +0200 Subject: ARM: stm32: Implement board coding on AV96 The AV96 board does exist in multiple variants. To cater for all of them, implement board code handling. There are two GPIOs which code the type of the board, read them out and use the value to pick the correct device tree from an fitImage. Reviewed-by: Patrick Delaunay Signed-off-by: Marek Vasut Cc: Manivannan Sadhasivam Cc: Patrick Delaunay Cc: Patrice Chotard Change-Id: Iddb330b9a66500495885457cbe17edc0eacaaf43 --- board/dhelectronics/dh_stm32mp1/Kconfig | 2 +- board/dhelectronics/dh_stm32mp1/board.c | 61 ++++++++++++++++++++++++ board/dhelectronics/dh_stm32mp1/u-boot-dhcom.its | 39 +++++++++++++++ board/dhelectronics/dh_stm32mp1/u-boot-dhcor.its | 39 +++++++++++++++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 board/dhelectronics/dh_stm32mp1/u-boot-dhcom.its create mode 100644 board/dhelectronics/dh_stm32mp1/u-boot-dhcor.its (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/Kconfig b/board/dhelectronics/dh_stm32mp1/Kconfig index 8eab986640c..0a839f2546e 100644 --- a/board/dhelectronics/dh_stm32mp1/Kconfig +++ b/board/dhelectronics/dh_stm32mp1/Kconfig @@ -7,7 +7,7 @@ config SYS_VENDOR default "dhelectronics" config SYS_CONFIG_NAME - default "stm32mp1" + default "dh_stm32mp1" config ENV_SECT_SIZE default 0x10000 if ENV_IS_IN_SPI_FLASH diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index 322558157ec..5193868d7cf 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -133,6 +133,62 @@ int checkboard(void) return 0; } +#ifdef CONFIG_BOARD_EARLY_INIT_F +static u8 brdcode __section("data"); +static u8 somcode __section("data"); + +static void board_get_coding_straps(void) +{ + struct gpio_desc gpio[4]; + ofnode node; + int i, ret; + + node = ofnode_path("/config"); + if (!ofnode_valid(node)) { + printf("%s: no /config node?\n", __func__); + return; + } + + brdcode = 0; + somcode = 0; + + ret = gpio_request_list_by_name_nodev(node, "dh,som-coding-gpios", + gpio, ARRAY_SIZE(gpio), + GPIOD_IS_IN); + for (i = 0; i < ret; i++) + somcode |= !!dm_gpio_get_value(&(gpio[i])) << i; + + ret = gpio_request_list_by_name_nodev(node, "dh,board-coding-gpios", + gpio, ARRAY_SIZE(gpio), + GPIOD_IS_IN); + for (i = 0; i < ret; i++) + brdcode |= !!dm_gpio_get_value(&(gpio[i])) << i; + + printf("Code: SoM:rev=%d Board:rev=%d\n", somcode, brdcode); +} + +int board_early_init_f(void) +{ + board_get_coding_straps(); + + return 0; +} + +#ifdef CONFIG_SPL_LOAD_FIT +int board_fit_config_name_match(const char *name) +{ + char test[20]; + + snprintf(test, sizeof(test), "somrev%d_boardrev%d", somcode, brdcode); + + if (!strcmp(name, test)) + return 0; + + return -EINVAL; +} +#endif +#endif + static void board_key_check(void) { #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG) @@ -478,6 +534,11 @@ int board_late_init(void) if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb")) env_set("bootdelay", "0"); +#ifdef CONFIG_BOARD_EARLY_INIT_F + env_set_ulong("dh_som_rev", somcode); + env_set_ulong("dh_board_rev", brdcode); +#endif + return 0; } diff --git a/board/dhelectronics/dh_stm32mp1/u-boot-dhcom.its b/board/dhelectronics/dh_stm32mp1/u-boot-dhcom.its new file mode 100644 index 00000000000..2776c41af1e --- /dev/null +++ b/board/dhelectronics/dh_stm32mp1/u-boot-dhcom.its @@ -0,0 +1,39 @@ +/dts-v1/; + +/ { + description = "U-Boot mainline"; + #address-cells = <1>; + + images { + uboot { + description = "U-Boot (32-bit)"; + data = /incbin/("u-boot-nodtb.bin"); + type = "standalone"; + os = "U-Boot"; + arch = "arm"; + compression = "none"; + load = <0xc0100000>; + entry = <0xc0100000>; + }; + + fdt-1 { + description = ".dtb"; + data = /incbin/("arch/arm/dts/stm32mp15xx-dhcom-pdk2.dtb"); + type = "flat_dt"; + arch = "arm"; + compression = "none"; + }; + }; + + configurations { + default = "config-1"; + + config-1 { + description = "somrev0_boardrev0"; /* SoM+board model */ + loadables = "uboot"; + fdt = "fdt-1"; + }; + + /* Add 587-100..587-400 with fdt-2..fdt-4 here */ + }; +}; diff --git a/board/dhelectronics/dh_stm32mp1/u-boot-dhcor.its b/board/dhelectronics/dh_stm32mp1/u-boot-dhcor.its new file mode 100644 index 00000000000..8844508f1a2 --- /dev/null +++ b/board/dhelectronics/dh_stm32mp1/u-boot-dhcor.its @@ -0,0 +1,39 @@ +/dts-v1/; + +/ { + description = "U-Boot mainline"; + #address-cells = <1>; + + images { + uboot { + description = "U-Boot (32-bit)"; + data = /incbin/("u-boot-nodtb.bin"); + type = "standalone"; + os = "U-Boot"; + arch = "arm"; + compression = "none"; + load = <0xc0100000>; + entry = <0xc0100000>; + }; + + fdt-1 { + description = ".dtb"; + data = /incbin/("arch/arm/dts/stm32mp15xx-dhcor-avenger96.dtb"); + type = "flat_dt"; + arch = "arm"; + compression = "none"; + }; + }; + + configurations { + default = "config-1"; + + config-1 { + description = "somrev0_boardrev1"; /* SoM+board model */ + loadables = "uboot"; + fdt = "fdt-1"; + }; + + /* Add 586-200..586-400 with fdt-2..fdt-4 here */ + }; +}; -- cgit v1.2.3 From 2d68365da17b7dc45543daaa9c5010c11332ba09 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 22 Apr 2020 13:18:14 +0200 Subject: ARM: stm32: Implement DDR3 coding on DHCOR SoM The DHCOR board does exist in multiple variants with different DDR3 DRAM sizes. To cater for all of them, implement DDR3 code handling. There are two GPIOs which code the DRAM size populated on the SoM, read them out and use the value to pick the correct DDR3 config. Reviewed-by: Patrick Delaunay Signed-off-by: Marek Vasut Cc: Manivannan Sadhasivam Cc: Patrick Delaunay Cc: Patrice Chotard --- board/dhelectronics/dh_stm32mp1/board.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index 5193868d7cf..9a2926bbe50 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -135,6 +135,7 @@ int checkboard(void) #ifdef CONFIG_BOARD_EARLY_INIT_F static u8 brdcode __section("data"); +static u8 ddr3code __section("data"); static u8 somcode __section("data"); static void board_get_coding_straps(void) @@ -150,6 +151,7 @@ static void board_get_coding_straps(void) } brdcode = 0; + ddr3code = 0; somcode = 0; ret = gpio_request_list_by_name_nodev(node, "dh,som-coding-gpios", @@ -158,13 +160,34 @@ static void board_get_coding_straps(void) for (i = 0; i < ret; i++) somcode |= !!dm_gpio_get_value(&(gpio[i])) << i; + ret = gpio_request_list_by_name_nodev(node, "dh,ddr3-coding-gpios", + gpio, ARRAY_SIZE(gpio), + GPIOD_IS_IN); + for (i = 0; i < ret; i++) + ddr3code |= !!dm_gpio_get_value(&(gpio[i])) << i; + ret = gpio_request_list_by_name_nodev(node, "dh,board-coding-gpios", gpio, ARRAY_SIZE(gpio), GPIOD_IS_IN); for (i = 0; i < ret; i++) brdcode |= !!dm_gpio_get_value(&(gpio[i])) << i; - printf("Code: SoM:rev=%d Board:rev=%d\n", somcode, brdcode); + printf("Code: SoM:rev=%d,ddr3=%d Board:rev=%d\n", + somcode, ddr3code, brdcode); +} + +int board_stm32mp1_ddr_config_name_match(struct udevice *dev, + const char *name) +{ + if (ddr3code == 2 && + !strcmp(name, "st,ddr3-1066-888-bin-g-1x4gb-533mhz")) + return 0; + + if (ddr3code == 3 && + !strcmp(name, "st,ddr3-1066-888-bin-g-2x4gb-533mhz")) + return 0; + + return -EINVAL; } int board_early_init_f(void) @@ -537,6 +560,7 @@ int board_late_init(void) #ifdef CONFIG_BOARD_EARLY_INIT_F env_set_ulong("dh_som_rev", somcode); env_set_ulong("dh_board_rev", brdcode); + env_set_ulong("dh_ddr3_code", ddr3code); #endif return 0; -- cgit v1.2.3 From 939ba160aa7e4f926599befc5e5cd0a4545dff6e Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:44 +0100 Subject: board: stm32mp1: move board_get_mtdparts in st common directory Move the stm32mp1 common code board_get_mtdparts() in common directory, this patch reduce the maintenance effort on this generic part (not board dependent). Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/dhelectronics/dh_stm32mp1/Makefile | 1 + board/dhelectronics/dh_stm32mp1/board.c | 89 ------------------------ board/st/common/Makefile | 4 ++ board/st/common/stm32mp_mtdparts.c | 115 +++++++++++++++++++++++++++++++ board/st/stm32mp1/stm32mp1.c | 102 --------------------------- 5 files changed, 120 insertions(+), 191 deletions(-) create mode 100644 board/st/common/stm32mp_mtdparts.c (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/Makefile b/board/dhelectronics/dh_stm32mp1/Makefile index b42c4e4c048..c77a1e3a84f 100644 --- a/board/dhelectronics/dh_stm32mp1/Makefile +++ b/board/dhelectronics/dh_stm32mp1/Makefile @@ -8,3 +8,4 @@ obj-y += ../../st/stm32mp1/spl.o endif obj-y += ../../st/stm32mp1/board.o board.o +obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += ../../st/common/stm32mp_mtdparts.o diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index 9a2926bbe50..5f3fe452ce2 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -655,95 +655,6 @@ enum env_location env_get_location(enum env_operation op, int prio) #endif } -#ifdef CONFIG_SYS_MTDPARTS_RUNTIME - -#define MTDPARTS_LEN 256 -#define MTDIDS_LEN 128 - -/** - * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long. - * If we need to access it before the env is relocated, then we need - * to use our own stack buffer. gd->env_buf will be too small. - * - * @param buf temporary buffer pointer MTDPARTS_LEN long - * @return mtdparts variable string, NULL if not found - */ -static const char *env_get_mtdparts(const char *str, char *buf) -{ - if (gd->flags & GD_FLG_ENV_READY) - return env_get(str); - if (env_get_f(str, buf, MTDPARTS_LEN) != -1) - return buf; - - return NULL; -} - -/** - * update the variables "mtdids" and "mtdparts" with content of mtdparts_ - */ -static void board_get_mtdparts(const char *dev, - char *mtdids, - char *mtdparts) -{ - char env_name[32] = "mtdparts_"; - char tmp_mtdparts[MTDPARTS_LEN]; - const char *tmp; - - /* name of env variable to read = mtdparts_ */ - strcat(env_name, dev); - tmp = env_get_mtdparts(env_name, tmp_mtdparts); - if (tmp) { - /* mtdids: "=, ...." */ - if (mtdids[0] != '\0') - strcat(mtdids, ","); - strcat(mtdids, dev); - strcat(mtdids, "="); - strcat(mtdids, dev); - - /* mtdparts: "mtdparts=:>;..." */ - if (mtdparts[0] != '\0') - strncat(mtdparts, ";", MTDPARTS_LEN); - else - strcat(mtdparts, "mtdparts="); - strncat(mtdparts, dev, MTDPARTS_LEN); - strncat(mtdparts, ":", MTDPARTS_LEN); - strncat(mtdparts, tmp, MTDPARTS_LEN); - } -} - -void board_mtdparts_default(const char **mtdids, const char **mtdparts) -{ - struct udevice *dev; - static char parts[3 * MTDPARTS_LEN + 1]; - static char ids[MTDIDS_LEN + 1]; - static bool mtd_initialized; - - if (mtd_initialized) { - *mtdids = ids; - *mtdparts = parts; - return; - } - - memset(parts, 0, sizeof(parts)); - memset(ids, 0, sizeof(ids)); - - /* probe all MTD devices */ - for (uclass_first_device(UCLASS_MTD, &dev); - dev; - uclass_next_device(&dev)) { - pr_debug("mtd device = %s\n", dev->name); - } - - if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) - board_get_mtdparts("nor0", ids, parts); - - mtd_initialized = true; - *mtdids = ids; - *mtdparts = parts; - debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts); -} -#endif - #if defined(CONFIG_OF_BOARD_SETUP) int ft_board_setup(void *blob, bd_t *bd) { diff --git a/board/st/common/Makefile b/board/st/common/Makefile index 8553606b904..4bb8b498675 100644 --- a/board/st/common/Makefile +++ b/board/st/common/Makefile @@ -4,3 +4,7 @@ # obj-$(CONFIG_CMD_STBOARD) += cmd_stboard.o + +ifeq ($(CONFIG_ARCH_STM32MP),y) +obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += stm32mp_mtdparts.o +endif diff --git a/board/st/common/stm32mp_mtdparts.c b/board/st/common/stm32mp_mtdparts.c new file mode 100644 index 00000000000..d77e075864d --- /dev/null +++ b/board/st/common/stm32mp_mtdparts.c @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2020, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include + +#define MTDPARTS_LEN 256 +#define MTDIDS_LEN 128 + +/* + * Get a global data pointer + */ +DECLARE_GLOBAL_DATA_PTR; + +/** + * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long. + * If we need to access it before the env is relocated, then we need + * to use our own stack buffer. gd->env_buf will be too small. + * + * @param buf temporary buffer pointer MTDPARTS_LEN long + * @return mtdparts variable string, NULL if not found + */ +static const char *env_get_mtdparts(const char *str, char *buf) +{ + if (gd->flags & GD_FLG_ENV_READY) + return env_get(str); + if (env_get_f(str, buf, MTDPARTS_LEN) != -1) + return buf; + + return NULL; +} + +/** + * update the variables "mtdids" and "mtdparts" with content of mtdparts_ + */ +static void board_get_mtdparts(const char *dev, + char *mtdids, + char *mtdparts) +{ + char env_name[32] = "mtdparts_"; + char tmp_mtdparts[MTDPARTS_LEN]; + const char *tmp; + + /* name of env variable to read = mtdparts_ */ + strcat(env_name, dev); + tmp = env_get_mtdparts(env_name, tmp_mtdparts); + if (tmp) { + /* mtdids: "=, ...." */ + if (mtdids[0] != '\0') + strcat(mtdids, ","); + strcat(mtdids, dev); + strcat(mtdids, "="); + strcat(mtdids, dev); + + /* mtdparts: "mtdparts=:>;..." */ + if (mtdparts[0] != '\0') + strncat(mtdparts, ";", MTDPARTS_LEN); + else + strcat(mtdparts, "mtdparts="); + strncat(mtdparts, dev, MTDPARTS_LEN); + strncat(mtdparts, ":", MTDPARTS_LEN); + strncat(mtdparts, tmp, MTDPARTS_LEN); + } +} + +void board_mtdparts_default(const char **mtdids, const char **mtdparts) +{ + struct mtd_info *mtd; + struct udevice *dev; + static char parts[3 * MTDPARTS_LEN + 1]; + static char ids[MTDIDS_LEN + 1]; + static bool mtd_initialized; + + if (mtd_initialized) { + *mtdids = ids; + *mtdparts = parts; + return; + } + + memset(parts, 0, sizeof(parts)); + memset(ids, 0, sizeof(ids)); + + /* probe all MTD devices */ + for (uclass_first_device(UCLASS_MTD, &dev); + dev; + uclass_next_device(&dev)) { + pr_debug("mtd device = %s\n", dev->name); + } + + mtd = get_mtd_device_nm("nand0"); + if (!IS_ERR_OR_NULL(mtd)) { + board_get_mtdparts("nand0", ids, parts); + put_mtd_device(mtd); + } + + mtd = get_mtd_device_nm("spi-nand0"); + if (!IS_ERR_OR_NULL(mtd)) { + board_get_mtdparts("spi-nand0", ids, parts); + put_mtd_device(mtd); + } + + if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) + board_get_mtdparts("nor0", ids, parts); + + mtd_initialized = true; + *mtdids = ids; + *mtdparts = parts; + debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts); +} diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 45068b1cd9d..641cfb14681 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -828,108 +828,6 @@ const char *env_ext4_get_dev_part(void) } #endif -#ifdef CONFIG_SYS_MTDPARTS_RUNTIME - -#define MTDPARTS_LEN 256 -#define MTDIDS_LEN 128 - -/** - * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long. - * If we need to access it before the env is relocated, then we need - * to use our own stack buffer. gd->env_buf will be too small. - * - * @param buf temporary buffer pointer MTDPARTS_LEN long - * @return mtdparts variable string, NULL if not found - */ -static const char *env_get_mtdparts(const char *str, char *buf) -{ - if (gd->flags & GD_FLG_ENV_READY) - return env_get(str); - if (env_get_f(str, buf, MTDPARTS_LEN) != -1) - return buf; - - return NULL; -} - -/** - * update the variables "mtdids" and "mtdparts" with content of mtdparts_ - */ -static void board_get_mtdparts(const char *dev, - char *mtdids, - char *mtdparts) -{ - char env_name[32] = "mtdparts_"; - char tmp_mtdparts[MTDPARTS_LEN]; - const char *tmp; - - /* name of env variable to read = mtdparts_ */ - strcat(env_name, dev); - tmp = env_get_mtdparts(env_name, tmp_mtdparts); - if (tmp) { - /* mtdids: "=, ...." */ - if (mtdids[0] != '\0') - strcat(mtdids, ","); - strcat(mtdids, dev); - strcat(mtdids, "="); - strcat(mtdids, dev); - - /* mtdparts: "mtdparts=:>;..." */ - if (mtdparts[0] != '\0') - strncat(mtdparts, ";", MTDPARTS_LEN); - else - strcat(mtdparts, "mtdparts="); - strncat(mtdparts, dev, MTDPARTS_LEN); - strncat(mtdparts, ":", MTDPARTS_LEN); - strncat(mtdparts, tmp, MTDPARTS_LEN); - } -} - -void board_mtdparts_default(const char **mtdids, const char **mtdparts) -{ - struct mtd_info *mtd; - struct udevice *dev; - static char parts[3 * MTDPARTS_LEN + 1]; - static char ids[MTDIDS_LEN + 1]; - static bool mtd_initialized; - - if (mtd_initialized) { - *mtdids = ids; - *mtdparts = parts; - return; - } - - memset(parts, 0, sizeof(parts)); - memset(ids, 0, sizeof(ids)); - - /* probe all MTD devices */ - for (uclass_first_device(UCLASS_MTD, &dev); - dev; - uclass_next_device(&dev)) { - pr_debug("mtd device = %s\n", dev->name); - } - - mtd = get_mtd_device_nm("nand0"); - if (!IS_ERR_OR_NULL(mtd)) { - board_get_mtdparts("nand0", ids, parts); - put_mtd_device(mtd); - } - - mtd = get_mtd_device_nm("spi-nand0"); - if (!IS_ERR_OR_NULL(mtd)) { - board_get_mtdparts("spi-nand0", ids, parts); - put_mtd_device(mtd); - } - - if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) - board_get_mtdparts("nor0", ids, parts); - - mtd_initialized = true; - *mtdids = ids; - *mtdparts = parts; - debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts); -} -#endif - #if defined(CONFIG_OF_BOARD_SETUP) int ft_board_setup(void *blob, bd_t *bd) { -- cgit v1.2.3 From ec2933e543dfe80bbb7b3c015392b44894081452 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:45 +0100 Subject: board: stm32mp1: move set_dfu_alt_info in st common directory Move the stm32mp1 common code set_dfu_alt_info() in common directory, this patch reduce the maintenance effort on this generic part (not board dependent). Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/dhelectronics/dh_stm32mp1/Makefile | 2 + board/dhelectronics/dh_stm32mp1/board.c | 50 ---------- board/st/common/Makefile | 1 + board/st/common/stm32mp_dfu.c | 151 +++++++++++++++++++++++++++++++ board/st/stm32mp1/stm32mp1.c | 145 ----------------------------- 5 files changed, 154 insertions(+), 195 deletions(-) create mode 100644 board/st/common/stm32mp_dfu.c (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/Makefile b/board/dhelectronics/dh_stm32mp1/Makefile index c77a1e3a84f..e8f218da085 100644 --- a/board/dhelectronics/dh_stm32mp1/Makefile +++ b/board/dhelectronics/dh_stm32mp1/Makefile @@ -8,4 +8,6 @@ obj-y += ../../st/stm32mp1/spl.o endif obj-y += ../../st/stm32mp1/board.o board.o + obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += ../../st/common/stm32mp_mtdparts.o +obj-$(CONFIG_SET_DFU_ALT_INFO) += ../../st/common/stm32mp_dfu.o diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index 5f3fe452ce2..873fa86e53c 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -662,56 +662,6 @@ int ft_board_setup(void *blob, bd_t *bd) } #endif -#ifdef CONFIG_SET_DFU_ALT_INFO -#define DFU_ALT_BUF_LEN SZ_1K - -static void board_get_alt_info(const char *dev, char *buff) -{ - char var_name[32] = "dfu_alt_info_"; - int ret; - - ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN); - - /* name of env variable to read = dfu_alt_info_ */ - 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); - } -} - -void set_dfu_alt_info(char *interface, char *devstr) -{ - struct udevice *dev; - - ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); - - if (env_get("dfu_alt_info")) - return; - - memset(buf, 0, sizeof(buf)); - - /* probe all MTD devices */ - mtd_probe_devices(); - - board_get_alt_info("ram", buf); - - if (!uclass_get_device(UCLASS_MMC, 0, &dev)) - board_get_alt_info("mmc0", 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); - - env_set("dfu_alt_info", buf); - puts("DFU alt info setting: done\n"); -} -#endif - static void board_copro_image_process(ulong fw_image, size_t fw_size) { int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */ diff --git a/board/st/common/Makefile b/board/st/common/Makefile index 4bb8b498675..aa030bacd81 100644 --- a/board/st/common/Makefile +++ b/board/st/common/Makefile @@ -7,4 +7,5 @@ obj-$(CONFIG_CMD_STBOARD) += cmd_stboard.o ifeq ($(CONFIG_ARCH_STM32MP),y) obj-$(CONFIG_SYS_MTDPARTS_RUNTIME) += stm32mp_mtdparts.o +obj-$(CONFIG_SET_DFU_ALT_INFO) += stm32mp_dfu.o endif diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c new file mode 100644 index 00000000000..99ea21ce15f --- /dev/null +++ b/board/st/common/stm32mp_dfu.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause +/* + * Copyright (C) 2020, STMicroelectronics - All Rights Reserved + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DFU_ALT_BUF_LEN SZ_1K + +static void board_get_alt_info(const char *dev, char *buff) +{ + char var_name[32] = "dfu_alt_info_"; + int ret; + + ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN); + + /* name of env variable to read = dfu_alt_info_ */ + 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); + } +} + +void set_dfu_alt_info(char *interface, char *devstr) +{ + struct udevice *dev; + struct mtd_info *mtd; + + ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); + + if (env_get("dfu_alt_info")) + return; + + memset(buf, 0, sizeof(buf)); + + /* probe all MTD devices */ + mtd_probe_devices(); + + board_get_alt_info("ram", buf); + + if (!uclass_get_device(UCLASS_MMC, 0, &dev)) + board_get_alt_info("mmc0", 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); + +#ifdef CONFIG_DFU_VIRT + strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN); + + if (IS_ENABLED(CONFIG_PMIC_STPMIC1)) + strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN); +#endif + + env_set("dfu_alt_info", buf); + puts("DFU alt info setting: done\n"); +} + +#if CONFIG_IS_ENABLED(DFU_VIRT) +#include +#include + +static int dfu_otp_read(u64 offset, u8 *buffer, long *size) +{ + struct udevice *dev; + int ret; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_GET_DRIVER(stm32mp_bsec), + &dev); + if (ret) + return ret; + + ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size); + if (ret >= 0) { + *size = ret; + ret = 0; + } + + return 0; +} + +static int dfu_pmic_read(u64 offset, u8 *buffer, long *size) +{ + int ret; +#ifdef CONFIG_PMIC_STPMIC1 + struct udevice *dev; + + ret = uclass_get_device_by_driver(UCLASS_MISC, + DM_GET_DRIVER(stpmic1_nvm), + &dev); + if (ret) + return ret; + + ret = misc_read(dev, 0xF8 + offset, buffer, *size); + if (ret >= 0) { + *size = ret; + ret = 0; + } + if (ret == -EACCES) { + *size = 0; + ret = 0; + } +#else + pr_err("PMIC update not supported"); + ret = -EOPNOTSUPP; +#endif + + return ret; +} + +int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset, + void *buf, long *len) +{ + switch (dfu->data.virt.dev_num) { + case 0x0: + return dfu_otp_read(offset, buf, len); + case 0x1: + return dfu_pmic_read(offset, buf, len); + } + *len = 0; + return 0; +} + +int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size) +{ + *size = SZ_1K; + + return 0; +} + +#endif diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 641cfb14681..3ccb12d817d 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -18,9 +17,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -843,148 +840,6 @@ int ft_board_setup(void *blob, bd_t *bd) } #endif -#ifdef CONFIG_SET_DFU_ALT_INFO -#define DFU_ALT_BUF_LEN SZ_1K - -static void board_get_alt_info(const char *dev, char *buff) -{ - char var_name[32] = "dfu_alt_info_"; - int ret; - - ALLOC_CACHE_ALIGN_BUFFER(char, tmp_alt, DFU_ALT_BUF_LEN); - - /* name of env variable to read = dfu_alt_info_ */ - 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); - } -} - -void set_dfu_alt_info(char *interface, char *devstr) -{ - struct udevice *dev; - struct mtd_info *mtd; - - ALLOC_CACHE_ALIGN_BUFFER(char, buf, DFU_ALT_BUF_LEN); - - if (env_get("dfu_alt_info")) - return; - - memset(buf, 0, sizeof(buf)); - - /* probe all MTD devices */ - mtd_probe_devices(); - - board_get_alt_info("ram", buf); - - if (!uclass_get_device(UCLASS_MMC, 0, &dev)) - board_get_alt_info("mmc0", 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); - -#ifdef CONFIG_DFU_VIRT - strncat(buf, "&virt 0=OTP", DFU_ALT_BUF_LEN); - - if (IS_ENABLED(CONFIG_PMIC_STPMIC1)) - strncat(buf, "&virt 1=PMIC", DFU_ALT_BUF_LEN); -#endif - - env_set("dfu_alt_info", buf); - puts("DFU alt info setting: done\n"); -} - -#if CONFIG_IS_ENABLED(DFU_VIRT) -#include -#include - -static int dfu_otp_read(u64 offset, u8 *buffer, long *size) -{ - struct udevice *dev; - int ret; - - ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stm32mp_bsec), - &dev); - if (ret) - return ret; - - ret = misc_read(dev, offset + STM32_BSEC_OTP_OFFSET, buffer, *size); - if (ret >= 0) { - *size = ret; - ret = 0; - } - - return 0; -} - -static int dfu_pmic_read(u64 offset, u8 *buffer, long *size) -{ - int ret; -#ifdef CONFIG_PMIC_STPMIC1 - struct udevice *dev; - - ret = uclass_get_device_by_driver(UCLASS_MISC, - DM_GET_DRIVER(stpmic1_nvm), - &dev); - if (ret) - return ret; - - ret = misc_read(dev, 0xF8 + offset, buffer, *size); - if (ret >= 0) { - *size = ret; - ret = 0; - } - if (ret == -EACCES) { - *size = 0; - ret = 0; - } -#else - pr_err("PMIC update not supported"); - ret = -EOPNOTSUPP; -#endif - - return ret; -} - -int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset, - void *buf, long *len) -{ - switch (dfu->data.virt.dev_num) { - case 0x0: - return dfu_otp_read(offset, buf, len); - case 0x1: - return dfu_pmic_read(offset, buf, len); - } - *len = 0; - return 0; -} - -int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size) -{ - *size = SZ_1K; - - return 0; -} - -#endif - -#endif - static void board_copro_image_process(ulong fw_image, size_t fw_size) { int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */ -- cgit v1.2.3 From 31325e1b8b9ce06b34add643f4a9d0b58235434a Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:46 +0100 Subject: stm32mp1: dynamically build DFU_ALT_INFO 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 Reviewed-by: Patrice Chotard --- board/dhelectronics/dh_stm32mp1/Kconfig | 1 + board/st/common/Kconfig | 7 ++ board/st/common/stm32mp_dfu.c | 130 +++++++++++++++++++++++++------- 3 files changed, 110 insertions(+), 28 deletions(-) (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/Kconfig b/board/dhelectronics/dh_stm32mp1/Kconfig index 0a839f2546e..1fc792c9d1a 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 af01ca4891c..08df8459827 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 99ea21ce15f..e129f8c8b5b 100644 --- a/board/st/common/stm32mp_dfu.c +++ b/board/st/common/stm32mp_dfu.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -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_ */ - 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); -- cgit v1.2.3 From 28a28ba9764d02b1e52938b5f7d322ffd13b01f1 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:47 +0100 Subject: stm32mp1: move MTDPART configuration in Kconfig This patch reduces the stm32mp1 environment size and builds dynamically the MTD partitions with information from defconfig (CONFIG_MTDPARTS_...). Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/common/Kconfig | 57 +++++++++++++++++++++++ board/st/common/stm32mp_mtdparts.c | 93 +++++++++++++++++++------------------- 2 files changed, 104 insertions(+), 46 deletions(-) (limited to 'board') diff --git a/board/st/common/Kconfig b/board/st/common/Kconfig index 08df8459827..015ba409396 100644 --- a/board/st/common/Kconfig +++ b/board/st/common/Kconfig @@ -6,6 +6,63 @@ config CMD_STBOARD This compile the stboard command to read and write the board in the OTP. +config MTDPARTS_NAND0_BOOT + string "mtd boot partitions for nand0" + default "2m(fsbl),2m(ssbl1),2m(ssbl2)" + depends on SYS_MTDPARTS_RUNTIME && ARCH_STM32MP + help + This define the partitions of nand0 used to build mtparts dynamically + for boot from nand0. + Each partition need to be aligned with the device erase block size, + 512KB is the max size for the NAND supported by stm32mp1 platform. + +config MTDPARTS_NAND0_TEE + string "mtd tee partitions for nand0" + default "512k(teeh),512k(teed),512k(teex)" + depends on SYS_MTDPARTS_RUNTIME && ARCH_STM32MP + help + This define the tee partitions added in mtparts dynamically + when tee is supported with boot from nand0. + Each partition need to be aligned with the device erase block size, + 512KB is the max size for the NAND supported by stm32mp1 platform. + +config MTDPARTS_NOR0_BOOT + string "mtd boot partitions for nor0" + default "256k(fsbl1),256k(fsbl2),2m(ssbl),512k(u-boot-env)" + depends on SYS_MTDPARTS_RUNTIME && ARCH_STM32MP + help + This define the partitions of nand0 used to build mtparts dynamically + for boot from nor0. + Each partition need to be aligned with the device erase block size, + with 256KB we support all the NOR. + U-Boot env partition (512kB) use 2 erase block for redundancy. + +config MTDPARTS_NOR0_TEE + string "mtd tee partitions for nor0" + default "256k(teeh),256k(teed),256k(teex)" + depends on SYS_MTDPARTS_RUNTIME && ARCH_STM32MP + help + This define the tee partitions added in mtparts dynamically + when tee is supported with boot from nor0. + +config MTDPARTS_SPINAND0_BOOT + string "mtd boot partitions for spi-nand0" + default "2m(fsbl),2m(ssbl1),2m(ssbl2)" + depends on SYS_MTDPARTS_RUNTIME && ARCH_STM32MP + help + This define the partitions of nand0 used to build mtparts dynamically + for boot from spi-nand0, + 512KB is the max size for the NAND supported by stm32mp1 platform. + +config MTDPARTS_SPINAND0_TEE + string "mtd tee partitions for spi-nand0" + default "512k(teeh),512k(teed),512k(teex)" + depends on SYS_MTDPARTS_RUNTIME && ARCH_STM32MP + help + This define the tee partitions added in mtparts dynamically + when tee is supported with boot from spi-nand0, + 512KB is the max size for the NAND supported by stm32mp1 platform. + config DFU_ALT_RAM0 string "dfu for ram0" default "uImage ram 0xc2000000 0x2000000;devicetree.dtb ram 0xc4000000 0x100000;uramdisk.image.gz ram 0xc4400000 0x10000000" diff --git a/board/st/common/stm32mp_mtdparts.c b/board/st/common/stm32mp_mtdparts.c index d77e075864d..d4c0a7db9fb 100644 --- a/board/st/common/stm32mp_mtdparts.c +++ b/board/st/common/stm32mp_mtdparts.c @@ -19,54 +19,42 @@ DECLARE_GLOBAL_DATA_PTR; /** - * The mtdparts_nand0 and mtdparts_nor0 variable tends to be long. - * If we need to access it before the env is relocated, then we need - * to use our own stack buffer. gd->env_buf will be too small. - * - * @param buf temporary buffer pointer MTDPARTS_LEN long - * @return mtdparts variable string, NULL if not found - */ -static const char *env_get_mtdparts(const char *str, char *buf) -{ - if (gd->flags & GD_FLG_ENV_READY) - return env_get(str); - if (env_get_f(str, buf, MTDPARTS_LEN) != -1) - return buf; - - return NULL; -} - -/** - * update the variables "mtdids" and "mtdparts" with content of mtdparts_ + * update the variables "mtdids" and "mtdparts" with boot, tee and user strings */ static void board_get_mtdparts(const char *dev, char *mtdids, - char *mtdparts) + char *mtdparts, + const char *boot, + const char *tee, + const char *user) { - char env_name[32] = "mtdparts_"; - char tmp_mtdparts[MTDPARTS_LEN]; - const char *tmp; - - /* name of env variable to read = mtdparts_ */ - strcat(env_name, dev); - tmp = env_get_mtdparts(env_name, tmp_mtdparts); - if (tmp) { - /* mtdids: "=, ...." */ - if (mtdids[0] != '\0') - strcat(mtdids, ","); - strcat(mtdids, dev); - strcat(mtdids, "="); - strcat(mtdids, dev); - - /* mtdparts: "mtdparts=:>;..." */ - if (mtdparts[0] != '\0') - strncat(mtdparts, ";", MTDPARTS_LEN); - else - strcat(mtdparts, "mtdparts="); - strncat(mtdparts, dev, MTDPARTS_LEN); - strncat(mtdparts, ":", MTDPARTS_LEN); - strncat(mtdparts, tmp, MTDPARTS_LEN); + /* mtdids: "=, ...." */ + if (mtdids[0] != '\0') + strcat(mtdids, ","); + strcat(mtdids, dev); + strcat(mtdids, "="); + strcat(mtdids, dev); + + /* mtdparts: "mtdparts=:>;..." */ + if (mtdparts[0] != '\0') + strncat(mtdparts, ";", MTDPARTS_LEN); + else + strcat(mtdparts, "mtdparts="); + + strncat(mtdparts, dev, MTDPARTS_LEN); + strncat(mtdparts, ":", MTDPARTS_LEN); + + if (boot) { + strncat(mtdparts, boot, MTDPARTS_LEN); + strncat(mtdparts, ",", MTDPARTS_LEN); + } + + if (CONFIG_IS_ENABLED(STM32MP1_OPTEE) && tee) { + strncat(mtdparts, tee, MTDPARTS_LEN); + strncat(mtdparts, ",", MTDPARTS_LEN); } + + strncat(mtdparts, user, MTDPARTS_LEN); } void board_mtdparts_default(const char **mtdids, const char **mtdparts) @@ -76,6 +64,7 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) static char parts[3 * MTDPARTS_LEN + 1]; static char ids[MTDIDS_LEN + 1]; static bool mtd_initialized; + bool tee = false; if (mtd_initialized) { *mtdids = ids; @@ -83,6 +72,9 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) return; } + if (CONFIG_IS_ENABLED(STM32MP1_OPTEE)) + tee = true; + memset(parts, 0, sizeof(parts)); memset(ids, 0, sizeof(ids)); @@ -95,18 +87,27 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) mtd = get_mtd_device_nm("nand0"); if (!IS_ERR_OR_NULL(mtd)) { - board_get_mtdparts("nand0", ids, parts); + board_get_mtdparts("nand0", ids, parts, + CONFIG_MTDPARTS_NAND0_BOOT, + tee ? CONFIG_MTDPARTS_NAND0_TEE : NULL, + "-(UBI)"); put_mtd_device(mtd); } mtd = get_mtd_device_nm("spi-nand0"); if (!IS_ERR_OR_NULL(mtd)) { - board_get_mtdparts("spi-nand0", ids, parts); + board_get_mtdparts("spi-nand0", ids, parts, + CONFIG_MTDPARTS_SPINAND0_BOOT, + tee ? CONFIG_MTDPARTS_SPINAND0_TEE : NULL, + "-(UBI)"); put_mtd_device(mtd); } if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) - board_get_mtdparts("nor0", ids, parts); + board_get_mtdparts("nor0", ids, parts, + CONFIG_MTDPARTS_NOR0_BOOT, + tee ? CONFIG_MTDPARTS_NOR0_TEE : NULL, + "-(nor_user)"); mtd_initialized = true; *mtdids = ids; -- cgit v1.2.3 From 43df0a159df6ef4c627553915634cd3d961d4da8 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:49 +0100 Subject: stm32mp1: dynamically detect op-tee presence Activate OP-TEE driver for trusted and optee defconfig. This driver allows detection of TEE presence for boot from flash; CONFIG_STM32MP1_OPTEE is also removed. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/dhelectronics/dh_stm32mp1/board.c | 4 +--- board/st/common/stm32mp_mtdparts.c | 6 ++++-- board/st/stm32mp1/stm32mp1.c | 4 +--- 3 files changed, 6 insertions(+), 8 deletions(-) (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index 873fa86e53c..ec1edd5c688 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -116,9 +116,7 @@ int checkboard(void) const char *fdt_compat; int fdt_compat_len; - if (IS_ENABLED(CONFIG_STM32MP1_OPTEE)) - mode = "trusted with OP-TEE"; - else if (IS_ENABLED(CONFIG_TFABOOT)) + if (IS_ENABLED(CONFIG_TFABOOT)) mode = "trusted"; else mode = "basic"; diff --git a/board/st/common/stm32mp_mtdparts.c b/board/st/common/stm32mp_mtdparts.c index d4c0a7db9fb..2b6413be166 100644 --- a/board/st/common/stm32mp_mtdparts.c +++ b/board/st/common/stm32mp_mtdparts.c @@ -9,6 +9,7 @@ #include #include #include +#include #define MTDPARTS_LEN 256 #define MTDIDS_LEN 128 @@ -49,7 +50,7 @@ static void board_get_mtdparts(const char *dev, strncat(mtdparts, ",", MTDPARTS_LEN); } - if (CONFIG_IS_ENABLED(STM32MP1_OPTEE) && tee) { + if (tee) { strncat(mtdparts, tee, MTDPARTS_LEN); strncat(mtdparts, ",", MTDPARTS_LEN); } @@ -72,7 +73,8 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) return; } - if (CONFIG_IS_ENABLED(STM32MP1_OPTEE)) + if (CONFIG_IS_ENABLED(OPTEE) && + tee_find_device(NULL, NULL, NULL, NULL)) tee = true; memset(parts, 0, sizeof(parts)); diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 3ccb12d817d..496ca56a145 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -87,9 +87,7 @@ int checkboard(void) const char *fdt_compat; int fdt_compat_len; - if (IS_ENABLED(CONFIG_STM32MP1_OPTEE)) - mode = "trusted with OP-TEE"; - else if (IS_ENABLED(TFABOOT)) + if (IS_ENABLED(CONFIG_TFABOOT)) mode = "trusted"; else mode = "basic"; -- cgit v1.2.3 From ccf6e9ff95d6e5c7dd3dc30239cfdd74ffbb9e85 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:51 +0100 Subject: configs: stm32mp1: remove optee defconfig As the op-tee presence is detected by U-boot, the stm32mp15_optee_defconfig is identical to stm32mp15_trusted_defconfig and can be removed. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/stm32mp1/MAINTAINERS | 1 - 1 file changed, 1 deletion(-) (limited to 'board') diff --git a/board/st/stm32mp1/MAINTAINERS b/board/st/stm32mp1/MAINTAINERS index 29309477167..96c45590337 100644 --- a/board/st/stm32mp1/MAINTAINERS +++ b/board/st/stm32mp1/MAINTAINERS @@ -6,6 +6,5 @@ S: Maintained F: arch/arm/dts/stm32mp15* F: board/st/stm32mp1/ F: configs/stm32mp15_basic_defconfig -F: configs/stm32mp15_optee_defconfig F: configs/stm32mp15_trusted_defconfig F: include/configs/stm32mp1.h -- cgit v1.2.3 From b664a74537c9a9a4a50940e4a2ced2428760235b Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:52 +0100 Subject: board: stm32mp1: support boot from spi-nand Manage BOOT_FLASH_SPINAND, with boot_device="spi-nand" and treat this value in bootcmd_stm32mp. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/stm32mp1/stm32mp1.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 496ca56a145..fe54947c1c7 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -789,6 +789,7 @@ enum env_location env_get_location(enum env_operation op, int prio) #endif #ifdef CONFIG_ENV_IS_IN_UBI case BOOT_FLASH_NAND: + case BOOT_FLASH_SPINAND: return ENVL_UBI; #endif #ifdef CONFIG_ENV_IS_IN_SPI_FLASH @@ -829,6 +830,7 @@ int ft_board_setup(void *blob, bd_t *bd) #ifdef CONFIG_FDT_FIXUP_PARTITIONS struct node_info nodes[] = { { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, }, + { "st,stm32f469-qspi", MTD_DEV_TYPE_SPINAND}, { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, }, }; fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); -- cgit v1.2.3 From 23229d030998f8c2425cc8bbf8c26360facc9300 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:22:53 +0100 Subject: board: stm32mp1: adapt MTD partition for BOOT from NOR or NAND Dynamically adapt the MTD partitions in NAND and SPI-NAND when boot from NOR or NAND/SPI-NAND is detected. This patch avoids to define the save MTD partition name for NOR and NAND devices and issue with latest kernel: only the needed MTD partitions are defined. For boot from NOR 1/ bootloader (TF-A, U-Boot and OP-TE) in NOR 2/ one large UBI partition in NAND For boot from NAND 1/ bootloader (TF-A, U-Boot and OP-TE) in MTD raw partition 2/ one large UBI partition Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/common/stm32mp_mtdparts.c | 81 ++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 21 deletions(-) (limited to 'board') diff --git a/board/st/common/stm32mp_mtdparts.c b/board/st/common/stm32mp_mtdparts.c index 2b6413be166..50285110770 100644 --- a/board/st/common/stm32mp_mtdparts.c +++ b/board/st/common/stm32mp_mtdparts.c @@ -10,6 +10,7 @@ #include #include #include +#include #define MTDPARTS_LEN 256 #define MTDIDS_LEN 128 @@ -22,7 +23,7 @@ DECLARE_GLOBAL_DATA_PTR; /** * update the variables "mtdids" and "mtdparts" with boot, tee and user strings */ -static void board_get_mtdparts(const char *dev, +static void board_set_mtdparts(const char *dev, char *mtdids, char *mtdparts, const char *boot, @@ -65,7 +66,7 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) static char parts[3 * MTDPARTS_LEN + 1]; static char ids[MTDIDS_LEN + 1]; static bool mtd_initialized; - bool tee = false; + bool tee, nor, nand, spinand; if (mtd_initialized) { *mtdids = ids; @@ -73,6 +74,28 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) return; } + tee = false; + nor = false; + nand = false; + spinand = false; + + switch (get_bootmode() & TAMP_BOOT_DEVICE_MASK) { + case BOOT_SERIAL_UART: + case BOOT_SERIAL_USB: + break; + case BOOT_FLASH_NAND: + nand = true; + break; + case BOOT_FLASH_SPINAND: + spinand = true; + break; + case BOOT_FLASH_NOR: + nor = true; + break; + default: + break; + } + if (CONFIG_IS_ENABLED(OPTEE) && tee_find_device(NULL, NULL, NULL, NULL)) tee = true; @@ -87,29 +110,45 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) pr_debug("mtd device = %s\n", dev->name); } - mtd = get_mtd_device_nm("nand0"); - if (!IS_ERR_OR_NULL(mtd)) { - board_get_mtdparts("nand0", ids, parts, - CONFIG_MTDPARTS_NAND0_BOOT, - tee ? CONFIG_MTDPARTS_NAND0_TEE : NULL, - "-(UBI)"); - put_mtd_device(mtd); + if (nor || nand) { + mtd = get_mtd_device_nm("nand0"); + if (!IS_ERR_OR_NULL(mtd)) { + const char *mtd_boot = CONFIG_MTDPARTS_NAND0_BOOT; + const char *mtd_tee = CONFIG_MTDPARTS_NAND0_TEE; + + board_set_mtdparts("nand0", ids, parts, + !nor ? mtd_boot : NULL, + !nor && tee ? mtd_tee : NULL, + "-(UBI)"); + put_mtd_device(mtd); + } } - mtd = get_mtd_device_nm("spi-nand0"); - if (!IS_ERR_OR_NULL(mtd)) { - board_get_mtdparts("spi-nand0", ids, parts, - CONFIG_MTDPARTS_SPINAND0_BOOT, - tee ? CONFIG_MTDPARTS_SPINAND0_TEE : NULL, - "-(UBI)"); - put_mtd_device(mtd); + if (nor || spinand) { + mtd = get_mtd_device_nm("spi-nand0"); + if (!IS_ERR_OR_NULL(mtd)) { + const char *mtd_boot = CONFIG_MTDPARTS_SPINAND0_BOOT; + const char *mtd_tee = CONFIG_MTDPARTS_SPINAND0_TEE; + + board_set_mtdparts("spi-nand0", ids, parts, + !nor ? mtd_boot : NULL, + !nor && tee ? mtd_tee : NULL, + "-(UBI)"); + put_mtd_device(mtd); + } } - if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) - board_get_mtdparts("nor0", ids, parts, - CONFIG_MTDPARTS_NOR0_BOOT, - tee ? CONFIG_MTDPARTS_NOR0_TEE : NULL, - "-(nor_user)"); + if (nor) { + if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) { + const char *mtd_boot = CONFIG_MTDPARTS_NOR0_BOOT; + const char *mtd_tee = CONFIG_MTDPARTS_NOR0_TEE; + + board_set_mtdparts("nor0", ids, parts, + mtd_boot, + tee ? mtd_tee : NULL, + "-(nor_user)"); + } + } mtd_initialized = true; *mtdids = ids; -- cgit v1.2.3 From 954bd1a923a686089c62195781616768f52eacc7 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:24:49 +0100 Subject: stm32mp: add the command stm32prog Add a specific command stm32prog for STM32MP soc family witch allows to program the boot devices with the tool STM32CubeProgrammer (http://www.st.com/STM32CubeProg). This command uses the same UART STM32 protocol than MCU STM32 with or USB with DFU protocol v1.1 (ithe MCU ST extension are no supported). The executed actions are based on a tab separated value file with a stm32 header, the FlashLayout file (https://wiki.st.com/stm32mpu/wiki/STM32CubeProgrammer_flashlayout). This file is parsed by the U-Boot command to: - initialize the devices - create the partition table on each device - initialize the DFU backend to access to not volatile memory (NOR/NAND/SD/eMMC) or to virtual device (OTP/PMIC) Up to STM32PROG_MAX_DEV (5) devices can be updated with a FlashLayout. The communication between U-Boot and STM32CubeProgrammer is done with the specific alternate configuration (see "AN5275: USB DFU/USART protocols used in STM32MP1 Series bootloaders" for details). The command stm32prog is executed when a boot from USB is detected (selected with bootpins) and we can program the boot devices with a simple command (on Windows or Linux): PC $> STM32_Programmer_CLI -c port=usb1 -w flaslayout.tsv 1/ the ROM code loads TF-A in embedded RAM (DFU or uart) 2/ TF-A loads flashlayout file and U-Boot in DDR (DFU or uart) 3/ U-Boot executes the stm32prog command (DFU or uart) Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard Reviewed-by: Patrice Chotard --- board/st/common/stm32mp_dfu.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'board') diff --git a/board/st/common/stm32mp_dfu.c b/board/st/common/stm32mp_dfu.c index e129f8c8b5b..3bd005bb04a 100644 --- a/board/st/common/stm32mp_dfu.c +++ b/board/st/common/stm32mp_dfu.c @@ -11,6 +11,7 @@ #include #include #include +#include #define DFU_ALT_BUF_LEN SZ_1K @@ -211,12 +212,31 @@ int dfu_read_medium_virt(struct dfu_entity *dfu, u64 offset, case 0x1: return dfu_pmic_read(offset, buf, len); } + + if (CONFIG_IS_ENABLED(CMD_STM32PROG) && + dfu->data.virt.dev_num >= STM32PROG_VIRT_FIRST_DEV_NUM) + return stm32prog_read_medium_virt(dfu, offset, buf, len); + *len = 0; return 0; } +int dfu_write_medium_virt(struct dfu_entity *dfu, u64 offset, + void *buf, long *len) +{ + if (CONFIG_IS_ENABLED(CMD_STM32PROG) && + dfu->data.virt.dev_num >= STM32PROG_VIRT_FIRST_DEV_NUM) + return stm32prog_write_medium_virt(dfu, offset, buf, len); + + return -EOPNOTSUPP; +} + int __weak dfu_get_medium_size_virt(struct dfu_entity *dfu, u64 *size) { + if (CONFIG_IS_ENABLED(CMD_STM32PROG) && + dfu->data.virt.dev_num >= STM32PROG_VIRT_FIRST_DEV_NUM) + return stm32prog_get_medium_size_virt(dfu, size); + *size = SZ_1K; return 0; -- cgit v1.2.3 From 8f035f7b48f79460d296824b37b69dd5cc0b9567 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 18 Mar 2020 09:24:55 +0100 Subject: stm32mp: stm32prog: adapt the MTD partitions Dynamically adapt the MTD partitions in NOR/NAND/SPI-NAND when stm32prog command detects in the parsed flash layout files: - a fsbl partition in NOR. - a tee partition in NOR/NAND/SPI-NAND Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/common/stm32mp_mtdparts.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'board') diff --git a/board/st/common/stm32mp_mtdparts.c b/board/st/common/stm32mp_mtdparts.c index 50285110770..9f5897f8c86 100644 --- a/board/st/common/stm32mp_mtdparts.c +++ b/board/st/common/stm32mp_mtdparts.c @@ -4,12 +4,14 @@ */ #include +#include #include #include #include #include #include #include +#include #include #define MTDPARTS_LEN 256 @@ -66,7 +68,7 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) static char parts[3 * MTDPARTS_LEN + 1]; static char ids[MTDIDS_LEN + 1]; static bool mtd_initialized; - bool tee, nor, nand, spinand; + bool tee, nor, nand, spinand, serial; if (mtd_initialized) { *mtdids = ids; @@ -78,10 +80,18 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) nor = false; nand = false; spinand = false; + serial = false; switch (get_bootmode() & TAMP_BOOT_DEVICE_MASK) { case BOOT_SERIAL_UART: case BOOT_SERIAL_USB: + serial = true; + if (CONFIG_IS_ENABLED(CMD_STM32PROG)) { + tee = stm32prog_get_tee_partitions(); + nor = stm32prog_get_fsbl_nor(); + } + nand = true; + spinand = true; break; case BOOT_FLASH_NAND: nand = true; @@ -96,7 +106,7 @@ void board_mtdparts_default(const char **mtdids, const char **mtdparts) break; } - if (CONFIG_IS_ENABLED(OPTEE) && + if (!serial && CONFIG_IS_ENABLED(OPTEE) && tee_find_device(NULL, NULL, NULL, NULL)) tee = true; -- cgit v1.2.3 From cadd1bfd2d92d1aa20dda21b787683977399eac1 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Wed, 22 Apr 2020 14:29:11 +0200 Subject: board: stm32mp1: Keep error led ON in case of low power detection Since commit commit dd2810851eb1 ("stm32mp1: board: support of error led on ed1/ev1 board") the attended behavior was no more respected in case of low power source detection on DK2. The expected behavior is either the error LED keeps blinking for ever, or blinks 2 or 3 times and must stay ON. Reviewed-by: Patrice Chotard Signed-off-by: Patrice Chotard Signed-off-by: Patrick Delaunay --- board/st/stm32mp1/stm32mp1.c | 1 + 1 file changed, 1 insertion(+) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index fe54947c1c7..d83081d9e22 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -311,6 +311,7 @@ static void __maybe_unused led_error_blink(u32 nb_blink) mdelay(125); WATCHDOG_RESET(); } + led_set_state(led, LEDST_ON); } #endif -- cgit v1.2.3 From 0c95295e17b046616457aaed8885a73b595a1ae8 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 22 Apr 2020 14:29:12 +0200 Subject: board: stm32mp1: update management of boot-led Force boot-led ON and no more rely on default-state. This patch avoid device-tree modification for U-Boot. Signed-off-by: Patrick Delaunay --- board/st/stm32mp1/stm32mp1.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index d83081d9e22..20823f511a0 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -255,7 +255,6 @@ int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) #endif /* CONFIG_USB_GADGET */ -#ifdef CONFIG_LED static int get_led(struct udevice **dev, char *led_string) { char *led_name; @@ -281,6 +280,9 @@ static int setup_led(enum led_state_t cmd) struct udevice *dev; int ret; + if (!CONFIG_IS_ENABLED(LED)) + return 0; + ret = get_led(&dev, "u-boot,boot-led"); if (ret) return ret; @@ -288,32 +290,29 @@ static int setup_led(enum led_state_t cmd) ret = led_set_state(dev, cmd); return ret; } -#endif static void __maybe_unused led_error_blink(u32 nb_blink) { -#ifdef CONFIG_LED int ret; struct udevice *led; u32 i; -#endif if (!nb_blink) return; -#ifdef CONFIG_LED - ret = get_led(&led, "u-boot,error-led"); - if (!ret) { - /* make u-boot,error-led blinking */ - /* if U32_MAX and 125ms interval, for 17.02 years */ - for (i = 0; i < 2 * nb_blink; i++) { - led_set_state(led, LEDST_TOGGLE); - mdelay(125); - WATCHDOG_RESET(); + if (CONFIG_IS_ENABLED(LED)) { + ret = get_led(&led, "u-boot,error-led"); + if (!ret) { + /* make u-boot,error-led blinking */ + /* if U32_MAX and 125ms interval, for 17.02 years */ + for (i = 0; i < 2 * nb_blink; i++) { + led_set_state(led, LEDST_TOGGLE); + mdelay(125); + WATCHDOG_RESET(); + } + led_set_state(led, LEDST_ON); } - led_set_state(led, LEDST_ON); } -#endif /* infinite: the boot process must be stopped */ if (nb_blink == U32_MAX) @@ -646,6 +645,8 @@ int board_init(void) if (CONFIG_IS_ENABLED(LED)) led_default_state(); + setup_led(LEDST_ON); + return 0; } @@ -700,9 +701,7 @@ int board_late_init(void) void board_quiesce_devices(void) { -#ifdef CONFIG_LED setup_led(LEDST_OFF); -#endif } /* eth init function : weak called in eqos driver */ -- cgit v1.2.3 From 055065a8acfb51b2aed415c62271ac3d5d34b641 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 22 Apr 2020 14:29:13 +0200 Subject: board: stm32mp1: gt9147 IRQ before reset on EV1 Software workaround for I2C issue on EV1 board, configure the IRQ line for touchscreen before LCD reset to fix the used I2C address. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/stm32mp1/stm32mp1.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 20823f511a0..62b648f6e47 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -616,6 +616,38 @@ static bool board_is_dk2(void) } #endif +static bool board_is_ev1(void) +{ + if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) && + (of_machine_is_compatible("st,stm32mp157a-ev1") || + of_machine_is_compatible("st,stm32mp157c-ev1") || + of_machine_is_compatible("st,stm32mp157d-ev1") || + of_machine_is_compatible("st,stm32mp157f-ev1"))) + return true; + + return false; +} + +/* touchscreen driver: only used for pincontrol configuration */ +static const struct udevice_id goodix_ids[] = { + { .compatible = "goodix,gt9147", }, + { } +}; + +U_BOOT_DRIVER(goodix) = { + .name = "goodix", + .id = UCLASS_NOP, + .of_match = goodix_ids, +}; + +static void board_ev1_init(void) +{ + struct udevice *dev; + + /* configure IRQ line on EV1 for touchscreen before LCD reset */ + uclass_get_device_by_driver(UCLASS_NOP, DM_GET_DRIVER(goodix), &dev); +} + /* board dependent setup after realloc */ int board_init(void) { @@ -633,6 +665,9 @@ int board_init(void) board_key_check(); + if (board_is_ev1()) + board_ev1_init(); + #ifdef CONFIG_DM_REGULATOR if (board_is_dk2()) dk2_i2c1_fix(); -- cgit v1.2.3 From 99f6743d6323c7cfa00a2517896aaf0af4f6a88e Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 22 Apr 2020 14:29:14 +0200 Subject: board: stm32mp1: set environment variable fdtfile For booting Linux in the generic distro mechanism and support of FDTDIR in extlinux.conf , cmd/pxe.c retrieves the FDT file name from "fdtfile" environment variable. Dynamically build this variable with compatible of STMicroelectronics boards. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/stm32mp1/stm32mp1.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 62b648f6e47..c64f20ab086 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -699,10 +699,19 @@ int board_late_init(void) fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", &fdt_compat_len); if (fdt_compat && fdt_compat_len) { - if (strncmp(fdt_compat, "st,", 3) != 0) + if (strncmp(fdt_compat, "st,", 3) != 0) { env_set("board_name", fdt_compat); - else + } else { + char dtb_name[256]; + int buf_len = sizeof(dtb_name); + env_set("board_name", fdt_compat + 3); + + strncpy(dtb_name, fdt_compat + 3, buf_len); + buf_len -= strlen(fdt_compat + 3); + strncat(dtb_name, ".dtb", buf_len); + env_set("fdtfile", dtb_name); + } } ret = uclass_get_device_by_driver(UCLASS_MISC, DM_GET_DRIVER(stm32mp_bsec), -- cgit v1.2.3 From 3cab9aae456d918b2e3e9b672f27590de829dea6 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 22 Apr 2020 14:29:15 +0200 Subject: board: stm32mp1: remove bootdelay configuration for usb or serial boot It is not allowed to change the user setting of bootdelay, so remove the check of the boot-source to disable it dynamically in board_late_init() Signed-off-by: Patrick Delaunay --- board/st/stm32mp1/stm32mp1.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index c64f20ab086..6873165a0f8 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -687,7 +687,6 @@ int board_init(void) int board_late_init(void) { - char *boot_device; #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG const void *fdt_compat; int fdt_compat_len; @@ -735,11 +734,6 @@ int board_late_init(void) board_check_usb_power(); #endif /* CONFIG_ADC */ - /* Check the boot-source to disable bootdelay */ - boot_device = env_get("boot_device"); - if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb")) - env_set("bootdelay", "0"); - return 0; } -- cgit v1.2.3 From 5ef642c1731f2967beb1c96d94e76ef3c07a9ca2 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Wed, 22 Apr 2020 14:29:16 +0200 Subject: board: stm32mp1: add timeout for I/O compensation ready This patch avoids infinite loop when I/O compensation failed, it adds a 1s timeout to detect error. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- board/st/stm32mp1/stm32mp1.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index 6873165a0f8..dcbfcc1bcb3 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -463,10 +464,10 @@ static void sysconf_init(void) struct udevice *pwr_dev; struct udevice *pwr_reg; struct udevice *dev; - int ret; u32 otp = 0; #endif - u32 bootr; + int ret; + u32 bootr, val; syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG); @@ -543,8 +544,15 @@ static void sysconf_init(void) */ writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR); - while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY)) - ; + /* poll until ready (1s timeout) */ + ret = readl_poll_timeout(syscfg + SYSCFG_CMPCR, val, + val & SYSCFG_CMPCR_READY, + 1000000); + if (ret) { + pr_err("SYSCFG: I/O compensation failed, timeout.\n"); + led_error_blink(10); + } + clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL); #endif } -- cgit v1.2.3 From 5eff168470a353f3397a0bf43e87c8830fe5bbbd Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 30 Apr 2020 18:41:05 +0200 Subject: stm32mp1: Fix warning display when 1.5A power supply is used On DK1/2 board, when a 1.5A power supply is detected, a warning message is displayed. In this message, "1.5mA" is displayed instead of "1.5A". Signed-off-by: Patrice Chotard Reviewed-by: Patrick Delaunay --- board/st/stm32mp1/stm32mp1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'board') diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c index dcbfcc1bcb3..33cb7f6c4d0 100644 --- a/board/st/stm32mp1/stm32mp1.c +++ b/board/st/stm32mp1/stm32mp1.c @@ -431,7 +431,7 @@ static int board_check_usb_power(void) if (max_uV > USB_WARNING_LOW_THRESHOLD_UV && max_uV <= USB_START_LOW_THRESHOLD_UV && min_uV <= USB_LOW_THRESHOLD_UV) { - pr_err("* WARNING 1.5mA power supply detected *\n"); + pr_err("* WARNING 1.5A power supply detected *\n"); nb_blink = 3; } -- cgit v1.2.3 From 92ca0f7446c5948f364bfb3377f9e08fad7ff857 Mon Sep 17 00:00:00 2001 From: Marek Vasut Date: Wed, 29 Apr 2020 15:08:38 +0200 Subject: ARM: dts: stm32: Synchronize DDR setttings on DH SoMs Add custom DDR DRAM settings for the DHCOR and DHCOM SoMs and put them into use by the board file instead of the default ones. These new DRAM settings are a better fit for the SoMs. Signed-off-by: Marek Vasut Cc: Patrick Delaunay Cc: Patrice Chotard Reviewed-by: Patrick Delaunay --- board/dhelectronics/dh_stm32mp1/board.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'board') diff --git a/board/dhelectronics/dh_stm32mp1/board.c b/board/dhelectronics/dh_stm32mp1/board.c index ec1edd5c688..85d56f6082b 100644 --- a/board/dhelectronics/dh_stm32mp1/board.c +++ b/board/dhelectronics/dh_stm32mp1/board.c @@ -177,12 +177,16 @@ static void board_get_coding_straps(void) int board_stm32mp1_ddr_config_name_match(struct udevice *dev, const char *name) { + if (ddr3code == 1 && + !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x1gb-533mhz")) + return 0; + if (ddr3code == 2 && - !strcmp(name, "st,ddr3-1066-888-bin-g-1x4gb-533mhz")) + !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x2gb-533mhz")) return 0; if (ddr3code == 3 && - !strcmp(name, "st,ddr3-1066-888-bin-g-2x4gb-533mhz")) + !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x4gb-533mhz")) return 0; return -EINVAL; -- cgit v1.2.3