Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,28 @@ dmfsi_context_t ctx = dmfsi_dmffs_init(NULL);

#### 2. Configuration String (Per-Instance)

The configuration string supports flexible formats for convenience:

```c
// Pass configuration directly
// Long format with semicolon (original)
dmfsi_context_t ctx = dmfsi_dmffs_init("flash_addr=0x08080000;flash_size=0x80000");

// Short format with comma (also supported)
dmfsi_context_t ctx = dmfsi_dmffs_init("addr=0x08080000,size=0x80000");

// Mixed formats work too
dmfsi_context_t ctx = dmfsi_dmffs_init("addr=0x08080000;size=0x80000");
dmfsi_context_t ctx = dmfsi_dmffs_init("flash_addr=0x08080000,flash_size=0x80000");
```

Supported key names:
- `flash_addr` or `addr` - Flash memory base address (hex value)
- `flash_size` or `size` - Flash memory size (hex value)

Supported separators:
- `;` (semicolon)
- `,` (comma)

### Advanced Features

#### Directory Support
Expand Down
21 changes: 13 additions & 8 deletions src/dmffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ static size_t parse_hex_string(const char* hex_str)
static bool parse_config_string( dmfsi_context_t ctx, const char* config )
{
// Example config string: "flash_addr=0x08000000;flash_size=0x100000"
// Also supports: "addr=0x08000000,size=0x100000"
const char* ptr = config;
while (*ptr) {
// Parse key
const char* key_start = ptr;
while (*ptr && *ptr != '=' && *ptr != ';') ptr++;
while (*ptr && *ptr != '=' && *ptr != ';' && *ptr != ',') ptr++;
size_t key_len = ptr - key_start;

if (*ptr != '=') {
Expand All @@ -122,23 +123,26 @@ static bool parse_config_string( dmfsi_context_t ctx, const char* config )

// Parse value
const char* value_start = ptr;
while (*ptr && *ptr != ';') ptr++;
while (*ptr && *ptr != ';' && *ptr != ',') ptr++;
size_t value_len = ptr - value_start;

// Process key-value pair
if (key_len == 10 && strncmp(key_start, "flash_addr", 10) == 0) {
// Process key-value pair - support both long and short key names
if ((key_len == 10 && strncmp(key_start, "flash_addr", 10) == 0) ||
(key_len == 4 && strncmp(key_start, "addr", 4) == 0)) {
char value_str[20] = {0};
strncpy(value_str, value_start, value_len < 19 ? value_len : 19);
ctx->flash_addr = (const void*)parse_hex_string(value_str);
} else if (key_len == 10 && strncmp(key_start, "flash_size", 10) == 0) {
} else if ((key_len == 10 && strncmp(key_start, "flash_size", 10) == 0) ||
(key_len == 4 && strncmp(key_start, "size", 4) == 0)) {
char value_str[20] = {0};
strncpy(value_str, value_start, value_len < 19 ? value_len : 19);
ctx->flash_size = parse_hex_string(value_str);
} else {
DMOD_LOG_WARN("Unknown config key: '%.*s'\n", (int)key_len, key_start);
}

if (*ptr == ';') ptr++; // Skip ';'
// Skip separator (semicolon or comma)
if (*ptr == ';' || *ptr == ',') ptr++;
}

return true;
Expand Down Expand Up @@ -518,9 +522,10 @@ int dmod_deinit(void)
*
* The function initializes the DMFFS file system with the provided configuration string.
* The configuration string can specify flash parameters such as address and size, in format:
* "flash_addr=0x08000000;flash_size=0x100000"
* "flash_addr=0x08000000;flash_size=0x100000" or "addr=0x08000000,size=0x100000"
* Both semicolon and comma separators are supported.
*
* If no configuration string is provided, default parameters from environment variables.
* If no configuration string is provided, default parameters are loaded from environment variables.
*
* @param config (optional) Configuration string (FS-specific)
* @return Context pointer on success, NULL on failure
Expand Down