Skip to content

eboot - copy_raw()'s buffers off the stack, 208 bytes smaller - #9353

Open
adamsthws wants to merge 1 commit into
esp8266:masterfrom
adamsthws:eboot-smaller-stack
Open

adamsthws wants to merge 1 commit into
esp8266:masterfrom
adamsthws:eboot-smaller-stack

Conversation

@adamsthws

@adamsthws adamsthws commented Dec 1, 2026 •

Copy link
Copy Markdown

copy_raw() kept its 4 KB sector buffer and the uzlib state (about
1.3 KB) on its stack. With a frame that large, the compiler needs more
instructions to address them than it needs for a global. This change makes
buffer and m_uncomp globals, like buffer2 and gzip_dict.

.text .rodata sector-0 image (+8: elf2bin keeps 8 bytes free) spare of 4096
master 3408 40 3488 (3496) 600
this PR 3204 40 3280 (3288) 808

The image is 208 bytes smaller. That leaves room in sector 0 for other
work, such as a copy that survives a power cut (#9354).

The 5.3 KB moves from the stack into BSS (buffer 4096 bytes, m_uncomp
1284 bytes), after the 41 KB of globals that eboot already has in DRAM.
That DRAM is free while eboot runs, and the sketch reclaims it when it
starts. eboot does not clear its BSS, and does not need to: the code writes
both buffers before it reads them, as it did on the stack. Behaviour does
not change: the same code runs on the same data, now at a fixed address.

Testing

eboot.elf was rebuilt with the toolchain that tools/get.py installs,
and tests/ci/eboot_test.sh passes. In an emulator
(bekensim, ESP8266
mode, booting the flash through the ROM), a sketch gave eboot an update as
Updater does: a raw image (75 sectors) and two gzip images (75 sectors
from about 230 KB, and 160 sectors from about 490 KB, copied over their own
source). Each copy left the flash byte for byte equal to the update, and
the new sketch started. Each copy also made the same erases and programs as
master's eboot, at the same addresses and in the same order (148, 148 and
318).

copy_raw() kept its 4 KB sector buffer and the uzlib state on its stack.
Addressing them there, past the reach of the stack-relative loads and
stores, takes more code than addressing a global. They are now globals,
as buffer2 and gzip_dict already are. Both are written before they are
read, so the uncleared BSS does not matter.

The sector-0 image goes from 3488 to 3280 bytes (3288 of its 4096 with
elf2bin's trailer).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant