Fix write & read to flash partition.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-04-09 19:58:33 +02:00
parent 1ba109bd0a
commit ab1b245f4f
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
3 changed files with 19 additions and 6 deletions

View file

@ -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,

1 # Name, Type, SubType, Offset, Size, Flags
2 # Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
3 nvs, data, nvs, 0x9000, 0x6000
4 phy_init, data, phy, 0xf000, 0x1000
5 factory, app, factory, 0x10000, 1M,
6 factory, app, factory, 0x10000, 1M, part0, 0x40, 0x1, 0x200000, 1M,
7

View file

@ -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

View file

@ -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