mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-11 04:48:15 +02:00
Fix write & read to flash partition.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -1,4 +1,7 @@
|
|||||||
# Name, Type, SubType, Offset, Size, Flags
|
# Name, Type, SubType, Offset, Size, Flags
|
||||||
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
|
# 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,
|
factory, app, factory, 0x10000, 1M,
|
||||||
part0, data, nvs, 0x200000, 1M,
|
part0, 0x40, 0x1, 0x200000, 1M,
|
||||||
|
|||||||
|
@@ -22,7 +22,11 @@
|
|||||||
#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM)
|
#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM)
|
||||||
#define XIP_BASE 0
|
#define XIP_BASE 0
|
||||||
#define FLASH_SECTOR_SIZE 4096
|
#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)
|
#define PICO_FLASH_SIZE_BYTES (8 * 1024 * 1024)
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include "pico/stdlib.h"
|
#include "pico/stdlib.h"
|
||||||
#include "hardware/flash.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
|
#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_DATA_HEADER_SIZE (sizeof(uintptr_t) + sizeof(uint32_t))
|
||||||
#define FLASH_PERMANENT_REGION (4 * FLASH_SECTOR_SIZE) // 4 sectors (16kb) of permanent memory
|
#define FLASH_PERMANENT_REGION (4 * FLASH_SECTOR_SIZE) // 4 sectors (16kb) of permanent memory
|
||||||
|
|
||||||
|
|||||||
@@ -166,7 +166,8 @@ void low_flash_init() {
|
|||||||
mutex_init(&mtx_flash);
|
mutex_init(&mtx_flash);
|
||||||
sem_init(&sem_wait, 0, 1);
|
sem_init(&sem_wait, 0, 1);
|
||||||
#if defined(ESP_PLATFORM)
|
#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
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -208,12 +209,12 @@ page_flash_t *find_free_page(uintptr_t addr) {
|
|||||||
flash_pages[r].address == addr_alg) { //first available
|
flash_pages[r].address == addr_alg) { //first available
|
||||||
p = &flash_pages[r];
|
p = &flash_pages[r];
|
||||||
if (!flash_pages[r].ready && !flash_pages[r].erase) {
|
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);
|
memcpy(p->page, (uint8_t *) addr_alg, FLASH_SECTOR_SIZE);
|
||||||
#else
|
#else
|
||||||
memcpy(p->page,
|
memcpy(p->page,
|
||||||
(addr >= start_data_pool &&
|
(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);
|
FLASH_SECTOR_SIZE);
|
||||||
#endif
|
#endif
|
||||||
ready_pages++;
|
ready_pages++;
|
||||||
@@ -289,8 +290,9 @@ uint8_t *flash_read(uintptr_t addr) {
|
|||||||
uint8_t *v = (uint8_t *) addr;
|
uint8_t *v = (uint8_t *) addr;
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
mutex_exit(&mtx_flash);
|
mutex_exit(&mtx_flash);
|
||||||
#else
|
#endif
|
||||||
if (addr >= start_data_pool && addr <= end_rom_pool) {
|
#if defined(ENABLE_EMULATION) || defined(ESP_PLATFORM)
|
||||||
|
if (addr >= start_data_pool && addr <= end_rom_pool + sizeof(uintptr_t)) {
|
||||||
v += (uintptr_t) map;
|
v += (uintptr_t) map;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user