不加载操作系统,直接在U-boot上执行自己的代码[转载两篇]
本帖最后由 WindLand 于 2013-4-18 11:39 编辑虽说硬件不同,但是原理一样
I.本文转自:http://blog.csdn.net/wfq0624/article/details/8605164
1 Cortex A8 LED点亮程序分析
1.1 环境搭建准备工作软件环境: 1.下载eclipse软件(绿色软件) 2.安装“yagarto-bu-2.22_gcc-4.7.1-c-c++_nl-1.20.0_gdb-7.4.1_eabi_20120616.exe” 3. tftpd32.exe硬件平台: FS_S5PC100
搭建硬件环境: 1.PC UART-->开发板串口COM1(通过串口线) 2.电脑网卡-->开发板网卡(通过网线)
1.2 启动Eclipse软件,导入已有LED project http://img.my.csdn.net/uploads/201302/23/1361599075_9586.png
1.3 Makefile文件分析红色字体必须根据实际安装路径和项目路径细微修改
# CORTEX-A8 PERI DRIVER CODE
# VERSION 1.0
# ATHUOR lapset (klapset@gmail.com)
# MODIFY DATE
# 2012.2.22 by lapset ,to change the format of Makefile
#NOTE :please fix the following info to adpat to your environment
CROSS_COMPILE=arm-none-eabi-
LDPATH="C:\Program Files\yagarto\lib\gcc\arm-none-eabi\4.7.1\include"
OUTPATH="G:\tftp"
NAME=led
COMMONPATH = "G:\ARM\example modify\led_FS_S5PC100\common\include"
#=============================================================================#
#DO NOT TO CHANG THE CODE AFTER THIS !!!
export CFLAGS LD CC STRIP OBJCOPY OBJDUMP COMMONPATH
CFLAGS += -g -O0 -fno-strict-aliasing -mabi=apcs-gnu -mfpu=vfpv3 -mfloat-abi=softfp-fno-builtin -nostdinc -isystem$(LDPATH) -I$(COMMONPATH)
LD= $(CROSS_COMPILE)ld
CC= $(CROSS_COMPILE)gcc
STRIP= $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
OBJS := start/start.o common/src/printf.o common/src/uart.o common/src/_udivsi3.o common/src/_umodsi3.o$(NAME).o
SUBDIRS := common/src/ start/
all:$(SUBDIRS)$(OBJS)
$(LD) $(OBJS) -Tmap.lds -o$(NAME).elf
$(OBJCOPY) -O binary $(NAME).elf$(NAME).bin
$(OBJDUMP) -D$(NAME).elf >$(NAME).dis
cp ./$(NAME).bin$(OUTPATH)
$(SUBDIRS):
$(MAKE) -C $@
%.o: %.S
$(CC)$(CFLAGS) -c -o $@ $<
%.o: %.c
$(CC)$(CFLAGS) -c -o $@ $<
clean:
rm -rf $(OBJS) *.elf *.bin *.dis$(OUTPATH)/$(NAME).bin
1.4 Build project生成led.bin文件1. 鼠标右击project name,选择“Build Project”
http://img.my.csdn.net/uploads/201302/23/1361599104_1646.png
2. 成功后,会在该目录下【OUTPATH="G:\tftp"】生成led.bin文件,
如下所示,将tftpd32.exe和led.bin放在同一个目录下
http://img.my.csdn.net/uploads/201302/23/1361599160_4789.png
1.5 配置ip地址1. 让开发板上电,进入uboot
2. 输入pri 打印环境变量,使用setenv命令来修改参数,让ip和PC ip地址保持一致
3. Ping ip地址,显示alive字样,表示网络连接OK
http://img.my.csdn.net/uploads/201302/23/1361599197_7448.png
4. 打开PC上的tftpd32.exe软件,设置好对应的ip地址
http://img.my.csdn.net/uploads/201302/23/1361599227_2931.png
5.执行tftp下载led.bin到内存0x20008000地址处,然后运行该程序”go 20008000”
http://img.my.csdn.net/uploads/201302/23/1361599280_1767.png
II.本文转自:http://blog.csdn.net/joans123/article/details/7380906
使用gcc编译出二进制文件给uboot中go的命令执行.
test.c 文件如下
================ Start of test.c =======================================
#include <stdio.h>
typedef void (*pr)(const char *fmt, ...);
int main(int argc, char **argv)
{
// 0x80e96d8c 是uboot中 printf的地址, 查看uboot下面的 System.map可知.
pr print = (pr)0x80e96d8c;
print("hello wolrd");
while (1);
return 0;
}
================ End of test.c =======================================
Makefile 文件如下:
1. 使用gcc的-c选项声场.o文件
2. 使用ld并指定lds文件生成elf文件
3. 使用objcopy去掉符号表, 生成二进制文件
================ Start of Makefile =======================================
CROSS_COMPILE ?= /opt/toolchain/arm-eabi-4.4.0/bin/arm-eabi-
CC := ${CROSS_COMPILE}gcc
LD:= ${CROSS_COMPILE}ld
NM:= ${CROSS_COMPILE}nm
OBJCOPY := ${CROSS_COMPILE}objcopy
OBJDUMP := ${CROSS_COMPILE}objdump
CFLAGS := -fno-builtin -Wall -Wstrict-prototypes -fno-stack-protector -fno-common -nostdinc -static -fPIC
CFLAGS += -isystem /opt/toolchain/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/include
CFLAGS +=-marm -mabi=aapcs-linux -mno-thumb-interwork -march=armv5
#LDFLAGS := -Ttext 0x82000000 -e main --oformat binary
LDFLAGS :=-Bstatic -T test.lds -v
# output map file
LDFLAGS += -Map test.map
LDFLAGS += -L /opt/toolchain/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0 -lgcc
all:
$(CC) ${CFLAGS} -c go_test.c -o go_test.o
$(LD) ${LDFLAGS} go_test.o -o go_test.elf
$(NM) -n go_test.elf > go_test.map
$(OBJCOPY) -S -O binary go_test.elf go_test.bin
cp go_test.bin /tftpboot/
================ End of Makefile =======================================
test.lds 文件如下:
OUTPUT_FORMAT : 输出的文件格式
OUTPUT_ARCH : 输出文件的cpu类型
ENTRY : 输出文件的入口, 与ld中的-e选项等效
指定其实地址为 : 0x82000000, 根据uboot中加载地址而定
================ Start of test.lds =======================================
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(main)
SECTIONS
{
. = 0x82000000;
.text : { *(.text) }
.data : { *(.data) }
.bss: { *(.bss)}
}
================ End of test.lds =======================================
使用上面3个文件便可编译出 go_test.bin的二进制文件, 然后拷贝到 /tftpboot目录下, 并在uboot中输入:
#tftp 82000000 go_test.bin
#go 82000000
执行这条命令后输出如下:
## Starting application at 0x82000000 ...
hello wolrd
可见go_test.bin正常执行.
错误解决:
1. go_test.o:(.ARM.exidx+0x0): undefined reference to `__aeabi_unwind_cpp_pr1': 更换一个gcc工具链即可, 原来使用arm-2010q1 出现这个错误. 后来更换成arm-eabi-4.4.0就可以了. 不过arm-eabi-4.4.0不能生成linux可执行的elf文件.
2. go_test.o:could not read symbols: File in wrong format :由于Makefile编写错误造成的, 没个CC变量赋值,而使用i386 gcc编译. 使用file命令可查看go_test.o文件的格式.
cubie的网络没驱动啊~提示Net: Net Initialization Skipped No ethernet found. 有人成功过吗? mark one mark 还没什么头绪,先做个记号
mark
谢谢
请问cubietruck如何让uboot不加载操作系统啊,怎么让他从SD卡启动呢
先記錄, 之後有時間回來嘗試
页:
[1]