فهرست منبع

Added AT firmware flash example.
Common functionality was moved to separate folder.

Martin Valik 5 سال پیش
والد
کامیت
e366590d0a
26فایلهای تغییر یافته به همراه431 افزوده شده و 209 حذف شده
  1. 3 2
      .gitlab-ci.yml
  2. 0 203
      example/main/serial_flash_example_main.c
  3. 143 0
      examples/common/example_common.c
  4. 23 0
      examples/common/example_common.h
  5. 1 1
      examples/flash_at_firmware/CMakeLists.txt
  6. 71 0
      examples/flash_at_firmware/README.md
  7. BIN
      examples/flash_at_firmware/image/Firmware.bin
  8. 2 0
      examples/flash_at_firmware/main/CMakeLists.txt
  9. 96 0
      examples/flash_at_firmware/main/flash_at_firmware.c
  10. 0 0
      examples/flash_at_firmware/main/loader_config_user.h
  11. 9 0
      examples/flash_multiple_partitions/CMakeLists.txt
  12. 1 1
      examples/flash_multiple_partitions/README.md
  13. 2 2
      examples/flash_multiple_partitions/main/CMakeLists.txt
  14. 72 0
      examples/flash_multiple_partitions/main/flash_multiple_partitions.c
  15. 8 0
      examples/flash_multiple_partitions/main/loader_config_user.h
  16. 0 0
      examples/flash_multiple_partitions/partitions_example.csv
  17. 0 0
      examples/flash_multiple_partitions/sdkconfig.defaults
  18. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP32/bootloader.bin
  19. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP32/hello-world.bin
  20. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP32/partition-table.bin
  21. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP32_S2/bootloader.bin
  22. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP32_S2/hello-world.bin
  23. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP32_S2/partition-table.bin
  24. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP8266/bootloader.bin
  25. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP8266/hello-world.bin
  26. 0 0
      examples/flash_multiple_partitions/spiffs_image/ESP8266/partition-table.bin

+ 3 - 2
.gitlab-ci.yml

@@ -29,9 +29,10 @@ build_with_idf:
     - internet
   script:
     - *clone_and_setup_idf
-    - cd $CI_PROJECT_DIR/example
+    - cd $CI_PROJECT_DIR/examples/flash_multiple_partitions
+    - idf.py build
+    - cd $CI_PROJECT_DIR/examples/flash_at_firmware
     - idf.py build
-
 
 run_tests:
   stage: test

+ 0 - 203
example/main/serial_flash_example_main.c

@@ -1,203 +0,0 @@
-/* Serial flasher Example
-
-   This example code is in the Public Domain (or CC0 licensed, at your option.)
-
-   Unless required by applicable law or agreed to in writing, this
-   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
-   CONDITIONS OF ANY KIND, either express or implied.
-*/
-
-#include <string.h>
-#include "esp_err.h"
-#include "esp_log.h"
-#include "esp_spiffs.h"
-#include "esp_loader.h"
-#include "serial_io.h"
-#include "driver/gpio.h"
-#include "driver/uart.h"
-#include <sys/param.h>
-
-
-static const char *TAG = "example";
-
-#ifndef TARGET_ESP8266
-const uint32_t BOOTLOADER_ADDRESS = 0x1000;
-#else
-const uint32_t BOOTLOADER_ADDRESS = 0x0;
-#endif
-const uint32_t PARTITION_ADDRESS = 0x8000;
-const uint32_t APPLICATION_ADDRESS = 0x10000;
-
-const uint32_t HIGHER_BAUD_RATE = 230400;
-static uint8_t payload[1024];
-
-#if defined TARGET_ESP8266
-#define PARTITION_FILE "/spiffs/ESP8266/partition-table.bin"
-#define BOOTLOADER_FILE "/spiffs/ESP8266/bootloader.bin"
-#define APPLICATION_FILE "/spiffs/ESP8266/hello-world.bin"
-#elif defined TARGET_ESP32
-#define PARTITION_FILE "/spiffs/ESP32/partition-table.bin"
-#define BOOTLOADER_FILE "/spiffs/ESP32/bootloader.bin"
-#define APPLICATION_FILE "/spiffs/ESP32/hello-world.bin"
-#elif defined TARGET_ESP32_S2
-#define PARTITION_FILE "/spiffs/ESP32_S2/partition-table.bin"
-#define BOOTLOADER_FILE "/spiffs/ESP32_S2/bootloader.bin"
-#define APPLICATION_FILE "/spiffs/ESP32_S2/hello-world.bin"
-#endif
-
-
-static void flash_binary(FILE *image, size_t image_size, size_t address)
-{
-    esp_loader_error_t err;
-    int32_t packet_number = 0;
-
-    err = esp_loader_flash_start(address, image_size, sizeof(payload));
-    if (err != ESP_LOADER_SUCCESS) {
-        ESP_LOGE(TAG, "Flash start operation failed with error %d.", err);
-        return;
-    }
-    ESP_LOGI(TAG, "Start programming");
-
-    while (image_size > 0) {
-        size_t to_read = MIN(image_size, sizeof(payload));
-
-        size_t read = fread(payload, 1, to_read, image);
-        if (read != to_read) {
-            ESP_LOGE(TAG, "Error occurred while reading file.");
-            return;
-        }
-
-        err = esp_loader_flash_write(payload, to_read);
-        if (err != ESP_LOADER_SUCCESS) {
-            ESP_LOGE(TAG, "Packet could not be written");
-            return;
-        }
-
-        ESP_LOGI(TAG, "packet: %d  written: %u B", packet_number++, to_read);
-
-        image_size -= to_read;
-    };
-
-    ESP_LOGI(TAG, "Finished programming");
-
-#ifndef TARGET_ESP8266
-    err = esp_loader_flash_verify();
-    if (err != ESP_LOADER_SUCCESS) {
-        ESP_LOGE(TAG, "MD5 does not match. err: %d", err);
-        return;
-    }
-#endif
-    ESP_LOGI(TAG, "Flash verified");
-}
-
-static FILE *get_image_and_its_size(const char *path, size_t *image_size)
-{
-    FILE *image = fopen(path, "r");
-    if (image == NULL) {
-        ESP_LOGE(TAG, "Failed to open file %s", path);
-        esp_vfs_spiffs_unregister(NULL);
-        return NULL;
-    }
-
-    fseek(image, 0L, SEEK_END);
-    *image_size = ftell(image);
-    rewind(image);
-
-    ESP_LOGW(TAG, "File %s opened. Size: %u bytes", path, *image_size);
-
-    return image;
-}
-
-static void upload_file(const char *path, size_t address)
-{
-    size_t image_size;
-    FILE *image = get_image_and_its_size(path, &image_size);
-
-    if (image != NULL) {
-        flash_binary(image, image_size, address);
-        fclose(image);
-    }
-}
-
-static esp_err_t connect_to_target()
-{
-    const loader_serial_config_t config = {
-        .baud_rate = 115200,
-        .uart_port = UART_NUM_1,
-        .uart_rx_pin = GPIO_NUM_5,
-        .uart_tx_pin = GPIO_NUM_4,
-        .reset_trigger_pin = GPIO_NUM_25,
-        .gpio0_trigger_pin = GPIO_NUM_26,
-    };
-
-    // Initialize UART
-    esp_loader_error_t err = loader_port_serial_init(&config);
-    if (err != ESP_LOADER_SUCCESS) {
-        ESP_LOGE(TAG, "serial initialization failed.");
-        return err;
-    }
-
-    esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT();
-
-    err = esp_loader_connect(&connect_config);
-    if (err != ESP_LOADER_SUCCESS) {
-        ESP_LOGE(TAG, "Cannot connect to target. Error: %u", err);
-        return err;
-    }
-    ESP_LOGI(TAG, "Connected to target");
-
-#ifndef TARGET_ESP8266
-    err = esp_loader_change_baudrate(HIGHER_BAUD_RATE);
-    if (err != ESP_LOADER_SUCCESS) {
-        ESP_LOGE(TAG, "Unable to change baud rate on target.");
-        return err;
-    }
-
-    err = loader_port_change_baudrate(HIGHER_BAUD_RATE);
-    if (err != ESP_LOADER_SUCCESS) {
-        ESP_LOGE(TAG, "Unable to change baud rate.");
-        return err;
-    }
-#endif
-
-    return ESP_OK;
-}
-
-static esp_err_t register_vfs()
-{
-    ESP_LOGI(TAG, "Initializing SPIFFS");
-
-    esp_vfs_spiffs_conf_t conf = {
-        .base_path = "/spiffs",
-        .partition_label = NULL,
-        .max_files = 5,
-        .format_if_mount_failed = false
-    };
-
-    // Use settings defined above to initialize and mount SPIFFS filesystem.
-    esp_err_t ret = esp_vfs_spiffs_register(&conf);
-
-    if (ret != ESP_OK) {
-        if (ret == ESP_FAIL) {
-            ESP_LOGE(TAG, "Failed to mount or format filesystem");
-        } else if (ret == ESP_ERR_NOT_FOUND) {
-            ESP_LOGE(TAG, "Failed to find SPIFFS partition");
-        } else {
-            ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
-        }
-    }
-
-    return ret;
-}
-
-void app_main(void)
-{
-    if ( register_vfs() == ESP_OK ) {
-        if ( connect_to_target() == ESP_OK) {
-            upload_file(PARTITION_FILE, PARTITION_ADDRESS);
-            upload_file(BOOTLOADER_FILE, BOOTLOADER_ADDRESS);
-            upload_file(APPLICATION_FILE, APPLICATION_ADDRESS);
-        }
-        esp_vfs_spiffs_unregister(NULL);
-    }
-}

+ 143 - 0
examples/common/example_common.c

@@ -0,0 +1,143 @@
+/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <sys/param.h>
+#include "esp_err.h"
+#include "esp_log.h"
+#include "serial_io.h"
+#include "esp_loader.h"
+#include "driver/uart.h"
+#include "driver/gpio.h"
+#include "example_common.h"
+
+#define HIGHER_BAUD_RATE 230400
+
+void flash_binary(FILE *image, size_t image_size, size_t address)
+{
+    esp_loader_error_t err;
+    int32_t packet_number = 0;
+    static uint8_t payload[1024];
+
+    ESP_LOGI(TAG, "Erasing flash...");
+    err = esp_loader_flash_start(address, image_size, sizeof(payload));
+    if (err != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "Erasing flash failed with error %d.", err);
+        return;
+    }
+    ESP_LOGI(TAG, "Start programming");
+
+    while (image_size > 0) {
+        size_t to_read = MIN(image_size, sizeof(payload));
+
+        size_t read = fread(payload, 1, to_read, image);
+        if (read != to_read) {
+            ESP_LOGE(TAG, "Error occurred while reading file. to_read %u, read %u", to_read, read);
+            return;
+        }
+
+        err = esp_loader_flash_write(payload, to_read);
+        if (err != ESP_LOADER_SUCCESS) {
+            ESP_LOGE(TAG, "Packet could not be written");
+            return;
+        }
+
+        printf("packet: %d  written: %u B\n", packet_number++, to_read);
+
+        image_size -= to_read;
+    };
+
+    ESP_LOGI(TAG, "Finished programming");
+
+#ifndef TARGET_ESP8266
+    err = esp_loader_flash_verify();
+    if (err != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "MD5 does not match. err: %d", err);
+        return;
+    }
+    ESP_LOGI(TAG, "Flash verified");
+#endif
+}
+
+FILE *get_image_and_its_size(const char *path, size_t *image_size)
+{
+    FILE *image = fopen(path, "r");
+    if (image == NULL) {
+        ESP_LOGE(TAG, "Failed to open file %s", path);
+        return NULL;
+    }
+
+    fseek(image, 0L, SEEK_END);
+    *image_size = ftell(image);
+    rewind(image);
+
+    ESP_LOGW(TAG, "File %s opened. Size: %u bytes", path, *image_size);
+
+    return image;
+}
+
+void upload_file(const char *path, size_t address)
+{
+    size_t image_size;
+    FILE *image = get_image_and_its_size(path, &image_size);
+
+    if (image != NULL) {
+        flash_binary(image, image_size, address);
+        fclose(image);
+    }
+}
+
+esp_err_t connect_to_target()
+{
+    const loader_serial_config_t config = {
+        .baud_rate = 115200,
+        .uart_port = UART_NUM_1,
+        .uart_rx_pin = GPIO_NUM_5,
+        .uart_tx_pin = GPIO_NUM_4,
+        .reset_trigger_pin = GPIO_NUM_25,
+        .gpio0_trigger_pin = GPIO_NUM_26,
+    };
+
+    // Initialize UART
+    esp_loader_error_t err = loader_port_serial_init(&config);
+    if (err != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "serial initialization failed.");
+        return err;
+    }
+
+    esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT();
+
+    err = esp_loader_connect(&connect_config);
+    if (err != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "Cannot connect to target. Error: %u", err);
+        return err;
+    }
+    ESP_LOGI(TAG, "Connected to target");
+
+#ifndef TARGET_ESP8266
+    err = esp_loader_change_baudrate(HIGHER_BAUD_RATE);
+    if (err != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "Unable to change baud rate on target.");
+        return err;
+    }
+
+    err = loader_port_change_baudrate(HIGHER_BAUD_RATE);
+    if (err != ESP_LOADER_SUCCESS) {
+        ESP_LOGE(TAG, "Unable to change baud rate.");
+        return err;
+    }
+#endif
+
+    return ESP_OK;
+}

+ 23 - 0
examples/common/example_common.h

@@ -0,0 +1,23 @@
+/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+static const char *TAG = "example";
+
+void flash_binary(FILE *image, size_t image_size, size_t address);
+FILE *get_image_and_its_size(const char *path, size_t *image_size);
+void upload_file(const char *path, size_t address);
+esp_err_t connect_to_target();

+ 1 - 1
example/CMakeLists.txt → examples/flash_at_firmware/CMakeLists.txt

@@ -2,7 +2,7 @@
 # in this exact order for cmake to work correctly
 cmake_minimum_required(VERSION 3.5)
 
-set(EXTRA_COMPONENT_DIRS ../)
+set(EXTRA_COMPONENT_DIRS ../../)
 include_directories(main)
 
 include($ENV{IDF_PATH}/tools/cmake/project.cmake)

+ 71 - 0
examples/flash_at_firmware/README.md

@@ -0,0 +1,71 @@
+# Flash AT firmware example
+
+## Overview
+
+Example demonstrates how to flash AT command firmware from one ESP32 to another using esp_serial_flash component API. Binary to be flashed has to be stored on SD card with `fat` filesystem. AT command firmware to copy onto SD card can be found in `image` folder. When other AT command firmware is stored on SD card, file name has to be changed in example accordingly.
+
+Following steps are performed in order to re-program target's memory:
+
+1. Filesystem is initialized and mounted.
+2. UART1 through which new binary will be transfered is initialized.
+3. Host puts slave device into boot mode tries to connect by calling `esp_loader_connect()`.
+4. Binary file is opened and its size is acquired, as it has to be known before flashing.
+5. Then `esp_loader_flash_start()` is called to enter flashing mode and erase amount of memory to be flashed.
+6. `esp_loader_flash_write()` function is called repeatedly until the whole binary image is transfered.
+
+## Target selection
+
+By default, example is compiled for ESP32 target.
+When target is not ESP32, user has set corresponding target in `loader_config_user.h` header file and provide appropriate binary.
+
+For available AT command firmwares refer to [AT firmwares](https://www.espressif.com/en/support/download/at)
+
+## Hardware Required
+
+* `ESP_WROVER_KIT` (with SD card connector)
+* Another board based on WROWER module.
+* One or two USB cables for power supply and programming.
+* microSD card
+
+Note: WROWER module(ESP32) to be flashed can be substituted with any other Espressif SoC as long as appropriate AT firmware version is used.
+
+## Hardware connection
+
+Table below shows connection between two ESP32 devices.
+
+| ESP32 (host) | ESP32 (slave) |
+|:------------:|:-------------:|
+|    IO26      |      IO0      |
+|    IO25      |     RESET     |
+|    IO4       |      RX0      |
+|    IO5       |      TX0      |
+
+### Build and flash
+
+To run the example, type the following command:
+
+```CMake
+idf.py -p PORT flash monitor
+```
+
+(To exit the serial monitor, type ``Ctrl-]``.)
+
+See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
+
+## Example output
+
+Here is the example's console output:
+
+```
+...
+I (342) example: Initializing SPIFFS
+I (482) example: Image size: 144672
+I (902) example: Connected to target
+I (1732) example: Start programming
+I (1832) example: packet: 0  written: 1024 B
+I (1932) example: packet: 1  written: 1024 B
+...
+I (16052) example: packet: 140  written: 1024 B
+I (16152) example: packet: 141  written: 288 B
+I (16152) example: Finished programming
+```

BIN
examples/flash_at_firmware/image/Firmware.bin


+ 2 - 0
examples/flash_at_firmware/main/CMakeLists.txt

@@ -0,0 +1,2 @@
+idf_component_register(SRCS "flash_at_firmware.c" "../../common/example_common.c"
+                       INCLUDE_DIRS ".""../../common")

+ 96 - 0
examples/flash_at_firmware/main/flash_at_firmware.c

@@ -0,0 +1,96 @@
+/* Flash AT firmware example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+#include "esp_err.h"
+#include "esp_log.h"
+#include "esp_vfs_fat.h"
+#include "driver/sdspi_host.h"
+#include "driver/spi_common.h"
+#include "example_common.h"
+
+#define MOUNT_POINT "/sdcard"
+
+#define SPI_DMA_CHAN 1
+
+#define PIN_NUM_MISO 2
+#define PIN_NUM_MOSI 15
+#define PIN_NUM_CLK  14
+#define PIN_NUM_CS   13
+
+static sdmmc_card_t *card;
+static sdmmc_host_t host = SDSPI_HOST_DEFAULT();
+
+esp_err_t sdcard_init(void)
+{
+    ESP_LOGI(TAG, "Initializing SD card");
+
+    // Use settings defined above to initialize SD card and mount FAT filesystem.
+    // Note: esp_vfs_fat_sdmmc/sdspi_mount is all-in-one convenience functions.
+    // Please check its source code and implement error recovery when developing
+    // production applications.
+
+    spi_bus_config_t bus_cfg = {
+        .mosi_io_num = PIN_NUM_MOSI,
+        .miso_io_num = PIN_NUM_MISO,
+        .sclk_io_num = PIN_NUM_CLK,
+        .quadwp_io_num = -1,
+        .quadhd_io_num = -1,
+        .max_transfer_sz = 4000,
+    };
+    
+    if( spi_bus_initialize(host.slot, &bus_cfg, SPI_DMA_CHAN) != ESP_OK ) {
+        ESP_LOGE(TAG, "Failed to initialize bus.");
+        return ESP_FAIL;
+    }
+
+    // This initializes the slot without card detect (CD) and write protect (WP) signals.
+    // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
+    sdspi_device_config_t slot_config = SDSPI_DEVICE_CONFIG_DEFAULT();
+    slot_config.gpio_cs = PIN_NUM_CS;
+    slot_config.host_id = host.slot;
+
+    esp_vfs_fat_sdmmc_mount_config_t mount_config = {
+        .format_if_mount_failed = false,
+        .max_files = 5,
+        .allocation_unit_size = 16 * 1024
+    };
+
+    const char mount_point[] = MOUNT_POINT;
+
+    esp_err_t ret = esp_vfs_fat_sdspi_mount(mount_point, &host, &slot_config, &mount_config, &card);
+
+    if (ret != ESP_OK) {
+        if (ret == ESP_FAIL) {
+            ESP_LOGE(TAG, "Failed to mount filesystem. "
+                     "If you want the card to be formatted, set the EXAMPLE_FORMAT_IF_MOUNT_FAILED menuconfig option.");
+        } else {
+            ESP_LOGE(TAG, "Failed to initialize the card (%s). "
+                     "Make sure SD card lines have pull-up resistors in place.", esp_err_to_name(ret));
+        }
+        return ESP_FAIL;
+    }
+
+    return ESP_OK;
+}
+
+void sdcard_deinit()
+{
+    esp_vfs_fat_sdcard_unmount(MOUNT_POINT, card);
+    ESP_LOGI(TAG, "Card unmounted");
+    spi_bus_free(host.slot);
+}
+
+void app_main(void)
+{
+    if ( sdcard_init() == ESP_OK ) {
+        if ( connect_to_target() == ESP_OK) {
+            upload_file(MOUNT_POINT"/Firmware.bin", 0);
+        }
+        sdcard_deinit();
+    }
+}

+ 0 - 0
example/main/loader_config_user.h → examples/flash_at_firmware/main/loader_config_user.h


+ 9 - 0
examples/flash_multiple_partitions/CMakeLists.txt

@@ -0,0 +1,9 @@
+# The following lines of boilerplate have to be in your project's CMakeLists
+# in this exact order for cmake to work correctly
+cmake_minimum_required(VERSION 3.5)
+
+set(EXTRA_COMPONENT_DIRS ../../)
+include_directories(main)
+
+include($ENV{IDF_PATH}/tools/cmake/project.cmake)
+project(esp-serial-flasher)

+ 1 - 1
example/README.md → examples/flash_multiple_partitions/README.md

@@ -1,4 +1,4 @@
-# Serial flash example
+# Flash multiple partitions example
 
 ## Overview
 

+ 2 - 2
example/main/CMakeLists.txt → examples/flash_multiple_partitions/main/CMakeLists.txt

@@ -1,5 +1,5 @@
-idf_component_register(SRCS "serial_flash_example_main.c"
-                    INCLUDE_DIRS ".")
+idf_component_register(SRCS "flash_multiple_partitions.c" "../../common/example_common.c"
+                       INCLUDE_DIRS ".""../../common")
 
 # Create a SPIFFS image from the contents of the 'spiffs_image' directory
 # that fits the partition named 'storage'. FLASH_IN_PROJECT indicates that

+ 72 - 0
examples/flash_multiple_partitions/main/flash_multiple_partitions.c

@@ -0,0 +1,72 @@
+/* Flash multiple partitions example
+
+   This example code is in the Public Domain (or CC0 licensed, at your option.)
+
+   Unless required by applicable law or agreed to in writing, this
+   software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+   CONDITIONS OF ANY KIND, either express or implied.
+*/
+
+#include <sys/param.h>
+#include <string.h>
+#include "esp_err.h"
+#include "esp_log.h"
+#include "esp_spiffs.h"
+#include "loader_config.h"
+#include "example_common.h"
+
+
+#ifndef TARGET_ESP8266
+const uint32_t BOOTLOADER_ADDRESS = 0x1000;
+#else
+const uint32_t BOOTLOADER_ADDRESS = 0x0;
+#endif
+const uint32_t PARTITION_ADDRESS = 0x8000;
+const uint32_t APPLICATION_ADDRESS = 0x10000;
+
+#if defined TARGET_ESP8266
+#define BINARY_PATH "/spiffs/ESP8266/"
+#elif defined TARGET_ESP32
+#define BINARY_PATH "/spiffs/ESP32/"
+#elif defined TARGET_ESP32_S2
+#define BINARY_PATH "/spiffs/ESP32_S2/"
+#endif
+
+static esp_err_t register_vfs()
+{
+    ESP_LOGI(TAG, "Initializing SPIFFS");
+
+    esp_vfs_spiffs_conf_t conf = {
+        .base_path = "/spiffs",
+        .partition_label = NULL,
+        .max_files = 5,
+        .format_if_mount_failed = false
+    };
+
+    // Use settings defined above to initialize and mount SPIFFS filesystem.
+    esp_err_t ret = esp_vfs_spiffs_register(&conf);
+
+    if (ret != ESP_OK) {
+        if (ret == ESP_FAIL) {
+            ESP_LOGE(TAG, "Failed to mount or format filesystem");
+        } else if (ret == ESP_ERR_NOT_FOUND) {
+            ESP_LOGE(TAG, "Failed to find SPIFFS partition");
+        } else {
+            ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
+        }
+    }
+
+    return ret;
+}
+
+void app_main(void)
+{
+    if ( register_vfs() == ESP_OK ) {
+        if ( connect_to_target() == ESP_OK) {
+            upload_file(BINARY_PATH"partition-table.bin", PARTITION_ADDRESS);
+            upload_file(BINARY_PATH"bootloader.bin", BOOTLOADER_ADDRESS);
+            upload_file(BINARY_PATH"hello-world.bin", APPLICATION_ADDRESS);
+        }
+        esp_vfs_spiffs_unregister(NULL);
+    }
+}

+ 8 - 0
examples/flash_multiple_partitions/main/loader_config_user.h

@@ -0,0 +1,8 @@
+#pragma once
+
+// Uncomment to compile for ESP8266 target
+// #define TARGET_ESP8266  1
+// #define MD5_ENABLED     0
+
+// Uncomment to compile for ESP32-S2 target
+// #define TARGET_ESP32_S2  1

+ 0 - 0
example/partitions_example.csv → examples/flash_multiple_partitions/partitions_example.csv


+ 0 - 0
example/sdkconfig.defaults → examples/flash_multiple_partitions/sdkconfig.defaults


+ 0 - 0
example/spiffs_image/ESP32/bootloader.bin → examples/flash_multiple_partitions/spiffs_image/ESP32/bootloader.bin


+ 0 - 0
example/spiffs_image/ESP32/hello-world.bin → examples/flash_multiple_partitions/spiffs_image/ESP32/hello-world.bin


+ 0 - 0
example/spiffs_image/ESP32/partition-table.bin → examples/flash_multiple_partitions/spiffs_image/ESP32/partition-table.bin


+ 0 - 0
example/spiffs_image/ESP32_S2/bootloader.bin → examples/flash_multiple_partitions/spiffs_image/ESP32_S2/bootloader.bin


+ 0 - 0
example/spiffs_image/ESP32_S2/hello-world.bin → examples/flash_multiple_partitions/spiffs_image/ESP32_S2/hello-world.bin


+ 0 - 0
example/spiffs_image/ESP32_S2/partition-table.bin → examples/flash_multiple_partitions/spiffs_image/ESP32_S2/partition-table.bin


+ 0 - 0
example/spiffs_image/ESP8266/bootloader.bin → examples/flash_multiple_partitions/spiffs_image/ESP8266/bootloader.bin


+ 0 - 0
example/spiffs_image/ESP8266/hello-world.bin → examples/flash_multiple_partitions/spiffs_image/ESP8266/hello-world.bin


+ 0 - 0
example/spiffs_image/ESP8266/partition-table.bin → examples/flash_multiple_partitions/spiffs_image/ESP8266/partition-table.bin