diff --git a/partitions.csv b/partitions.csv index 9d74ef7..89fe79f 100755 --- a/partitions.csv +++ b/partitions.csv @@ -1,4 +1,7 @@ # Name, Type, SubType, Offset, Size, Flags # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap + +nvs, data, nvs, 0x9000, 0x6000 +phy_init, data, phy, 0xf000, 0x1000 factory, app, factory, 0x10000, 1M, -part0, data, nvs, 0x200000, 1M, +part0, 0x40, 0x1, 0x200000, 1M, diff --git a/src/fs/flash.c b/src/fs/flash.c index 8d83a7e..430b1d1 100644 --- a/src/fs/flash.c +++ b/src/fs/flash.c @@ -22,7 +22,11 @@ #if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM) #define XIP_BASE 0 #define FLASH_SECTOR_SIZE 4096 +#ifdef ESP_PLATFORM +#define PICO_FLASH_SIZE_BYTES (1 * 1024 * 1024) +#else #define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024) +#endif #else #include "pico/stdlib.h" #include "hardware/flash.h" @@ -38,7 +42,11 @@ * | | * ------------------------------------------------------ */ +#ifdef ESP_PLATFORM +#define FLASH_TARGET_OFFSET 0 +#else #define FLASH_TARGET_OFFSET (PICO_FLASH_SIZE_BYTES >> 1) // DATA starts at the mid of flash +#endif #define FLASH_DATA_HEADER_SIZE (sizeof(uintptr_t) + sizeof(uint32_t)) #define FLASH_PERMANENT_REGION (4 * FLASH_SECTOR_SIZE) // 4 sectors (16kb) of permanent memory diff --git a/src/fs/low_flash.c b/src/fs/low_flash.c index ec96437..b5c2837 100644 --- a/src/fs/low_flash.c +++ b/src/fs/low_flash.c @@ -166,7 +166,8 @@ void low_flash_init() { mutex_init(&mtx_flash); sem_init(&sem_wait, 0, 1); #if defined(ESP_PLATFORM) - part0 = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_NVS, "part0"); + part0 = esp_partition_find_first(0x40, 0x1, "part0"); + esp_partition_mmap(part0, 0, part0->size, ESP_PARTITION_MMAP_DATA, (const void **)&map, (esp_partition_mmap_handle_t *)&fd_map); #endif #endif } @@ -208,12 +209,12 @@ page_flash_t *find_free_page(uintptr_t addr) { flash_pages[r].address == addr_alg) { //first available p = &flash_pages[r]; if (!flash_pages[r].ready && !flash_pages[r].erase) { -#ifndef ENABLE_EMULATION +#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM) memcpy(p->page, (uint8_t *) addr_alg, FLASH_SECTOR_SIZE); #else memcpy(p->page, (addr >= start_data_pool && - addr <= end_rom_pool) ? (uint8_t *) (map + addr_alg) : (uint8_t *) addr_alg, + addr <= end_rom_pool + sizeof(uintptr_t)) ? (uint8_t *) (map + addr_alg) : (uint8_t *) addr_alg, FLASH_SECTOR_SIZE); #endif ready_pages++; @@ -289,8 +290,9 @@ uint8_t *flash_read(uintptr_t addr) { uint8_t *v = (uint8_t *) addr; #ifndef ENABLE_EMULATION mutex_exit(&mtx_flash); -#else - if (addr >= start_data_pool && addr <= end_rom_pool) { +#endif +#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM) + if (addr >= start_data_pool && addr <= end_rom_pool + sizeof(uintptr_t)) { v += (uintptr_t) map; } #endif