mirror of
https://github.com/polhenarejos/pico-hsm.git
synced 2026-01-29 22:59:21 +00:00
Allow for null data write to allocate physical space.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
857aaf2679
commit
6777221e48
2 changed files with 7 additions and 2 deletions
6
flash.c
6
flash.c
|
|
@ -141,7 +141,8 @@ int flash_write_data_to_file(file_t *file, const uint8_t *data, uint16_t len) {
|
|||
uint16_t size_file_flash = flash_read_uint16((uintptr_t)file->data);
|
||||
if (len <= size_file_flash) { //it fits, no need to move it
|
||||
flash_program_halfword((uintptr_t)file->data, len);
|
||||
flash_program_block((uintptr_t)file->data+sizeof(uint16_t), data, len);
|
||||
if (data)
|
||||
flash_program_block((uintptr_t)file->data+sizeof(uint16_t), data, len);
|
||||
return HSM_OK;
|
||||
}
|
||||
else { //we clear the old file
|
||||
|
|
@ -155,6 +156,7 @@ int flash_write_data_to_file(file_t *file, const uint8_t *data, uint16_t len) {
|
|||
file->data = (uint8_t *)new_addr+sizeof(uintptr_t)+sizeof(uint16_t); //next addr+fid
|
||||
flash_program_halfword(new_addr+sizeof(uintptr_t), file->fid);
|
||||
flash_program_halfword((uintptr_t)file->data, len);
|
||||
flash_program_block((uintptr_t)file->data+sizeof(uint16_t), data, len);
|
||||
if (data)
|
||||
flash_program_block((uintptr_t)file->data+sizeof(uint16_t), data, len);
|
||||
return HSM_OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -132,6 +132,9 @@ int flash_program_block(uintptr_t addr, const uint8_t *data, size_t len) {
|
|||
uintptr_t addr_alg = addr & -FLASH_SECTOR_SIZE;
|
||||
page_flash_t *p = NULL;
|
||||
|
||||
if (!data || len == 0)
|
||||
return HSM_ERR_NULL_PARAM;
|
||||
|
||||
mutex_enter_blocking(&mtx_flash);
|
||||
if (ready_pages == TOTAL_FLASH_PAGES) {
|
||||
mutex_exit(&mtx_flash);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue