Thread (44 messages) 44 messages, 12 authors, 2009-11-01

RE: Accessing flash directly from User Space

From: Jonathan Haws <hidden>
Date: 2009-10-27 22:35:41

quoted
Okay, I now have access to the flash memory, however when I write
to it the writes do not take.  I have tried calling msync() on the
mapping to no avail.  I have opened the fd with O_SYNC, but cannot
get things to work right.
quoted
Here are the calls:

	int fd =3D open("/dev/mem", O_SYNC | O_RDWR);
	uint16_t * flash =3D (uint16_t *)mmap(NULL, NOR_FLASH_SIZE,
			(PROT_READ | PROT_WRITE), MAP_PRIVATE, fd,
			NOR_FLASH_BASE_ADRS);

When I do flash[0] =3D 0x1234, and then check the value, they do not
match.
quoted
	flash[0] =3D 0x1234;
	msync(flash, NOR_FLASH_SIZE, MS_SYNC | MS_INVALIDATE);
	printf("flash[0] =3D %#04x\n", flash[0]);

That prints flash[0] =3D 0x7f45.  I have verified that I am reading
the correct values.  I can display the flash contents in U-Boot and
7f45 is what is in the first 16 bits of flash.
quoted
Why can I not write to flash?  What am I doing wrong?
=20
Flash does not work that way -- you must send it commands to erase a
block, and then further commands to program new data.
I realize that.  I have a driver written that does exactly that.  However, =
I need to be able to write to certain registers to setup the erasure.  The =
driver works perfectly in VxWorks, now I am porting it to Linux.
It sounds like what you really want is the /dev/mtd or /dev/mtdblock
interface, not raw access to the flash chip.
As mentioned in my initial post, I need to use my custom driver to maintain=
 the interface to the application that uses the flash for data storage.

I had thought about using MTD, but decided against it because with previous=
 benchmarking that we did with MTD and our custom driver, we found that our=
 custom driver was about 10x faster.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help