Skip to content

selector: the first sector - bank selection, trial and rollback, persistency; port for the STM32F7 - #152

Open
JaxCalder wants to merge 3 commits into
masterfrom
feat/selector
Open

JaxCalder wants to merge 3 commits into
masterfrom
feat/selector

Conversation

@JaxCalder

Copy link
Copy Markdown
Contributor

What

The selector – the code of the first sector of the flash (S0) – with its port for the STM32F7, the table that the firmware calls, and the tool that makes the images of the banks. Nothing in dmod-boot uses it yet (the firmware is not linked for the banks); this is the base.

  • selector/src, include/dmsel.h – the portable core (2.8 kB): images with a 512-byte header (magic, version, size, CRC, vectors at +0x200 for VTOR), the choice of the bank, a try of an image on trial (3 starts, then dropped, back to the previous one), a lost state rebuilt from the banks, the store in one sector (a log of CRC-protected records: the state and the persistent items, compacted in RAM).
  • selector/fw – the selector as firmware for the STM32F746 (5.4 kB of 32 kB): the flash registers (only the store sector is ever erased/programmed), the jump with VTOR and MSP, the watchdog for an image on trial (DMSEL_WATCHDOG_MS, 0 until the firmware feeds it), dmlog for the log.
  • include/dmsel_table.h – the table of functions at 0x08000100 for the firmware (the SAL Dmod_Firmware* / Dmod_*Persistency will be implemented over it); the state and the scratch memory are the firmware's.
  • tools/dmsel_mkimage.py – the header and the CRC in front of the code linked at the bank + 0x200.
  • fw/testbank – a test image of a bank (reports what the table says into RAM).

Flash layout: S0 selector, S1 store (persistency + state), S2/S3 file systems of the banks, A = S4+S5, B = S6+S7 (384 kB each).

Tested

  • Host: 1208 checks on a flash in RAM with the rules of the real one (programming only on erased words, a power cut at any program), AddressSanitizer/UBSanitizer; a ctest checks that the core accepts the images of the tool. CI job test-selector also builds the F7 firmware and the test images.
  • STM32F746G-DISCO (selector in S0, two test images): the newest good image starts; a persistent item is written and read back; the other bank on trial starts with tries 1, 2, 3 and at the fourth start is dropped and the first one runs; ready confirms; a permanent choice holds across resets.

Next: link dmod-boot for the banks (origin, header, VTOR), the SAL over the table, bootok, the update command, install.

🤖 Generated with Claude Code

JaxCalder and others added 3 commits October 28, 2026 21:36
…rmation, store of the state and of the persistent items

The code of the first sector of the flash. Portable C with a port made of five functions (the flash as
memory, erase, program, jump, log) and a layout; nothing of the chip is in the core (2.8 kB of code on
Cortex-M).

* Images: a header of up to 512 bytes at the start of a bank (magic, version, size, CRC of the image,
  offset of the vectors - a multiple of 512, as VTOR wants), verified before every start.
* Choice: the selected bank, then the one to go back to, then the others; a bank on trial gets
  max_tries starts and is dropped when it does not confirm; a lost state is rebuilt from the banks (the
  newest good image).
* The store (one sector, S1): a log of CRC-protected records - the state of the banks and the
  persistent items (Dmod_WritePersistency / Dmod_ReadPersistency); a full store is compacted in RAM.
  Payload first, header last, so that a record cut short is not a record.
* The functions behind Dmod_FirmwareGetBankCount / GetRunningBank / GetBankInfo / VerifyBank /
  SelectBank / Ready.

Tests on the flash in RAM that keeps the rules of the real one (programming only on erased words;
a power cut at any program): 1202 checks, run with the sanitizers in the CI.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… the table for the firmware, the image tool

* selector/fw: the selector as firmware (5.4 kB of the 32 kB sector): vectors and the reset handler, the linker
  script (the DTCM for the RAM, the table at 0x08000100), the port (flash registers of the F7 - erase and
  program only in the store sector -, jump with VTOR and MSP, the independent watchdog for an image on trial),
  dmlog for the log (dmod's symbols that it takes are stubs), a minimal libc.
* include/dmsel_table.h: the table of functions that the firmware finds at DMSEL_TABLE_ADDRESS; the state is the
  firmware's memory (the RAM of the selector is gone when it starts), the scratch for the store is given at init.
* tools/dmsel_mkimage.py: the 512 byte header (magic, version, size, CRC) in front of the code linked at the
  start of the bank + 0x200; a ctest checks that the core accepts what the tool makes.
* The core: the scratch is given at dmsel_init; an optional watchdog is started when an image on trial is started.
* fw/testbank: a test image of a bank that reports what the table says into the RAM.

Tested on the STM32F746G-DISCO (selector in S0, two test images): the newest good image is started; the
persistent item is written and read back; the other bank on trial starts with tries 1, 2, 3 and at the fourth
start is dropped and the first one runs again; Dmod_FirmwareReady confirms; a permanent choice holds across
resets; the record is in S1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…or uses dmlog and the config header of dmod)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
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