1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-29 05:21:37 +03:00

update UpdaterClass to flashing SPIFFS image

This commit is contained in:
Pascal Gollor
2015-09-18 16:44:10 +02:00
parent 0dcb883b81
commit f54386e1c0
2 changed files with 54 additions and 23 deletions

View File

@ -19,6 +19,7 @@ UpdaterClass::UpdaterClass()
, _size(0) , _size(0)
, _startAddress(0) , _startAddress(0)
, _currentAddress(0) , _currentAddress(0)
, _command(U_FLASH)
{ {
} }
@ -30,9 +31,10 @@ void UpdaterClass::_reset() {
_startAddress = 0; _startAddress = 0;
_currentAddress = 0; _currentAddress = 0;
_size = 0; _size = 0;
_command = U_FLASH;
} }
bool UpdaterClass::begin(size_t size){ bool UpdaterClass::begin(size_t size, int command) {
if(_size > 0){ if(_size > 0){
#ifdef DEBUG_UPDATER #ifdef DEBUG_UPDATER
DEBUG_UPDATER.println("already running"); DEBUG_UPDATER.println("already running");
@ -40,7 +42,13 @@ bool UpdaterClass::begin(size_t size){
return false; return false;
} }
if(size == 0){ #ifdef DEBUG_UPDATER
if (command == U_SPIFFS) {
DEBUG_UPDATER.println("Update SPIFFS.");
}
#endif
if(size == 0) {
_error = UPDATE_ERROR_SIZE; _error = UPDATE_ERROR_SIZE;
#ifdef DEBUG_UPDATER #ifdef DEBUG_UPDATER
printError(DEBUG_UPDATER); printError(DEBUG_UPDATER);
@ -51,20 +59,33 @@ bool UpdaterClass::begin(size_t size){
_reset(); _reset();
_error = 0; _error = 0;
//size of current sketch rounded to a sector uint32_t updateStartAddress = 0;
uint32_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1)); if (command == U_FLASH) {
//address of the end of the space available for sketch and update //size of current sketch rounded to a sector
uint32_t updateEndAddress = (uint32_t)&_SPIFFS_start - 0x40200000; uint32_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
//size of the update rounded to a sector //address of the end of the space available for sketch and update
uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1)); uint32_t updateEndAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
//address where we will start writing the update //size of the update rounded to a sector
uint32_t updateStartAddress = updateEndAddress - roundedSize; uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
//address where we will start writing the update
updateStartAddress = updateEndAddress - roundedSize;
//make sure that the size of both sketches is less than the total space (updateEndAddress) //make sure that the size of both sketches is less than the total space (updateEndAddress)
if(updateStartAddress < currentSketchSize){ if(updateStartAddress < currentSketchSize) {
_error = UPDATE_ERROR_SPACE; _error = UPDATE_ERROR_SPACE;
#ifdef DEBUG_UPDATER #ifdef DEBUG_UPDATER
printError(DEBUG_UPDATER); printError(DEBUG_UPDATER);
#endif
return false;
}
}
else if (command == U_SPIFFS) {
updateStartAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
}
else {
// unknown command
#ifdef DEBUG_UPDATER
DEBUG_UPDATER.println("Unknown update command.");
#endif #endif
return false; return false;
} }
@ -74,6 +95,7 @@ bool UpdaterClass::begin(size_t size){
_currentAddress = _startAddress; _currentAddress = _startAddress;
_size = size; _size = size;
_buffer = new uint8_t[FLASH_SECTOR_SIZE]; _buffer = new uint8_t[FLASH_SECTOR_SIZE];
_command = command;
return true; return true;
} }
@ -95,23 +117,28 @@ bool UpdaterClass::end(bool evenIfRemaining){
return false; return false;
} }
if(evenIfRemaining){ if(evenIfRemaining) {
if(_bufferLen > 0){ if(_bufferLen > 0) {
_writeBuffer(); _writeBuffer();
} }
_size = progress(); _size = progress();
} }
eboot_command ebcmd; if (_command == U_FLASH) {
ebcmd.action = ACTION_COPY_RAW; eboot_command ebcmd;
ebcmd.args[0] = _startAddress; ebcmd.action = ACTION_COPY_RAW;
ebcmd.args[1] = 0x00000; ebcmd.args[0] = _startAddress;
ebcmd.args[2] = _size; ebcmd.args[1] = 0x00000;
eboot_command_write(&ebcmd); ebcmd.args[2] = _size;
eboot_command_write(&ebcmd);
#ifdef DEBUG_UPDATER #ifdef DEBUG_UPDATER
DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08X\n", _startAddress, _size); DEBUG_UPDATER.printf("Staged: address:0x%08X, size:0x%08X\n", _startAddress, _size);
}
else if (_command == U_SPIFFS) {
DEBUG_UPDATER.printf("SPIFFS: address:0x%08X, size:0x%08X\n", _startAddress, _size);
#endif #endif
}
_reset(); _reset();
return true; return true;

View File

@ -11,6 +11,9 @@
#define UPDATE_ERROR_SIZE 4 #define UPDATE_ERROR_SIZE 4
#define UPDATE_ERROR_STREAM 5 #define UPDATE_ERROR_STREAM 5
#define U_FLASH 0
#define U_SPIFFS 100
//#define DEBUG_UPDATER Serial1 //#define DEBUG_UPDATER Serial1
class UpdaterClass { class UpdaterClass {
@ -20,7 +23,7 @@ class UpdaterClass {
Call this to check the space needed for the update Call this to check the space needed for the update
Will return false if there is not enough space Will return false if there is not enough space
*/ */
bool begin(size_t size); bool begin(size_t size, int = U_FLASH);
/* /*
Writes a buffer to the flash and increments the address Writes a buffer to the flash and increments the address
@ -116,6 +119,7 @@ class UpdaterClass {
size_t _size; size_t _size;
uint32_t _startAddress; uint32_t _startAddress;
uint32_t _currentAddress; uint32_t _currentAddress;
uint32_t _command;
}; };
extern UpdaterClass Update; extern UpdaterClass Update;