Re: [uCsimm] Flash programming

From: David Beckemeyer (david@bdt.com)
Date: Tue May 08 2001 - 11:35:58 EDT


On Tue, May 08, 2001 at 03:34:54PM +0200, Uwe Beutin wrote:
>
> which value should I give the *flashptr in the function
> flash_write_range() to save data for an application? Or is there any
> other way to store an array in the form char array[n][m] for power off?
>
> Can I use the area 0x10E00000-offset for this? Are there any examples in
> source code to achieve this? I'm having a hard time with this.

The following sample would write a block of memory passed as
an argument to a fixed address in the flash FLASH_ADDR. You have
to make sure FLASH_ADDR is available.

Hope this helps.

----------------------------------------------------------------

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <bootstd.h>
#include <flash.h>

/* start/end addresses of the flash chip */
#define FLASH_DEVICE 0x10c00000
#define FLASH_END 0x10e00000

/* address of the saved data block */
#define FLASH_ADDR 0x10dc0000

void *chain[512];

flash_write_block (unsigned char *dataptr, int count)
{
  int fd;
  int n, start, end;
  int b;
  mnode_t m;

  b = 0;
  n = 0;
  while (n < count)
    {
      chain[b++] = dataptr;
      dataptr += 4096;
      n += 4096;
    }
  if (FLASH_ADDR + count > FLASH_END)
    {
      fprintf (stderr, "data block too big, exceeds %d bytes\n",
               FLASH_END - FLASH_ADDR);
      return (-1);
    }

  start = FLASH_ADDR - FLASH_DEVICE;
  n = b * 4096 - 1;
  end = start + n;

  printf ("Writing block: start=%lx end=%lx\n", start, end);

  n = flash_erase_range ((unsigned short *) FLASH_DEVICE, start, end);

  printf ("Flash erase returned: %d\n", n);
  if (n < 0)
    return (-1);

  m.len = count;
  m.offset = (void *) chain;

  n = flash_write_range ((unsigned short *) FLASH_DEVICE, &m, start);

  printf ("Flash write returned: %d\n", n);

  return (0);
}
This message resent by the ucsimm@uclinux.com list server http://www.uClinux.com/



This archive was generated by hypermail 2b30 : Sun Apr 07 2002 - 00:01:43 EST