Files
Gen4_R-Car_Trace32/2_Trunk/demo/arm/flash/mkl10.cmm
2025-10-14 09:52:32 +09:00

322 lines
9.5 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: Generic script for Freescale MKL14, MKL15 and MKL17 internal flash.
;
; @Description:
;
; Example for flash declaration of Freescale MKL14, MKL15 and MKL17
; internal flash.
;
; Script arguments:
;
; DO mkl1 [PREPAREONLY] [CPU=<cpu>] [MASSERASE]
;
; PREPAREONLY only declares flash but does not execute flash programming
;
; 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.
;
; MASSERASE forces mass erase of device before establishing debug connection
;
; For example:
;
; DO ~~/demo/arm/flash/mkl10 CPU=MK15Z128VLK4 PREPAREONLY
;
; List of MKL14, MKL15 and MKL17 derivatives and their configuration:
;
; CPU-Type ProgFlash RamSize
; [Byte] [Byte]
; --------------------------------------------------------------------------------
; MKL14Z32VFM4 32kB 4kB
; MKL14Z32VFM4R 32kB 4kB
; MKL14Z32VFT4 32kB 4kB
; MKL14Z32VLH4 32kB 4kB
; MKL14Z32VLK4 32kB 4kB
; MKL14Z64VFM4 64kB 8kB
; MKL14Z64VFM4R 64kB 8kB
; MKL14Z64VFT4 64kB 8kB
; MKL14Z64VFT4R 64kB 8kB
; MKL14Z64VLH4 64kB 8kB
; MKL14Z64VLK4 64kB 8kB
; MKL14Z64VLK4R 64kB 8kB
; --------------------------------------------------------------------------------
; MKL15Z32VFM4 32kB 4kB
; MKL15Z32VFM4R 32kB 4kB
; MKL15Z32VFT4 32kB 4kB
; MKL15Z32VLH4 32kB 4kB
; MKL15Z32VLK4 32kB 4kB
; MKL15Z64VFM4 64kB 8kB
; MKL15Z64VFM4R 64kB 8kB
; MKL15Z64VFT4 64kB 8kB
; MKL15Z64VLH4 64kB 8kB
; MKL15Z64VLK4 64kB 8kB
; MKL15Z128VFM4 128kB 16kB
; MKL15Z128VFM4R 128kB 16kB
; MKL15Z128VFT4 128kB 16kB
; MKL15Z128VLH4 128kB 16kB
; MKL15Z128VLH4R 128kB 16kB
; MKL15Z128VLK4 128kB 16kB
; MKL15Z128VLK4R 128kB 16kB
; MKL15Z128CAD4R 128kB 16kB
; KKL15Z128CAD4R 128kB 16kB
; --------------------------------------------------------------------------------
; MKL16Z32VFM4 32kB 4kB
; MKL16Z32VFT4 32kB 4kB
; MKL16Z32VFT4R 32kB 4kB
; MKL16Z32VLH4 32kB 4kB
; MKL16Z64VFM4 64kB 8kB
; MKL16Z64VFM4R 64kB 8kB
; MKL16Z64VFT4 64kB 8kB
; MKL16Z64VFT4R 64kB 8kB
; MKL16Z64VLH4 64kB 8kB
; MKL16Z64VLH4R 64kB 8kB
; MKL16Z128VFM4 128kB 16kB
; MKL16Z128VFM4R 128kB 16kB
; MKL16Z128VFT4 128kB 16kB
; MKL16Z128VFT4R 128kB 16kB
; MKL16Z128VLH4 128kB 16kB
; MKL16Z128VLH4R 128kB 16kB
; MKL16Z256VLH4 256kB 32kB
; MKL16Z256VLH4R 256kB 32kB
; MKL16Z256VMP4 256kB 32kB
; MKL16Z256VMP4R 256kB 32kB
; --------------------------------------------------------------------------------
; MKL17Z32VFM4 32kB 4kB
; MKL17Z32VFM4R 32kB 4kB
; MKL17Z32VDA4 32kB 4kB
; MKL17Z32VDA4R 32kB 4kB
; MKL17Z32VFT4 32kB 4kB
; MKL17Z32VMP4 32kB 4kB
; MKL17Z32VLH4 32kB 4kB
; MKL17Z64VFM4 64kB 8kB
; MKL17Z64VFM4R 64kB 8kB
; MKL17Z64VDA4 64kB 8kB
; MKL17Z64VDA4R 64kB 8kB
; MKL17Z64VFT4 64kB 8kB
; MKL17Z64VMP4 64kB 8kB
; MKL17Z64VLH4 64kB 8kB
; MKL17Z128VFM4 128kB 32kB
; MKL17Z128VFM4R 128kB 32kB
; MKL17Z128VFT4 128kB 32kB
; MKL17Z128VLH4 128kB 32kB
; MKL17Z128VLH4R 128kB 32kB
; MKL17Z128VMP4 128kB 32kB
; MKL17Z128VMP4R 128kB 32kB
; MKL17Z256CAL4R 256kB 32kB
; KKL17Z256CAL4R 256kB 32kB
; MKL17Z256VFM4 256kB 32kB
; MKL17Z256VFT4 256kB 32kB
; MKL17Z256VFT4R 256kB 32kB
; MKL17Z256VLH4 256kB 32kB
; MKL17Z256VLH4R 256kB 32kB
; MKL17Z256VMP4 256kB 32kB
; MKL17Z256VMP4R 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: MKL14* MKL15* MKL17*
; @Author: WRD
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Rev: 10516 $
; $Id: mkl10.cmm 10516 2022-02-02 11:39:30Z bschroefel $
;
LOCAL &parameters
ENTRY %LINE &parameters
LOCAL &param_prepareonly &param_masserase &param_cpu
&param_prepareonly=(STRing.SCAN(STRing.UPpeR("&parameters"),"PREPAREONLY",0)!=-1)
&param_masserase=(STRing.SCAN(STRing.UPpeR("&parameters"),"MASSERASE",0)!=-1)
&param_cpu=STRing.SCANAndExtract(STRing.UPpeR("&parameters"),"CPU=","")
; ------------------------------------------------------------------------------
; Setup CPU
IF (SYStem.MODE()<5)||&param_masserase
(
SYStem.RESet
IF "&param_cpu"!=""
SYStem.CPU &param_cpu
IF !CPUIS(MKL1*)
SYStem.CPU MKL1*
SYStem.CONFIG.DEBUGPORTTYPE SWD
IF &param_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
; Flash script ends here if called with parameter PREPAREONLY
IF &param_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 &PFlashSize
; Setup configuration values
IF CPUIS("MKL1?Z32V*")
&PFlashSize=0x8000
ELSE IF CPUIS("MKL1?Z64V*")
&PFlashSize=0x10000
ELSE IF CPUIS("MKL1?Z128*")||CPUIS("KKL1?Z128*")
&PFlashSize=0x20000
ELSE IF CPUIS("MKL1?Z256*")||CPUIS("KKL1?Z128*")
&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
FLASH.TARGET 0x1FFFFC00 0x20000400 0x400 ~~/demo/arm/flash/long/ftfa.bin
RETURN