|
|
@@ -11,18 +11,27 @@
|
|
|
#include <esp_partition.h>
|
|
|
#include <esp_flash_encrypt.h>
|
|
|
|
|
|
-#include "test_config.h"
|
|
|
+#include "test_utils.h"
|
|
|
|
|
|
static uint32_t buffer[1024];
|
|
|
|
|
|
-/* read-only region used for mmap tests */
|
|
|
-static const uint32_t start = 0x100000;
|
|
|
-static const uint32_t end = 0x200000;
|
|
|
+/* read-only region used for mmap tests, intialised in setup_mmap_tests() */
|
|
|
+static uint32_t start;
|
|
|
+static uint32_t end;
|
|
|
|
|
|
static spi_flash_mmap_handle_t handle1, handle2, handle3;
|
|
|
|
|
|
static void setup_mmap_tests()
|
|
|
{
|
|
|
+ if (start == 0) {
|
|
|
+ const esp_partition_t *part = get_test_data_partition();
|
|
|
+ start = part->address;
|
|
|
+ end = part->address + part->size;
|
|
|
+ printf("Test data partition @ 0x%x - 0x%x\n", start, end);
|
|
|
+ }
|
|
|
+ TEST_ASSERT(end > start);
|
|
|
+ TEST_ASSERT(end - start >= 512*1024);
|
|
|
+
|
|
|
/* clean up any mmap handles left over from failed tests */
|
|
|
if (handle1) {
|
|
|
spi_flash_munmap(handle1);
|
|
|
@@ -41,7 +50,7 @@ static void setup_mmap_tests()
|
|
|
srand(0);
|
|
|
for (int block = start / 0x10000; block < end / 0x10000; ++block) {
|
|
|
for (int sector = 0; sector < 16; ++sector) {
|
|
|
- uint32_t abs_sector = (block) * 16 + sector;
|
|
|
+ uint32_t abs_sector = (block * 16) + sector;
|
|
|
uint32_t sector_offs = abs_sector * SPI_FLASH_SEC_SIZE;
|
|
|
bool sector_needs_write = false;
|
|
|
|
|
|
@@ -50,7 +59,7 @@ static void setup_mmap_tests()
|
|
|
for (uint32_t word = 0; word < 1024; ++word) {
|
|
|
uint32_t val = rand();
|
|
|
if (block == start / 0x10000 && sector == 0 && word == 0) {
|
|
|
- printf("setup_mmap_tests(): first prepped word: %08x\n", val);
|
|
|
+ printf("setup_mmap_tests(): first prepped word: 0x%08x (flash holds 0x%08x)\n", val, buffer[word]);
|
|
|
}
|
|
|
if (buffer[word] != val) {
|
|
|
buffer[word] = val;
|
|
|
@@ -67,7 +76,7 @@ static void setup_mmap_tests()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-TEST_CASE("Can mmap into data address space", "[mmap]")
|
|
|
+TEST_CASE("Can mmap into data address space", "[spi_flash]")
|
|
|
{
|
|
|
setup_mmap_tests();
|
|
|
|
|
|
@@ -81,9 +90,11 @@ TEST_CASE("Can mmap into data address space", "[mmap]")
|
|
|
srand(0);
|
|
|
const uint32_t *data = (const uint32_t *) ptr1;
|
|
|
for (int block = 0; block < (end - start) / 0x10000; ++block) {
|
|
|
+ printf("block %d\n", block);
|
|
|
for (int sector = 0; sector < 16; ++sector) {
|
|
|
+ printf("sector %d\n", sector);
|
|
|
for (uint32_t word = 0; word < 1024; ++word) {
|
|
|
- TEST_ASSERT_EQUAL_UINT32(rand(), data[(block * 16 + sector) * 1024 + word]);
|
|
|
+ TEST_ASSERT_EQUAL_HEX32(rand(), data[(block * 16 + sector) * 1024 + word]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -137,10 +148,10 @@ TEST_CASE("flash_mmap invalidates just-written data", "[spi_flash]")
|
|
|
TEST_IGNORE_MESSAGE("flash encryption enabled, spi_flash_write_encrypted() test won't pass as-is");
|
|
|
}
|
|
|
|
|
|
- ESP_ERROR_CHECK( spi_flash_erase_sector(TEST_REGION_START / SPI_FLASH_SEC_SIZE) );
|
|
|
+ ESP_ERROR_CHECK( spi_flash_erase_sector(start / SPI_FLASH_SEC_SIZE) );
|
|
|
|
|
|
/* map erased test region to ptr1 */
|
|
|
- ESP_ERROR_CHECK( spi_flash_mmap(TEST_REGION_START, test_size, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) );
|
|
|
+ ESP_ERROR_CHECK( spi_flash_mmap(start, test_size, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) );
|
|
|
printf("mmap_res ptr1: handle=%d ptr=%p\n", handle1, ptr1);
|
|
|
|
|
|
/* verify it's all 0xFF */
|
|
|
@@ -155,14 +166,14 @@ TEST_CASE("flash_mmap invalidates just-written data", "[spi_flash]")
|
|
|
/* write flash region to 0xEE */
|
|
|
uint8_t buf[test_size];
|
|
|
memset(buf, 0xEE, test_size);
|
|
|
- ESP_ERROR_CHECK( spi_flash_write(TEST_REGION_START, buf, test_size) );
|
|
|
+ ESP_ERROR_CHECK( spi_flash_write(start, buf, test_size) );
|
|
|
|
|
|
/* re-map the test region at ptr1.
|
|
|
|
|
|
this is a fresh mmap call so should trigger a cache flush,
|
|
|
ensuring we see the updated flash.
|
|
|
*/
|
|
|
- ESP_ERROR_CHECK( spi_flash_mmap(TEST_REGION_START, test_size, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) );
|
|
|
+ ESP_ERROR_CHECK( spi_flash_mmap(start, test_size, SPI_FLASH_MMAP_DATA, &ptr1, &handle1) );
|
|
|
printf("mmap_res ptr1 #2: handle=%d ptr=%p\n", handle1, ptr1);
|
|
|
|
|
|
/* assert that ptr1 now maps to the new values on flash,
|
|
|
@@ -176,7 +187,9 @@ TEST_CASE("flash_mmap invalidates just-written data", "[spi_flash]")
|
|
|
|
|
|
TEST_CASE("phys2cache/cache2phys basic checks", "[spi_flash]")
|
|
|
{
|
|
|
- uint8_t buf_a[32], buf_b[32];
|
|
|
+ uint8_t buf[64];
|
|
|
+
|
|
|
+ static const uint8_t constant_data[] = { 1, 2, 3, 7, 11, 16, 3, 88 };
|
|
|
|
|
|
/* esp_partition_find is in IROM */
|
|
|
uint32_t phys = spi_flash_cache2phys(esp_partition_find);
|
|
|
@@ -184,27 +197,25 @@ TEST_CASE("phys2cache/cache2phys basic checks", "[spi_flash]")
|
|
|
TEST_ASSERT_EQUAL_PTR(esp_partition_find, spi_flash_phys2cache(phys, SPI_FLASH_MMAP_INST));
|
|
|
TEST_ASSERT_EQUAL_PTR(NULL, spi_flash_phys2cache(phys, SPI_FLASH_MMAP_DATA));
|
|
|
|
|
|
- /* Read the flash @ 'phys' and compare it to the data we get via cache */
|
|
|
- memcpy(buf_a, esp_partition_find, sizeof(buf_a));
|
|
|
- spi_flash_read(phys, buf_b, sizeof(buf_b));
|
|
|
- TEST_ASSERT_EQUAL_HEX8_ARRAY(buf_a, buf_b, sizeof(buf_b));
|
|
|
+ /* Read the flash @ 'phys' and compare it to the data we get via regular cache access */
|
|
|
+ spi_flash_read(phys, buf, sizeof(buf));
|
|
|
+ TEST_ASSERT_EQUAL_HEX32_ARRAY((void *)esp_partition_find, buf, sizeof(buf)/sizeof(uint32_t));
|
|
|
|
|
|
/* spi_flash_mmap is in IRAM */
|
|
|
printf("%p\n", spi_flash_mmap);
|
|
|
TEST_ASSERT_EQUAL_HEX32(SPI_FLASH_CACHE2PHYS_FAIL,
|
|
|
spi_flash_cache2phys(spi_flash_mmap));
|
|
|
|
|
|
- /* 'start' should be in DROM */
|
|
|
- phys = spi_flash_cache2phys(&start);
|
|
|
+ /* 'constant_data' should be in DROM */
|
|
|
+ phys = spi_flash_cache2phys(&constant_data);
|
|
|
TEST_ASSERT_NOT_EQUAL(SPI_FLASH_CACHE2PHYS_FAIL, phys);
|
|
|
- TEST_ASSERT_EQUAL_PTR(&start,
|
|
|
+ TEST_ASSERT_EQUAL_PTR(&constant_data,
|
|
|
spi_flash_phys2cache(phys, SPI_FLASH_MMAP_DATA));
|
|
|
TEST_ASSERT_EQUAL_PTR(NULL, spi_flash_phys2cache(phys, SPI_FLASH_MMAP_INST));
|
|
|
|
|
|
- /* Read the flash @ 'phys' and compare it to the data we get via cache */
|
|
|
- memcpy(buf_a, &start, sizeof(start));
|
|
|
- spi_flash_read(phys, buf_b, sizeof(start));
|
|
|
- TEST_ASSERT_EQUAL_HEX8_ARRAY(buf_a, buf_b, sizeof(start));
|
|
|
+ /* Read the flash @ 'phys' and compare it to the data we get via normal cache access */
|
|
|
+ spi_flash_read(phys, buf, sizeof(constant_data));
|
|
|
+ TEST_ASSERT_EQUAL_HEX8_ARRAY(constant_data, buf, sizeof(constant_data));
|
|
|
}
|
|
|
|
|
|
TEST_CASE("mmap consistent with phys2cache/cache2phys", "[spi_flash]")
|
|
|
@@ -216,15 +227,15 @@ TEST_CASE("mmap consistent with phys2cache/cache2phys", "[spi_flash]")
|
|
|
|
|
|
TEST_ASSERT_EQUAL_HEX(SPI_FLASH_CACHE2PHYS_FAIL, spi_flash_cache2phys(ptr));
|
|
|
|
|
|
- ESP_ERROR_CHECK( spi_flash_mmap(TEST_REGION_START, test_size, SPI_FLASH_MMAP_DATA, &ptr, &handle1) );
|
|
|
+ ESP_ERROR_CHECK( spi_flash_mmap(start, test_size, SPI_FLASH_MMAP_DATA, &ptr, &handle1) );
|
|
|
TEST_ASSERT_NOT_NULL(ptr);
|
|
|
TEST_ASSERT_NOT_EQUAL(0, handle1);
|
|
|
|
|
|
- TEST_ASSERT_EQUAL_HEX(TEST_REGION_START, spi_flash_cache2phys(ptr));
|
|
|
- TEST_ASSERT_EQUAL_HEX(TEST_REGION_START + 1024, spi_flash_cache2phys((void *)((intptr_t)ptr + 1024)));
|
|
|
- TEST_ASSERT_EQUAL_HEX(TEST_REGION_START + 3000, spi_flash_cache2phys((void *)((intptr_t)ptr + 3000)));
|
|
|
+ TEST_ASSERT_EQUAL_HEX(start, spi_flash_cache2phys(ptr));
|
|
|
+ TEST_ASSERT_EQUAL_HEX(start + 1024, spi_flash_cache2phys((void *)((intptr_t)ptr + 1024)));
|
|
|
+ TEST_ASSERT_EQUAL_HEX(start + 3000, spi_flash_cache2phys((void *)((intptr_t)ptr + 3000)));
|
|
|
/* this pointer lands in a different MMU table entry */
|
|
|
- TEST_ASSERT_EQUAL_HEX(TEST_REGION_START + test_size - 4, spi_flash_cache2phys((void *)((intptr_t)ptr + test_size - 4)));
|
|
|
+ TEST_ASSERT_EQUAL_HEX(start + test_size - 4, spi_flash_cache2phys((void *)((intptr_t)ptr + test_size - 4)));
|
|
|
|
|
|
spi_flash_munmap(handle1);
|
|
|
handle1 = 0;
|