Skip to content

Commit

Permalink
Merge pull request wolfSSL#497 from bigbrett/imxrt-followup-fixes
Browse files Browse the repository at this point in the history
Fix ROM API hang for imx rt1064
  • Loading branch information
dgarske authored Aug 26, 2024
2 parents 12d2f27 + 340d9df commit 6828505
Showing 1 changed file with 33 additions and 9 deletions.
42 changes: 33 additions & 9 deletions hal/imx_rt.c
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,9 @@ bootloader_api_entry_t *g_bootloaderTree;
#define CONFIG_FLASH_SIZE (4 * 1024 * 1024) /* 4MBytes */
#endif

/* "Instance" number of the FLEXSPI peripheral, passed to ROM API */
#define CONFIG_FLASH_FLEXSPI_INSTANCE (1)

#define CONFIG_FLASH_PAGE_SIZE 256UL /* 256Bytes */
#define CONFIG_FLASH_SECTOR_SIZE (4 * 1024) /* 4KBytes */
#define CONFIG_FLASH_BLOCK_SIZE (64 * 1024) /* 64KBytes */
Expand Down Expand Up @@ -324,6 +327,9 @@ const flexspi_nor_config_t FLASH_CONFIG_SECTION qspiflash_config = {
#define CONFIG_FLASH_SIZE (8 * 1024 * 1024) /* 8MBytes */
#endif

/* "Instance" number of the FLEXSPI peripheral, passed to ROM API */
#define CONFIG_FLASH_FLEXSPI_INSTANCE (0)

#define CONFIG_FLASH_PAGE_SIZE 256UL /* 256Bytes */
#define CONFIG_FLASH_SECTOR_SIZE (4 * 1024) /* 4KBytes */
#define CONFIG_FLASH_BLOCK_SIZE (64 * 1024) /* 64KBytes */
Expand Down Expand Up @@ -394,6 +400,9 @@ const flexspi_nor_config_t FLASH_CONFIG_SECTION qspiflash_config = {
#define CONFIG_HYPERFLASH
#endif

/* "Instance" number of the FLEXSPI peripheral, passed to ROM API */
#define CONFIG_FLASH_FLEXSPI_INSTANCE (0)

#ifdef CONFIG_HYPERFLASH
#define CONFIG_FLASH_SIZE (64 * 1024 * 1024) /* 64MBytes */
#define CONFIG_FLASH_PAGE_SIZE 512UL /* 512Bytes */
Expand Down Expand Up @@ -897,6 +906,7 @@ void hal_prepare_boot(void)

static int RAMFUNCTION hal_flash_init(void)
{
status_t ret = 0;
#ifdef USE_GET_CONFIG
serial_nor_config_option_t flexspi_cfg_option;
#endif
Expand All @@ -910,18 +920,27 @@ static int RAMFUNCTION hal_flash_init(void)
* (note 4 p.279 in i.MX RT1060 Processor Reference Manual, Rev. 3, 07/2021)
*/
asm volatile("cpsid i");
g_bootloaderTree->flexSpiNorDriver->get_config(0,
ret = g_bootloaderTree->flexSpiNorDriver->get_config(
CONFIG_FLASH_FLEXSPI_INSTANCE,
&flexspi_config,
&flexspi_cfg_option);
g_bootloaderTree->flexSpiNorDriver->init(0, &flexspi_config);
g_bootloaderTree->flexSpiNorDriver->clear_cache(0);
/* Ensure no speculative prefetching happens before flash access is finished */
if (ret == kStatus_Success) {
ret = g_bootloaderTree->flexSpiNorDriver->init(
CONFIG_FLASH_FLEXSPI_INSTANCE,
&flexspi_config);
}
if (ret == kStatus_Success) {
g_bootloaderTree->flexSpiNorDriver->clear_cache(
CONFIG_FLASH_FLEXSPI_INSTANCE);
}
/* Ensure no speculative prefetching happens before flash access is
* finished */
asm volatile("dsb");
/* Re-enable interrupts */
asm volatile("cpsie i");
#endif
#endif
}
return 0;
return (ret == kStatus_Success) ? 0 : -1;
}

int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
Expand All @@ -942,7 +961,9 @@ int RAMFUNCTION hal_flash_write(uint32_t address, const uint8_t *data, int len)
int write_success = 0;
for (i = 0; i < len; i+= CONFIG_FLASH_PAGE_SIZE) {
memcpy(wbuf, data + i, CONFIG_FLASH_PAGE_SIZE);
status = g_bootloaderTree->flexSpiNorDriver->program(0, FLEXSPI_CONFIG,
status = g_bootloaderTree->flexSpiNorDriver->program(
CONFIG_FLASH_FLEXSPI_INSTANCE,
FLEXSPI_CONFIG,
(address + i) - FLASH_BASE, wbuf);
if (status != kStatus_Success)
{
Expand Down Expand Up @@ -989,8 +1010,11 @@ int RAMFUNCTION hal_flash_erase(uint32_t address, int len)
* (note 4 p.279 in i.MX RT1060 Processor Reference Manual, Rev. 3, 07/2021)
*/
asm volatile("cpsid i");
status = g_bootloaderTree->flexSpiNorDriver->erase(0, FLEXSPI_CONFIG,
address - FLASH_BASE, len);
status = g_bootloaderTree->flexSpiNorDriver->erase(
CONFIG_FLASH_FLEXSPI_INSTANCE,
FLEXSPI_CONFIG,
address - FLASH_BASE,
len);
/* Ensure no speculative prefetching happens before flash erase is finished */
asm volatile("dsb");
/**
Expand Down

0 comments on commit 6828505

Please sign in to comment.