Skip to content

sys/eepreg: use MTD#22158

Open
fabian18 wants to merge 13 commits intoRIOT-OS:masterfrom
fabian18:pr/eepreg_mtd
Open

sys/eepreg: use MTD#22158
fabian18 wants to merge 13 commits intoRIOT-OS:masterfrom
fabian18:pr/eepreg_mtd

Conversation

@fabian18
Copy link
Copy Markdown
Contributor

Contribution description

Add an MTD to the EEPROM registry API, so that other MTD (EEPROMS) can also be used.

  • Extend EEPROM registry API
  • Create internal EEPROM MTD
  • Add mtd_eeprom to boards that support periph/eeprom
  • Adapt tests

Testing procedure

USEMODULE+=at24mac CFLAGS+=-DTEST_EEPREG_MTD="mtd_dev_get\(1\)" DEVELHELP=1 VERBOSE_ASSERT=1 make -C tests/sys/eepreg/ BOARD=same54-xpro flash term

2026-03-30 20:42:36,101 # START
2026-03-30 20:42:36,107 # main(): This is RIOT! (Version: 2026.04-devel-325-ge13ff-pr/eepreg_mtd)
2026-03-30 20:42:36,110 # EEPROM registry (eepreg) test routine
2026-03-30 20:42:36,121 # Testing new registry creation: reset check [SUCCESS]
2026-03-30 20:42:36,162 # Testing writing and reading entries: add write add read [SUCCESS]
2026-03-30 20:42:36,171 # Testing detection of conflicting size: add [SUCCESS]
2026-03-30 20:42:36,184 # Testing calculation of lengths: len len [SUCCESS]
2026-03-30 20:42:36,347 # Testing of successful data move after rm: rm read data [SUCCESS]
2026-03-30 20:42:36,373 # Testing of free space change after write: free add free [SUCCESS]
2026-03-30 20:42:36,384 # Testing of iteration over registry: iter bar foo [SUCCESS]
2026-03-30 20:42:36,385 # Tests complete!
2026-03-30 20:42:36,392 # { "threads": [{ "name": "main", "stack_size": 1536, "stack_used": 488 }]}

Issues/PRs references

@github-actions github-actions Bot added Platform: native Platform: This PR/issue effects the native platform Area: tests Area: tests and testing framework Platform: AVR Platform: This PR/issue effects AVR-based platforms Area: drivers Area: Device drivers Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: sys Area: System labels Mar 30, 2026
@crasbe crasbe added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Mar 30, 2026
Copy link
Copy Markdown
Contributor

@crasbe crasbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static test has some comments too and why is mtd_eeprom.h sometimes conditionally and sometimes unconditionally included? 🤔

Comment thread boards/common/atmega/board_common.c
Comment thread boards/common/native/board_init.c Outdated
Comment thread boards/common/nucleo/board_common.c
Comment thread boards/common/nucleo/board_common.c Outdated
Comment thread boards/i-nucleo-lrwan1/board.c
Comment thread boards/nz32-sc151/board.c
Comment thread boards/stm32l0538-disco/board.c
Comment thread tests/drivers/mtd_eeprom/main.c
Comment thread tests/drivers/mtd_eeprom/tests/01-run.py Outdated
Comment thread tests/sys/eepreg/main.c Outdated
@riot-ci
Copy link
Copy Markdown

riot-ci commented Mar 30, 2026

Murdock results

FAILED

82dcd5b fixup! fixup! boards: expose default EEPROM MTD

Build failures (21)
Application Target Toolchain Runtime (s) Worker
tests/drivers/mtd_at24cxxx native32 gnu 0.81 mobi6
tests/drivers/mtd_at24cxxx native64 gnu 0.78 mobi6
tests/drivers/mtd_at24cxxx native64 llvm 0.77 mobi7
tests/drivers/mtd_at24cxxx native32 llvm 0.87 mobi6
tests/net/nanocoap_cli native64 llvm 1.28 mobi7
tests/net/nanocoap_cli native32 gnu 1.69 mobi6
tests/net/nanocoap_cli native64 gnu 1.66 mobi6
tests/net/nanocoap_cli native32 llvm 7.06 mobi7
tests/pkg/fatfs native32 gnu 1.10 mobi6
tests/pkg/fatfs native64 gnu 1.07 mobi6
tests/pkg/fatfs native32 llvm 1.13 mobi6
tests/pkg/fatfs native64 llvm 3.13 skyleaf
tests/pkg/spiffs native64 gnu 0.78 mobi7
tests/pkg/spiffs native32 gnu 1.18 mobi6
tests/pkg/spiffs native64 llvm 1.23 mobi6
tests/pkg/spiffs native32 llvm 3.06 skyleaf
tests/sys/shell_scripting native32 gnu 0.91 mobi6
tests/sys/shell_scripting native64 gnu 0.91 mobi6
tests/sys/shell_scripting native64 llvm 0.75 mobi7
tests/sys/shell_scripting native32 llvm 0.99 mobi6

and 74 more build failures...

Artifacts

@crasbe crasbe added the Type: new feature The issue requests / The PR implemements a new feature for RIOT label Apr 3, 2026
@crasbe crasbe added the CI: no fast fail don't abort PR build after first error label Apr 14, 2026
@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Apr 14, 2026

The build for arduino-leonardo currently fails:

buechse@skyleaf:~/RIOTstuff/riot-vanilla/RIOT/tests/drivers/mtd_eeprom$ BUILD_IN_DOCKER=1 BOARD=arduino-leonardo make
Launching build container using image "docker.io/riot/riotbuild@sha256:08fa7da2c702ac4db7cf57c23fc46c1971f3bffc4a6eff129793f853ec808736".
docker run --rm --tty --user $(id -u) --platform linux/amd64 -v '/home/buechse/RIOTstuff/riot-vanilla/RIOT:/data/riotbuild/riotbase:delegated' -v '/home/buechse/.cargo/registry:/data/riotbuild/.cargo/registry:delegated' -v '/home/buechse/.cargo/git:/data/riotbuild/.cargo/git:delegated' -e 'TZ=Europe/Berlin' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'BUILD_IN_DOCKER=0' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'      -e 'BOARD=arduino-leonardo' -e 'DISABLE_MODULE=' -e 'DEFAULT_MODULE=test_utils_interactive_sync test_utils_print_stack_usage' -e 'FEATURES_REQUIRED=' -e 'FEATURES_BLACKLIST=' -e 'FEATURES_OPTIONAL=' -e 'USEMODULE=embunit mtd_eeprom' -e 'USEPKG='  -w '/data/riotbuild/riotbase/tests/drivers/mtd_eeprom/' 'docker.io/riot/riotbuild@sha256:08fa7da2c702ac4db7cf57c23fc46c1971f3bffc4a6eff129793f853ec808736' make
Building application "tests_mtd_eeprom" for "arduino-leonardo" with CPU "atmega32u4".

"make" -C /data/riotbuild/riotbase/boards
...
"make" -C /data/riotbuild/riotbase/sys/tsrb
/data/riotbuild/riotbase/tests/drivers/mtd_eeprom/bin/arduino-leonardo/boards_common_atmega/board_common.o:(.roxfa.mtd_dev_xfa.5_0+0x0): multiple definition of `mtd0'
/data/riotbuild/riotbase/tests/drivers/mtd_eeprom/bin/arduino-leonardo/board/board.o:(.roxfa.mtd_dev_xfa.5_0+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [/data/riotbuild/riotbase/Makefile.include:734: /data/riotbuild/riotbase/tests/drivers/mtd_eeprom/bin/arduino-leonardo/tests_mtd_eeprom.elf] Error 1
make: *** [/home/buechse/RIOTstuff/riot-vanilla/RIOT/makefiles/docker.inc.mk:395: ..in-docker-container] Error 2

@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Apr 14, 2026

The tests/drivers/mtd_eeprom also needs a Makefile.ci which includes the atmega8.

@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Apr 14, 2026

The tests/sys/eepreg/Makefile probably needs USEMODULE += mtd_eeprom, now that the MTD subsystem is used to access the EEPROM.

I'm unfamiliar with eepgreg, is that only for EEPROMs integrated into the microcontroller or also for external EEPROMs?

@fabian18
Copy link
Copy Markdown
Contributor Author

tests/sys/eepreg/Makefile --> eepreg --> mtd

The mtd pulls mtd_eeprom depending on the board.
Technically eepreg compiles with any mtd. I would just not guarantee that it works for anything else than EEPROM.
But mtd_at24cxxx works, which is an external EEPROM, hence it is a real alternative to mtd_eeprom.

@crasbe
Copy link
Copy Markdown
Contributor

crasbe commented Apr 14, 2026

In general we might have to think about the name, mtd_eeprom does not really make it clear that it is only for internal EEPROMs.

I mean for external ones we have mtd_at24cxxx, so at the very least we should have a reference to that if someone is looking through the documentation and wonders where the documentation for external EEPROMs is.

Speaking of which... the documentation about the driver is a bit... slim.
image

You should add some information about how to use the driver (for new boards, CPUs at least), where it gets it's information from about the EEPROM size(s), how it's integrated, what it can be used for etc.

Comment thread sys/eepreg/Makefile.dep
@@ -1 +1 @@
FEATURES_REQUIRED += periph_eeprom
USEMODULE += mtd
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
USEMODULE += mtd
# eepreg works with other `mtd_%` subsystems than `mtd_eeprom` too as not all
# microcontrollers have built-in EEPROMs. However at least one `mtd_%`
# subsystem has to be configured, otherwise fall back to requiring the internal
# EEPROM. This makes sure the automatic feature resultion of the CI only
# tries to compile the test for boards that it would work on.
# Checking the USEMODULE before adding to it makes sure we don't test in the
# first round of dependency resolution to avoid false-negatives.
ifneq (,$(filter mtd,$(USEMODULE)))
ifeq (,$(filter mtd_%,$(USEMODULE)))
FEATURES_REQUIRED += periph_eeprom
endif
endif
USEMODULE += mtd

This should make sure that eepreg builds for all boards that expose an MTD_0 if they have an mtd_% configured or have periph_eeprom present.

buechse@skyleaf:~/RIOTstuff/riot-vanilla/RIOT/tests/sys/eepreg$ BUILD_IN_DOCKER=1 BOARD=nrf52dk make
There are unsatisfied feature requirements: periph_eeprom
/home/buechse/RIOTstuff/riot-vanilla/RIOT/tests/sys/eepreg/../../../Makefile.include:1033: *** You can let the build continue on expected errors by setting CONTINUE_ON_EXPECTED_ERRORS=1 to the command line.  Stop.

buechse@skyleaf:~/RIOTstuff/riot-vanilla/RIOT/tests/sys/eepreg$ BUILD_IN_DOCKER=1 BOARD=nrf52840dk make
Launching build container using image "docker.io/riot/riotbuild@sha256:08fa7da2c702ac4db7cf57c23fc46c1971f3bffc4a6eff129793f853ec808736".
docker run --rm --tty --user $(id -u) --platform linux/amd64 -v '/home/buechse/RIOTstuff/riot-vanilla/RIOT:/data/riotbuild/riotbase:delegated' -v '/home/buechse/.cargo/registry:/data/riotbuild/.cargo/registry:delegated' -v '/home/buechse/.cargo/git:/data/riotbuild/.cargo/git:delegated' -e 'TZ=Europe/Berlin' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'BUILD_IN_DOCKER=0' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'      -e 'BOARD=nrf52840dk' -e 'DISABLE_MODULE=' -e 'DEFAULT_MODULE=test_utils_interactive_sync test_utils_print_stack_usage' -e 'FEATURES_REQUIRED=' -e 'FEATURES_BLACKLIST=' -e 'FEATURES_OPTIONAL=' -e 'USEMODULE=eepreg' -e 'USEPKG='  -w '/data/riotbuild/riotbase/tests/sys/eepreg/' 'docker.io/riot/riotbuild@sha256:08fa7da2c702ac4db7cf57c23fc46c1971f3bffc4a6eff129793f853ec808736' make
Building application "tests_eepreg" for "nrf52840dk" with CPU "nrf52".

"make" -C /data/riotbuild/riotbase/pkg/cmsis/
...
"make" -C /data/riotbuild/riotbase/sys/tsrb
   text    data     bss     dec     hex filename
  16728     168    2548   19444    4bf4 /data/riotbuild/riotbase/tests/sys/eepreg/bin/nrf52840dk/tests_eepreg.elf

Copy link
Copy Markdown
Contributor Author

@fabian18 fabian18 Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this patch I would see USEMODULE += mtd_eeprom there instead of FEATURES_REQUIRED += periph_eeprom. This in the end requires periph_eepom too but it is not explicitly mentioned.

So this will pull mtd_eeprom as a fallback if no particular MTD is used.

Copy link
Copy Markdown
Contributor

@crasbe crasbe Apr 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Then it depends on whether you want to open eepreg for other MTDs too.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could also filter for mtd_24cxxxx only for EEPROM-like MTD devices instead of filtering for all mtd_%.

Comment thread tests/sys/eepreg/main.c
#ifndef TEST_EEPREG_MTD
# define TEST_EEPREG_MTD MTD_0
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#ifndef MTD_0
# define MTD_0 mtd_dev_get(0)
#endif

This would be a workaround since not all boards provide MTD_0 (for example if mtd_sdmmc is used).

Or do you want to do a full treewide migration and add the appropriate MTD_0 defines? This would be relevant for devices that have more than one MTD 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I added an MTD_<0|1> for all boards that support periph_eeprom.
Giving them an MTD is a benefit for boards that previously did not have any.

Why is mtd_sdmmc relevant? Because the CI will attempt to compile the eepreg test for a board that has only mtd_sdmmc but no MTD_0 defined? That's a a bit of a flaw. Maybe the workaround can be integrated in to mtd in general. I dont know yet

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You removed the periph_eeprom feature requirement, so now CI will try to compile for all boards.

I assumed this was intentional.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but I expected that every board supporting an MTD defines at least MTD_0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have not applied this yet. For native it is currently an issue that the eeprom would be MTD_1. The eepreg test for native MTD fails.

I would by now not use any MTD_ but rather introduce the naming convention that the internal EEPROM MTD must be calles "mtd_eeprom" for example.

Comment thread tests/sys/eepreg/main.c

#define DAT_START (EEPROM_SIZE - EEPROM_RESERV_CPU_HI \
#ifndef TEST_EEPREG_MTD
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This configuration parameter should be documented in the tests/sys/eepreg/README.md, especially considering boards that might have multiple MTD devices.

@github-actions github-actions Bot added the Area: doc Area: Documentation label Apr 14, 2026
Comment thread tests/sys/eepreg/README.md Outdated
WARNING: This will write to your EEPROM and probably corrupt any data that is
there!

Add `CFLAGS += -DTEST_EEPREG_MTD=MTD_<X>` if a different MTD should be used than MTD_0.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be changed to MTD_EEPROM now I guess?

Comment thread tests/sys/eepreg/main.c Outdated

#ifndef TEST_EEPREG_MTD
# define TEST_EEPREG_MTD MTD_0
# define TEST_EEPREG_MTD (&mtd_eeprom.base)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use MTD_EEPROM here?

Comment thread drivers/include/mtd_default.h Outdated
#endif

#if defined(MODULE_MTD_EEPROM)
#include "mtd_eeprom.h"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#include "mtd_eeprom.h"
# include "mtd_eeprom.h"

#if MODULE_MTD_EEPROM
static mtd_eeprom_t eeprom_mtd = MTD_EEPROM_INIT_VAL;
MTD_XFA_ADD(eeprom_mtd, 0);
mtd_eeprom_t mtd_eeprom = MTD_EEPROM_INIT_VAL;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though this is not a define, I'd propose to call it MTD_EEPROM to reduce the confusion with the module.

But still, there is confusion potential between the module and the MTD device when both have the same name 😅

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I don't have a better name for the MTD device unfortunately :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports Area: cpu Area: CPU/MCU ports Area: doc Area: Documentation Area: drivers Area: Device drivers Area: sys Area: System Area: tests Area: tests and testing framework CI: no fast fail don't abort PR build after first error CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: AVR Platform: This PR/issue effects AVR-based platforms Platform: native Platform: This PR/issue effects the native platform Type: new feature The issue requests / The PR implemements a new feature for RIOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants