Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: add support for MTDs emulated in RAM #19443

Merged
merged 10 commits into from
Apr 12, 2023

Conversation

gschorcht
Copy link
Contributor

Contribution description

This PR adds a driver to provide MTDs that are emulated in RAM. It allows to test MTD-based applications on boards that do not provide MTDs by hardware.

It includes also some small documentation fixes for mtd.h that were found while writing the driver.

Testing procedure

The following tests should work on any board:

tests/pkg_littlefs
tests/pkg_littlefs2
tests/pkg_spiffs

Issues/PRs references

@github-actions github-actions bot added Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: tests Area: tests and testing framework labels Apr 3, 2023
@gschorcht gschorcht added Type: new feature The issue requests / The PR implemements a new feature for RIOT CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Apr 3, 2023
@gschorcht gschorcht changed the title Drivers/mtd emulated drivers: add support for MTDs emulated in RAM Apr 3, 2023
@riot-ci
Copy link

riot-ci commented Apr 3, 2023

Murdock results

✔️ PASSED

89f18c7 tests/littlefs: remove blacklisted boards due to reduced sector count

Success Failures Total Runtime
6882 0 6882 10m:02s

Artifacts

Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

Quick round of review.
I didn't test it yet.

drivers/mtd_emulated/Kconfig Outdated Show resolved Hide resolved
drivers/include/mtd.h Outdated Show resolved Hide resolved
drivers/include/mtd.h Outdated Show resolved Hide resolved
drivers/include/mtd.h Outdated Show resolved Hide resolved
drivers/mtd_emulated/Kconfig Outdated Show resolved Hide resolved
@dylad
Copy link
Member

dylad commented Apr 7, 2023

@gschorcht Please squash !

Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

spotted this on lastest commit

tests/usbus_msc/README.md Outdated Show resolved Hide resolved
tests/usbus_msc/README.md Outdated Show resolved Hide resolved
bors bot added a commit that referenced this pull request Apr 9, 2023
19460: cpu/stm32/usbdev_fs: fix ep registration and EP_REG assignments r=gschorcht a=dylad

### Contribution description
This PR provides two fixes for the `usbdev_fs` driver:

- Fix endpoints registration
- Fix assignment of toggleable bits in EP_REG(x) registers

These bugs were encountered with the USBUS MSC implementation.

Regarding the endpoints registration:

For the `usbdev_fs` peripheral, IN and OUT endpoints of the same index must have the same type.
For instance, if EP1 OUT is a bulk endpoint, EP1 IN must either be unused or used as bulk too but it cannot be used as interrupt or isochronous.
With the previous check, the following registration pattern (EP OUT Bulk -> EP IN Interrupt -> EP IN Bulk) would assign both EP OUT Bulk and EP IN Interrupt to same endpoint index. So the configuration would be broken.
Applying the same registration pattern with this patch would now produce EP OUT Bulk -> 1 / EP IN Interrupt -> 2 / EP IN Bulk 1. Which is a working configuration for this IP.

and for the second fix:

EP_REG(x) registers have a total of 6 toggleable bits. Those bits can only be toggled if we write a one to it, otherwise writing a zero has no effect
This commit fixes all the access to these registers to prevent from modifying these bits when not needed.
Without this patch, the endpoint status (VALID / NACK / STALL) can be erroneously modify because bits are not cleared when assigning the new content to the register and thus make the bits toggle and change values.

### Testing procedure
This can be tested with tests/usbus_msc on any board using this `usbdev_fs` driver.
It is easier to test this PR with #19443 alongside. Then the following would be enough:
`CFLAGS='-DSECTOR_COUNT=64' USEMODULE='mtd_emulated' make -j8 BOARD=p-nucleo-wb55 -C tests/usbus_msc flash`

Otherwise this can also be tested by attaching a SPI<->SDCARD adapter.

### Issues/PRs references
None.

Co-authored-by: Dylan Laduranty <dylan.laduranty@mesotic.com>
@dylad dylad requested a review from benpicco April 10, 2023 19:29
Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

Please squash (including these two nitpicks)

drivers/include/mtd_default.h Outdated Show resolved Hide resolved
drivers/include/mtd_emulated.h Outdated Show resolved Hide resolved
@gschorcht
Copy link
Contributor Author

Squashed

This driver provides support for MTDs emulated in RAM to test MTD-based applications on boards that do not provide MTDs in hardware.
Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

CI complains about unittests.

tests/unittests/tests-mtd/tests-mtd.c Outdated Show resolved Hide resolved
Copy link
Member

@dylad dylad left a comment

Choose a reason for hiding this comment

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

ACK.

@dylad
Copy link
Member

dylad commented Apr 12, 2023

bors merge

bors bot added a commit that referenced this pull request Apr 12, 2023
19443: drivers: add support for MTDs emulated in RAM r=dylad a=gschorcht

### Contribution description

This PR adds a driver to provide MTDs that are emulated in RAM. It allows to test MTD-based applications on boards that do not provide MTDs by hardware.

It includes also some small documentation fixes for `mtd.h` that were found while writing the driver.

### Testing procedure

The following tests should work on any board:

`tests/pkg_littlefs`
`tests/pkg_littlefs2`
`tests/pkg_spiffs`

### Issues/PRs references


Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
@bors
Copy link
Contributor

bors bot commented Apr 12, 2023

Build failed:

A `SECTOR_COUNT` of 12 seems to be sufficient to work for this test in emulated MTD.
Removing boards blacklisted for insufficient memory after reducing the number of sectors of the emulated MTD.
@dylad
Copy link
Member

dylad commented Apr 12, 2023

bors merge

@bors
Copy link
Contributor

bors bot commented Apr 12, 2023

Build succeeded:

@bors bors bot merged commit b342cdc into RIOT-OS:master Apr 12, 2023
@gschorcht
Copy link
Contributor Author

Thanks

@gschorcht gschorcht deleted the drivers/mtd_emulated branch April 12, 2023 12:19
@benpicco benpicco added this to the Release 2023.07 milestone Aug 2, 2023
bors bot added a commit that referenced this pull request Oct 19, 2023
19465: drivers/mtd: use XFA for pointers to defined MTDs r=benpicco a=gschorcht

### Contribution description

This PR provides the support to hold pointers to defined MTDs within a XFA. The XFA allows
- to access MTDs of different types (`mtd_flashpage`, `mtd_sdcard`, `mtd_emulated`, ...) by an index
- to determine the number of MTDs defined in the system.

### Testing procedure

To be defined once PR #19443 is merged because emulated MTDs will allow to test this PR on arbitrary boards.

### Porting Guide

For external boards:
 - remove the `MTD_NUMOF` definition from `board.h`
 - add `MTD_XFA_ADD(<mtd_dev>, <idx>);` to the definition of `<mtd_dev>`.
 - `MTD_0`, `MTD_1`, … defines are no longer needed.

### Issues/PRs references

 Related to PR #19443

19981: Fletcher32: Add incremental API r=benpicco a=bergzand

### Contribution description

This PR extends the current fletcher32 checksum with an incremental API mode. This way the bytes to be checksummed can be supplied via multiple successive calls and do not have to be provided in a single consecutive buffer.

I've also rephrased the warning with the original function a bit as that function uses an `unaligned_get_u16` to access the data. The data thus does not require alignment, but the length does need to be supplied as number of 16 bit words.

### Testing procedure

The test has been extended


### Issues/PRs references

None

19995: sys/psa_crypto: Fix macro for public key max size and SE example r=benpicco a=Einhornhool

### Contribution description
#### 1. Wrong public key size when using secure elements, introduced by  #19954
Fixed conditions for key size macros in `crypto_sizes.h`.

#### 2. EdDSA and ECDSA examples fail when using a secure element because of unsopported changes introduced by #19954
Updated `example/psa_crypto` to use only supported functions for secure elements.

### Testing procedure
Build `example/psa_crypto` for secure elements and run application

Output on master:
```
2023-10-19 14:33:24,372 # main(): This is RIOT! (Version: 2019.07-devel-22378-gb6772)
2023-10-19 14:33:24,372 # HMAC SHA256 took 56393 us
2023-10-19 14:33:24,372 # Cipher AES 128 took 68826 us
2023-10-19 14:33:24,372 # *** RIOT kernel panic:
2023-10-19 14:33:24,373 # HARD FAULT HANDLER
2023-10-19 14:33:24,373 # 
2023-10-19 14:33:24,373 # *** rebooting...

```
Output with fixes:
```
2023-10-19 13:35:24,715 # main(): This is RIOT! (Version: 2019.07-devel-22384-g8ef66-dev/psa-crypto-fixes)
2023-10-19 13:35:24,715 # HMAC SHA256 took 56374 us
2023-10-19 13:35:24,715 # Cipher AES 128 took 68805 us
2023-10-19 13:35:24,715 # ECDSA took 281164 us
2023-10-19 13:35:24,715 # All Done
```


Co-authored-by: Gunar Schorcht <gunar@schorcht.net>
Co-authored-by: Koen Zandberg <koen@bergzand.net>
Co-authored-by: Lena Boeckmann <lena.boeckmann@haw-hamburg.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: doc Area: Documentation Area: drivers Area: Device drivers Area: Kconfig Area: Kconfig integration Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR 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.

4 participants