279 lines
7.7 KiB
Plaintext
279 lines
7.7 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: Generic script for Freescale MKL33 internal flash
|
|
;
|
|
; @Description:
|
|
;
|
|
; Example for flash declaration of Freescale MKL33 internal
|
|
; flash.
|
|
;
|
|
; Script arguments:
|
|
;
|
|
; DO mkl2 [PREPAREONLY] [CPU=<cpu>] [DUALPORT=0|1] [MASSERASE]
|
|
;
|
|
; PREPAREONLY only declares flash but does not execute flash programming
|
|
; example
|
|
;
|
|
; CPU=<cpu> selects CPU derivative <cpu>. <cpu> can be CPU name out of the
|
|
; table listed below. For these derivatives the flash declaration
|
|
; is done by the script.
|
|
;
|
|
; DUALPORT default value is 0 (disabled). If DualPort mode is enabled
|
|
; flash algorithm stays running until flash programming is
|
|
; finished. Data is tranferred via dual port memory access.
|
|
;
|
|
; MASSERASE forces mass erase of device before establishing debug connection
|
|
;
|
|
; For example:
|
|
;
|
|
; DO ~~/demo/arm/flash/mk30 CPU=MKL33Z128VLH4 DUALPORT=1 PREPAREONLY
|
|
;
|
|
; List of MKL33 derivatives and their configuration:
|
|
;
|
|
; CPU-Type ProgFlash RamSize
|
|
; [Byte] [Byte]
|
|
; --------------------------------------------------------------------------------
|
|
; MKL33Z32VLH4 32kB 4kB
|
|
; MKL33Z32VLK4 32kB 4kB
|
|
; MKL33Z64VLH4 64kB 8kB
|
|
; MKL33Z64VLK4 64kB 8kB
|
|
; MKL33Z128VLH4 128kB 8kB
|
|
; MKL33Z128VLH4R 128kB 16kB
|
|
; MKL33Z128VMP4 128kB 16kB
|
|
; MKL33Z256VLH4 256kB 32kB
|
|
; MKL33Z256VMP4 256kB 32kB
|
|
; --------------------------------------------------------------------------------
|
|
; MKL34Z64VLH4 64kB 8kB
|
|
; MKL34Z64VLL4 64kB 8kB
|
|
; --------------------------------------------------------------------------------
|
|
; MKL36Z64VLH4 64kB 8kB
|
|
; MKL36Z64VLL4 64kB 8kB
|
|
; MKL36Z128VLH4 128kB 16kB
|
|
; MKL36Z128VLL4 128kB 16kB
|
|
; MKL36Z128VLL4R 128kB 16kB
|
|
; MKL36Z128VMC4 128kB 16kB
|
|
; MKL36Z256VLH4 256kB 32kB
|
|
; MKL36Z256VLL4 256kB 32kB
|
|
; MKL36Z256VLL4R 256kB 32kB
|
|
; MKL36Z256VMC4 256kB 32kB
|
|
; MKL36Z256VMP4 256kB 32kB
|
|
;
|
|
;
|
|
; Flash Configuration Field:
|
|
;
|
|
; Byte address Width Description
|
|
; --------------------------------------------------------------------------------
|
|
; 0x0400--0x0407 8 Backdoor Comparison Key.
|
|
; 0x0408--0x040B 4 Program flash protection bytes (FPROT0-3).
|
|
; 0x040F 1 Program flash only devices: Reserved
|
|
; FlexNVM devices: Data flash protection byte
|
|
; (FDPROT).
|
|
; 0x040E 1 Program flash only devices: Reserved
|
|
; FlexNVM devices: EEPROM protection byte
|
|
; (FEPROT).
|
|
; 0x040D 1 Flash nonvolatile option byte (FOPT).
|
|
; 0x040C 1 Flash security byte (FSEC).
|
|
;
|
|
; Flash Configuration Field can be programmed using FLASH.AUTO command
|
|
; with /CENSORSHIP option.
|
|
;
|
|
; @Chip: MKL33Z*
|
|
; @Author: WRD
|
|
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
|
|
; --------------------------------------------------------------------------------
|
|
; $Rev: 12736 $
|
|
; $Id: mkl30.cmm 12736 2023-11-17 07:29:32Z mschaeffner $
|
|
;
|
|
|
|
LOCAL ¶meters
|
|
ENTRY %LINE ¶meters
|
|
|
|
LOCAL ¶m_prepareonly ¶m_masserase ¶m_cpu
|
|
¶m_prepareonly=(STRing.SCAN(STRing.UPpeR("¶meters"),"PREPAREONLY",0)!=-1)
|
|
¶m_masserase=(STRing.SCAN(STRing.UPpeR("¶meters"),"MASSERASE",0)!=-1)
|
|
¶m_cpu=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"CPU=","")
|
|
|
|
LOCAL ¶m_dualport
|
|
¶m_dualport=0
|
|
IF VERSION.BUILD.BASE()>=43441.
|
|
¶m_dualport=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"DUALPORT=","0")
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Setup CPU
|
|
|
|
IF (SYStem.MODE()<5)||¶m_masserase
|
|
(
|
|
SYStem.RESet
|
|
|
|
IF "¶m_cpu"!=""
|
|
SYStem.CPU ¶m_cpu
|
|
IF !CPUIS(MKL2*)
|
|
SYStem.CPU MKL2*
|
|
|
|
SYStem.CONFIG.DEBUGPORTTYPE SWD
|
|
|
|
IF ¶m_masserase
|
|
GOSUB MassErase
|
|
|
|
ON.ERROR GOSUB Unsecure
|
|
SYStem.Up
|
|
ON.ERROR
|
|
)
|
|
|
|
; Unsecure device
|
|
IF (Data.Long(EDBG:0x40000100)&0x04)==0x04
|
|
GOSUB Unsecure
|
|
|
|
; Disable watchdog
|
|
ON.ERROR GOSUB Unsecure
|
|
GOSUB DisableWatchdog
|
|
ON.ERROR
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Flash declaration
|
|
|
|
FLASH.RESet
|
|
GOSUB FlashDeclaration ¶m_dualport
|
|
|
|
; Flash script ends here if called with parameter PREPAREONLY
|
|
IF ¶m_prepareonly
|
|
ENDDO PREPAREDONE
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Flash programming example
|
|
|
|
DIALOG.YESNO "Program flash memory?"
|
|
LOCAL &progflash
|
|
ENTRY &progflash
|
|
IF &progflash
|
|
(
|
|
FLASH.ReProgram.ALL /Erase
|
|
Data.LOAD.auto *
|
|
FLASH.ReProgram.off
|
|
|
|
; Reset device
|
|
SYStem.Down
|
|
SYStem.Up
|
|
|
|
; Disable watchdog
|
|
GOSUB DisableWatchdog
|
|
)
|
|
|
|
ENDDO
|
|
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Disable watchdog
|
|
|
|
DisableWatchdog:
|
|
|
|
Data.Set SD:0x40048100 %Long 0x00000000 ; this register can only be accessed once after reset.
|
|
|
|
RETURN
|
|
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Try to unsecure a secured device
|
|
|
|
Unsecure:
|
|
IF VERSION.BUILD()<48722.
|
|
DO ~~~~/kinetis-unsecure
|
|
ELSE
|
|
(
|
|
; Print security state information
|
|
SYStem.Mode.Prepare
|
|
PRINT "MDM-AP Status Register is 0x" Data.Long(EDBG:0x40000100)
|
|
|
|
DIALOG.YESNO "Execute mass erase to unsecure chip?"
|
|
LOCAL &masserase
|
|
ENTRY &masserase
|
|
IF &masserase
|
|
(
|
|
ON.ERROR DEFault
|
|
|
|
; Unsecure device
|
|
SYStem.Down
|
|
FLASH.UNSECUREerase
|
|
SYStem.Mode.Prepare
|
|
IF (Data.Long(EDBG:0x40000100)&0x04)==0x04
|
|
(
|
|
PRINT %ERROR "Unsecure failed, MDM-AP Status Register is 0x" Data.Long(EDBG:0x40000100)
|
|
SYStem.Down
|
|
ENDDO
|
|
)
|
|
)
|
|
ELSE
|
|
ENDDO
|
|
)
|
|
|
|
SYStem.Up
|
|
|
|
; Disable watchdog
|
|
GOSUB DisableWatchdog
|
|
|
|
RETURN
|
|
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Try to mass erase the device
|
|
|
|
MassErase:
|
|
IF VERSION.BUILD.BASE()<49714.
|
|
DO ~~~~/kinetis-unsecure
|
|
ELSE
|
|
(
|
|
; Mass erase device by unsecure command
|
|
SYStem.Down
|
|
FLASH.UNSECUREerase
|
|
SYStem.Mode.Prepare
|
|
IF (Data.Long(EDBG:0x40000100)&0x24)!=0x20
|
|
(
|
|
PRINT %ERROR "Mass erase failed, MDM-AP Status Register is 0x" Data.Long(EDBG:0x40000100)
|
|
SYStem.Down
|
|
ENDDO
|
|
)
|
|
)
|
|
|
|
RETURN
|
|
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Flash declaration depending on selected CPU
|
|
|
|
FlashDeclaration:
|
|
LOCAL &DualPort
|
|
ENTRY &DualPort
|
|
|
|
LOCAL &PFlashSize
|
|
|
|
; Setup configuration values
|
|
IF CPUIS("MKL3?Z32V*")
|
|
&PFlashSize=0x8000
|
|
ELSE IF CPUIS("MKL3?Z64V*")
|
|
&PFlashSize=0x10000
|
|
ELSE IF CPUIS("MKL3?Z128V*")
|
|
&PFlashSize=0x20000
|
|
ELSE IF CPUIS("MKL3?Z256V*")
|
|
&PFlashSize=0x40000
|
|
ELSE
|
|
(
|
|
PRINT %ERROR "FLASH size of CPU type is not supported by the script"
|
|
ENDDO
|
|
)
|
|
|
|
; Program Flash
|
|
IF &PFlashSize>=0x8000
|
|
FLASH.Create 1. 0x00000000--0x00007FFF 0x400 TARGET Long /KEEP 0x3FC--0x3FF /CENSORSHIP 0x400--0x40F
|
|
IF &PFlashSize>=0x10000
|
|
FLASH.Create 1. 0x00008000--0x0000FFFF 0x400 TARGET Long
|
|
IF &PFlashSize>=0x20000
|
|
FLASH.Create 1. 0x00010000--0x0001FFFF 0x400 TARGET Long
|
|
IF &PFlashSize>=0x40000
|
|
FLASH.Create 1. 0x00020000--0x0003FFFF 0x400 TARGET Long
|
|
|
|
IF &DualPort==0
|
|
FLASH.TARGET 0x1FFFFC00 0x20000400 0x400 ~~/demo/arm/flash/long/ftfa.bin
|
|
ELSE
|
|
FLASH.TARGET 0x1FFFFC00 EAHB:0x20000400 0x400 ~~/demo/arm/flash/long/ftfa.bin /DualPort
|
|
|
|
RETURN
|