mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-08 08:03:35 +02:00
Fix accessing to mapped memory.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -58,8 +58,9 @@ void process_fci(const file_t *pe, int fmd) {
|
|||||||
res_APDU[res_APDU_size++] = len & 0xff;
|
res_APDU[res_APDU_size++] = len & 0xff;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res_APDU[res_APDU_size++] = pe->data[1];
|
uint16_t v = file_get_size(pe);
|
||||||
res_APDU[res_APDU_size++] = pe->data[0];
|
res_APDU[res_APDU_size++] = v >> 8;
|
||||||
|
res_APDU[res_APDU_size++] = v & 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ extern int flash_program_halfword (uintptr_t addr, uint16_t data);
|
|||||||
extern int flash_program_uintptr(uintptr_t, uintptr_t);
|
extern int flash_program_uintptr(uintptr_t, uintptr_t);
|
||||||
extern uintptr_t flash_read_uintptr(uintptr_t addr);
|
extern uintptr_t flash_read_uintptr(uintptr_t addr);
|
||||||
extern uint16_t flash_read_uint16(uintptr_t addr);
|
extern uint16_t flash_read_uint16(uintptr_t addr);
|
||||||
|
extern uint8_t *flash_read(uintptr_t addr);
|
||||||
|
|
||||||
extern void low_flash_available();
|
extern void low_flash_available();
|
||||||
|
|
||||||
@@ -133,7 +134,7 @@ int flash_write_data_to_file_offset(file_t *file, const uint8_t *data, uint16_t
|
|||||||
flash_clear_file(file);
|
flash_clear_file(file);
|
||||||
if (offset > 0) {
|
if (offset > 0) {
|
||||||
old_data = (uint8_t *)calloc(1, offset+len);
|
old_data = (uint8_t *)calloc(1, offset+len);
|
||||||
memcpy(old_data, file->data+sizeof(uint16_t), offset);
|
memcpy(old_data, flash_read((uintptr_t)(file->data+sizeof(uint16_t))), offset);
|
||||||
memcpy(old_data+offset, data, len);
|
memcpy(old_data+offset, data, len);
|
||||||
len = offset+len;
|
len = offset+len;
|
||||||
data = old_data;
|
data = old_data;
|
||||||
|
|||||||
@@ -55,7 +55,11 @@ static page_flash_t flash_pages[TOTAL_FLASH_PAGES];
|
|||||||
static mutex_t mtx_flash;
|
static mutex_t mtx_flash;
|
||||||
static semaphore_t sem_wait;
|
static semaphore_t sem_wait;
|
||||||
#endif
|
#endif
|
||||||
|
#ifndef ENABLE_EMULATION
|
||||||
static bool locked_out = false;
|
static bool locked_out = false;
|
||||||
|
#else
|
||||||
|
static bool locked_out = true;
|
||||||
|
#endif
|
||||||
|
|
||||||
static uint8_t ready_pages = 0;
|
static uint8_t ready_pages = 0;
|
||||||
|
|
||||||
@@ -63,8 +67,7 @@ bool flash_available = false;
|
|||||||
|
|
||||||
|
|
||||||
//this function has to be called from the core 0
|
//this function has to be called from the core 0
|
||||||
void do_flash()
|
void do_flash() {
|
||||||
{
|
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
if (mutex_try_enter(&mtx_flash, NULL) == true) {
|
if (mutex_try_enter(&mtx_flash, NULL) == true) {
|
||||||
#endif
|
#endif
|
||||||
@@ -104,11 +107,11 @@ void do_flash()
|
|||||||
#ifdef ENABLE_EMULATION
|
#ifdef ENABLE_EMULATION
|
||||||
msync(map, PICO_FLASH_SIZE_BYTES, MS_SYNC);
|
msync(map, PICO_FLASH_SIZE_BYTES, MS_SYNC);
|
||||||
#endif
|
#endif
|
||||||
flash_available = false;
|
|
||||||
if (ready_pages != 0) {
|
if (ready_pages != 0) {
|
||||||
printf("ERROR: DO FLASH DOES NOT HAVE ZERO PAGES\n");
|
printf("ERROR: DO FLASH DOES NOT HAVE ZERO PAGES\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
flash_available = false;
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
mutex_exit(&mtx_flash);
|
mutex_exit(&mtx_flash);
|
||||||
}
|
}
|
||||||
@@ -169,7 +172,11 @@ page_flash_t *find_free_page(uintptr_t addr) {
|
|||||||
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
|
||||||
memcpy(p->page, (uint8_t *)addr_alg, FLASH_SECTOR_SIZE);
|
memcpy(p->page, (uint8_t *)addr_alg, FLASH_SECTOR_SIZE);
|
||||||
|
#else
|
||||||
|
memcpy(p->page, (uint8_t *)(map+addr_alg), FLASH_SECTOR_SIZE);
|
||||||
|
#endif
|
||||||
ready_pages++;
|
ready_pages++;
|
||||||
p->address = addr_alg;
|
p->address = addr_alg;
|
||||||
p->ready = true;
|
p->ready = true;
|
||||||
@@ -230,8 +237,7 @@ uint8_t *flash_read(uintptr_t addr) {
|
|||||||
mutex_enter_blocking(&mtx_flash);
|
mutex_enter_blocking(&mtx_flash);
|
||||||
#endif
|
#endif
|
||||||
if (ready_pages > 0) {
|
if (ready_pages > 0) {
|
||||||
for (int r = 0; r < TOTAL_FLASH_PAGES; r++)
|
for (int r = 0; r < TOTAL_FLASH_PAGES; r++) {
|
||||||
{
|
|
||||||
if (flash_pages[r].ready && flash_pages[r].address == addr_alg) {
|
if (flash_pages[r].ready && flash_pages[r].address == addr_alg) {
|
||||||
uint8_t *v = &flash_pages[r].page[addr&(FLASH_SECTOR_SIZE-1)];
|
uint8_t *v = &flash_pages[r].page[addr&(FLASH_SECTOR_SIZE-1)];
|
||||||
#ifndef ENABLE_EMULATION
|
#ifndef ENABLE_EMULATION
|
||||||
@@ -244,6 +250,8 @@ 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
|
||||||
|
v += (uintptr_t)map;
|
||||||
#endif
|
#endif
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user