partition: use esp_partition_munmap instead of spi_flash_munmap

This commit is contained in:
Armando 2022-11-07 19:31:29 +08:00
parent 5bed8fab49
commit aba9f80cd2
9 changed files with 35 additions and 38 deletions

View File

@ -69,11 +69,11 @@ static uint8_t get_boot_count_from_nvs(void)
static void copy_app_partition(esp_ota_handle_t update_handle, const esp_partition_t *curr_app) static void copy_app_partition(esp_ota_handle_t update_handle, const esp_partition_t *curr_app)
{ {
const void *partition_bin = NULL; const void *partition_bin = NULL;
spi_flash_mmap_handle_t data_map; esp_partition_mmap_handle_t data_map;
ESP_LOGI(TAG, "start the copy process"); ESP_LOGI(TAG, "start the copy process");
TEST_ESP_OK(esp_partition_mmap(curr_app, 0, curr_app->size, SPI_FLASH_MMAP_DATA, &partition_bin, &data_map)); TEST_ESP_OK(esp_partition_mmap(curr_app, 0, curr_app->size, ESP_PARTITION_MMAP_DATA, &partition_bin, &data_map));
TEST_ESP_OK(esp_ota_write(update_handle, (const void *)partition_bin, curr_app->size)); TEST_ESP_OK(esp_ota_write(update_handle, (const void *)partition_bin, curr_app->size));
spi_flash_munmap(data_map); esp_partition_munmap(data_map);
ESP_LOGI(TAG, "finish the copy process"); ESP_LOGI(TAG, "finish the copy process");
} }
@ -85,15 +85,15 @@ static void copy_app_partition(esp_ota_handle_t update_handle, const esp_partiti
static void copy_app_partition_with_offset(esp_ota_handle_t update_handle, const esp_partition_t *curr_app) static void copy_app_partition_with_offset(esp_ota_handle_t update_handle, const esp_partition_t *curr_app)
{ {
const void *partition_bin = NULL; const void *partition_bin = NULL;
spi_flash_mmap_handle_t data_map; esp_partition_mmap_handle_t data_map;
ESP_LOGI(TAG, "start the copy process"); ESP_LOGI(TAG, "start the copy process");
uint32_t offset = 0, bytes_to_write = curr_app->size; uint32_t offset = 0, bytes_to_write = curr_app->size;
uint32_t write_bytes; uint32_t write_bytes;
while (bytes_to_write > 0) { while (bytes_to_write > 0) {
write_bytes = (bytes_to_write > (4 * 1024)) ? (4 * 1024) : bytes_to_write; write_bytes = (bytes_to_write > (4 * 1024)) ? (4 * 1024) : bytes_to_write;
TEST_ESP_OK(esp_partition_mmap(curr_app, offset, write_bytes, SPI_FLASH_MMAP_DATA, &partition_bin, &data_map)); TEST_ESP_OK(esp_partition_mmap(curr_app, offset, write_bytes, ESP_PARTITION_MMAP_DATA, &partition_bin, &data_map));
TEST_ESP_OK(esp_ota_write_with_offset(update_handle, (const void *)partition_bin, write_bytes, offset)); TEST_ESP_OK(esp_ota_write_with_offset(update_handle, (const void *)partition_bin, write_bytes, offset));
spi_flash_munmap(data_map); esp_partition_munmap(data_map);
bytes_to_write -= write_bytes; bytes_to_write -= write_bytes;
offset += write_bytes; offset += write_bytes;
} }
@ -110,11 +110,11 @@ static void copy_app_partition_with_offset(esp_ota_handle_t update_handle, const
static void copy_partition(const esp_partition_t *dst_partition, const esp_partition_t *src_partition) static void copy_partition(const esp_partition_t *dst_partition, const esp_partition_t *src_partition)
{ {
const void *partition_bin = NULL; const void *partition_bin = NULL;
spi_flash_mmap_handle_t data_map; esp_partition_mmap_handle_t data_map;
TEST_ESP_OK(esp_partition_mmap(src_partition, 0, src_partition->size, SPI_FLASH_MMAP_DATA, &partition_bin, &data_map)); TEST_ESP_OK(esp_partition_mmap(src_partition, 0, src_partition->size, ESP_PARTITION_MMAP_DATA, &partition_bin, &data_map));
TEST_ESP_OK(esp_partition_erase_range(dst_partition, 0, dst_partition->size)); TEST_ESP_OK(esp_partition_erase_range(dst_partition, 0, dst_partition->size));
TEST_ESP_OK(esp_partition_write(dst_partition, 0, (const void *)partition_bin, dst_partition->size)); TEST_ESP_OK(esp_partition_write(dst_partition, 0, (const void *)partition_bin, dst_partition->size));
spi_flash_munmap(data_map); esp_partition_munmap(data_map);
} }
#endif #endif

View File

@ -126,14 +126,14 @@ TEST_CASE("Spiram cache flush on write/read", "[spiram]")
char buf[512]; char buf[512];
const void *out; const void *out;
spi_flash_mmap_handle_t handle; esp_partition_mmap_handle_t handle;
esp_partition_mmap(part, 0, 512, SPI_FLASH_MMAP_DATA, &out, &handle); esp_partition_mmap(part, 0, 512, ESP_PARTITION_MMAP_DATA, &out, &handle);
for (int i=0; i<CYCLES; i++) { for (int i=0; i<CYCLES; i++) {
esp_partition_write(part, 0, buf, 512); esp_partition_write(part, 0, buf, 512);
esp_partition_read(part, 0, buf, 512); esp_partition_read(part, 0, buf, 512);
vTaskDelay(1); vTaskDelay(1);
} }
spi_flash_munmap(handle); esp_partition_munmap(handle);
printf("Checked memory %d and %d times.\n", res[0], res[1]); printf("Checked memory %d and %d times.\n", res[0], res[1]);

View File

@ -53,7 +53,7 @@ esp_err_t esp_partition_read(const esp_partition_t *partition,
return err; return err;
} }
memcpy(dst, buf, size); memcpy(dst, buf, size);
spi_flash_munmap(handle); esp_partition_munmap(handle);
return ESP_OK; return ESP_OK;
#else #else
return ESP_ERR_NOT_SUPPORTED; return ESP_ERR_NOT_SUPPORTED;

View File

@ -6,7 +6,6 @@
#include <string.h> #include <string.h>
#include "esp_attr.h" #include "esp_attr.h"
#include "esp_partition.h" #include "esp_partition.h"
#include "spi_flash_mmap.h"
#include "esp_flash_encrypt.h" #include "esp_flash_encrypt.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#include "core_dump_checksum.h" #include "core_dump_checksum.h"
@ -645,7 +644,7 @@ esp_err_t esp_core_dump_write_elf(core_dump_write_config_t *write_cfg)
/* Below are the helper function to parse the core dump ELF stored in flash */ /* Below are the helper function to parse the core dump ELF stored in flash */
static esp_err_t elf_core_dump_image_mmap(spi_flash_mmap_handle_t* core_data_handle, const void **map_addr) static esp_err_t elf_core_dump_image_mmap(esp_partition_mmap_handle_t* core_data_handle, const void **map_addr)
{ {
size_t out_size; size_t out_size;
assert (core_data_handle); assert (core_data_handle);
@ -677,7 +676,7 @@ static esp_err_t elf_core_dump_image_mmap(spi_flash_mmap_handle_t* core_data_han
return ret; return ret;
} }
/* map the full core dump parition, including the checksum. */ /* map the full core dump parition, including the checksum. */
return esp_partition_mmap(core_part, 0, out_size, SPI_FLASH_MMAP_DATA, return esp_partition_mmap(core_part, 0, out_size, ESP_PARTITION_MMAP_DATA,
map_addr, core_data_handle); map_addr, core_data_handle);
} }
@ -708,7 +707,7 @@ esp_err_t esp_core_dump_get_summary(esp_core_dump_summary_t *summary)
elf_note *note; elf_note *note;
const void *map_addr; const void *map_addr;
size_t consumed_note_sz; size_t consumed_note_sz;
spi_flash_mmap_handle_t core_data_handle; esp_partition_mmap_handle_t core_data_handle;
if (!summary) { if (!summary) {
return ESP_ERR_INVALID_ARG; return ESP_ERR_INVALID_ARG;
@ -766,7 +765,7 @@ esp_err_t esp_core_dump_get_summary(esp_core_dump_summary_t *summary)
} }
} }
} }
spi_flash_munmap(core_data_handle); esp_partition_munmap(core_data_handle);
return ESP_OK; return ESP_OK;
} }

View File

@ -23,7 +23,7 @@
#include "test_mqtt_client_broker.h" #include "test_mqtt_client_broker.h"
#include "test_mqtt_connection.h" #include "test_mqtt_connection.h"
#include "esp_mac.h" #include "esp_mac.h"
#include "spi_flash_mmap.h" #include "esp_partition.h"
static void test_leak_setup(const char * file, long line) static void test_leak_setup(const char * file, long line)
{ {
@ -59,10 +59,10 @@ TEST_CASE("mqtt init and deinit", "[mqtt][leaks=0]")
static const char* this_bin_addr(void) static const char* this_bin_addr(void)
{ {
spi_flash_mmap_handle_t out_handle; esp_partition_mmap_handle_t out_handle;
const void *binary_address; const void *binary_address;
const esp_partition_t* partition = esp_ota_get_running_partition(); const esp_partition_t* partition = esp_ota_get_running_partition();
esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle); esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle);
return binary_address; return binary_address;
} }

View File

@ -17,7 +17,7 @@
#include "test_mqtt5_client_broker.h" #include "test_mqtt5_client_broker.h"
#include "test_mqtt_connection.h" #include "test_mqtt_connection.h"
#include "esp_mac.h" #include "esp_mac.h"
#include "spi_flash_mmap.h" #include "esp_partition.h"
static esp_mqtt5_user_property_item_t user_property_arr[3] = { static esp_mqtt5_user_property_item_t user_property_arr[3] = {
{"board", "esp32"}, {"board", "esp32"},
@ -89,10 +89,10 @@ TEST_CASE("mqtt5 init and deinit", "[mqtt5][leaks=0]")
static const char* this_bin_addr(void) static const char* this_bin_addr(void)
{ {
spi_flash_mmap_handle_t out_handle; esp_partition_mmap_handle_t out_handle;
const void *binary_address; const void *binary_address;
const esp_partition_t* partition = esp_ota_get_running_partition(); const esp_partition_t* partition = esp_ota_get_running_partition();
esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle); esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle);
return binary_address; return binary_address;
} }

View File

@ -445,15 +445,15 @@ TEST_CASE("munmap followed by mmap flushes cache", "[spi_flash][mmap]")
const esp_partition_t *p = get_test_data_partition(); const esp_partition_t *p = get_test_data_partition();
const uint32_t *data; const uint32_t *data;
spi_flash_mmap_handle_t handle; esp_partition_mmap_handle_t handle;
TEST_ESP_OK( esp_partition_mmap(p, 0, SPI_FLASH_MMU_PAGE_SIZE, TEST_ESP_OK( esp_partition_mmap(p, 0, SPI_FLASH_MMU_PAGE_SIZE,
SPI_FLASH_MMAP_DATA, (const void **) &data, &handle) ); ESP_PARTITION_MMAP_DATA, (const void **) &data, &handle) );
uint32_t buf[16]; uint32_t buf[16];
memcpy(buf, data, sizeof(buf)); memcpy(buf, data, sizeof(buf));
spi_flash_munmap(handle); esp_partition_munmap(handle);
TEST_ESP_OK( esp_partition_mmap(p, SPI_FLASH_MMU_PAGE_SIZE, SPI_FLASH_MMU_PAGE_SIZE, TEST_ESP_OK( esp_partition_mmap(p, SPI_FLASH_MMU_PAGE_SIZE, SPI_FLASH_MMU_PAGE_SIZE,
SPI_FLASH_MMAP_DATA, (const void **) &data, &handle) ); ESP_PARTITION_MMAP_DATA, (const void **) &data, &handle) );
TEST_ASSERT_NOT_EQUAL(0, memcmp(buf, data, sizeof(buf))); TEST_ASSERT_NOT_EQUAL(0, memcmp(buf, data, sizeof(buf)));
} }
@ -467,9 +467,9 @@ TEST_CASE("no stale data read post mmap and write partition", "[spi_flash][mmap]
const esp_partition_t *p = get_test_data_partition(); const esp_partition_t *p = get_test_data_partition();
const uint32_t *data; const uint32_t *data;
spi_flash_mmap_handle_t handle; esp_partition_mmap_handle_t handle;
TEST_ESP_OK(esp_partition_mmap(p, 0, SPI_FLASH_MMU_PAGE_SIZE, TEST_ESP_OK(esp_partition_mmap(p, 0, SPI_FLASH_MMU_PAGE_SIZE,
SPI_FLASH_MMAP_DATA, (const void **) &data, &handle) ); ESP_PARTITION_MMAP_DATA, (const void **) &data, &handle) );
memcpy(read_data, data, sizeof(read_data)); memcpy(read_data, data, sizeof(read_data));
TEST_ESP_OK(esp_partition_erase_range(p, 0, SPI_FLASH_MMU_PAGE_SIZE)); TEST_ESP_OK(esp_partition_erase_range(p, 0, SPI_FLASH_MMU_PAGE_SIZE));
/* not using esp_partition_write here, since the partition in not marked as "encrypted" /* not using esp_partition_write here, since the partition in not marked as "encrypted"
@ -478,6 +478,6 @@ TEST_CASE("no stale data read post mmap and write partition", "[spi_flash][mmap]
/* This should retrigger actual flash content read */ /* This should retrigger actual flash content read */
memcpy(read_data, data, sizeof(read_data)); memcpy(read_data, data, sizeof(read_data));
spi_flash_munmap(handle); esp_partition_munmap(handle);
TEST_ASSERT_EQUAL(0, memcmp(buf, read_data, sizeof(buf))); TEST_ASSERT_EQUAL(0, memcmp(buf, read_data, sizeof(buf)));
} }

View File

@ -13,7 +13,6 @@
#include <string.h> #include <string.h>
#include "esp_system.h" #include "esp_system.h"
#include "esp_partition.h" #include "esp_partition.h"
#include "spi_flash_mmap.h"
#include "nvs_flash.h" #include "nvs_flash.h"
#include "esp_event.h" #include "esp_event.h"
#include "esp_netif.h" #include "esp_netif.h"
@ -41,10 +40,10 @@ extern const uint8_t mqtt_eclipseprojects_io_pem_end[] asm("_binary_mqtt_eclip
// //
static void send_binary(esp_mqtt_client_handle_t client) static void send_binary(esp_mqtt_client_handle_t client)
{ {
spi_flash_mmap_handle_t out_handle; esp_partition_mmap_handle_t out_handle;
const void *binary_address; const void *binary_address;
const esp_partition_t *partition = esp_ota_get_running_partition(); const esp_partition_t *partition = esp_ota_get_running_partition();
esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &binary_address, &out_handle); esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &binary_address, &out_handle);
// sending only the configured portion of the partition (if it's less than the partition size) // sending only the configured portion of the partition (if it's less than the partition size)
int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND, partition->size); int binary_size = MIN(CONFIG_BROKER_BIN_SIZE_TO_SEND, partition->size);
int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 0, 0); int msg_id = esp_mqtt_client_publish(client, "/topic/binary", binary_address, binary_size, 0, 0);

View File

@ -8,7 +8,6 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include "esp_partition.h" #include "esp_partition.h"
#include "spi_flash_mmap.h"
#include "esp_log.h" #include "esp_log.h"
static const char *TAG = "example"; static const char *TAG = "example";
@ -36,10 +35,10 @@ void app_main(void)
ESP_LOGI(TAG, "Written sample data to partition: %s", store_data); ESP_LOGI(TAG, "Written sample data to partition: %s", store_data);
const void *map_ptr; const void *map_ptr;
spi_flash_mmap_handle_t map_handle; esp_partition_mmap_handle_t map_handle;
// Map the partition to data memory // Map the partition to data memory
ESP_ERROR_CHECK(esp_partition_mmap(partition, 0, partition->size, SPI_FLASH_MMAP_DATA, &map_ptr, &map_handle)); ESP_ERROR_CHECK(esp_partition_mmap(partition, 0, partition->size, ESP_PARTITION_MMAP_DATA, &map_ptr, &map_handle));
ESP_LOGI(TAG, "Mapped partition to data memory address %p", map_ptr); ESP_LOGI(TAG, "Mapped partition to data memory address %p", map_ptr);
// Read back the written verification data using the mapped memory pointer // Read back the written verification data using the mapped memory pointer
@ -51,7 +50,7 @@ void app_main(void)
ESP_LOGI(TAG, "Data matches"); ESP_LOGI(TAG, "Data matches");
// Unmap mapped memory // Unmap mapped memory
spi_flash_munmap(map_handle); esp_partition_munmap(map_handle);
ESP_LOGI(TAG, "Unmapped partition from data memory"); ESP_LOGI(TAG, "Unmapped partition from data memory");
ESP_LOGI(TAG, "Example end"); ESP_LOGI(TAG, "Example end");