This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 092af63594b33daa471ccc3ef9a1a6b6889748d4 Author: davidiogos <[email protected]> AuthorDate: Tue Oct 8 16:59:30 2024 -0300 add OTA to esp32c6 --- .../risc-v/esp32c6/common/src/esp_board_spiflash.c | 92 ++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c b/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c index 716d74fba5..b729795e19 100644 --- a/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c +++ b/boards/risc-v/esp32c6/common/src/esp_board_spiflash.c @@ -58,18 +58,102 @@ * 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 ****************************************************************************/ +#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; + int ret = OK; + +#ifdef CONFIG_BCH + char blockdev[18]; +#endif + + 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); + if (ret < 0) + { + ferr("ERROR: Failed to initialize the FTL layer: %d\n", ret); + return ret; + } + +#ifdef CONFIG_BCH + snprintf(blockdev, sizeof(blockdev), "/dev/mtdblock%d", i); + + ret = bchdev_register(blockdev, part->devpath, false); + if (ret < 0) + { + ferr("ERROR: bchdev_register %s failed: %d\n", part->devpath, ret); + return ret; + } +#endif + } + + return ret; +} +#endif + /**************************************************************************** * Name: setup_smartfs * @@ -406,6 +490,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) {
