From a22d671f42686afe9434f44ae498912abe27b2ed Mon Sep 17 00:00:00 2001 From: Alice Ziuziakowska Date: Mon, 1 Jun 2026 13:41:42 +0100 Subject: [PATCH 1/2] app: fix payload size in `bootstrap` command This was erroneously doubling the file size instead of rounding it up to the nearest multiple of the flash page size. Signed-off-by: Alice Ziuziakowska --- app/commands.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/commands.hh b/app/commands.hh index 7e8028e..75d77b3 100644 --- a/app/commands.hh +++ b/app/commands.hh @@ -218,7 +218,7 @@ struct LoadFile : public Commands { std::println("File is empty"); return 0; } - auto size = file_size + (file_size - file_size % flash::PageSize); + auto size = (file_size + flash::PageSize - 1) & ~(flash::PageSize - 1); std::vector buffer(size, 0xff); if (!file.read(reinterpret_cast(buffer.data()), file_size)) { std::println("Error reading the file."); From bbfcee3370f238a695f0622eb25f80acbdc99e3d Mon Sep 17 00:00:00 2001 From: Alice Ziuziakowska Date: Mon, 1 Jun 2026 13:43:33 +0100 Subject: [PATCH 2/2] flash: allow page program to program less than a whole page at a time Signed-off-by: Alice Ziuziakowska --- lib/flash/flash.hh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/flash/flash.hh b/lib/flash/flash.hh index 51aee5e..8693599 100644 --- a/lib/flash/flash.hh +++ b/lib/flash/flash.hh @@ -264,16 +264,17 @@ class Generic { op = Opcode::PageProgram4b; } - std::array cmd = {op}; + auto total_size = 1 + ADDR_SIZE + data.size(); + std::array cmd = {op}; for (size_t i = 0; i < ADDR_SIZE; ++i) { // This calculates the correct shift (24, 16, 8, 0 for 4-byte; 16, 8, 0 for 3-byte) cmd[1 + i] = static_cast(address >> (8 * (ADDR_SIZE - 1 - i))); } - auto slice = std::span(cmd).last<256>(); + auto payload = std::span(cmd).last(); + std::ranges::copy(data, payload.begin()); - std::ranges::copy(data, slice.begin()); - TRY_OPT(spih.transfer(cmd, std::span())); + TRY_OPT(spih.transfer(std::span(cmd).subspan(0, total_size), std::span())); return true; }