Skip to content

Commit bbc14c0

Browse files
Use 32b loads to set print strings (#7545)
Instead of using either a series of etc_putc or setting a series of bytes one by one, use a simple macro to define 32b constants to build up strings. Saves ~30 bytes of program code in eboot for #6538 to work with.
1 parent e79eb11 commit bbc14c0

File tree

2 files changed

+23
-14
lines changed

2 files changed

+23
-14
lines changed

bootloaders/eboot/eboot.c

+23-14
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ extern unsigned char _gzip_dict;
2121
extern void ets_wdt_enable(void);
2222
extern void ets_wdt_disable(void);
2323

24+
// Converts bit of a string into a uint32
25+
#define S(a,b,c,d) ( (((uint32_t)a) & 0xff) | (((uint32_t)b) << 8) | (((uint32_t)c) << 16) | (((uint32_t)d)<<24) )
26+
2427
int print_version(const uint32_t flash_addr)
2528
{
2629
uint32_t ver;
2730
if (SPIRead(flash_addr + APP_START_OFFSET + sizeof(image_header_t) + sizeof(section_header_t), &ver, sizeof(ver))) {
2831
return 1;
2932
}
30-
char fmt[7];
31-
fmt[0] = 'v';
32-
fmt[1] = '%';
33-
fmt[2] = '0';
34-
fmt[3] = '8';
35-
fmt[4] = 'x';
36-
fmt[5] = '\n';
37-
fmt[6] = 0;
33+
// We don't have BSS and can't print from flash, so build up string
34+
// 4 chars at a time. Smaller code than byte-wise assignment.
35+
uint32_t fmt[2];
36+
fmt[0] = S('v', '%', '0', '8');
37+
fmt[1] = S('x', '\n', 0, 0);
3838
ets_printf((const char*) fmt, ver);
3939
return 0;
4040
}
@@ -234,26 +234,32 @@ int main()
234234
}
235235

236236
if (cmd.action == ACTION_COPY_RAW) {
237-
ets_putc('c'); ets_putc('p'); ets_putc(':');
237+
uint32_t cp = S('c', 'p', ':', 0);
238+
ets_printf((const char *)cp);
238239

239240
ets_wdt_disable();
240241
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2], false);
241242
ets_wdt_enable();
242243

243-
ets_putc('0'+res); ets_putc('\n');
244+
cp = S('0' + res, '\n', 0, 0 );
245+
ets_printf((const char *)cp);
244246
#if 0
245247
//devyte: this verify step below (cmp:) only works when the end of copy operation above does not overwrite the
246248
//beginning of the image in the empty area, see #7458. Disabling for now.
247249
//TODO: replace the below verify with hash type, crc, or similar.
248250
// Verify the copy
249-
ets_putc('c'); ets_putc('m'); ets_putc('p'); ets_putc(':');
251+
uint32_t v[2];
252+
v[0] = S('c', 'm', 'p', ':');
253+
v[1] = 0;
254+
ets_printf(const char *)v);
250255
if (res == 0) {
251256
ets_wdt_disable();
252257
res = copy_raw(cmd.args[0], cmd.args[1], cmd.args[2], true);
253258
ets_wdt_enable();
254259
}
255260

256-
ets_putc('0'+res); ets_putc('\n');
261+
cp = S('0' + res, '\n', 0, 0 );
262+
ets_printf((const char *)cp);
257263
#endif
258264
if (res == 0) {
259265
cmd.action = ACTION_LOAD_APP;
@@ -268,8 +274,11 @@ int main()
268274
if (cmd.action == ACTION_LOAD_APP) {
269275
ets_putc('l'); ets_putc('d'); ets_putc('\n');
270276
res = load_app_from_flash_raw(cmd.args[0]);
271-
//we will get to this only on load fail
272-
ets_putc('e'); ets_putc(':'); ets_putc('0'+res); ets_putc('\n');
277+
// We will get to this only on load fail
278+
uint32_t e[2];
279+
e[0] = S('e', ':', '0' + res, '\n' );
280+
e[1] = 0;
281+
ets_printf((const char*)e);
273282
}
274283

275284
if (res) {

bootloaders/eboot/eboot.elf

-8 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)