mtd flash: add a generic low level flash interface [RFC]#5624
mtd flash: add a generic low level flash interface [RFC]#5624vincent-d merged 5 commits intoRIOT-OS:masterfrom
Conversation
|
Please compare with #2239 and fuse the efforts. |
|
OK, I'm refraining from code review until #5624 (comment) is addressed. |
drivers/include/mtdi.h
Outdated
| */ | ||
| typedef enum { | ||
| MTDI_STA_INIT = 0x00, /**< Drive initialized */ | ||
| MTDI_STA_NOINIT = 0x01, /**< Drive not initialized */ |
There was a problem hiding this comment.
IMO it's better to have noinit = 0, because then the initial value will be set to "not initialized" on boot even if placed in .bss
|
The native MTD emulation device needs to do some bounds checking on the addresses and sizes to avoid writing outside the emulated memory. The fwrite will succeed and the file will grow, but that won't work when you move it to a real MTD. Some introductory documentation is needed to explain what is meant by a page and a sector and what the alignment requirements are for the different functions. Are writes to already written sectors allowed? native MTD emulation should emulate flash by only programming the 0 bits ( |
|
@LudwigKnuepfer I like the proposed structure with a driver struct containing pointers to all the functions to allow more than one type of flash device present in the same running system, this was difficult to achieve with the interface proposed in #2239. The interface proposed in this PR is similar to the already existing NVRAM interface. |
|
@LudwigKnuepfer though I agree that there are many good parts in #2239 that could be lifted into this PR. For example the native flash emulation in #2239 emulate the properties of flash better than the current state of this PR does. |
cpu/native/mtdi/native_mtdi.c
Outdated
| if (addr + size > NATIVE_MTDI_FLASH_SIZE) { | ||
| return MTDI_RES_PARERR; | ||
| } | ||
| if (addr % NATIVE_MTDI_SECTOR_SIZE + size > NATIVE_MTDI_SECTOR_SIZE) { |
There was a problem hiding this comment.
add some parentheses to make this a bit more readable
|
Doc improved, even if it could still be better. Still not entirely sure about the boundaries for read/write/erase, but it seems to match at least how SPIFFS uses it. I also improved the flash emulation. |
cpu/native/mtdi/native_mtdi.c
Outdated
| if (addr + size > NATIVE_MTDI_FLASH_SIZE) { | ||
| return MTDI_RES_PARERR; | ||
| } | ||
| if (addr % NATIVE_MTDI_SECTOR_SIZE != 0 || size % NATIVE_MTDI_SECTOR_SIZE != 0) { |
|
btw, why is it called MTDI and not just MTD? |
|
The I stands for interface. @AurelienGONCE wanted to clearly show that it's an interface ;) |
cpu/native/mtdi/native_mtdi.c
Outdated
| #define ENABLE_DEBUG (0) | ||
| #include "debug.h" | ||
|
|
||
| static const char _fname[] = "MEMORY.bin"; |
There was a problem hiding this comment.
I would like to see this provided as a command line parameter or option.
|
I'd prefer to call the interface MTD and the main interface file btw, I'm working on a SPI NOR flash driver for this interface. |
drivers/include/mtdi.h
Outdated
| * The number of pages in a sector must be constant for the whole MTD. | ||
| * | ||
| * Most of the flash filesystems implementation will use pages as basic unit for writing. | ||
| * This interface does not limit the writing on bage boundaries but user must not write on |
|
What is the use case for the |
|
Some more review comments: The argument types for buffers I suggest that the We tend to avoid "getter" functions for simple values in RIOT. I suggest that the typedef struct {
const mtdi_desc_t *driver;
uint32_t sector_count;
uint32_t pages_per_sector;
uint32_t page_size;
} mtdi_dev_t;The other numbers can be derived from those three values by multiplication. Also, it avoids a possible ambiguity regarding total memory size by eliminating the redundant counts. |
|
Fix doxygen and cppcheck errors |
| TEST_ASSERT_EQUAL_INT(0, memcmp(buf_empty, buf_read + sizeof(buf), sizeof(buf_empty))); | ||
|
|
||
| /* Unaligned write / read */ | ||
| ret = mtd_write(dev, buf, dev->page_size, sizeof(buf)); |
There was a problem hiding this comment.
How about we change this to
ret = mtd_write(dev, buf, dev->page_size + sizeof(buf_empty), sizeof(buf));and change the readback to match:
TEST_ASSERT_EQUAL_INT(0, memcmp(buf_empty, buf_read, sizeof(buf_empty)));
TEST_ASSERT_EQUAL_INT(0, memcmp(buf, buf_read + sizeof(buf_empty), sizeof(buf)));that will test completely unaligned writes, and also catch implementation errors where the read or write addresses are not the same
|
It looks okay now, I'll give it a spin later tonight or tomorrow and give my ACK. |
|
Ok to squash |
cpu/native/mtd/mtd_native.c
Outdated
| if (!f) { | ||
| return -EIO; | ||
| } | ||
| unsigned long size = dev->sector_count * dev->pages_per_sector * dev->page_size; |
There was a problem hiding this comment.
It could make sense. I'll change that here and in other places.
|
found one minor nit in mtd_vfs. I'm writing a unittest for mtd_vfs too. I'll post back when it's done |
3e8f754 to
2afca63
Compare
|
Squashed, with @kaspar030 remark fixed |
|
Two commits for mtd-vfs: |
2afca63 to
454b891
Compare
|
@gebart cherry-picked and squashed, thanks |
34b15d2 to
3ca1446
Compare
3ca1446 to
9782be1
Compare
|
I don't understand why Murdock2 failed. Murdock and Jenkins seem happy anyway. |
|
@gebart thanks! Shall I press the button ? |
|
ACK, |
|
Then GO! |
|
Congratulations 🎊 🎉 |
This PR adds a low level flash interface and a basic dummy flash implementation for the native cpu.
Comments are welcomed.