xilinx petalinux基础
这段时间的学习整理总结,有些是个人理解,不一定正确。基于petalinux 2015.4
1. 安装petalinux开发工具
注意:系统要求ubuntu是64位,否则安装失败(cannot execute binary file)。
ubuntu默认使用美国的软件镜像源,下载速度太慢,首先更换成国内清华大学的
https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/
1.1 修改默认shell为bash
先用命令ls -l /bin/sh 看看
结果是: /bin/sh -> dash
我们会发现Ubuntu默认采用的是 dash
如果要修改默认的sh,可以采用命令
sudo dpkg-reconfigure dash
然后选择【否】
成功后再执行ls -l /bin/sh 看看
结果是: /bin/sh -> bash
修改成功!
1.2 安装依赖环境
sudo apt-get install tofrodos iproute iproute2 gawk gcc git-core make net-tools libncurses5-dev zlib1g-dev openssl libssl-dev flex bison lib32z1 lib32ncurses5 lib32stdc++6 libselinux1 xvfb build-essential git chrpath socat autoconf libtool texinfo gcc-multilib libsdl1.2-dev libglib2.0-dev iproute2 gawk gcc git make net-tools libncurses5-dev tftpd zlib1g-dev libssl-dev flex bison libselinux1 gnupg wget diffstat chrpath socat xterm autoconf libtool tar unzip texinfo zlib1g-dev gcc-multilib build-essential libsdl1.2-dev libglib2.0-dev zlib1g:i386
1.3 安装petalinux
参考 https://blog.csdn.net/u013793399/article/details/53054734
任何问题,都可在xilinx社区搜索答案
https://forums.xilinx.com/
linux代码就在安装的petalinux路径里
安装目录/petalinux-v2015.4-final/components/linux-kernel/xlnx-4.0/
2. 安装vivado
如果安装时,提示 “unable to open archive file”,因为安装包在中文路径下
3. troubleshooting:
1,编译时提示
[ERROR] ERROR: Invalid ELF file '/opt/petalinux/Xilinx-ZC702-2015.2/images/linux/vmlinux'
ERROR: Failed to build linux
A:安装依赖包
sudo apt-get install tofrodos iproute tftpd-hpa gawk gcc git-core make net-tools libncurses5-dev zlib1g-dev libssl-dev flex bison lib32z1 lib32ncurses5 lib32bz2-1.0 lib32stdc++6 libselinux1
2,打包提示
petalinux-package --boot --fpga xxx.bit --u-boot
ERROR: This tool requires 'bootgen' and it is missing. Please source Xilinx Tools settings first
A:需要去官网下载sdk
I downloaded "Vivado full image for Linux with SDK" from http://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/vivado-design-tools.html
5GB later and 20 minutes of installation time I was able to run the petalinux-package
export PATH=$PATH:/<SDK inst. folder>/Xilinx/SDK/2014\.4/bin
cd <myproject>
petalinux-package —boot —format BIN —fsbl images/linux/zynq_fsbl.elf —u-boot
success and there is a BOOT.BIN file in <myproject>/images/linux as well as in "/tftpboot"
4. 添加内核config
petalinux创建工程时,把初始模板的config从模板拷到工程对应路径,作为kerne的config,即
/opt1/template/x497/subsystems/linux/configs/kernel/config
拷贝到
工程根目录/subsystems/linux/configs/kernel/config
后面如果新添加了模块,修改config时,只要修改工程里的config(重要!!!),即
工程根目录/subsystems/linux/configs/kernel/config
编译时自动把这个config拷贝到编译输出路径里,与其他config一起合成.config
编译输出路径在 /opt1/new_prj/build/linux/kernel/xlnx-4.0/
至于其他config怎么生成的,还没搞懂。
5. 编译源码
5.1 初始创建,编译全工程
1,创建工程
petalinux-create --type project --template zynq --name demo
2,配置工程,导入硬件模板hdf
cd demo petalinux-config --get-hw-description=/home/dev/top_hw_platform
3,编译(需要先切到root, petalinux 2018不需要),编译生成imag.ub
petalinux-build
4,打包生成 BOOT.BIN(平台不同,命令有差异,具体参看ug1144 “Generate Boot Image”,或者petalinux-package --boot --help)
petalinux-package --force --boot --fsbl images/linux/zynqmp_fsbl.elf --fpga images/linux/system.bit --u-boot
编译得到的BOOT.BIN image.ub top.bit 就是我们需要的镜像。
BOOT文件由三个文件合成,分别是:
系统第一阶段引导文件fsbl.elf,
FPGA配置文件design.bit(ZC706板子为system_wrapper.bit),
Linux系统的启动文件u-boot.elf。
image.ub为Linux系统镜像文件,由petalinux工具编译而成
top.bit是FPGA启动使用的镜像
配置内核
petalinux-config - c kernel
注意:
直接拷贝工程模板时,一定要把CONFIG_INITRAMFS_SOURCE=路径改成自己的targetroot路径。
e.g.
./subsystems/linux/configs/kernel/config:130:CONFIG_INITRAMFS_SOURCE="/his_module/template/targetroot"
改成
./subsystems/linux/configs/kernel/config:130:CONFIG_INITRAMFS_SOURCE="/your_module/template/targetroot"
5.2 单独编译内核模块
工程编译过之后,后面修改了模块可以单独编译打包,不用全编。
方法一:
编译时直接在工程目录下,使用petalinux-build ,自动打包成image.ub。
缺点是费时,因为全编还要编译其他模块,如rootfs。
root@ubuntu:/home/dev/prj_gpio_ctrl#petalinux-build
方法二:
在工程目录下,单独编译kernel
petalinux-build -c kernel
然后打包成imag.ub
petalinux-package --image
5.3 编译app模块
编译app模块比较简单,直接通过以下命令编译
e.g.
arm-xilinx-linux-gnueabi-gcc -o test sti-gpiotest.c
其他功能,如添加调试等待补充。
6.petalinux 2018.1 使用总结
6.1 device tree
petalinux工具生成的dts在 components/plnx_workspace/device-tree/device-tree,这里面的文件是自动生成的,不能直接修改,改了也不起效。
要修改dts,在另一个文件夹 project-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi,在这里面修改才能生效。
添加dts方法,在system-user.dtsi 里Includ 要添加的dtsi,然后在components/plnx_workspace/device-tree/device-tree 里创建dtsi。
6.2 kernel 代码
build/tmp/work-shared/plnx-zynqmp/kernel-source/
浙公网安备 33010602011771号