12
12
#include <string.h>
13
13
#include "flash.h"
14
14
#include "eboot_command.h"
15
-
#include "spi_vendors.h"
16
15
#include <uzlib.h>
17
16
18
17
extern unsigned char _gzip_dict;
@@ -115,10 +114,12 @@ int uzlib_flash_read_cb(struct uzlib_uncomp *m)
115
114
}
116
115
117
116
unsigned char gzip_dict[32768];
117
+
uint8_t buffer2[FLASH_SECTOR_SIZE]; // no room for this on the stack
118
118
119
119
int copy_raw(const uint32_t src_addr,
120
120
const uint32_t dst_addr,
121
-
const uint32_t size)
121
+
const uint32_t size,
122
+
const bool verify)
122
123
{
123
124
// require regions to be aligned
124
125
if ((src_addr & 0xfff) != 0 ||
@@ -158,8 +159,10 @@ int copy_raw(const uint32_t src_addr,
158
159
gzip = true;
159
160
}
160
161
while (left > 0) {
161
-
if (SPIEraseSector(daddr/buffer_size)) {
162
-
return 2;
162
+
if (!verify) {
163
+
if (SPIEraseSector(daddr/buffer_size)) {
164
+
return 2;
165
+
}
163
166
}
164
167
if (!gzip) {
165
168
if (SPIRead(saddr, buffer, buffer_size)) {
@@ -179,8 +182,17 @@ int copy_raw(const uint32_t src_addr,
179
182
buffer[i] = 0xff;
180
183
}
181
184
}
182
-
if (SPIWrite(daddr, buffer, buffer_size)) {
183
-
return 4;
185
+
if (verify) {
186
+
if (SPIRead(daddr, buffer2, buffer_size)) {
187
+
return 4;
188
+
}
189
+
if (memcmp(buffer, buffer2, buffer_size)) {
190
+
return 9;
191
+
}
192
+
} else {
193
+
if (SPIWrite(daddr, buffer, buffer_size)) {
194
+
return 4;
195
+
}
184
196
}
185
197
saddr += buffer_size;
186
198
daddr += buffer_size;
@@ -190,29 +202,6 @@ int copy_raw(const uint32_t src_addr,
190
202
return 0;
191
203
}
192
204
193
-
//#define XMC_SUPPORT
194
-
#ifdef XMC_SUPPORT
195
-
// Define a few SPI0 registers we need access to
196
-
#define ESP8266_REG(addr) *((volatile uint32_t *)(0x60000000+(addr)))
197
-
#define SPI0CMD ESP8266_REG(0x200)
198
-
#define SPI0CLK ESP8266_REG(0x218)
199
-
#define SPI0C ESP8266_REG(0x208)
200
-
#define SPI0W0 ESP8266_REG(0x240)
201
-
202
-
#define SPICMDRDID (1 << 28)
203
-
204
-
/* spi_flash_get_id()
205
-
Returns the flash chip ID - same as the SDK function.
206
-
We need our own version as the SDK isn't available here.
207
-
*/
208
-
uint32_t __attribute__((noinline)) spi_flash_get_id() {
209
-
SPI0W0=0;
210
-
SPI0CMD=SPICMDRDID;
211
-
while (SPI0CMD) {}
212
-
return SPI0W0;
213
-
}
214
-
#endif // XMC_SUPPORT
215
-
216
205
int main()
217
206
{
218
207
int res = 9;
@@ -235,47 +224,20 @@ int main()
235
224
if (cmd.action == ACTION_COPY_RAW) {
236
225
ets_putc('c'); ets_putc('p'); ets_putc(':');
237
226
238
-
#ifdef XMC_SUPPORT
239
-
// save the flash access speed registers
240
-
uint32_t spi0clk = SPI0CLK;
241
-
uint32_t spi0c = SPI0C;
242
-
243
-
uint32_t vendor = spi_flash_get_id() & 0x000000ff;
244
-
if (vendor == SPI_FLASH_VENDOR_XMC) {
245
-
uint32_t flashinfo=0;
246
-
if (SPIRead(0, &flashinfo, 4)) {
247
-
// failed to read the configured flash speed.
248
-
// Do not change anything,
249
-
} else {
250
-
// select an appropriate flash speed
251
-
// Register values are those used by ROM
252
-
switch ((flashinfo >> 24) & 0x0f) {
253
-
case 0x0: // 40MHz, slow to 20
254
-
case 0x1: // 26MHz, slow to 20
255
-
SPI0CLK = 0x00003043;
256
-
SPI0C = 0x00EAA313;
257
-
break;
258
-
case 0x2: // 20MHz, no change
259
-
break;
260
-
case 0xf: // 80MHz, slow to 26
261
-
SPI0CLK = 0x00002002;
262
-
SPI0C = 0x00EAA202;
263
-
break;
264
-
default:
265
-
break;
266
-
}
267
-
}
268
-
}
269
-
#endif // XMC_SUPPORT
270
227
ets_wdt_disable();
271
-
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
228
+
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2], false);
272
229
ets_wdt_enable();
273
-
274
-
#ifdef XMC_SUPPORT
275
-
// restore the saved flash access speed registers
276
-
SPI0CLK = spi0clk;
277
-
SPI0C = spi0c;
278
-
#endif
230
+
231
+
ets_putc('0'+res); ets_putc('\n');
232
+
233
+
// Verify the copy
234
+
ets_putc('c'); ets_putc('m'); ets_putc('p'); ets_putc(':');
235
+
if (res == 0) {
236
+
ets_wdt_disable();
237
+
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2], true);
238
+
ets_wdt_enable();
239
+
}
240
+
279
241
ets_putc('0'+res); ets_putc('\n');
280
242
if (res == 0) {
281
243
cmd.action = ACTION_LOAD_APP;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4