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

343 lines
9.6 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: Generic script for Freescale MKE02 and MKE04 internal flash.
;
; @Description:
;
; Example for flash declaration of Freescale MKE02 and MKE04 internal flash.
;
; Script arguments:
;
; DO mke0 [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/mke0 CPU=MKE02Z64VQH2 PREPAREONLY
;
; List of MKE02 and MKE04 derivatives and their configuration:
;
; CPU-Type Flash ProgFlash RamSize
; Type [Byte] [Byte]
; --------------------------------------------------------------------------------
; MKE02Z16VFM4 FTMRH 16kB 2kB
; MKE02Z16VLC2 FTMRH 16kB 2kB
; MKE02Z16VLD2 FTMRH 16kB 2kB
; MKE02Z32VFM4 FTMRH 32kB 4kB
; MKE02Z32VLC2 FTMRH 32kB 4kB
; MKE02Z32VLC4 FTMRH 32kB 4kB
; MKE02Z32VLD2 FTMRH 32kB 4kB
; MKE02Z32VLD4 FTMRH 32kB 4kB
; MKE02Z32VLH2 FTMRH 32kB 4kB
; MKE02Z32VQH2 FTMRH 32kB 4kB
; MKE02Z64VFM4 FTMRH 64kB 4kB
; MKE02Z64VLC2 FTMRH 64kB 4kB
; MKE02Z64VLC4 FTMRH 64kB 4kB
; MKE02Z64VLD2 FTMRH 64kB 4kB
; MKE02Z64VLD4 FTMRH 64kB 4kB
; MKE02Z64VLH2 FTMRH 64kB 4kB
; MKE02Z64VLH4 FTMRH 64kB 4kB
; MKE02Z64VQH2 FTMRH 64kB 4kB
; --------------------------------------------------------------------------------
; MKE04Z8VTG4 FTMRE 8kB 1kB
; MKE04Z8VTG4R FTMRE 8kB 1kB
; MKE04Z8VWJ4 FTMRE 8kB 1kB
; MKE04Z8VWJ4R FTMRE 8kB 1kB
; MKE04Z8VFK4 FTMRE 8kB 1kB
; MKE04Z8VFK4R FTMRE 8kB 1kB
; MKE04Z64VLK4 FTMRE 64kB 8kB
; MKE04Z128VLH4 FTMRE 128kB 16kB
; --------------------------------------------------------------------------------
; MKE06Z64VLD4 FTMRE 64kB 8kB
; MKE06Z128VLD4 FTMRE 128kB 16kB
; MKE06Z64VQH4 FTMRE 64kB 8kB
; MKE06Z128VQH4 FTMRE 128kB 16kB
; MKE06Z64VLH4 FTMRE 64kB 8kB
; MKE06Z128VLH4 FTMRE 128kB 16kB
; MKE06Z64VLK4 FTMRE 64kB 8kB
; MKE06Z128VLK4 FTMRE 128kB 16kB
;
; Flash Configuration Field:
;
; Byte address Width Description
; --------------------------------------------------------------------------------
; 0x0400--0x0407 8 Backdoor Comparison Key
; 0x0408--0x040B 4 reserved
; 0x040C 1 EEPROM protection byte (FEPROT)
; 0x040D 1 Program flash protection bytes (FPROT)
; 0x040E 1 Flash security byte (FSEC)
; 0x040F 1 Flash nonvolatile option byte (FOPT)
;
; Flash Configuration Field can be programmed using FLASH.AUTO command
; with /CENSORSHIP option.
;
; @Author: WRD
; @Chip: MKE02*
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Rev: 10516 $
; $Id: mke0.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(MKE0*)
SYStem.CPU MKE0*
SYStem.CONFIG.DEBUGPORTTYPE SWD
SYStem.Option ResBreak OFF
SYStem.Option WaitReset 500us
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
GOSUB DisableWatchdog
; ------------------------------------------------------------------------------
; 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 VM:0x20000000++0x2F %Long 0
Data.Assemble VMT:0x20000000 adr r0,0x20000014
Data.Assemble , ldm r0,{r0-r4}
Data.Assemble , movs r5,0
Data.Assemble , strb r5, [r0, #1]
Data.Assemble , strh r1, [r0, #2]
Data.Assemble , strh r2, [r0, #2]
Data.Assemble , strh r3, [r0, #4]
Data.Assemble , strh r4, [r0, #0]
Data.Assemble , bkpt #0x0
Data.Set VM:0x20000014 %Long 0x40052000
Data.Set VM:0x20000018 %Long 0x20c5
Data.Set VM:0x2000001C %Long 0x28D9
Data.Set VM:0x20000020 %Long 0xFFFF
Data.Set VM:0x20000024 %Long 0x20
Data.COPY SD:0x20000000++0x2F VM:0x20000030
Data.COPY VM:0x20000000++0x2F SD:0x20000000
Register.Set PC 0x20000000
Go.direct
WAIT !STATE.RUN()
Data.COPY VM:0x20000030++0x2F SD:0x20000000
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
IF (Data.Long(EDBG:0x40000104)&0x08)==0x08
(
Data.Set EDBG:0x40000104 %Long (Data.Long(EDBG:0x40000104)&0xFFFFFFF7)
)
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)&0x04)==0x04
(
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 &FlashType &RAMSize
; Setup configuration values
IF CPUIS("MKE04Z8V*")
(
&PFlashSize=0x2000
&FlashType="FTMRE"
&RAMSize=0x400
)
ELSE IF CPUIS("MKE02Z16V*")
(
&PFlashSize=0x4000
&FlashType="FTMRH"
&RAMSize=0x800
)
ELSE IF CPUIS("MKE02Z32V*")
(
&PFlashSize=0x8000
&FlashType="FTMRH"
&RAMSize=0x1000
)
ELSE IF CPUIS("MKE02Z64V*")
(
&PFlashSize=0x10000
&FlashType="FTMRH"
&RAMSize=0x1000
)
ELSE IF CPUIS("MKE06Z64V*")
(
&PFlashSize=0x10000
&FlashType="FTMRE"
&RAMSize=0x2000
)
ELSE IF CPUIS("MKE06Z128V*")
(
&PFlashSize=0x20000
&FlashType="FTMRE"
&RAMSize=0x4000
)
ELSE
(
PRINT %ERROR "FLASH size of CPU type is not supported by the script"
ENDDO
)
; Program Flash
IF &PFlashSize>=0x2000
FLASH.Create 1. 0x00000000--0x00001FFF 0x200 TARGET Long /CENSORSHIP 0x400--0x40F
IF &PFlashSize>=0x4000
FLASH.Create 1. 0x00002000--0x00003FFF 0x200 TARGET Long
IF &PFlashSize>=0x8000
FLASH.Create 1. 0x00004000--0x00007FFF 0x200 TARGET Long
IF &PFlashSize>=0x10000
FLASH.Create 1. 0x00008000--0x0000FFFF 0x200 TARGET Long
IF &PFlashSize>=0x20000
FLASH.Create 1. 0x00010000--0x0001FFFF 0x200 TARGET Long
IF "&FlashType"=="FTMRH"
(
IF &RAMSize>=0x1000
FLASH.TARGET 0x1FFFFC00 0x20000400 0x200 ~~/demo/arm/flash/long/ftmrh.bin
ELSE IF &RAMSize>=0x800
FLASH.TARGET 0x1FFFFE00 0x20000380 0x100 ~~/demo/arm/flash/long/ftmrh.bin
ELSE
(
PRINT %ERROR "Memory configuration preliminary not supported, please request an update"
ENDDO
)
)
ELSE IF "&FlashType"=="FTMRE"
(
FLASH.TARGET 0x1FFFFF00 0x20000200 0x80 ~~/demo/arm/flash/long/ftmre.bin /STACKSIZE 0x40
)
ELSE
(
PRINT %ERROR "Flash type preliminary not supported, please request an update"
ENDDO
)
FLASH.CLocK.AUTO
RETURN