boards/esp32: Remove SPI Flash encryption test
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
This commit is contained in:
parent
1623848720
commit
2739f86654
13 changed files with 0 additions and 756 deletions
|
@ -40,22 +40,6 @@ choice ESP32_SPIFLASH_FS
|
|||
|
||||
endchoice
|
||||
|
||||
config ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
bool "SPI Flash encryption test"
|
||||
default n
|
||||
depends on ESP32_SPIFLASH
|
||||
select DEBUG_ASSERTIONS
|
||||
---help---
|
||||
Enable SPI Flash encryption test. This option will also select
|
||||
DEBUG_ASSERTIONS to enable kernel assert macro.
|
||||
|
||||
config ESP32_SPIFLASH_TEST_ADDRESS
|
||||
hex "SPI Flash test address"
|
||||
default 0x180000
|
||||
depends on ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
---help---
|
||||
SPI Flash encryption test read/write address.
|
||||
|
||||
config ESP32_LCD_OVERCLOCK
|
||||
bool "Run LCD at higher clock speed than allowed"
|
||||
default n
|
||||
|
|
|
@ -110,24 +110,6 @@ int esp32_mmcsd_initialize(int minor);
|
|||
|
||||
int esp32_spiflash_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
void esp32_spiflash_encrypt_test(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_gpio_init
|
||||
****************************************************************************/
|
||||
|
|
|
@ -196,11 +196,6 @@ int esp32_bringup(void)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
esp32_spiflash_encrypt_test();
|
||||
#endif
|
||||
|
||||
ret = esp32_spiflash_init();
|
||||
if (ret)
|
||||
{
|
||||
|
|
|
@ -515,165 +515,3 @@ int esp32_spiflash_init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
|
||||
void esp32_spiflash_encrypt_test(void)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
uint8_t *wbuf;
|
||||
uint8_t *rbuf;
|
||||
struct mtd_geometry_s geo;
|
||||
uint32_t erase_block;
|
||||
uint32_t erase_nblocks;
|
||||
uint32_t rw_block;
|
||||
uint32_t rw_nblocks;
|
||||
struct mtd_dev_s *mtd = esp32_spiflash_get_mtd();
|
||||
struct mtd_dev_s *enc_mtd = esp32_spiflash_encrypt_get_mtd();
|
||||
const uint32_t address = CONFIG_ESP32_SPIFLASH_TEST_ADDRESS;
|
||||
const uint32_t size = 4096;
|
||||
|
||||
ret = MTD_IOCTL(enc_mtd, MTDIOC_GEOMETRY,
|
||||
(unsigned long)(uintptr_t)&geo);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to get GEO ret = %d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
wbuf = kmm_malloc(size);
|
||||
if (!wbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
rbuf = kmm_malloc(size);
|
||||
if (!rbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
erase_block = address / geo.erasesize;
|
||||
erase_nblocks = size / geo.erasesize;
|
||||
|
||||
rw_block = address / geo.blocksize;
|
||||
rw_nblocks = size / geo.blocksize;
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase block ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(enc_mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to encrypt write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and decrypted data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and normal data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and decrypted data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and normal data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
kmm_free(wbuf);
|
||||
kmm_free(rbuf);
|
||||
|
||||
finfo("INFO: ESP32 SPI Flash encryption test successfully\n");
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST */
|
||||
|
|
|
@ -99,23 +99,5 @@ int esp32_mmcsd_initialize(int minor);
|
|||
|
||||
int esp32_spiflash_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
void esp32_spiflash_encrypt_test(void);
|
||||
#endif
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __BOARDS_XTENSA_ESP32_ESP32_ETHERNETKIT_SRC_ESP32_ETHERNETKIT_H */
|
||||
|
|
|
@ -141,11 +141,6 @@ int esp32_bringup(void)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
esp32_spiflash_encrypt_test();
|
||||
#endif
|
||||
|
||||
ret = esp32_spiflash_init();
|
||||
if (ret)
|
||||
{
|
||||
|
|
|
@ -515,165 +515,3 @@ int esp32_spiflash_init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
|
||||
void esp32_spiflash_encrypt_test(void)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
uint8_t *wbuf;
|
||||
uint8_t *rbuf;
|
||||
struct mtd_geometry_s geo;
|
||||
uint32_t erase_block;
|
||||
uint32_t erase_nblocks;
|
||||
uint32_t rw_block;
|
||||
uint32_t rw_nblocks;
|
||||
struct mtd_dev_s *mtd = esp32_spiflash_get_mtd();
|
||||
struct mtd_dev_s *enc_mtd = esp32_spiflash_encrypt_get_mtd();
|
||||
const uint32_t address = CONFIG_ESP32_SPIFLASH_TEST_ADDRESS;
|
||||
const uint32_t size = 4096;
|
||||
|
||||
ret = MTD_IOCTL(enc_mtd, MTDIOC_GEOMETRY,
|
||||
(unsigned long)(uintptr_t)&geo);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to get GEO ret = %d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
wbuf = kmm_malloc(size);
|
||||
if (!wbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
rbuf = kmm_malloc(size);
|
||||
if (!rbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
erase_block = address / geo.erasesize;
|
||||
erase_nblocks = size / geo.erasesize;
|
||||
|
||||
rw_block = address / geo.blocksize;
|
||||
rw_nblocks = size / geo.blocksize;
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase block ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(enc_mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to encrypt write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and decrypted data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and normal data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and decrypted data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and normal data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
kmm_free(wbuf);
|
||||
kmm_free(rbuf);
|
||||
|
||||
finfo("INFO: ESP32 SPI Flash encryption test successfully\n");
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST */
|
||||
|
|
|
@ -106,24 +106,6 @@ int esp32_mmcsd_initialize(int minor);
|
|||
|
||||
int esp32_spiflash_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
void esp32_spiflash_encrypt_test(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_gpio_init
|
||||
****************************************************************************/
|
||||
|
|
|
@ -175,11 +175,6 @@ int esp32_bringup(void)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
esp32_spiflash_encrypt_test();
|
||||
#endif
|
||||
|
||||
ret = esp32_spiflash_init();
|
||||
if (ret)
|
||||
{
|
||||
|
|
|
@ -515,165 +515,3 @@ int esp32_spiflash_init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
|
||||
void esp32_spiflash_encrypt_test(void)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
uint8_t *wbuf;
|
||||
uint8_t *rbuf;
|
||||
struct mtd_geometry_s geo;
|
||||
uint32_t erase_block;
|
||||
uint32_t erase_nblocks;
|
||||
uint32_t rw_block;
|
||||
uint32_t rw_nblocks;
|
||||
struct mtd_dev_s *mtd = esp32_spiflash_get_mtd();
|
||||
struct mtd_dev_s *enc_mtd = esp32_spiflash_encrypt_get_mtd();
|
||||
const uint32_t address = CONFIG_ESP32_SPIFLASH_TEST_ADDRESS;
|
||||
const uint32_t size = 4096;
|
||||
|
||||
ret = MTD_IOCTL(enc_mtd, MTDIOC_GEOMETRY,
|
||||
(unsigned long)(uintptr_t)&geo);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to get GEO ret = %d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
wbuf = kmm_malloc(size);
|
||||
if (!wbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
rbuf = kmm_malloc(size);
|
||||
if (!rbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
erase_block = address / geo.erasesize;
|
||||
erase_nblocks = size / geo.erasesize;
|
||||
|
||||
rw_block = address / geo.blocksize;
|
||||
rw_nblocks = size / geo.blocksize;
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase block ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(enc_mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to encrypt write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and decrypted data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and normal data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and decrypted data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and normal data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
kmm_free(wbuf);
|
||||
kmm_free(rbuf);
|
||||
|
||||
finfo("INFO: ESP32 SPI Flash encryption test successfully\n");
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST */
|
||||
|
|
|
@ -165,11 +165,6 @@ int esp32_bringup(void)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
esp32_spiflash_encrypt_test();
|
||||
#endif
|
||||
|
||||
ret = esp32_spiflash_init();
|
||||
if (ret)
|
||||
{
|
||||
|
|
|
@ -206,165 +206,3 @@ int esp32_spiflash_init(void)
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
|
||||
void esp32_spiflash_encrypt_test(void)
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
uint8_t *wbuf;
|
||||
uint8_t *rbuf;
|
||||
struct mtd_geometry_s geo;
|
||||
uint32_t erase_block;
|
||||
uint32_t erase_nblocks;
|
||||
uint32_t rw_block;
|
||||
uint32_t rw_nblocks;
|
||||
struct mtd_dev_s *mtd = esp32_spiflash_get_mtd();
|
||||
struct mtd_dev_s *enc_mtd = esp32_spiflash_encrypt_get_mtd();
|
||||
const uint32_t address = CONFIG_ESP32_SPIFLASH_TEST_ADDRESS;
|
||||
const uint32_t size = 4096;
|
||||
|
||||
ret = MTD_IOCTL(enc_mtd, MTDIOC_GEOMETRY,
|
||||
(unsigned long)(uintptr_t)&geo);
|
||||
if (ret < 0)
|
||||
{
|
||||
ferr("ERROR: Failed to get GEO ret = %d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
wbuf = kmm_malloc(size);
|
||||
if (!wbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
rbuf = kmm_malloc(size);
|
||||
if (!rbuf)
|
||||
{
|
||||
ferr("ERROR: Failed to alloc %d heap\n", size);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
erase_block = address / geo.erasesize;
|
||||
erase_nblocks = size / geo.erasesize;
|
||||
|
||||
rw_block = address / geo.blocksize;
|
||||
rw_nblocks = size / geo.blocksize;
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase block ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(enc_mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to encrypt write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and decrypted data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Encrypted and normal data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
wbuf[i] = (uint8_t)random();
|
||||
}
|
||||
|
||||
ret = MTD_ERASE(enc_mtd, erase_block, erase_nblocks);
|
||||
if (ret != erase_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to erase ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
ret = MTD_BWRITE(mtd, rw_block, rw_nblocks, wbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to write ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(enc_mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to decrypt read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (!memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and decrypted data is same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
memset(rbuf, 0, size);
|
||||
ret = MTD_BREAD(mtd, rw_block, rw_nblocks, rbuf);
|
||||
if (ret != rw_nblocks)
|
||||
{
|
||||
ferr("ERROR: Failed to read ret=%d\n", ret);
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
if (memcmp(wbuf, rbuf, size))
|
||||
{
|
||||
ferr("ASSERT: Normal and normal data is not same\n");
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
kmm_free(wbuf);
|
||||
kmm_free(rbuf);
|
||||
|
||||
finfo("INFO: ESP32 SPI Flash encryption test successfully\n");
|
||||
}
|
||||
|
||||
#endif /* CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST */
|
||||
|
|
|
@ -121,24 +121,6 @@ int esp32_mmcsd_initialize(int minor);
|
|||
|
||||
int esp32_spiflash_init(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_spiflash_encrypt_test
|
||||
*
|
||||
* Description:
|
||||
* Test ESP32 SPI Flash driver read/write with encryption.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_ESP32_SPIFLASH_ENCRYPTION_TEST
|
||||
void esp32_spiflash_encrypt_test(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp32_gpio_init
|
||||
****************************************************************************/
|
||||
|
|
Loading…
Reference in a new issue