Merge pull request #8589 from davidsaada/david_flash_erase_value

Support erase value in Flash HAL drivers, FlashIAP and block devices
pull/8681/head
Cruz Monrreal 2018-11-08 10:06:58 -06:00 committed by GitHub
commit 3046e31349
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 232 additions and 4 deletions

View File

@ -55,9 +55,6 @@ void flashiap_program_test()
TEST_ASSERT_TRUE(sector_size % page_size == 0); TEST_ASSERT_TRUE(sector_size % page_size == 0);
uint32_t prog_size = std::max(page_size, (uint32_t)8); uint32_t prog_size = std::max(page_size, (uint32_t)8);
uint8_t *data = new uint8_t[prog_size + 2]; uint8_t *data = new uint8_t[prog_size + 2];
for (uint32_t i = 0; i < prog_size + 2; i++) {
data[i] = i;
}
// the one before the last sector in the system // the one before the last sector in the system
uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size); uint32_t address = (flash_device.get_flash_start() + flash_device.get_flash_size()) - (sector_size);
@ -68,6 +65,20 @@ void flashiap_program_test()
ret = flash_device.erase(address, sector_size); ret = flash_device.erase(address, sector_size);
TEST_ASSERT_EQUAL_INT32(0, ret); TEST_ASSERT_EQUAL_INT32(0, ret);
uint8_t erase_val = flash_device.get_erase_value();
memset(data, erase_val, prog_size);
uint8_t *data_flashed = new uint8_t[prog_size];
for (uint32_t i = 0; i < sector_size / prog_size; i++) {
uint32_t page_addr = address + i * prog_size;
ret = flash_device.read(data_flashed, page_addr, prog_size);
TEST_ASSERT_EQUAL_INT32(0, ret);
TEST_ASSERT_EQUAL_UINT8_ARRAY(data, data_flashed, prog_size);
}
for (uint32_t i = 0; i < prog_size + 2; i++) {
data[i] = i;
}
for (uint32_t i = 0; i < sector_size / prog_size; i++) { for (uint32_t i = 0; i < sector_size / prog_size; i++) {
uint32_t prog_addr = address + i * prog_size; uint32_t prog_addr = address + i * prog_size;
@ -75,7 +86,6 @@ void flashiap_program_test()
TEST_ASSERT_EQUAL_INT32(0, ret); TEST_ASSERT_EQUAL_INT32(0, ret);
} }
uint8_t *data_flashed = new uint8_t[prog_size];
for (uint32_t i = 0; i < sector_size / prog_size; i++) { for (uint32_t i = 0; i < sector_size / prog_size; i++) {
uint32_t page_addr = address + i * prog_size; uint32_t page_addr = address + i * prog_size;
ret = flash_device.read(data_flashed, page_addr, prog_size); ret = flash_device.read(data_flashed, page_addr, prog_size);

View File

@ -227,6 +227,20 @@ bd_size_t FlashIAPBlockDevice::get_erase_size(bd_addr_t addr) const
return erase_size; return erase_size;
} }
int FlashIAPBlockDevice::get_erase_value() const
{
if (!_is_initialized) {
return -1;
}
uint8_t erase_val = _flash.get_erase_value();
DEBUG_PRINTF("get_erase_value: %" PRIX8 "\r\n", erase_val);
return erase_val;
}
bd_size_t FlashIAPBlockDevice::size() const bd_size_t FlashIAPBlockDevice::size() const
{ {
DEBUG_PRINTF("size: %" PRIX64 "\r\n", _size); DEBUG_PRINTF("size: %" PRIX64 "\r\n", _size);

View File

@ -109,6 +109,12 @@ public:
*/ */
virtual bd_size_t get_erase_size(bd_addr_t addr) const; virtual bd_size_t get_erase_size(bd_addr_t addr) const;
/** Get the value of storage when erased
*
* @return The value of storage when erased
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device /** Get the total size of the underlying device
* *
* @return Size of the underlying device in bytes * @return Size of the underlying device in bytes

View File

@ -203,6 +203,11 @@ uint32_t FlashIAP::get_flash_size() const
return flash_get_size(&_flash); return flash_get_size(&_flash);
} }
uint8_t FlashIAP::get_erase_value() const
{
return flash_get_erase_value(&_flash);
}
} }
#endif #endif

View File

@ -131,6 +131,13 @@ public:
*/ */
uint32_t get_page_size() const; uint32_t get_page_size() const;
/** Get the flash erase value
*
* Get the value we read after erase operation
* @return flash erase value
*/
uint8_t get_erase_value() const;
private: private:
/* Check if address and size are aligned to a sector /* Check if address and size are aligned to a sector

View File

@ -260,4 +260,11 @@ MBED_NONSECURE_ENTRY uint32_t flash_get_size(const flash_t *obj)
return obj->target_config->flash_size; return obj->target_config->flash_size;
} }
MBED_NONSECURE_ENTRY uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif // #ifndef DOMAIN_NS #endif // #ifndef DOMAIN_NS

View File

@ -117,6 +117,13 @@ uint32_t flash_get_start_address(const flash_t *obj);
*/ */
uint32_t flash_get_size(const flash_t *obj); uint32_t flash_get_size(const flash_t *obj);
/** Get the flash erase value
*
* @param obj The flash object
* @return The flash erase value
*/
uint8_t flash_get_erase_value(const flash_t *obj);
/**@}*/ /**@}*/
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -101,3 +101,10 @@ uint32_t flash_get_size(const flash_t *obj)
return ZBT_SRAM1_SIZE; return ZBT_SRAM1_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}

View File

@ -101,3 +101,10 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}

View File

@ -82,4 +82,11 @@ uint32_t flash_get_size(const flash_t *obj)
return CY_FLASH_SIZE; return CY_FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif // DEVICE_FLASH #endif // DEVICE_FLASH

View File

@ -148,4 +148,11 @@ uint32_t flash_get_size(const flash_t *obj)
#endif #endif
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -195,6 +195,13 @@ uint32_t flash_get_start_address(const flash_t *obj)
return 0; return 0;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif
/** @}*/ /** @}*/

View File

@ -209,4 +209,11 @@ uint32_t flash_get_start_address(const flash_t *obj)
return 0; return 0;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -134,4 +134,12 @@ void flash_set_target_config(flash_t *obj)
} }
#endif // #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U) #endif // #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
MBED_NONSECURE_ENTRY uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif // #if DEVICE_FLASH #endif // #if DEVICE_FLASH

View File

@ -200,4 +200,11 @@ uint32_t flash_get_size(const flash_t *obj)
return 0x80000; return 0x80000;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -122,4 +122,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FSL_FEATURE_SYSCON_FLASH_SIZE_BYTES; return FSL_FEATURE_SYSCON_FLASH_SIZE_BYTES;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -751,4 +751,12 @@ static void cache_control(void)
__DSB(); // ensure completion of the invalidation __DSB(); // ensure completion of the invalidation
__ISB(); // ensure instruction fetch path sees new I cache state __ISB(); // ensure instruction fetch path sees new I cache state
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -69,3 +69,10 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}

View File

@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -215,4 +215,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize; return sectorsize;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -172,4 +172,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -230,4 +230,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize; return sectorsize;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -265,4 +265,11 @@ static uint32_t GetSectorSize(uint32_t Sector)
return sectorsize; return sectorsize;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -174,4 +174,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -171,4 +171,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -284,4 +284,11 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif #endif

View File

@ -144,4 +144,16 @@ uint32_t flash_get_size(const flash_t *obj)
return FLASH_SIZE; return FLASH_SIZE;
} }
/** Get the flash erase value
*
* @param obj The flash object
* @return The flash erase value
*/
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}
#endif // DEVICE_FLASH #endif // DEVICE_FLASH

View File

@ -162,3 +162,14 @@ uint32_t flash_get_size(const flash_t *obj)
{ {
return FLASH_CHIP_SIZE; return FLASH_CHIP_SIZE;
} }
#if defined ( __ICCARM__ ) /* IAR Compiler */
#pragma location = "FLASH_ROM"
#endif
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}

View File

@ -121,3 +121,10 @@ static void internal_hosc_enable(void)
work = (uint32_t)(TSB_CG->OSCCR & ~CGOSCCR_IHOSC1EN_MASK); work = (uint32_t)(TSB_CG->OSCCR & ~CGOSCCR_IHOSC1EN_MASK);
TSB_CG->OSCCR = (uint32_t)(work | CGOSCCR_IHOSC1EN_RW_ENABLE); TSB_CG->OSCCR = (uint32_t)(work | CGOSCCR_IHOSC1EN_RW_ENABLE);
} }
uint8_t flash_get_erase_value(const flash_t *obj)
{
(void)obj;
return 0xFF;
}