Skip to content

Commit ae9cd6f

Browse files
committed
Update documentation
1 parent 33388d6 commit ae9cd6f

10 files changed

Lines changed: 291 additions & 29 deletions

File tree

‎Doxyfile‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ ENABLE_PREPROCESSING = YES
9090
MACRO_EXPANSION = NO
9191
EXPAND_ONLY_PREDEF = NO
9292
SEARCH_INCLUDES = YES
93-
INCLUDE_PATH = include
94-
PREDEFINED = CFGPACK_LZ4 CFGPACK_HEATSHRINK
93+
INCLUDE_PATH = include third_party/littlefs
94+
PREDEFINED = CFGPACK_LZ4 CFGPACK_HEATSHRINK CFGPACK_LITTLEFS
9595

9696
#---------------------------------------------------------------------------
9797
# Graph configuration (requires Graphviz)

‎README.md‎

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This checks for required tools (`clang`, `clang-format`, `make`, `ar`), installs
3131
- [API Reference](docs/source/api-reference.md) — Complete API documentation (errors, values, schema, runtime, typed functions)
3232
- [Schema Versioning](docs/source/versioning.md) — Version detection, migration, and type widening
3333
- [Compression](docs/source/compression.md) — LZ4/heatshrink decompression support
34+
- [LittleFS](docs/source/littlefs.md) — LittleFS flash storage wrappers
3435
- [Stack Analysis](docs/source/stack-analysis.md) — Per-function stack frame sizes for embedded budgeting
3536
- [Fuzz Testing](docs/source/fuzz-testing.md) — libFuzzer harnesses for parser and decode robustness
3637

@@ -92,11 +93,12 @@ vehicle 1
9293
- `api.h` — main cfgpack runtime API (set/get/pagein/pageout/print/version/size).
9394
- `decompress.h` — optional LZ4/heatshrink decompression support.
9495
- `io_file.h` — optional FILE*-based convenience wrappers for desktop/POSIX systems.
95-
- `src/` — library implementation (`core.c`, `io.c`, `io_file.c`, `msgpack.c`, `schema_parser.c`, `tokens.c`, `wbuf.c`, `decompress.c`).
96+
- `io_littlefs.h` — optional LittleFS-based convenience wrappers for flash storage.
97+
- `src/` — library implementation (`core.c`, `io.c`, `io_file.c`, `io_littlefs.c`, `msgpack.c`, `schema_parser.c`, `tokens.c`, `wbuf.c`, `decompress.c`).
9698
- `tests/` — C test programs plus sample data under `tests/data/`.
9799
- `tools/` — CLI tools source (`cfgpack-compress.c` for LZ4/heatshrink compression, `cfgpack-schema-pack.c` for converting schemas to msgpack binary).
98-
- `examples/` — complete usage examples (`allocate-once/`, `datalogger/`, `fleet_gateway/`, `low_memory/`, `sensor_hub/`).
99-
- `third_party/` — vendored dependencies (`lz4/`, `heatshrink/`).
100+
- `examples/` — complete usage examples (`allocate-once/`, `datalogger/`, `flash_config/`, `fleet_gateway/`, `low_memory/`, `sensor_hub/`).
101+
- `third_party/` — vendored dependencies (`lz4/`, `heatshrink/`, `littlefs/`).
100102
- `Makefile` — builds `build/out/libcfgpack.a`, test binaries, and tools.
101103

102104
## Building
@@ -130,21 +132,22 @@ Output:
130132
```
131133
Running tests...
132134
133-
basic: 4/4 passed
134-
core_edge: 11/11 passed
135-
decompress: 8/8 passed
136-
io_edge: 16/16 passed
137-
json_edge: 8/8 passed
138-
json_remap: 10/10 passed
139-
measure: 15/15 passed
140-
msgpack: 16/16 passed
135+
basic: 4/4 passed
136+
core_edge: 11/11 passed
137+
decompress: 8/8 passed
138+
io_edge: 16/16 passed
139+
io_littlefs: 8/8 passed
140+
json_edge: 8/8 passed
141+
json_remap: 10/10 passed
142+
measure: 15/15 passed
143+
msgpack: 16/16 passed
141144
msgpack_schema: 17/17 passed
142-
null_args: 40/40 passed
143-
parser_bounds: 23/23 passed
144-
parser: 3/3 passed
145-
runtime: 24/24 passed
145+
null_args: 40/40 passed
146+
parser_bounds: 23/23 passed
147+
parser: 3/3 passed
148+
runtime: 24/24 passed
146149
147-
TOTAL: 195/195 passed
150+
TOTAL: 203/203 passed
148151
```
149152

150153
### Fuzz Testing
@@ -178,7 +181,7 @@ See [Fuzz Testing](docs/source/fuzz-testing.md) for detailed documentation on th
178181

179182
## Examples
180183

181-
Five complete examples are provided in the `examples/` directory:
184+
Six complete examples are provided in the `examples/` directory:
182185

183186
### allocate-once
184187

@@ -196,6 +199,14 @@ Basic data logger demonstrating schema parsing, typed convenience functions, and
196199
cd examples/datalogger && make run
197200
```
198201

202+
### flash_config
203+
204+
Industrial sensor node demonstrating LittleFS flash storage with LZ4-compressed msgpack binary schemas and a v1 → v2 schema migration. Uses a RAM-backed LittleFS block device for desktop testing. Shows the composable I/O pattern: manual LFS read + `cfgpack_pagein_remap()` for cross-version migration, and `cfgpack_pageout_lfs()` / `cfgpack_pagein_lfs()` for same-version round-trips. Covers all five migration scenarios: keep, widen, move, remove, and add.
205+
206+
```bash
207+
cd examples/flash_config && make run
208+
```
209+
199210
### fleet_gateway
200211

201212
Fleet management gateway demonstrating LZ4-compressed msgpack binary schemas (pre-compiled from `.map` files via `cfgpack-schema-pack` and compressed with `cfgpack-compress lz4`) and a three-version migration chain (v1 -> v2 -> v3). Shows runtime LZ4 decompression of schema data before parsing, and uses `cfgpack_schema_measure_msgpack()` for right-sized heap allocation with no static buffer guessing. Covers all five migration scenarios: keep, widen, move, remove, and add.

‎docs/infrastructure.md‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ Two additional feature flags gate decompression library support:
116116

117117
These are also passed to Doxygen as `PREDEFINED` macros so that conditional API surfaces appear in documentation.
118118

119+
### Optional LittleFS Storage Wrappers
120+
121+
- `-DCFGPACK_LITTLEFS` -- enables LittleFS storage wrappers (`cfgpack_pageout_lfs`, `cfgpack_pagein_lfs`)
122+
123+
Unlike the compression flags, this is NOT on by default in `CFLAGS`. Applications that need LittleFS must explicitly pass `-DCFGPACK_LITTLEFS` and link `src/io_littlefs.c` along with the vendored LittleFS sources (`third_party/littlefs/lfs.c`, `third_party/littlefs/lfs_util.c`). This flag is also passed to Doxygen as a `PREDEFINED` macro.
124+
119125
### Compile-Time Limits
120126

121127
Defined in `include/cfgpack/config.h` and overridable before including cfgpack headers:
@@ -145,6 +151,8 @@ third_party/heatshrink/heatshrink_decoder.c
145151

146152
Notably, `src/io_file.c` is **excluded** from the core library because it depends on `<stdio.h>`. It is compiled separately with hosted flags and linked into tests and tools as needed. This preserves the embedded-friendly, zero-stdio core.
147153

154+
Similarly, `src/io_littlefs.c` is **excluded** from the core library because it depends on LittleFS. It is compiled separately with `-DCFGPACK_LITTLEFS` and linked into applications, tests, and examples that use LittleFS storage.
155+
148156
The archiver creates the library with `ar rcs`.
149157

150158
---
@@ -195,14 +203,15 @@ Each test binary links against: the core static library, `io_file.o`, the encode
195203
196204
### Test Binaries
197205
198-
14 test files producing 13 test binaries (test.c is shared infrastructure, not a standalone binary):
206+
15 test files producing 14 test binaries (test.c is shared infrastructure, not a standalone binary):
199207
200208
| Binary | Source | Area |
201209
|--------|--------|------|
202210
| `basic` | `tests/basic.c` | Core set/get/pageout/pagein, defaults, typed convenience functions |
203211
| `core_edge` | `tests/core_edge.c` | Edge cases in core API |
204212
| `decompress` | `tests/decompress.c` | LZ4 and heatshrink decompression |
205213
| `io_edge` | `tests/io_edge.c` | I/O edge cases |
214+
| `io_littlefs` | `tests/io_littlefs.c` | LittleFS I/O wrappers (RAM-backed block device) |
206215
| `json_edge` | `tests/json_edge.c` | JSON parser edge cases |
207216
| `json_remap` | `tests/json_remap.c` | JSON remapping functionality |
208217
| `measure` | `tests/measure.c` | Schema measure (pre-parse sizing) |
@@ -482,7 +491,20 @@ third_party/heatshrink/
482491

483492
Heatshrink is an LZSS-based compression library designed for embedded systems with very low memory overhead. The decoder is compiled into the core library when `CFGPACK_HEATSHRINK` is defined. The encoder is used by tests (to generate compressed test data) and the `cfgpack-compress` tool.
484493

485-
Both libraries are included via `-Ithird_party/lz4` and `-Ithird_party/heatshrink` in `CPPFLAGS`.
494+
### LittleFS
495+
496+
```
497+
third_party/littlefs/
498+
lfs.c
499+
lfs.h
500+
lfs_util.c
501+
lfs_util.h
502+
LICENSE.md
503+
```
504+
505+
LittleFS is a little fail-safe filesystem designed for microcontrollers. The LittleFS sources are compiled directly into applications that use the cfgpack LittleFS wrappers (they are not part of the core `libcfgpack.a`).
506+
507+
All three libraries are included via `-Ithird_party/lz4`, `-Ithird_party/heatshrink`, and `-Ithird_party/littlefs` in `CPPFLAGS`.
486508

487509
---
488510

@@ -535,6 +557,7 @@ cfgpack/
535557
│ ├── config.h # Build configuration / compile-time limits
536558
│ ├── msgpack.h # MessagePack encode/decode
537559
│ ├── io_file.h # File I/O (hosted only)
560+
│ ├── io_littlefs.h # LittleFS I/O (optional, -DCFGPACK_LITTLEFS)
538561
│ └── decompress.h # Decompression API
539562
├── src/ # Library implementation
540563
│ ├── core.c # Core get/set/init/pageout/pagein
@@ -543,6 +566,7 @@ cfgpack/
543566
│ ├── decompress.c # LZ4/heatshrink decompression
544567
│ ├── io.c # Buffer I/O
545568
│ ├── io_file.c # File I/O (hosted, excluded from core lib)
569+
│ ├── io_littlefs.c # LittleFS I/O (optional, excluded from core lib)
546570
│ ├── tokens.c # Tokenizer for schema parsing
547571
│ └── wbuf.c # Internal write buffer
548572
├── tests/ # Test files
@@ -565,12 +589,14 @@ cfgpack/
565589
├── examples/ # Usage examples
566590
│ ├── allocate-once/ # One-shot allocation pattern
567591
│ ├── datalogger/ # Data logger example
592+
│ ├── flash_config/ # LittleFS + LZ4 + schema migration
568593
│ ├── fleet_gateway/ # Fleet gateway with schema versioning
569594
│ ├── low_memory/ # Low-memory embedded example
570595
│ └── sensor_hub/ # Sensor hub example
571596
├── third_party/ # Vendored dependencies
572597
│ ├── lz4/ # LZ4 compression library
573-
│ └── heatshrink/ # Heatshrink compression library
598+
│ ├── heatshrink/ # Heatshrink compression library
599+
│ └── littlefs/ # LittleFS filesystem library
574600
├── scripts/ # Build/test/setup scripts
575601
│ ├── setup.sh # One-time project setup
576602
│ ├── run-tests.sh # Test runner with summary
@@ -585,6 +611,7 @@ cfgpack/
585611
├── api.rst
586612
├── api-reference.md
587613
├── compression.md
614+
├── littlefs.md
588615
├── fuzz-testing.md
589616
├── stack-analysis.md
590617
└── versioning.md

‎docs/source/api-reference.md‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,32 @@ cfgpack_err_t cfgpack_pagein_file(cfgpack_ctx_t *ctx, const char *path,
574574
uint8_t *scratch, size_t scratch_cap);
575575
```
576576
577+
## LittleFS I/O Wrappers (Optional)
578+
579+
These functions use LittleFS operations and are provided for embedded systems with flash storage. The caller owns the `lfs_t` instance and must mount/unmount it externally. To use these, compile with `-DCFGPACK_LITTLEFS` and link `src/io_littlefs.c` and the LittleFS sources with your project.
580+
581+
The scratch buffer serves double duty: the first `lfs->cfg->cache_size` bytes are used as the LittleFS file cache (via `lfs_file_opencfg`), and the remainder holds the serialized data. This avoids `lfs_malloc`, making the wrappers compatible with `LFS_NO_MALLOC` builds. See [LittleFS Storage Wrappers](littlefs.md) for the full scratch buffer layout and usage guide.
582+
583+
```c
584+
#include "cfgpack/io_littlefs.h"
585+
586+
/* Encode to a LittleFS file using caller scratch buffer (no heap).
587+
* scratch must be >= cfg->cache_size + encoded size. */
588+
cfgpack_err_t cfgpack_pageout_lfs(const cfgpack_ctx_t *ctx,
589+
lfs_t *lfs,
590+
const char *path,
591+
uint8_t *scratch,
592+
size_t scratch_cap);
593+
594+
/* Decode from a LittleFS file using caller scratch buffer (no heap).
595+
* scratch must be >= cfg->cache_size + file size. */
596+
cfgpack_err_t cfgpack_pagein_lfs(cfgpack_ctx_t *ctx,
597+
lfs_t *lfs,
598+
const char *path,
599+
uint8_t *scratch,
600+
size_t scratch_cap);
601+
```
602+
577603
## MessagePack Helpers (Internal-Facing)
578604

579605
These are lower-level functions used internally. They're exposed for advanced use cases.

‎docs/source/api.rst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ File I/O Wrappers
3939
.. doxygenfile:: io_file.h
4040
:project: CFGPack
4141

42+
LittleFS I/O Wrappers
43+
---------------------
44+
45+
.. doxygenfile:: io_littlefs.h
46+
:project: CFGPack
47+
4248
Decompression
4349
-------------
4450

‎docs/source/compression.md‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Where `<algorithm>` is either `lz4` or `heatshrink`.
7575
[0..3] 4-byte little-endian original size
7676
[4..N] LZ4-compressed data
7777
```
78-
This header is required because LZ4 decompression needs to know the output buffer size. The `examples/fleet_gateway/` example demonstrates reading this format at runtime.
78+
This header is required because LZ4 decompression needs to know the output buffer size. The `examples/fleet_gateway/` example demonstrates reading this format at runtime. The `examples/flash_config/` example demonstrates the same pipeline with LittleFS flash storage.
7979

8080
- **Heatshrink**: The output file contains raw compressed data only (no header). Heatshrink is a streaming decoder and does not require the original size up front.
8181

@@ -108,15 +108,32 @@ The output binary can be parsed on-device with `cfgpack_schema_measure_msgpack()
108108

109109
## Third-Party Libraries
110110

111-
LZ4 and heatshrink sources are vendored in `third_party/` for self-contained builds:
111+
LZ4, heatshrink, and LittleFS sources are vendored in `third_party/` for self-contained builds:
112+
113+
### LZ4
112114

113115
```
114-
third_party/
115-
lz4/
116+
third_party/lz4/
116117
lz4.h, lz4.c # BSD-2-Clause license
117-
heatshrink/
118+
```
119+
120+
### Heatshrink
121+
122+
```
123+
third_party/heatshrink/
118124
heatshrink_config.h # window=8, lookahead=4
119125
heatshrink_decoder.h/c # Used by library
120126
heatshrink_encoder.h/c # Used by compression tool and tests
121127
# ISC license
122128
```
129+
130+
### LittleFS
131+
132+
```
133+
third_party/littlefs/
134+
lfs.h, lfs.c # Core filesystem implementation
135+
lfs_util.h, lfs_util.c # Utility functions
136+
LICENSE.md # BSD-3-Clause license
137+
```
138+
139+
LittleFS is a little fail-safe filesystem designed for microcontrollers. Unlike LZ4 and heatshrink, it is not compiled into the core library — it is linked directly by applications that use the LittleFS wrappers (`-DCFGPACK_LITTLEFS`). See [LittleFS Storage Wrappers](littlefs.md) for details.

‎docs/source/getting-started.rst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ Include just ``cfgpack/cfgpack.h``; it re-exports the public API surface.
5656
the full measure-then-allocate pattern, ``examples/low_memory/`` for a
5757
complete example combining measure-then-allocate with schema migration, or
5858
``examples/fleet_gateway/`` for msgpack binary schemas with a three-version
59-
migration chain using ``cfgpack_schema_measure_msgpack()``.
59+
migration chain using ``cfgpack_schema_measure_msgpack()``, or
60+
``examples/flash_config/`` for LittleFS flash storage with LZ4-compressed
61+
msgpack schemas and a v1 → v2 remap migration.
6062

6163
Map Format
6264
----------

‎docs/source/index.rst‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Hard caps: max 128 schema entries.
1515
api-reference
1616
versioning
1717
compression
18+
littlefs
1819
stack-analysis
1920
fuzz-testing
2021

@@ -29,6 +30,7 @@ Features
2930
- Schema versioning with embedded schema name for version detection
3031
- Index remapping and type widening for schema migrations
3132
- Optional LZ4/heatshrink decompression support
33+
- Optional LittleFS storage wrappers for flash-based embedded systems
3234

3335
Indices and tables
3436
==================

0 commit comments

Comments
 (0)