; --------------------------------------------------------------------------------
; @Title: NAND FLASH Programming Script
; @Description: 
;   FLASH type: NAND FLASH(SAMSUNG, K9F2g08) connected 
; 
;   S(D)RAM address  : 0x00010000
;   Command Register : 0xF8000000  
;   Address Register : 0xF8000004
;   Data Register    : 0xF8000008
;
; @Keywords: NAND SAMSUNG K9F2g08
; @Author: JIM
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: nand-generic.cmm 4745 2017-09-19 14:44:24Z jjeong $

LOCAL &arg1
ENTRY &arg1
&arg1=STRing.UPpeR("&arg1")  // for example "PREPAREONLY"



//JTAG connection
  SYStem.Up

//  Configuration of the NAND Flash Controller and Bus
//  Data.Set <addr> %LE %LONG <data>
  ;Data.Set ASD:0xF8000034 %Long 0x80002222

  Break.RESet

  FLASHFILE.RESet
  
//FLASHFILE.CONFIG <Cmd_reg> <Addr_reg> <Data_reg>
  FLASHFILE.CONFIG 0xF8000000 0xF8000004 0xF8000008
  
// FLASHFILE.TARGET <code range>    <data range>       <Algorithm file>
  FLASHFILE.TARGET 0x10000++0x1FFF  0x12000++0x1FFF   ~~/demo/powerpc/flash/byte/nand2g08.bin

//Read FLASH Manufacture and Device ID
  FLASHFILE.GETID

//End of the test prepareonly
IF "&arg1"=="PREPAREONLY"
ENDDO


//Open the Dump Windows
  FLASHFILE.DUMP 0x0

//Put a list of bad blocks into area window for 2Gbit (256MB) size
  ;FLASHFILE.GETBADBLOCK 0x0--0xFFFFFFF

  DIALOG.YESNO "Program flash memory?"
  ENTRY &progflash
  IF &progflash 
  (
  //Erase NAND FLASH Main and Bad block inforamtion
    FLASHFILE.Erase 0x0--0xFFFFFFF 

	//Program NAND FLASH
    FLASHFILE.LOAD.binary  * 0x0 
    FLASHFILE.LOAD.binary  * 0x0 /ComPare
  )

ENDDO 