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

make eboot erase/read/write sector by sector

that makes possible having sketches with size up to the free size
This commit is contained in:
John Doe
2015-07-04 00:27:13 +03:00
committed by Ivan Grokhotkov
parent 7596ed0742
commit f3f500936d
7 changed files with 49 additions and 52 deletions

View File

@ -76,38 +76,31 @@ int copy_raw(const uint32_t src_addr,
const uint32_t dst_addr,
const uint32_t size)
{
ets_putc('\n');
ets_putc('c');
ets_putc('p');
ets_putc('\n');
// require regions to be aligned
if (src_addr & 0xfff != 0 ||
dst_addr & 0xfff != 0) {
return 1;
}
if (SPIEraseAreaEx(dst_addr, size)) {
return 2;
}
const uint32_t buffer_size = 4096;
const uint32_t buffer_size = FLASH_SECTOR_SIZE;
uint8_t buffer[buffer_size];
const uint32_t end = src_addr + size;
uint32_t left = ((size+buffer_size-1) & ~(buffer_size-1));
uint32_t saddr = src_addr;
uint32_t daddr = dst_addr;
uint32_t left = size;
while (saddr < end) {
uint32_t will_copy = (left < buffer_size) ? left : buffer_size;
if (SPIRead(saddr, buffer, will_copy)) {
return 3;
}
if (SPIWrite(daddr, buffer, will_copy)) {
return 4;
}
saddr += will_copy;
daddr += will_copy;
left -= will_copy;
while (left) {
if (SPIEraseSector(daddr/buffer_size)) {
return 2;
}
if (SPIRead(saddr, buffer, buffer_size)) {
return 3;
}
if (SPIWrite(daddr, buffer, buffer_size)) {
return 4;
}
saddr += buffer_size;
daddr += buffer_size;
left -= buffer_size;
}
return 0;
@ -123,14 +116,16 @@ void main()
if (eboot_command_read(&cmd)) {
cmd.action = ACTION_LOAD_APP;
cmd.args[0] = 0;
ets_putc('e');
ets_putc('~');
} else {
ets_putc('@');
}
eboot_command_clear();
if (cmd.action == ACTION_COPY_RAW) {
ets_putc('c'); ets_putc('p'); ets_putc(':');
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
ets_putc((char)0x30+res); ets_putc('\n');
if (res == 0) {
cmd.action = ACTION_LOAD_APP;
cmd.args[0] = cmd.args[1];
@ -138,15 +133,14 @@ void main()
}
if (cmd.action == ACTION_LOAD_APP) {
res = load_app_from_flash_raw(cmd.args[0]);
ets_putc('l'); ets_putc('d'); ets_putc('\n');
res = load_app_from_flash_raw(cmd.args[0]);
//we will get to this only on load fail
ets_putc('e'); ets_putc(':'); ets_putc((char)0x30+res); ets_putc('\n');
}
if (res) {
ets_putc('\n');
ets_putc('#');
ets_putc('0' + res);
ets_putc('\n');
SWRST;
SWRST;
}
while(true){}