Skip to content

Commit

Permalink
Corrected new flash driver
Browse files Browse the repository at this point in the history
  • Loading branch information
mahi committed Jan 2, 2012
1 parent c5c3cb9 commit f290a9b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 137 deletions.
56 changes: 39 additions & 17 deletions arch/ppc/mpc55xx/drivers/Fls.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ typedef enum {

typedef struct {
uint32_t dest;
uint32_t size;
// uint32_t size;
uint32_t source;
uint32_t left;

uint32_t pDest;
uint32_t pLeft;
} Fls_ProgInfoType;


Expand All @@ -191,8 +194,8 @@ typedef struct {
MemIf_StatusType status;
MemIf_JobResultType jobResultType;
Fls_Arc_JobType jobType;
Fls_AddressType sourceAddr;
uint8 * targetAddr;
Fls_AddressType flashAddr; //sourceAddr
uint8 * ramAddr; // targetAddr
Fls_LengthType length;
Fls_ProgInfoType flashWriteInfo;
bool mustCheck;
Expand Down Expand Up @@ -372,7 +375,8 @@ Std_ReturnType Fls_Erase(Fls_AddressType TargetAddress, Fls_LengthType Length) {
Fls_Global.status = MEMIF_BUSY; /** @req FLS219 3.0 */ /** @req FLS328 4.0 */
Fls_Global.jobResultType = MEMIF_JOB_PENDING; /** @req FLS329 4.0 */
Fls_Global.jobType = FLS_JOB_ERASE;
Fls_Global.targetAddr = TargetAddress;
Fls_Global.flashAddr = TargetAddress;
Fls_Global.length = Length;

/* Unlock */
Flash_Lock(Fls_Global.config->FlsInfo,FLASH_OP_UNLOCK,TargetAddress, Length );
Expand Down Expand Up @@ -428,11 +432,16 @@ Std_ReturnType Fls_Write(Fls_AddressType TargetAddress,
Fls_Global.flashWriteInfo.dest = TargetAddress;
Fls_Global.flashWriteInfo.left = Length;

// unlock flash....

// unlock flash for the entire range.
Flash_Lock(Fls_Global.config->FlsInfo,FLASH_OP_UNLOCK, TargetAddress, Length );
// Program
/** @req FLS146 3.0/4.0 */
Flash_ProgramPageStart( Fls_Global.config->FlsInfo,

/* Save to original request */
Fls_Global.flashWriteInfo.pDest = TargetAddress;
Fls_Global.flashWriteInfo.pLeft = Length;

/** @req FLS146 3.0/4.0 */
Flash_ProgramPageStart( Fls_Global.config->FlsInfo,
&Fls_Global.flashWriteInfo.dest,
&Fls_Global.flashWriteInfo.source,
&Fls_Global.flashWriteInfo.left,
Expand Down Expand Up @@ -501,8 +510,8 @@ void Fls_MainFunction(void) {
// ( we are reading directly from flash so it makes no sense )

/** @req FLS244 */
result = memcmp(Fls_Global.targetAddr,
(void *) Fls_Global.sourceAddr, Fls_Global.length);
result = memcmp((void *)Fls_Global.ramAddr,
(void *)Fls_Global.flashAddr, Fls_Global.length);
if (result == 0) {
Fls_Global.jobResultType = MEMIF_JOB_OK;
} else {
Expand All @@ -514,7 +523,7 @@ void Fls_MainFunction(void) {
break;
case FLS_JOB_ERASE: {

flashStatus = Flash_CheckStatus(Fls_Global.config->FlsInfo, Fls_Global.targetAddr);
flashStatus = Flash_CheckStatus(Fls_Global.config->FlsInfo, (uint32 *)Fls_Global.flashAddr, Fls_Global.length );

if (flashStatus == EE_OK ) {
Fls_Global.jobResultType = MEMIF_JOB_OK;
Expand All @@ -535,7 +544,7 @@ void Fls_MainFunction(void) {

// NOT implemented. Hardware error = FLS_E_READ_FAILED
// ( we are reading directly from flash so it makes no sense )
memcpy(Fls_Global.targetAddr, (void *) Fls_Global.sourceAddr,
memcpy( (void *)Fls_Global.ramAddr, (void *) Fls_Global.flashAddr,
Fls_Global.length);
Fls_Global.jobResultType = MEMIF_JOB_OK;
Fls_Global.status = MEMIF_IDLE;
Expand All @@ -547,7 +556,9 @@ void Fls_MainFunction(void) {
{

do {
flashStatus = Flash_CheckStatus(Fls_Global.config->FlsInfo, &Fls_Global.flashWriteInfo.dest);
flashStatus = Flash_CheckStatus(Fls_Global.config->FlsInfo,
(uint32_t *)Fls_Global.flashWriteInfo.pDest,
Fls_Global.flashWriteInfo.left -Fls_Global.flashWriteInfo.pLeft);

if (flashStatus == EE_OK ) {

Expand All @@ -560,6 +571,8 @@ void Fls_MainFunction(void) {
FEE_JOB_END_NOTIFICATION();
break;
}
Fls_Global.flashWriteInfo.pDest = Fls_Global.flashWriteInfo.dest;
Fls_Global.flashWriteInfo.pLeft = Fls_Global.flashWriteInfo.left;

flashStatus = Flash_ProgramPageStart(Fls_Global.config->FlsInfo,
&Fls_Global.flashWriteInfo.dest,
Expand Down Expand Up @@ -594,6 +607,15 @@ void Fls_MainFunction(void) {
} /* if */
}


/**
* Read from flash memory
*
* @param SourceAddress
* @param TargetAddressPtr
* @param Length
* @return
*/
Std_ReturnType Fls_Read( Fls_AddressType SourceAddress,
uint8 *TargetAddressPtr,
Fls_LengthType Length)
Expand Down Expand Up @@ -624,8 +646,8 @@ Std_ReturnType Fls_Read( Fls_AddressType SourceAddress,
Fls_Global.jobType = FLS_JOB_READ;

/** @req FLS237 */
Fls_Global.sourceAddr = SourceAddress;
Fls_Global.targetAddr = TargetAddressPtr;
Fls_Global.flashAddr = SourceAddress;
Fls_Global.ramAddr = TargetAddressPtr;
Fls_Global.length = Length;

return E_OK;
Expand Down Expand Up @@ -662,8 +684,8 @@ Std_ReturnType Fls_Compare( Fls_AddressType SourceAddress,
Fls_Global.jobResultType = MEMIF_JOB_PENDING;
Fls_Global.jobType = FLS_JOB_COMPARE;
/* @req FLS242 */
Fls_Global.sourceAddr = SourceAddress;
Fls_Global.targetAddr = TargetAddressPtr;
Fls_Global.flashAddr = SourceAddress;
Fls_Global.ramAddr = TargetAddressPtr;
Fls_Global.length = Length;

return E_OK;
Expand Down
2 changes: 1 addition & 1 deletion arch/ppc/mpc55xx/drivers/flash.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ uint32_t Flash_Lock(const struct Flash *fPtr, uint32_t op, uintptr_t from, uint3
uint32_t Flash_Erase(const struct Flash *fPtr, uintptr_t dest, uint32_t size, flashCbType sb);
//uint32_t Flash_Program(const struct Flash *fPtr, uintptr_t to, uintptr_t from,uint32_t size, flashCbType sb);
uint32_t Flash_ProgramPageStart(const struct Flash *fPtr, uint32_t *to, uint32_t *from,uint32_t *size, flashCbType sb);
uint32_t Flash_CheckStatus( const struct Flash *fPtr );
uint32_t Flash_CheckStatus( const struct Flash *fPtr, uint32_t *to, uint32_t size );
uint32_t Flash_SectorAligned( const struct Flash *fPtr, uintptr_t addr );

#endif /* FLASH_H_ */
107 changes: 35 additions & 72 deletions arch/ppc/mpc55xx/drivers/flash_h7f_c90.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ uint32_t Flash_Erase( const FlashType *fPtr, uintptr_t dest, uint32_t size, flas
return EE_ERROR_PE_OPT;
}

#if 0
/* Poll status */
while ((rv = FSL_FlashCheckStatus(bPtr->regBase)) != EE_OK) {

Expand All @@ -203,82 +204,18 @@ uint32_t Flash_Erase( const FlashType *fPtr, uintptr_t dest, uint32_t size, flas
if( cb != NULL ) {
cb();
}

}
}
return EE_OK;
}


#if 0
/**
*
* @param to
* @param from
* @param size
* @return
*/
uint32_t Flash_ProgramStart( const FlashType *fPtr, uint32_t *to, uint32_t * from, uint32_t * size, flashCbType cb) {
uint32_t rv;
uint16_t fSize = size;
uint32_t fDest = (uint32_t) to;
uint32_t fSource = (uint32_t) from;
uint32_t flashBlocks[ADDR_SPACE_CNT];
uint32_t maxToProg;
const FlashType *bPtr;
bool affected;


/* Check double word alignment */
ASSERT((size % 8) == 0 );

/* FSL functions are for each bank, so loop over banks */
for (int bank = 0; bank < FLASH_BANK_CNT; bank++) {
bPtr = &fPtr[bank];

affected = getAffectedBlocks(bPtr, to, size, &flashBlocks);
if( affected == false ) {
/* This bank was not affected */
continue;
}

/* Program to the end of bank */
maxToProg = MIN(fSize, (bPtr->sectAddr[0] + bPtr->bankSize - fDest));
fSize -= maxToProg;

while(maxToProg) {
/* Program page */
rv = FSL_FlashProgramStart(bPtr->regBase, &fDest, &maxToProg, &fSource);

if (rv != EE_OK) {
return EE_ERROR_PE_OPT;
}

#if 0
/* Poll status */
while ((rv = FSL_FlashCheckStatus(bPtr->regBase)) != EE_OK) {

if (rv == EE_ERROR_PE_OPT) {
return rv;
}

if( cb != NULL ) {
cb();
}
}
#endif
}
}
return EE_OK;
}
#endif


/**
*
* @param to
* @param from
* @param size
* @param to Flash address to write. Updated to next address to write for each call
* @param from RAM address to read from. Updated with next address to read from for each call
* @param size The size to program. Updated for each for each call.
* @return
*/
uint32_t Flash_ProgramPageStart( const FlashType *fPtr, uint32_t *to, uint32_t * from, uint32_t * size, flashCbType cb) {
Expand Down Expand Up @@ -306,24 +243,50 @@ uint32_t Flash_ProgramPageStart( const FlashType *fPtr, uint32_t *to, uint32_t *
return EE_OK;
}

uint32_t Flash_CheckStatus( const FlashType *fPtr, uint32_t *to ) {
uint32_t flashBlocks[ADDR_SPACE_CNT];
/**
* Check status of programming/erase
*
* @param fPtr
* @param to
* @return
*/
uint32_t Flash_CheckStatus( const FlashType *fPtr, uint32_t *to, uint32_t size ) {
const FlashType *bPtr;
bool affected;
uint32_t rv = E_NOT_OK;
uintptr_t flAddr = (uintptr_t)to;

for (int bank = 0; bank < FLASH_BANK_CNT; bank++) {
bPtr = &fPtr[bank];

affected = getAffectedBlocks(bPtr, *to, 1, &flashBlocks);
/* We only need to figure out what bank is used, note that multiple banks
* must be handled at the same time here */
affected = OVERLAP(flAddr,flAddr+size,bPtr->sectAddr[0],bPtr->bankSize);
if( affected == false ) {
/* This bank was not affected */
continue;
}

return FSL_FlashCheckStatus(bPtr->regBase);
rv = FSL_FlashCheckStatus(bPtr->regBase);
if( rv != EE_OK) {
return rv;
}
}
}

return rv;
}
#if 0
for (int sector = 0; sector < bPtr->sectCnt; sector++)
{
if (OVERLAP( addr,addr+size-1,
bPtr->sectAddr[sector],bPtr->sectAddr[sector+1]-1))
{
addrSpace = bPtr->addrSpace[sector];
(*fb)[ADDR_SPACE_GET(addrSpace)] |= (1 << ADDR_SPACE_GET_SECTOR(addrSpace));
anyAffected = true;
}
}
#endif



47 changes: 0 additions & 47 deletions include/flash.h

This file was deleted.

0 comments on commit f290a9b

Please sign in to comment.