怎么使用uboot引导应用程序?

描述

uboot默认是支持执行应用程序的,就像引导内核一样,我们也可以自己写一个应用程序,让uboot启动时引导。

在uboot examples/standalone 目录下,有hello_world.c文件,编译uboot的时候,会自动编译hello_world.bin文件。

裸机程序未加链接地址时,只能使用text代码段,如果裸机程序中使用出现了跨端操作(使用text端段以外的段:rodata,data,bss段),必须在链接时手工指定连接链接地址为实际的运行地址。

默认的链接地址由 Makefile中通过CONFIG_STANDALONE_LOAD_ADDR 指定。

Uboot

这个地址不一定适合我们的板子,为了不影响uboot的正常运行,我们修改该地址为内核的链接地址0x280000

重新编译的uboot后,将hello_world.bin通过tftp加载到内存中。

uboot设置好参数。

=> setenv ipaddr 192.168.137.110
=> setenv serverip 192.168.137.1
=> setenv gatewayip 192.168.137.1
=> tftp 0x00280000 hello_world.bin
ethernet@fe300000 Waiting for PHY auto negotiation to complete.. done
Speed: 1000, full duplex
Using ethernet@fe300000 device
TFTP from server 192.168.137.1; our IP address is 192.168.137.110
Filename 'hello_world.bin'.
Load address: 0x280000
Loading: #
         0 Bytes/s
done
Bytes transferred = 794 (31a hex)

执行go指令去引导我们的程序。

=> go 0x280000
## Starting application at 0x00280000 ...
Example expects ABI version 9
Actual U-Boot ABI version 9
Hello World
argc = 1
argv[0] = "0x280000"
argv[1] = ""
Hit any key to exit ...

成功打印出Hello World。

也可以将 go 0x280000 添加到bootcmd 中,每次启动内核前,先去引导应用程序,再引导内核。

end

打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分