From f646f8d0cfd08f4eebff4a3b5bc623701228e650 Mon Sep 17 00:00:00 2001 From: Maureen Helm Date: Wed, 11 Sep 2019 17:52:35 -0500 Subject: [PATCH] soc: nxp_kinetis: Refactor flash configuration field to a common place Refactors the kinetis flash configuration field so it can be shared across all kinetis SoCs. Defaults are overridden for the k8x and ke1xf series to preserve values used prior to this refactoring. Signed-off-by: Maureen Helm --- soc/arm/nxp_kinetis/CMakeLists.txt | 2 ++ soc/arm/nxp_kinetis/Kconfig | 33 +++++++++++++++++++ soc/arm/nxp_kinetis/flash_configuration.c | 33 +++++++++++++++++++ soc/arm/nxp_kinetis/k6x/soc.c | 32 ------------------ .../nxp_kinetis/k8x/Kconfig.defconfig.series | 7 ++++ soc/arm/nxp_kinetis/k8x/soc.c | 22 ------------- .../ke1xf/Kconfig.defconfig.series | 7 ++++ soc/arm/nxp_kinetis/ke1xf/soc.c | 30 ----------------- soc/arm/nxp_kinetis/kl2x/soc.c | 32 ------------------ soc/arm/nxp_kinetis/kwx/soc_kw2xd.c | 32 ------------------ soc/arm/nxp_kinetis/kwx/soc_kw4xz.c | 32 ------------------ 11 files changed, 82 insertions(+), 180 deletions(-) create mode 100644 soc/arm/nxp_kinetis/flash_configuration.c diff --git a/soc/arm/nxp_kinetis/CMakeLists.txt b/soc/arm/nxp_kinetis/CMakeLists.txt index 226f3bd626f..82567384f3a 100644 --- a/soc/arm/nxp_kinetis/CMakeLists.txt +++ b/soc/arm/nxp_kinetis/CMakeLists.txt @@ -1,3 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 +zephyr_sources_ifdef(CONFIG_KINETIS_FLASH_CONFIG flash_configuration.c) + add_subdirectory(${SOC_SERIES}) diff --git a/soc/arm/nxp_kinetis/Kconfig b/soc/arm/nxp_kinetis/Kconfig index 8b14baf92a8..d080bd4ebd8 100644 --- a/soc/arm/nxp_kinetis/Kconfig +++ b/soc/arm/nxp_kinetis/Kconfig @@ -122,6 +122,39 @@ config KINETIS_FLASH_CONFIG_OFFSET hex "Kinetis flash configuration field offset" default 0x400 +config KINETIS_FLASH_CONFIG_FSEC + hex "Flash security byte (FSEC)" + range 0 0xff + default 0xfe + help + Configures the reset value of the FSEC register, which includes + backdoor key access, mass erase, factory access, and flash security + options. + +config KINETIS_FLASH_CONFIG_FOPT + hex "Flash nonvolatile option byte (FOPT)" + range 0 0xff + default 0xff + help + Configures the reset value of the FOPT register, which includes boot, + NMI, and EzPort options. + +config KINETIS_FLASH_CONFIG_FEPROT + hex "EEPROM protection byte (FEPROT)" + range 0 0xff + default 0xff + help + Configures the reset value of the FEPROT register for FlexNVM + devices. For program flash only devices, this byte is reserved. + +config KINETIS_FLASH_CONFIG_FDPROT + hex "Data flash protection byte (FDPROT)" + range 0 0xff + default 0xff + help + Configures the reset value of the FDPROT register for FlexNVM + devices. For program flash only devices, this byte is reserved. + endif # KINETIS_FLASH_CONFIG endif # SOC_FAMILY_KINETIS diff --git a/soc/arm/nxp_kinetis/flash_configuration.c b/soc/arm/nxp_kinetis/flash_configuration.c new file mode 100644 index 00000000000..0ed9cb1097e --- /dev/null +++ b/soc/arm/nxp_kinetis/flash_configuration.c @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019, NXP + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +u8_t __kinetis_flash_config_section __kinetis_flash_config[] = { + /* Backdoor Comparison Key (unused) */ + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + + /* Program flash protection; 1 bit/region - 0=protected, 1=unprotected + */ + 0xFF, 0xFF, 0xFF, 0xFF, + + /* Flash security register (FSEC) enables/disables backdoor key access, + * mass erase, factory access, and flash security + */ + CONFIG_KINETIS_FLASH_CONFIG_FSEC, + + /* Flash nonvolatile option register (FOPT) enables/disables NMI, + * EzPort, and boot options + */ + CONFIG_KINETIS_FLASH_CONFIG_FOPT, + + /* EEPROM protection register (FEPROT) for FlexNVM devices */ + CONFIG_KINETIS_FLASH_CONFIG_FEPROT, + + /* Data flash protection register (FDPROT) for FlexNVM devices */ + CONFIG_KINETIS_FLASH_CONFIG_FDPROT, +}; diff --git a/soc/arm/nxp_kinetis/k6x/soc.c b/soc/arm/nxp_kinetis/k6x/soc.c index 4dc2d90767c..efa33ad7bd6 100644 --- a/soc/arm/nxp_kinetis/k6x/soc.c +++ b/soc/arm/nxp_kinetis/k6x/soc.c @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -34,37 +33,6 @@ #define TIMESRC_OSCERCLK (2) -/* - * K64F Flash configuration fields - * These 16 bytes, which must be loaded to address 0x400, include default - * protection and security settings. - * They are loaded at reset to various Flash Memory module (FTFE) registers. - * - * The structure is: - * -Backdoor Comparison Key for unsecuring the MCU - 8 bytes - * -Program flash protection bytes, 4 bytes, written to FPROT0-3 - * -Flash security byte, 1 byte, written to FSEC - * -Flash nonvolatile option byte, 1 byte, written to FOPT - * -Reserved, 1 byte, (Data flash protection byte for FlexNVM) - * -Reserved, 1 byte, (EEPROM protection byte for FlexNVM) - * - */ -u8_t __kinetis_flash_config_section __kinetis_flash_config[] = { - /* Backdoor Comparison Key (unused) */ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - /* Program flash protection; 1 bit/region - 0=protected, 1=unprotected - */ - 0xFF, 0xFF, 0xFF, 0xFF, - /* - * Flash security: Backdoor key disabled, Mass erase enabled, - * Factory access enabled, MCU is unsecure - */ - 0xFE, - /* Flash nonvolatile option: NMI enabled, EzPort enabled, Normal boot */ - 0xFF, - /* Reserved for FlexNVM feature (unsupported by this MCU) */ - 0xFF, 0xFF}; - static const osc_config_t oscConfig = { .freq = CONFIG_OSC_XTAL0_FREQ, .capLoad = 0, diff --git a/soc/arm/nxp_kinetis/k8x/Kconfig.defconfig.series b/soc/arm/nxp_kinetis/k8x/Kconfig.defconfig.series index 239233b08dc..77f5559418e 100644 --- a/soc/arm/nxp_kinetis/k8x/Kconfig.defconfig.series +++ b/soc/arm/nxp_kinetis/k8x/Kconfig.defconfig.series @@ -15,6 +15,13 @@ config NUM_IRQS # must be >= the highest interrupt number used default 106 +if KINETIS_FLASH_CONFIG + +config KINETIS_FLASH_CONFIG_FOPT + default 0x3f + +endif # KINETIS_FLASH_CONFIG + if ADC config ADC_MCUX_ADC16 diff --git a/soc/arm/nxp_kinetis/k8x/soc.c b/soc/arm/nxp_kinetis/k8x/soc.c index c5973099ee0..9f0d458da4e 100644 --- a/soc/arm/nxp_kinetis/k8x/soc.c +++ b/soc/arm/nxp_kinetis/k8x/soc.c @@ -29,28 +29,6 @@ #define RUNM_VLPR (2) #define RUNM_HSRUN (3) -/* - * K8x flash configuration fields - * These 16 bytes, which must be loaded into flash memory at offset 0x400, - * include default protection and security settings. - * They are loaded at reset to various Flash Memory module (FTFA) registers. - */ -u8_t __kinetis_flash_config_section __kinetis_flash_config[] = { - /* Backdoor Comparison Key (unused) */ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - /* Program flash protection */ - 0xFF, 0xFF, 0xFF, 0xFF, - /* - * Flash security: Backdoor key disabled, Mass erase enabled, - * Factory access enabled, MCU is unsecure - */ - 0xFE, - /* Flash nonvolatile option: NMI enabled, EzPort enabled, Normal boot */ - 0x3F, - /* Reserved for FlexNVM feature (unsupported by this MCU) */ - 0xFF, 0xFF -}; - static const osc_config_t osc_config = { .freq = CONFIG_OSC_XTAL0_FREQ, .capLoad = 0, diff --git a/soc/arm/nxp_kinetis/ke1xf/Kconfig.defconfig.series b/soc/arm/nxp_kinetis/ke1xf/Kconfig.defconfig.series index 5ea42a811b8..eb0a0133154 100644 --- a/soc/arm/nxp_kinetis/ke1xf/Kconfig.defconfig.series +++ b/soc/arm/nxp_kinetis/ke1xf/Kconfig.defconfig.series @@ -15,6 +15,13 @@ config NUM_IRQS # must be >= the highest interrupt number used default 91 +if KINETIS_FLASH_CONFIG + +config KINETIS_FLASH_CONFIG_FOPT + default 0x7d + +endif # KINETIS_FLASH_CONFIG + if CLOCK_CONTROL config CLOCK_CONTROL_MCUX_SCG diff --git a/soc/arm/nxp_kinetis/ke1xf/soc.c b/soc/arm/nxp_kinetis/ke1xf/soc.c index 098c83f88d0..fb9ce480524 100644 --- a/soc/arm/nxp_kinetis/ke1xf/soc.c +++ b/soc/arm/nxp_kinetis/ke1xf/soc.c @@ -15,36 +15,6 @@ #include #include -/* - * KE1xF flash configuration fields - * These 16 bytes, which must be loaded to address 0x400, include default - * protection, boot options and security settings. - * They are loaded at reset to various Flash Memory module (FTFE) registers. - */ -u8_t __kinetis_flash_config_section __kinetis_flash_config[] = { - /* Backdoor Comparison Key (unused) */ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - /* Program flash protection */ - 0xFF, 0xFF, 0xFF, 0xFF, - /* - * Flash security: Backdoor key disabled, Mass erase enabled, - * Factory access enabled, MCU is unsecure - */ - 0xFE, - /* - * Flash nonvolatile option: Boot from ROM with BOOTCFG0/NMI - * pin low, boot from flash with - * BOOTCFG0/NMI pin high, RESET_b - * pin dedicated, NMI enabled, - * normal boot - */ - 0x7d, - /* EEPROM protection */ - 0xFF, - /* Data flash protection */ - 0xFF, -}; - #define ASSERT_WITHIN_RANGE(val, min, max, str) \ BUILD_ASSERT_MSG(val >= min && val <= max, str) diff --git a/soc/arm/nxp_kinetis/kl2x/soc.c b/soc/arm/nxp_kinetis/kl2x/soc.c index 5ee5ca0929b..b7aff45dfdb 100644 --- a/soc/arm/nxp_kinetis/kl2x/soc.c +++ b/soc/arm/nxp_kinetis/kl2x/soc.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -19,37 +18,6 @@ * Variables ******************************************************************************/ -/* - * KL25Z Flash configuration fields - * These 16 bytes, which must be loaded to address 0x400, include default - * protection and security settings. - * They are loaded at reset to various Flash Memory module (FTFE) registers. - * - * The structure is: - * -Backdoor Comparison Key for unsecuring the MCU - 8 bytes - * -Program flash protection bytes, 4 bytes, written to FPROT0-3 - * -Flash security byte, 1 byte, written to FSEC - * -Flash nonvolatile option byte, 1 byte, written to FOPT - * -Reserved, 1 byte, (Data flash protection byte for FlexNVM) - * -Reserved, 1 byte, (EEPROM protection byte for FlexNVM) - * - */ -u8_t __kinetis_flash_config_section __kinetis_flash_config[] = { - /* Backdoor Comparison Key (unused) */ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - /* Program flash protection; 1 bit/region - 0=protected, 1=unprotected - */ - 0xFF, 0xFF, 0xFF, 0xFF, - /* - * Flash security: Backdoor key disabled, Mass erase enabled, - * Factory access enabled, MCU is unsecure - */ - 0xFE, - /* Flash nonvolatile option: NMI enabled, EzPort enabled, Normal boot */ - 0xFF, - /* Reserved for FlexNVM feature (unsupported by this MCU) */ - 0xFF, 0xFF}; - static ALWAYS_INLINE void clkInit(void) { /* diff --git a/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c b/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c index 89dcb44c687..5c0406a11dc 100644 --- a/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c +++ b/soc/arm/nxp_kinetis/kwx/soc_kw2xd.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -27,37 +26,6 @@ #define TIMESRC_OSCERCLK (2) -/* - * KW2xD Flash configuration fields - * These 16 bytes, which must be loaded to address 0x400, include default - * protection and security settings. - * They are loaded at reset to various Flash Memory module (FTFE) registers. - * - * The structure is: - * -Backdoor Comparison Key for unsecuring the MCU - 8 bytes - * -Program flash protection bytes, 4 bytes, written to FPROT0-3 - * -Flash security byte, 1 byte, written to FSEC - * -Flash nonvolatile option byte, 1 byte, written to FOPT - * -Reserved, 1 byte, (Data flash protection byte for FlexNVM) - * -Reserved, 1 byte, (EEPROM protection byte for FlexNVM) - * - */ -uint8_t __kinetis_flash_config_section __kinetis_flash_config[] = { - /* Backdoor Comparison Key (unused) */ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - /* Program flash protection; 1 bit/region - 0=protected, 1=unprotected - */ - 0xFF, 0xFF, 0xFF, 0xFF, - /* - * Flash security: Backdoor key disabled, Mass erase enabled, - * Factory access enabled, MCU is unsecure - */ - 0xFE, - /* Flash nonvolatile option: NMI enabled, EzPort enabled, Normal boot */ - 0xFF, - /* Reserved for FlexNVM feature (unsupported by this MCU) */ - 0xFF, 0xFF}; - static const osc_config_t oscConfig = { .freq = CONFIG_OSC_XTAL0_FREQ, .capLoad = 0, diff --git a/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c b/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c index be627c663b3..a9dc974bf9d 100644 --- a/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c +++ b/soc/arm/nxp_kinetis/kwx/soc_kw4xz.c @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -22,37 +21,6 @@ #define CLKDIV1_DIVBY2 (1) -/* - * KW41Z Flash configuration fields - * These 16 bytes, which must be loaded to address 0x400, include default - * protection and security settings. - * They are loaded at reset to various Flash Memory module (FTFE) registers. - * - * The structure is: - * -Backdoor Comparison Key for unsecuring the MCU - 8 bytes - * -Program flash protection bytes, 4 bytes, written to FPROT0-3 - * -Flash security byte, 1 byte, written to FSEC - * -Flash nonvolatile option byte, 1 byte, written to FOPT - * -Reserved, 1 byte, (Data flash protection byte for FlexNVM) - * -Reserved, 1 byte, (EEPROM protection byte for FlexNVM) - * - */ -u8_t __kinetis_flash_config_section __kinetis_flash_config[] = { - /* Backdoor Comparison Key (unused) */ - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - /* Program flash protection; 1 bit/region - 0=protected, 1=unprotected - */ - 0xFF, 0xFF, 0xFF, 0xFF, - /* - * Flash security: Backdoor key disabled, Mass erase enabled, - * Factory access enabled, MCU is unsecure - */ - 0xFE, - /* Flash nonvolatile option: NMI enabled, EzPort enabled, Normal boot */ - 0xFF, - /* Reserved for FlexNVM feature (unsupported by this MCU) */ - 0xFF, 0xFF}; - static const osc_config_t oscConfig = { .freq = CONFIG_OSC_XTAL0_FREQ,