Skip to content

Commit c6488fc

Browse files
Kevin Wangkartben
authored andcommitted
drivers: flash: andes_qspi: check if spi is used as flash fetch device
XIP may indicate that the program is executed either in local memory or flash. However, the SPI node is only used as a flash fetch device when the program is executed in flash. Therefore, optimize the related checks to ensure that when XIP is enabled but the program is executed in local memory, the qspi flash node can still be used. Signed-off-by: Kevin Wang <[email protected]>
1 parent 72d7a0f commit c6488fc

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

drivers/flash/flash_andes_qspi.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct flash_andes_qspi_config {
5353
uint32_t base;
5454
uint32_t irq_num;
5555
struct flash_parameters parameters;
56-
bool xip;
56+
bool qspi_cfg_rom;
5757
#if defined(CONFIG_FLASH_ANDES_QSPI_SFDP_DEVICETREE)
5858
uint8_t jedec_id[SPI_NOR_MAX_ID_LEN];
5959
uint32_t flash_size;
@@ -823,7 +823,7 @@ static int flash_andes_qspi_init(const struct device *dev)
823823
uint8_t jedec_id[SPI_NOR_MAX_ID_LEN];
824824

825825
/* we should not configure the device we are running on */
826-
if (config->xip) {
826+
if (config->qspi_cfg_rom) {
827827
return -EINVAL;
828828
}
829829

@@ -917,11 +917,21 @@ static const struct flash_driver_api flash_andes_qspi_api = {
917917
};
918918

919919
#if (CONFIG_XIP)
920-
#define QSPI_ROM_CFG_XIP(node_id) DT_SAME_NODE(node_id, DT_CHOSEN(zephyr_flash))
920+
#define QSPI_FLASH_BASE DT_REG_ADDR_BY_IDX(DT_PARENT(DT_CHOSEN(zephyr_flash)), 1)
921+
#define QSPI_FLASH_SIZE DT_REG_SIZE_BY_IDX(DT_PARENT(DT_CHOSEN(zephyr_flash)), 1)
922+
#define QSPI_FLASH_END (QSPI_FLASH_BASE + QSPI_FLASH_SIZE)
923+
924+
#if ((QSPI_FLASH_BASE <= CONFIG_FLASH_BASE_ADDRESS) && \
925+
(CONFIG_FLASH_BASE_ADDRESS <= QSPI_FLASH_END))
926+
#define QSPI_CFG_ROM(node_id) DT_SAME_NODE(node_id, DT_CHOSEN(zephyr_flash))
921927
#else
922-
#define QSPI_ROM_CFG_XIP(node_id) false
928+
#define QSPI_CFG_ROM(node_id) false
923929
#endif
924930

931+
#else /* CONFIG_XIP */
932+
#define QSPI_CFG_ROM(node_id) false
933+
#endif /* CONFIG_XIP */
934+
925935
#define LAYOUT_PAGES_PROP(n) \
926936
IF_ENABLED(CONFIG_FLASH_PAGE_LAYOUT, \
927937
(.layout = { \
@@ -962,7 +972,7 @@ static const struct flash_driver_api flash_andes_qspi_api = {
962972
.write_block_size = 1, \
963973
.erase_value = 0xff \
964974
}, \
965-
.xip = QSPI_ROM_CFG_XIP(DT_DRV_INST(n)), \
975+
.qspi_cfg_rom = QSPI_CFG_ROM(DT_DRV_INST(n)), \
966976
ANDES_QSPI_SFDP_DEVICETREE_PROP(n) \
967977
}; \
968978
\

0 commit comments

Comments
 (0)