BOOL __section(SectionForFlashOperations) SAM7X_BS_Driver::IsBlockErased( void* context, ByteAddress Address, UINT32 BlockLength ) { MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context; const BlockDeviceInfo * deviceInfo = config->BlockConfig.BlockDeviceInformation; UINT32 iRegion, iRange; CHIP_WORD *chipAddress, *endAddress; // 1st or 2nd FLASH controller if (!deviceInfo->FindRegionFromAddress( Address, iRegion, iRange )) return FALSE; Address = CPU_GetCachableAddress(Address); chipAddress = (CHIP_WORD *) Address; endAddress = (CHIP_WORD *)(Address + BlockLength); while(chipAddress < endAddress) { if(*chipAddress++ != 0xFFFFFFFF) { return FALSE; } } return TRUE; }
CryptoState::CryptoState( UINT32 dataAddress, UINT32 dataLength, BYTE* sig, UINT32 sigLength, UINT32 sectorType ) : #if defined(ARM_V1_2) m_dataAddress( CPU_GetCachableAddress( dataAddress ) ), #else m_dataAddress( dataAddress ), #endif m_dataLength ( dataLength ), m_sig ( sig ), m_sigLength ( sigLength ), m_sectorType ( sectorType ), m_handle ( NULL ), m_res ( CRYPTO_FAILURE ) { }
// erase one page BOOL __section(SectionForFlashOperations) SAM7X_BS_Driver::EraseBlock( void* context, ByteAddress address ) { MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context; const BlockDeviceInfo * deviceInfo = config->BlockConfig.BlockDeviceInformation; UINT32 iRegion, iRange; UINT32 pageNumber=0, baseAddress; // 1st or 2nd FLASH controller if (!deviceInfo->FindRegionFromAddress( address, iRegion, iRange )) return FALSE; address = CPU_GetUncachableAddress(address); baseAddress = CPU_GetCachableAddress(deviceInfo->Regions[iRegion].Start); // the pageNumber is the start of page of "Sector", even Sector is not the start sectoraddres of the block pageNumber = ((address - baseAddress) / AT91C_IFLASH_PAGE_SIZE); AT91_BL_EFC &efc = AT91_BL_EFC::BL_EFC(( pageNumber < 1024 ) ? 0:1); ChipReadOnly( context, FALSE, FLASH_PROTECTION_KEY ); // Set EFC Mode Register - number of cycles during 1.5 microsecond efc.EFC_FMR = (efc.EFC_FMR & ~(AT91_BL_EFC::MC_FMCN | AT91_BL_EFC::MC_NEBP)) | (((SYSTEM_CYCLE_CLOCK_HZ / 2000000) * 3) << 16); pageNumber = pageNumber % 1024; { GLOBAL_LOCK(irq); // Erase Block (write 0xFFFFFFFF) // perform write/erase command for (UINT32 i=0; i<AT91C_IFLASH_PAGE_PER_BLOCK; i++) { efc.EFC_FCR = (AT91_BL_EFC::MC_KEY_VALUE | (pageNumber << 8) | AT91_BL_EFC::MC_FCMD_START_PROG); // wait for FLASH ready while( (efc.EFC_FSR & AT91_BL_EFC::MC_FRDY) != AT91_BL_EFC::MC_FRDY ); pageNumber ++; } } ChipReadOnly( context, TRUE, FLASH_PROTECTION_KEY ); return TRUE; }
I28F_16_BS_Driver::CHIP_WORD __section("SectionForFlashOperations") I28F_16_BS_Driver::Action_WriteWord( volatile CHIP_WORD * Sector, CHIP_WORD Data, MEMORY_MAPPED_NOR_BLOCK_CONFIG* FlashConfig ) { NATIVE_PROFILE_HAL_DRIVERS_FLASH(); CHIP_WORD StatusRegister; /////////////////////////////////// // // FLASH_BEGIN_PROGRAMMING_FAST(); Sector = CPU_GetUncachableAddress( Sector ); // Enter Word Program Mode. *Sector = PROGRAM_WORD; *Sector = Data; // wait for device to signal completion // break when the device signals completion by looking for Data (0xff erasure value) on I/O 7 (a 0 on I/O 7 indicates erasure in progress) while((*Sector & SR_WSM_READY) != SR_WSM_READY); StatusRegister = *Sector; // Exit Status Read Mode. *Sector = CLEAR_STATUS_REGISTER; *Sector = ENTER_READ_ARRAY_MODE; CPU_InvalidateAddress( CPU_GetCachableAddress( Sector ) ); FLASH_END_PROGRAMMING_FAST( "I28F_16 WriteWord", Sector ); // // /////////////////////////////////// return StatusRegister; }
BOOL DK_LM3S9B96_BlockStorage_Driver::IsBlockErased( void* context, ByteAddress Address, UINT32 BlockLength ) { MEMORY_MAPPED_NOR_BLOCK_CONFIG* config = (MEMORY_MAPPED_NOR_BLOCK_CONFIG*)context; const BlockDeviceInfo * deviceInfo = config->BlockConfig.BlockDeviceInformation; UINT32 iRegion, iRange; unsigned long StartAddress, EndAddress, PageAddress; // 1st or 2nd FLASH controller if (!deviceInfo->FindRegionFromAddress( Address, iRegion, iRange )) return FALSE; Address = CPU_GetCachableAddress(Address); StartAddress = (unsigned long) Address; EndAddress = (unsigned long)(Address + BlockLength); for(PageAddress = StartAddress; PageAddress < EndAddress; PageAddress+=LM3S_IFLASH_PAGE_SIZE) { unsigned long ulAddress = PageAddress - LM3S_IFLASH; if( SSIFlashRead(ulAddress,LM3S_IFLASH_PAGE_SIZE,pageBuffer) == LM3S_IFLASH_PAGE_SIZE) { int i, LoopCnt; UINT32 *pData = (UINT32*)pageBuffer; for(i=0, LoopCnt = (LM3S_IFLASH_PAGE_SIZE>>2); i< LoopCnt; i++) { if( *pData++ != 0xFFFFFFFF) { return FALSE; } } } else { return FALSE;