2020-03-18 08:22:44 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020, STMicroelectronics - All Rights Reserved
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-03-18 08:24:55 +00:00
|
|
|
#include <dfu.h>
|
2020-03-18 08:22:44 +00:00
|
|
|
#include <dm.h>
|
|
|
|
#include <env.h>
|
|
|
|
#include <env_internal.h>
|
2020-11-06 18:02:00 +00:00
|
|
|
#include <log.h>
|
2020-03-18 08:22:44 +00:00
|
|
|
#include <mtd.h>
|
|
|
|
#include <mtd_node.h>
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
2020-03-18 08:22:49 +00:00
|
|
|
#include <tee.h>
|
2021-07-26 09:21:36 +00:00
|
|
|
#endif
|
2020-03-18 08:24:55 +00:00
|
|
|
#include <asm/arch/stm32prog.h>
|
2020-03-18 08:22:53 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-03-18 08:22:44 +00:00
|
|
|
|
|
|
|
#define MTDPARTS_LEN 256
|
|
|
|
#define MTDIDS_LEN 128
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get a global data pointer
|
|
|
|
*/
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
/**
|
2020-03-18 08:22:47 +00:00
|
|
|
* update the variables "mtdids" and "mtdparts" with boot, tee and user strings
|
2020-03-18 08:22:44 +00:00
|
|
|
*/
|
2020-03-18 08:22:53 +00:00
|
|
|
static void board_set_mtdparts(const char *dev,
|
2020-03-18 08:22:44 +00:00
|
|
|
char *mtdids,
|
2020-03-18 08:22:47 +00:00
|
|
|
char *mtdparts,
|
|
|
|
const char *boot,
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
2020-03-18 08:22:47 +00:00
|
|
|
const char *tee,
|
2021-07-26 09:21:36 +00:00
|
|
|
#endif
|
2020-03-18 08:22:47 +00:00
|
|
|
const char *user)
|
2020-03-18 08:22:44 +00:00
|
|
|
{
|
2020-03-18 08:22:47 +00:00
|
|
|
/* mtdids: "<dev>=<dev>, ...." */
|
|
|
|
if (mtdids[0] != '\0')
|
|
|
|
strcat(mtdids, ",");
|
|
|
|
strcat(mtdids, dev);
|
|
|
|
strcat(mtdids, "=");
|
|
|
|
strcat(mtdids, dev);
|
|
|
|
|
|
|
|
/* mtdparts: "mtdparts=<dev>:<mtdparts_<dev>>;..." */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
2020-03-18 08:22:49 +00:00
|
|
|
if (tee) {
|
2020-03-18 08:22:47 +00:00
|
|
|
strncat(mtdparts, tee, MTDPARTS_LEN);
|
|
|
|
strncat(mtdparts, ",", MTDPARTS_LEN);
|
2020-03-18 08:22:44 +00:00
|
|
|
}
|
2021-07-26 09:21:36 +00:00
|
|
|
#endif
|
2020-03-18 08:22:47 +00:00
|
|
|
|
|
|
|
strncat(mtdparts, user, MTDPARTS_LEN);
|
2020-03-18 08:22:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-07-26 09:21:36 +00:00
|
|
|
bool nor, nand, spinand, serial;
|
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
|
|
|
bool tee = false;
|
|
|
|
#endif
|
2020-03-18 08:22:44 +00:00
|
|
|
|
|
|
|
if (mtd_initialized) {
|
|
|
|
*mtdids = ids;
|
|
|
|
*mtdparts = parts;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-03-18 08:22:53 +00:00
|
|
|
nor = false;
|
|
|
|
nand = false;
|
|
|
|
spinand = false;
|
2020-03-18 08:24:55 +00:00
|
|
|
serial = false;
|
2020-03-18 08:22:53 +00:00
|
|
|
|
|
|
|
switch (get_bootmode() & TAMP_BOOT_DEVICE_MASK) {
|
|
|
|
case BOOT_SERIAL_UART:
|
|
|
|
case BOOT_SERIAL_USB:
|
2020-03-18 08:24:55 +00:00
|
|
|
serial = true;
|
|
|
|
if (CONFIG_IS_ENABLED(CMD_STM32PROG)) {
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
2020-03-18 08:24:55 +00:00
|
|
|
tee = stm32prog_get_tee_partitions();
|
2021-07-26 09:21:36 +00:00
|
|
|
#endif
|
2020-03-18 08:24:55 +00:00
|
|
|
nor = stm32prog_get_fsbl_nor();
|
|
|
|
}
|
|
|
|
nand = true;
|
|
|
|
spinand = true;
|
2020-03-18 08:22:53 +00:00
|
|
|
break;
|
|
|
|
case BOOT_FLASH_NAND:
|
|
|
|
nand = true;
|
|
|
|
break;
|
|
|
|
case BOOT_FLASH_SPINAND:
|
|
|
|
spinand = true;
|
|
|
|
break;
|
|
|
|
case BOOT_FLASH_NOR:
|
|
|
|
nor = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
2021-09-02 09:56:17 +00:00
|
|
|
if (!serial && tee_find_device(NULL, NULL, NULL, NULL))
|
2020-03-18 08:22:47 +00:00
|
|
|
tee = true;
|
2021-07-26 09:21:36 +00:00
|
|
|
#endif
|
2020-03-18 08:22:47 +00:00
|
|
|
|
2020-03-18 08:22:44 +00:00
|
|
|
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)) {
|
2020-11-06 18:02:00 +00:00
|
|
|
log_debug("mtd device = %s\n", dev->name);
|
2020-03-18 08:22:44 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 10:49:28 +00:00
|
|
|
if (nand) {
|
2020-03-18 08:22:53 +00:00
|
|
|
mtd = get_mtd_device_nm("nand0");
|
|
|
|
if (!IS_ERR_OR_NULL(mtd)) {
|
|
|
|
board_set_mtdparts("nand0", ids, parts,
|
2021-02-25 10:49:28 +00:00
|
|
|
CONFIG_MTDPARTS_NAND0_BOOT,
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
|
|
|
!nor && tee ? CONFIG_MTDPARTS_NAND0_TEE : NULL,
|
|
|
|
#endif
|
2020-03-18 08:22:53 +00:00
|
|
|
"-(UBI)");
|
|
|
|
put_mtd_device(mtd);
|
|
|
|
}
|
2020-03-18 08:22:44 +00:00
|
|
|
}
|
|
|
|
|
2021-02-25 10:49:28 +00:00
|
|
|
if (spinand) {
|
2020-03-18 08:22:53 +00:00
|
|
|
mtd = get_mtd_device_nm("spi-nand0");
|
|
|
|
if (!IS_ERR_OR_NULL(mtd)) {
|
|
|
|
board_set_mtdparts("spi-nand0", ids, parts,
|
2021-02-25 10:49:28 +00:00
|
|
|
CONFIG_MTDPARTS_SPINAND0_BOOT,
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
|
|
|
!nor && tee ? CONFIG_MTDPARTS_SPINAND0_TEE : NULL,
|
|
|
|
#endif
|
2020-03-18 08:22:53 +00:00
|
|
|
"-(UBI)");
|
|
|
|
put_mtd_device(mtd);
|
|
|
|
}
|
2020-03-18 08:22:44 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 08:22:53 +00:00
|
|
|
if (nor) {
|
|
|
|
if (!uclass_get_device(UCLASS_SPI_FLASH, 0, &dev)) {
|
|
|
|
board_set_mtdparts("nor0", ids, parts,
|
2021-02-25 10:49:28 +00:00
|
|
|
CONFIG_MTDPARTS_NOR0_BOOT,
|
2021-07-26 09:21:36 +00:00
|
|
|
#ifdef CONFIG_STM32MP15x_STM32IMAGE
|
|
|
|
tee ? CONFIG_MTDPARTS_NOR0_TEE : NULL,
|
|
|
|
#endif
|
2020-03-18 08:22:53 +00:00
|
|
|
"-(nor_user)");
|
|
|
|
}
|
|
|
|
}
|
2020-03-18 08:22:44 +00:00
|
|
|
|
|
|
|
mtd_initialized = true;
|
|
|
|
*mtdids = ids;
|
|
|
|
*mtdparts = parts;
|
2020-11-06 18:02:00 +00:00
|
|
|
log_debug("mtdids=%s & mtdparts=%s\n", ids, parts);
|
2020-03-18 08:22:44 +00:00
|
|
|
}
|