464 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
		
		
			
		
	
	
			464 lines
		
	
	
		
			7.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
|  | # These are some useful functions to add to your ~/.xt-gdbinit file | ||
|  | # Standard gdb debug settings | ||
|  | 
 | ||
|  | set history filename ~/.gdb_history | ||
|  | set history save on | ||
|  | set print pretty on | ||
|  | set print object on | ||
|  | set print vtbl on | ||
|  | set pagination off | ||
|  | set output-radix 16 | ||
|  | 
 | ||
|  | set $new=1 | ||
|  | 
 | ||
|  | define fpga_ver | ||
|  | x 0xa6048 | ||
|  | end | ||
|  | 
 | ||
|  | define dmem_usage | ||
|  | end | ||
|  | 
 | ||
|  | define ana_read_gain | ||
|  | set *0x51c00180=1 | ||
|  | x/w 0x51c0017c | ||
|  | set *0x51c00180=25 | ||
|  | x/w 0x51c0017c | ||
|  | set *0x51c00180=41 | ||
|  | x/w 0x51c0017c | ||
|  | end | ||
|  | 
 | ||
|  | define ana_read | ||
|  | set *0x51c00180=$arg0*4+1 | ||
|  | x/w 0x51c0017c | ||
|  | x/b 0x51c00181 | ||
|  | end | ||
|  | 
 | ||
|  | define ana_write | ||
|  | set $addr = $arg0 | ||
|  | set $value = $arg1 | ||
|  | set $mask = $arg2 | ||
|  | set *0x51c00178=$mask | ||
|  | set *0x51c00174=$value | ||
|  | set *0x51c00180=$addr*4+3 | ||
|  | end | ||
|  | 
 | ||
|  | define dump_all | ||
|  | set $phy_reg=0x51800000 | ||
|  | set $phy_tx_reg=0x51900000 | ||
|  | set $phy_rxtd_reg=0x51a00000 | ||
|  | set $phy_rxfd_reg=0x51b00000 | ||
|  | set $phy_dfe_reg=0x51c00000 | ||
|  | set $mac_sys_reg=0x51000000 | ||
|  | set $rgf_rx_reg=0x51000c00 | ||
|  | set $ahb_reg=0x50000000 | ||
|  | set $apb_reg=0x44000000 | ||
|  | set $clk_reg=0x44009000 | ||
|  | set $start=0 | ||
|  | set $size=0x700/4 | ||
|  | set $end=$size | ||
|  | set logging file phy_reg_dump.txt | ||
|  | set logging on | ||
|  | while $start < $end | ||
|  |     x $phy_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file phy_tx_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $phy_tx_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file phy_rxtd_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $phy_rxtd_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file phy_rx_fd_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $phy_rxfd_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file phy_dfe_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $phy_dfe_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file mac_sys_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $mac_sys_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file rgf_rx_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $rgf_rx_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file ahb_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $ahb_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file apb_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $apb_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | 
 | ||
|  | set logging file clk_reg_dump.txt | ||
|  | set logging on | ||
|  | set $start=0 | ||
|  | while $start < $end | ||
|  |     x $clk_reg+$start*4 | ||
|  |     set $start++ | ||
|  | end | ||
|  | set logging off | ||
|  | end | ||
|  | 
 | ||
|  | define vm | ||
|  | target remote localhost:3333 | ||
|  | end | ||
|  | 
 | ||
|  | # reset fpga | ||
|  | define resetfpga | ||
|  | set *0x00100000=0x6f | ||
|  | set *0x50000004=0xffffffff | ||
|  | end | ||
|  | 
 | ||
|  | # Run to appstart and load app | ||
|  | define loadfw | ||
|  | monitor soft_reset_halt | ||
|  | disable_watchdog | ||
|  | load | ||
|  | set $sp = &__StackTop | ||
|  | #set $pc = __Vectors[1] | ||
|  | end | ||
|  | 
 | ||
|  | #dump uart register | ||
|  | define dump_uart | ||
|  | p *(struct pl011_regs*)0x44001000 | ||
|  | p *(struct pl011_regs*)0x44005000 | ||
|  | end | ||
|  | 
 | ||
|  | define uart_info | ||
|  | p g_uart_info | ||
|  | end | ||
|  | 
 | ||
|  | #dump intc register | ||
|  | define dump_intc | ||
|  | p *(struct intc_regs*)0x44004000 | ||
|  | end | ||
|  | 
 | ||
|  | #dump apb register | ||
|  | define dump_apb | ||
|  | p *(struct apb_regs*)0x44000000 | ||
|  | end | ||
|  | 
 | ||
|  | #dump gptimer register | ||
|  | define dump_gptmr | ||
|  | p *(struct gpmtr_regs*)0x44003000 | ||
|  | end | ||
|  | 
 | ||
|  | define cache_disable | ||
|  | set *0x50000008 &= ~(0x18) | ||
|  | set *0x50000004 |= (0x18) | ||
|  | end | ||
|  | 
 | ||
|  | define map_flash_core | ||
|  | set *0x4400703c |= 0x30 | ||
|  | set *0x44007098 |= 0x30 | ||
|  | set *0x44007038 |= 0x30 | ||
|  | set *0x44007064 |= 0x30 | ||
|  | set *0x44007068 |= 0x30 | ||
|  | set *0x44007040 |= 0x30 | ||
|  | 
 | ||
|  | set *0x4400001c |= 0x4 | ||
|  | 
 | ||
|  | set *0x44020010 |= 0x1000 | ||
|  | set *0x44020014 |= 0x1000 | ||
|  | set *0x44020018 |= 0x1000 | ||
|  | set *0x4402001c |= 0x1000 | ||
|  | end | ||
|  | 
 | ||
|  | define map_flash_gpio_ver14 | ||
|  | # config pin 23-28 select FUNCTION0 | ||
|  | set *0x44007080=0 | ||
|  | set *0x44007084=0 | ||
|  | set *0x44007088=0 | ||
|  | set *0x4400708c=0 | ||
|  | set *0x44007090=0 | ||
|  | set *0x44007094=0 | ||
|  | # enable gpio matrix | ||
|  | set *0x4400001c=0x4 | ||
|  | # config gpio matrix in | ||
|  | # SFC INID 4-7 => GPIO 25-28 | ||
|  | set *0x44020010=25 | ||
|  | set *0x44020014=26 | ||
|  | set *0x44020018=27 | ||
|  | set *0x4402001c=28 | ||
|  | #config gpio matrix out | ||
|  | # SFC OUTID 6-11 => GPIO 25-28 | ||
|  | set *0x4402045c=0x6 | ||
|  | set *0x44020460=0x7 | ||
|  | set *0x44020464=0x8 | ||
|  | set *0x44020468=0x9 | ||
|  | set *0x4402046c=10 | ||
|  | set *0x44020470=11 | ||
|  | end | ||
|  | 
 | ||
|  | define map_uart2_gpio_mtx | ||
|  | set *0x44007040=0 | ||
|  | set *0x44007044=0 | ||
|  | set *0x4400001c=0x4 | ||
|  | set *0x44020024=0x1000 | ||
|  | set *0x4402002c=0x8 | ||
|  | set *0x440200f8=15 | ||
|  | end | ||
|  | 
 | ||
|  | define map_uart2_gpio_ver14 | ||
|  | set *0x44007040=0 | ||
|  | set *0x44007044=0 | ||
|  | set *0x4400001c |= 0x4 | ||
|  | set *0x44020024 |= 0x1000 | ||
|  | set *0x4402002c=0x8 | ||
|  | set *0x44020464=15 | ||
|  | end | ||
|  | 
 | ||
|  | define map_psram_core_def | ||
|  | set *0x4400001c |= 0x4 | ||
|  | set *0x44020000 |= 0x1000 | ||
|  | set *0x44020004 |= 0x1000 | ||
|  | set *0x44020008 |= 0x1000 | ||
|  | set *0x4402000c |= 0x1000 | ||
|  | end | ||
|  | 
 | ||
|  | define set_cache_buffer_mode | ||
|  | set *0x5000000c=0x10000 | ||
|  | set *0x50000008=0x00090010 | ||
|  | set *0x50000004=0xe | ||
|  | end | ||
|  | 
 | ||
|  | define cache_qspi_enable | ||
|  | set *0x50000004=0x2001A | ||
|  | set *0x50000008=0x90004 | ||
|  | # modify | ||
|  | set *0x52000188=0x03057a75 | ||
|  | set *0x5200018c=0x100 | ||
|  | set *0x52000190=0x08180000 | ||
|  | # dual | ||
|  | #set *0x52000188=0x3b057a75 | ||
|  | #set *0x5200018c=0x102 | ||
|  | #set *0x52000190=0x08180008 | ||
|  | #quad | ||
|  | #set *0x52000188=0xeb057a75 | ||
|  | #set *0x5200018c=0x115 | ||
|  | #set *0x52000190=0x08060204 | ||
|  | 
 | ||
|  | set *0x52000194=0x100 | ||
|  | set *0x52000198=0x08000000 | ||
|  | set *0x5200019c=0x100 | ||
|  | set *0x520001a0=0x08000000 | ||
|  | set *0x520001a4=0x100 | ||
|  | set *0x520001a8=0x08000000 | ||
|  | #set *0x52000130=0x3 | ||
|  | # set cache quad | ||
|  | #set *0x5200020c=0x102 | ||
|  | set *0x5200020c=0x1102 | ||
|  | set *0x52000208=0x35000000 | ||
|  | set *0x52000204=0x80000000 | ||
|  | 
 | ||
|  | set *0x50000004=0x20002 | ||
|  | set *0x50000008=0x9001C | ||
|  | end | ||
|  | 
 | ||
|  | define enable_emc | ||
|  | set *0x62000004 |= 0x1 | ||
|  | set *0x62000008 |= 0x1 | ||
|  | set *0x62000008 &= ~(0x1) | ||
|  | end | ||
|  | 
 | ||
|  | define init_flash | ||
|  | set *0x61000140=0x2000 | ||
|  | #set *0x61000188=0x03057a75 | ||
|  | #set *0x6100018c=0x100 | ||
|  | #set *0x61000190=0x08180000 | ||
|  | set *0x52000188=0xeb057a75 | ||
|  | set *0x5200018c=0x115 | ||
|  | set *0x52000190=0x08060204 | ||
|  | 
 | ||
|  | set *0x61000194=0x100 | ||
|  | set *0x61000198=0x08000000 | ||
|  | set *0x6100019c=0x100 | ||
|  | set *0x610001a0=0x08000000 | ||
|  | set *0x610001a4=0x100 | ||
|  | set *0x610001a8=0x08000000 | ||
|  | end | ||
|  | 
 | ||
|  | define psram_qpi_mode | ||
|  | set *0x6100020c=0x1102 | ||
|  | set *0x61000208=0x35000000 | ||
|  | set *0x61000204=0x80000000 | ||
|  | end | ||
|  | 
 | ||
|  | define psram_spi_mode | ||
|  | set *0x6100020c=0x1000 | ||
|  | set *0x61000208=0xf5000000 | ||
|  | set *0x61000204=0x80000000 | ||
|  | set *0x6100020c=0x0000 | ||
|  | end | ||
|  | 
 | ||
|  | define enable_cache | ||
|  | set *0x50000008 |= 0x18 | ||
|  | set *0x50000004 &= ~(0x18) | ||
|  | set $space = *0x5000008c | ||
|  | if $space != 0x44 | ||
|  |     set *0x5000008c=0x44 | ||
|  | end | ||
|  | end | ||
|  | 
 | ||
|  | define cache_cfg_qpi_ver14 | ||
|  | enable_emc | ||
|  | init_flash | ||
|  | psram_qpi_mode | ||
|  | enable_cache | ||
|  | end | ||
|  | 
 | ||
|  | define cache_cfg_spi_ver14 | ||
|  | enable_emc | ||
|  | psram_spi_mode | ||
|  | init_flash | ||
|  | enable_cache | ||
|  | end | ||
|  | 
 | ||
|  | define loadfirmware | ||
|  | monitor soft_reset_halt | ||
|  | cache_disable | ||
|  | map_flash_gpio_mtx | ||
|  | map_psram_core_def | ||
|  | map_uart2_gpio_mtx | ||
|  | cache_qspi_enable | ||
|  | load | ||
|  | end | ||
|  | 
 | ||
|  | define disable_watchdog | ||
|  | set *0x62010008=0x0 | ||
|  | set *0x4400e008=0x0 | ||
|  | end | ||
|  | 
 | ||
|  | define set_cpu_freq_150 | ||
|  | set *0x44009004=0x100 | ||
|  | set *0x44009000=0x1 | ||
|  | end | ||
|  | 
 | ||
|  | define set_sfc_clk_75 | ||
|  | set *0x61000134=0x10 | ||
|  | end | ||
|  | 
 | ||
|  | define set_smc_clk_75 | ||
|  | set *0x61000210=0x10 | ||
|  | end | ||
|  | 
 | ||
|  | define load_ver14_qpi | ||
|  | monitor soft_reset_halt | ||
|  | disable_watchdog | ||
|  | cache_disable | ||
|  | if $new == 1 | ||
|  |     map_flash_core | ||
|  | else | ||
|  |     map_flash_gpio_ver14 | ||
|  | end | ||
|  | map_psram_core_def | ||
|  | #map_uart2_gpio_ver14 | ||
|  | cache_cfg_qpi_ver14 | ||
|  | load | ||
|  | set_cpu_freq_150 | ||
|  | #set_sfc_clk_75 | ||
|  | #set_smc_clk_75 | ||
|  | while $a0 != 0x0 | ||
|  |     set $a0=0x0 | ||
|  | end | ||
|  | end | ||
|  | 
 | ||
|  | define load_ver14_spi | ||
|  | monitor soft_reset_halt | ||
|  | disable_watchdog | ||
|  | cache_disable | ||
|  | if $new == 1 | ||
|  |     map_flash_core | ||
|  | else | ||
|  |     map_flash_gpio_ver14 | ||
|  | end | ||
|  | map_psram_core_def | ||
|  | #map_uart2_gpio_ver14 | ||
|  | cache_cfg_spi_ver14 | ||
|  | load | ||
|  | set $a0=0x0 | ||
|  | end | ||
|  | 
 | ||
|  | define snapshot | ||
|  | set *0x52000004=0x10101 | ||
|  | set *0x52000008=0x1e007 | ||
|  | end | ||
|  | 
 | ||
|  | define map_jtag_gpio_mtx | ||
|  | # config pin 00 - 04 select FUCNTION0 | ||
|  | set *0x44007024=0 | ||
|  | set *0x44007028=0 | ||
|  | set *0x4400702c=0 | ||
|  | set *0x44007030=0 | ||
|  | set *0x44007034=0 | ||
|  | # enable gpio matrix | ||
|  | set *0x4400001c=0x4 | ||
|  | #in 44 - 47 => 00 01 03 04 | ||
|  | set *0x440200b0=00 | ||
|  | set *0x440200b4=01 | ||
|  | set *0x440200b8=03 | ||
|  | set *0x440200bc=04 | ||
|  | #out 2 => 66 | ||
|  | set *0x44020408=62 | ||
|  | end | ||
|  | 
 | ||
|  | define print_dump_info | ||
|  |     set trace-commands off | ||
|  |     set $i = 0 | ||
|  |     while($i < 10) | ||
|  |         set $dump = g_exception_dump.ra[$i] | ||
|  |         if ($dump != 0x0) | ||
|  |             p/a $dump | ||
|  |         end | ||
|  |         set $i = $i + 1 | ||
|  |     end | ||
|  |     set trace-commands on | ||
|  | end |