【教程】在Ubuntu下搭建ARM处理器 arm-linux-gcc 交叉编译环境以及OpenJTAG + openocd 烧写环境
2016-11-14 15:57
956 查看
在Ubuntu下搭建ARM处理器 arm-linux-gcc 交叉编译环境以及OpenJTAG + openocd 烧写环境
前言
本教程所用操作系统为Ubuntu 16.04,所用ARM处理器为Samsung S3C2440,在FriendlyARM Mini2440开发板上进行操作,使用OpenJTAG + openocd 烧录程序。当然,道理是相通的,所以在不同平台下也只是稍微修改一部分的配置就可以了。
步骤
1. 下载arm-linux-gcc交叉编译工具,编写程序。
(接下来的文章我会发布我学习过程中写的程序(C语言和汇编交互))Makefile 可以这样写(以点亮led为例子):
led.bin:start.o arm-linux-ld -Ttext 0 -o led.elf start.o arm-linux-objcopy -O binary led.elf led.bin arm-linux-objdump -D led.elf > led.dis start.o:start.s arm-linux-gcc -o start.o start.s -c
生成文件 led.bin 供后续使用
OpenJTAG 是一款调试/仿真工具,这里用它来烧录程序。我手头上这个使用的是FT2232D芯片,同时具备USB转JTAG、USB转串口功能。那么它和我们以前用JLink在Windows下的Keil MDK下开发stm32之类的有什么区别呢?比如,OpenJTAG可以用在Windows、Linux、MAC下,而JLink只能用在Windows,并且在Linux下它的调试功能无法使用。因此,某种程度上,OpenJTAG更有实用性。
要时使用一种硬件,当然首先要安装它的驱动程序了,我们需要到 intra2net 公司网站下载最新版(旧版当然也可以,但可能在某些配置上就不一样咯)的 libftdi ,这是OpenJTAG使用的FT2232D 芯片的底层驱动库。(注意:需要先安装libusb-dev)
下载解包后编译安装:
./configure make sudo make install
当然你也可以通过git下载源代码。
如果你也想安装ftdi-eeprom(烧写FT2232所连接的e2prom的工具),可用同样的方法下载安装。(注意:需要先安装libconfuse-dev)
2. 安装openocd
openocd是一个开源的JTAG上位机程序,目前支持很多种芯片了,并且支持的芯片还在不断增加中。当然,由于源代码都是公开的,并且可以自己编译,所以增加自定义的工具驱动程序也是相当容易的。打开你的工作目录,打开终端,输入:(当然你要安装git : sudo apt-get install git)
git clone git://openocd.git.sourceforge.net/gitroot/openocd/openocd
之后你会得到openocd最新版的源码
进入openocd的目录,执行:
sudo ./bootstrap sudo ./configure --enable-ftdi --enable-usb_blaster_libftdi --enable-openjtag_ftdi --enable-maintainer-mode --enable-legacy-ft2232_libftdi sudo make sudo make install
上面 ./configure 的参数是根据我的板子定的,如果要使用别的芯片,调试工具什么的,要进行相应修改,详情:
./configure --help
安装完毕之后,执行
openocd -v
会输出版本信息:
Open On-Chip Debugger 0.10.0-dev-00251-g888d5a5-dirty (2016-04-24-13:35) Licensed under GNU GPL v2 For bug reports, read http://openocd.org/doc/doxygen/bugs.html[/code]3. 配置 openocd.cfg
可以参考以下配置文件:(这里我也是根据自己的情况配置,具体视硬件而定)interface ftdi ftdi_device_desc "USB<=>JTAG&RS232" ftdi_vid_pid 0x1457 0x5118 ftdi_layout_init 0x0f08 0x0f1b ftdi_layout_signal nSRST -data 0x0200 -noe 0x0800 ftdi_layout_signal nTRST -data 0x0100 -noe 0x0400 jtag_khz 1500 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 0x40000000 -work-area-size 0x4000 -work-area-backup 1 #reset configuration adapter_nsrst_delay 100 jtag_ntrst_delay 100 reset_config trst_and_srst #------------------------------------------------------------------------- # JTAG ADAPTER SPECIFIC # IMPORTANT! See README at top of this file. #------------------------------------------------------------------------- adapter_khz 12000 #jtag interface #------------------------------------------------------------------------- # GDB Setup #------------------------------------------------------------------------- gdb_breakpoint_override hard #------------------------------------------------ # ARM SPECIFIC #------------------------------------------------ targets arm7_9 dcc_downloads enable arm7_9 fast_memory_access enable nand device 0 s3c2440 $_TARGETNAME adapter_nsrst_delay 100 jtag_ntrst_delay 100 reset_config trst_and_srst init echo "--- login with - telnet localhost 4444 ---"4. 启动openocd
将开发板连接的OpenJTAG的USB接口接入PC,在终端输入:openocd -f openocd.cfg
成功接入之后,打开另一个终端,输入:telnet localhost 4444
进入操控指令方式Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. Open On-Chip Debugger >
输入 poll ,显示开发板当前信息
输入 halt ,暂停
输入 resume ,恢复
输入 reset ,复位
以烧写以个点亮LED的程序为例子:halt //先暂停当前程序的运行 nand probe 0//识别出Nand Flash nand erase 0 0 0x20000//擦除0地址开始的128K内容 nand write 0 led.bin 0//写入LED.bin reset//复位
然后就可以看到LED亮了!
欢迎阅读我的后续学习过程的 程序分享 & 解析
谢谢阅读,^ _ ^
部分参考资料来自:http://blog.chinaunix.net/uid-20543672-id-94365.html
我的个人主页:http://www.techping.cn/
我的个人站点博客:http://www.techping.cn/blog/wordpress/
我的CSDN博客:http://blog.csdn.net/techping
我的简书:http://www.jianshu.com/users/b2a36e431d5e/timeline
我的GitHub:https://github.com/techping
欢迎相互follow~
相关文章推荐
- ubuntu14.01 搭建交叉编译环境arm-linux-gcc 4.3.2
- Ubuntu14.04下arm-linux-gcc交叉编译环境搭建
- ubuntu下arm-linux-gcc交叉编译环境搭建
- Ubuntu 16.04搭建交叉编译环境arm-linux-gcc遇到的问题
- Ubuntu 16.04[64bit]嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- Ubuntu 16.04[64bit]嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- Ubuntu16.04下arm-linux-gcc交叉编译环境搭建
- 【Linux学习】Ubuntu下嵌入式交叉编译环境arm-linux-gcc搭建
- Ubuntu 16.04(64bit)嵌入式交叉编译环境搭建arm-linux-gcc使用
- Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- ok6410[001] Ubuntu 16.04[64bit]嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- 64位Ubuntu 16.04搭建嵌入式交叉编译环境arm-linux-gcc过程图解
- Ubuntu 16.04[64bit]嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- ubuntu arm-linux-gcc-4.4.3交叉编译环境搭建
- 在Ubuntu13.10上自己动手搭建交叉编译环境arm-linux-gcc-4.8.2
- Ubuntu开发环境搭建(2)【安装arm-linux-gcc-4.4.3交叉编译环境】
- Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- Ubuntu 14.04 LTS嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- Ubuntu16.4(64位)下gcc-linaro-arm-linux-gnueabihf交叉编译环境搭建