xiaoxiang781216 commented on code in PR #16735:
URL: https://github.com/apache/nuttx/pull/16735#discussion_r2211983218


##########
boards/xtensa/esp32s2/common/src/esp32s2_board_spiflash.c:
##########
@@ -60,10 +61,109 @@
 #  define CONFIG_ESP32S2_STORAGE_MTD_SIZE 0x100000
 #endif
 
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
+struct ota_partition_s

Review Comment:
   ditto



##########
boards/xtensa/esp32s3/common/src/esp32s3_board_spiflash.c:
##########
@@ -333,7 +440,11 @@ static int init_storage_partition(void)
       return ret;
     }
 
+#ifdef CONFIG_ESP32S3_HAVE_OTA_PARTITION
+  ret = ftl_initialize(nitems(g_ota_partition_table), mtd);
+#else
   ret = ftl_initialize(0, mtd);

Review Comment:
   ditto



##########
boards/xtensa/esp32s2/common/src/esp32s2_board_spiflash.c:
##########
@@ -60,10 +61,109 @@
 #  define CONFIG_ESP32S2_STORAGE_MTD_SIZE 0x100000
 #endif
 
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
+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 */
+};
+#endif
+
+/****************************************************************************
+ * 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 ota_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
+  },
+  {
+    .offset  = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_OFFSET,
+    .size    = CONFIG_ESPRESSIF_OTA_SLOT_SIZE,
+    .devpath = CONFIG_ESPRESSIF_OTA_SECONDARY_SLOT_DEVPATH
+  },
+  {
+    .offset  = CONFIG_ESPRESSIF_OTA_SCRATCH_OFFSET,
+    .size    = CONFIG_ESPRESSIF_OTA_SCRATCH_SIZE,
+    .devpath = CONFIG_ESPRESSIF_OTA_SCRATCH_DEVPATH
+  }
+};
+#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;
+#ifdef CONFIG_BCH
+  char blockdev[18];
+#endif
+  int ret = OK;
+
+  for (int 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);
+
+      ret = ftl_initialize(i, mtd);

Review Comment:
   change to register_mtddriver like https://github.com/apache/nuttx/pull/16642



##########
boards/xtensa/esp32s2/common/src/esp32s2_board_spiflash.c:
##########
@@ -338,11 +438,15 @@ static int init_storage_partition(void)
       return ret;
     }
 
+#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
+  ret = ftl_initialize(nitems(g_ota_partition_table), mtd);
+#else
   ret = ftl_initialize(0, mtd);

Review Comment:
   ditto



##########
boards/xtensa/esp32s2/common/src/esp32s2_board_spiflash.c:
##########
@@ -338,11 +438,15 @@ static int init_storage_partition(void)
       return ret;
     }
 
+#ifdef CONFIG_ESPRESSIF_HAVE_OTA_PARTITION
+  ret = ftl_initialize(nitems(g_ota_partition_table), mtd);

Review Comment:
   ditto



##########
boards/xtensa/esp32s3/common/src/esp32s3_board_spiflash.c:
##########
@@ -54,10 +55,116 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
+#ifdef CONFIG_ESP32S3_OTA_PARTITION_ENCRYPT
+#  define OTA_ENCRYPT true
+#else
+#  define OTA_ENCRYPT false
+#endif
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+#ifdef CONFIG_ESP32S3_HAVE_OTA_PARTITION
+struct ota_partition_s

Review Comment:
   could we reuse `partition_s` from include/nuttx/fs/partition.h?



##########
boards/xtensa/esp32s3/common/src/esp32s3_board_spiflash.c:
##########
@@ -333,7 +440,11 @@ static int init_storage_partition(void)
       return ret;
     }
 
+#ifdef CONFIG_ESP32S3_HAVE_OTA_PARTITION
+  ret = ftl_initialize(nitems(g_ota_partition_table), mtd);

Review Comment:
   change to register_mtddriver like https://github.com/apache/nuttx/pull/16642



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to