;=================================================================================
; SMDKV210 CMM File : <SMDKV210_WCE_WMO.cmm>
; - Loading the binary and information files of S5PV210 Win CE/Mobile images.
;   * NB0 files : NK / Eboot / IPL / Steploader / NBL1 / NBL2
; - Attach the system and load informatioin files at Win CE/Mobile running system.
;   * EXE files : NK / FLASH / Eboot / IPL / Steploader / NBL1 / NBL2
; - Burning the SMDK UMON images to NAND memory.
; - Loading or Attach the Firmware binary image
;
;                            2008.10.27 / by AP Dev.System LSI.Samsung Electronics
;=================================================================================
;do SMDKV210_WCE_WMO_Header.cmm
 print " Reset System"
 
 sYmbol.RESet
 SYStem.RESet
 TASK.RESet
 Break.Delete
 MAP.RESet
 MMU.RESet
 Break.Delete

;*********************************************************************************
; Define Environment Variables
;*********************************************************************************
; [ Definition of Operation Mode]
&LOAD_BIN='L'
&ATTACH='A'
&BURN_UMON='U'
&FIRMWARE='W'
&BURN_OS='O'

; [ Definition of Image Type ]
&NK='N'
&FLASH='N'      ; NK and Flash images are same when loading.
&EBOOT='E'
&IPL='I'
&STEPLDR='S'
&NBL1='C'
&NBL2='D'
&SUPERIPL='U'

; [ Definition of System Attributes ]
&ONE_NAND='a'
&NAND_N8='b'	; Nand Normal 8bit
&NAND_A8='c'	; Nand Advanced 8bit
&NAND_M8='d'	; Nand MLC 8bit
&ROM='e'
&SRAM='f'

&S_JTAG=0		; Normal JTAG = 0, Secure JTAG = 1
&NEED_SYSINIT=1



; [ Definition of Others ]
&TRUE=(1==1)
&FALSE=(1==0)

;*********************************************************************************
; System UP and Setting the basic envirionments.
;*********************************************************************************

sYmbol.RESet
MMU.RESet
SYStem.CPU CORTEXA8
SYStem.JC 10mhz
SYStem.Option RB OFF
SYStem.Option mmu OFF
SYStem.Option dacr ON
SYStem.Option enreset OFF
SYStem.Option trst ON

term.reset
TrOnchip.Set SWI ON 
term.method ARMSWI
;term.gate
 
 ;;;;;;;;;; CoreSight access & setting (DAP)
area
diag 3400 
SYStem.MultiCore MEMORYACCESSPORT 0x0
SYStem.MultiCore DEBUGACCESSPORT 0x1
SYStem.MultiCore COREBASE	0x80005000  ; ARM core 
SYStem.MultiCore ETBBASE	0x80001000  ; ETB

SYS.MODE PREPARE	; DAP on in 2008.03 update version
wait 0.1s

; [ WinCE Awareness Loading ]
 
;TASK.CONFIG wince       ; loads WinCE awareness (wince.t32)
;MENU.ReProgram wince    ; loads WinCE menu (wince.men)


;---------------------------------------------------------------------------------
; AHB Initialization
;---------------------------------------------------------------------------------
IF &S_JTAG==1
(
	SYStem.Option enreset OFF
	SYStem.Option trst OFF

	;;; Secure JTAG open          
	print "Secure JTAG start"
	d.s AHB:0xF4080024 %LE %LONG 0x00000001	
	
	print "Secure JTAG password"
	d.s AHB:0xF4080020 %LE %LONG 0xc4d6edba
	d.s AHB:0xF4080020 %LE %LONG 0xaef4136a
	d.s AHB:0xF4080020 %LE %LONG 0x2c278959
	d.s AHB:0xF4080020 %LE %LONG 0x11ad221b
	d.s AHB:0xF4080020 %LE %LONG 0xf8d51722
	d.s AHB:0xF4080020 %LE %LONG 0xb4ee8a02
	d.s AHB:0xF4080020 %LE %LONG 0x513ced11
	d.s AHB:0xF4080020 %LE %LONG 0x316f0d0f
	d.s AHB:0xF4080020 %LE %LONG 0xee011800
	d.s AHB:0xF4080020 %LE %LONG 0xb3078f19
	d.s AHB:0xF4080020 %LE %LONG 0xcc050af3
	d.s AHB:0xF4080020 %LE %LONG 0x95312f08
	d.s AHB:0xF4080020 %LE %LONG 0xc9f4937e
	
	;;; waiting 80 clocks to complete hashing
	print "Secure JTAG hash polling"  
	wait 0.1s
	
	print "Secure JTAG finish"
	d.s AHB:0xF4080024 %LE %LONG 0x00000002
	
	print "Status REG=0x" data.long(AHB:0xF4080004)
	print "Result REG=0x" data.long(AHB:0xF4080008)
	print "Header Info REG=0x" data.long(AHB:0xF408000C)

	print "Authentication Status REG=0x" data.long(APB:0x80005FB8)  ; must be 0xAA
;	print "CPU debug Status REG=0x" data.long(APB:0x80005088) 
	wait 0.1s
)

; [ Disable Abort/Undefined Exception ]
TrOnchip.Set DABORT OFF
TrOnchip.Set PABORT OFF
TrOnchip.Set UNDEF OFF

&ONENAND_ERASE_BLOCK0=0

; [ SYStemp UP ]
print "system going up"
SYStem.Up

 r.s cpsr (r(cpsr)&0xffffff00)|0xd3  ; change to supervisor mode
 wait 0.1s


 ;------------------------------------------------------------------------------;
; System Controller                                                          ;
;------------------------------------------------------------------------------;
 if &TRUE
 (
   d.s ASD:0xe2700000 %LE %LONG 0x00000000		;watchdog timer disable
 )
 

;;;;; Erase Block #0 in OneNAND Flash ;;;;; 
;;; Cation : in order to this script 
;;;   Open 'Debug' for CD.PEDIT 
;;;   Execute 'Step' till ONENAND_ERASE_BLOCK0 script 
;;; 
IF &ONENAND_ERASE_BLOCK0==1 
( 
    Data.set ASD:0xB8000000 %LE %LONG 0x0E		; Unlock command toward OneNAND
    wait 1000.us
    Data.set ASD:0xB8000000 %LE %LONG 0x03		; Erase Block No.0 in OneNAND
    enddo
)

;r.s cpsr (r(cpsr)&0xffffff00)|0xd3
;PER.S C15:0x42F %LE %LONG 0x70000013   			; Peripheral Port Enable
; d.s ASD:0xEA200000 %LE %LONG 0x0 				; Disable Watchdog

;enddo

;*********************************************************************************
; Define Operating Mode and Image Type
;*********************************************************************************
; [ Select Operation Mode ]
; Select one of followings,  
; :  &LOAD_BIN / &ATTACH / &BURN_UMON / &FIRMWARE /&BURN_OS
&RUNNING_MODE=&LOAD_BIN










; [ Select Image Type ]
; Select one of followings,  
; :  &NK / &FLASH / &EBOOT / &IPL / &STEPLDR / &NBL1 / &NBL2 /&SUPERIPL
;   (When your running mode is BURN_UMON or FIRMWARE, following value has to be 0)
&IMAGE_TYPE=&EBOOT

 






 


; [ Select whether Using Booting-Rom or Not ]
; If you need to initialize Clock & DRAM, set following value to 1.
IF &NEED_SYSINIT==1
(                  
    do SMDKV210_SystemInit.cmm
)
;*********************************************************************************
; Define Image and Source code Path  
;*********************************************************************************
 &CEROOT_PATH="C:\WINCE600"
 
 &PROJECT_NAME="SMDKV210"

 &BSP_NAME="SMDKV210"
 &RELEASE_MODE="Release"

 &PLATFORM_PATH="&(CEROOT_PATH)\PLATFORM"
 &BSP_PATH="&(PLATFORM_PATH)\&(BSP_NAME)"
 &BSPSRC_PATH="&(BSP_PATH)\SRC"
 &REL_PATH="&(CEROOT_PATH)\OSDesigns\&(PROJECT_NAME)\&(PROJECT_NAME)\RelDir\&(BSP_NAME)_ARMV4I_&(RELEASE_MODE)"
 
;*********************************************************************************
;
; Load NK/Flash Image.
;
;********************************************************************************* 
IF &RUNNING_MODE==&LOAD_BIN
(
    IF &IMAGE_TYPE==&FLASH   ; Includes (&IMAGE_TYPE==&NK)   
    (
        ; [ Kernel Relocation Address ]
        ;&NK_TEXT= 0x80101000
        ;&NK_KDATA=0x83176000
        ;&NK_DATA= 0x80123000
        ;&NK_PDATA=0x83170000
        
        &CODE_START=0x40020000
        
        d.load.binary "&REL_PATH\nk.nb0" &(CODE_START)
        
        
        ;d.load.exe "&REL_PATH\nk.exe" /noclear /nocode /reloc .text at &(NK_TEXT) /reloc .KDATA at &(NK_KDATA) /reloc .data at &(NK_DATA) /reloc .pdata at &(NK_PDATA)
        sYmbol.SPATH + "&(BSPSRC_PATH)\OAL\OALLIB"
        sYmbol.SPATH + "&(BSPSRC_PATH)\Common\Timer"
        sYmbol.SPATH + "&(BSPSRC_PATH)\Common\Intr"
        sYmbol.SPATH + "&(BSPSRC_PATH)\Common\Power"

        ;--------------------------------------------------------------------------------
        ; Load DLLs if you need.
        ;--------------------------------------------------------------------------------
        &DLL_LOAD=0;
        IF &DLL_LOAD==1
        (
            ; Load touch.dll 
            &DLL1_TEXT=0x023c7000
            &DLL2_DATA=0x01e7c000
            d.load.exe "&REL_PATH\touch.dll" 0x8800:0 /noclear /nocode /reloc .text at &(DLL1_TEXT) /reloc .data at &(DLL2_DATA)
            sYmbol.SPATH + "&(BSPSRC_PATH)\Drivers\Touch"
        )

        ; [ Set Break point ]
        ;b.s OEMInit /onchip
        
        r.set pc &CODE_START
        print "End of Loading Flash/NK Module"
        enddo 
    )

;*********************************************************************************
;
; Load EBOOT Image.
;
;********************************************************************************* 
    IF &IMAGE_TYPE==&EBOOT   
    (
        ; [ Kernel Relocation Address ]
        &IMG_TEXT=0x87701000
        &IMG_DATA=0x87800000
        &CODE_START=0x47700000
        
        d.load.binary "&REL_PATH\eboot.nb0" &(CODE_START) /noclear
        d.load.exe "&REL_PATH\eboot.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
        sYmbol.SPATH + "&(BSPSRC_PATH)\KERNEL\OAL"
        sYmbol.SPATH + "&(BSPSRC_PATH)\BOOTLOADER\EBOOT"
        sYmbol.SPATH + "C:\WINCE600\PLATFORM\COMMON\SRC\COMMON\BOOT\BLCOMMON"
	sYmbol.SPATH + "C:\WINCE600\PLATFORM\COMMON\SRC\COMMON\BOOT\BOOTPART"
        r.set pc &CODE_START
        
        b.s BootloaderMain /onchip
        print "End of Loading EBOOT Module"
        enddo
    )

;*********************************************************************************
;
; Load IPL Image.
;
;********************************************************************************* 
    IF &IMAGE_TYPE==&IPL   
    (
        ; [ Kernel Relocation Address ]
        &IMG_TEXT=0x80139000
        &IMG_DATA=0x81346000
        
        &CODE_START=0x40138000
        d.load.binary "&REL_PATH\ipl.nb0" &(CODE_START) /noclear
        d.load.exe "&REL_PATH\ipl.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
        sYmbol.SPATH + "&(BSPSRC_PATH)\Kernel\OAL"
        sYmbol.SPATH + "&(BSPSRC_PATH)\Bootloader\IPL"
        sYmbol.SPATH + "&(BSPSRC_PATH)\Common\Nandflash\Fmd"
        
        r.set pc &CODE_START
        print "End of Loading IPL Module"
        enddo
    )

;*********************************************************************************
;
; Load STEPLOADER Image.
;
;********************************************************************************* 
    IF &IMAGE_TYPE==&STEPLDR   
    (
        ; [ Kernel Relocation Address ]
        &IMG_TEXT=0x00000000
        &IMG_DATA=0x47ff0000
        
        &CODE_START=0x00000000
        d.load.binary "&REL_PATH\stepldr.nb0" &(CODE_START) /noclear
        
        d.load.exe "&REL_PATH\stepldr.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
        sYmbol.SPATH + "&(BSPSRC_PATH)\Kernel\OAL"
        sYmbol.SPATH + "&(BSPSRC_PATH)\Bootloader\stepldr"
        sYmbol.SPATH + "&(BSPSRC_PATH)\Common\Nandflash\Fmd"
        
        r.set pc &CODE_START
        ;b.s _Read_512Byte /onchip
        print "End of Loading STEPLOADER Module"
        endd
    )

;*********************************************************************************
;
; Load NBL1 Image.
;
;********************************************************************************* 
    IF &IMAGE_TYPE==&NBL1   
    (
        ; [ Kernel Relocation Address ]
&IMG_TEXT=0x00001000
&IMG_DATA=0x47800000
        
&CODE_START=0x00000000
d.load.binary "&REL_PATH\ONBL1.nb0"  &(CODE_START) /noclear
        
d.load.exe "&REL_PATH\ONBL1.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
;sYmbol.SPATH + "&(BSPSRC_PATH)\OAL\OALLIB"
sYmbol.SPATH + "&(BSPSRC_PATH)\Bootloader\NAND\ONBL1"
        
r.set pc &CODE_START
        print "End of Loading NBL1 Module"
        enddo
    )


;*********************************************************************************
;
; Load NBL2 Image.
;
;********************************************************************************* 
    IF &IMAGE_TYPE==&NBL2   
    (
        ; [ Kernel Relocation Address ]
        &IMG_TEXT=0x80009000
        &IMG_DATA=0x800EE000
        
&CODE_START=0x41300000
d.load.binary "&REL_PATH\ONBL2.nb0" &(CODE_START) /noclear
        
;d.load.exe "&REL_PATH\ONBL2.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
;sYmbol.SPATH + "&(BSPSRC_PATH)\Kernel\OAL"
;sYmbol.SPATH + "&(BSPSRC_PATH)\Bootloader"
        
        r.set pc &CODE_START
print "End of Loading ONBL2 Module"
        enddo
    )
)

;*********************************************************************************
;
; Fusing Flash and SUPERIPL
;
;********************************************************************************* 

IF &RUNNING_MODE==&BURN_OS
(
    IF &IMAGE_TYPE==&FLASH   ; Includes (&IMAGE_TYPE==&NK)   
    (
        &CODE_START=0x47700000
        &LOAD_ADDRESS=0x41000000
        &IMG_TEXT=0x47701000
        &IMG_DATA=0x47800000
        
        d.load.binary "&REL_PATH\flash.bin" &(LOAD_ADDRESS)
        
        d.load.binary "&REL_PATH\eboot.nb0" &(CODE_START) /noclear
;d.load.exe "&REL_PATH\eboot.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
;sYmbol.SPATH + "&(BSPSRC_PATH)\KERNEL\OAL"
;sYmbol.SPATH + "&(BSPSRC_PATH)\BOOTLOADER\EBOOT"
        
        r.set pc &CODE_START
        
        print "End of Loading EBOOT and Flash.bin"
        
        enddo
    )

;*********************************************************************************
;
; Fusing superipl Image.
;
;********************************************************************************* 
    IF &IMAGE_TYPE==&SUPERIPL  
    (
        &CODE_START=0x47700000
        &LOAD_ADDRESS=0x41000000
        &IMG_TEXT=0x47701000
        &IMG_DATA=0x47800000
        
        ;Before Transferring, make ubootimage_nb0.ubi file by DNW
        d.load.binary "&REL_PATH\ubootimage_nb0.ubi" &(LOAD_ADDRESS)
        
        d.load.binary "&REL_PATH\eboot.nb0" &(CODE_START) /noclear
        d.load.exe "&REL_PATH\eboot.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
        sYmbol.SPATH + "&(BSPSRC_PATH)\KERNEL\OAL"
        sYmbol.SPATH + "&(BSPSRC_PATH)\BOOTLOADER\EBOOT"
        
        r.set pc &CODE_START
        
        print "End of Loading EBOOT and superipl"
        enddo
    )

;*********************************************************************************
;
; Fusing EBOOT Image.
;
;********************************************************************************* 
IF &IMAGE_TYPE==&EBOOT  
(
&CODE_START=0x40038000
&LOAD_ADDRESS=0x41000000
&IMG_TEXT=0x80039000
&IMG_DATA=0x80120000

;Before Transferring, make ubootimage_nb0.ubi file by DNW
d.load.binary "&REL_PATH\Eboot.bin" &(LOAD_ADDRESS)

d.load.binary "&REL_PATH\eboot.nb0" &(CODE_START) /noclear
d.load.exe "&REL_PATH\eboot.exe" /noclear /nocode /reloc .text at &(IMG_TEXT) /reloc .data at &(IMG_DATA)
sYmbol.SPATH + "&(BSPSRC_PATH)\KERNEL\OAL"
sYmbol.SPATH + "&(BSPSRC_PATH)\BOOTLOADER\EBOOT"

r.set pc &CODE_START

print "End of Loading EBOOT and Eboot.bin"
enddo
)

)


;*********************************************************************************
;
; Firmware Operating Mode
;
;********************************************************************************* 
;---------------------------------------------------------------------------------
; Running Firmware
;---------------------------------------------------------------------------------
IF &RUNNING_MODE==&FIRMWARE   
(
    &CODE_START=0x40000000
    d.load.binary "UMON_FW\c100.dram.bin" &(CODE_START) /noclear
    r.set pc &CODE_START
    print "End of Loading FIRMWARE Module"
    enddo
)
;---------------------------------------------------------------------------------
; Burnning UMON to NAND
;---------------------------------------------------------------------------------
IF &RUNNING_MODE==&BURN_UMON
(
    &CODE_START=0x40000000
    &UMON_NAND=0x41000000
    &UMON_DRAM=0x41004000
    d.load.binary "UMON_FW\c100_umon.nand.bin" &(UMON_NAND) /noclear
    d.load.binary "UMON_FW\c100_umon.dram.bin" &(UMON_DRAM) /noclear
    d.load.binary "UMON_FW\c100.dram.bin" &(CODE_START) /noclear
    r.set pc &CODE_START
    go
    
    print "End of Loading FIRMWARE Module"
    enddo
)






































































































































