快乐虾
http://blog.csdn.net/lights_joy/
欢迎转载,但请保留作者信息
VELT的全称是Visual EmbedLinuxTools,它是一个与visual gdb类似的visual studio插件,用以辅助完成Linux开发。利用这个插件,将可以在visual studio的IDE中进行Linux应用程序的开发(包括编译和调试),也可以进行uboot和linux内核的编译,并根据编译时的错误信息正确定位到源码。目前的版本是0.1.1,仅支持vs2013,是一个刚刚启动开发不久的插件。可以在CSDN下载频道下载(http://download.csdn.net/detail/lights_joy/8322193),安装过程参见《用Vs2013+VELT-0.1.0进行Linux开发:环境搭建》。下面是它的基本功能:
支持x86 Linux,hi3516,hi3520三个平台。
完成UBOOT的编译,并根据编译的错误信息自动定位到相应的文件位置。
完成LINUX内核的编译,并根据编译的错误信息自动定位到相应的文件位置。
完成LINUX内核的配置。
不使用Makefile进行Linux应用程序的编译。
使用SSH连接目标机器并用gdb进行应用程序的调试。
使用Telnet连接目标机器并用gdb进行应用程序的调试。
VELT的发布文件中并不包含UBOOT的示例工程,也不包含Hi3516相关的工程,本文尝试让其支持Hi3516uboot的编译。
在velt-0.1.1的安装目录下有一个叫template的子目录,里面有一个叫LinuxConsoleApplication的示例工程,我们先拿它做为基础工程进行修改。
把LinuxConsoleApplication工程改名为HI3516Uboot并和u-boot放在同级目录下:
此工程文件在windows下的访问路径为Z:\projects\test\hi3516,对应的Linux路径为:
/work/projects/test/hi3516
由于示例工程中并不包含Hi3516平台,在VS中添加一个:
再删除其余几个平台,只保留Hi3516平台:
接着在项目属性中修改项目类型和源码根目录:
修改编译主机的参数:
接着修改编译器参数:
需要注意的是,这里的编译器路径不需要加上bin。当VELT进行编译操作时,它将登录编译主机,将此路径添加到PATH变量中且设置为第一个路径。
接着修改工程文件,打开Hi3516Uboot.vcxproj,找到这一行:
<Import Condition="$(Platform)==‘hi3516‘" Project="$(EMBEDLINUX_ROOT)\msbuild\EmbedLinux.Msbuild.targets" /> 将之修改为: <Import Condition="$(Platform)==‘hi3516‘" Project="$(EMBEDLINUX_ROOT)\msbuild\EmbedLinux.Make.targets" />
接下来修改make.py,定义编译时要执行的操作。
第一个操作是Build
def Build(self, chan) : self.error = False exec_command(chan, "cd /work/projects/test/hi3516/u-boot-2010.06/ && " "make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- && " "echo xxxxx\n") return not self.error;
当我们在VS中选择“生成项目“的时候,VELT将执行此python脚本,在这里可以定义要执行的bash脚本。exec_command是预先定义的一个python函数,用以执行一段bash脚本。
接下来是Rebuild,在VS中进行重新生成操作时将调用此脚本:
def Rebuild(self, chan) : self.error = False exec_command(chan, "cd /work/projects/test/hi3516/u-boot-2010.06/ && " "make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- distclean && " "make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- godeyes_config && " "make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- && " "echo xxxxx\n") return not self.error;
第三个是Clean
def Clean(self, chan) : self.error = False exec_command(chan, "cd /work/projects/test/hi3516/u-boot-2010.06/ && " "make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- clean && " "echo xxxxx\n") return not self.error;
最后要修改Convert函数,此函数的作用在于将make生成的信息转换为vs可以识别的信息:
cur_dir = ‘.‘ def Convert(self, ln) : if re.match(".*Entering directory", ln): idx1 = ln.find("`") ln2 = ln[idx1+1:] self.cur_dir = ln2[:len(ln2)-2] + ‘/‘ self.cur_dir = self.cur_dir.replace(HostShareRoot, HostShareRootWin) self.cur_dir = self.cur_dir.replace(‘/‘, ‘\\‘) elif re.match(".*:[0-9]+: error:", ln): lst = ln.split(‘:‘) file = self.cur_dir + lst[0] ln = file + "(" + lst[1] + "): error C2004: " + lst[3] self.error = True elif re.match(".*:[0-9]+: warning:", ln): lst = ln.split(‘:‘) file = self.cur_dir + lst[0] ln = file + "(" + lst[1] + "): warning C2005: " + lst[3] elif re.match(".*:[0-9]+: undefined reference", ln): lst = ln.split(‘:‘) file = lst[0].replace(HostShareRoot, HostShareRootWin) file = file.replace("/", "\\") ln = file + "(" + lst[1] + "): error C2007: " + lst[2] self.error = True elif re.match("make\[[0-9]+\]:.*Error [0-9]", ln): self.error = True return ln
然后就可以正常编译了:
1>------ 已启动全部重新生成: 项目: HI3516Uboot, 配置: Debug hi3516 ------ 1> EmbedLinux: Rebuild Task, prepare to execute 1> HostIp: 192.168.24.129 1> Platform: hi3516 1> Configuration: Debug 1> Last login: Thu Jan 8 22:24:57 2015 from 192.168.24.1 1> 1> [embed@localhost ~]$ PATH=/work/toolchain/hi3516/1.0.9.0/arm-hisiv100-linux/bin/:$PATH 1> [embed@localhost ~]$ cd /work/projects/test/hi3516/u-boot-2010.06/ && make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- distclean && make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- godeyes_config && make arch=arm CROSS_COMPILE=arm-hisiv100-linux-uclibcgnueabi- && echo xxxxx 1> Configuring for godeyes board... 1> Generating include/autoconf.mk 1> Generating include/autoconf.mk.dep 1> for dir in tools examples/standalone examples/api arch/arm/cpu/godeyes /work/projects/test/hi3516/u-boot-2010.06/arch/arm/cpu/godeyes/ ; do 1> make -C $dir _depend ; done 1> make[1]: Entering directory `/work/projects/test/hi3516/u-boot-2010.06/tools‘ ............. 1> make[1]: Entering directory `/work/projects/test/hi3516/u-boot-2010.06/arch/arm/cpu/godeyes‘ 1> make[1]: Nothing to be done for `u-boot.lds‘. 1> make[1]: Leaving directory `/work/projects/test/hi3516/u-boot-2010.06/arch/arm/cpu/godeyes‘ 1> arm-hisiv100-linux-uclibcgnueabi-gcc -E -g -Os -fno-strict-aliasing -fno-common -ffixed-r8 -D__KERNEL__ -DTEXT_BASE=0x80500000 -I/work/projects/test/hi3516/u-boot-2010.06/include -fno-builtin -ffreestanding -nostdinc -isystem /work/toolchain/hi3516/1.0.9.0/arm-hisiv100-linux/bin/../lib/gcc/arm-hisiv100-linux-uclibcgnueabi/4.4.1/include -pipe -DCONFIG_ARM -D__ARM__ -marm -mabi=aapcs-linux -mno-thumb-interwork -march=armv7-a -include /work/projects/test/hi3516/u-boot-2010.06/include/u-boot/u-boot.lds.h -ansi -D__ASSEMBLY__ -P - </work/projects/test/hi3516/u-boot-2010.06/arch/arm/cpu/godeyes/u-boot.lds >u-boot.lds 1> UNDEF_SYM=`arm-hisiv100-linux-uclibcgnueabi-objdump -x board/godeyes/libgodeyes.a lib/libgeneric.a lib/lzma/liblzma.a lib/lzo/liblzo.a arch/arm/cpu/godeyes/libgodeyes.a arch/arm/cpu/godeyes/godeyes/libgodeyes.a arch/arm/lib/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a fs/yaffs2/libyaffs2.a fs/ubifs/libubifs.a net/libnet.a disk/libdisk.a drivers/bios_emulator/libatibiosemu.a drivers/block/libblock.a drivers/dma/libdma.a drivers/fpga/libfpga.a drivers/gpio/libgpio.a drivers/hwmon/libhwmon.a drivers/i2c/libi2c.a drivers/input/libinput.a drivers/misc/libmisc.a drivers/mmc/libmmc.a drivers/mtd/libmtd.a drivers/mtd/nand/libnand.a drivers/mtd/onenand/libonenand.a drivers/mtd/ubi/libubi.a drivers/mtd/spi/libspi_flash.a drivers/net/libnet.a drivers/net/phy/libphy.a drivers/net/hisfv300/libhisfv300.a drivers/net/higmac/libhigmac.a drivers/net/stmmac/libstmmac.a drivers/pci/libpci.a drivers/pcmcia/libpcmcia.a drivers/power/libpower.a drivers/spi/libspi.a drivers/rtc/librtc.a drivers/serial/libserial.a drivers/twserial/libtws.a drivers/usb/gadget/libusb_gadget.a drivers/usb/host/libusb_host.a drivers/usb/musb/libusb_musb.a drivers/usb/phy/libusb_phy.a drivers/video/libvideo.a drivers/watchdog/libwatchdog.a common/libcommon.a lib/libfdt/libfdt.a api/libapi.a post/libpost.a product/libproduct.a | sed -n -e ‘s/.*\(__u_boot_cmd_.*\)/-u\1/p‘|sort|uniq`; cd /work/projects/test/hi3516/u-boot-2010.06 && arm-hisiv100-linux-uclibcgnueabi-ld -Bstatic -T u-boot.lds -Ttext 0x80500000 $UNDEF_SYM arch/arm/cpu/godeyes/start.o --start-group lib/libgeneric.a lib/lzma/liblzma.a lib/lzo/liblzo.a arch/arm/cpu/godeyes/libgodeyes.a arch/arm/cpu/godeyes/godeyes/libgodeyes.a arch/arm/lib/libarm.a fs/cramfs/libcramfs.a fs/fat/libfat.a fs/fdos/libfdos.a fs/jffs2/libjffs2.a fs/reiserfs/libreiserfs.a fs/ext2/libext2fs.a fs/yaffs2/libyaffs2.a fs/ubifs/libubifs.a net/libnet.a disk/libdisk.a drivers/bios_emulator/libatibiosemu.a drivers/block/libblock.a drivers/dma/libdma.a drivers/fpga/libfpga.a drivers/gpio/libgpio.a drivers/hwmon/libhwmon.a drivers/i2c/libi2c.a drivers/input/libinput.a drivers/misc/libmisc.a drivers/mmc/libmmc.a drivers/mtd/libmtd.a drivers/mtd/nand/libnand.a drivers/mtd/onenand/libonenand.a drivers/mtd/ubi/libubi.a drivers/mtd/spi/libspi_flash.a drivers/net/libnet.a drivers/net/phy/libphy.a drivers/net/hisfv300/libhisfv300.a drivers/net/higmac/libhigmac.a drivers/net/stmmac/libstmmac.a drivers/pci/libpci.a drivers/pcmcia/libpcmcia.a drivers/power/libpower.a drivers/spi/libspi.a drivers/rtc/librtc.a drivers/serial/libserial.a drivers/twserial/libtws.a drivers/usb/gadget/libusb_gadget.a drivers/usb/host/libusb_host.a drivers/usb/musb/libusb_musb.a drivers/usb/phy/libusb_phy.a drivers/video/libvideo.a drivers/watchdog/libwatchdog.a common/libcommon.a lib/libfdt/libfdt.a api/libapi.a post/libpost.a product/libproduct.a board/godeyes/libgodeyes.a --end-group /work/projects/test/hi3516/u-boot-2010.06/arch/arm/lib/eabi_compat.o -L /work/toolchain/hi3516/1.0.9.0/arm-hisiv100-linux/bin/../lib/gcc/arm-hisiv100-linux-uclibcgnueabi/4.4.1 -lgcc -Map u-boot.map -o u-boot 1> arm-hisiv100-linux-uclibcgnueabi-objcopy -O srec u-boot u-boot.srec 1> arm-hisiv100-linux-uclibcgnueabi-objcopy --gap-fill=0xff -O binary u-boot u-boot.bin 1> xxxxx 1> [embed@localhost u-boot-2010.06]$ 1> 1> *** EOF *** 1> 1> 1> 1> ========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
在此项目中根据需要加上uboot的源文件,此时VS2013并不能很好的分析源文件,因此必须加上包含目录:
这里的包含目录配置并不会传递给make程序,仅仅是让VS2013能够正确进行语法分析而已,因此可以自由设置。
下面测试一下VELT是否可以正确定位错误的位置:
随便找一个函数,让他产生一个语法错误:
显然,这里的211行是有错误的,在VS下生成项目:
1> arm-hisiv100-linux-uclibcgnueabi-gcc -g -Os -fno-strict-aliasing -fno-common -ffixed-r8 -D__KERNEL__ -DTEXT_BASE=0x80500000 -I/work/projects/test/hi3516/u-boot-2010.06/include -fno-builtin -ffreestanding -nostdinc -isystem /work/toolchain/hi3516/1.0.9.0/arm-hisiv100-linux/bin/../lib/gcc/arm-hisiv100-linux-uclibcgnueabi/4.4.1/include -pipe -DCONFIG_ARM -D__ARM__ -marm -mabi=aapcs-linux -mno-thumb-interwork -march=armv7-a -Wall -Wstrict-prototypes -fno-stack-protector 1> -o cmd_bootm.o cmd_bootm.c -c 1> cmd_bootm.c: In function ‘bootm_start‘: 1> Z:\projects\test\hi3516\u-boot-2010.06\common\cmd_bootm.c(211): error C2004: ‘a‘ undeclared (first use in this function) 1> Z:\projects\test\hi3516\u-boot-2010.06\common\cmd_bootm.c(211): error C2004: (Each undeclared identifier is reported only once 1> Z:\projects\test\hi3516\u-boot-2010.06\common\cmd_bootm.c(211): error C2004: for each function it appears in.) 1> make[1]: *** [cmd_bootm.o] Error 1 1> make[1]: Leaving directory `/work/projects/test/hi3516/u-boot-2010.06/common‘ 1> make: *** [common/libcommon.a] Error 2 1> [embed@localhost u-boot-2010.06]$ 1> 1> *** EOF *** 1> 1> 1> ========== 全部重新生成: 成功 0 个,失败 1 个,跳过 0 个 ==========
搞定!
此项目工程可在http://download.csdn.net/detail/lights_joy/8346943下载,当然,此项目中不包含UBOOT的源码,需要自己获取。
用Vs2013+VELT进行Hi3516开发:编译UBOOT
原文地址:http://blog.csdn.net/lights_joy/article/details/42581783