Accessing flash directly from User Space

Scott Wood scottwood at
Wed Oct 28 09:32:13 EST 2009

Jonathan Haws wrote:
> 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.
> Here are the calls:
> 	int fd = open("/dev/mem", O_SYNC | O_RDWR);
> 	uint16_t * flash = (uint16_t *)mmap(NULL, NOR_FLASH_SIZE,
> When I do flash[0] = 0x1234, and then check the value, they do not match.
> 	flash[0] = 0x1234;
> 	printf("flash[0] = %#04x\n", flash[0]);
> That prints flash[0] = 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.
> Why can I not write to flash?  What am I doing wrong?

Flash does not work that way -- you must send it commands to erase a 
block, and then further commands to program new data.

It sounds like what you really want is the /dev/mtd or /dev/mtdblock 
interface, not raw access to the flash chip.


More information about the Linuxppc-dev mailing list