Accessing flash directly from User Space

Jonathan Haws Jonathan.Haws at sdl.usu.edu
Wed Oct 28 09:24:53 EST 2009


> >>> How can I get that pointer?  Unfortunately I cannot simply use
> the
> >>>
> >> address of the flash.  Is there some magical function call that
> >> gives me access to that portion of the memory space?
> >>
> >> $ man 2 mmap
> >>
> >> You want MAP_SHARED and O_SYNC.
> >>
> >
> >
> > To use that I need to have a file descriptor to a device, do I
> not?  However, I do not have a base flash driver to give me that
> file descriptor.  Am I missing something with that call?
> >
> 
> /dev/mem
> 
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,
			(PROT_READ | PROT_WRITE), MAP_PRIVATE, fd,
			NOR_FLASH_BASE_ADRS);

When I do flash[0] = 0x1234, and then check the value, they do not match.

	flash[0] = 0x1234;
	msync(flash, NOR_FLASH_SIZE, MS_SYNC | MS_INVALIDATE);
	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?

Thanks!

Jonathan





More information about the Linuxppc-dev mailing list