From 3ce817ea031a43ad3e63c83656e1f2dfaf2fa6f4 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Mon, 27 Jul 2026 22:11:28 +0200 Subject: [PATCH] ide: the Atmel Studio solution master has, on the libavr port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit master carries bootloader.atsln, so main does too. Two projects, because a .cppproj is one binary at one flag set and this build has hundreds: the stock 328P pureboot loader (USART0 at 115200 on a 16 MHz crystal), and the tsb_asm tier that occupies the same 512-byte section master's own tsb project targeted. Both come out byte-identical to the Ninja build — 404 B and 510 B of .text — in both configurations. Debug keeps -Os and adds only -gdwarf-4. A loader's section is a correctness bound, and -Og builds this source to 590 B: the link at 0x7e00 accepts that without a diagnostic, 78 bytes past flash end, where rcall/rjmp wrap modulo flash size and the image dies just after activation. Debug info costs no flash, so the optimisation level stays where correctness needs it. Co-Authored-By: Claude Opus 5 --- ide/README.md | 78 ++++++++++++++++++++++ ide/bootloader.atsln | 28 ++++++++ ide/pureboot/pureboot.cppproj | 118 ++++++++++++++++++++++++++++++++++ ide/tsb_asm/tsb_asm.cppproj | 112 ++++++++++++++++++++++++++++++++ libavr | 2 +- 5 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 ide/README.md create mode 100644 ide/bootloader.atsln create mode 100644 ide/pureboot/pureboot.cppproj create mode 100644 ide/tsb_asm/tsb_asm.cppproj diff --git a/ide/README.md b/ide/README.md new file mode 100644 index 0000000..6594c07 --- /dev/null +++ b/ide/README.md @@ -0,0 +1,78 @@ +# Atmel Studio + +`master` carries `bootloader.atsln`, so this branch does too: `ide/bootloader.atsln` +builds the loaders from the same sources Ninja does, to a **byte-identical +`.text`** — 404 B for the 328P pureboot loader, 510 B for the `tsb_asm` tier in +its 512-byte section. CMake remains the build system; the solution is here so the +port opens in Studio as its predecessor did. + +## The two projects, and why two + +pureboot is a chip × backend × clock × baud matrix — `pureboot_add_loader()` +resolves a deployment into compile definitions — and a `.cppproj` is one binary +at one set of flags, so a project can only ever be one point of it. `pureboot` +is that point: the stock 328P deployment, USART0 at 115200 on a 16 MHz crystal, +an 8-second activation window. `tsb_asm` is the TinySafeBoot tier that occupies +the same 512-byte section `master`'s `tsb` project targeted. + +The other three tsb tiers (`tsb_pure`, `tsb_tricks`, `tsb_policy`) are not here. +They differ from `tsb_asm` in their source file, their section size, and — for +`tsb_policy` — two loop flags; nothing about that is a Studio concern, and what +they exist to demonstrate is a size gradient only the CMake size tests measure. +Adding one is a copy of `tsb_asm/tsb_asm.cppproj` in its own directory, with its +name, its GUID, its source path and its `--section-start` changed (`0x7c00` for +the 1 KiB tiers), plus four lines in the solution. + +`avrdevice` is a project property, so each project gets its own directory: +Studio builds into `/` whatever `OutputDirectory` +says, and two projects sharing a directory would share one object file. + +## Debug keeps `-Os` + +Both configurations compile at `-Os`; Debug adds only `-gdwarf-4`. The `.text` +is therefore identical in both, which is the point — a loader's section is a +**correctness** bound and not a budget. `-Og` builds this same source to 590 B, +and linking it at `--section-start=.text=0x7e00` on a 32 KiB part puts 78 bytes +past flash end **without a diagnostic**: `rcall`/`rjmp` targets there wrap +modulo flash size, so the image dies right after activation. A debug +configuration that silently produces that is worse than none, and DWARF costs no +flash, so the optimisation level stays where correctness needs it. + +## What Studio needs from the machine + +libavr checked out **beside this repo**, found at +`$(MSBuildProjectDirectory)\..\..\..\libavr\include` — anchored to the project, +because a plain relative path resolves against the generated makefile's +directory (the configuration's output directory), not the project's. There is no +`LIBAVR_ROOT` escape hatch: a variable exported in a shell is invisible to Studio +launched from the Start menu, and the failure reads as a missing +`libavr/libavr.hpp`. Pinning libavr as a submodule is the better answer and is on +libavr's task list. + +A GCC 16.1 toolchain registered as flavour `avr-g++-16.1.0`, nothing older +reaching `-std=c++26`. + +## Generating and gating + +One generated file is required before a project will load at all, and one command +per project checks the flags have not drifted (both from libavr's +`tools/atmelstudio/`): + +```sh +for name in pureboot tsb_asm; do + python ../libavr/tools/atmelstudio/componentinfo.py \ + "ide/$name/$name.componentinfo.xml" --device ATmega328P + python ../libavr/tools/atmelstudio/check-flags.py \ + --solution ide/bootloader.atsln --project "$name" --target "$name" \ + --compile-commands build/atmega328p-generated/compile_commands.json \ + --log "build/as-$name.log" +done +``` + +`--project` because one reference describes one binary; `--target` because +`pureboot.cpp` is compiled by every point of the size matrix and the flags +differ per point, so the basename alone does not name a reference. Release is +what the gate compares — the presets define no debug build, and Debug differs +from Release only in `-gdwarf-4`. + +Legacy (the yazoalfa-era submodules) stays on `master`. diff --git a/ide/bootloader.atsln b/ide/bootloader.atsln new file mode 100644 index 0000000..0f93a37 --- /dev/null +++ b/ide/bootloader.atsln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Atmel Studio Solution File, Format Version 11.00 +VisualStudioVersion = 14.0.23107.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "pureboot", "pureboot\pureboot.cppproj", "{99067222-32D5-49E3-B4F8-5ABA0F7722B7}" +EndProject +Project("{E66E83B9-2572-4076-B26E-6BE79FF3018A}") = "tsb_asm", "tsb_asm\tsb_asm.cppproj", "{6618D3BE-7EB3-49A2-9113-F128E396FF06}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|AVR = Debug|AVR + Release|AVR = Release|AVR + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {99067222-32D5-49E3-B4F8-5ABA0F7722B7}.Debug|AVR.ActiveCfg = Debug|AVR + {99067222-32D5-49E3-B4F8-5ABA0F7722B7}.Debug|AVR.Build.0 = Debug|AVR + {99067222-32D5-49E3-B4F8-5ABA0F7722B7}.Release|AVR.ActiveCfg = Release|AVR + {99067222-32D5-49E3-B4F8-5ABA0F7722B7}.Release|AVR.Build.0 = Release|AVR + {6618D3BE-7EB3-49A2-9113-F128E396FF06}.Debug|AVR.ActiveCfg = Debug|AVR + {6618D3BE-7EB3-49A2-9113-F128E396FF06}.Debug|AVR.Build.0 = Debug|AVR + {6618D3BE-7EB3-49A2-9113-F128E396FF06}.Release|AVR.ActiveCfg = Release|AVR + {6618D3BE-7EB3-49A2-9113-F128E396FF06}.Release|AVR.Build.0 = Release|AVR + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/ide/pureboot/pureboot.cppproj b/ide/pureboot/pureboot.cppproj new file mode 100644 index 0000000..312273b --- /dev/null +++ b/ide/pureboot/pureboot.cppproj @@ -0,0 +1,118 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.CPP + 99067222-32d5-49e3-b4f8-5aba0f7722b7 + ATmega328P + none + Executable + CPP + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + pureboot + pureboot + pureboot + avr-g++-16.1.0 + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + 0 + + + + + + + + + + + + + + + + + + -mmcu=atmega328p + True + True + True + True + False + + + NDEBUG + PUREBOOT_CLOCK_HZ=16000000 + PUREBOOT_BAUD=115200 + PUREBOOT_TIMEOUT=8 + + + + + $(MSBuildProjectDirectory)\..\..\..\libavr\include + + + Optimize for size (-Os) + True + True + True + -std=c++26 -Wextra -Werror -mrelax -fno-exceptions -fno-rtti -fno-threadsafe-statics -fno-ivopts -fira-algorithm=priority -fno-tree-ter -fno-split-wide-types + True + -mrelax -nostartfiles -Wl,--section-start=.text=0x7e00 -Wl,--defsym=pureboot_app=0 -Wl,--pmem-wrap-around=32k + + + + + + + -mmcu=atmega328p + True + True + True + True + False + + + DEBUG + PUREBOOT_CLOCK_HZ=16000000 + PUREBOOT_BAUD=115200 + PUREBOOT_TIMEOUT=8 + + + + + $(MSBuildProjectDirectory)\..\..\..\libavr\include + + + Optimize for size (-Os) + True + True + True + -std=c++26 -Wextra -Werror -mrelax -fno-exceptions -fno-rtti -fno-threadsafe-statics -fno-ivopts -fira-algorithm=priority -fno-tree-ter -fno-split-wide-types -gdwarf-4 + True + -mrelax -nostartfiles -Wl,--section-start=.text=0x7e00 -Wl,--defsym=pureboot_app=0 -Wl,--pmem-wrap-around=32k + + + + + + compile + pureboot\pureboot.cpp + + + + + + + diff --git a/ide/tsb_asm/tsb_asm.cppproj b/ide/tsb_asm/tsb_asm.cppproj new file mode 100644 index 0000000..a84f839 --- /dev/null +++ b/ide/tsb_asm/tsb_asm.cppproj @@ -0,0 +1,112 @@ + + + + 2.0 + 7.0 + com.Atmel.AVRGCC8.CPP + 6618d3be-7eb3-49a2-9113-f128e396ff06 + ATmega328P + none + Executable + CPP + $(MSBuildProjectName) + .elf + $(MSBuildProjectDirectory)\$(Configuration) + tsb_asm + tsb_asm + tsb_asm + avr-g++-16.1.0 + true + false + true + true + 0x20000000 + + true + exception_table + 2 + 0 + 0 + + + + + + + + + + + + + + + + + + -mmcu=atmega328p + True + True + True + True + False + + + NDEBUG + + + + + $(MSBuildProjectDirectory)\..\..\..\libavr\include + + + Optimize for size (-Os) + True + True + True + -std=c++26 -Wextra -Werror -mrelax -fno-exceptions -fno-rtti -fno-threadsafe-statics + True + -mrelax -nostartfiles -Wl,--section-start=.text=0x7e00 -Wl,--defsym=tsb_app=0 -Wl,--pmem-wrap-around=32k + + + + + + + -mmcu=atmega328p + True + True + True + True + False + + + DEBUG + + + + + $(MSBuildProjectDirectory)\..\..\..\libavr\include + + + Optimize for size (-Os) + True + True + True + -std=c++26 -Wextra -Werror -mrelax -fno-exceptions -fno-rtti -fno-threadsafe-statics -gdwarf-4 + True + -mrelax -nostartfiles -Wl,--section-start=.text=0x7e00 -Wl,--defsym=tsb_app=0 -Wl,--pmem-wrap-around=32k + + + + + + compile + tsb\tsb_asm.cpp + + + + + + + diff --git a/libavr b/libavr index 20d8cdb..10d33d7 160000 --- a/libavr +++ b/libavr @@ -1 +1 @@ -Subproject commit 20d8cdb8aa8a882457ebe06b04ded4aee83f2b81 +Subproject commit 10d33d78948e3870b7283ca72e60e90b9ad8e7a2