boards/risc-v: fixes SPI Flash for MCUBoot usage
Adds partitions required for MCUBoot usage and a sample defconfig. Signed-off-by: Filipe Cavalcanti <filipe.cavalcanti@espressif.com>
This commit is contained in:
parent
a7cd6bb401
commit
8c932b50fb
5 changed files with 349 additions and 57 deletions
|
|
@ -43,9 +43,7 @@
|
|||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/mtd/configdata.h>
|
||||
#include <nuttx/fs/nxffs.h>
|
||||
#ifdef CONFIG_BCH
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
#endif
|
||||
#include <nuttx/fs/partition.h>
|
||||
|
||||
#include "espressif/esp_spiflash.h"
|
||||
#include "espressif/esp_spiflash_mtd.h"
|
||||
|
|
@ -64,14 +62,82 @@
|
|||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
static int init_ota_partitions(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
static const struct partition_s g_ota_partition_table[] =
|
||||
{
|
||||
{
|
||||
.name = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_DEVPATH,
|
||||
.index = 0,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
},
|
||||
{
|
||||
.name = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_DEVPATH,
|
||||
.index = 1,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
},
|
||||
{
|
||||
.name = CONFIG_ESPRESSIF_OTA_SCRATCH_DEVPATH,
|
||||
.index = 2,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_SCRATCH_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SCRATCH_SIZE,
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: init_ota_partitions
|
||||
*
|
||||
* Description:
|
||||
* Initialize partitions that are dedicated to firmware OTA update.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
static int init_ota_partitions(void)
|
||||
{
|
||||
struct mtd_dev_s *mtd;
|
||||
int ret = OK;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems(g_ota_partition_table); ++i)
|
||||
{
|
||||
const struct partition_s *part = &g_ota_partition_table[i];
|
||||
mtd = esp_spiflash_alloc_mtdpart(part->firstblock, part->blocksize);
|
||||
|
||||
ret = register_mtddriver(part->name, mtd, 0755, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: register_mtddriver %s failed: %d\n",
|
||||
part->name, ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: setup_smartfs
|
||||
*
|
||||
|
|
@ -125,7 +191,8 @@ static int setup_smartfs(int smartn, struct mtd_dev_s *mtd,
|
|||
ret = nx_mount(path, mnt_pt, "smartfs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n", ret);
|
||||
syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n",
|
||||
ret);
|
||||
if (ret == -ENODEV)
|
||||
{
|
||||
syslog(LOG_WARNING, "Smartfs seems unformatted. "
|
||||
|
|
@ -224,7 +291,8 @@ static int setup_spiffs(const char *path, struct mtd_dev_s *mtd,
|
|||
ret = nx_mount(path, mnt_pt, "spiffs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n", ret);
|
||||
syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -265,7 +333,8 @@ static int setup_nxffs(struct mtd_dev_s *mtd, const char *mnt_pt)
|
|||
ret = nx_mount(NULL, mnt_pt, "nxffs", 0, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n", ret);
|
||||
syslog(LOG_ERR, "ERROR: Failed to mount the FS volume: %d\n",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -297,7 +366,7 @@ static int init_storage_partition(void)
|
|||
CONFIG_ESPRESSIF_STORAGE_MTD_SIZE);
|
||||
if (!mtd)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to alloc MTD partition of SPI Flash\n");
|
||||
syslog(LOG_ERR, "ERROR: Fail to alloc MTD partition of SPI Flash\n");
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
|
|
@ -333,7 +402,8 @@ static int init_storage_partition(void)
|
|||
#elif defined (CONFIG_ESPRESSIF_SPIFLASH_SPIFFS)
|
||||
|
||||
const char *path = "/dev/espflash";
|
||||
ret = setup_spiffs(path, mtd, CONFIG_ESPRESSIF_SPIFLASH_FS_MOUNT_PT, 0755);
|
||||
ret = setup_spiffs(path, mtd, CONFIG_ESPRESSIF_SPIFLASH_FS_MOUNT_PT,
|
||||
0755);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to setup spiffs\n");
|
||||
|
|
@ -379,12 +449,6 @@ static int init_storage_partition(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret = register_mtddriver("/dev/mtdblock0", mtd, 0755, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to register MTD mtdblock0: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
|
|
@ -415,6 +479,14 @@ int board_spiflash_init(void)
|
|||
|
||||
esp_spiflash_init();
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
ret = init_ota_partitions();
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = init_storage_partition();
|
||||
if (ret < 0)
|
||||
{
|
||||
|
|
@ -423,4 +495,3 @@ int board_spiflash_init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,83 @@
|
|||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_NDEBUG is not set
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
CONFIG_ALLOW_BSD_COMPONENTS=y
|
||||
CONFIG_ARCH="risc-v"
|
||||
CONFIG_ARCH_BOARD="esp32c3-generic"
|
||||
CONFIG_ARCH_BOARD_COMMON=y
|
||||
CONFIG_ARCH_BOARD_ESP32C3_GENERIC=y
|
||||
CONFIG_ARCH_CHIP="esp32c3"
|
||||
CONFIG_ARCH_CHIP_ESP32C3_GENERIC=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=1536
|
||||
CONFIG_ARCH_RISCV=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=15000
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DRIVERS_IEEE80211=y
|
||||
CONFIG_DRIVERS_WIRELESS=y
|
||||
CONFIG_ESPRESSIF_BOOTLOADER_MCUBOOT=y
|
||||
CONFIG_ESPRESSIF_SPIFLASH=y
|
||||
CONFIG_ESPRESSIF_SPIFLASH_SPIFFS=y
|
||||
CONFIG_ESPRESSIF_WIFI=y
|
||||
CONFIG_EXAMPLES_MCUBOOT_SLOT_CONFIRM=y
|
||||
CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT=y
|
||||
CONFIG_EXAMPLES_RANDOM=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=2048
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INIT_STACKSIZE=8192
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_IOB_THROTTLE=24
|
||||
CONFIG_LIBC_PERROR_STDOUT=y
|
||||
CONFIG_LIBC_STRERROR=y
|
||||
CONFIG_NETDB_DNSCLIENT=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETDEV_PHY_IOCTL=y
|
||||
CONFIG_NETDEV_WIRELESS_IOCTL=y
|
||||
CONFIG_NETDEV_WORK_THREAD=y
|
||||
CONFIG_NETUTILS_CJSON=y
|
||||
CONFIG_NETUTILS_WEBCLIENT=y
|
||||
CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
CONFIG_NET_TCP_WRITE_BUFFERS=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_MOTD=y
|
||||
CONFIG_NSH_MOTD_STRING="This is MCUBoot Update Agent image"
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NSH_STRERROR=y
|
||||
CONFIG_PREALLOC_TIMERS=0
|
||||
CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_BACKTRACE=y
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_START_DAY=29
|
||||
CONFIG_START_MONTH=11
|
||||
CONFIG_START_YEAR=2019
|
||||
CONFIG_SYSTEM_DHCPC_RENEW=y
|
||||
CONFIG_SYSTEM_DUMPSTACK=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_PING=y
|
||||
CONFIG_TESTING_GETPRIME=y
|
||||
CONFIG_TESTING_OSTEST=y
|
||||
CONFIG_TLS_TASK_NELEM=4
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_WIRELESS=y
|
||||
CONFIG_WIRELESS_WAPI=y
|
||||
CONFIG_WIRELESS_WAPI_CMDTOOL=y
|
||||
CONFIG_WIRELESS_WAPI_INITCONF=y
|
||||
|
|
@ -43,9 +43,7 @@
|
|||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/mtd/configdata.h>
|
||||
#include <nuttx/fs/nxffs.h>
|
||||
#ifdef CONFIG_BCH
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
#endif
|
||||
#include <nuttx/fs/partition.h>
|
||||
|
||||
#include "espressif/esp_spiflash.h"
|
||||
#include "espressif/esp_spiflash_mtd.h"
|
||||
|
|
@ -60,13 +58,6 @@
|
|||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct ota_partition_s
|
||||
{
|
||||
uint32_t offset; /* Partition offset from the beginning of MTD */
|
||||
uint32_t size; /* Partition size in bytes */
|
||||
const char *devpath; /* Partition device path */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
|
@ -80,22 +71,25 @@ static int init_ota_partitions(void);
|
|||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
static const struct ota_partition_s g_ota_partition_table[] =
|
||||
static const struct partition_s g_ota_partition_table[] =
|
||||
{
|
||||
{
|
||||
.offset = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.size = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_DEVPATH
|
||||
.name = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_DEVPATH,
|
||||
.index = 0,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.size = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
.devpath = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_DEVPATH
|
||||
.name = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_DEVPATH,
|
||||
.index = 1,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
},
|
||||
{
|
||||
.offset = CONFIG_ESPRESSIF_OTA_SCRATCH_OFFSET,
|
||||
.size = CONFIG_ESPRESSIF_OTA_SCRATCH_SIZE,
|
||||
.devpath = CONFIG_ESPRESSIF_OTA_SCRATCH_DEVPATH
|
||||
.name = CONFIG_ESPRESSIF_OTA_SCRATCH_DEVPATH,
|
||||
.index = 2,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_SCRATCH_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SCRATCH_SIZE,
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
|
@ -127,14 +121,14 @@ static int init_ota_partitions(void)
|
|||
|
||||
for (i = 0; i < nitems(g_ota_partition_table); ++i)
|
||||
{
|
||||
const struct ota_partition_s *part = &g_ota_partition_table[i];
|
||||
mtd = esp_spiflash_alloc_mtdpart(part->offset, part->size);
|
||||
const struct partition_s *part = &g_ota_partition_table[i];
|
||||
mtd = esp_spiflash_alloc_mtdpart(part->firstblock, part->blocksize);
|
||||
|
||||
ret = register_mtddriver(part->devpath, mtd, 0755, NULL);
|
||||
ret = register_mtddriver(part->name, mtd, 0755, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: register_mtddriver %s failed: %d\n",
|
||||
part->devpath, ret);
|
||||
syslog(LOG_ERR, "ERROR: register_mtddriver %s failed: %d\n",
|
||||
part->name, ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
@ -451,12 +445,6 @@ static int init_storage_partition(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret = register_mtddriver("/dev/mtdblock0", mtd, 0755, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to register MTD mtdblock0: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
|
|
@ -503,4 +491,3 @@ int board_spiflash_init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,85 @@
|
|||
#
|
||||
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||
#
|
||||
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||
# modifications.
|
||||
#
|
||||
# CONFIG_NDEBUG is not set
|
||||
# CONFIG_NSH_ARGCAT is not set
|
||||
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||
CONFIG_ALLOW_BSD_COMPONENTS=y
|
||||
CONFIG_ARCH="risc-v"
|
||||
CONFIG_ARCH_BOARD="esp32c6-devkitc"
|
||||
CONFIG_ARCH_BOARD_COMMON=y
|
||||
CONFIG_ARCH_BOARD_ESP32C6_DEVKITC=y
|
||||
CONFIG_ARCH_CHIP="esp32c6"
|
||||
CONFIG_ARCH_CHIP_ESP32C6=y
|
||||
CONFIG_ARCH_CHIP_ESP32C6WROOM1=y
|
||||
CONFIG_ARCH_INTERRUPTSTACK=2048
|
||||
CONFIG_ARCH_RISCV=y
|
||||
CONFIG_ARCH_STACKDUMP=y
|
||||
CONFIG_BOARDCTL_RESET=y
|
||||
CONFIG_BOARD_LOOPSPERMSEC=15000
|
||||
CONFIG_BUILTIN=y
|
||||
CONFIG_DRIVERS_IEEE80211=y
|
||||
CONFIG_DRIVERS_WIRELESS=y
|
||||
CONFIG_ESPRESSIF_BOOTLOADER_MCUBOOT=y
|
||||
CONFIG_ESPRESSIF_ESP32C6=y
|
||||
CONFIG_ESPRESSIF_SPIFLASH=y
|
||||
CONFIG_ESPRESSIF_SPIFLASH_SPIFFS=y
|
||||
CONFIG_ESPRESSIF_WIFI=y
|
||||
CONFIG_EXAMPLES_MCUBOOT_SLOT_CONFIRM=y
|
||||
CONFIG_EXAMPLES_MCUBOOT_UPDATE_AGENT=y
|
||||
CONFIG_EXAMPLES_RANDOM=y
|
||||
CONFIG_FS_PROCFS=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=2048
|
||||
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||
CONFIG_INIT_STACKSIZE=8192
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_IOB_THROTTLE=24
|
||||
CONFIG_LIBC_PERROR_STDOUT=y
|
||||
CONFIG_LIBC_STRERROR=y
|
||||
CONFIG_NETDB_DNSCLIENT=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETDEV_PHY_IOCTL=y
|
||||
CONFIG_NETDEV_WIRELESS_IOCTL=y
|
||||
CONFIG_NETDEV_WORK_THREAD=y
|
||||
CONFIG_NETUTILS_CJSON=y
|
||||
CONFIG_NETUTILS_WEBCLIENT=y
|
||||
CONFIG_NET_BROADCAST=y
|
||||
CONFIG_NET_ICMP_SOCKET=y
|
||||
CONFIG_NET_TCP=y
|
||||
CONFIG_NET_TCP_DELAYED_ACK=y
|
||||
CONFIG_NET_TCP_WRITE_BUFFERS=y
|
||||
CONFIG_NET_UDP=y
|
||||
CONFIG_NFILE_DESCRIPTORS_PER_BLOCK=6
|
||||
CONFIG_NSH_ARCHINIT=y
|
||||
CONFIG_NSH_BUILTIN_APPS=y
|
||||
CONFIG_NSH_FILEIOSIZE=512
|
||||
CONFIG_NSH_MOTD=y
|
||||
CONFIG_NSH_MOTD_STRING="This is MCUBoot Update Agent image"
|
||||
CONFIG_NSH_READLINE=y
|
||||
CONFIG_NSH_STRERROR=y
|
||||
CONFIG_PREALLOC_TIMERS=0
|
||||
CONFIG_PTHREAD_MUTEX_TYPES=y
|
||||
CONFIG_RR_INTERVAL=200
|
||||
CONFIG_SCHED_BACKTRACE=y
|
||||
CONFIG_SCHED_LPWORK=y
|
||||
CONFIG_SCHED_WAITPID=y
|
||||
CONFIG_SIG_DEFAULT=y
|
||||
CONFIG_START_DAY=29
|
||||
CONFIG_START_MONTH=11
|
||||
CONFIG_START_YEAR=2019
|
||||
CONFIG_SYSTEM_DHCPC_RENEW=y
|
||||
CONFIG_SYSTEM_DUMPSTACK=y
|
||||
CONFIG_SYSTEM_NSH=y
|
||||
CONFIG_SYSTEM_PING=y
|
||||
CONFIG_TESTING_GETPRIME=y
|
||||
CONFIG_TESTING_OSTEST=y
|
||||
CONFIG_TLS_TASK_NELEM=4
|
||||
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||
CONFIG_WIRELESS=y
|
||||
CONFIG_WIRELESS_WAPI=y
|
||||
CONFIG_WIRELESS_WAPI_CMDTOOL=y
|
||||
CONFIG_WIRELESS_WAPI_INITCONF=y
|
||||
|
|
@ -43,9 +43,7 @@
|
|||
#include <nuttx/mtd/mtd.h>
|
||||
#include <nuttx/mtd/configdata.h>
|
||||
#include <nuttx/fs/nxffs.h>
|
||||
#ifdef CONFIG_BCH
|
||||
#include <nuttx/drivers/drivers.h>
|
||||
#endif
|
||||
#include <nuttx/fs/partition.h>
|
||||
|
||||
#include "espressif/esp_spiflash.h"
|
||||
#include "espressif/esp_spiflash_mtd.h"
|
||||
|
|
@ -64,14 +62,81 @@
|
|||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
static int init_ota_partitions(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
static const struct partition_s g_ota_partition_table[] =
|
||||
{
|
||||
{
|
||||
.name = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_DEVPATH,
|
||||
.index = 0,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_PRIMARY_SLOT_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
},
|
||||
{
|
||||
.name = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_DEVPATH,
|
||||
.index = 1,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
|
||||
},
|
||||
{
|
||||
.name = CONFIG_ESPRESSIF_OTA_SCRATCH_DEVPATH,
|
||||
.index = 2,
|
||||
.firstblock = CONFIG_ESPRESSIF_OTA_SCRATCH_OFFSET,
|
||||
.blocksize = CONFIG_ESPRESSIF_OTA_SCRATCH_SIZE,
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: init_ota_partitions
|
||||
*
|
||||
* Description:
|
||||
* Initialize partitions that are dedicated to firmware OTA update.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
static int init_ota_partitions(void)
|
||||
{
|
||||
struct mtd_dev_s *mtd;
|
||||
int ret = OK;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < nitems(g_ota_partition_table); ++i)
|
||||
{
|
||||
const struct partition_s *part = &g_ota_partition_table[i];
|
||||
mtd = esp_spiflash_alloc_mtdpart(part->firstblock, part->blocksize);
|
||||
|
||||
ret = register_mtddriver(part->name, mtd, 0755, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: register_mtddriver %s failed: %d\n",
|
||||
part->name, ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: setup_smartfs
|
||||
*
|
||||
|
|
@ -379,12 +444,6 @@ static int init_storage_partition(void)
|
|||
return ret;
|
||||
}
|
||||
|
||||
ret = register_mtddriver("/dev/mtdblock0", mtd, 0755, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ERROR: Failed to register MTD mtdblock0: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
|
|
@ -415,6 +474,14 @@ int board_spiflash_init(void)
|
|||
|
||||
esp_spiflash_init();
|
||||
|
||||
#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
|
||||
ret = init_ota_partitions();
|
||||
if (ret < 0)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
ret = init_storage_partition();
|
||||
if (ret < 0)
|
||||
{
|
||||
|
|
@ -423,4 +490,3 @@ int board_spiflash_init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue