; -------------------------------------------------------------------------------- ; @Title: Flash declaration for Freescale MKE1* internal flash. ; ; @Description: ; ; Flash declaration of Freescale MKE1* internal flash. ; ; Script arguments: ; ; DO mke0 [PREPAREONLY] [CPU=] [MASSERASE] ; ; PREPAREONLY only declares flash but does not execute flash programming ; ; CPU= selects CPU derivative . 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/mke1 CPU=MKE14F256VLH16 PREPAREONLY ; ; List of MKE1* derivatives and their configuration: ; ; CPU-Type Flash ProgFlash RamSize ; Type [Byte] [Byte] ; -------------------------------------------------------------------------------- ; MKE14F256VLH16 FTFE 256kB 32kB ; MKE14F256VLL16 FTFE 256kB 32kB ; MKE14F512VLH16 FTFE 512kB 64kB ; MKE14F512VLL16 FTFE 512kB 64kB ; MKE14Z128VLH7 FTFE 128kB 16kB ; MKE14Z128VLL7 FTFE 128kB 16kB ; MKE14Z256VLH7 FTFE 256kB 32kB ; MKE14Z256VLL7 FTFE 256kB 32kB ; -------------------------------------------------------------------------------- ; MKE15Z128VLH7 FTFE 128kB 16kB ; MKE15Z128VLL7 FTFE 128kB 16kB ; MKE15Z256VLH7 FTFE 256kB 32kB ; MKE15Z256VLL7 FTFE 256kB 32kB ; -------------------------------------------------------------------------------- ; MKE16F256VLH16 FTFE 256kB 32kB ; MKE16F256VLL16 FTFE 256kB 32kB ; MKE16F512VLH16 FTFE 512kB 64kB ; MKE16F512VLL16 FTFE 512kB 64kB ; -------------------------------------------------------------------------------- ; MKE18F256VLH16 FTFE 256kB 32kB ; MKE18F256VLL16 FTFE 256kB 32kB ; MKE18F512VLH16 FTFE 512kB 64kB ; MKE18F512VLL16 FTFE 512kB 64kB ; ; 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: FLC ; @Chip: MKE1* ; @Copyright: (C) 1989-2022 Lauterbach GmbH, licensed for use with TRACE32(R) only ; -------------------------------------------------------------------------------- ; $Rev: 10516 $ ; $Id: mke1.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(MKE1*) SYStem.CPU MKE1* SYStem.CONFIG.DEBUGPORTTYPE SWD SYStem.Option ResBreak OFF SYStem.Option WaitReset 500us 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 GOSUB DisableWatchdog ; ------------------------------------------------------------------------------ ; 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: ( IF CPUIS("MKE1?F*")||CPUIS("MKE1?Z*") ( Frame.SWAP Register.Set R0 0x40052000 Register.Set R1 0xD928C520 Register.Set R2 0xffff Register.Set R3 0x80 Data.Set VM:0x20000000++0x2F %Long 0 Data.Assemble VMT:0x20000000 str r1, [r0, #4] Data.Assemble , str r2, [r0, #8] Data.Assemble , ldr r5, [r0, #0] Data.Assemble , bics r5, r3 Data.Assemble , str r5, [r0, #0] Data.Assemble , bkpt #0x0 Data.COPY SD:0x20000000++0x2F VM:0x20000030 Data.COPY VM:0x20000000++0x2F SD:0x20000000 Register.Set PC 0x20000000 Go.direct WAIT !STATE.RUN() Frame.SWAP 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: ( PRIVATE &FlashDriver &PFlashSize &FlexNVMSize &FlexRAMSize &DFlashSize &EepromSize &PFlashSectorSize &DFlashSectorSize &DFlashSize=0x0 &EepromSize=0x0 ; Setup configuration values IF CPUIS("MKE1?Z128*") ( &PFlashSize=0x20000 &FlexNVMSize=0x8000 &FlexRAMSize=0x800 &PFlashSectorSize=0x800 &DFlashSectorSize=0x800 &FlashDriver="ftfe_2k2k.bin" ) ELSE IF CPUIS("MKE1?Z256*") ( &PFlashSize=0x40000 &FlexNVMSize=0x8000 &FlexRAMSize=0x800 &PFlashSectorSize=0x800 &DFlashSectorSize=0x800 &FlashDriver="ftfe_2k2k.bin" ) ELSE IF CPUIS("MKE1?F256*") ( &PFlashSize=0x40000 &FlexNVMSize=0x10000 &FlexRAMSize=0x1000 &PFlashSectorSize=0x1000 &DFlashSectorSize=0x800 &FlashDriver="ftfe_4k2k.bin" ) ELSE IF CPUIS("MKE1?F512*") ( &PFlashSize=0x80000 &FlexNVMSize=0x10000 &FlexRAMSize=0x1000 &PFlashSectorSize=0x1000 &DFlashSectorSize=0x800 &FlashDriver="ftfe_4k2k.bin" ) ELSE ( PRINT %ERROR "FLASH size of CPU type is not supported by the script" ENDDO ) GOSUB getDFlashEepromSize "&PFlashSize" "&FlexNVMSize" "&FlexRAMSize" RETURNVALUES &DFlashSize &EepromSize ; Program Flash FLASH.Create 1. 0x00000000++(&PFlashSize-1.) &PFlashSectorSize TARGET Quad /CENSORSHIP 0x400--0x40F IF &DFlashSize>0x0 FLASH.Create 2. 0x10000000++(&DFlashSize-0x1) &DFlashSectorSize TARGET Quad IF &EepromSize>0x0 FLASH.Create 3. 0x14000000++(&EepromSize-0x1) &EepromSize TARGET Long &EepromSize FLASH.TARGET 0x1FFFFC00 0x20000400 0x800 ~~/demo/arm/flash/quad/&FlashDriver RETURN ) getDFlashEepromSize: ;(PFlashSize, FlexNvmSize, &FlexRAMSize) ( PARAMETERS &PFlashSize &FlexNVMSize &FlexRAMSize PRIVATE &DEPART &DFlashSize &EepromSize &DEPART=(Data.Long(AD:0x4004804C)>>12.)&0xf &DFlashSize=0x0 IF (&FlexNVMSize==(0x8000))&&(&PFlashSize==(0x20000||0x40000)) ( ; 128kB and 256kB configurations with 32kB FlexNVM IF (&DEPART==(0x0||0xb||0xf)) &DFlashSize=0x8000 ELSE IF (&DEPART==(0x9)) &DFlashSize=0x2000 ELSE IF (&DEPART==(0x3||0x8)) &DFlashSize=0x0 ELSE PRINT "Unknown DFlash Size - DEPART invalid" &EepromSize=0x0 ) ELSE IF (&FlexNVMSize==(0x10000))&&(&PFlashSize==(0x40000||0x80000)) ( ; 256KB, 512kB configurations with 64kB FlexNVM IF (&DEPART==(0x0||0xc||0xf)) &DFlashSize=0x10000 ELSE IF (&DEPART==(0x3||0xb)) &DFlashSize=0x8000 ELSE IF (&DEPART==(0xa)) &DFlashSize=0x4000 ELSE IF (&DEPART==(0x4||0x8)) &DFlashSize=0x0 ELSE PRINT "Unknown DFlash Size - DEPART invalid" &EepromSize=0x0 ) ELSE ( PRINT "Unknown DFlash Size - Flash Controller unknown" ) RETURN "&DFlashSize" "&EepromSize" )