22
22
#include " flash_utils.h"
23
23
#include " eboot_command.h"
24
24
#include < memory>
25
- #include < interrupts.h>
25
+ #include " interrupts.h"
26
26
#include " MD5Builder.h"
27
27
#include " umm_malloc/umm_malloc.h"
28
28
#include " cont.h"
@@ -132,9 +132,43 @@ uint64_t EspClass::deepSleepMax()
132
132
133
133
}
134
134
135
+ /*
136
+ Layout of RTC Memory is as follows:
137
+ Ref: Espressif doc 2C-ESP8266_Non_OS_SDK_API_Reference, section 3.3.23 (system_rtc_mem_write)
138
+
139
+ |<------system data (256 bytes)------->|<-----------------user data (512 bytes)--------------->|
140
+
141
+ SDK function signature:
142
+ bool system_rtc_mem_read (
143
+ uint32 des_addr,
144
+ void * src_addr,
145
+ uint32 save_size
146
+ )
147
+
148
+ The system data section can't be used by the user, so:
149
+ des_addr must be >=64 (i.e.: 256/4) and <192 (i.e.: 768/4)
150
+ src_addr is a pointer to data
151
+ save_size is the number of bytes to write
152
+
153
+ For the method interface:
154
+ offset is the user block number (block size is 4 bytes) must be >= 0 and <128
155
+ data is a pointer to data, 4-byte aligned
156
+ size is number of bytes in the block pointed to by data
157
+
158
+ Same for write
159
+
160
+ Note: If the Updater class is in play, e.g.: the application uses OTA, the eboot
161
+ command will be stored into the first 128 bytes of user data, then it will be
162
+ retrieved by eboot on boot. That means that user data present there will be lost.
163
+ Ref:
164
+ - discussion in PR #5330.
165
+ - https://github.com/esp8266/esp8266-wiki/wiki/Memory-Map#memmory-mapped-io-registers
166
+ - Arduino/bootloaders/eboot/eboot_command.h RTC_MEM definition
167
+ */
168
+
135
169
bool EspClass::rtcUserMemoryRead (uint32_t offset, uint32_t *data, size_t size)
136
170
{
137
- if (size + offset > 512 ) {
171
+ if (offset * 4 + size > 512 || size == 0 ) {
138
172
return false ;
139
173
} else {
140
174
return system_rtc_mem_read (64 + offset, data, size);
@@ -143,13 +177,15 @@ bool EspClass::rtcUserMemoryRead(uint32_t offset, uint32_t *data, size_t size)
143
177
144
178
bool EspClass::rtcUserMemoryWrite (uint32_t offset, uint32_t *data, size_t size)
145
179
{
146
- if (size + offset > 512 ) {
180
+ if (offset * 4 + size > 512 || size == 0 ) {
147
181
return false ;
148
182
} else {
149
183
return system_rtc_mem_write (64 + offset, data, size);
150
184
}
151
185
}
152
186
187
+
188
+
153
189
extern " C" void __real_system_restart_local ();
154
190
void EspClass::reset (void )
155
191
{
0 commit comments