260 lines
6.8 KiB
Plaintext
260 lines
6.8 KiB
Plaintext
; --------------------------------------------------------------------------------
|
|
; @Title: Generic script for Freescale MK80 internal flash.
|
|
;
|
|
; @Description:
|
|
;
|
|
; Example for flash declaration of Freescale MK80 internal flash.
|
|
;
|
|
; Script arguments:
|
|
;
|
|
; DO mk80 [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/mk80 CPU=MK80FN256VDC15 PREPAREONLY
|
|
;
|
|
; List of MK80 derivatives and their configuration:
|
|
;
|
|
; CPU-Type ProgFlash RamSize
|
|
; [Byte] [Byte]
|
|
; --------------------------------------------------------------------------------
|
|
; MK80FN256VDC15 256KB 256KB
|
|
; MK80FN256VLL15 256KB 256KB
|
|
; MK81FN256VDC15 256KB 256KB
|
|
; MK81FN256VLL15 256KB 256KB
|
|
; MK82FN256VDC15 256KB 256KB
|
|
; MK82FN256VLL15 256KB 256KB
|
|
; MK84FN2M0CAU15R 2 MB 512KB
|
|
;
|
|
;
|
|
; 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: MK8*
|
|
; @Author: FLC
|
|
; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only
|
|
; --------------------------------------------------------------------------------
|
|
; $Rev: 10516 $
|
|
; $Id: mk80.cmm 10516 2022-02-02 11:39:30Z bschroefel $
|
|
;
|
|
|
|
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=","")
|
|
|
|
; ------------------------------------------------------------------------------
|
|
; Setup CPU
|
|
|
|
IF (SYStem.MODE()<5)||¶m_masserase
|
|
(
|
|
SYStem.RESet
|
|
|
|
IF "¶m_cpu"!=""
|
|
SYStem.CPU ¶m_cpu
|
|
IF !CPUIS(MK8*)
|
|
SYStem.CPU MK8*
|
|
|
|
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
|
|
|
|
; 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:
|
|
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 &PFlashSize &FlashDriver
|
|
|
|
; Setup configuration values
|
|
IF CPUIS("MK8?FN256???15")
|
|
(
|
|
&PFlashSize=0x40000
|
|
&FlashDriver="ftfa3n.bin"
|
|
)
|
|
ELSE IFCPUIS("MK8?FN2M0*")
|
|
(
|
|
&PFlashSize=0x200000
|
|
&flashdriver="ftfe5n.bin"
|
|
)
|
|
ELSE
|
|
(
|
|
PRINT %ERROR "FLASH size of CPU type is not supported by the script"
|
|
ENDDO
|
|
)
|
|
|
|
; Program Flash
|
|
IF &PFlashSize>=0x40000
|
|
FLASH.Create 1. 0x00000000++(&PFlashSize-1.) 0x1000 TARGET Long /CENSORSHIP 0x400++0xf
|
|
|
|
FLASH.TARGET 0x1FFFF000 0x20000400 0x1000 ~~/demo/arm/flash/long/&FlashDriver
|
|
|
|
RETURN
|