You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2021/07/29 18:17:21 UTC

[incubator-nuttx] branch master updated: xtensa/esp32: Enable the allocation of multiple SPI Flash partitions

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new a7a9226  xtensa/esp32: Enable the allocation of multiple SPI Flash partitions
a7a9226 is described below

commit a7a922611bb44999abc7e858eaa618999f8aed0d
Author: Gustavo Henrique Nihei <gu...@espressif.com>
AuthorDate: Wed Jul 28 18:34:09 2021 -0300

    xtensa/esp32: Enable the allocation of multiple SPI Flash partitions
    
    Currently the "esp32_spiflash_alloc_mtdpart" allocates a
    statically-defined partition from "offset" and "size" set via
    Kconfig.
    This commit changes the function interface to receive those information
    as arguments, enabling the creation of multiple MTD partitions with
    different offsets and sizes.
    
    Signed-off-by: Gustavo Henrique Nihei <gu...@espressif.com>
---
 arch/xtensa/src/esp32/esp32_spiflash.c             | 34 ++++++++++++----------
 arch/xtensa/src/esp32/esp32_spiflash.h             | 12 ++++----
 boards/xtensa/esp32/common/src/esp32_board_wlan.c  |  9 +++++-
 .../esp32/esp32-devkitc/src/esp32_spiflash.c       |  9 +++++-
 .../esp32/esp32-ethernet-kit/src/esp32_spiflash.c  |  9 +++++-
 .../esp32/esp32-wrover-kit/src/esp32_spiflash.c    |  9 +++++-
 6 files changed, 57 insertions(+), 25 deletions(-)

diff --git a/arch/xtensa/src/esp32/esp32_spiflash.c b/arch/xtensa/src/esp32/esp32_spiflash.c
index 5da7893..344e95b 100644
--- a/arch/xtensa/src/esp32/esp32_spiflash.c
+++ b/arch/xtensa/src/esp32/esp32_spiflash.c
@@ -71,9 +71,6 @@
 #define SPI_FLASH_ENCRYPT_WORDS     (32 / 4)
 #define SPI_FLASH_ERASED_STATE      (0xff)
 
-#define ESP32_MTD_OFFSET            CONFIG_ESP32_MTD_OFFSET
-#define ESP32_MTD_SIZE              CONFIG_ESP32_MTD_SIZE
-
 #define MTD2PRIV(_dev)              ((FAR struct esp32_spiflash_s *)_dev)
 #define MTD_SIZE(_priv)             ((_priv)->chip->chip_size)
 #define MTD_BLKSIZE(_priv)          ((_priv)->chip->page_size)
@@ -1960,17 +1957,19 @@ static int esp32_ioctl(FAR struct mtd_dev_s *dev, int cmd,
  * Name: esp32_spiflash_alloc_mtdpart
  *
  * Description:
- *   Alloc ESP32 SPI Flash MTD
+ *   Allocate an MTD partition from the ESP32 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 SPI Flash MTD data pointer if success or NULL if fail
  *
  ****************************************************************************/
 
-FAR struct mtd_dev_s *esp32_spiflash_alloc_mtdpart(void)
+FAR struct mtd_dev_s *esp32_spiflash_alloc_mtdpart(uint32_t mtd_offset,
+                                                   uint32_t mtd_size)
 {
   struct esp32_spiflash_s *priv = &g_esp32_spiflash1;
   esp32_spiflash_chip_t *chip = priv->chip;
@@ -1979,9 +1978,9 @@ FAR struct mtd_dev_s *esp32_spiflash_alloc_mtdpart(void)
   uint32_t startblock;
   uint32_t size;
 
-  ASSERT((ESP32_MTD_OFFSET + ESP32_MTD_SIZE) <= chip->chip_size);
-  ASSERT((ESP32_MTD_OFFSET % chip->sector_size) == 0);
-  ASSERT((ESP32_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 SPI Flash information:\n");
   finfo("\tID = 0x%x\n", chip->device_id);
@@ -1991,16 +1990,19 @@ FAR struct mtd_dev_s *esp32_spiflash_alloc_mtdpart(void)
   finfo("\tSector size = %d KB\n", chip->sector_size / 1024);
   finfo("\tBlock size = %d KB\n", chip->block_size / 1024);
 
-#if ESP32_MTD_SIZE == 0
-  size = chip->chip_size - ESP32_MTD_OFFSET;
-#else
-  size = ESP32_MTD_SIZE;
-#endif
+  if (mtd_size == 0)
+    {
+      size = chip->chip_size - mtd_offset;
+    }
+  else
+    {
+      size = mtd_size;
+    }
 
-  finfo("\tMTD offset = 0x%x\n", ESP32_MTD_OFFSET);
+  finfo("\tMTD offset = 0x%x\n", mtd_offset);
   finfo("\tMTD size = 0x%x\n", size);
 
-  startblock = MTD_SIZE2BLK(priv, ESP32_MTD_OFFSET);
+  startblock = MTD_SIZE2BLK(priv, mtd_offset);
   blocks = MTD_SIZE2BLK(priv, size);
 
   mtd_part = mtd_partition(&priv->mtd, startblock, blocks);
diff --git a/arch/xtensa/src/esp32/esp32_spiflash.h b/arch/xtensa/src/esp32/esp32_spiflash.h
index cda155d..f1f5b30 100644
--- a/arch/xtensa/src/esp32/esp32_spiflash.h
+++ b/arch/xtensa/src/esp32/esp32_spiflash.h
@@ -49,20 +49,22 @@ extern "C"
  ****************************************************************************/
 
 /****************************************************************************
- * Name: esp32_spiflash_init
+ * Name: esp32_spiflash_alloc_mtdpart
  *
  * Description:
- *   Alloc ESP32 SPI Flash MTD.
+ *   Allocate an MTD partition from the ESP32 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 SPI Flash MTD data pointer if success or NULL if fail.
  *
  ****************************************************************************/
 
-FAR struct mtd_dev_s *esp32_spiflash_alloc_mtdpart(void);
+FAR struct mtd_dev_s *esp32_spiflash_alloc_mtdpart(uint32_t mtd_offset,
+                                                   uint32_t mtd_size);
 
 /****************************************************************************
  * Name: esp32_spiflash_get_mtd
@@ -81,7 +83,7 @@ FAR struct mtd_dev_s *esp32_spiflash_alloc_mtdpart(void);
 FAR struct mtd_dev_s *esp32_spiflash_get_mtd(void);
 
 /****************************************************************************
- * Name: esp32_spiflash_get_mtd
+ * Name: esp32_spiflash_encrypt_get_mtd
  *
  * Description:
  *   Get ESP32 SPI Flash encryption raw MTD.
diff --git a/boards/xtensa/esp32/common/src/esp32_board_wlan.c b/boards/xtensa/esp32/common/src/esp32_board_wlan.c
index 76362d3..b631aa1 100644
--- a/boards/xtensa/esp32/common/src/esp32_board_wlan.c
+++ b/boards/xtensa/esp32/common/src/esp32_board_wlan.c
@@ -37,6 +37,13 @@
 #include "esp32_wlan.h"
 
 /****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ESP32_MTD_OFFSET            CONFIG_ESP32_MTD_OFFSET
+#define ESP32_MTD_SIZE              CONFIG_ESP32_MTD_SIZE
+
+/****************************************************************************
  * Private Functions
  ****************************************************************************/
 
@@ -47,7 +54,7 @@ static int esp32_init_wifi_storage(void)
   const char *path = "/dev/mtdblock1";
   FAR struct mtd_dev_s *mtd_part;
 
-  mtd_part = esp32_spiflash_alloc_mtdpart();
+  mtd_part = esp32_spiflash_alloc_mtdpart(ESP32_MTD_OFFSET, ESP32_MTD_SIZE);
   if (!mtd_part)
     {
       syslog(LOG_ERR, "ERROR: Failed to alloc MTD partition of SPI Flash\n");
diff --git a/boards/xtensa/esp32/esp32-devkitc/src/esp32_spiflash.c b/boards/xtensa/esp32/esp32-devkitc/src/esp32_spiflash.c
index 2ccba64..0de2166 100644
--- a/boards/xtensa/esp32/esp32-devkitc/src/esp32_spiflash.c
+++ b/boards/xtensa/esp32/esp32-devkitc/src/esp32_spiflash.c
@@ -40,6 +40,13 @@
 #include "esp32-devkitc.h"
 
 /****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ESP32_MTD_OFFSET            CONFIG_ESP32_MTD_OFFSET
+#define ESP32_MTD_SIZE              CONFIG_ESP32_MTD_SIZE
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -55,7 +62,7 @@ int esp32_spiflash_init(void)
   FAR struct mtd_dev_s *mtd;
   int ret = ERROR;
 
-  mtd = esp32_spiflash_alloc_mtdpart();
+  mtd = esp32_spiflash_alloc_mtdpart(ESP32_MTD_OFFSET, ESP32_MTD_SIZE);
 
 #if defined (CONFIG_ESP32_SPIFLASH_SMARTFS)
   ret = smart_initialize(0, mtd, NULL);
diff --git a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_spiflash.c b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_spiflash.c
index 9a0d3b9..a8dcb41 100644
--- a/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_spiflash.c
+++ b/boards/xtensa/esp32/esp32-ethernet-kit/src/esp32_spiflash.c
@@ -40,6 +40,13 @@
 #include "esp32-ethernet-kit.h"
 
 /****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ESP32_MTD_OFFSET            CONFIG_ESP32_MTD_OFFSET
+#define ESP32_MTD_SIZE              CONFIG_ESP32_MTD_SIZE
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -55,7 +62,7 @@ int esp32_spiflash_init(void)
   FAR struct mtd_dev_s *mtd;
   int ret = ERROR;
 
-  mtd = esp32_spiflash_alloc_mtdpart();
+  mtd = esp32_spiflash_alloc_mtdpart(ESP32_MTD_OFFSET, ESP32_MTD_SIZE);
 
 #if defined (CONFIG_ESP32_SPIFLASH_SMARTFS)
   ret = smart_initialize(0, mtd, NULL);
diff --git a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_spiflash.c b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_spiflash.c
index a0622e7..4eaf028 100644
--- a/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_spiflash.c
+++ b/boards/xtensa/esp32/esp32-wrover-kit/src/esp32_spiflash.c
@@ -40,6 +40,13 @@
 #include "esp32-wrover-kit.h"
 
 /****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ESP32_MTD_OFFSET            CONFIG_ESP32_MTD_OFFSET
+#define ESP32_MTD_SIZE              CONFIG_ESP32_MTD_SIZE
+
+/****************************************************************************
  * Public Functions
  ****************************************************************************/
 
@@ -55,7 +62,7 @@ int esp32_spiflash_init(void)
   FAR struct mtd_dev_s *mtd;
   int ret = ERROR;
 
-  mtd = esp32_spiflash_alloc_mtdpart();
+  mtd = esp32_spiflash_alloc_mtdpart(ESP32_MTD_OFFSET, ESP32_MTD_SIZE);
 
 #if defined (CONFIG_ESP32_SPIFLASH_SMARTFS)
   ret = smart_initialize(0, mtd, NULL);