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

305 lines
8.1 KiB
Plaintext

; --------------------------------------------------------------------------------
; @Title: Generic script for Freescale MKV50 internal flash
;
; @Description:
;
; Example for flash declaration of Freescale MKV50 internal flash.
;
; Script arguments:
;
; DO mkv50 [PREPAREONLY] [CPU=<cpu>] [DUALPORT=0|1] [MASSERASE]
;
; PREPAREONLY only declares flash but does not execute flash programming
; example
;
; CPU=<cpu> selects CPU derivative <cpu>
;
; 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
;
; Example:
;
; DO ~~/demo/arm/flash/mkv50 CPU=MKV50FN1M0VMF12 DUALPORT=1 PREPAREONLY
;
; List of MKV50 derivatives and their configuration:
;
; CPU-Type Flash ProgFlash FlexNVM EEPROM RamSize
; type [Byte] [Byte] [Byte] [Byte]
; --------------------------------------------------------------------------------
; MKV58F1M0VMD24 3N 1MB - - 64KB
; MKV58F1M0VLQ24 3N 1MB - - 64KB
; MKV58F1M0VLL24 3N 1MB - - 64KB
; MKV56F1M0VMD24 3N 1MB - - 64KB
; MKV56F1M0VLQ24 3N 1MB - - 64KB
; MKV56F1M0VLL24 3N 1MB - - 64KB
; MKV58F512VMD24 3N 512KB - - 64KB
; MKV58F512VLQ24 3N 512KB - - 64KB
; MKV58F512VLL24 3N 512KB - - 64KB
; MKV56F512VMD24 3N 512KB - - 64KB
; MKV56F512VLQ24 3N 512KB - - 64KB
; MKV56F512VLL24 3N 512KB - - 64KB
;
; Flash Configuration Field:
;
; Byte offset Width Description
; --------------------------------------------------------------------------------
; 0x0400--0x0407 8 Backdoor Comparison Key.
; 0x0408--0x040B 4 Program flash protection bytes (FPROT0-3).
; 0x040F 1 Reserved
; 0x040E 1 Reserved
; 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: MKV5*
; @Author: FLC
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Rev: 10516 $
; $Id: mkv50.cmm 10516 2022-02-02 11:39:30Z bschroefel $
;
LOCAL &parameters
ENTRY %LINE &parameters
LOCAL &param_prepareonly &param_masserase
&param_prepareonly=(STRing.SCAN(STRing.UPpeR("&parameters"),"PREPAREONLY",0)!=-1)
&param_masserase=(STRing.SCAN(STRing.UPpeR("&parameters"),"MASSERASE",0)!=-1)
LOCAL &param_cpu
&param_cpu=STRing.SCANAndExtract(STRing.UPpeR("&parameters"),"CPU=","")
IF "&param_cpu"==""
(
&param_cpu=STRing.SCANAndExtract(STRing.UPpeR("&parameters"),"MKV50","")
IF "&param_cpu"!=""
&param_cpu="MKV50"+"&param_cpu"
ELSE
(
&param_cpu=STRing.SCANAndExtract(STRing.UPpeR("&parameters"),"K70","")
IF "&param_cpu"!=""
&param_cpu="K70"+"&param_cpu"
)
)
LOCAL &param_dualport
IF VERSION.BUILD.BASE()>=43441.
&param_dualport=STRing.SCANAndExtract(STRing.UPpeR("&parameters"),"DUALPORT=","1")
; ------------------------------------------------------------------------------
; Start debugging
IF (SYStem.MODE()<5)||&param_masserase
(
SYStem.RESet
IF "&param_cpu"!=""
SYStem.CPU &param_cpu
IF !CPUIS(MKV5*)
SYStem.CPU MKV5*
IF CABLE.TWOWIRE()
SYStem.CONFIG.DEBUGPORTTYPE SWD
ELSE
SYStem.CONFIG.DEBUGPORTTYPE JTAG
IF &param_masserase
GOSUB MassErase
ON.ERROR GOSUB Unsecure
SYStem.Up
ON.ERROR
)
; Unsecure device
IF VERSION.BUILD()>=34133.
(
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 &param_dualport
; 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:
LOCAL &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:0x4005200E = 0xC520 (Key 1)
Data.Assemble , strh r2,[r0] ;SD:0x4005200E = 0xD928 (Key 2)
Data.Assemble , strh r4,[r3] ;SD:0x40052000 = 0x0000 (Config register)
Data.Assemble , bkpt #0
Register.Set PC 0x20000000
Register.Set R0 0x4005200E
Register.Set R1 0xC520
Register.Set R2 0xD928
Register.Set R3 0x40052000
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 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("MKV5?F512*")
(
&PFlashSize=0x80000
)
ELSE IF CPUIS("MKV5?F1M0*")
(
&PFlashSize=0x100000
)
ELSE
(
PRINT %ERROR "FLASH size of CPU type is not supported by the script"
ENDDO
)
; Program Flash
IF &PFlashSize>=0x80000
(
FLASH.Create 1. 0x10000000--0x1003FFFF 0x2000 TARGET Quad /CENSORSHIP 0x10000400++0xf
FLASH.Create 1. 0x10040000--0x1007FFFF 0x2000 TARGET Quad
)
IF &PFlashSize>=0x100000
(
FLASH.Create 1. 0x10080000--0x100BFFFF 0x2000 TARGET Quad
FLASH.Create 1. 0x100C0000--0x100FFFFF 0x2000 TARGET Quad
)
LOCAL &access &option
IF &DualPort==0
&access="D"
ELSE
(
&access="EAHB"
&option="/DualPort"
)
FLASH.TARGET 0x00000000 &access:0x00002000 0x2000 ~~/demo/arm/flash/quad/ftfe_8k0k.bin &option
RETURN