From 29095ab30ed7fc750305e3b84eed0fdeebf508dc Mon Sep 17 00:00:00 2001 From: pvvx Date: Wed, 14 Sep 2016 15:50:38 +0300 Subject: [PATCH] add OpenOCD --- openocd/Check_Jtag.sh | 77 +++++++++ openocd/SetupGDB_NORMAL.sh | 20 +++ openocd/ameba1.cfg | 124 +++++++++++++++ openocd/rtl_gdb_debug.txt | 57 +++++++ openocd/rtl_gdb_debug_jlink.txt | 57 +++++++ openocd/rtl_gdb_debug_openocd.txt | 57 +++++++ openocd/rtl_gdb_flash_write.txt | 198 +++++++++++++++++++++++ openocd/rtl_gdb_flash_write_jlink.txt | 199 ++++++++++++++++++++++++ openocd/rtl_gdb_flash_write_openocd.txt | 198 +++++++++++++++++++++++ openocd/rtl_gdb_ramdebug.txt | 60 +++++++ openocd/rtl_gdb_ramdebug_jlink.txt | 112 +++++++++++++ openocd/rtl_gdb_ramdebug_openocd.txt | 60 +++++++ openocd/run_gdb.bat | 3 + openocd/run_openocd.bat | 3 + 14 files changed, 1225 insertions(+) create mode 100644 openocd/Check_Jtag.sh create mode 100644 openocd/SetupGDB_NORMAL.sh create mode 100644 openocd/ameba1.cfg create mode 100644 openocd/rtl_gdb_debug.txt create mode 100644 openocd/rtl_gdb_debug_jlink.txt create mode 100644 openocd/rtl_gdb_debug_openocd.txt create mode 100644 openocd/rtl_gdb_flash_write.txt create mode 100644 openocd/rtl_gdb_flash_write_jlink.txt create mode 100644 openocd/rtl_gdb_flash_write_openocd.txt create mode 100644 openocd/rtl_gdb_ramdebug.txt create mode 100644 openocd/rtl_gdb_ramdebug_jlink.txt create mode 100644 openocd/rtl_gdb_ramdebug_openocd.txt create mode 100644 openocd/run_gdb.bat create mode 100644 openocd/run_openocd.bat diff --git a/openocd/Check_Jtag.sh b/openocd/Check_Jtag.sh new file mode 100644 index 0000000..e5a80d4 --- /dev/null +++ b/openocd/Check_Jtag.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +#=============================================================================== +CURRENT_UTILITY_DIR=$(pwd) +GDBSCPTFILE="../../../component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_flash_write.txt" + +#=============================================================================== +RLXSTS=$(ps -W | grep "rlx_probe_driver.exe" | grep -v "grep" | wc -l) +echo $RLXSTS +JLKSTS=$(ps -W | grep "JLinkGDBServer.exe" | grep -v "grep" | wc -l) +echo $JLKSTS + +echo $CURRENT_UTILITY_DIR + +#=============================================================================== +#make the new string for being written +if [ $RLXSTS = 1 ] +then + echo "probe get" + + #------------------------------------------- + LINE_NUMBER=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $1}') + DEFAULT_STR=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $2}') + #echo $LINE_NUMBER + echo $DEFAULT_STR + STRLEN_DFT=$(expr length "$DEFAULT_STR") + DEFAULT_STR="#monitor reset 1" + echo $DEFAULT_STR + #------------------------------------------- + SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR" + sed -i "$SED_PARA" $GDBSCPTFILE + + #=========================================== + LINE_NUMBER=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $1}') + DEFAULT_STR=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $2}') + #echo $LINE_NUMBER + echo $DEFAULT_STR + STRLEN_DFT=$(expr length "$DEFAULT_STR") + DEFAULT_STR="#monitor sleep 20" + echo $DEFAULT_STR + #------------------------------------------- + SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR" + sed -i "$SED_PARA" $GDBSCPTFILE +else + +if [ $JLKSTS = 1 ] +then + echo "jlink get" + + #------------------------------------------- + LINE_NUMBER=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $1}') + DEFAULT_STR=$(grep -n "monitor reset " $GDBSCPTFILE | awk -F":" '{print $2}') + #echo $LINE_NUMBER + echo $DEFAULT_STR + STRLEN_DFT=$(expr length "$DEFAULT_STR") + DEFAULT_STR="monitor reset 1" + echo $DEFAULT_STR + #------------------------------------------- + SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR" + sed -i "$SED_PARA" $GDBSCPTFILE + + #=========================================== + LINE_NUMBER=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $1}') + DEFAULT_STR=$(grep -n "monitor sleep " $GDBSCPTFILE | awk -F":" '{print $2}') + #echo $LINE_NUMBER + echo $DEFAULT_STR + STRLEN_DFT=$(expr length "$DEFAULT_STR") + DEFAULT_STR="monitor sleep 20" + echo $DEFAULT_STR + #------------------------------------------- + SED_PARA="$LINE_NUMBER""c""$DEFAULT_STR" + sed -i "$SED_PARA" $GDBSCPTFILE + +fi +fi + +#=============================================================================== diff --git a/openocd/SetupGDB_NORMAL.sh b/openocd/SetupGDB_NORMAL.sh new file mode 100644 index 0000000..ba44ef8 --- /dev/null +++ b/openocd/SetupGDB_NORMAL.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +#=============================================================================== +CURRENT_UTILITY_DIR=$(pwd) +echo "..." +echo $CURRENT_UTILITY_DIR +RAMFILENAME="./application/Debug/bin/ram_all.bin" +echo $RAMFILENAME +#RAMFILENAME="ram_2.bin" +GDBSCPTFILE="../../../component/soc/realtek/8195a/misc/gcc_utility/rtl_gdb_flash_write.txt" + +#=============================================================================== +#get file size +RAM_FILE_SIZE=$(stat -c %s $RAMFILENAME) +RAM_FILE_SIZE_HEX=`echo "obase=16; $RAM_FILE_SIZE"|bc` + +echo "size "$RAM_FILE_SIZE" --> 0x"$RAM_FILE_SIZE_HEX + +echo "set \$RamFileSize = 0x$RAM_FILE_SIZE_HEX" > fwsize.gdb +exit diff --git a/openocd/ameba1.cfg b/openocd/ameba1.cfg new file mode 100644 index 0000000..963b196 --- /dev/null +++ b/openocd/ameba1.cfg @@ -0,0 +1,124 @@ +# Main file for Ameba1 series Cortex-M3 parts +# +# !!!!!! +# + +set CHIPNAME rtl8195a +set CHIPSERIES ameba1 + +# Adapt based on what transport is active. +source [find target/swj-dp.tcl] + +if { [info exists CHIPNAME] } { + set _CHIPNAME $CHIPNAME +} else { + error "CHIPNAME not set. Please do not include ameba1.cfg directly." +} + +if { [info exists CHIPSERIES] } { + # Validate chip series is supported + if { $CHIPSERIES != "ameba1" } { + error "Unsupported chip series specified." + } + set _CHIPSERIES $CHIPSERIES +} else { + error "CHIPSERIES not set. Please do not include ameba1.cfg directly." +} + +if { [info exists CPUTAPID] } { + # Allow user override + set _CPUTAPID $CPUTAPID +} else { + # Ameba1 use a Cortex M3 core. + if { $_CHIPSERIES == "ameba1" } { + if { [using_jtag] } { + set _CPUTAPID 0x4ba00477 + } { + set _CPUTAPID 0x2ba01477 + } + } +} + +swj_newdap $_CHIPNAME cpu -irlen 4 -expected-id $_CPUTAPID + +set _TARGETNAME $_CHIPNAME.cpu +target create $_TARGETNAME cortex_m -chain-position $_TARGETNAME + + +# Run with *real slow* clock by default since the +# boot rom could have been playing with the PLL, so +# we have no idea what clock the target is running at. +adapter_khz 2000 + +# delays on reset lines +adapter_nsrst_delay 200 +if {[using_jtag]} { + jtag_ntrst_delay 200 +} + + +# Ameba1 (Cortex M3 core) support SYSRESETREQ +if {![using_hla]} { + # if srst is not fitted use SYSRESETREQ to + # perform a soft reset + cortex_m reset_config sysresetreq +} + +$_TARGETNAME configure -event reset-init {ameba1_init} + +# Ameba1 SDRAM enable +proc ameba1_init { } { + # init System + mww 0x40000014 0x00000021 + sleep 10 + mww 0x40000304 0x1fc00002 + sleep 10 + mww 0x40000250 0x00000400 + sleep 10 + mww 0x40000340 0x00000000 + sleep 10 + mww 0x40000230 0x0000dcc4 + sleep 10 + mww 0x40000210 0x00011117 + sleep 10 + mww 0x40000210 0x00011157 + sleep 10 + mww 0x400002c0 0x00110011 + sleep 10 + mww 0x40000320 0xffffffff + sleep 10 + # init SDRAM + mww 0x40000040 0x00fcc702 + sleep 10 + mdw 0x40000040 + mww 0x40005224 0x00000001 + sleep 10 + mww 0x40005004 0x00000208 + sleep 10 + mww 0x40005008 0xffffd000 + sleep 13 + mww 0x40005020 0x00000022 + sleep 13 + mww 0x40005010 0x09006201 + sleep 13 + mww 0x40005014 0x00002611 + sleep 13 + mww 0x40005018 0x00068413 + sleep 13 + mww 0x4000501c 0x00000042 + sleep 13 + mww 0x4000500c 0x700 ;# set Idle + sleep 20 + mww 0x40005000 0x1 ;# start init + sleep 100 + mdw 0x40005000 + mww 0x4000500c 0x600 ;# enter memory mode + sleep 30 + + mww 0x40005008 0x00000000 ;# 0xf00 + ;# mww 0x40005008 0x00000f00 + sleep 3 + mww 0x40000300 0x0006005e ;# 0x5e + ;# mww 0x40000300 0x0000005e + sleep 3 +} diff --git a/openocd/rtl_gdb_debug.txt b/openocd/rtl_gdb_debug.txt new file mode 100644 index 0000000..c08c920 --- /dev/null +++ b/openocd/rtl_gdb_debug.txt @@ -0,0 +1,57 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote :3333 + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +monitor reset init +monitor sleep 20 +monitor halt +#=============================================================================== +#Load flash download file +file ../flash.elf + +#skip sdram init, it has been init in openocd config +set {int}0x40000210=0x211157 +#x /1xw 0x40000210 + +b main +continue +clear main +#Load the file +#lo + + + + diff --git a/openocd/rtl_gdb_debug_jlink.txt b/openocd/rtl_gdb_debug_jlink.txt new file mode 100644 index 0000000..3deec30 --- /dev/null +++ b/openocd/rtl_gdb_debug_jlink.txt @@ -0,0 +1,57 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote :10000 + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +monitor reset 1 +monitor sleep 20 +monitor clrbp +#=============================================================================== +#Load flash download file +file ./application/Debug/bin/application.axf + +#skip sdram init, it has been init in openocd config +set {int}0x40000210=0x211157 +#x /1xw 0x40000210 + +b main +continue +clear main +#Load the file +#lo + + + + diff --git a/openocd/rtl_gdb_debug_openocd.txt b/openocd/rtl_gdb_debug_openocd.txt new file mode 100644 index 0000000..48a2705 --- /dev/null +++ b/openocd/rtl_gdb_debug_openocd.txt @@ -0,0 +1,57 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote localhost:10000 + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +monitor reset init +monitor sleep 20 +monitor halt +#=============================================================================== +#Load flash download file +file ../flash.elf + +#skip sdram init, it has been init in openocd config +set {int}0x40000210=0x211157 +#x /1xw 0x40000210 + +b main +continue +clear main +#Load the file +#lo + + + + diff --git a/openocd/rtl_gdb_flash_write.txt b/openocd/rtl_gdb_flash_write.txt new file mode 100644 index 0000000..9920c21 --- /dev/null +++ b/openocd/rtl_gdb_flash_write.txt @@ -0,0 +1,198 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote :10000 + +#=============================================================================== +#set file path +set $BINFILE = "./application/Debug/bin/ram_all.bin" + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +#set JTAG and external SRAM +monitor reset init +monitor halt +monitor sleep 20 +#=============================================================================== +#Variables declaration (1) +#binary file size +set $RamFileSize = 0x0000 +source fwsize.gdb +printf "-------------------------------\n" +printf "RamFileSize: %x\n",$RamFileSize +printf "-------------------------------\n" + +#=============================================================================== +set $FLASHDATBUFSIZE = 0x800 + +#=============================================================================== +#define PERI_ON_BASE 0x40000000 +set $PERI_ON_BASE = 0x40000000 +#define REG_SOC_PERI_FUNC0_EN 0x0218 +set $REG_SOC_PERI_FUNC0_EN = 0x0210 + +#define SPI_FLASH_BASE 0x4000000 +set $SPI_FLASH_BASE = 0x98000000 + +#------------------------------------------------------------------ +set $Temp = 0x0 + +#=============================================================================== +#Load flash download file +file ../../../component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf + +#Load the file +lo + +printf "Load flash controller.\n" +#=============================================================================== +#Set for executing flash controller funciton +set $Temp = {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) +p /x $Temp + +set $Temp = ($Temp | (0x01 << 27)) +p /x $Temp + +set {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) = $Temp +printf "....\n" +printf "wakeup bit(%x):%x\n", ($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN), {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) +#=============================================================================== +#Direct the startup wake function to flash program function +#the function pointer address +#set $testpointer = 0x200006b4 +#set $testpointer2 = 0x200006b8 +#set $FuntionPointer = 0x200006c4 +#set $FPTemp = 0x200a08e9 +#set {int}($FuntionPointer) = $FPTemp +#printf "testpointer(%x):%x\n", $testpointer, {int}$testpointer +#printf "testpointer2(%x):%x\n", $testpointer2, {int}$testpointer2 +#printf "FuntionPointer(%x):%x\n", $FuntionPointer, {int}$FuntionPointer + +#=============================================================================== +#Load file +# restore filename [binary] bias start end +# Restore the contents of file filename into memory. +# The restore command can automatically recognize any known bfd file format, except for raw binary. +# To restore a raw binary file you must specify the optional keyword binary after the filename. +#=============================================================================== + +set $LoopNum = ($RamFileSize / $FLASHDATBUFSIZE) +printf "LoopNum = %x\n", $LoopNum +set $TailSize = ($RamFileSize % $FLASHDATBUFSIZE) +printf "TailSize = %x\n", $TailSize + +printf "global variables\n" + +set $FLASHDATSRC = 0x0 +set $FILESTARTADDR = 0X0 +set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE + +#b RtlFlashProgram:StartOfFlashBlockWrite +b rtl_flash_download.c:489 +b rtl_flash_download.c:524 +#b Rtl_flash_control.c:RtlFlashProgram + +#continue to 489 +c + +# Mode 0: erase full chip, Mode 1: skip calibration section and erase to firmware size +set EraseMode=1 +print EraseMode +set FirmwareSize=$RamFileSize +print FirmwareSize + +#continue to 524 +c + +#printf "...\n" +set $FLASHDATSRC = FlashDatSrc +printf "FlashDatSrc:%x\n", $FLASHDATSRC + +printf "FlashBlockWriteSize " +set FlashBlockWriteSize = $FLASHDATBUFSIZE +#p /x FlashBlockWriteSize +printf "FlashBlockWriteSize:%x\n", FlashBlockWriteSize + +printf "FlashAddrForWrite" +set FlashAddrForWrite = 0x0 + + + +printf "Flash write start...\n" +set $LoopCnt = 0 +while ($LoopCnt < $LoopNum) + p /x FlashAddrForWrite + restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR + c + + printf "FILEENDADDR" + p /x $FILEENDADDR + set FlashBlockWriteSize = $FLASHDATBUFSIZE + set FlashAddrForWrite = $FILEENDADDR + set $FILESTARTADDR = $FILEENDADDR + set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE + + set $LoopCnt = $LoopCnt + 0x01 +end + +#set FlashBlockWriteSize = $FLASHDATBUFSIZE +#set FlashAddrForWrite = $FILEENDADDR +#set $FILESTARTADDR = $FILEENDADDR +set $FILEENDADDR = $FILESTARTADDR + $TailSize +restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR +c + +#Set complete flas +set FlashWriteComplete = 0x1 + +printf "dump for check\n" + +set $LoopCnt = 0 +set $dumpaddr = 0 + +set $dumpstartaddr = $SPI_FLASH_BASE +set $dumpendaddr = $SPI_FLASH_BASE + $RamFileSize +printf "start addr of dumping" +p /x $dumpstartaddr +printf "end addr of dumping" +p /x $dumpendaddr +dump binary memory ./application/Debug/bin/dump.bin $dumpstartaddr $dumpendaddr + + +delete +b rtl_flash_download.c:556 +c + +quit +#=============================================================================== + diff --git a/openocd/rtl_gdb_flash_write_jlink.txt b/openocd/rtl_gdb_flash_write_jlink.txt new file mode 100644 index 0000000..9260f53 --- /dev/null +++ b/openocd/rtl_gdb_flash_write_jlink.txt @@ -0,0 +1,199 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote :10000 + +#=============================================================================== +#set file path +set $BINFILE = "./application/Debug/bin/ram_all.bin" + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +#set JTAG and external SRAM +monitor reset 1 +monitor sleep 20 +monitor clrbp +#=============================================================================== +#Variables declaration (1) +#binary file size +set $RamFileSize = 0x0000 +source fwsize.gdb +printf "-------------------------------\n" +printf "RamFileSize: %x\n",$RamFileSize +printf "-------------------------------\n" + +#=============================================================================== +set $FLASHDATBUFSIZE = 0x800 + +#=============================================================================== +#define PERI_ON_BASE 0x40000000 +set $PERI_ON_BASE = 0x40000000 +#define REG_SOC_PERI_FUNC0_EN 0x0218 +set $REG_SOC_PERI_FUNC0_EN = 0x0210 + +#define SPI_FLASH_BASE 0x4000000 +set $SPI_FLASH_BASE = 0x98000000 + +#------------------------------------------------------------------ +set $Temp = 0x0 + +#=============================================================================== +#Load flash download file +file ../../../component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf + +#Load the file +lo + +printf "Load flash controller.\n" + +#=============================================================================== +#Set for executing flash controller funciton +set $Temp = {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) +p /x $Temp + +set $Temp = ($Temp | (0x01 << 27)) +p /x $Temp + +set {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) = $Temp +printf "....\n" +printf "wakeup bit(%x):%x\n", ($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN), {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) +#=============================================================================== +#Direct the startup wake function to flash program function +#the function pointer address +#set $testpointer = 0x200006b4 +#set $testpointer2 = 0x200006b8 +#set $FuntionPointer = 0x200006c4 +#set $FPTemp = 0x200a08e9 +#set {int}($FuntionPointer) = $FPTemp +#printf "testpointer(%x):%x\n", $testpointer, {int}$testpointer +#printf "testpointer2(%x):%x\n", $testpointer2, {int}$testpointer2 +#printf "FuntionPointer(%x):%x\n", $FuntionPointer, {int}$FuntionPointer + +#=============================================================================== +#Load file +# restore filename [binary] bias start end +# Restore the contents of file filename into memory. +# The restore command can automatically recognize any known bfd file format, except for raw binary. +# To restore a raw binary file you must specify the optional keyword binary after the filename. +#=============================================================================== + +set $LoopNum = ($RamFileSize / $FLASHDATBUFSIZE) +printf "LoopNum = %x\n", $LoopNum +set $TailSize = ($RamFileSize % $FLASHDATBUFSIZE) +printf "TailSize = %x\n", $TailSize + +printf "global variables\n" + +set $FLASHDATSRC = 0x0 +set $FILESTARTADDR = 0X0 +set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE + +#b RtlFlashProgram:StartOfFlashBlockWrite +b rtl_flash_download.c:489 +b rtl_flash_download.c:524 +#b Rtl_flash_control.c:RtlFlashProgram + +#continue to 489 +c + +# Mode 0: erase full chip, Mode 1: skip calibration section and erase to firmware size +set EraseMode=1 +print EraseMode +set FirmwareSize=$RamFileSize +print FirmwareSize + +#continue to 524 +c + +#printf "...\n" +set $FLASHDATSRC = FlashDatSrc +printf "FlashDatSrc:%x\n", $FLASHDATSRC + +printf "FlashBlockWriteSize " +set FlashBlockWriteSize = $FLASHDATBUFSIZE +#p /x FlashBlockWriteSize +printf "FlashBlockWriteSize:%x\n", FlashBlockWriteSize + +printf "FlashAddrForWrite" +set FlashAddrForWrite = 0x0 + + + +printf "Flash write start...\n" +set $LoopCnt = 0 +while ($LoopCnt < $LoopNum) + p /x FlashAddrForWrite + restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR + c + + printf "FILEENDADDR" + p /x $FILEENDADDR + set FlashBlockWriteSize = $FLASHDATBUFSIZE + set FlashAddrForWrite = $FILEENDADDR + set $FILESTARTADDR = $FILEENDADDR + set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE + + set $LoopCnt = $LoopCnt + 0x01 +end + +#set FlashBlockWriteSize = $FLASHDATBUFSIZE +#set FlashAddrForWrite = $FILEENDADDR +#set $FILESTARTADDR = $FILEENDADDR +set $FILEENDADDR = $FILESTARTADDR + $TailSize +restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR +c + +#Set complete flas +set FlashWriteComplete = 0x1 + +printf "dump for check\n" + +set $LoopCnt = 0 +set $dumpaddr = 0 + +set $dumpstartaddr = $SPI_FLASH_BASE +set $dumpendaddr = $SPI_FLASH_BASE + $RamFileSize +printf "start addr of dumping" +p /x $dumpstartaddr +printf "end addr of dumping" +p /x $dumpendaddr +dump binary memory ./application/Debug/bin/dump.bin $dumpstartaddr $dumpendaddr + + +delete +b rtl_flash_download.c:556 +c + +quit +#=============================================================================== + diff --git a/openocd/rtl_gdb_flash_write_openocd.txt b/openocd/rtl_gdb_flash_write_openocd.txt new file mode 100644 index 0000000..9920c21 --- /dev/null +++ b/openocd/rtl_gdb_flash_write_openocd.txt @@ -0,0 +1,198 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote :10000 + +#=============================================================================== +#set file path +set $BINFILE = "./application/Debug/bin/ram_all.bin" + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +#set JTAG and external SRAM +monitor reset init +monitor halt +monitor sleep 20 +#=============================================================================== +#Variables declaration (1) +#binary file size +set $RamFileSize = 0x0000 +source fwsize.gdb +printf "-------------------------------\n" +printf "RamFileSize: %x\n",$RamFileSize +printf "-------------------------------\n" + +#=============================================================================== +set $FLASHDATBUFSIZE = 0x800 + +#=============================================================================== +#define PERI_ON_BASE 0x40000000 +set $PERI_ON_BASE = 0x40000000 +#define REG_SOC_PERI_FUNC0_EN 0x0218 +set $REG_SOC_PERI_FUNC0_EN = 0x0210 + +#define SPI_FLASH_BASE 0x4000000 +set $SPI_FLASH_BASE = 0x98000000 + +#------------------------------------------------------------------ +set $Temp = 0x0 + +#=============================================================================== +#Load flash download file +file ../../../component/soc/realtek/8195a/misc/gcc_utility/target_NORMAL.axf + +#Load the file +lo + +printf "Load flash controller.\n" +#=============================================================================== +#Set for executing flash controller funciton +set $Temp = {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) +p /x $Temp + +set $Temp = ($Temp | (0x01 << 27)) +p /x $Temp + +set {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) = $Temp +printf "....\n" +printf "wakeup bit(%x):%x\n", ($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN), {int}($PERI_ON_BASE+$REG_SOC_PERI_FUNC0_EN) +#=============================================================================== +#Direct the startup wake function to flash program function +#the function pointer address +#set $testpointer = 0x200006b4 +#set $testpointer2 = 0x200006b8 +#set $FuntionPointer = 0x200006c4 +#set $FPTemp = 0x200a08e9 +#set {int}($FuntionPointer) = $FPTemp +#printf "testpointer(%x):%x\n", $testpointer, {int}$testpointer +#printf "testpointer2(%x):%x\n", $testpointer2, {int}$testpointer2 +#printf "FuntionPointer(%x):%x\n", $FuntionPointer, {int}$FuntionPointer + +#=============================================================================== +#Load file +# restore filename [binary] bias start end +# Restore the contents of file filename into memory. +# The restore command can automatically recognize any known bfd file format, except for raw binary. +# To restore a raw binary file you must specify the optional keyword binary after the filename. +#=============================================================================== + +set $LoopNum = ($RamFileSize / $FLASHDATBUFSIZE) +printf "LoopNum = %x\n", $LoopNum +set $TailSize = ($RamFileSize % $FLASHDATBUFSIZE) +printf "TailSize = %x\n", $TailSize + +printf "global variables\n" + +set $FLASHDATSRC = 0x0 +set $FILESTARTADDR = 0X0 +set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE + +#b RtlFlashProgram:StartOfFlashBlockWrite +b rtl_flash_download.c:489 +b rtl_flash_download.c:524 +#b Rtl_flash_control.c:RtlFlashProgram + +#continue to 489 +c + +# Mode 0: erase full chip, Mode 1: skip calibration section and erase to firmware size +set EraseMode=1 +print EraseMode +set FirmwareSize=$RamFileSize +print FirmwareSize + +#continue to 524 +c + +#printf "...\n" +set $FLASHDATSRC = FlashDatSrc +printf "FlashDatSrc:%x\n", $FLASHDATSRC + +printf "FlashBlockWriteSize " +set FlashBlockWriteSize = $FLASHDATBUFSIZE +#p /x FlashBlockWriteSize +printf "FlashBlockWriteSize:%x\n", FlashBlockWriteSize + +printf "FlashAddrForWrite" +set FlashAddrForWrite = 0x0 + + + +printf "Flash write start...\n" +set $LoopCnt = 0 +while ($LoopCnt < $LoopNum) + p /x FlashAddrForWrite + restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR + c + + printf "FILEENDADDR" + p /x $FILEENDADDR + set FlashBlockWriteSize = $FLASHDATBUFSIZE + set FlashAddrForWrite = $FILEENDADDR + set $FILESTARTADDR = $FILEENDADDR + set $FILEENDADDR = $FILESTARTADDR + $FLASHDATBUFSIZE + + set $LoopCnt = $LoopCnt + 0x01 +end + +#set FlashBlockWriteSize = $FLASHDATBUFSIZE +#set FlashAddrForWrite = $FILEENDADDR +#set $FILESTARTADDR = $FILEENDADDR +set $FILEENDADDR = $FILESTARTADDR + $TailSize +restore ./application/Debug/bin/ram_all.bin binary ($FLASHDATSRC-$FILESTARTADDR) $FILESTARTADDR $FILEENDADDR +c + +#Set complete flas +set FlashWriteComplete = 0x1 + +printf "dump for check\n" + +set $LoopCnt = 0 +set $dumpaddr = 0 + +set $dumpstartaddr = $SPI_FLASH_BASE +set $dumpendaddr = $SPI_FLASH_BASE + $RamFileSize +printf "start addr of dumping" +p /x $dumpstartaddr +printf "end addr of dumping" +p /x $dumpendaddr +dump binary memory ./application/Debug/bin/dump.bin $dumpstartaddr $dumpendaddr + + +delete +b rtl_flash_download.c:556 +c + +quit +#=============================================================================== + diff --git a/openocd/rtl_gdb_ramdebug.txt b/openocd/rtl_gdb_ramdebug.txt new file mode 100644 index 0000000..5f7d5ac --- /dev/null +++ b/openocd/rtl_gdb_ramdebug.txt @@ -0,0 +1,60 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote :3333 + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +monitor reset init +monitor sleep 20 +monitor halt +#=============================================================================== +#Load flash download file +file ../flash.elf + +#boot from ram, igonore loading flash +set {int}0x40000210=0x8011157 + +#Load the file +lo + +#Run to main +b main +continue +clear main + + + + + + diff --git a/openocd/rtl_gdb_ramdebug_jlink.txt b/openocd/rtl_gdb_ramdebug_jlink.txt new file mode 100644 index 0000000..93311e6 --- /dev/null +++ b/openocd/rtl_gdb_ramdebug_jlink.txt @@ -0,0 +1,112 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 100000 +target remote :10000 + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +monitor reset 1 +monitor sleep 20 +monitor clrbp +#=============================================================================== +#Init SDRAM here + # init System +monitor MemU32 0x40000014=0x00000021 +monitor sleep 10 +monitor MemU32 0x40000304=0x1fc00002 +monitor sleep 10 +monitor MemU32 0x40000250=0x00000400 +monitor sleep 10 +monitor MemU32 0x40000340=0x00000000 +monitor sleep 10 +monitor MemU32 0x40000230=0x0000dcc4 +monitor sleep 10 +monitor MemU32 0x40000210=0x00011117 +monitor sleep 10 +monitor MemU32 0x40000210=0x00011157 +monitor sleep 10 +monitor MemU32 0x400002c0=0x00110011 +monitor sleep 10 +monitor MemU32 0x40000320=0xffffffff +monitor sleep 10 + # init SDRAM +monitor MemU32 0x40000040=0x00fcc702 +monitor sleep 10 +monitor MemU32 0x40000040 +monitor MemU32 0x40005224=0x00000001 +monitor sleep 10 +monitor MemU32 0x40005004=0x00000208 +monitor sleep 10 +monitor MemU32 0x40005008=0xffffd000 +monitor sleep 13 +monitor MemU32 0x40005020=0x00000022 +monitor sleep 13 +monitor MemU32 0x40005010=0x09006201 +monitor sleep 13 +monitor MemU32 0x40005014=0x00002611 +monitor sleep 13 +monitor MemU32 0x40005018=0x00068413 +monitor sleep 13 +monitor MemU32 0x4000501c=0x00000042 +monitor sleep 13 +monitor MemU32 0x4000500c=0x700 +monitor sleep 20 +monitor MemU32 0x40005000=0x1 +monitor sleep 100 +monitor MemU32 0x40005000 +monitor MemU32 0x4000500c=0x600 +monitor sleep 30 + +monitor MemU32 0x40005008=0x00000000 +monitor sleep 3 +monitor MemU32 0x40000300=0x0006005e +monitor sleep 3 +#=============================================================================== +#Load flash download file +file ./application/Debug/bin/application.axf + +#boot from ram, igonore loading flash +monitor MemU32 0x40000210=0x8011157 + +#Load the file +lo + +#Run to main +b main +continue +clear main + + + + + diff --git a/openocd/rtl_gdb_ramdebug_openocd.txt b/openocd/rtl_gdb_ramdebug_openocd.txt new file mode 100644 index 0000000..2183f9e --- /dev/null +++ b/openocd/rtl_gdb_ramdebug_openocd.txt @@ -0,0 +1,60 @@ +# GDB script for loading ram.bin process + +#=============================================================================== +#set GDB connection +set remotetimeout 30000 +target remote localhost:10000 + +#=============================================================================== +#Message display setting +#disable all messages + +set verbose off +set complaints 0 +set confirm off +set exec-done-display off +show exec-done-display +set trace-commands off +#set debug aix-thread off +#set debug dwarf2-die 0 +set debug displaced off +set debug expression 0 +set debug frame 0 +set debug infrun 0 +set debug observer 0 +set debug overload 0 +set debugvarobj 0 +set pagination off +set print address off +set print symbol-filename off +set print symbol off +set print pretty off +set print object off +#set debug notification off +set debug parser off +set debug remote 0 + +#=============================================================================== +monitor reset init +monitor sleep 20 +monitor halt +#=============================================================================== +#Load flash download file +file ../flash.elf + + +#boot from ram, igonore loading flash +set {int}0x40000210=0x8011157 + +#Load the file +lo + +#Run to main +b main +continue +clear main + + + + + diff --git a/openocd/run_gdb.bat b/openocd/run_gdb.bat new file mode 100644 index 0000000..f43ef2d --- /dev/null +++ b/openocd/run_gdb.bat @@ -0,0 +1,3 @@ +cmd /c start openocd -f interface\jlink.cfg -f ameba1.cfg +cmd /c start arm-none-eabi-gdb -x rtl_gdb_debug.txt + diff --git a/openocd/run_openocd.bat b/openocd/run_openocd.bat new file mode 100644 index 0000000..fefe507 --- /dev/null +++ b/openocd/run_openocd.bat @@ -0,0 +1,3 @@ +taskkill /F /IM openocd.exe +@rem openocd -f interface\cmsis-dap.cfg -f ..\..\..\component\soc\realtek\8195a\misc\gcc_utility\openocd\ameba1.cfg +openocd -f interface\jlink.cfg -f ameba1.cfg