Refined Question
How do read and write text information from a MTD SRAM device with erase block size zero?
Notes:
- I am using the 23K256 Driver
- Attempts to use MTD-Util tools have failed because
libmtd
cannot handle a erase block size of zero - Attempts to artificially add an erase block size has also failed (see below)
- Attempts to use
echo >
andcat
to themtdblock
have only produced garbage
Original
I am attempting to read and write to a SRAM chip connected to a ARM processor running Linux. I do not care if i interface with the SRAM like a file, serial device or memory partition. The existing device driver for the SRAM chip registers the device as a MTD. I verified this by checking /proc/mtd
:
~# cat /proc/mtd
dev: size erasesize name
mtd0: 00020000 00000000 "spi1.0"
I found a tutorial to format the MTD using MTD utils. The problem I am experiencing is that I cannot interface with the SRAM/MTD device because all the user-space MTD/UBI/JFF2 tools crash when looking at this device, IE:
~# mtdinfo
Count of MTD devices: 1
Floating point exception (core dumped)
This exception appears to be occurring because all the MTD utilities use libmtd. The mtd_get_dev_info1
function in libmtd divides by the erase block size and in my case the erase block size is zero.
mtd->eb_cnt = mtd->size / mtd->eb_size;
Even though this chip has a MTD driver, i do not think write cycles are a concern and that is why the erase block is zero. so my questions are the following:
- Should i modify the driver to give the chip an erase block size so the utilities work correctly? If so what size?
- Should i modify
libmtd
to ignore the zero erase block size? If so what should i set theeb_cnt
to? - Is there a better way to read and write data to the MTD device?
Additional Notes:
- Stability is more important than optimal performance in my situation
- I tried to do an
echo test > /dev/mtdblock0
andcat /dev/mtdblock0
and got nothing but garbage
Update 10/20 Changed the erase block size to 1 in the driver (I desired to change it to 4000, but i was unsure about units). MTD Utils no longer throws the exception given before.
~# mtdinfo
Count of MTD devices: 1
Present MTD devices: mtd0
Sysfs interface supported: yes
However ubiformat does fail:
~# ubiformat /dev/mtd0
ubiformat: mtd0 (ram), size 131072 bytes (128.0 KiB), 131072 eraseblocks of
1 bytes, min. I/O size 1 bytes
libscan: scanning eraseblock 0 -- 0 % complete libmtd: error!: bad offset
0 or length 64, mtd0 eraseblock size is 1
ubiformat: error!: failed to scan mtd0 (/dev/mtd0)
Update #2 10/20 Unfortunately setting the erase block size to 4000 (actually 0x4000) cause the kernel to crash after running ubiformat
~# ubiformat /dev/mtd0
ubiformat: mtd0 (ram), size 131072 bytes (128.0 KiB), 8 eraseblocks of 16384
bytes (16.0 KiB), min. I/O size 1 bytes
libscan: scanning erasebUnable to handle kernel NULL pointer dereference at
virtual address 00000000
libscanpgd = 8cc6c000te
libscan: scanning eras[00000000] *pgd=8cbbb835, *pte=00000000, *ppte=00000000
libscan: scanning eInternal error: Oops: 80000007 [#1] PREEMPT SMP ARM
Update 10/23 I tried to format the drive normally with fdisk, but seem to be getting errors regarding the lack of cylinders:
:~# fdisk /dev/mtdblock0
...
Command (m for help): p
Disk /dev/mtdblock0: 0 MB, 131072 bytes
255 heads, 63 sectors/track, 0 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Unknown value(s) for: cylinders (settable in the extra functions menu)