From: Kenneth Johansson <kenneth@southpole.se>
To: Joakim Tjernlund <joakim.tjernlund@transmode.se>
Cc: Bill Gatliff <bgat@billgatliff.com>,
"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>,
Jonathan Haws <Jonathan.Haws@sdl.usu.edu>
Subject: RE: Accessing flash directly from User Space [SOLVED]
Date: Thu, 29 Oct 2009 12:08:56 +0100 [thread overview]
Message-ID: <1256814536.24490.36.camel@kenjo-laptop> (raw)
In-Reply-To: <OFE3AA516D.46A96178-ONC125765E.0030DA7C-C125765E.00317B8C@transmode.se>
On Thu, 2009-10-29 at 10:00 +0100, Joakim Tjernlund wrote:
> >
> > > > On Tue, Oct 27, 2009 at 04:24:53PM -0600, Jonathan Haws wrote:
> > > > >> >>> 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);
> > > >
> > > > What board and CPU are you using? Is your flash really at
> > > > 0xFC800000, or is
> > > > that the virtual address that VxWorks puts it at?
> > >
> > > I am using a custom board based on the AMCC Kilauea development
> > > board. It uses a 405EX CPU. Yes, the flash is really at
> > > 0xFC000000.
> >
> > I have found the problem. It occurred to me in the shower (okay not really,
> > but most good ideas happen there).
> >
> > What was happening is that I was in fact able to write to the correct
> > registers. However, I would try and write to them in a batch. But the way
> > mmap works (at least according to the man page) with MAP_SHARED is that the
> > file may not be updated until msync() is called. Now, I thought that O_SYNC
> > would take care of that when I open /dev/mem, but that was not the case.
> >
> > Anyway, to make a long story short, I inserted an msync() after each
> > assignment to the flash. This resolved my problem and I can now program my flash.
>
> Ouch, this was news to me too. Calling msync() after every write kills performance.
> We use mmap(/dev/mem) to access HW and havn't seen any issues yet. Is this
> perhaps a new behaviour for mmap(/dev/mem) and is there a way
> to avoid calling msync()?
The address range should be outside the dram and thus uncached. Any
write to any address in the range mmaped should go directly to the NOR
flash. Any other behavior is a bug. It's not mapping an actual file
here.
next prev parent reply other threads:[~2009-10-29 11:09 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-27 19:59 Accessing flash directly from User Space Jonathan Haws
2009-10-27 20:13 ` Bill Gatliff
2009-10-27 20:15 ` Jonathan Haws
2009-10-27 20:30 ` Bill Gatliff
2009-10-27 20:31 ` Jonathan Haws
2009-10-27 22:24 ` Jonathan Haws
2009-10-27 22:32 ` Scott Wood
2009-10-27 22:35 ` Jonathan Haws
2009-10-27 22:42 ` Scott Wood
2009-10-27 22:52 ` Jonathan Haws
2009-10-28 9:56 ` Kenneth Johansson
2009-10-28 14:45 ` Jonathan Haws
2009-10-29 21:36 ` Joerg Albert
2009-10-29 21:39 ` Jonathan Haws
2009-10-29 16:33 ` Scott Wood
2009-10-29 16:48 ` Jonathan Haws
[not found] ` <BB99A6BA28709744BF22A68E6D7EB51F0330D368AA@midas.usurf.usu.edu >
2009-10-27 22:42 ` Alessandro Rubini
2009-10-28 11:24 ` Josh Boyer
2009-10-28 14:38 ` Jonathan Haws
2009-10-28 17:44 ` Accessing flash directly from User Space [SOLVED] Jonathan Haws
2009-10-29 9:00 ` Joakim Tjernlund
2009-10-29 9:15 ` Joakim Tjernlund
2009-10-29 17:01 ` Jonathan Haws
2009-10-29 11:08 ` Kenneth Johansson [this message]
2009-10-29 17:02 ` Jonathan Haws
2009-10-29 23:30 ` Scott Wood
2009-10-30 14:50 ` Jonathan Haws
2009-10-30 14:56 ` Michael Buesch
2009-10-30 14:57 ` Jonathan Haws
[not found] ` <BB99A6BA28709744BF22A68E6D7EB51F0330E23124@midas.usurf.usu.edu >
2009-10-30 15:08 ` Alessandro Rubini
2009-10-30 15:24 ` Michael Buesch
2009-10-30 15:33 ` Jonathan Haws
2009-10-31 13:26 ` Joakim Tjernlund
2009-10-31 16:42 ` Michael Buesch
2009-10-31 20:14 ` Joakim Tjernlund
2009-10-31 20:35 ` Michael Buesch
2009-10-31 22:31 ` Joakim Tjernlund
2009-11-01 10:07 ` Segher Boessenkool
2009-10-30 15:48 ` Micha Nelissen
2009-10-30 16:46 ` Jonathan Haws
2009-10-30 17:49 ` Gabriel Paubert
2009-10-30 15:57 ` Scott Wood
[not found] ` <BB99A6BA28709744BF22A68E6D7EB51F0330D3688B@midas.usurf.usu.edu >
2009-10-27 22:32 ` Accessing flash directly from User Space Alessandro Rubini
2009-10-27 22:33 ` Jonathan Haws
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1256814536.24490.36.camel@kenjo-laptop \
--to=kenneth@southpole.se \
--cc=Jonathan.Haws@sdl.usu.edu \
--cc=bgat@billgatliff.com \
--cc=joakim.tjernlund@transmode.se \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox