; --------------------------------------------------------------------------------
; @Title: Timesys Linux Demo for TRACE32
; @Description:
;
;   This batchfile demonstrates the use of TRACE32 with Timesys Linux
;
;   The example is generated for an MPC8548CDS board using an ICD.
;   It will NOT run on any other board, but may be used as a template
;   for others.
;
;   The Linux kernel will be downloaded via ICD.
;
; @Keywords: awareness, linux, mpc8548cds, timesys
; @Author: DIE
; @Board: MPC8548CDS
; @Chip: MPC8548E
; @Copyright: (C) 1989-2014 Lauterbach GmbH, licensed for use with TRACE32(R) only
; --------------------------------------------------------------------------------
; $Id: linux.cmm 13987 2019-02-19 16:15:20Z kjmal $


; Starting Timesys Linux example with TRACE32:
; - Connect NULL modem cable to processor card
; - Start TRACE32
; - Switch on the board
; - TRACE32: do linux
; - Terminal: open a Shell and start "/usr/sbin/hello"


; Directory and path declarations
 &linux="linux-2.6.32"
 &build="build_powerpc-timesys-linux-gnuspe"
 &factory_path="S:\linux\Distributions\TimeSys\factory"
 &images_path="&factory_path/&build/images"
 &linux_path="&factory_path/&build/&linux"


 SCREEN.ALways      ; permanent update for internal terminal window
 ; screen.on        ; if you use external terminal


; Debugger Reset

 WinPAGE.RESet
 AREA.RESet
 WinPOS 0. 21. 70. 9. 0. 0. W000
 AREA.view

 PRINT "resetting..."

 RESet


; Initializing Debugger

 PRINT "initializing..."
 SYStem.CPU MPC8548
 ;SYStem.BdmClock 10.0MHz
 SYStem.Option MMUSPACES ON     ; enable space ids to virtual addresses
 SYStem.Up
 SETUP.IMASKASM ON
 Register.RESet


; Open a Code Window -- we like to see something

 WinPOS 0. 0. 75. 20.
 List.auto
 SCREEN.display


; Open serial terminal window on COM1

 WinPOS 35. 0. ,,,,, TERM.view
 TERM.METHOD COM COM1 115200. 8 NONE 1STOP NONE
 TERM.SIZE 80. 1000.
 TERM.Mode VT100
 TERM.SCROLL ON
 TERM.view


; Target Setup

 PRINT "target setup..."

 ; start u-boot to initialize the board
 Go.direct
 WAIT 5.s
 Break.direct


; Load the Linux kernel image and device tree blob

 ; Use the next lines only to load the Linux image into
 ; RAM using the debugger.

 PRINT "loading Linux kernel image..."
 Data.LOAD.Binary &images_path/uImage-2.6.32-ts-powerpc 0x01000000

 PRINT "loading device tree blob..."
 Data.LOAD.Binary &images_path/mpc8548cds.dtb 0x02000000


; Load the Linux kernel symbols into the debugger

 PRINT "loading Linux kernel symbols..."
 Data.LOAD.Elf &linux_path/vmlinux /NoCODE /StripPART "&linux"
 sYmbol.SourcePATH.Set &linux_path


; Start Linux via U-Boot

 Go.direct
 PRINT "starting Linux..."
 ; stop autoboot of U-Boot
 TERM.Out 0x0a
 WAIT 0.5s
 ; set boot arguments
 TERM.Out "setenv bootargs console=ttyS1,115200 root=/dev/nfs rw nfsroot=10.17.0.13:/root/mpc8548cds_test ip=10.17.0.42::10.17.0.254:255.255.255.0::eth1:off" 0xa
 WAIT 0.5s
 ; boot Linux from memory: bootm <kernel> <initrd> <dtb>
 TERM.Out "bootm 0x01000000 - 0x02000000" 0x0a


; Declare the MMU format to the debugger
 ; - table format is "LINUX"
 ; - table base address is at label "swapper_pg_dir"
 ; - kernel address translation
 ; Map the virtual kernel symbols to physical addresses to give
 ; the debugger access to it before CPU MMU is initialized

 PRINT "initializing debugger MMU..."
 MMU.FORMAT LINUX swapper_pg_dir 0xc0000000--0xcfffffff 0x00000000
 TRANSlation.Create 0xc0000000--0xcfffffff 0x00000000   ; map kernel pages at RAM start
 TRANSlation.COMMON 0xc0000000--0xffffffff              ; common area for kernel and processes
 TRANSlation.TableWalk ON   ; debugger uses a table walk to decode virtual addresses
 TRANSlation.ON             ; switch on debugger(!) address translation


; Initialize Linux Support

 ; Note that the Linux awareness needs the kernel symbols to work

 PRINT "initializing Linux support..."
 ; Choose the correct Linux major version below
 TASK.CONFIG ~~/demo/powerpc/kernel/linux/linux-2.x/linux.t32     ; loads Linux awareness for linux-2.x
 MENU.ReProgram ~~/demo/powerpc/kernel/linux/linux-2.x/linux.men  ; loads Linux menu  for linux-2.x
 ;TASK.CONFIG ~~/demo/powerpc/kernel/linux/linux-3.x/linux3.t32     ; loads Linux awareness for linux-3.x
 ;MENU.ReProgram ~~/demo/powerpc/kernel/linux/linux-3.x/linux.men  ; loads Linux menu  for linux-3.x


 ; Group kernel area to be displayed with red bar
 GROUP.Create "kernel" 0xc0000000--0xffffffff /RED


; Ok, we're done, let's continue

 PRINT "still starting Linux... (please wait)"
 WAIT 5.s

 PRINT "done."     ; done with loading and starting NetBSD


; --------------------------------------------------------------------------------
;       Application Debugging
;           e.g. "hello"
; --------------------------------------------------------------------------------

 ;LOCAL &extdir
 ;&extdir=TASK.GETDIR()
 ;DO &extdir/app_debug hello

 ENDDO

