|
|
@ -6,8 +6,9 @@ |
|
|
|
#include "cgioptiboot.h" |
|
|
|
#include "cgioptiboot.h" |
|
|
|
#include "multipart.h" |
|
|
|
#include "multipart.h" |
|
|
|
#include "espfsformat.h" |
|
|
|
#include "espfsformat.h" |
|
|
|
|
|
|
|
#include "config.h" |
|
|
|
|
|
|
|
|
|
|
|
int webServerMultipartCallback(MultipartCmd cmd, char *data, int dataLen, int position) |
|
|
|
int ICACHE_FLASH_ATTR webServerMultipartCallback(MultipartCmd cmd, char *data, int dataLen, int position) |
|
|
|
{ |
|
|
|
{ |
|
|
|
switch(cmd) |
|
|
|
switch(cmd) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -27,10 +28,38 @@ int webServerMultipartCallback(MultipartCmd cmd, char *data, int dataLen, int po |
|
|
|
data[p - position] = 0xFF; // clean espfs magic to mark as invalid
|
|
|
|
data[p - position] = 0xFF; // clean espfs magic to mark as invalid
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// TODO: flash write
|
|
|
|
|
|
|
|
|
|
|
|
int spi_flash_addr = getUserPageSectionStart() + position; |
|
|
|
|
|
|
|
int spi_flash_end_addr = spi_flash_addr + dataLen; |
|
|
|
|
|
|
|
if( spi_flash_end_addr + dataLen >= getUserPageSectionEnd() ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
os_printf("No more space in the flash!\n"); |
|
|
|
|
|
|
|
return 1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int ptr = 0; |
|
|
|
|
|
|
|
while( spi_flash_addr < spi_flash_end_addr ) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (spi_flash_addr % SPI_FLASH_SEC_SIZE == 0){ |
|
|
|
|
|
|
|
spi_flash_erase_sector(spi_flash_addr/SPI_FLASH_SEC_SIZE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int max = (spi_flash_addr | (SPI_FLASH_SEC_SIZE - 1)) + 1; |
|
|
|
|
|
|
|
int len = spi_flash_end_addr - spi_flash_addr; |
|
|
|
|
|
|
|
if( spi_flash_end_addr > max ) |
|
|
|
|
|
|
|
len = max - spi_flash_addr; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spi_flash_write( spi_flash_addr, (uint32_t *)(data + ptr), len ); |
|
|
|
|
|
|
|
ptr += len; |
|
|
|
|
|
|
|
spi_flash_addr += len; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
break; |
|
|
|
break; |
|
|
|
case FILE_DONE: |
|
|
|
case FILE_DONE: |
|
|
|
// TODO: finalize changes, set back espfs magic
|
|
|
|
{ |
|
|
|
|
|
|
|
uint32_t magic = ESPFS_MAGIC; |
|
|
|
|
|
|
|
spi_flash_write( (int)getUserPageSectionStart(), (uint32_t *)&magic, sizeof(uint32_t) ); |
|
|
|
|
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|