risc-v/esp32-c3: Enable the allocation of multiple MTD SPI Flash partitions

This commit is contained in:
Sara Souza
2021-08-03 18:32:09 -03:00
committed by Xiang Xiao
parent d4e59b7e8d
commit 11068fad1b
4 changed files with 33 additions and 21 deletions
+18 -16
View File
@@ -77,9 +77,6 @@
#define SPI_FLASH_ERASED_STATE (0xff)
#define SPI_FLASH_SIZE (4 * 1024 * 1024)
#define ESP32C3_MTD_OFFSET CONFIG_ESP32C3_MTD_OFFSET
#define ESP32C3_MTD_SIZE CONFIG_ESP32C3_MTD_SIZE
#define MTD2PRIV(_dev) ((FAR struct esp32c3_spiflash_s *)_dev)
#define MTD_SIZE(_priv) ((*(_priv)->data)->chip.chip_size)
#define MTD_BLKSIZE(_priv) ((*(_priv)->data)->chip.page_size)
@@ -914,17 +911,19 @@ static int esp32c3_ioctl(struct mtd_dev_s *dev, int cmd,
* Name: esp32c3_spiflash_alloc_mtdpart
*
* Description:
* Allocate SPI Flash MTD.
* Allocate an MTD partition from the ESP32-C3 SPI Flash.
*
* Input Parameters:
* None
* mtd_offset - MTD Partition offset from the base address in SPI Flash.
* mtd_size - Size for the MTD partition.
*
* Returned Value:
* SPI Flash MTD data pointer if success or NULL if fail.
*
****************************************************************************/
FAR struct mtd_dev_s *esp32c3_spiflash_alloc_mtdpart(void)
FAR struct mtd_dev_s *esp32c3_spiflash_alloc_mtdpart(uint32_t mtd_offset,
uint32_t mtd_size)
{
struct esp32c3_spiflash_s *priv = &g_esp32c3_spiflash;
const esp32c3_spiflash_chip_t *chip = &(*priv->data)->chip;
@@ -933,9 +932,9 @@ FAR struct mtd_dev_s *esp32c3_spiflash_alloc_mtdpart(void)
uint32_t startblock;
uint32_t size;
ASSERT((ESP32C3_MTD_OFFSET + ESP32C3_MTD_SIZE) <= chip->chip_size);
ASSERT((ESP32C3_MTD_OFFSET % chip->sector_size) == 0);
ASSERT((ESP32C3_MTD_SIZE % chip->sector_size) == 0);
ASSERT((mtd_offset + mtd_size) <= chip->chip_size);
ASSERT((mtd_offset % chip->sector_size) == 0);
ASSERT((mtd_size % chip->sector_size) == 0);
finfo("ESP32-C3 SPI Flash information:\n");
finfo("\tID = 0x%" PRIx32 "\n", chip->device_id);
@@ -945,16 +944,19 @@ FAR struct mtd_dev_s *esp32c3_spiflash_alloc_mtdpart(void)
finfo("\tSector size = %" PRId32 " KB\n", chip->sector_size / 1024);
finfo("\tBlock size = %" PRId32 " KB\n", chip->block_size / 1024);
#if ESP32C3_MTD_SIZE == 0
size = chip->chip_size - ESP32C3_MTD_OFFSET;
#else
size = ESP32C3_MTD_SIZE;
#endif
if (mtd_size == 0)
{
size = chip->chip_size - mtd_offset;
}
else
{
size = mtd_size;
}
finfo("\tMTD offset = 0x%x\n", ESP32C3_MTD_OFFSET);
finfo("\tMTD offset = 0x%x\n", mtd_offset);
finfo("\tMTD size = 0x%" PRIx32 "\n", size);
startblock = MTD_SIZE2BLK(priv, ESP32C3_MTD_OFFSET);
startblock = MTD_SIZE2BLK(priv, mtd_offset);
blocks = MTD_SIZE2BLK(priv, size);
mtd_part = mtd_partition(&priv->mtd, startblock, blocks);
+5 -3
View File
@@ -66,17 +66,19 @@ struct mtd_dev_s *esp32c3_spiflash_mtd(void);
* Name: esp32c3_spiflash_alloc_mtdpart
*
* Description:
* Alloc ESP32-C3 SPI Flash MTD
* Allocate an MTD partition from the ESP32-C3 SPI Flash.
*
* Input Parameters:
* None
* mtd_offset - MTD Partition offset from the base address in SPI Flash.
* mtd_size - Size for the MTD partition.
*
* Returned Value:
* ESP32-C3 SPI Flash MTD data pointer if success or NULL if fail
*
****************************************************************************/
FAR struct mtd_dev_s *esp32c3_spiflash_alloc_mtdpart(void);
FAR struct mtd_dev_s *esp32c3_spiflash_alloc_mtdpart(uint32_t mtd_offset,
uint32_t mtd_size);
/****************************************************************************
* Name: esp32c3_spiflash_encrypt_mtd
@@ -75,6 +75,9 @@
* Pre-processor Definitions
****************************************************************************/
#define ESP32C3_MTD_OFFSET CONFIG_ESP32C3_MTD_OFFSET
#define ESP32C3_MTD_SIZE CONFIG_ESP32C3_MTD_SIZE
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -94,7 +97,8 @@ static int esp32c3_init_wifi_storage(void)
const char *path = "/dev/mtdblock1";
FAR struct mtd_dev_s *mtd_part;
mtd_part = esp32c3_spiflash_alloc_mtdpart();
mtd_part = esp32c3_spiflash_alloc_mtdpart(ESP32C3_MTD_OFFSET,
ESP32C3_MTD_SIZE);
if (!mtd_part)
{
syslog(LOG_ERR, "ERROR: Failed to alloc MTD partition of SPI Flash\n");
@@ -50,6 +50,9 @@
#define ESP32C3_FS_MOUNT_PT CONFIG_ESP32C3_SPIFLASH_FS_MOUNT_PT
#define ESP32C3_MTD_OFFSET CONFIG_ESP32C3_MTD_OFFSET
#define ESP32C3_MTD_SIZE CONFIG_ESP32C3_MTD_SIZE
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -66,7 +69,8 @@ int esp32c3_spiflash_init(void)
FAR struct mtd_dev_s *mtd;
int ret = ERROR;
mtd = esp32c3_spiflash_alloc_mtdpart();
mtd = esp32c3_spiflash_alloc_mtdpart(ESP32C3_MTD_OFFSET,
ESP32C3_MTD_SIZE);
#if defined (CONFIG_ESP32C3_SPIFLASH_SMARTFS)
ret = smart_initialize(0, mtd, NULL);