skllskll 发表于 2019-4-2 14:49:12

#
# Hisilicon SD5115 (T?)
#
# Author : CserSoft
# Version : 1.3.2
#
adapter_khz 6000
transport select jtag

if { } {
    set_CHIPNAME $CHIPNAME
} else {
    set_CHIPNAME sd5115
}

if { } {
    set _CPU_TAPID $CPUTAPID
} else {
    set _CPU_TAPID 0x4ba00477
}

if { } {
    set _ENDIAN $ENDIAN
} else {
    # this defaults to a bigendian
    set _ENDIAN little
}

if { } {
    set _ETB_TAPID $ETB_TAPID
} else {
    set _ETB_TAPID 0x410CF231
}

jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0xf -expected-id $_CPU_TAPID

# jtag newtap $_CHIPNAME etb -irlen 4 -expected-id $_ETB_TAPID

set _TARGETNAME $_CHIPNAME.cpu

target create $_TARGETNAME cortex_a -endian $_ENDIAN -chain-position $_TARGETNAME

# etm_dummy config $_TARGETNAME
# etb config $_TARGETNAME $_CHIPNAME.etb


#调试初始化
proc sd5115_dbginit { target } {
    cortex_a dbginit
}

$_TARGETNAME configure -event reset-assert-post "sd5115_dbginit $_TARGETNAME"

# init
# dap apsel 1



#获取内存数据 32 bit
proc getmem32 { addr } {
    mem2array atmp 32 $addr 1
    return
}


#设置内存数据 32 bit
proc setmem32 { addr value } {
    mww phys $addr $value 1
}


#对内存数据进行And操作 32 bit
proc andmem32 { addr value } {
    set vmem
    return
}


#对内存数据进行And操作并写回内存 32 bit
proc andmem32w { addr value } {
    set vmem & $value]
    mww phys $addr $vmem 1
    return $vmem
}


#对内存数据进行Or操作 32 bit
proc ormem32 { addr value } {
    set vmem
    return
}


#对内存数据进行Or操作并写回内存 32 bit
proc ormem32w { addr value } {
    set vmem | $value]
    mww phys $addr $vmem 1
    return $vmem
}


proc sd5115_startcode_offset_0x6EC { } {
    andmem32w 0x10180000 0xFFFFFFFE
}

proc sd5115_startcode_offset_0x700 { } {
    mww phys 0x1018000C 0xFFFFFFFF 1
}

proc sd5115_startcode_offset_0x710 { } {
    ormem32w 0x10180054 0xFF
    ormem32w 0x10180000 0x1
}

proc sd5115_startcode_offset_0xFAD4 { } {
    setmem32 0x10100144 | 0x400]
}

proc sd5115_startcode_offset_0xFAF4 { } {
    set vcpuid
   
    if { $vcpuid == 0x51151100 } {
      ormem32w    0x13000000 0x80000
      ormem32w    0x10106008 0xC0
      ormem32w    0x10106008 0x300
    } elseif { $vcpuid == 0x51152100 } {
      ormem32w    0x13000000 0x60000
      ormem32w    0x10108008 0xF0
    } else {
      ormem32w    0x130001C8 0x100
      ormem32w    0x10106008 0xC00
      andmem32w   0x13000000 0xFFFFFFFB
      andmem32w   0x130001C8 0xFFFFFFDF
      ormem32w    0x10106008 0x3000
      andmem32w   0x13000000 0xFFFDFFFF
      andmem32w   0x130001C8 0xFFFFFFBF
    }
}

proc sd5115_startcode_offset_0xFBD8 { } {
    set vcpuid
   
    if { $vcpuid != 0x51151100 } {
      if { $vcpuid == 0x51152100 } {
            setmem32    0x10400500 0x1FFF800
            andmem32w   0x10100134 0xFFFFFFFC
            andmem32w   0x10107008 0xDDFFFFFF
            ormem32w    0x10107004 0x22000000
            ormem32w    0x10107000 0x22000000
            andmem32w   0x10108008 0xFFF7FFFF
            ormem32w    0x10108004 0x80000
            ormem32w    0x10108000 0x80000
            andmem32w   0x10100144 0x3FFFFFFF
      } else {
            setmem32    0x10400500 0x1FFF800
            andmem32w   0x10100134 0xFFFFFFFC
            ormem32w    0x10107004 0x18000
            andmem32w   0x10107000 0xFFFE7FFF
            ormem32w    0x10107000 0x18000
            andmem32w   0x1300016C 0xFFFFFFFC
      }
    }
}

proc sd5115_startcode_offset_0xFCD4 { } {
    set vcpuid
   
    if { $vcpuid == 0x51151100 } {
      andmem32w   0x1010012C 0xFFBFFFFF
      andmem32w   0x10100138 0xFFFFFFBF
      ormem32w    0x10100080 0x9
      andmem32w   0x1010013C 0xFFFFEFFF
      setmem32    0x1010005C 0x81020248
      
      while { != 0x10000 } {sleep 1}
      
      ormem32w 0x1010007C 0x9
      ormem32w 0x10100148 0x2
      ormem32w 0x1010012C 0x400000
      ormem32w 0x10100138 0x40
      
    } elseif { $vcpuid == 0x51152100 } {
      if { == 1 } {
            andmem32w   0x1010012C 0xFFBFFFFF
            andmem32w   0x10100138 0xFFFFFFBF
            ormem32w    0x10100080 0x9
            andmem32w   0x10100144 0xFEFFFFFF
            andmem32w   0x10100140 0xFFFFCFFF
            ormem32w    0x10100140 0x40000000
            setmem32    0x10100074 0x81028249
            
            while { != 0x40000 } {sleep 1}

            ormem32w 0x1010007C 0x9
            ormem32w 0x10100148 0x2
            ormem32w 0x1010012C 0x400000
            ormem32w 0x10100138 0x40
      } else {
            while { != 0x20000 } {sleep 1}
      }
      
    } else {
      andmem32w   0x1010012C 0xFFBFFFFF
      andmem32w   0x10100138 0xFFFFFFBF
      ormem32w    0x10100080 0x9
      setmem32    0x1010011C 0x81028648

      while { != 0x20000 } {sleep 1}

      ormem32w 0x1010007C 0x9
      ormem32w 0x10100148 0x2
      ormem32w 0x1010012C 0x400000
      ormem32w 0x10100138 0x40
    }
}

#sd5115_startcode_offset_0xFED4
proc sd5115_init_dram { } {
    halt
    echo "Info: init dram..."
   
    set vcpuid
   
    if { $vcpuid == 0x51151100 } {
      setmem32 0x10102010 1
      setmem32 0x1010201C 0x8DF40630
      setmem32 0x10102020 0x10184
      setmem32 0x1010202C 0x132
      setmem32 0x10102040 0x80000000
      setmem32 0x10102050 0x62330A08
      setmem32 0x10102054 0x7F525616
      setmem32 0x1010205C 0x4BE58352
      setmem32 0x101020F4 1
      setmem32 0x10102058 0x6230A000
      setmem32 0x10102004 0

      while { != 0 } { sleep 1 }

      setmem32 0x10102404 0x80000000
      
      while { != 1 } { sleep 1 }
         
      setmem32 0x10102418 0xDC000
      setmem32 0x10102584 0x5D
      setmem32 0x1010240C 0x3008401
      setmem32 0x10102444 0x48B
      setmem32 0x10102448 0x51106644
      setmem32 0x1010244C 0x1A81629A
      setmem32 0x10102450 0x100220C8
      setmem32 0x10102454 0x1520
      setmem32 0x10102458 6
      setmem32 0x1010245C 0
      setmem32 0x10102460 0
      setmem32 0x101025C0 0x44000887
      setmem32 0x10102440 0xF008003E
      setmem32 0x10102468 0x1001541
      setmem32 0x10102404 0xFFF3
      
      while { != 0x80000FFF } { sleep 1 }
      
      setmem32 0x10102058 0x6230A05F
      setmem32 0x10102020 0x410185
      setmem32 0x1010201C 0x8DF40630
      setmem32 0x10102200 0x305133
      setmem32 0x10102204 0x3062CC
      
    } elseif { $vcpuid == 0x51152100 } {
      if { == 1 } {
            setmem32 0x10102010 1
            setmem32 0x1010201C 0x80000600
            setmem32 0x10102020 0x584
            setmem32 0x1010202C 0x142
            setmem32 0x10102040 0x80000000
            setmem32 0x10102050 0x63440E0A
            setmem32 0x10102054 0xFF526720
            setmem32 0x10102058 0x6240A000
            setmem32 0x1010205C 0xFFDFF5F2
            setmem32 0x101020F4 0x21
            setmem32 0x101020AC 0x3000501
            setmem32 0x10102004 0

            while { != 0 } { sleep 1 }

            setmem32 0x10102404 0x80000000

            while { != 1 } { sleep 1 }

            setmem32 0x10102418 0x5C000
            setmem32 0x1010248C 0xF01E78
            setmem32 0x1010241C 0x1F40FA10
            setmem32 0x10102420 0x61A808CA
            setmem32 0x10102428 0xC83D090
            setmem32 0x1010242C 0x1F4186A0
            setmem32 0x10102444 0x48B
            setmem32 0x10102448 0x6D538844
            setmem32 0x1010244C 0x22820282
            setmem32 0x10102450 0x1002EA00
            setmem32 0x10102454 0x1930
            setmem32 0x10102458 0x42
            setmem32 0x1010245C 8
            setmem32 0x10102460 0
            setmem32 0x10102464 0x210000
            setmem32 0x10102468 0x210035C3
            setmem32 0x10102584 0x2D
            setmem32 0x101025C0 0x44000E81
            setmem32 0x10102600 0x44000E81
            setmem32 0x10102440 0xF000603E
            setmem32 0x10102404 0xFFF3

            while { != 1 } { sleep 1 }

            setmem32 0x10102058 0x6240A079
            setmem32 0x10102200 0x304132
            setmem32 0x10102204 0x306132
            setmem32 0x10102208 0x304066
            setmem32 0x10102210 0x306132
      } else {
            setmem32 0x10102010 1
            setmem32 0x1010201C 0x80000601
            setmem32 0x10102020 0x580
            setmem32 0x1010202C 0x142
            setmem32 0x10102040 0x80000000
            setmem32 0x10102050 0xC466150F
            setmem32 0x10102054 0xFF545540
            setmem32 0x10102058 0x84610000
            setmem32 0x1010205C 0xFFDFF4F4
            setmem32 0x101020F4 0x21
            setmem32 0x101020AC 0x3000501
            setmem32 0x10102004 0

            while { != 0 } { sleep 1 }

            setmem32 0x10102404 0x80000000

            while { != 1 } { sleep 1 }

            setmem32 0x10102418 0x5C000
            setmem32 0x1010248C 0xF01860
            setmem32 0x1010241C 0x1900C810
            setmem32 0x10102420 0x4E200708
            setmem32 0x10102428 0xA030D40
            setmem32 0x1010242C 0x19013880
            setmem32 0x10102444 0x48B
            setmem32 0x10102448 0x550F6644
            setmem32 0x1010244C 0x22820202
            setmem32 0x10102450 0x1002EA00
            setmem32 0x10102454 0x1510
            setmem32 0x10102458 0x42
            setmem32 0x1010245C 0
            setmem32 0x10102460 0
            setmem32 0x10102464 0x210000
            setmem32 0x10102468 0x210035C3
            setmem32 0x10102584 0x2D
            setmem32 0x101025C0 0x44000E81
            setmem32 0x10102600 0x44000E81
            setmem32 0x10102440 0xF008603E
            setmem32 0x10102404 0xFFF3

            while { != 1 } { sleep 1 }

            setmem32 0x10102058 0x846100C3
            setmem32 0x10102200 0x304132
            setmem32 0x10102204 0x306132
            setmem32 0x10102208 0x304066
            setmem32 0x10102210 0x306132
      }
    } else {
      setmem32 0x10102010 1
      setmem32 0x1010201C 0xE92E0601
      setmem32 0x10102020 0x1F180
      setmem32 0x1010202C 0x132
      setmem32 0x10102040 0x80000000
      setmem32 0x10102050 0xC466130E
      setmem32 0x10102054 0xFF535625
      setmem32 0x1010205C 0x7E58484
      setmem32 0x101020F4 1
      setmem32 0x10102058 0x74511000
      setmem32 0x101020AC 0x3000501
      setmem32 0x10102004 0
      
      while { != 0 } { sleep 1 }
      
      setmem32 0x10102404 0x80000000
      
      while { != 1 } { sleep 1 }
      
      setmem32 0x10102418 0xDC000
      setmem32 0x1010240C 0x3008401
      setmem32 0x10102444 0x48B
      setmem32 0x10102448 0x4D0E6644
      setmem32 0x1010244C 0x1A812A30
      setmem32 0x10102450 0x1001A0C8
      setmem32 0x10102454 0x1320
      setmem32 0x10102458 0x42
      setmem32 0x1010245C 0
      setmem32 0x10102460 0
      setmem32 0x10102468 0x11001547
      setmem32 0x101025C0 0x44000887
      setmem32 0x10102600 0x44000E81
      setmem32 0x10102440 0xF008003E
      setmem32 0x10102584 0x1D
      setmem32 0x10102404 0xFFF3
      
      while { != 0x80000FFF } { sleep 1 }
      
      setmem32 0x10102058 0x7450F09E
      setmem32 0x10102020 0x40EF01
      setmem32 0x101020F8 0
      setmem32 0x10102200 0x305133
      setmem32 0x10102204 0x306266
      setmem32 0x10102208 0x306066
      setmem32 0x1010220C 0
      setmem32 0x1010201C 0xB9D60601
    }
}

proc sd5115_hwinit { } {
    halt
    poll
   
    #enter Supervisor mode
    reg cpsr 0x1D3
   
    arm mcr 15 0 8 7 0 0
    arm mcr 15 0 7 5 0 0
    arm mcr 15 2 0 0 0 0
   
   
    set v5 >> 13) & 0x1ff]
    set v6 0
   
   
    while {$v6 < 4} {
      set v7 0
      
      while {$v7 <= $v5} {
            set vtmp
            set v7
            
            arm mcr 15 0 7 6 2 $vtmp
      }
      
      set v6
    }
   
    if { & 0xf] != 0} {
      echo "Error: (arm mrc 15 0 0 0 5) & 0xf != 0 !"
      
      ;# while { != 0xDD2 } { sleep 1 }
      ;# resume 0x820002C8
      
      if 0 {
            ormem32w 0x10100000 0x100
            
            if { != 0x51152100 } {
                echo "getmem32 0x10100800 != 0x51152100 !"
                ;# ...
                ;# ...
                ;# ...
                ;# ...
                ;# ...
            } else {
                while { == 0 } { sleep 1 }
                echo "0x1010011C is not zero!"
            }
      }
      
      return
    }
   
    arm mcr 15 0 1 0 0 & 0xFFFFDFF8 | 0x802]
   
    if { & 0xf] == 0 } {
      echo "Info: (arm mrc 15 0 0 0 5) & 0xf == 0 ."
      
      echo "Info: call offset 0x6EC ."
      sd5115_startcode_offset_0x6EC
      
      echo "Info: call offset 0x700 ."
      sd5115_startcode_offset_0x700
      
      echo "Info: call offset 0x710 ."
      sd5115_startcode_offset_0x710
    }
   
    arm mcr 15 0 1 0 0 | 0x1000]
   
    setmem32 0x10A30004 0x00000355
   
    ormem32w 0x10A20100 0x2
   
    echo "Info: call offset 0xFAD4 ."
    sd5115_startcode_offset_0xFAD4
   
    setmem32 0x1010007C 0xFFFFFFFF
    setmem32 0x1010008C 0xFFFFFFFF
    setmem32 0x1010012C 0xFFFFFFFF
    setmem32 0x10100130 0xFE7FFFFF
   
    ormem32w 0x10100138 0x7F
    ormem32w 0x10100140 0x80000000

    set vcpuid
   
    if { $vcpuid == 0x51152100 } {
      if { & 1] == 1 } {
            mww phys 0x1010005C 0x8103844D 1
      }
      
      mww phys 0x1010005C 0x8103444D 1
    }
   
    while { != 0x10000 } {sleep 1}
    while { != 0x40000 } {sleep 1}
   
    setmem32 0x1010013C | 0x10]
   
    echo "Info: call offset 0xFCD4 ."
    sd5115_startcode_offset_0xFCD4
   
    andmem32w 0x1010013C 0xFFFFF3FF
    andmem32w 0x10100138 0xFFDFFFFF
    andmem32w 0x10100138 0xFFF7FFFF
    setmem32 0x10100054 0xFFFFFFE0
    setmem32 0x10100050 0x7FF00
    ormem32w 0x10100000 0x4
   
    while { != 0x4 } {sleep 1}
   
    echo "Info: call offset 0xFAF4 ."
    sd5115_startcode_offset_0xFAF4
   
    echo "Info: call offset 0xFBD8 ."
    sd5115_startcode_offset_0xFBD8
   
    echo "Info: call offset 0xFED4 (init dram)."
    sd5115_init_dram
   
    echo "Hardware initialization is complete!"
}

proc sd5115_loadsc { filepath } {
    halt
    load_image $filepath 0x82000000
    ;# verify_image $filepath 0x82000000
}

proc sd5115_goto_entry { } {
    if { != 0x51152100 } {
      resume 0x82000000
    } else {
      if { & 0xf] != 0 } {
            while { != 0xDD2 } { sleep 1 }
            resume 0x82000000
      } else {
            echo "Warn: Can't resume (1)!"
      }
    }
}

proc sd5115_goto_continue { } {
    if { != 0x51152100 } {
      resume 0x820002C8
    } else {
      if { & 0xf] != 0 } {
            while { != 0xDD2 } { sleep 1 }
            resume 0x820002C8
      } else {
            echo "Warn: Can't resume (2)!"
      }
    }
}

proc sd5115_enter_svc_mode { } {
    halt
    #enter Supervisor mode
    reg cpsr 0x1D3
}

proc sd5115_help { } {
    echo "Usage 1:"
    echo "*Step1:{sd5115_hwinit}"
    echo "*Step2:{sd5115_loadsc mtd0.bin}"
    echo "   Step3:{sd5115_enter_svc_mode}"
    echo "*Step4:{sd5115_goto_entry} or {sd5115_goto_continue}"
    echo "!Note!:{sd5115_goto_continue} is not recommended"
    echo " "
    echo "Usage 2:"
    echo "*Step1:{sd5115_init_dram}"
    echo "*Step2:{sd5115_loadsc mtd0.bin}"
    echo "   Step3:{sd5115_enter_svc_mode}"
    echo "*Step4:{sd5115_goto_entry} or {resume 0x82000000}"
    echo " "
}



Step1:{sd5115_hwinit} 执行这一条

然后
halt ; load_image uboot.BIN 0x81F00000 ; resume 0x81F00000

然后用uboot里的命令写固件

方活就在这就看你不会不

tm5880891 发表于 2019-4-2 15:32:10

{:7_215:}

hanyun0105 发表于 2020-12-12 22:43:45

学习了。。。。。。。。。。。。。。。。。。。。。。。

safeqq2 发表于 2020-12-19 22:30:56


回帖赚猫粮

jamesyan520 发表于 2021-2-1 12:52:56

回帖赚猫粮

xizangdelang 发表于 2021-12-2 09:02:18

学习了学习了

wwsswd 发表于 2021-12-22 23:08:01


回帖赚猫粮

宴尼 发表于 2022-6-19 00:30:57

好好学习,天天向上,高手如云啊
页: 1 2 3 [4]
查看完整版本: HG8245C2/HG8245H用JLINK可JTAG读到CPU;TTL无反应救助,各路大神看看,求助,求助...