@@ -19,6 +19,7 @@ UpdaterClass::UpdaterClass()
19
19
, _size(0 )
20
20
, _startAddress(0 )
21
21
, _currentAddress(0 )
22
+ , _command(U_FLASH)
22
23
{
23
24
}
24
25
@@ -30,17 +31,24 @@ void UpdaterClass::_reset() {
30
31
_startAddress = 0 ;
31
32
_currentAddress = 0 ;
32
33
_size = 0 ;
34
+ _command = U_FLASH;
33
35
}
34
36
35
- bool UpdaterClass::begin (size_t size) {
37
+ bool UpdaterClass::begin (size_t size, int command) {
36
38
if (_size > 0 ){
37
39
#ifdef DEBUG_UPDATER
38
40
DEBUG_UPDATER.println (" already running" );
39
41
#endif
40
42
return false ;
41
43
}
42
44
43
- if (size == 0 ){
45
+ #ifdef DEBUG_UPDATER
46
+ if (command == U_SPIFFS) {
47
+ DEBUG_UPDATER.println (" Update SPIFFS." );
48
+ }
49
+ #endif
50
+
51
+ if (size == 0 ) {
44
52
_error = UPDATE_ERROR_SIZE;
45
53
#ifdef DEBUG_UPDATER
46
54
printError (DEBUG_UPDATER);
@@ -51,20 +59,33 @@ bool UpdaterClass::begin(size_t size){
51
59
_reset ();
52
60
_error = 0 ;
53
61
54
- // size of current sketch rounded to a sector
55
- uint32_t currentSketchSize = (ESP.getSketchSize () + FLASH_SECTOR_SIZE - 1 ) & (~(FLASH_SECTOR_SIZE - 1 ));
56
- // address of the end of the space available for sketch and update
57
- uint32_t updateEndAddress = (uint32_t )&_SPIFFS_start - 0x40200000 ;
58
- // size of the update rounded to a sector
59
- uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1 ) & (~(FLASH_SECTOR_SIZE - 1 ));
60
- // address where we will start writing the update
61
- uint32_t updateStartAddress = updateEndAddress - roundedSize;
62
-
63
- // make sure that the size of both sketches is less than the total space (updateEndAddress)
64
- if (updateStartAddress < currentSketchSize){
65
- _error = UPDATE_ERROR_SPACE;
62
+ uint32_t updateStartAddress = 0 ;
63
+ if (command == U_FLASH) {
64
+ // size of current sketch rounded to a sector
65
+ uint32_t currentSketchSize = (ESP.getSketchSize () + FLASH_SECTOR_SIZE - 1 ) & (~(FLASH_SECTOR_SIZE - 1 ));
66
+ // address of the end of the space available for sketch and update
67
+ uint32_t updateEndAddress = (uint32_t )&_SPIFFS_start - 0x40200000 ;
68
+ // size of the update rounded to a sector
69
+ uint32_t roundedSize = (size + FLASH_SECTOR_SIZE - 1 ) & (~(FLASH_SECTOR_SIZE - 1 ));
70
+ // address where we will start writing the update
71
+ updateStartAddress = updateEndAddress - roundedSize;
72
+
73
+ // make sure that the size of both sketches is less than the total space (updateEndAddress)
74
+ if (updateStartAddress < currentSketchSize) {
75
+ _error = UPDATE_ERROR_SPACE;
66
76
#ifdef DEBUG_UPDATER
67
- printError (DEBUG_UPDATER);
77
+ printError (DEBUG_UPDATER);
78
+ #endif
79
+ return false ;
80
+ }
81
+ }
82
+ else if (command == U_SPIFFS) {
83
+ updateStartAddress = (uint32_t )&_SPIFFS_start - 0x40200000 ;
84
+ }
85
+ else {
86
+ // unknown command
87
+ #ifdef DEBUG_UPDATER
88
+ DEBUG_UPDATER.println (" Unknown update command." );
68
89
#endif
69
90
return false ;
70
91
}
@@ -74,6 +95,7 @@ bool UpdaterClass::begin(size_t size){
74
95
_currentAddress = _startAddress;
75
96
_size = size;
76
97
_buffer = new uint8_t [FLASH_SECTOR_SIZE];
98
+ _command = command;
77
99
78
100
return true ;
79
101
}
@@ -95,23 +117,28 @@ bool UpdaterClass::end(bool evenIfRemaining){
95
117
return false ;
96
118
}
97
119
98
- if (evenIfRemaining){
99
- if (_bufferLen > 0 ){
120
+ if (evenIfRemaining) {
121
+ if (_bufferLen > 0 ) {
100
122
_writeBuffer ();
101
123
}
102
124
_size = progress ();
103
125
}
104
126
105
- eboot_command ebcmd;
106
- ebcmd.action = ACTION_COPY_RAW;
107
- ebcmd.args [0 ] = _startAddress;
108
- ebcmd.args [1 ] = 0x00000 ;
109
- ebcmd.args [2 ] = _size;
110
- eboot_command_write (&ebcmd);
127
+ if (_command == U_FLASH) {
128
+ eboot_command ebcmd;
129
+ ebcmd.action = ACTION_COPY_RAW;
130
+ ebcmd.args [0 ] = _startAddress;
131
+ ebcmd.args [1 ] = 0x00000 ;
132
+ ebcmd.args [2 ] = _size;
133
+ eboot_command_write (&ebcmd);
111
134
112
135
#ifdef DEBUG_UPDATER
113
136
DEBUG_UPDATER.printf (" Staged: address:0x%08X, size:0x%08X\n " , _startAddress, _size);
137
+ }
138
+ else if (_command == U_SPIFFS) {
139
+ DEBUG_UPDATER.printf (" SPIFFS: address:0x%08X, size:0x%08X\n " , _startAddress, _size);
114
140
#endif
141
+ }
115
142
116
143
_reset ();
117
144
return true ;
0 commit comments