【嵌入式开发】 嵌入式开发工具简介 (裸板调试示例 | 交叉工具链 | Makefile | 链接器脚本 | e

发布者:DazzlingSmile最新更新时间:2024-10-18 来源: cnblogs关键字:裸板调试  交叉工具链  Makefile  链接器脚本  eclipse  JLink  调试环境 手机看文章 扫描二维码
随时随地手机看文章

开发环境 : 

-- 操作系统 : Vmware11 + RedHat6.3 企业版 + Win8.1;

-- 硬件 : OK-6410-A 开发板, JLink;


一. 编译并烧写裸板程序示例

1. 设置交叉编译工具

OK-6410-A 使用 4.3.2 的交叉编译工具链, 将交叉编译工具链设置成 Ubuntu 的默认交叉编译工具链;


安装交叉编译工具链 : 解压 arm-linux-gcc-4.3.2.tgz 文件 


-- 安装命令 : 使用命令 tar -xvzf arm-linux-gcc-4.3.2.tgz -C /, 由于 tgz 压缩文件内也是存在目录结构, 解压后, 交叉编译工具链直接解压到了 /usr/local/arm/4.3.2 目录;


-- 配置环境变量 : 环境变量在 /etc/profile 中配置, 在该文件中添加如下代码 : 



ARM_LINUX='/usr/local/arm/4.3.2/bin'

export PATH=$PATH:$ARM_LINUX

-- 使配置文件生效 : 执行 source /etc/profile 命令, 该配置即可生效, 执行 arm-linux 按 tab 键 : 


octopus@octopus:~$ arm-linux-

arm-linux-addr2line  arm-linux-c++filt    arm-linux-gcc-4.3.2  arm-linux-gprof      arm-linux-objdump    arm-linux-sprite

arm-linux-ar         arm-linux-cpp        arm-linux-gcov       arm-linux-ld         arm-linux-ranlib     arm-linux-strings

arm-linux-as         arm-linux-g++        arm-linux-gdb        arm-linux-nm         arm-linux-readelf    arm-linux-strip

arm-linux-c++        arm-linux-gcc        arm-linux-gdbtui     arm-linux-objcopy    arm-linux-size  


2. 编译代码

(1) 代码示例


代码直接是开发板的示例代码:

-- led.S : 

octopus@octopus:~/arm/01_code$ more led.S 
.text
.globl _start
#define VIC0_INT	0x71200000
#define VIC1_INT	0x71300000

_start: bl reset
		ldr	pc, _undefined_instruction
		ldr	pc, _software_interrupt
		ldr	pc, _prefetch_abort
		ldr	pc, _data_abort
		ldr	pc, _not_used
		ldr	pc, _irq
		ldr	pc, _fiq
_undefined_instruction:b .
_software_interrupt:b .
_prefetch_abort:b .
_data_abort:b .
_not_used:b .
_irq:b .
_fiq:b .
reset:
		mrs	r0,cpsr
		bic	r0,r0,#0x1f
		orr	r0,r0,#0xd3
		msr	cpsr,r0

		bl set_peri_port
		bl disable_watchdog
		bl disable_irq
		bl init_led
		bl light_led

halt:
		bl halt

set_peri_port:
@告诉cpu外设的地址
	    ldr r0, =0x70000000
	    orr r0, r0, #0x13
	    mcr p15,0,r0,c15,c2,4
		mov	pc, lr

disable_watchdog:
@关闭看门狗
		ldr r0, =0x7E004000
		mov r1, #0
		str r1, [r0] @ str, store,
		mov	pc, lr

disable_irq:
@屏蔽中断
		ldr	r1, =0x0
		ldr	r0, =VIC0_INT
		str	r1, [r0]

		ldr	r1, =0x0
		ldr	r0, =VIC1_INT
		str	r1, [r0]
		mov	pc, lr

init_led:
@设置GPN为输出模式
		ldr r1, =0x7F008820
		ldr r0, =0x1111
		str r0, [r1]
		mov	pc, lr

light_led:
@点亮LED1
		ldr r1, =0x7F008824
		mov r0, #0xf
		str r0, [r1]
	    mov r0,#0xe
	    str r0,[r1]
	    mov	pc, lr

-- led.lds : 


octopus@octopus:~/arm/01_code$ more led.lds 


OUTPUT_FORMAT('elf32-littlearm', 'elf32-littlearm', 'elf32-littlearm')
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
	. = 0x50008000;

	. = ALIGN(4);
	.text :
	{
		led.o	(.text)
		*(.text)
	}

	. = ALIGN(4);
	.rodata : { *(SORT_BY_ALIGNMENT(SORT_BY_NAME(.rodata*))) }

	. = ALIGN(4);
	.data : { *(.data) }


	. = ALIGN(4);
	__bss_start = .;
	.bss (NOLOAD) : { *(.bss) . = ALIGN(4); }
	_end = .;
}


-- Makefile : 


octopus@octopus:~/arm/01_code$ more Makefile 
all: led.o 
	arm-linux-ld -Tled.lds -o led.elf led.o
	arm-linux-objcopy -O binary led.elf led.bin
	
led.o : led.S
	arm-linux-gcc -g -o led.o -c led.S
	
.PHONY: clean
clean:
	rm *.o led.elf led.bin




(2) 编译



编译 : 在该目录执行 make 命令, 编译后多了 led.o, led.elf, led.bin 三个文件, 其中 led.bin 是要烧写到 nand flash 中的可执行二进制程序;

-- 编译前 : 

octopus@octopus:~/arm/01_code$ ls
led.lds  led.S  Makefile


-- 编译后 : 

octopus@octopus:~/arm/01_code$ make
arm-linux-gcc -g -o led.o -c led.S
arm-linux-ld -Tled.lds -o led.elf led.o
arm-linux-objcopy -O binary led.elf led.bin
octopus@octopus:~/arm/01_code$ ls
led.bin  led.elf  led.lds  led.o  led.S  Makefile




3. 烧写 led.bin



(1) 启动方式切换



sd 卡启动 : (1~8) 位置 : 0, 0, 0, 1, 1, 1, 1, 1;

nand flash 启动 : (1~8) 位置 : x, x, x, 1, 1, 0, 0, 1;

nor flash 启动 : (1~8) 位置 : x, x, x, 1, 0, 1, 0, x;




(2) 制作SD卡启动盘



详细过程参照 : http://blog.csdn.net/shulianghan/article/details/42254237#t42


(3) 串口操作



开发板串口方案一 -- 使用SecureCRT 串口连接 : 

-- 设备管理器中查看串口端口 : COM7;


-- 串口连接属性 : 


-- 连接串口 : 




开发板串口方案二 -- 打开 minicom 工具 : minicom 串口调试工具;

-- 注意 : 使用 root 用户打开, sudo minicom;


sd 卡启动 : 

-- 启动方式 : 插入 sd 卡, 将启动模式设置为 sd 卡启动, 即将 屏幕右侧的 8个开关设置成 (1~8) 位置 : 0, 0, 0, 1, 1, 1, 1, 1, 打开电源;

-- 注意 : 打开电源时 不停按 空格键;

-- 串口终端显示 : 


U-Boot 1.1.6 (Oct  9 2012 - 13:20:58) for SMDK6410


****************************************

**    u-boot 1.1.6                    **

**    Updated for OK6410  TE6410 Board  **

**    Version (2012-09-23)          **

**    OEM: Forlinx Embedded           **

**    Web: http://www.witech.com.cn   **

****************************************


CPU:     S3C6410 @532MHz

         Fclk = 532MHz, Hclk = 133MHz, Pclk = 66MHz, Serial = CLKUART (SYNC Mode) 

Board:   SMDK6410

DRAM:    256 MB

Flash:   0 kB

NandFlash Information:

Nandflash:ChipType= SLC  ChipName=MT29F16G08ABACAWP

No  No Calc pagesize, blocksize, erasesize,  use ids table .............

NandFlash:name=NAND 2GiB 1,8V 8-bit,id=38, pagesize=4096 ,chipsize=1024 MB,erasesize=524288 oobsize=128

NandFlash Size is 1024 MB 

SD/MMC:  SD 2.0 / Manufacturer: 0x1B,OEM: 'SM/00000',REV: 1.0,S/N: -1320320343,DATE: 2008/3

         MMC/SD size: 971 MiB

         Freq = 25MHz

In:      serial

Out:     lcd

Err:     lcd

Hit any key to stop autoboot:  0 


###################### User Menu for OK6410#####################

[1] Format the nand flash

[2] Burn image from SD card

[3] Burn image from USB

[4] Reboot the u-boot

[5] Exit to command line

-----------------------------Select---------------------------------

Enter your Selection: 

格式化 nand flash : 在上面的 minicom 命令行, 选择 1 ([1] Format the nand flash -- 格式化 nand Flash), 弹出 Really scrub this NAND flash? 时 选择 y;

-----------------------------Select---------------------------------
Enter your Selection:1

NAND scrub: device 0 whole chip
Warning: scrub option will erase all factory set bad blocks!
         There is no reliable way to recover them.
         Use this command only for testing purposes if you
         are sure of what you are doing!

Really scrub this NAND flash? 
Erasing at 0x3ff80000 -- 100% complete.
Scanning device for bad blocks
OK

###################### User Menu for OK6410#####################
[1] Format the nand flash
[2] Burn image from SD card
[3] Burn image from USB
[4] Reboot the u-boot
[5] Exit to command line
-----------------------------Select---------------------------------
Enter your Selection:




选择从 usb 烧写映像 : 选择 3 ([3] Burn image from USB -- 从usb烧写映像);

-----------------------------Select---------------------------------
Enter your Selection:3

##### Select the fuction #####
[1] Flash u-boot
[2] Flash kernel
[3] Flash system
[4] Exit
Enter your Selection:



选择 烧写 u-boot 类型程序 : 裸板程序都属于 u-boot 类型的;

##### Select the fuction #####
[1] Flash u-boot
[2] Flash kernel
[3] Flash system
[4] Exit
Enter your Selection:1

NAND erase: device 0 offset 0x0, size 0x200000
Erasing at 0x180000 -- 100% complete.
OK
Insert a OTG cable into the connector!


设置虚拟机的 USB 接口 : 之前写过, 详情见 http://blog.csdn.net/shulianghan/article/details/42254237#t45 ;



(3) Linux 操作



编译 led 源码 : 

-- 进入 led 源码目录 : 执行 make 命令, 将编译后的文件 拷贝到 dnw 所在目录;



烧写 led.bin : 

-- 加载 dnw 驱动 : 使用 insmod dnw_usb.ko 命令;


-- 烧写 led.bin : 使用 ./dnw led.bin 50008000 命令;


-- 串口终端显示 : 如下显示, 烧写成功;


-- 关闭开发板使用 nand flash 启动 : 可以看到 LED1 点亮;




二. 交叉工具链






1. 交叉编译器





(1) 普通编译



编译下面的代码 : 

/*************************************************************************
    > File Name: main.c
    > Author: octopus
    > Mail: octopus_work.163.com 
    > Created Time: 2015年01月03日 星期六 14时25分11秒
 ************************************************************************/

#include
int main(int argc, char** argv)
{
	printf('Hello World!n');
	return 0;
}

-- 编译执行代码 : 

[1] [2] [3] [4] [5]
关键字:裸板调试  交叉工具链  Makefile  链接器脚本  eclipse  JLink  调试环境 引用地址:【嵌入式开发】 嵌入式开发工具简介 (裸板调试示例 | 交叉工具链 | Makefile | 链接器脚本 | e

上一篇:【嵌入式开发】ARM 芯片简介 (ARM芯片类型 | ARM处理器工作模式 | ARM 寄存器 | ARM 寻址)
下一篇:Linux驱动——LED闪烁

推荐阅读最新更新时间:2026-03-25 15:20

[国嵌笔记][016][交叉工具]
交叉工具链 1.交叉工具是编译在arm平台上运行程序的工具,交叉工具链是交叉工具的集合 2.file filename 通过file命令可以查看程序运行的平台等相关信息 3.交叉开发 1.在x86平台上产生其他平台上运行程序的模式叫做交叉开发 2.宿主机是产生嵌入式软件的平台,目标机是运行嵌入式软件的平台 常用的交叉工具 1.交叉编译器 arm-linux-gcc 相同之处 arm-linux-gcc file.c -o file 与gcc用法上一样 不同之处 gcc从 /usr/include/ 下寻找头文件 arm-linux-gcc从 /usr/loacl/arm/.../lib 下寻找头文件
[单片机]
S5PV210 | 安装交叉编译工具(toolchain)
交叉工具链 交叉编译:是A机器上编译生成,运行在B机器上。两个机子有不同的机器指令。 工具链:一般由编译器、连接器、解释器和调试器组成。 扩展阅读:交叉编译工具链(详解)- 博客园 1.准备资料: 项目地址: 1.linux+QT项目:x210bv3s / qt_x210v3s_160307 2.裸机项目:x210bv3s / v210_NoOsDemo 交叉编译工具链: arm-2009q3.tar.bz2(可百度搜索网络资源) 网友分享资源: https://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/arm-2009q
[单片机]
玩转S3C6410之一 交叉工具制作(gcc4.5.1-armv6-vfp)
软件平台:ubuntu 11.10(按照本人博客中“玩转Ubuntu-11.10”系列的文章进行安装) 主机编译器: gcc 4.6.1 硬件平台:tiny6410 1、准备环境 必备工具包:bison、flex、texinfo、automake、libtool、cvs、patch、libncurses5-dev、aria2、curl、g++、svn、gawk、cvsd、subversion (有些文章有写要安装gcj,在我的Ubuntu11.10安装不了,提示说它被其它的软件包引用了,可能是我之前装的其他工具已经包含gcj了把) 我们可以通过以下一条命令来获得它们,但需要ubuntu11.10接入
[单片机]
U-boot 在 mini2440-S3C2440 上的移植(1)-开发环境搭建-交叉编译工具的安装
编译U-boot给mini2440时,要编译出能在ARM平台上使用的可执行文件-bin,首先要在ubuntu 中安装交叉编译工具链,因为我使用的是友善之臂的开发板,所以我使用的已经制作好的工具链,当然也可以自己制作工具链:如基于GCC和glibc制作工具链,可以使用cross tools编译; 我使用的工具链的版本是arm-linux-gcc-4.3.3版本,下载地址:下载地址 1.在pc端下载好以后,将压缩包用xftp传输到Ubuntu;当然也可以用其他软件上传;上传后把它放在根目录下的/usr/local文件夹中新建一个arm文件夹,然后把压缩包复制到这个文件夹;注意先建好文件夹再上传,可以减少很多工作量; 一定要上传压缩包,
[单片机]
U-boot 在 mini2440-S3C2440 上的移植(1)-开发<font color='red'>环境</font>搭建-<font color='red'>交叉</font>编译<font color='red'>工具</font><font color='red'>链</font>的安装
Exynos4412 Uboot 编译工具 —— 交叉工具 arm-linux-gcc 的安装
一、什么是交叉编译? 在开发主机运行编译器编译内核、应用程序。内核和程序在目标机上运行,这个编译过程被称为交叉编译。编译器运行在开发主机(通常是X86体系的PC机)上,编译出的的代码是目标机体系结构的,如:ARM。 在主机上除了编译还可以完成制作根文件系统地工作。 嵌入式Linux开发,交叉编译使用开源GNU工具集,gcc等。 二、制作交叉编译器 我们可以自己制作交叉编译器,需要gcc,glibc,二进制工具集 ,通过crosstool,crosstool-ng脚本来实现。这里不展示制作过程。 三、安装交叉编译器 1、解压工具链压缩包 1)将gcc-4.6.4.tar.xz 拷贝到 toolschain文
[单片机]
Exynos4412 Uboot 编译<font color='red'>工具</font> —— <font color='red'>交叉</font><font color='red'>工具</font><font color='red'>链</font> arm-linux-gcc 的安装
S3C2440-裸机篇-02 | 安装和使用arm-linux-gcc交叉编译工具
1.为什么需要交叉编译工具 宿主机运行的是标准Linux操作系统,编译出的程序却需要在目标机的Linux上跑,这就叫交叉编译,编译器叫做交叉编译器。 之前我们已经使用过gcc编译Linux本地主机的程序(Linux C语言编程(上篇) | gcc的使用),而我们现在需要的这个编译器的目标系统是ARM,不运行操作系统,仅运行裸机程序,需要在Linux主机上编译出可以运行在S3C2440@ARM920T芯片上跑的程序,所以不能使用这个编译器,需要使用arm-linux-gcc交叉编译器。 2.arm-linux-gcc的安装 arm-linux-gcc是ARM官方基于Linux平台的arm编译器,其特点有: 开源免费 支持
[单片机]
S3C2440-裸机篇-02 | 安装和使用arm-linux-gcc<font color='red'>交叉</font>编译<font color='red'>工具</font><font color='red'>链</font>
AT91RM9200引导程序的建立(一)建立交叉编译工具
写在前面: 本系列文章将详细的讲述AT91RM9200引导程序的建立过程,其中包括建立交叉编译工具链,gdb+gdbserver的编译安装使用,tftp,NFS的安装使用,超级终端或者minicom的使用,内核的编译升级,U-Boot的移植,Ramdisk、根文件系统的建立制作,busybox的编译、应用等。从而重现完整的开发过程。在写这个文档的过程中,本人参考了许多资料,在这里要感谢互联网,感谢所有社区,论坛里无私提供帮助的同行们。特别感谢一下鲁郁先生,是他让我在AT91RM9200上成功的移植了U-Boot 1.1.4 。本人是从不懂一路走来,走的过程中将开发过程详细记述下来,从一个初学者的角度来写下这个系列的文章,以方
[单片机]
ARM Linux 交叉编译 工具 制作攻略
制作之前确保你的机子上有如下几个工具:bison flex build-essential。 build-essential主要是用于提供GCC、GLIBC等必要的编译资源,一般做开发的人员机子上应该都会有的。如果没有,对于UBUNTU用 户:sudo apt-get install build-essential bison flex,其它用户自己看着办,! 1、从http://kegel.com/crosstool处下载crosstool-0.43.tar.gz并解开存于$HOME下。 假如你想要arm9tdmi上的工具链(其它工具链方法相同),进入crosstool-0.43目录,用文本编辑器打开d
[单片机]
小广播
最新单片机文章
何立民专栏 单片机及嵌入式宝典

北京航空航天大学教授,20余年来致力于单片机与嵌入式系统推广工作。

厂商技术中心

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

 
机器人开发圈

电子工程世界版权所有 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2026 EEWORLD.com.cn, Inc. All rights reserved