From 73f43354a5354d1b8002bee8420fac1627ccf0a4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 11 Jun 2015 08:38:56 -0600 Subject: [PATCH] Kinetis: Add logic to set CFM protect area to all 0xff in all configurations --- arch/arm/src/kinetis/Make.defs | 1 + arch/arm/src/kinetis/kinetis_cfmconfig.c | 28 ++++++++++++++++++++++++ arch/arm/src/kinetis/kinetis_start.c | 4 ++-- configs/kwikstik-k40/scripts/ld.script | 7 +++--- configs/teensy-3.x/scripts/flash.ld | 7 +++--- configs/twr-k60n512/scripts/ld.script | 7 +++--- 6 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 arch/arm/src/kinetis/kinetis_cfmconfig.c diff --git a/arch/arm/src/kinetis/Make.defs b/arch/arm/src/kinetis/Make.defs index 18896f1d728..65cea6f6e3f 100644 --- a/arch/arm/src/kinetis/Make.defs +++ b/arch/arm/src/kinetis/Make.defs @@ -84,6 +84,7 @@ CHIP_CSRCS = kinetis_allocateheap.c kinetis_clockconfig.c CHIP_CSRCS += kinetis_clrpend.c kinetis_idle.c kinetis_irq.c CHIP_CSRCS += kinetis_lowputc.c kinetis_pin.c kinetis_pingpio.c CHIP_CSRCS += kinetis_serial.c kinetis_start.c kinetis_wdog.c +CHIP_CSRCS += kinetis_cfmconfig.c # Configuration-dependent Kinetis files diff --git a/arch/arm/src/kinetis/kinetis_cfmconfig.c b/arch/arm/src/kinetis/kinetis_cfmconfig.c new file mode 100644 index 00000000000..97c3f30cb89 --- /dev/null +++ b/arch/arm/src/kinetis/kinetis_cfmconfig.c @@ -0,0 +1,28 @@ +/* Barely based on "bare metal" sample from Freedom board: +Copyright (c) 2012-2013 Andrew Payne + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ + +#include + +__attribute__ ((section(".cfmconfig"))) +const uint8_t __flashconfigbytes[16] = +{ + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff +}; diff --git a/arch/arm/src/kinetis/kinetis_start.c b/arch/arm/src/kinetis/kinetis_start.c index 90f6d991f2c..df5b6adec33 100644 --- a/arch/arm/src/kinetis/kinetis_start.c +++ b/arch/arm/src/kinetis/kinetis_start.c @@ -112,8 +112,8 @@ void __start(void) } /* Copy any necessary code sections from FLASH to RAM. The correct - * destination in SRAM is geive by _sramfuncs and _eramfuncs. The - * temporary location is in flash after the data initalization code + * destination in SRAM is given by _sramfuncs and _eramfuncs. The + * temporary location is in flash after the data initialization code * at _framfuncs */ diff --git a/configs/kwikstik-k40/scripts/ld.script b/configs/kwikstik-k40/scripts/ld.script index 97ac473caaa..bcd32829998 100755 --- a/configs/kwikstik-k40/scripts/ld.script +++ b/configs/kwikstik-k40/scripts/ld.script @@ -1,7 +1,7 @@ /**************************************************************************** * configs/kwikstik-k40/scripts/ld.script * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,7 +48,7 @@ MEMORY { - vectflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K - 16 + vectflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K cfmprotect (rx) : ORIGIN = 0x00000400, LENGTH = 16 progflash (rx) : ORIGIN = 0x00000800, LENGTH = 256K - 2K datasram (rwx) : ORIGIN = 0x1fff8000, LENGTH = 64K @@ -56,6 +56,7 @@ MEMORY OUTPUT_ARCH(arm) ENTRY(_stext) +EXTERN(__flashconfigbytes) SECTIONS { .vectors : { @@ -65,7 +66,7 @@ SECTIONS } > vectflash .cfmprotect : { - *(.cfmconfig) + KEEP(*(.cfmconfig)) } > cfmprotect .text : { diff --git a/configs/teensy-3.x/scripts/flash.ld b/configs/teensy-3.x/scripts/flash.ld index 742ea90c9ea..d3a7fc78ad2 100644 --- a/configs/teensy-3.x/scripts/flash.ld +++ b/configs/teensy-3.x/scripts/flash.ld @@ -33,7 +33,7 @@ * ****************************************************************************/ -/* The K20X256VLQ100 has 256Kb of FLASH beginning at address 0x0000:0000 and +/* The MK20DX256VLH7 has 256Kb of FLASH beginning at address 0x0000:0000 and * 64Kb of SRAM beginning at address 0x1c00:0000 (SRAM_L) and 0x2000:000 * bitband region (SRAM_U). * @@ -48,7 +48,7 @@ MEMORY { - vectflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K - 16 + vectflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K cfmprotect (rx) : ORIGIN = 0x00000400, LENGTH = 16 progflash (rx) : ORIGIN = 0x00000800, LENGTH = 256K - 2K datasram (rwx) : ORIGIN = 0x1fff8000, LENGTH = 64K @@ -56,6 +56,7 @@ MEMORY OUTPUT_ARCH(arm) ENTRY(_stext) +EXTERN(__flashconfigbytes) SECTIONS { .vectors : { @@ -65,7 +66,7 @@ SECTIONS } > vectflash .cfmprotect : { - *(.cfmconfig) + KEEP(*(.cfmconfig)) } > cfmprotect .text : { diff --git a/configs/twr-k60n512/scripts/ld.script b/configs/twr-k60n512/scripts/ld.script index 34f1527eb91..9f4f9427fee 100644 --- a/configs/twr-k60n512/scripts/ld.script +++ b/configs/twr-k60n512/scripts/ld.script @@ -1,7 +1,7 @@ /**************************************************************************** * configs/twr-k60n512/scripts/ld.script * - * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -48,7 +48,7 @@ MEMORY { - vectflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K - 16 + vectflash (rx) : ORIGIN = 0x00000000, LENGTH = 1K cfmprotect (rx) : ORIGIN = 0x00000400, LENGTH = 16 progflash (rx) : ORIGIN = 0x00000800, LENGTH = 512K - 2K datasram (rwx) : ORIGIN = 0x1fff0000, LENGTH = 128K @@ -56,6 +56,7 @@ MEMORY OUTPUT_ARCH(arm) ENTRY(_stext) +EXTERN(__flashconfigbytes) SECTIONS { .vectors : { @@ -65,7 +66,7 @@ SECTIONS } > vectflash .cfmprotect : { - *(.cfmconfig) + KEEP(*(.cfmconfig)) } > cfmprotect .text : {