mirror of
https://github.com/esp8266/Arduino.git
synced 2025-07-27 18:02:17 +03:00
update UpdaterClass to flashing SPIFFS image
This commit is contained in:
@ -19,6 +19,7 @@ UpdaterClass::UpdaterClass()
|
||||
, _size(0)
|
||||
, _startAddress(0)
|
||||
, _currentAddress(0)
|
||||
, _command(U_FLASH)
|
||||
{
|
||||
}
|
||||
|
||||
@ -30,9 +31,10 @@ void UpdaterClass::_reset() {
|
||||
_startAddress = 0;
|
||||
_currentAddress = 0;
|
||||
_size = 0;
|
||||
_command = U_FLASH;
|
||||
}
|
||||
|
||||
bool UpdaterClass::begin(size_t size){
|
||||
bool UpdaterClass::begin(size_t size, int command) {
|
||||
if(_size > 0){
|
||||
#ifdef DEBUG_UPDATER
|
||||
DEBUG_UPDATER.println("already running");
|
||||
@ -40,7 +42,13 @@ bool UpdaterClass::begin(size_t size){
|
||||
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;
|
||||
#ifdef DEBUG_UPDATER
|
||||
printError(DEBUG_UPDATER);
|
||||
@ -51,20 +59,33 @@ bool UpdaterClass::begin(size_t size){
|
||||
_reset();
|
||||
_error = 0;
|
||||
|
||||
//size of current sketch rounded to a sector
|
||||
uint32_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
|
||||
//address of the end of the space available for sketch and update
|
||||
uint32_t updateEndAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
|
||||
//size of the update rounded to a sector
|
||||
uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
|
||||
//address where we will start writing the update
|
||||
uint32_t updateStartAddress = updateEndAddress - roundedSize;
|
||||
uint32_t updateStartAddress = 0;
|
||||
if (command == U_FLASH) {
|
||||
//size of current sketch rounded to a sector
|
||||
uint32_t currentSketchSize = (ESP.getSketchSize() + FLASH_SECTOR_SIZE - 1) & (~(FLASH_SECTOR_SIZE - 1));
|
||||
//address of the end of the space available for sketch and update
|
||||
uint32_t updateEndAddress = (uint32_t)&_SPIFFS_start - 0x40200000;
|
||||
//size of the update rounded to a sector
|
||||
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)
|
||||
if(updateStartAddress < currentSketchSize){
|
||||
_error = UPDATE_ERROR_SPACE;
|
||||
//make sure that the size of both sketches is less than the total space (updateEndAddress)
|
||||
if(updateStartAddress < currentSketchSize) {
|
||||
_error = UPDATE_ERROR_SPACE;
|
||||
#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
|
||||
return false;
|
||||
}
|
||||
@ -74,6 +95,7 @@ bool UpdaterClass::begin(size_t size){
|
||||
_currentAddress = _startAddress;
|
||||
_size = size;
|
||||
_buffer = new uint8_t[FLASH_SECTOR_SIZE];
|
||||
_command = command;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -95,23 +117,28 @@ bool UpdaterClass::end(bool evenIfRemaining){
|
||||
return false;
|
||||
}
|
||||
|
||||
if(evenIfRemaining){
|
||||
if(_bufferLen > 0){
|
||||
if(evenIfRemaining) {
|
||||
if(_bufferLen > 0) {
|
||||
_writeBuffer();
|
||||
}
|
||||
_size = progress();
|
||||
}
|
||||
|
||||
eboot_command ebcmd;
|
||||
ebcmd.action = ACTION_COPY_RAW;
|
||||
ebcmd.args[0] = _startAddress;
|
||||
ebcmd.args[1] = 0x00000;
|
||||
ebcmd.args[2] = _size;
|
||||
eboot_command_write(&ebcmd);
|
||||
if (_command == U_FLASH) {
|
||||
eboot_command ebcmd;
|
||||
ebcmd.action = ACTION_COPY_RAW;
|
||||
ebcmd.args[0] = _startAddress;
|
||||
ebcmd.args[1] = 0x00000;
|
||||
ebcmd.args[2] = _size;
|
||||
eboot_command_write(&ebcmd);
|
||||
|
||||
#ifdef DEBUG_UPDATER
|
||||
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
|
||||
}
|
||||
|
||||
_reset();
|
||||
return true;
|
||||
|
@ -11,6 +11,9 @@
|
||||
#define UPDATE_ERROR_SIZE 4
|
||||
#define UPDATE_ERROR_STREAM 5
|
||||
|
||||
#define U_FLASH 0
|
||||
#define U_SPIFFS 100
|
||||
|
||||
//#define DEBUG_UPDATER Serial1
|
||||
|
||||
class UpdaterClass {
|
||||
@ -20,7 +23,7 @@ class UpdaterClass {
|
||||
Call this to check the space needed for the update
|
||||
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
|
||||
@ -116,6 +119,7 @@ class UpdaterClass {
|
||||
size_t _size;
|
||||
uint32_t _startAddress;
|
||||
uint32_t _currentAddress;
|
||||
uint32_t _command;
|
||||
};
|
||||
|
||||
extern UpdaterClass Update;
|
||||
|
Reference in New Issue
Block a user