From d095963e739726e25a0d8acdeaae30821ea27b60 Mon Sep 17 00:00:00 2001 From: Andrzej Puzdrowski Date: Thu, 23 Nov 2017 13:47:35 +0100 Subject: [PATCH] drivers: flash: Assert implementation of Flash Page Layout Some drivers doesn't implement flash API page layout extension which is causing the application crash once the API was calling. This patch introduce system termination for this in those drivers which doesn't implement extension. This will help to discover this problem early. It is not done by preprocessor check because it is possible to have enabled a driver which support and a driver which doesn't support this API simultaneously. Now FLASH_PAGE_LAYOUT configuration option is accessible only in case that at last one driver which implements mentioned API is enabled. Signed-off-by: Andrzej Puzdrowski --- arch/Kconfig | 7 +++++++ drivers/flash/Kconfig | 3 ++- drivers/flash/Kconfig.stm32 | 3 +++ drivers/flash/flash_priv.h | 17 +++++++++++++++++ drivers/flash/soc_flash_mcux.c | 5 +++++ drivers/flash/soc_flash_qmsi.c | 5 +++++ drivers/flash/spi_flash_w25qxxdv.c | 5 +++++ 7 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 drivers/flash/flash_priv.h diff --git a/arch/Kconfig b/arch/Kconfig index 6fe71b6de98..4ce43b4db91 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -234,6 +234,13 @@ config FP_SHARING endmenu +config FLASH_HAS_PAGE_LAYOUT + bool + default n + help + This option is enabled when the SoC flash driver supports + retrieving the layout of flash memory pages. + # # End hidden PM feature configs # diff --git a/drivers/flash/Kconfig b/drivers/flash/Kconfig index 6c8d6ec1af1..d4588633210 100644 --- a/drivers/flash/Kconfig +++ b/drivers/flash/Kconfig @@ -18,7 +18,7 @@ menuconfig FLASH config FLASH_PAGE_LAYOUT bool "API for retrieving the layout of pages" - depends on FLASH + depends on FLASH && FLASH_HAS_PAGE_LAYOUT default n help Enables API for retrieving the layout of flash memory pages. @@ -127,6 +127,7 @@ config SOC_FLASH_NRF5 bool "Nordic Semiconductor nRF5X flash driver" depends on FLASH && SOC_FAMILY_NRF5 default n + select FLASH_HAS_PAGE_LAYOUT help Enables Nordic Semiconductor nRF5X flash driver. diff --git a/drivers/flash/Kconfig.stm32 b/drivers/flash/Kconfig.stm32 index ee7447855f9..20a5627adf8 100644 --- a/drivers/flash/Kconfig.stm32 +++ b/drivers/flash/Kconfig.stm32 @@ -16,6 +16,9 @@ menuconfig SOC_FLASH_STM32 select FLASH_PAGE_LAYOUT if SOC_SERIES_STM32F0X select FLASH_PAGE_LAYOUT if SOC_SERIES_STM32F4X select FLASH_PAGE_LAYOUT if SOC_SERIES_STM32L4X + select FLASH_HAS_PAGE_LAYOUT if SOC_SERIES_STM32F0X + select FLASH_HAS_PAGE_LAYOUT if SOC_SERIES_STM32F4X + select FLASH_HAS_PAGE_LAYOUT if SOC_SERIES_STM32L4X help Enable STM32F0x, STM32F3x, STM32F4x OR STM32L4x series flash driver. diff --git a/drivers/flash/flash_priv.h b/drivers/flash/flash_priv.h new file mode 100644 index 00000000000..a925db4b5f2 --- /dev/null +++ b/drivers/flash/flash_priv.h @@ -0,0 +1,17 @@ +/* + * Copyright (c) 2017 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef __FLASH_PRIV_H__ +#define __FLASH_PRIV_H__ + +#if defined(CONFIG_FLASH_PAGE_LAYOUT) +static inline void flash_page_layout_not_implemented(void) +{ + k_panic(); +} +#endif + +#endif diff --git a/drivers/flash/soc_flash_mcux.c b/drivers/flash/soc_flash_mcux.c index b424fbac306..4b9b794176d 100644 --- a/drivers/flash/soc_flash_mcux.c +++ b/drivers/flash/soc_flash_mcux.c @@ -12,6 +12,7 @@ #include #include #include +#include "flash_priv.h" #include "fsl_common.h" #include "fsl_flash.h" @@ -92,6 +93,10 @@ static const struct flash_driver_api flash_mcux_api = { .erase = flash_mcux_erase, .write = flash_mcux_write, .read = flash_mcux_read, +#if defined(CONFIG_FLASH_PAGE_LAYOUT) + .page_layout = (flash_api_pages_layout) + flash_page_layout_not_implemented, +#endif .write_block_size = FSL_FEATURE_FLASH_PFLASH_BLOCK_WRITE_UNIT_SIZE, }; diff --git a/drivers/flash/soc_flash_qmsi.c b/drivers/flash/soc_flash_qmsi.c index 030aaad9f21..11b7bdcd729 100644 --- a/drivers/flash/soc_flash_qmsi.c +++ b/drivers/flash/soc_flash_qmsi.c @@ -11,6 +11,7 @@ #include #include +#include "flash_priv.h" #include "qm_flash.h" #include "qm_soc_regs.h" @@ -253,6 +254,10 @@ static const struct flash_driver_api flash_qmsi_api = { .write = flash_qmsi_write, .erase = flash_qmsi_erase, .write_protection = flash_qmsi_write_protection, +#if defined(CONFIG_FLASH_PAGE_LAYOUT) + .page_layout = (flash_api_pages_layout) + flash_page_layout_not_implemented, +#endif .write_block_size = 4, }; diff --git a/drivers/flash/spi_flash_w25qxxdv.c b/drivers/flash/spi_flash_w25qxxdv.c index f9fdf6f1a4c..218a83b1d3d 100644 --- a/drivers/flash/spi_flash_w25qxxdv.c +++ b/drivers/flash/spi_flash_w25qxxdv.c @@ -12,6 +12,7 @@ #include #include "spi_flash_w25qxxdv_defs.h" #include "spi_flash_w25qxxdv.h" +#include "flash_priv.h" static inline int spi_flash_wb_id(struct device *dev) { @@ -344,6 +345,10 @@ static const struct flash_driver_api spi_flash_api = { .write = spi_flash_wb_write, .erase = spi_flash_wb_erase, .write_protection = spi_flash_wb_write_protection_set, +#if defined(CONFIG_FLASH_PAGE_LAYOUT) + .page_layout = (flash_api_pages_layout) + flash_page_layout_not_implemented, +#endif .write_block_size = 1, };