Subject: Re: How do I access nvRAM from user space?

From: David Hawkins <[email-masked]>
Date: Thu, 25 Sep 2008 11:14:10 -0700

Hi Bruce,

> Thanks for the reply.  So if my nvSRAM device is located at 0xb0000000 in 
> physical memory, what would the mmap() call look like?  Also, do I need to 
> have a device tree entry for the kernel to know about the memory?  I can 
> access the device in uboot so I know it works, but I can't figure out the 
> mmap to get it from linux

Its pretty much:

	/* Open /dev/mem and map it */
	printf(" * open /dev/mem\n");
	fd = open("/dev/mem", O_RDWR | O_SYNC);
	if (fd < 0) {
		printf("Open /dev/mem failed - %s\n",
			strerror(errno));
		return -1;
	}
	printf(" * map %d page(s) (%d-bytes) at address 0x%.8X\n",
			mem_pages, mem_size, mem_phys);
	mem_addr = (char *)mmap(
		0,
		mem_size,
		PROT_READ|PROT_WRITE,
		MAP_SHARED,
		fd,
		mem_phys);
	if (mem_addr == (char *)MAP_FAILED) {
		printf("Error: mmap failed\n");
		close(fd);
		return -1;
	}

I'll send you the code I ripped that from, and another
example from the Busybox code.

Cheers,
Dave