; --------------------------------------------------------------------------------
; @Title: Example for flash declaration of Fujitsu MB9DF126 (Atlas) internal flash.
;
; @Description:
; Script arguments:
;
;  DO mb9df126 [PREPAREONLY]
;
;   PREPAREONLY only declares flash but does not execute flash programming example
;
; @Chip: MB9DF126
; @Author: WRD
; @Copyright: (C) 1989-2019 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Rev: 7602 $
; $Id: mb9df126.cmm 7602 2019-11-05 15:02:25Z bschroefel $

LOCAL &parameters &param_prepareonly
ENTRY %LINE &parameters
&param_prepareonly=(STRing.SCAN(STRing.UPpeR("&parameters"),"PREPAREONLY",0)!=-1)

; --------------------------------------------------------------------------------
; Start debugging

IF SYStem.MODE()<5
(
  PRIVATE &val
  SYStem.RESet
  SYStem.CPU MB9DF126
  SYStem.Option.ResBreak OFF
  SYStem.Option.WaitReset 2.ms
  ; connect and handle watchdog
  ; <timing critical>
  SYStem.Up

  &val=Data.Long(AD:0xB0608048)
  IF (&val&0x01000000)==0
  (
    ; disable watchdog
    Data.Set AD:0xB0608000 %Long 0xEDACCE55
    Data.Set AD:0xB0608048 %Long 0x01000000
  )
  ELSE IF (&val&0xb)==(0x1||0x2||0x3)
  (
    ; watchdog already locked - bug DBGEN not set
    DIALOG.OK "Watchdog enabled BUT DBGEN not set!"
    STOP
  )
  ; </timing critical>

  ; Initialize TCM RAM to have valid ECC
  Data.Set 0x0--0x1FFFF %Long 0x0
)

; --------------------------------------------------------------------------------
; Flash declaration

FLASH.RESet
; TC Flash large sectors (AXI address range)
FLASH.Create 1. 0x01000000--0x011FFFFF 0x40000 TARGET Long
; TC Flash small sectors (AXI address range)
FLASH.Create 3. 0x017E0000--0x017E3FFF  0x4000 TARGET Long /CENSORSHIP 0x17E0000--0x17E013F ; TCSDR1
FLASH.Create 3. 0x017E4000--0x017EFFFF  0x4000 TARGET Long
FLASH.Create 2. 0x017F0000--0x017F3FFF  0x4000 TARGET Long /CENSORSHIP 0x17F0000--0x17F01BF ; MSDR + TCSDR0
FLASH.Create 2. 0x017F4000--0x017FBFFF  0x4000 TARGET Long
FLASH.Create 2. 0x017FC000--0x017FFFFF  0x4000 TARGET Long /CENSORSHIP 0x17FFFE0--0x17FFFFF ; BDR

; Map TCM address range to AXI address range
FLASH.CreateALIAS 0x00800000--0x00FFFFFF 0x01000000
; Map AXI slave core0 address range to AXI address range
FLASH.CreateALIAS 0x05800000--0x05FFFFFF 0x01000000

FLASH.TARGET 0x1000 0x2000 0x1000 ~~/demo/arm/flash/long/fcr4.bin

; 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
)

ENDDO
