From 07f93caba899513f3870354422249733d995114c Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 24 Jul 2026 17:57:47 +0200 Subject: [PATCH] pureboot: take the running slot from avr::startup::caller_page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The write guard's anchor was costing a materialised pointer and a byte swap to use one byte of it. The libavr primitive answers it in a single load, which is eight bytes off every build — and what lets the USART release fit the tightest configuration in the space: the 1284 autobaud on USART-shared pins was 514 of its 512 and is now 506, with the default pinning down from 510 to 502. Verified on silicon: the guard still refuses an erase aimed at the slot it runs from, and still permits one in the application region. Co-Authored-By: Claude Opus 4.8 (1M context) --- libavr | 2 +- pureboot/pureboot.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/libavr b/libavr index 6cfc7a8..b23b2c4 160000 --- a/libavr +++ b/libavr @@ -1 +1 @@ -Subproject commit 6cfc7a8eeec18b6a643b0daec7844f8eebc4b423 +Subproject commit b23b2c4398d8e9de6bda0312f6c18559b875d99a diff --git a/pureboot/pureboot.cpp b/pureboot/pureboot.cpp index 7881008..9dd36db 100644 --- a/pureboot/pureboot.cpp +++ b/pureboot/pureboot.cpp @@ -488,8 +488,7 @@ void fill_page(std::uint8_t bank, std::uint16_t at) // address is a word address and a slot is half as many words as bytes, so // its high byte is the slot index outright. No absolute address is ever // formed, so the image stays position-independent. - const auto return_words = reinterpret_cast(__builtin_return_address(0)); - const auto slot_high = static_cast(return_words >> 8); + const auto slot_high = avr::startup::caller_page(); await_host();