From a142a1dd908073f85f5324dfb2dba92d25c86891 Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 8 Jun 2023 17:16:40 +0200 Subject: stm32mp: stm32prog: Remove usage of "mtdparts" function Motivation for this patch is to remove usage of function define in cmd/mtdparts.c interface, based on env variables mtdids and mtdparts: mtdparts_init() and find_dev_and_part(). See commit 938db6fe5da3 ("cmd: mtdparts: describe as legacy") Now, all MTD devices are populated with their partition's information found in DT, accessible in MTD devices. Use these information to find the wanted partitions, no more need of find_dev_and_part() usage. Signed-off-by: Patrice Chotard Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 42 +++++++++++-------------- 1 file changed, 19 insertions(+), 23 deletions(-) (limited to 'arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c') diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index 6f3641ccf57..241ad40abb7 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -208,11 +208,6 @@ static int optee_ta_invoke(struct stm32prog_data *data, int cmd, int type, return rc; } -/* partition handling routines : CONFIG_CMD_MTDPARTS */ -int mtdparts_init(void); -int find_dev_and_part(const char *id, struct mtd_device **dev, - u8 *part_num, struct part_info **part); - char *stm32prog_get_error(struct stm32prog_data *data) { static const char error_msg[] = "Unspecified"; @@ -741,6 +736,7 @@ static int init_device(struct stm32prog_data *data, struct mmc *mmc = NULL; struct blk_desc *block_dev = NULL; struct mtd_info *mtd = NULL; + struct mtd_info *partition; char mtd_id[16]; int part_id; int ret; @@ -749,6 +745,7 @@ static int init_device(struct stm32prog_data *data, u64 part_addr, part_size; bool part_found; const char *part_name; + u8 i; switch (dev->target) { case STM32PROG_MMC: @@ -793,10 +790,11 @@ static int init_device(struct stm32prog_data *data, stm32prog_err("unknown device type = %d", dev->target); return -ENODEV; } + /* register partitions with MTDIDS/MTDPARTS or OF fallback */ + mtd_probe_devices(); get_mtd_by_target(mtd_id, dev->target, dev->dev_id); log_debug("%s\n", mtd_id); - mtdparts_init(); mtd = get_mtd_device_nm(mtd_id); if (IS_ERR(mtd)) { stm32prog_err("MTD device %s not found", mtd_id); @@ -943,25 +941,23 @@ static int init_device(struct stm32prog_data *data, } if (IS_ENABLED(CONFIG_MTD) && mtd) { - char mtd_part_id[32]; - struct part_info *mtd_part; - struct mtd_device *mtd_dev; - u8 part_num; - - sprintf(mtd_part_id, "%s,%d", mtd_id, - part->part_id - 1); - ret = find_dev_and_part(mtd_part_id, &mtd_dev, - &part_num, &mtd_part); - if (ret != 0) { - stm32prog_err("%s (0x%x): Invalid MTD partition %s", - part->name, part->id, - mtd_part_id); + i = 0; + list_for_each_entry(partition, &mtd->partitions, node) { + if ((part->part_id - 1) == i) { + part_found = true; + break; + } + i++; + } + if (part_found) { + part_addr = partition->offset; + part_size = partition->size; + part_name = partition->name; + } else { + stm32prog_err("%s (0x%x):Couldn't find part %d on device mtd %s", + part->name, part->id, part->part_id, mtd_id); return -ENODEV; } - part_addr = mtd_part->offset; - part_size = mtd_part->size; - part_name = mtd_part->name; - part_found = true; } /* no partition for this device */ -- cgit v1.2.3 From 5d3abc6023bfe6cfbfcdc39445793a01ddfd00db Mon Sep 17 00:00:00 2001 From: Patrice Chotard Date: Thu, 8 Jun 2023 17:16:46 +0200 Subject: stm32mp: stm32prog: Remove tee_detected from stm32prog_data struct As stm32prog_get_tee_partitions() is no more used, remove tee_detected boolean from stm32prog_data struct and all code using it. Signed-off-by: Patrice Chotard Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c') diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index 241ad40abb7..0cdc14dd5bc 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -995,9 +995,6 @@ static int treat_partition_list(struct stm32prog_data *data) INIT_LIST_HEAD(&data->dev[j].part_list); } -#ifdef CONFIG_STM32MP15x_STM32IMAGE - data->tee_detected = false; -#endif data->fsbl_nor_detected = false; for (i = 0; i < data->part_nb; i++) { part = &data->part_array[i]; @@ -1049,14 +1046,6 @@ static int treat_partition_list(struct stm32prog_data *data) !strncmp(part->name, "fsbl", 4)) data->fsbl_nor_detected = true; /* fallthrough */ - case STM32PROG_NAND: - case STM32PROG_SPI_NAND: -#ifdef CONFIG_STM32MP15x_STM32IMAGE - if (!data->tee_detected && - !strncmp(part->name, "tee", 3)) - data->tee_detected = true; - break; -#endif default: break; } -- cgit v1.2.3 From 82a4a255aa4898cbea16677d7e5b34cc83345f51 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 8 Jun 2023 17:09:54 +0200 Subject: stm32mp: stm32prog: Add support of ENV partition type Add support of "ENV" partition type in flashlayout to select the "u-boot-env" GUID, with PARTITION_U_BOOT_ENVIRONMENT = 3de21764-95bd-54bd-a5c3-4abe786f38a8, that mean a partition holding a U-Boot environment introduced by commit c0364ce1c695 ("doc/README.gpt: define partition type GUID for U-Boot environment")' Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c') diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index 0cdc14dd5bc..bddd7a4462c 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -425,6 +425,8 @@ static int parse_type(struct stm32prog_data *data, } } else if (!strcmp(p, "FIP")) { part->part_type = PART_FIP; + } else if (!strcmp(p, "ENV")) { + part->part_type = PART_ENV; } else if (!strcmp(p, "System")) { part->part_type = PART_SYSTEM; } else if (!strcmp(p, "FileSystem")) { @@ -1115,6 +1117,9 @@ static int create_gpt_partitions(struct stm32prog_data *data) case PART_BINARY: type_str = LINUX_RESERVED_UUID; break; + case PART_ENV: + type_str = "u-boot-env"; + break; case PART_FIP: type_str = FIP_TYPE_UUID; break; -- cgit v1.2.3 From 3a67b61ca04cea80e86008d83d6d996734609dfe Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 8 Jun 2023 17:09:55 +0200 Subject: stm32mp: stm32prog: Add support of ESP partition type Add support of "ESP" partition type in flashlayout to select the "EFI System Partition", associated to U-Boot "system" partition type guid, PARTITION_SYSTEM_GUID = C12A7328-F81F-11d2-BA4B-00A0C93EC93B. This partition is the bootable partition for efi boot. Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c') diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index bddd7a4462c..030614c14dd 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -429,6 +429,8 @@ static int parse_type(struct stm32prog_data *data, part->part_type = PART_ENV; } else if (!strcmp(p, "System")) { part->part_type = PART_SYSTEM; + } else if (!strcmp(p, "ESP")) { + part->part_type = PART_ESP; } else if (!strcmp(p, "FileSystem")) { part->part_type = PART_FILESYSTEM; } else if (!strcmp(p, "RawImage")) { @@ -1123,7 +1125,11 @@ static int create_gpt_partitions(struct stm32prog_data *data) case PART_FIP: type_str = FIP_TYPE_UUID; break; - default: + case PART_ESP: + /* EFI System Partition */ + type_str = "system"; + break; + default: /* PART_FILESYSTEM or PART_SYSTEM for distro */ type_str = "linux"; break; } -- cgit v1.2.3 From dac5b065125cc1b6733097b826cc3cd322a670a0 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 8 Jun 2023 17:09:56 +0200 Subject: stm32mp: stm32prog: Add support of FWU_MDATA partition type Add support of "FWU_MDATA" partition type in flashlayout to select the TF-A firmware update metadata partition type guid, associated to U-Boot "system" partition type guid, FWU_MDATA_GUID introduced by commit 2eaedc95164f ("FWU: Add FWU metadata structure and driver for accessing metadata") and used in gpt_get_mdata_partitions() for commit 554b38f7a532 ("FWU: Add FWU metadata access driver for GPT partitioned block devices") See also recommendation in FWU-PSA-A_DEN0118_1.0ALP3.pdf 4.1.2 Metadata integration with GPT When embedded in a GPT, each metadata replica occupies a single partition with PartitionTypeGUID = metadata_uuid. UUID = 8a7a84a0-8387-40f6-ab41-a8b9a5a60d23 Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c') diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index 030614c14dd..773bae81f66 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -63,6 +63,12 @@ static const efi_guid_t uuid_mmc[3] = { ROOTFS_MMC2_UUID }; +/* + * GUID value defined in the FWU specification for identification + * of the FWU metadata partition. + */ +#define FWU_MDATA_UUID "8a7a84a0-8387-40f6-ab41-a8b9a5a60d23" + /* FIP type partition UUID used by TF-A*/ #define FIP_TYPE_UUID "19D5DF83-11B0-457B-BE2C-7559C13142A5" @@ -425,6 +431,8 @@ static int parse_type(struct stm32prog_data *data, } } else if (!strcmp(p, "FIP")) { part->part_type = PART_FIP; + } else if (!strcmp(p, "FWU_MDATA")) { + part->part_type = PART_FWU_MDATA; } else if (!strcmp(p, "ENV")) { part->part_type = PART_ENV; } else if (!strcmp(p, "System")) { @@ -1125,6 +1133,9 @@ static int create_gpt_partitions(struct stm32prog_data *data) case PART_FIP: type_str = FIP_TYPE_UUID; break; + case PART_FWU_MDATA: + type_str = FWU_MDATA_UUID; + break; case PART_ESP: /* EFI System Partition */ type_str = "system"; -- cgit v1.2.3 From 09f50c75a18da5a6d949b8bc5510f8ec5693a5b0 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 27 Apr 2023 15:36:36 +0200 Subject: stm32mp: stm32prog: fix OTP read/write error management Avoid to ignore the OTP read/write error and transmits the error to STM32CubeProgrammer. Today the error is only displayed in log error: so the user on HOST thinks the OTP operation is performed. Reported-by: Mickael GARDET Signed-off-by: Patrick Delaunay Fixes: 75ea9e75931c ("stm32mp: stm32prog: add TEE support in stm32prog command") Reviewed-by: Patrice Chotard --- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c') diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index 773bae81f66..1e40bdf0f6c 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -1446,8 +1446,11 @@ int stm32prog_otp_write(struct stm32prog_data *data, u32 offset, u8 *buffer, if (!data->otp_part) { data->otp_part = memalign(CONFIG_SYS_CACHELINE_SIZE, otp_size); - if (!data->otp_part) + if (!data->otp_part) { + stm32prog_err("OTP write issue %d", -ENOMEM); + return -ENOMEM; + } } if (!offset) @@ -1510,6 +1513,8 @@ int stm32prog_otp_read(struct stm32prog_data *data, u32 offset, u8 *buffer, memcpy(buffer, (void *)((uintptr_t)data->otp_part + offset), *size); end_otp_read: + if (result) + stm32prog_err("OTP read issue %d", result); log_debug("%s: result %i\n", __func__, result); return result; @@ -1563,6 +1568,8 @@ int stm32prog_otp_start(struct stm32prog_data *data) free(data->otp_part); data->otp_part = NULL; + if (result) + stm32prog_err("OTP write issue %d", result); log_debug("%s: result %i\n", __func__, result); return result; -- cgit v1.2.3 From bd087f62c9f56bb6610706aeea0825fd55c393e9 Mon Sep 17 00:00:00 2001 From: Patrick Delaunay Date: Thu, 27 Apr 2023 15:36:37 +0200 Subject: stm32mp: stm32prog: use the decimal format by default for offset parsing Change the default base for offset parsing with simple_strtoull(), so offset in flashlayout is coded in base 10 by default, even if string start with '0'. The Octal encoding is not supported. The base 16 is still supported when the '0x' header is detected. This patch solves an unexpected parsing result when the address, provided by decimal value is starting by 0, for example 0x4400 = 00017408 is a invalid with current code. ... P 0x04 fsbl1 Binary mmc0 00017408 tf-a.stm32 .... Signed-off-by: Patrick Delaunay Reviewed-by: Patrice Chotard --- arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c') diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c index 1e40bdf0f6c..9ba94be804e 100644 --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog.c @@ -521,7 +521,7 @@ static int parse_offset(struct stm32prog_data *data, stm32prog_err("Layout line %d: invalid part '%s'", i, p); } else { - part->addr = simple_strtoull(p, &tail, 0); + part->addr = simple_strtoull(p, &tail, 10); if (tail == p || *tail != '\0') { stm32prog_err("Layout line %d: invalid offset '%s'", i, p); -- cgit v1.2.3