From 1436bdcc67029fdfc0ff03b73e12045bb6a9f272 Mon Sep 17 00:00:00 2001 From: Gerardo Rodriguez Date: Sun, 18 Oct 2020 00:10:46 -0500 Subject: [PATCH] #99 Enable flash protection on DAPLink bootloader region - Set backdoor key to 'MICROBIT'. - Enable FPROT for first 32 kB of flash. - Fix FPROTx numbering according to KL27 RM, where FPROT3 is at address 0x408. - Enable backdoor key in FSEC. - Added asterisks next to selected options in comments for FOPT and FSEC. --- .../freescale/kl27z/armcc/startup_MKL27Z4.s | 120 +++++++++--------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/source/hic_hal/freescale/kl27z/armcc/startup_MKL27Z4.s b/source/hic_hal/freescale/kl27z/armcc/startup_MKL27Z4.s index 71d78d5fc..4724fcc60 100644 --- a/source/hic_hal/freescale/kl27z/armcc/startup_MKL27Z4.s +++ b/source/hic_hal/freescale/kl27z/armcc/startup_MKL27Z4.s @@ -167,49 +167,35 @@ __Vectors_Size EQU __Vectors_End - __Vectors ; Backdoor Comparison Key 5. <0x0-0xFF:2> ; Backdoor Comparison Key 6. <0x0-0xFF:2> ; Backdoor Comparison Key 7. <0x0-0xFF:2> -BackDoorK0 EQU 0xFF -BackDoorK1 EQU 0xFF -BackDoorK2 EQU 0xFF -BackDoorK3 EQU 0xFF -BackDoorK4 EQU 0xFF -BackDoorK5 EQU 0xFF -BackDoorK6 EQU 0xFF -BackDoorK7 EQU 0xFF +BackDoorK0 EQU 0x4D ; 'M' +BackDoorK1 EQU 0x49 ; 'I' +BackDoorK2 EQU 0x43 ; 'C' +BackDoorK3 EQU 0x52 ; 'R' +BackDoorK4 EQU 0x4F ; 'O' +BackDoorK5 EQU 0x42 ; 'B' +BackDoorK6 EQU 0x49 ; 'I' +BackDoorK7 EQU 0x54 ; 'T' ; ; Program flash protection bytes (FPROT) ; Each program flash region can be protected from program and erase operation by setting the associated PROT bit. ; Each bit protects a 1/32 region of the program flash memory. -; FPROT0 -; Program Flash Region Protect Register 0 +; FPROT3 +; Program Flash Region Protect Register 3 ; 1/32 - 8/32 region -; FPROT0.0 -; FPROT0.1 -; FPROT0.2 -; FPROT0.3 -; FPROT0.4 -; FPROT0.5 -; FPROT0.6 -; FPROT0.7 -nFPROT0 EQU 0x00 -FPROT0 EQU nFPROT0:EOR:0xFF -; -; FPROT1 -; Program Flash Region Protect Register 1 -; 9/32 - 16/32 region -; FPROT1.0 -; FPROT1.1 -; FPROT1.2 -; FPROT1.3 -; FPROT1.4 -; FPROT1.5 -; FPROT1.6 -; FPROT1.7 -nFPROT1 EQU 0x00 -FPROT1 EQU nFPROT1:EOR:0xFF +; FPROT3.0 +; FPROT3.1 +; FPROT3.2 +; FPROT3.3 +; FPROT3.4 +; FPROT3.5 +; FPROT3.6 +; FPROT3.7 +nFPROT3 EQU 0x0F ; Enable protection of the first 32 kB of flash +FPROT3 EQU nFPROT3:EOR:0xFF ; ; FPROT2 ; Program Flash Region Protect Register 2 -; 17/32 - 24/32 region +; 9/32 - 16/32 region ; FPROT2.0 ; FPROT2.1 ; FPROT2.2 @@ -221,43 +207,57 @@ FPROT1 EQU nFPROT1:EOR:0xFF nFPROT2 EQU 0x00 FPROT2 EQU nFPROT2:EOR:0xFF ; -; FPROT3 -; Program Flash Region Protect Register 3 +; FPROT1 +; Program Flash Region Protect Register 1 +; 17/32 - 24/32 region +; FPROT1.0 +; FPROT1.1 +; FPROT1.2 +; FPROT1.3 +; FPROT1.4 +; FPROT1.5 +; FPROT1.6 +; FPROT1.7 +nFPROT1 EQU 0x00 +FPROT1 EQU nFPROT1:EOR:0xFF +; +; FPROT0 +; Program Flash Region Protect Register 0 ; 25/32 - 32/32 region -; FPROT3.0 -; FPROT3.1 -; FPROT3.2 -; FPROT3.3 -; FPROT3.4 -; FPROT3.5 -; FPROT3.6 -; FPROT3.7 -nFPROT3 EQU 0x00 -FPROT3 EQU nFPROT3:EOR:0xFF +; FPROT0.0 +; FPROT0.1 +; FPROT0.2 +; FPROT0.3 +; FPROT0.4 +; FPROT0.5 +; FPROT0.6 +; FPROT0.7 +nFPROT0 EQU 0x00 +FPROT0 EQU nFPROT0:EOR:0xFF ; ; ; Flash nonvolatile option byte (FOPT) ; Allows the user to customize the operation of the MCU at boot time. ; LPBOOT0 ; <0=> Core and system clock divider (OUTDIV1) is 0x7 (divide by 8) when LPBOOT1=0 or 0x1 (divide by 2) when LPBOOT1=1. -; <1=> Core and system clock divider (OUTDIV1) is 0x3 (divide by 4) when LPBOOT1=0 or 0x0 (divide by 1) when LPBOOT1=1. +; * <1=> Core and system clock divider (OUTDIV1) is 0x3 (divide by 4) when LPBOOT1=0 or 0x0 (divide by 1) when LPBOOT1=1. ; BOOTPIN_OPT -; <0=> Force Boot from ROM if BOOTCFG0 asserted, where BOOTCFG0 is the boot config function which is muxed with NMI pin +; * <0=> Force Boot from ROM if BOOTCFG0 asserted, where BOOTCFG0 is the boot config function which is muxed with NMI pin ; <1=> Boot source configured by FOPT (BOOTSRC_SEL) bits ; NMI_DIS -; <0=> NMI interrupts are always blocked +; * <0=> NMI interrupts are always blocked ; <1=> NMI_b pin/interrupts reset default to enabled ; RESET_PIN_CFG ; <0=> RESET pin is disabled following a POR and cannot be enabled as reset function -; <1=> RESET_b pin is dedicated +; * <1=> RESET_b pin is dedicated ; LPBOOT1 ; <0=> Core and system clock divider (OUTDIV1) is 0x7 (divide by 8) when LPBOOT0=0 or 0x3 (divide by 4) when LPBOOT0=1. -; <1=> Core and system clock divider (OUTDIV1) is 0x1 (divide by 2) when LPBOOT0=0 or 0x0 (divide by 1) when LPBOOT0=1. +; * <1=> Core and system clock divider (OUTDIV1) is 0x1 (divide by 2) when LPBOOT0=0 or 0x0 (divide by 1) when LPBOOT0=1. ; FAST_INIT ; <0=> Slower initialization -; <1=> Fast Initialization +; * <1=> Fast Initialization ; BOOTSRC_SEL -; <0=> Boot from Flash +; * <0=> Boot from Flash ; <2=> Boot from ROM ; <3=> Boot from ROM ; Boot source selection @@ -267,21 +267,21 @@ FOPT EQU 0x39 ; WARNING: If SEC field is configured as "MCU security status is secure" and MEEN field is configured as "Mass erase is disabled", ; MCU's security status cannot be set back to unsecure state since Mass erase via the debugger is blocked !!! ; SEC -; <2=> MCU security status is unsecure +; * <2=> MCU security status is unsecure ; <3=> MCU security status is secure ; Flash Security ; FSLACC ; <2=> Freescale factory access denied -; <3=> Freescale factory access granted +; * <3=> Freescale factory access granted ; Freescale Failure Analysis Access Code ; MEEN ; <2=> Mass erase is disabled -; <3=> Mass erase is enabled +; * <3=> Mass erase is enabled ; KEYEN -; <2=> Backdoor key access enabled +; * <2=> Backdoor key access enabled ; <3=> Backdoor key access disabled ; Backdoor Key Security Enable -FSEC EQU 0xFE +FSEC EQU 0xBE ; ; @@ -293,7 +293,7 @@ FSEC EQU 0xFE DCB BackDoorK0, BackDoorK1, BackDoorK2, BackDoorK3 DCB BackDoorK4, BackDoorK5, BackDoorK6, BackDoorK7 - DCB FPROT0 , FPROT1 , FPROT2 , FPROT3 + DCB FPROT3 , FPROT2 , FPROT1 , FPROT0 DCB FSEC , FOPT , 0xFF , 0xFF AREA |.text|, CODE, READONLY