In development. It changes without notice.
Topic
Storage
LittleFS, NVS, the SD card's file system, the writer of updates, and what the security fuses say.
LittleFS holds the encrypted vault and survives an update. NVS holds preferences, the lockout's count, the event log and the hosts' names. The SD card is there only on the boards with a slot. Each has a handle that closes what it opened.
Mounting never formats; a partition is formatted only where every sector of it reads blank or a caller says so. This facade reads the security fuses and burns none.
- See also
- Vault Storage, SD Card, Update Policy
Files | |
| file | src/ |
| The bench probe under the vault's storage: link-time wraps of the vault partition's flash calls and of the LittleFS API, and the flash primitives. | |
| file | src/ |
| The bench probe under the vault's storage: what LittleFS and the flash cost one vault operation, and what one vault write programs and erases. | |
| file | src/ |
| LittleFS mount, file, and directory operations. | |
| file | src/ |
| LittleFS mount lifecycle and file I/O facade. | |
| file | src/ |
| When LittleFS may be handed a vault partition it reads through a memory map. | |
| file | src/ |
| When a failed LittleFS mount may format: the blank test and the decision, with no ESP-IDF in it. | |
| file | src/ |
| ESP-IDF NVS namespace handle and typed accessors. | |
| file | src/ |
| ESP-IDF NVS (non-volatile storage) key/value facade. | |
| file | src/ |
| OTA application-partition update implementation. | |
| file | src/ |
| OTA application-partition update facade. | |
| file | src/ |
| SD-card (FATFS over SPI) mount, file, and directory operations. | |
| file | src/ |
| SD-card (FATFS over SPI) mount lifecycle and file I/O facade. | |
| file | src/ |
| Production eFuse hardening implementation. | |
| file | src/ |
| Production eFuse hardening helpers. | |
| file | src/ |
| A bounded set of mapped 64 KiB pages of the vault, least recently used out first. | |
| file | src/ |
| The three ways an image reads the vault partition, and when each may serve. | |
| file | src/ |
| Shared POSIX-over-VFS file, directory, and path operations. | |
| file | src/ |
| Shared POSIX-over-VFS file handle and path operations. | |
Typedefs | |
| using | kleidos:: |
| using | kleidos:: |
| using | kleidos:: |
| Visitor invoked once per directory entry. | |
Functions | |
| File | kleidos:: |
| Open a file or directory on LittleFS. | |
| constexpr bool | kleidos:: |
| Whether a mapped read of the vault partition returns what was written. | |
| constexpr MmapVerdict | kleidos:: |
| The verdict on handing LittleFS the vault partition. | |
| constexpr uint32_t | kleidos:: |
MMU pages a map of size bytes at flash offset offset takes. | |
| constexpr MountAttempt | kleidos:: |
| Name one mount attempt from what the driver answered and what the heap saw. | |
| constexpr bool | kleidos:: |
Whether the file system is mounted after outcome. | |
| constexpr bool | kleidos:: |
Whether outcome is one only the owner of the device can settle. | |
| constexpr bool | kleidos:: |
Whether outcome is a verdict on what the partition holds. | |
| constexpr const char * | kleidos:: |
The token the debug console prints for outcome. | |
| constexpr bool | kleidos:: |
Whether bytes read as erased flash. | |
| template<typename Reader> | |
| BlankScan | kleidos:: |
| Walk every sector of a partition and say whether it stores nothing. | |
| template<typename Steps> | |
| MountOutcome | kleidos:: |
| Mount, and format only a partition a walk finds blank. | |
| NvsStats | kleidos:: |
| Read aggregate usage statistics for the default NVS partition. | |
| NvsErase | kleidos:: |
| Erase the whole default NVS partition at the sector level, and prove it. | |
| bool | kleidos:: |
| Initialize the default NVS partition now, and say whether it took. | |
| uint32_t | kleidos:: |
| Visit the namespace and key name of every entry the default NVS holds. | |
| ImageState | kleidos:: |
| Return the OTA state of the currently running partition. | |
| size_t | kleidos:: |
| Size in bytes of the partition the next OTA image would be written to. | |
| bool | kleidos:: |
| Confirm the running image as valid and cancel the rollback timer. | |
| bool | kleidos:: |
| Reject the running image and reboot into the previous one. | |
| bool | kleidos:: |
Copy the running partition label into output. | |
| const char * | kleidos:: |
| Return a human-readable name for an update stage. | |
| File | kleidos:: |
| Open a file or directory on the SD card. | |
| bool | kleidos:: |
| Read-only: whether Secure Boot v2 is active on this SoC. | |
| bool | kleidos:: |
| Read-only: whether Flash Encryption is active on this SoC. | |
| bool | kleidos:: |
Read-only: whether key block KEY<keyIndex> holds a device-binding key. | |
| constexpr bool | kleidos:: |
| Whether a partition sits on whole MMU pages, the only kind the cache serves. | |
| constexpr VaultReadPath | kleidos:: |
| The read path a build's Kconfig choice names. | |
| constexpr const char * | kleidos:: |
The name the build command and the debug console give path. | |
| constexpr bool | kleidos:: |
| Whether the page cache may serve the vault's reads. | |
| constexpr bool | kleidos:: |
Whether a page-cache build may keep pages mapped. | |
| File | kleidos:: |
| Open a file or directory on the given backend. | |
| bool | kleidos:: |
| True when the path exists on the backend. | |
| Presence | kleidos:: |
Presence of path, distinguishing "not there" from "cannot tell". | |
| bool | kleidos:: |
| Visit every entry of a directory by name, in ONE traversal. | |
| bool | kleidos:: |
| Create a directory. | |
| bool | kleidos:: |
| Remove an empty directory. | |
| bool | kleidos:: |
| Remove a file. | |
| bool | kleidos:: |
| Rename or move a file or directory. | |
Variables | |
| constexpr size_t | kleidos:: |
| constexpr size_t | kleidos:: |
| Sectors the walk reads before it lets other tasks run. | |
| constexpr size_t | kleidos:: |
| Max partition label length incl. NUL. | |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
| constexpr uint32_t | kleidos:: |
The unit the cache maps: one MMU page (CONFIG_ on both families). | |
| constexpr uint32_t | kleidos:: |
| The fewest pages a page-cache build may keep mapped. | |
| constexpr uint32_t | kleidos:: |
LittleFS: the partition below the file system | |
The factory reset's own bytes ( | |
| constexpr size_t | kleidos:: |
| One erase unit of the vault partition: what eraseFirstSector erases. | |
| BlankScan | kleidos:: |
| Walk every sector of the vault partition and say whether it holds nothing. | |
| bool | kleidos:: |
| Read bytes of the vault partition raw (no decryption). | |
| bool | kleidos:: |
| Program bytes of the vault partition raw (no encryption). | |
| bool | kleidos:: |
| Erase the first sector (kPartitionSectorBytes) of the vault partition. | |
LittleFS: lifecycle | |
| bool | kleidos:: |
| Mount LittleFS as it is found. Never writes to the flash. | |
| MountOutcome | kleidos:: |
| Mount LittleFS, and format it only when the partition holds nothing. | |
| BlankWalkRecord | kleidos:: |
| The last walk beginOrFormatBlank ran over the vault partition. | |
| void | kleidos:: |
| Unmount LittleFS. | |
| bool | kleidos:: |
| True when LittleFS is currently mounted. | |
| bool | kleidos:: |
| Whether this image's read path would refuse the vault partition. | |
| bool | kleidos:: |
| Format the LittleFS partition, whatever it holds. | |
| bool | kleidos:: |
| Physically erase the ENTIRE LittleFS/ | |
LittleFS: properties | |
| bool | kleidos:: |
| True when the vault partition is stored under Flash Encryption. | |
| MapWindow | kleidos:: |
| Read the data window and the vault's place in it, as they are now. | |
LittleFS: directory and path operations | |
| bool | kleidos:: |
| True when the path exists on LittleFS. | |
| vfs::Presence | kleidos:: |
Presence of path on LittleFS, with "cannot tell" named. | |
| bool | kleidos:: |
| Visit every entry of a LittleFS directory by name, in ONE traversal. | |
| bool | kleidos:: |
| Create a directory. | |
| bool | kleidos:: |
| Remove an empty directory. | |
| bool | kleidos:: |
| Remove a file. | |
| bool | kleidos:: |
| Rename or move a file or directory. | |
LittleFS: capacity | |
| size_t | kleidos:: |
| Return bytes currently used on LittleFS. | |
| size_t | kleidos:: |
| Return total LittleFS partition capacity in bytes. | |
| bool | kleidos:: |
| Read the capacity and the used-byte total in ONE traversal. | |
SD card: lifecycle | |
| bool | kleidos:: |
| Mount the SD card. Never formats it. | |
| void | kleidos:: |
| Unmount the SD card. | |
| CardInit | kleidos:: |
| Initialize the card in the slot and let it go, with no filesystem. | |
| MountOutcome | kleidos:: |
| How the last begin that tried a mount ended. | |
| const char * | kleidos:: |
| Console token of a mount outcome. | |
| bool | kleidos:: |
| True when an SD card is currently mounted. | |
| bool | kleidos:: |
| Format the mounted SD card. | |
SD card: directory and path operations | |
| bool | kleidos:: |
| True when the path exists on the SD card. | |
| vfs::Presence | kleidos:: |
Presence of path on the SD card, with "cannot tell" named. | |
| bool | kleidos:: |
| Create a directory. | |
| bool | kleidos:: |
| Remove an empty directory. | |
| bool | kleidos:: |
| Remove a file. | |
| bool | kleidos:: |
| Rename or move a file or directory. | |
SD card: capacity and info | |
| uint64_t | kleidos:: |
| Return bytes currently used on the SD card. | |
| uint64_t | kleidos:: |
| Return the total SD card capacity in bytes. | |
| bool | kleidos:: |
| Read the mounted volume's FAT geometry and allocation state. | |
| uint32_t | kleidos:: |
| The SPI clock the host actually settled on for the card, in kHz. | |
| uint32_t | kleidos:: |
| The fastest SPI clock the mounted card agreed to, in kHz. | |
| const char * | kleidos:: |
| Return a human-readable card type string. | |
Typedef Documentation
EntryVisitor #
Visitor invoked once per directory entry.
- Parameters
-
Name Direction Meaning name in Entry basename; valid only for the duration of the call. context in Opaque pointer handed through from forEachEntry.
- Return values
-
Value Meaning true Continue the traversal. false Stop the traversal here.
File [1/2] #
RAII handle to an open file or directory on LittleFS. LittleFS and SD-FATFS share the POSIX-over-VFS handle in vfs::File.
File [2/2] #
RAII handle to an open file or directory on the SD card. LittleFS and SD-FATFS share the POSIX-over-VFS handle in vfs::File.
Enumeration Type Documentation
BlankScan #
CardInit #
How a card-level initialization ended (initializeCard).
DriverAnswer #
What the driver's register call answered, before the heap is weighed.
ImageState #
Validity state of an OTA image.
| Value | Meaning |
|---|---|
New | Freshly written, not yet booted. |
PendingVerify | Booted, awaiting rollback confirmation. |
Valid | Confirmed valid (rollback cancelled). |
Invalid | Marked invalid (will not boot again). |
Aborted | Update was aborted. |
Undefined | State could not be determined. |
MmapVerdict #
MountAttempt #
How one mount attempt ended, with nothing formatted.
| Enumerator | |
|---|---|
| Mounted | The file system is mounted. |
| OutOfMemory | No memory: the driver said so, an allocation failed meanwhile, or the data window had no room for the driver's map of the vault. |
| Refused | An error, while no allocation failed (classifyAttempt). |
MountOutcome [1/2] #
How a mount that may format a blank partition ended.
| Enumerator | |
|---|---|
| Mounted | Mounted as it was found. No flash was written. |
| FormattedBlank | Every sector was blank, so it was formatted and mounted. |
| OutOfMemory | No memory for the mount's buffers, or no room in the data window for its map of the vault. No flash was written. |
| Unreadable | It would not mount with memory to spare, and it holds data or could not be read. No flash was written. |
| FormatFailed | It was blank, and the format or the mount after it failed. |
| ReadPathRefused | This image's read path refused the partition before anything read it (little_ |
MountOutcome [2/2] #
How the last mount attempt ended.
A slot with no card and a seated card whose volume FatFs cannot mount (an exFAT card, which this build's FatFs does not read, or a card with no filesystem at all) both fail begin; only the second identified a card.
NvsErase #
How nvsErasePartition ended.
Presence #
SpiHost #
UpdateStage #
Stage reached by an update session (for diagnostics).
| Value | Meaning |
|---|---|
None | Not started (or last operation succeeded). |
SelectPartition | Selecting the next update partition. |
Begin | Beginning the write. |
Write | Streaming image data. |
End | Finalizing the image (esp_ |
SetBootPartition | Setting the boot partition. |
Abort | Aborting and discarding the partial image. |
VaultReadPath #
Function Documentation
actualClockKHz() #
The SPI clock the host actually settled on for the card, in kHz.
A request is only a request: the peripheral divides a fixed source clock and takes the divisor nearest the clock the mount runs at (on the ESP32-S3, the 80 MHz APB clock over 2, 3, 4 and so on), and the mount runs at most at what the card agreed to (cardMaxClockKHz). Reading the negotiated value back is what separates "this board is as fast as it gets" from "the request was rounded away".
- Returns
- Working clock in kHz, or 0 when no card is mounted.
allErased() #
Whether bytes read as erased flash.
- Parameters
-
Name Direction Meaning bytes in Bytes read. count in How many.
- Returns
- True when every byte is 0xFF.
begin() [1/2] #
Mount LittleFS as it is found. Never writes to the flash.
- Return values
-
Value Meaning true Filesystem was successfully mounted. false Mount failed (see KLEIDOS_LOGoutput for theesp_errcode).
begin() [2/2] #
Mount the SD card. Never formats it.
A card whose volume does not mount is reported (MountOutcome::
A chip-select a sleep latched (gpio::) is released first: a latched pad ignores the driver, and the card would never be selected.
- Parameters
-
Name Meaning config SPI pins, host, clock, and mount options.
- Return values
-
Value Meaning true Card was successfully mounted. false Mount failed (no card, bad filesystem, or driver error).
beginOrFormatBlank() #
Mount LittleFS, and format it only when the partition holds nothing.
The one path a mount can format through. A mount error says nothing about what the flash holds, so whatever it was, the format runs only after every sector of the partition has read blank, on an unflagged and a flagged partition alike (little_
It reads the whole partition when the partition is blank, which is seconds on the larger tables, so it belongs on a task that may wait (the vault worker). A partition with anything in it is told apart in a read or two.
- Returns
- How the mount ended.
- See also
- isMounted, needsOwner
cardMaxClockKHz() #
The fastest SPI clock the mounted card agreed to, in kHz.
A request at or below the default speed (20 MHz) is taken as it is. A faster one first asks the card to switch to high speed (CMD6), and a card that reports no support for the switch keeps its 20 MHz default while the mount still succeeds. So this below the request is the card refusing high speed, and actualClockKHz below this is the divider's rounding.
- Returns
- The card's ceiling in kHz, or 0 when no card is mounted.
cardType() #
Return a human-readable card type string.
- Returns
- Static string such as "SDHC" or "Unknown".
classifyAttempt() #
Name one mount attempt from what the driver answered and what the heap saw.
lfs_mount reports a cache it could not allocate as it reports a damaged directory, and the driver passes both on as one error. An allocation that failed anywhere while the attempt ran is therefore taken as its cause. Running out of memory is never read as damage, at the price of deferring a refusal that met another task's failed allocation in the same window: out of memory leads to no walk, no format and no prompt, only to a later attempt. A data window with no room for the vault's map is a shortage of the same kind (DriverAnswer::): the admission found room a moment before, so another map holds it now, and the partition was never judged.
- Parameters
-
Name Direction Meaning answer in What the driver answered. allocationFailed in Whether the heap reported a failed allocation while the attempt ran.
- Returns
- How the attempt ended.
eraseAll() #
Physically erase the ENTIRE LittleFS/
Unlike format() — which only rewrites the LittleFS superblock pair and leaves every other (including freed) data block untouched — this performs a raw esp_ across the whole partition, returning every byte to the flash-erased state. It is the authoritative physical destruction used by the panic / brute-force vault wipe.
Why it is required: LittleFS is copy-on-write. Unlinking or overwriting a file writes to NEW blocks and merely drops the old blocks from the allocator ("block deallocation is a noop"); the original bytes — including the KDF salt and the secret's verifier in meta.bin — survive in freed-but-not-erased blocks. On an open build, a release build included, a raw flash dump holds them and could resume an offline brute force of the secret from that salt. On a hardened build, whose table flags this partition for Flash Encryption, the dump holds them as ciphertext under the chip's key, and the device binding stands under that. Erasing the whole partition removes every block unconditionally, closing that gap on all builds.
Lifecycle: unmounts the partition first (via end()) and leaves it BLANK and unmounted. The caller MUST re-mount (beginOrFormatBlank formats a fresh empty FS over it) or reboot before using the filesystem again — do not operate on the partition while it is in this state.
- Return values
-
Value Meaning true The partition was found and fully erased. false The partition was not found or the erase failed (see the KLEIDOS_LOGoutput for theesp_errcode).
- Warning
- Destroys ALL data on the vault partition irrecoverably. On the native host build there is no flash to erase, so this is a no-op seam (returns true); unit tests observe the invocation through the fake facade rather than by inspecting bytes.
- See also
- format, beginOrFormatBlank, end
eraseFirstSector() #
Erase the first sector (kPartitionSectorBytes) of the vault partition.
- Return values
-
Value Meaning true The erase completed. false The partition is missing or the erase failed.
exists() [1/3] #
True when the path exists on LittleFS.
Two-valued: "not there" and "I could not tell" are both false. Any caller whose false branch destroys, overwrites or abandons data must ask presence instead.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true pathrefers to an existing file or directory.false pathdoes not exist, the partition is not mounted, or the lookup failed.
- See also
- presence
exists() [2/3] #
True when the path exists on the SD card.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true pathrefers to an existing file or directory.false pathdoes not exist on the card — OR the lookup itself failed. Use presence when thefalsebranch destroys or replaces something.
- See also
- presence
exists() [3/3] #
True when the path exists on the backend.
Two-valued, so it folds "I could not tell" into false. Use presence wherever the false branch destroys, overwrites or abandons data: a caller that unlinks a file's only surviving twin on a false answer must know whether that answer was stat reporting ENOENT or the lookup failing.
- Parameters
-
Name Meaning backend Backend descriptor. path NUL-terminated path string.
- Return values
-
Value Meaning true pathrefers to an existing file or directory.false pathdoes not exist, the backend is not mounted, or the lookup itself failed.
- See also
- presence
flashEncryptionEnabled() #
Read-only: whether Flash Encryption is active on this SoC.
A pure eFuse query with no side effects. Reads 0 (false) on open builds.
- Return values
-
Value Meaning true Flash Encryption is enabled (eFuse burned). false Flash Encryption is disabled, or the native build.
forEachEntry() [1/2] #
Visit every entry of a LittleFS directory by name, in ONE traversal.
Use this instead of a loop of exists whenever the question is "which of these files are there": each exists resolves the directory again, and on LittleFS resolving a name walks the directory's metadata pairs, so N probes cost N walks where this costs one.
- Parameters
-
Name Direction Meaning path in NUL-terminated directory path. visit in Callback invoked per entry; "."and".."are skipped.context in Opaque pointer handed to visit.
- Return values
-
Value Meaning true The directory was opened, traversed and closed; what visitsaw is a COMPLETE listing.false The listing is incomplete or never started; the caller must not conclude that an unseen file is absent.
forEachEntry() [2/2] #
Visit every entry of a directory by name, in ONE traversal.
The counterpart of exists for the question "which of these files are there": asking exists once per candidate resolves the directory once per candidate, and on a log-structured filesystem resolving a name walks the directory's metadata pairs. This walks them once and reports what it finds.
Names only — no stat, no open per entry — so the caller pays one traversal and nothing per candidate it was going to reject anyway. The directory is not to be mutated from inside visit.
- Parameters
-
Name Direction Meaning backend in Backend descriptor. path in NUL-terminated directory path. visit in Callback invoked per entry; "."and".."are skipped.context in Opaque pointer handed to visit. A traversal that stops early becausevisitreturned false is still a complete answer — the caller asked for the stop — and reportstrue.
- Return values
-
Value Meaning true The directory was opened, traversed to its end (or to a stop visitasked for) and closed: whatvisitsaw IS the listing.false The backend is unmounted, pathis not an openable directory, a read failed part-way through, or the close failed — the caller cannot treat what it saw as a complete listing. A caller whosefalsebranch allocates, overwrites or destroys must not act on the entries it did see.
- See also
- exists
format() [1/2] #
Format the LittleFS partition, whatever it holds.
For a path a person asked for. A mount that failed does not reach this; it goes through beginOrFormatBlank.
- Note
- This rewrites only the LittleFS superblock pair (blocks 0-1); it does NOT erase the rest of the partition. Previously-written data blocks (including freed ones) survive a format untouched. For an authoritative physical wipe of every byte use eraseAll().
- Return values
-
Value Meaning true Format completed successfully. false Format operation failed.
format() [2/2] #
Format the mounted SD card.
- Return values
-
Value Meaning true Format completed successfully. false Format operation failed.
hmacKeyReady() #
Read-only: whether key block KEY<keyIndex> holds a device-binding key.
True only when the block's purpose is HMAC_UP AND it is read-protected, which is what a host-side burn with espefuse burn-key ... HMAC_UP leaves. A key with the purpose but without the read protection works and is not ready: software could read it back, so a vault bound to it would be bound to a secret the chip does not keep.
Reports the eFuses as they are; it never burns one. A pure eFuse query with no side effects.
- Parameters
-
Name Direction Meaning keyIndex in Key block index, 0 for BLOCK_KEY0.
- Return values
-
Value Meaning true KEY<keyIndex>is a read-protectedHMAC_UPkey.false Any other purpose or protection, an index past the last key block, a chip without key purposes or an HMAC peripheral (classic ESP32), or the native build.
info() #
Read the capacity and the used-byte total in ONE traversal.
usedBytes and totalBytes each ask the filesystem separately, and the used figure is counted by a full walk, so a caller that wants both pays that walk twice for one line of output. This pays it once.
- Parameters
-
Name Direction Meaning total out Partition capacity in bytes. used out Bytes currently occupied.
- Return values
-
Value Meaning true Both figures were read. false The filesystem is not mounted or could not be queried; totalandusedare set to 0.
initializeCard() #
Initialize the card in the slot and let it go, with no filesystem.
Sends the card the commands a mount begins with and nothing after them: the reset (CMD0), the interface check (CMD8), the operating-condition handshake (ACMD41), the register reads (CID, CSD, SCR, SD status) and the clock switch, exactly as sdmmc_ sends them inside begin. No sector is read, no volume is mounted and nothing is written, so nothing on the card can change. The card's SPI device is then removed and its chip-select driven high: the card is left initialized and deselected, its supply on, as end leaves a card it unmounts.
Bus handling is begin's: a bus another device set up (the panel's) is joined and left in place, so the card's commands interleave with that device's through the SPI bus lock; a bus nobody set up is set up for the call and freed again. A chip-select a sleep latched is released first.
It blocks the calling task for the whole exchange, so call it from a task that may wait (the HAL runs it on Core 0). With a card that answers, that is the card's own initialization, mostly its ACMD41 handshake. With the slot empty, ESP-IDF's init gives up early (6.0.3, the same in 6.1.1). When MISO idles high it fails at the second CMD0, which finds no R1 byte in the eight it reads: the CMD52 the SDIO-enabled init sends first, the two CMD0s and the 20 ms SDMMC_ between them come to about 21 ms (the LILYGO T-Deck's empty slot measured about 25 ms, ESP_). When MISO idles low the reply reads as a zero R1 and it fails at CMD8, whose echo is wrong: each of those four commands first polls MISO for up to the default 40 ms (wait_for_miso) with the bus held, which with the two 20 ms delays is at most about 200 ms. Each command takes the bus for its own exchange only: under a millisecond at the 400 kHz probing clock, up to about 41 ms with that MISO poll.
Not safe beside begin, end or another call on another task: the caller serializes them (the HAL's boot settle does).
- Parameters
-
Name Meaning config SPI pins, host and clock; the mount options are not read.
- Returns
- How it ended;
CardInit::when a card is mounted already.Mounted
isMounted() #
Whether the file system is mounted after outcome.
- Parameters
-
Name Direction Meaning outcome in How the mount ended.
- Returns
- True when it may be used.
judgedPartition() #
Whether outcome is a verdict on what the partition holds.
Running short of memory, for the mount's buffers or for the data window's pages, and a read path that refuses the partition both end before any walk, so neither says anything about the flash: a caller keeps what the last mount that judged the partition found.
- Parameters
-
Name Direction Meaning outcome in How the mount ended.
- Returns
- False for
OutOfMemoryandReadPathRefused, true for every other.
lastBlankWalk() #
The last walk beginOrFormatBlank ran over the vault partition.
A walk runs only after a refused mount, so a mount that works leaves this as it was. For diagnostics (the debug console): nothing decides on it. A board whose boot log is lost with the reset that printed it still reports what its boot's walk cost, and how far into a damaged partition it read before stopping.
- Returns
- A copy of the record.
lastMountOutcome() #
How the last begin that tried a mount ended.
A begin on a card already mounted tries nothing and leaves it as it was. end leaves it too: it says how the card was last brought up.
- Returns
- The outcome,
MountOutcome::before the first attempt.None
mapPagesFor() #
MMU pages a map of size bytes at flash offset offset takes.
esp_ maps from the page that holds the first byte (esp_), and the MMU maps whole pages (esp_), so a span that starts inside a page takes one more than its size alone.
- Parameters
-
Name Meaning offset Flash offset of the first byte. size Bytes to map. pageBytes MMU page size ( CONFIG_, 64 KiB on both families).MMU_ PAGE_ SIZE
- Returns
- Pages spanned; 0 for an empty span or a zero page size.
mapWindow() #
Read the data window and the vault's place in it, as they are now.
Mounts nothing and maps nothing: mapped is true while the vault's first and last bytes are mapped (the whole vault, on a mounted littlefs_mmap build; the two end pages, when a page cache happens to hold both), and freePages counts the window with whatever is mapped at the moment. The cache fields describe a page_cache build and stay zero on the other paths; its counters are counted by a debug build only.
- Returns
- The reading;
pathis always the build's, and every other field zero andfalseon the native host build or when the partition is missing.
markRunningAppInvalidRollbackAndReboot() #
Reject the running image and reboot into the previous one.
For an image still pending verification that must not be confirmed: the bootloader marks it invalid and the restart boots the image it replaced.
- Returns
- Only on failure (no image pending verification, or no other valid image to return to):
false. On success the chip restarts and the call never returns.
markRunningAppValidCancelRollback() #
Confirm the running image as valid and cancel the rollback timer.
- Return values
-
Value Meaning true Image confirmed; bootloader will not roll back. false Confirmation failed (e.g. no pending-verify image).
mkdir() [1/3] #
Create a directory.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true Directory created successfully. false Creation failed (already exists, missing parent, or driver error).
mkdir() [2/3] #
Create a directory.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true Directory created successfully. false Creation failed (already exists, missing parent, or driver error).
mkdir() [3/3] #
Create a directory.
- Parameters
-
Name Meaning backend Backend descriptor. path NUL-terminated path string.
- Return values
-
Value Meaning true Directory created (or already present as a directory). false Creation failed (missing parent, name collision, or driver error).
mmapReadsMatchWrites() #
Whether a mapped read of the vault partition returns what was written.
- Parameters
-
Name Meaning flashEncryptionOn The chip's Flash Encryption is enabled (eFuse). partitionEncrypted ESP-IDF treats the vault partition as encrypted: its table row is flagged and Flash Encryption is on ( esp_).partition_ t:: encrypted
- Return values
-
Value Meaning true Reads through the map match writes: either nothing is encrypted, or both the writes and the map go through Flash Encryption. false Flash Encryption is on and the partition is not flagged: the writes are plaintext and the map decrypts them.
mmapVerdict() #
The verdict on handing LittleFS the vault partition.
The encryption rule is decided first: a partition it refuses is never mapped, so mapSucceeded is not consulted for it.
- Parameters
-
Name Meaning flashEncryptionOn The chip's Flash Encryption is enabled (eFuse). partitionEncrypted esp_of the vault partition.partition_ t:: encrypted mapSucceeded The facade's own map of the whole partition, made and released before the mount, succeeded.
- Returns
- MmapVerdict::
Admitted only when both decisions allow it.
mountAdmitted() #
Whether this image's read path would refuse the vault partition.
Asks the read path's own question before a mount, without mounting. On a build that maps the whole vault at mount (CONFIG_) that is the Flash Encryption rule and a map of the partition made and released at once (little_
It catches that refusal and nothing else. Nothing is mounted, so a mount that would fail for another reason (a LittleFS geometry or on-disk version the image does not share with the partition) is admitted here.
- Return values
-
Value Meaning true The read path would not refuse the vault, or it is mounted already. Always trueon the plain and page-cache paths and on the native host build. Not a promise that a mount succeeds.false The read path would refuse the vault partition.
mounted() [1/2] #
True when LittleFS is currently mounted.
- Return values
-
Value Meaning true Mounted (a successful begin()orLittleFsGuardconstruction).false Not currently mounted.
mounted() [2/2] #
True when an SD card is currently mounted.
- Return values
-
Value Meaning true Mounted (a successful begin()is in effect).false Not currently mounted.
mountOutcomeName() #
Console token of a mount outcome.
- Parameters
-
Name Meaning outcome The outcome.
- Returns
none,ok,nofsornocard;nafor a value outside the enumeration.
needsOwner() #
Whether outcome is one only the owner of the device can settle.
Running short of memory is not among them: the flash was never looked at, and a later mount can succeed. Nor is a read path that refuses the partition: the flash was never looked at either, a wipe would not bring the partition within this image's reach, and an image that reads it another way finds it as it was.
- Parameters
-
Name Direction Meaning outcome in How the mount ended.
- Returns
- True for a refusal that will outlast a retry.
nextUpdatePartitionSize() #
Size in bytes of the partition the next OTA image would be written to.
Returns the size of the partition esp_ selects, so a caller can reject an oversized image before opening a write session (which first erases the inactive slot).
- Return values
-
Value Meaning >0 Size in bytes of the next update partition. 0 No OTA partition is available (e.g. host/native builds).
nvsErasePartition() #
Erase the whole default NVS partition at the sector level, and prove it.
nvs_erase_key and nvs_erase_all only mark entries erased; their bytes stay on the flash until NVS recycles the page. This erases every sector of the partition (nvs_, which closes NVS first if it was open), then reads the whole partition back raw and requires every byte to be 0xFF. NVS is left uninitialized: the next NvsStore::
Meant for the one moment no other task holds NVS: the top of setup(), before any reader has opened it (reset/).
- Returns
- How the erase ended.
nvsForEachEntry() #
Visit the namespace and key name of every entry the default NVS holds.
Names only, never values, for the debug console's listing of what survived a factory reset.
- Parameters
-
Name Direction Meaning visit in Called once per entry with its namespace and key; returning false stops the walk. context in Handed to visit.
- Returns
- How many entries were visited; 0 when NVS is not initialized, holds nothing, or on the native build.
nvsInit() #
Initialize the default NVS partition now, and say whether it took.
Every NvsStore::
- Return values
-
Value Meaning true NVS is initialized. false nvs_failed (logged).flash_ init
nvsStats() #
Read aggregate usage statistics for the default NVS partition.
A cheap read-only query over nvs_. Requires NVS to be initialized; if it is not, NvsStats::ok reads false and the counts are 0.
- Returns
- A populated NvsStats on device; a zeroed value on native.
open() [1/3] #
Open a file or directory on LittleFS.
- Parameters
-
Name Meaning path NUL-terminated path string. mode fopen-style mode string ("r", "w", "a", etc.).
- Returns
- RAII File handle; check valid() before use.
open() [2/3] #
Open a file or directory on the SD card.
- Parameters
-
Name Meaning path NUL-terminated path string. mode fopen-style mode string ("r", "w", "a", etc.).
- Returns
- RAII File handle; check valid() before use.
open() [3/3] #
outcomeName() #
The token the debug console prints for outcome.
- Parameters
-
Name Direction Meaning outcome in How the mount ended.
- Returns
- A static string with no spaces.
pageCacheAligned() #
Whether a partition sits on whole MMU pages, the only kind the cache serves.
- Parameters
-
Name Meaning partitionAddress The partition's flash address ( esp_).partition_ t:: address partitionBytes Its size ( esp_).partition_ t:: size
- Return values
-
Value Meaning true Both are multiples of kVaultCachePageBytes, and it is not empty: each cached page is one MMU page, mapped once. false Otherwise: every read of it takes the plain path.
pageCacheServes() #
Whether the page cache may serve the vault's reads.
A read through a mapping is decrypted whenever the chip's Flash Encryption is on, so the cache serves only where the writes went through it too, or nothing is encrypted (mmapReadsMatchWrites). Where it may not, every read falls through to the plain path, which reads an unflagged row as written: unlike the whole-vault map, the page cache never refuses a mount.
- Parameters
-
Name Meaning flashEncryptionOn The chip's Flash Encryption is enabled (eFuse). partitionEncrypted esp_of the vault partition.partition_ t:: encrypted
- Return values
-
Value Meaning true Mapped pages read what was written. false Flash Encryption is on over an unflagged row: read the plain way.
pageCacheSlotsValid() #
Whether a page-cache build may keep pages mapped.
- Parameters
-
Name Meaning pages CONFIG_.KLEIDOS_ VAULT_ PAGE_ CACHE_ PAGES
- Return values
-
Value Meaning true kVaultCacheMinPages to kVaultCacheMaxPages. false Outside that range.
partitionEncrypted() #
True when the vault partition is stored under Flash Encryption.
Reads the encrypted field ESP-IDF resolved for the partition at boot. It is set only when the partition table flags the row encrypted (the secure tables do, held there by a check of the build) and the chip's Flash Encryption is on (esp_, is_). Every LittleFS read and write of the vault then goes through the chip's Flash Encryption, so what the flash holds is ciphertext under the chip's own key, beneath the records' own envelopes, and raw 0xFF wherever nothing has been programmed since the last erase.
- Return values
-
Value Meaning true The vault partition is flash-encrypted. false It is stored as written: an open build, a chip whose Flash Encryption is off, a table that leaves the row unflagged, a missing partition, or the native host build.
partitionReadsBlank() #
Walk every sector of the vault partition and say whether it holds nothing.
The walk beginOrFormatBlank runs before it may format (both views of a partition flagged encrypted, little_
- Returns
- What the walk found;
BlankScan::when the partition is missing or a read failed.ReadFailed
presence() [1/3] #
Presence of path on LittleFS, with "cannot tell" named.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Returns
vfs::,Presence:: Present vfs::, orPresence:: Absent vfs::when the lookup itself failed.Presence:: Unknown
- See also
- exists, kleidos::
platform:: vfs:: presence
presence() [2/3] #
Presence of path on the SD card, with "cannot tell" named.
exists answers false for an absent path, for an unmounted card and for every stat errno alike, which is the wrong shape for a caller whose false branch overwrites a file or picks a key-derivation input: on a card that is unseated or has a dirty contact, "no key file" and "this vault has no
key file" are the same answer.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Returns
vfs::,Presence:: Present vfs::, orPresence:: Absent vfs::when the lookup itself failed.Presence:: Unknown
- See also
- exists
presence() [3/3] #
Presence of path, distinguishing "not there" from "cannot tell".
exists answers false for an absent path, for an unmounted backend, for a path that does not fit the physical buffer and for every stat errno alike — ENOMEM, EIO and an exhausted descriptor table included. A caller whose false branch destroys data needs those apart, because only Presence:: is evidence that there is nothing to lose.
- Parameters
-
Name Meaning backend Backend descriptor. path NUL-terminated path string.
- Returns
Presence::,Present Presence::, orAbsent Presence::when the question could not be answered.Unknown
- See also
- exists
readRaw() #
Read bytes of the vault partition raw (no decryption).
- Parameters
-
Name Direction Meaning offset in Offset into the partition. out out Destination, byteslong.bytes in How many bytes.
- Return values
-
Value Meaning true outholds what the flash stores there.false The partition is missing, the range falls outside it, or the read failed.
remove() [1/3] #
Remove a file.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true File removed successfully. false Removal failed (missing file or driver error).
remove() [2/3] #
Remove a file.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true File removed successfully. false Removal failed (missing file or driver error).
remove() [3/3] #
rename() [1/3] #
Rename or move a file or directory.
- Parameters
-
Name Meaning from Source path. to Destination path.
- Return values
-
Value Meaning true Rename completed successfully. false Driver reported a rename error.
rename() [2/3] #
Rename or move a file or directory.
- Parameters
-
Name Meaning from Source path. to Destination path.
- Return values
-
Value Meaning true Rename completed successfully. false Driver reported a rename error.
rename() [3/3] #
Rename or move a file or directory.
- Parameters
-
Name Meaning backend Backend descriptor. from Source path. to Destination path.
- Return values
-
Value Meaning true Rename completed successfully. false Driver reported a rename error.
resolveMount() #
Mount, and format only a partition a walk finds blank.
An attempt that failed an allocation is out of memory (classifyAttempt), and so is a refusal with no room left for the mount's buffers, which covers a heap whose failures nothing reports; the flash is not looked at. A refusal with room is tried again. One that outlasts the retry leaves the decision to the walk, whatever the mount reported, so a mount error alone can never format.
- Template Parameters
-
Name Meaning Steps Provides MountAttempttryMount(),boolbuffersAvailable(),BlankScanscan() andboolformat().
- Parameters
-
Name Direction Meaning steps in, out What each step does on this platform.
- Returns
- How the mount ended.
rmdir() [1/3] #
Remove an empty directory.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true Directory removed successfully. false Removal failed or the directory is not empty.
rmdir() [2/3] #
Remove an empty directory.
- Parameters
-
Name Meaning path NUL-terminated path string.
- Return values
-
Value Meaning true Directory removed successfully. false Removal failed or the directory is not empty.
rmdir() [3/3] #
Remove an empty directory.
- Parameters
-
Name Meaning backend Backend descriptor. path NUL-terminated path string.
- Return values
-
Value Meaning true Directory removed successfully. false Removal failed or the directory is not empty.
runningPartitionLabel() #
Copy the running partition label into output.
- Parameters
-
Name Direction Meaning output out Destination buffer. outputLength in Buffer size in bytes.
- Return values
-
Value Meaning true Label was written to output.false outputis too small to hold the label.
runningPartitionState() #
Return the OTA state of the currently running partition.
- Return values
-
Value Meaning ImageState:: New Freshly written, not yet booted. ImageState:: PendingVerify Booted, awaiting rollback confirmation. ImageState:: Valid Confirmed valid. ImageState:: Invalid Marked invalid (will not boot again). ImageState:: Aborted Update was aborted. ImageState:: Undefined State could not be determined.
scanForBlank() #
Walk every sector of a partition and say whether it stores nothing.
Stops at the first sector that holds data, so a partition with a file system in it is told apart in a read or two, and only a blank one costs the whole walk.
- Template Parameters
-
Name Meaning Reader Provides size_tsizeBytes(),boolencrypted(),boolreadRaw(size_t offset, uint8_t* out, size_t bytes), boolreadDecrypted(size_t offset, uint8_t* out, size_t bytes) and voidpause().
- Parameters
-
Name Direction Meaning reader in, out The partition. scratch out Buffer for the reads. scratchBytes in Its size; a sector is read in several chunks when it is shorter than one.
- Returns
- What the walk found. Nothing to read from or with is
ReadFailed:a partition that could not be looked at is not verifiably blank.
secureBootEnabled() #
Read-only: whether Secure Boot v2 is active on this SoC.
A pure eFuse query with no side effects. Reads 0 (false) on every open build, which is deliberate: QA uses it to confirm a board under test is NOT accidentally running a hardened build.
- Return values
-
Value Meaning true Secure Boot is enabled (eFuse burned). false Secure Boot is disabled, or the native build.
totalBytes() [1/2] #
Return total LittleFS partition capacity in bytes.
Free: the capacity is the block size times the block count, both known from the mount. Unlike usedBytes this walks nothing.
- Returns
- Total capacity in bytes.
totalBytes() [2/2] #
Return the total SD card capacity in bytes.
- Returns
- Total capacity in bytes.
updateStageName() #
Return a human-readable name for an update stage.
- Parameters
-
Name Direction Meaning stage in UpdateStage value to name.
- Returns
- Pointer to a static string.
usedBytes() [1/2] #
Return bytes currently used on LittleFS.
- Note
- Costs a FULL filesystem traversal: LittleFS has no stored used-byte total, so the figure is counted by walking every metadata pair and every file's block chain. The price therefore grows with the file count, and the vault holds one file per credential slot. Treat it as a diagnostic, never as something to read per operation, and take it through info when the capacity is wanted alongside it.
- Returns
- Used byte count.
usedBytes() [2/2] #
Return bytes currently used on the SD card.
- Returns
- Used byte count.
vaultReadPathName() #
The name the build command and the debug console give path.
- Parameters
-
Name Meaning path A read path.
- Returns
"plain","littlefs_ormmap" "page_cache".
vaultReadPathOf() #
The read path a build's Kconfig choice names.
- Parameters
-
Name Meaning littlefsMmap CONFIG_is set.KLEIDOS_ VAULT_ READ_ LITTLEFS_ MMAP pageCache CONFIG_is set.KLEIDOS_ VAULT_ READ_ PAGE_ CACHE
- Returns
- The path; VaultReadPath::
Plain when neither is. The choice sets at most one, and little_fs.cpprefuses to build a component map set outside the choice.
volumeInfo() #
Read the mounted volume's FAT geometry and allocation state.
The allocation hint decides how long the next write that needs a new cluster takes: FAT finds a free cluster by reading the table entry by entry from the hint on, so with no hint on a nearly full card it reads most of the table first.
- Parameters
-
Name Direction Meaning out out The volume's state; untouched on failure.
- Return values
-
Value Meaning true outholds the volume's state.false No card mounted.
writeRaw() #
Program bytes of the vault partition raw (no encryption).
The range must be erased: NOR flash only clears bits. The offset and the length are kept multiples of 32 bytes by the caller, the classic ESP32's Flash Encryption row, so the bytes are whole rows on every chip.
- Parameters
-
Name Direction Meaning offset in Offset into the partition. data in Bytes to program, byteslong.bytes in How many bytes.
- Return values
-
Value Meaning true The write was accepted. false The partition is missing, the range falls outside it, or the write failed.
Variable Documentation
kBlankScanSectorBytes #
Bytes the blank walk judges at a time: the flash's erase unit and LittleFS's block, so one erase takes a whole one back to the erased state.
kFastestClockKHz #
The fastest SPI clock this chip's SPI master reads a card at, kHz: the source clock over 3 (26,666 kHz) on the classic ESP32. The SDSPI host reads the card in full duplex, where no dummy cycle can absorb a late input, and the classic ESP32's driver refuses a full-duplex clock whose read needs one. A MISO routed through the GPIO matrix (every slot board's: the Core2 v1.3's is GPIO38, not an IOMUX pin) arrives 25 ns late, which puts the ceiling at the source over 3; a mount asked for more fails when it switches the clock. The most Config::
The fastest SPI clock this chip's SPI master reads a card at, kHz: the source clock over 2 (40,000 kHz) on the ESP32-S3, whose driver applies no read-delay limit, and the fastest divisor of the source a high-speed card (50 MHz at most) accepts. The most Config::
kSpiSourceClockKHz #
The clock the SPI master divides to make the card's clock, kHz: the 80 MHz APB clock, on both chip families.
kVaultCacheMaxPages #
The most: the classic ESP32's 64-page window less the image's 20-page budget and the 4 pages kept free beside the vault leave 40, of which 32 are allowed.