forked from Imagelibrary/rtems
2007-11-29 Till Straumann <strauman@slac.stanford.edu>
* shared/flash/flash.c, shared/flash/flashPgm.h: added calls to obtain info about flash bank start, size and block size.
This commit is contained in:
@@ -104,6 +104,9 @@ BSP_flashProbeSize(struct bankdesc *b);
|
||||
STATIC struct bankdesc *
|
||||
bankValidate(int bank, int quiet);
|
||||
|
||||
static struct bankdesc *
|
||||
argcheck(int bank, uint32_t offset, char *src, uint32_t size);
|
||||
|
||||
/* Type definitions */
|
||||
|
||||
union bconv {
|
||||
@@ -407,10 +410,39 @@ unsigned q;
|
||||
for ( rval = 0, q=1; rval < max && (dd = BSP_flashCheckId(b, b->start + max - SCAN_BACK_OFFSET - rval, q)); q=3 ) {
|
||||
rval += dd->size * FLASH_NDEVS(b);
|
||||
}
|
||||
b->start += max - rval;
|
||||
}
|
||||
return rval;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
BSP_flashStart(int bank)
|
||||
{
|
||||
struct bankdesc *b;
|
||||
if ( ! ( b = argcheck(bank, 0, 0, 0) ) )
|
||||
return -1;
|
||||
return b->start;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
BSP_flashSize(int bank)
|
||||
{
|
||||
struct bankdesc *b;
|
||||
if ( ! ( b = argcheck(bank, 0, 0, 0) ) )
|
||||
return -1;
|
||||
return b->size;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
BSP_flashBlockSize(int bank)
|
||||
{
|
||||
struct bankdesc *b;
|
||||
if ( ! ( b = argcheck(bank, 0, 0, 0) ) )
|
||||
return -1;
|
||||
return b->fblksz;
|
||||
}
|
||||
|
||||
|
||||
#ifndef TESTING
|
||||
|
||||
/* Obtain bank description making sure it is initialized and not write protected */
|
||||
@@ -446,7 +478,7 @@ struct bankdesc *b = BSP_flashBspOps.bankcheck(bank, quiet);
|
||||
*/
|
||||
|
||||
static struct bankdesc *
|
||||
argcheck(uint32_t bank, uint32_t offset, char *src, uint32_t size)
|
||||
argcheck(int bank, uint32_t offset, char *src, uint32_t size)
|
||||
{
|
||||
struct bankdesc *b;
|
||||
|
||||
@@ -639,7 +671,7 @@ bail:
|
||||
}
|
||||
|
||||
int
|
||||
BSP_flashErase(uint32_t bank, uint32_t offset, uint32_t size, int quiet)
|
||||
BSP_flashErase(int bank, uint32_t offset, uint32_t size, int quiet)
|
||||
{
|
||||
struct bankdesc *b;
|
||||
uint32_t a,i;
|
||||
@@ -660,7 +692,7 @@ int f;
|
||||
a = b->start + offset;
|
||||
|
||||
if ( !quiet ) {
|
||||
printf("ERASING Flash (Bank #%"PRIu32")\n from 0x%08"PRIx32" .. 0x%08"PRIx32"\nproceed y/[n]?",
|
||||
printf("ERASING Flash (Bank #%i)\n from 0x%08"PRIx32" .. 0x%08"PRIx32"\nproceed y/[n]?",
|
||||
bank, a, (a+size-1));
|
||||
fflush(stdout);
|
||||
if ( 'Y' != getUc() ) {
|
||||
|
||||
@@ -70,12 +70,13 @@ BSP_flashWriteDisable(int bank);
|
||||
* NOTES: - 'offset' and 'size' must be block-aligned. Common 16-bit devices
|
||||
* have a block size of 0x20000 bytes. If two such devices are
|
||||
* operated in parallel to form a 32-bit word then the 'effective'
|
||||
* block size is 0x40000 bytes.
|
||||
* block size is 0x40000 bytes. The block size can be queried by
|
||||
* BSP_flashBlockSize(int bank);
|
||||
*
|
||||
* - erase operation is verified.
|
||||
*/
|
||||
int
|
||||
BSP_flashErase(uint32_t bank, uint32_t offset, uint32_t size, int quiet);
|
||||
BSP_flashErase(int bank, uint32_t offset, uint32_t size, int quiet);
|
||||
|
||||
/* Write data from a buffer to flash. The target area is erased if necessary.
|
||||
*
|
||||
@@ -133,6 +134,30 @@ BSP_flashWriteFile(int bank, uint32_t offset, char *path, int quiet);
|
||||
int
|
||||
BSP_flashDumpInfo(FILE *f);
|
||||
|
||||
/*
|
||||
* Obtain starting-address of flash bank (as seen from CPU)
|
||||
* (returns ((uint32_t) -1) if the bank argument is invalid).
|
||||
*/
|
||||
|
||||
uint32_t
|
||||
BSP_flashStart(int bank);
|
||||
|
||||
/*
|
||||
* Obtain size of flash bank (returns ((uint32_t) -1) if the
|
||||
* bank argument is invalid).
|
||||
*/
|
||||
uint32_t
|
||||
BSP_flashSize(int bank);
|
||||
|
||||
/*
|
||||
* Obtain block size of flash bank (sector size times
|
||||
* number of devices in parallel; the block size determines
|
||||
* alignment and granularity accepted by BSP_flashErase()
|
||||
* (returns ((uint32_t) -1) if the bank argument is invalid).
|
||||
*/
|
||||
uint32_t
|
||||
BSP_flashBlockSize(int bank);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user