Allow for null data write to allocate physical space.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
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);
|
uint16_t size_file_flash = flash_read_uint16((uintptr_t)file->data);
|
||||||
if (len <= size_file_flash) { //it fits, no need to move it
|
if (len <= size_file_flash) { //it fits, no need to move it
|
||||||
flash_program_halfword((uintptr_t)file->data, len);
|
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;
|
return HSM_OK;
|
||||||
}
|
}
|
||||||
else { //we clear the old file
|
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
|
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(new_addr+sizeof(uintptr_t), file->fid);
|
||||||
flash_program_halfword((uintptr_t)file->data, len);
|
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;
|
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;
|
uintptr_t addr_alg = addr & -FLASH_SECTOR_SIZE;
|
||||||
page_flash_t *p = NULL;
|
page_flash_t *p = NULL;
|
||||||
|
|
||||||
|
if (!data || len == 0)
|
||||||
|
return HSM_ERR_NULL_PARAM;
|
||||||
|
|
||||||
mutex_enter_blocking(&mtx_flash);
|
mutex_enter_blocking(&mtx_flash);
|
||||||
if (ready_pages == TOTAL_FLASH_PAGES) {
|
if (ready_pages == TOTAL_FLASH_PAGES) {
|
||||||
mutex_exit(&mtx_flash);
|
mutex_exit(&mtx_flash);
|
||||||
|
|||||||
Reference in New Issue
Block a user