S3C2440之开发环境搭建(jtag)

mini2440开发环境搭建

一、开发板介绍

先介绍下开发版:

详细介绍请查看官网:http://www.arm9.net/mini2440-feature.asp

二、OpenJTAG调试流程

如果我们要调试裸板和uboot等,最好的方式是通过openjtag来调试,
一是容易下载代码到板子,而是我们可以通过gdb调试程序.
当然如果通过sd卡也能启动,只是并不适合学习和调试.
以下是实际当中openjtag的连接图:

1)驱动和相关软件安装:

需要安装的有:libusb-dev libftdi-dev openocd telnet

用到的命令有:dmesg lsusb

通过dmesg查看是否检测到硬件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 [ 2172.600041] usb 6-1: new full-speed USB device number 5 using uhci_hcd 

[ 2172.787177] usb 6-1: New USB device found, idVendor=1457, idProduct=5118

[ 2172.787181] usb 6-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0

[ 2172.787183] usb 6-1: Product: USB<=>JTAG&RS232

[ 2172.787185] usb 6-1: Manufacturer: [www.100ask.net](http://www.100ask.net/)

[ 2172.795240] usb 6-1: Ignoring serial port reserved for JTAG [ 2172.799302] ftdi_sio 6-1:1.1: FTDI USB Serial Device converter detected

[ 2172.799351] usb 6-1: Detected FT2232C

[ 2172.801290] usb 6-1: FTDI USB Serial Device converter now attached to ttyUSB0

其次lsusb有以下显示,说明驱动已经安装. Bus 006 Device 005: ID 1457:5118 First International Computer, Inc. OpenMoko Neo1973 Debug board (V2+)

2)以下是通过openocd连接板子 1. 启动openocd.

openocd.cfg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
telnet_port 4444
tcl_port 6666

#-------------------------------------------------------------------------
# GDB Setup
#-------------------------------------------------------------------------

gdb_port 3333
gdb_breakpoint_override hard
gdb_memory_map disable
gdb_flash_program enable

interface ftdi
#ftdi_device_desc "USB device (FTDI CDM)"
ftdi_device_desc "USB<=>JTAG&RS232"
#ftdi_device_desc "100ASK JTAG"
ftdi_vid_pid 0x1457 0x5118

#引脚定义,相当于旧版中的 ft2232_layout jtagkey
ftdi_layout_init 0x0c08 0x0f1b
ftdi_layout_signal nTRST -data 0x0100 -noe 0x0400
ftdi_layout_signal nSRST -data 0x0200 -noe 0x0800

# Target configuration for the Samsung 2440 system on chip
# Tested on a S3C2440 Evaluation board by keesj
# Processor : ARM920Tid(wb) rev 0 (v4l)
# Info: JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (Manufacturer: 0x04e, Part: 0x0324, Version: 0x0)

if { [info exists CHIPNAME] } {
set _CHIPNAME $CHIPNAME
} else {
set _CHIPNAME s3c2440
}

if { [info exists ENDIAN] } {
set _ENDIAN $ENDIAN
} else {
# this defaults to a bigendian
set _ENDIAN little
}

if { [info exists CPUTAPID] } {
set _CPUTAPID $CPUTAPID
} else {
set _CPUTAPID 0x0032409d
}

#jtag scan chain
jtag newtap $_CHIPNAME cpu -irlen 4 -ircapture 0x1 -irmask 0x0f -expected-id $_CPUTAPID

set _TARGETNAME $_CHIPNAME.cpu
target create $_TARGETNAME arm920t -endian $_ENDIAN -chain-position $_TARGETNAME

$_TARGETNAME configure -work-area-phys 0x200000 -work-area-size 0x4000 -work-area-backup 1

#reset configuration
reset_config trst_and_srst


#Flash CFG<openocd.pdf P[74~]
#flash bank name driver base size chip_width bus_width target [driver_options]
#usage: flash bank <name> <driver> <base> <size> <chip_width> <bus_width> <target>
#flash bank bank_id driver_name base_address size_bytes chip_width_bytes bus_width_bytes target [driver_options ...]
flash bank 0 cfi 0x0 0x200000 2 2 $_TARGETNAME

#NAND CFG <openocd.pdf P[88~92]>
#nand device name driver target [ configparams... ]
nand device 0 s3c2440 $_TARGETNAME

adapter_khz 6000

注意启动openocd 直接执行即可 不要用-f *.cfg的方式, 例如:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 $sudo openocd

Open On-Chip Debugger 0.10.0

Licensed under GNU GPL v2

For bug reports, read

​ http://openocd.org/doc/doxygen/bugs.html

force hard breakpoints

Info : auto-selecting first available session transport "jtag". To override use 'transport select <transport>'.

trst_and_srst separate srst_gates_jtag trst_push_pull srst_open_drain connect_deassert_srst

adapter speed: 6000 kHz

Info : clock speed 6000 kHz

Info : JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (mfg: 0x04e (Samsung), part: 0x0324, ver: 0x0)

Info : Embedded ICE version 2

Info : s3c2440.cpu: hardware has 2 breakpoint/watchpoint units

2.用telnet连上openocd烧写uboot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
$telnet 127.0.0.1 4444

Trying 127.0.0.1...

Connected to 127.0.0.1.

Escape character is '^]'.

Open On-Chip Debugger

\> reset; halt

JTAG tap: s3c2440.cpu tap/device found: 0x0032409d (mfg: 0x04e (Samsung), part: 0x0324, ver: 0x0)

NOTE! DCC downloads have not been enabled, defaulting to slow memory writes. Type 'help dcc'.

NOTE! Severe performance degradation without fast memory access enabled. Type 'help fast'.

target halted in ARM state due to debug-request, current mode: Supervisor

cpsr: 0x800000d3 pc: 0x00000058

MMU: disabled, D-Cache: disabled, I-Cache: disabled

\> nand probe 0

NAND flash device 'NAND 256MiB 3.3V 8-bit (Samsung)' found

\> nand erase 0 0 0x100000

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

s3c2440_read_block_data: reading data: 0x1473650, 0x7fffa313c8d0, 6

erased blocks 0 to 7 on NAND flash device #0 'NAND 256MiB 3.3V 8-bit'

\> nand write 0 u-boot.bin 0

wrote file u-boot.bin to NAND flash 0 up to offset 0x00039800 in 123.920341s (1.823 KiB/s)


​ 很多时候会出现写不成功的情况,你可以在写完用nand dump看一下写成功没有,没有的话再写一遍就OK了。

3.测试u-boot

烧写成功后为了简单测试,我们可以先退出openocd

然后重启板子通过minicom进入u-boot

1
2
3
4
5
6
7
8
9
  Welcome to minicom 2.7
​ OPTIONS: I18n Compiled on Mar 14 2018, 09:40:14. Port /dev/ttyUSB0, 11:45:28
Press CTRL-A Z for help on special keys
U-Boot 2010.03 (7月 29 2017 - 15:00:02)
modified by tekkamanninja ([tekkamanninja@163.com](mailto:tekkamanninja@163.com)) Love Linux forever!!
I2C: ready DRAM: 64 MB Flash: 2 MB NAND: 256 MiB

* Warning - bad CRC or NAND, using default environment
In: serial Out: serial Err: serial USB slave is enable! Net: dm9000 Hit any key to stop autoboot: 0 ##### FriendlyARM U-Boot(2012-07) for 2440 ##### [f] Format the nand flash [v] Download u-boot.bin [k] Download Linux kernel [y] Download root yaffs2 image [a] Download Absolute User Application ~~ Set the boot parameter of Linux~~~~ **Boot Linux**~~~~ **[r] Reboot**~~~~ **[q] Quit to shell**~~~~ **Enter your Selection:**~~
三、OpenJTAG与JLink的区别比较

相同点:都同时具备USB转JTAG、USB转串口功能
差别:

  1. 操作系统:
    OpenJTAG可以用在Windows、Linux下;
    JLink只能用在Windows下,在Linux下它的调试功能无法使用,只能使用“JLink+USB转串口2合1”中的USB转串口功能
  2. 集成开发环境:
    OpenJTAG能用在所有支持GDB调试协议的工具上,比如IAR、Eclipse、winarm,不能用在支持RDI协议的工具上,比如ADS。
    JLink支持多种调试协议RDI、GDB调试,几乎所有Windows下的工具都支持,比如ADS、Keil MDK、IAR。
  3. 对Flash的烧写:
    OpenJTAG、JLink对FLASH的烧写功能几乎一样强。
    但是对于S3C2410、S3C2440来说,OpenJTAG更胜一筹:OpenJTAG可以烧写NAND Flash;JLink理论上也行,但是没人实现这点。
  4. 如何选择:
    如果是学习Linux,那么OpenJTAG比较适用;
    如果比较喜欢ADS、Keil等工具,那么JLink比较适用;
    如果你的开发板是S3C2410、S3C2440,那么OpenJTAG绝对适用。
四、jtag知识点小结

jtag调试是嵌入式开发中常用的一种调试方法。目前大多数soc都支持jtag调试,开发者只需要一个jtag转接器,一边是usb口连接电脑,一边是jtag连接开发板,就可以顺利进行后续的开发和调试工作了。

1、jtag是硬件协议

​ jtag和spi、nand、uart、iic一样,是一个硬件协议,主要由5个pin组成,分别是tdi、tdo、clk、rst、tms。

2、jtag的主要功能

​ 目前,jtag主要负责下载和调试两个功能。下载,即利用jtag将二进制文件下载到norflash或者是nandflash当中。调试,就是利用jtag实现对cpu的单步调试。这在开发的初始阶段是非常有用的。

3、jtag下载flash的基本原理

​ 很多时候,jtag实现flash的下载功能,是因为jtag先实现一个最小bin文件,加载到内部sram中。紧接着jtag使能cpu,这个最小bin完成flash的驱动配置,将从jtag接受到文件写入到flash当中去,比如说stm32中下载算法就是这里说的最小bin文件,如果使用的不是通用型flash,那么就需要自己编写。

4、jtag调试原理

​ jtag调试离不开cpu内部的debug模块。所有的断点设置、外设访问、寄存器读取、ram操作这些动作都需要cpu的配合。除此之外,为了实现jtag和gdb的完美配合,还需要在上位机侧实现一个gdbserver + commnd解析工具,实现pc和usb的通信。

5、jtag的硬件实现

​ 目前网上有一些jtag的开源实现方法,比如说openjtag。要做一个适合自己的仿真器或者下载器,一般需要一个stm32芯片,负责pc和仿真器通讯(usb通信),还需要一个fpga,负责jtag的收发操作。当然,fpga中的verilog代码也是需要自己完成的。

6、jtag的软件实现

​ 除了硬件之外,jtag还需要一个command上位机程序、一个下位机的固件程序。当然,为了方便上位机使用,还需要设计一个GUI、gdbserver、command parse的框架。

7、jtag的基本流程

pc -> || usb -> stm32 -> fpga || -> dev board

pc <- || usb <- stm32 <- fpag || <- dev board

8、目前市场上的jtag工具

​ 由于现在电脑普遍没有并口,现在用的最多的jtag调试工具还是jlink或者openjtag这样的usb转jtag调试板。

9、什么情况下不需要jtag

 目前很多开发板支持从sd卡启动系统,那么这个时候其实不存在flash烧录的情况,也就无所谓jtag功能了。通常,一般的soc支持jtag、norflash、nandflash、sd四种启动方式,如果能用sd卡启动,那也是非常不错的一种选择。

参考:

随想录(jtag知识点小结)

https://blog.csdn.net/feixiaoxing/article/details/93379770

使用JLINK间接烧写NAND FLASH

https://blog.csdn.net/go213/article/details/9927181


S3C2440之开发环境搭建(jtag)
http://blog.uanet.cn/EMBEDDED/mini2440/S3C2440之开发环境搭建(jtag).html
作者
dnsnat
发布于
2024年4月19日
许可协议