1 // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
3 * Copyright (C) 2020, STMicroelectronics - All Rights Reserved
9 #include <env_internal.h>
14 #define MTDPARTS_LEN 256
15 #define MTDIDS_LEN 128
18 * Get a global data pointer
20 DECLARE_GLOBAL_DATA_PTR;
23 * update the variables "mtdids" and "mtdparts" with boot, tee and user strings
25 static void board_get_mtdparts(const char *dev,
32 /* mtdids: "<dev>=<dev>, ...." */
33 if (mtdids[0] != '\0')
39 /* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
40 if (mtdparts[0] != '\0')
41 strncat(mtdparts, ";", MTDPARTS_LEN);
43 strcat(mtdparts, "mtdparts=");
45 strncat(mtdparts, dev, MTDPARTS_LEN);
46 strncat(mtdparts, ":", MTDPARTS_LEN);
49 strncat(mtdparts, boot, MTDPARTS_LEN);
50 strncat(mtdparts, ",", MTDPARTS_LEN);
54 strncat(mtdparts, tee, MTDPARTS_LEN);
55 strncat(mtdparts, ",", MTDPARTS_LEN);
58 strncat(mtdparts, user, MTDPARTS_LEN);
61 void board_mtdparts_default(const char **mtdids, const char **mtdparts)
65 static char parts[3 * MTDPARTS_LEN + 1];
66 static char ids[MTDIDS_LEN + 1];
67 static bool mtd_initialized;
70 if (mtd_initialized) {
76 if (CONFIG_IS_ENABLED(OPTEE) &&
77 tee_find_device(NULL, NULL, NULL, NULL))
80 memset(parts, 0, sizeof(parts));
81 memset(ids, 0, sizeof(ids));
83 /* probe all MTD devices */
84 for (uclass_first_device(UCLASS_MTD, &dev);
86 uclass_next_device(&dev)) {
87 pr_debug("mtd device = %s\n", dev->name);
90 mtd = get_mtd_device_nm("nand0");
91 if (!IS_ERR_OR_NULL(mtd)) {
92 board_get_mtdparts("nand0", ids, parts,
93 CONFIG_MTDPARTS_NAND0_BOOT,
94 tee ? CONFIG_MTDPARTS_NAND0_TEE : NULL,
99 mtd = get_mtd_device_nm("spi-nand0");
100 if (!IS_ERR_OR_NULL(mtd)) {
101 board_get_mtdparts("spi-nand0", ids, parts,
102 CONFIG_MTDPARTS_SPINAND0_BOOT,
103 tee ? CONFIG_MTDPARTS_SPINAND0_TEE : NULL,
108 if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev))
109 board_get_mtdparts("nor0", ids, parts,
110 CONFIG_MTDPARTS_NOR0_BOOT,
111 tee ? CONFIG_MTDPARTS_NOR0_TEE : NULL,
114 mtd_initialized = true;
117 debug("%s:mtdids=%s & mtdparts=%s\n", __func__, ids, parts);