tsb: reimplement TinySafeBoot on libavr in three size tiers
The native-UART fixed-baud TinySafeBoot protocol, ported onto libavr as a
crt-free boot-section loader, in three variants that trade clarity for size:
tsb_pure 740 B idiomatic C++: SRAM page buffer, separate flash/EEPROM
leaves, shared framing; the polled `unused` guard posture.
tsb_tricks 658 B unified runtime-flag paths (noinline/noclone), call-saved
global-register page walk — attributes only, no asm.
tsb_asm 508 B streaming store + hand-rolled UART/SPM/EEPROM/erase loops;
fits the 512 B boot section (BOOTSZ=11). Trims the optional
password gate and WDT-reset bail — unreachable in C++ with
both (hand-asm is ~15 % denser). Tiers 1-2 keep them and
live in the 1 KB section they fit.
All three are .text byte-identical across libavr's generated and reflect modes.
The CMake build strips the leaked -O3 (a Release build is silently -O3, not the
-Os this loader is measured against) and gates each variant's size against its
section. A simavr harness (test/device.c + test/tsbtest.py) drives the real wire
protocol over a pty and flashes the device; the size and protocol tests run in
ctest. Verified byte-for-byte against the reference tsbloader_adv (C#/mono):
activate, read info, flash write + verify.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
44
CMakePresets.json
Normal file
44
CMakePresets.json
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"version": 8,
|
||||
"configurePresets": [
|
||||
{
|
||||
"name": "base",
|
||||
"hidden": true,
|
||||
"generator": "Ninja",
|
||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||
"toolchainFile": "$env{LIBAVR_ROOT}/cmake/avr-toolchain.cmake",
|
||||
"cacheVariables": {
|
||||
"CMAKE_BUILD_TYPE": "Release",
|
||||
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
|
||||
"CMAKE_COLOR_DIAGNOSTICS": "ON"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "atmega328p-generated",
|
||||
"inherits": "base",
|
||||
"cacheVariables": { "LIBAVR_MCU": "atmega328p", "LIBAVR_REFLECT": "OFF" }
|
||||
},
|
||||
{
|
||||
"name": "atmega328p-reflect",
|
||||
"inherits": "base",
|
||||
"cacheVariables": { "LIBAVR_MCU": "atmega328p", "LIBAVR_REFLECT": "ON" }
|
||||
}
|
||||
],
|
||||
"buildPresets": [
|
||||
{ "name": "atmega328p-generated", "configurePreset": "atmega328p-generated" },
|
||||
{ "name": "atmega328p-reflect", "configurePreset": "atmega328p-reflect" }
|
||||
],
|
||||
"workflowPresets": [
|
||||
{
|
||||
"name": "atmega328p-generated",
|
||||
"steps": [
|
||||
{ "type": "configure", "name": "atmega328p-generated" },
|
||||
{ "type": "build", "name": "atmega328p-generated" },
|
||||
{ "type": "test", "name": "atmega328p-generated" }
|
||||
]
|
||||
}
|
||||
],
|
||||
"testPresets": [
|
||||
{ "name": "atmega328p-generated", "configurePreset": "atmega328p-generated", "output": { "outputOnFailure": true } }
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user