[PATCH 08/12] cfi flash: fix flash_make_cmd for big endian access
Teresa Gamez
T.Gamez at phytec.de
Fri Sep 23 10:05:29 EDT 2011
Hello Sascha,
Am Freitag, den 23.09.2011, 11:26 +0200 schrieb Sascha Hauer:
> Hi Teresa,
>
> On Fri, Sep 23, 2011 at 11:24:16AM +0200, Sascha Hauer wrote:
> > This is broken on big endian systems since:
> >
> > 943b271 cfi_flash: support of u32 cmd
> >
> > I looked over it and I *think* that the function was correct
> > for both big and little endian systems before this patch.
> > To support u32 cmd we only have to change the data type of
> > the command from u8 to u32.
>
> Can you please test if this patch works on your u8-is-not-enough
> flash?
Successfully tested with a u8-is-not-enough flash (28F256P33BF) on a
phyCORE-i.MX35.
Teresa
>
> Sascha
>
> >
> > Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
> > Cc: Teresa Gámez <t.gamez at phytec.de>
> > ---
> > drivers/nor/cfi_flash.c | 24 +++++-------------------
> > 1 files changed, 5 insertions(+), 19 deletions(-)
> >
> > diff --git a/drivers/nor/cfi_flash.c b/drivers/nor/cfi_flash.c
> > index f9b96c5..654e647 100644
> > --- a/drivers/nor/cfi_flash.c
> > +++ b/drivers/nor/cfi_flash.c
> > @@ -822,26 +822,12 @@ int flash_generic_status_check (struct flash_info *info, flash_sect_t sector,
> > */
> > void flash_make_cmd(struct flash_info *info, u32 cmd, cfiword_t *cmdbuf)
> > {
> > - int i;
> > - int cp_offset;
> > - int cword_offset;
> > - uchar val;
> > - uchar *cp;
> > -
> > - *cmdbuf = 0;
> > - cp = (uchar *)cmdbuf;
> > + cfiword_t result = 0;
> > + int i = info->portwidth / info->chipwidth;
> >
> > - for (i = info->portwidth; i > 0; i--) {
> > - cword_offset = (info->portwidth-i) % info->chipwidth;
> > -#if __BYTE_ORDER == __LITTLE_ENDIAN
> > - cp_offset = info->portwidth - i;
> > - val = *((uchar *)&cmd + cword_offset);
> > -#else
> > - cp_offset = i - 1;
> > - val = *((uchar *)&cmd + sizeof(u32) - cword_offset - 1);
> > -#endif
> > - cp[cp_offset] = (cword_offset >= sizeof(u32)) ? 0x00 : val;
> > - }
> > + while (i--)
> > + result = (result << (8 * info->chipwidth)) | cmd;
> > + *cmdbuf = result;
> > }
> >
> > /*
> > --
> > 1.7.6.3
> >
> >
>
More information about the barebox
mailing list