Skip to content

Commit 91ca9ba

Browse files
committed
Make sure WDT is re-enabled in eboot even in case of error (#517)
1 parent 481cee6 commit 91ca9ba

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

bootloaders/eboot/eboot.c

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
1+
/* Copyright (c) 2015 Ivan Grokhotkov. All rights reserved.
22
* This file is part of eboot bootloader.
33
*
44
* Redistribution and use is permitted according to the conditions of the
@@ -26,10 +26,10 @@ int load_app_from_flash_raw(const uint32_t flash_addr)
2626
return 1;
2727
}
2828
pos += sizeof(image_header);
29-
29+
3030

3131
for (uint32_t section_index = 0;
32-
section_index < image_header.num_segments;
32+
section_index < image_header.num_segments;
3333
++section_index)
3434
{
3535
section_header_t section_header = {0};
@@ -74,8 +74,8 @@ int load_app_from_flash_raw(const uint32_t flash_addr)
7474

7575

7676

77-
int copy_raw(const uint32_t src_addr,
78-
const uint32_t dst_addr,
77+
int copy_raw(const uint32_t src_addr,
78+
const uint32_t dst_addr,
7979
const uint32_t size)
8080
{
8181
// require regions to be aligned
@@ -90,25 +90,21 @@ int copy_raw(const uint32_t src_addr,
9090
uint32_t saddr = src_addr;
9191
uint32_t daddr = dst_addr;
9292

93-
ets_wdt_disable();
94-
9593
while (left) {
96-
if (SPIEraseSector(daddr/buffer_size)) {
97-
return 2;
98-
}
99-
if (SPIRead(saddr, buffer, buffer_size)) {
100-
return 3;
101-
}
102-
if (SPIWrite(daddr, buffer, buffer_size)) {
103-
return 4;
104-
}
105-
saddr += buffer_size;
106-
daddr += buffer_size;
107-
left -= buffer_size;
94+
if (SPIEraseSector(daddr/buffer_size)) {
95+
return 2;
96+
}
97+
if (SPIRead(saddr, buffer, buffer_size)) {
98+
return 3;
99+
}
100+
if (SPIWrite(daddr, buffer, buffer_size)) {
101+
return 4;
102+
}
103+
saddr += buffer_size;
104+
daddr += buffer_size;
105+
left -= buffer_size;
108106
}
109107

110-
ets_wdt_enable();
111-
112108
return 0;
113109
}
114110

@@ -127,10 +123,12 @@ void main()
127123
ets_putc('@');
128124
}
129125
eboot_command_clear();
130-
126+
131127
if (cmd.action == ACTION_COPY_RAW) {
132128
ets_putc('c'); ets_putc('p'); ets_putc(':');
129+
ets_wdt_disable();
133130
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2]);
131+
ets_wdt_enable();
134132
ets_putc('0'+res); ets_putc('\n');
135133
if (res == 0) {
136134
cmd.action = ACTION_LOAD_APP;
@@ -139,14 +137,14 @@ void main()
139137
}
140138

141139
if (cmd.action == ACTION_LOAD_APP) {
142-
ets_putc('l'); ets_putc('d'); ets_putc('\n');
143-
res = load_app_from_flash_raw(cmd.args[0]);
144-
//we will get to this only on load fail
145-
ets_putc('e'); ets_putc(':'); ets_putc('0'+res); ets_putc('\n');
140+
ets_putc('l'); ets_putc('d'); ets_putc('\n');
141+
res = load_app_from_flash_raw(cmd.args[0]);
142+
//we will get to this only on load fail
143+
ets_putc('e'); ets_putc(':'); ets_putc('0'+res); ets_putc('\n');
146144
}
147145

148146
if (res) {
149-
SWRST;
147+
SWRST;
150148
}
151149

152150
while(true){}

bootloaders/eboot/eboot.elf

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)