I'm trying to write on a NAND flash memory using MTD block device but I don't understand everything.
As I read here
mtdblockN
is the read only block device NmtdN
is the read/write char device NmtdNro
is the read only char device N
But I'd like to directly write bytes to the partition using a simple write
in C and I don't understand how it works (I read somewhre that I first must erase the sectors I want to write on).
Which device should I use and how to write on this device?
Reading and writing from/to memory technology devices isn't really all that different than any other type of IO, with the exception that before you write you need to erase the sector (erase block)
To make things simple on yourself you can always just use the mtd-utils (such as
flash_erase
,nanddump
andnandwrite
, for erasing, read, and writing respectively) without the need for writing code.However if you do want to do it pragmatically, here's an example, make sure to read all the comments as I put all the details in there:
The nice thing about this is since you can use the standards utils as you do from other devices, it makes it easy to understand what
write()
,open()
, andread()
do and what to expect from them.For example if while using
write()
you got a value ofEINVAL
it could mean: