1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +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

@ -1,4 +1,5 @@
XTENSA_TOOLCHAIN ?=
XTENSA_TOOLCHAIN ?= ../../tools/xtensa-lx106-elf/bin/
ESPTOOL ?= ../../tools/esptool
BIN_DIR := ./
TARGET_DIR := ./

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){}

Binary file not shown.

View File

@ -4,7 +4,7 @@
* Redistribution and use is permitted according to the conditions of the
* 3-clause BSD license to be found in the LICENSE file.
*/
/*
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
@ -46,4 +46,4 @@ int SPIEraseAreaEx(const uint32_t start, const uint32_t size)
return 0;
}
*/

View File

@ -12,7 +12,7 @@ int SPIEraseBlock(uint32_t block);
int SPIEraseSector(uint32_t sector);
int SPIRead(uint32_t addr, void *dest, size_t size);
int SPIWrite(uint32_t addr, void *src, size_t size);
int SPIEraseAreaEx(const uint32_t start, const uint32_t size);
//int SPIEraseAreaEx(const uint32_t start, const uint32_t size);
#define FLASH_SECTOR_SIZE 0x1000
#define FLASH_BLOCK_SIZE 0x10000