266 lines
7.5 KiB
Plaintext
266 lines
7.5 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: Generic script for Freescale MKM30 internal flash
|
|
;
|
|
; @Description:
|
|
; Example for flash declaration of Freescale MKM30 internal flash.
|
|
;
|
|
; Script arguments:
|
|
;
|
|
; DO mkm30 [PREPAREONLY] [CPU=<cpu>] [MASSERASE]
|
|
;
|
|
; PREPAREONLY only declares flash but does not execute flash programming
|
|
;
|
|
; CPU=<cpu> selects CPU derivative <cpu>
|
|
;
|
|
; MASSERASE forces mass erase of device before establishing debug connection
|
|
;
|
|
; Example:
|
|
;
|
|
; DO ~~/demo/arm/flash/mkm30 CPU=MKM34Z256VLQ7 PREPAREONLY
|
|
;
|
|
; List of MKV11 derivatives and their configuration:
|
|
;
|
|
; CPU-Type ProgFlash RamSize
|
|
; [Byte] [Byte]
|
|
; --------------------------------------------------------------------------------
|
|
; MKM14Z64CHH5 64 16KB
|
|
; MKM14Z128CHH5 128 16KB
|
|
; --------------------------------------------------------------------------------
|
|
; MKM33Z64CLH5 64 16KB
|
|
; MKM33Z64CLL5 64 16KB
|
|
; MKM33Z128CLH5 128 16KB
|
|
; MKM33Z128CLL5 128 16KB
|
|
; --------------------------------------------------------------------------------
|
|
; MKM34Z128CLL5 128 16KB
|
|
; MKM34Z256VLL7 256 32KB
|
|
; MKM34Z256VLQ7 256 32KB
|
|
;
|
|
; Flash at 0x00000000 to 0x0003FFFF
|
|
; MKM34Z256 else
|
|
; SRAM_L: Lower SRAM All masters 0x1FFFE000 to 0x1FFFFFFF
|
|
; 0x1FFFF000 to 0x1FFFFFFF
|
|
; SRAM_U: Upper SRAM 0x20000000 to 0x20005FFF
|
|
; 0x20000000 to 0x20002FFF
|
|
;
|
|
; IFR (Information Flash Registers) Program Once:
|
|
;
|
|
; Address range Size(Bytes) Field Description
|
|
; --------------------------------------------------------------------------------
|
|
; 0x00 to 0x9F 160 Reserved
|
|
; 0xA0 to 0xFF 96 Program Once Fields
|
|
; 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).
|
|
;
|
|
; @Chip: MKM30*
|
|
; @Author: FLC
|
|
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
|
|
; --------------------------------------------------------------------------------
|
|
; $Rev: 12737 $
|
|
; $Id: mkm30.cmm 12737 2023-11-17 07:32:11Z mschaeffner $
|
|
;
|
|
|
|
PRIVATE ¶meters
|
|
ENTRY %LINE ¶meters
|
|
|
|
PRIVATE ¶m_cpu ¶m_prepareonly ¶m_masserase &DualPort &DualPortOpt
|
|
|
|
¶m_cpu=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"CPU=","")
|
|
¶m_prepareonly=(STRing.SCAN(STRing.UPpeR("¶meters"),"PREPAREONLY",0)!=-1)
|
|
¶m_masserase=(STRing.SCAN(STRing.UPpeR("¶meters"),"MASSERASE",0)!=-1)
|
|
&DualPort=STRing.SCANAndExtract(STRing.UPpeR("¶meters"),"DUALPORT=","1")
|
|
&DualPortOpt="/DualPort"
|
|
if (("&DualPort"=="0")||("&DualPort"=="0x0")||("&DualPort"=="0."))
|
|
&DualPortOpt=""
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Setup CPU
|
|
|
|
IF (SYStem.MODE()<5)||¶m_masserase
|
|
(
|
|
SYStem.RESet
|
|
|
|
IF "¶m_cpu"!=""
|
|
SYStem.CPU ¶m_cpu
|
|
IF !(CPUIS(MKM30*)||CPUIS(MKM14*)||CPUIS(MKM34*))
|
|
SYStem.CPU MKM*
|
|
|
|
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 &DualPortOpt
|
|
|
|
; Flash script ends here if called with parameter PREPAREONLY
|
|
IF ¶m_prepareonly
|
|
ENDDO PREPAREDONE
|
|
|
|
;---------------------------------------------------------------------------------
|
|
; Flash programming example
|
|
|
|
DIALOG.YESNO "Program flash memory?"
|
|
PRIVATE &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:
|
|
PRIVATE &tmp1 &tmp2
|
|
&tmp1=Data.Long(ST:0x20000000)
|
|
&tmp2=Data.Long(ST:0x20000004)
|
|
|
|
; The watchdog has a restrictive timing. It has to be configured and unlocked within a peripod
|
|
; of 20+256 cycles. Therefor the unlock sequence need to be done by a small target program.
|
|
Data.Assemble ST:0x20000000 strh r1,[r0] ;SD:0x4005300E = 0xC520 (Key 1)
|
|
Data.Assemble , strh r2,[r0] ;SD:0x4005300E = 0xD928 (Key 2)
|
|
Data.Assemble , strh r4,[r3] ;SD:0x40053000 = 0x0000 (Config register)
|
|
Data.Assemble , bkpt #0
|
|
Register.Set PC 0x20000000
|
|
Register.Set SP 0x20001000
|
|
Register.Set R0 0x4005300E
|
|
Register.Set R1 0xC520
|
|
Register.Set R2 0xD928
|
|
Register.Set R3 0x40053000
|
|
Register.Set R4 0x0
|
|
Go.direct
|
|
WAIT !STATE.RUN()
|
|
|
|
Data.Set ST:0x20000000 %Long &tmp1
|
|
Data.Set ST:0x20000004 %Long &tmp2
|
|
|
|
RETURN
|
|
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Try to unsecure a secured device
|
|
|
|
Unsecure:
|
|
(
|
|
IF (Data.Long(EDBG:0x40000104)&0x08)==0x08
|
|
(
|
|
Data.Set EDBG:0x40000104 %Long (Data.Long(EDBG:0x40000104)&0xFFFFFFF7)
|
|
)
|
|
; 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?"
|
|
PRIVATE &masserase
|
|
ENTRY &masserase
|
|
IF &masserase
|
|
(
|
|
ON.ERROR DEFault
|
|
|
|
; Unsecure device
|
|
SYStem.Down
|
|
FLASH.UNSECUREerase
|
|
SYStem.Mode.Prepare
|
|
)
|
|
SYStem.Up
|
|
|
|
; Disable watchdog
|
|
GOSUB DisableWatchdog
|
|
|
|
RETURN
|
|
)
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Try to mass erase the device
|
|
|
|
MassErase:
|
|
(
|
|
; Mass erase device by unsecure command
|
|
SYStem.Down
|
|
FLASH.UNSECUREerase
|
|
SYStem.Mode.Prepare
|
|
RETURN
|
|
)
|
|
|
|
; --------------------------------------------------------------------------------
|
|
; Flash declaration depending on selected CPU
|
|
|
|
FlashDeclaration:
|
|
(
|
|
PRIVATE &RamStart &PFlashSize &PSectorSize &RamStart &BufferSize &FlashDriver
|
|
PRIVATE &DualPortOpt
|
|
ENTRY &DualPortOpt
|
|
|
|
&RamStart=0x1FFFF000
|
|
&PSectorSize=0x400
|
|
&FlashDriver="ftfa.bin"
|
|
|
|
; Setup configuration values
|
|
IF CPUIS("MKM??Z64*")
|
|
&PFlashSize=0x10000
|
|
ELSE IF CPUIS("MKM??Z128*")
|
|
&PFlashSize=0x20000
|
|
ELSE IF CPUIS("MKM??Z256*")
|
|
(
|
|
&RamStart=0x1FFFE000
|
|
&PFlashSize=0x40000
|
|
&PSectorSize=0x800
|
|
&FlashDriver="ftfa1n.bin"
|
|
)
|
|
ELSE
|
|
(
|
|
PRINT %ERROR "FLASH size of CPU type is not supported by the script"
|
|
ENDDO
|
|
)
|
|
&BufferSize=&PSectorSize
|
|
|
|
; Program Flash
|
|
FLASH.Create 1. 0x00000000--(&PFlashSize-1.) &PSectorSize TARGET Long /KEEP 0x3FC--0x3FF /CENSORSHIP 0x400++0xf
|
|
|
|
FLASH.TARGET &RamStart &RamStart+0x500 &BufferSize ~~/demo/arm/flash/long/&FlashDriver &DualPortOpt
|
|
|
|
RETURN
|
|
|
|
)
|