1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2020, STMicroelectronics - All Rights Reserved
9 #include <env_internal.h>
13 #define MTDPARTS_LEN 256
14 #define MTDIDS_LEN 128
17 * Get a global data pointer
19 DECLARE_GLOBAL_DATA_PTR;
22 * update the variables "mtdids" and "mtdparts" with boot, tee and user strings
24 static void board_get_mtdparts(const char *dev,
31 /* mtdids: "<dev>=<dev>, ...." */
32 if (mtdids[0] != '\0')
38 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
39 if (mtdparts[0] != '\0')
40 strncat(mtdparts, ";", MTDPARTS_LEN);
42 strcat(mtdparts, "mtdparts=");
44 strncat(mtdparts, dev, MTDPARTS_LEN);
45 strncat(mtdparts, ":", MTDPARTS_LEN);
48 strncat(mtdparts, boot, MTDPARTS_LEN);
49 strncat(mtdparts, ",", MTDPARTS_LEN);
52 if (CONFIG_IS_ENABLED(STM32MP1_OPTEE) && tee) {
53 strncat(mtdparts, tee, MTDPARTS_LEN);
54 strncat(mtdparts, ",", MTDPARTS_LEN);
57 strncat(mtdparts, user, MTDPARTS_LEN);
60 void board_mtdparts_default(const char **mtdids, const char **mtdparts)
64 static char parts[3 * MTDPARTS_LEN + 1];
65 static char ids[MTDIDS_LEN + 1];
66 static bool mtd_initialized;
69 if (mtd_initialized) {
75 if (CONFIG_IS_ENABLED(STM32MP1_OPTEE))
78 memset(parts, 0, sizeof(parts));
79 memset(ids, 0, sizeof(ids));
81 /* probe all MTD devices */
82 for (uclass_first_device(UCLASS_MTD, &dev);
84 uclass_next_device(&dev)) {
85 pr_debug("mtd device = %s\n", dev->name);
88 mtd = get_mtd_device_nm("nand0");
89 if (!IS_ERR_OR_NULL(mtd)) {
90 board_get_mtdparts("nand0", ids, parts,
91 CONFIG_MTDPARTS_NAND0_BOOT,
92 tee ? CONFIG_MTDPARTS_NAND0_TEE : NULL,
97 mtd = get_mtd_device_nm("spi-nand0");
98 if (!IS_ERR_OR_NULL(mtd)) {
99 board_get_mtdparts("spi-nand0", ids, parts,
100 CONFIG_MTDPARTS_SPINAND0_BOOT,
101 tee ? CONFIG_MTDPARTS_SPINAND0_TEE : NULL,
106 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
107 board_get_mtdparts("nor0", ids, parts,
108 CONFIG_MTDPARTS_NOR0_BOOT,
109 tee ? CONFIG_MTDPARTS_NOR0_TEE : NULL,
112 mtd_initialized = true;
115 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);