From 7a2abbd0f16b771ff6bfa6bf4e172a463fa0de24 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 20 Oct 2016 15:07:32 +0200 Subject: [PATCH] permit SPIFFS_write() on NULL buffer SPIFFS_write(&spi_fs, fd, buf, count) with buf = 0x0 can be valid when dumping the firmware of the microcontroller mapped to address 0x0. SPIFFS_write(&spi_fs, fd, 0x0, firmware_size) would previously omit the first page when dumping the firmware to flash (all 0xFF). Use len instead to signal where only page header is stored in spiffs_page_allocate_data --- src/spiffs_nucleus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spiffs_nucleus.c b/src/spiffs_nucleus.c index 27ecdff..8d2bc15 100644 --- a/src/spiffs_nucleus.c +++ b/src/spiffs_nucleus.c @@ -749,7 +749,7 @@ s32_t spiffs_populate_ix_map(spiffs *fs, spiffs_fd *fd, u32_t vec_entry_start, u #if !SPIFFS_READ_ONLY // Allocates a free defined page with given obj_id // Occupies object lookup entry and page -// data may be NULL; where only page header is stored, len and page_offs is ignored +// len may be 0; where only page header is stored, data and page_offs is ignored s32_t spiffs_page_allocate_data( spiffs *fs, spiffs_obj_id obj_id, @@ -781,7 +781,7 @@ s32_t spiffs_page_allocate_data( SPIFFS_CHECK_RES(res); // write page data - if (data) { + if (len) { res = _spiffs_wr(fs, SPIFFS_OP_T_OBJ_DA | SPIFFS_OP_C_UPDT, 0,SPIFFS_OBJ_LOOKUP_ENTRY_TO_PADDR(fs, bix, entry) + sizeof(spiffs_page_header) + page_offs, len, data); SPIFFS_CHECK_RES(res);