ZYNQ嵌入式Linux——手把手移植,从裸板进到Linux命令行
0——前言1——BOOT.BIN1-1:U-boot内核和设备树:1-1-1源码下载1-1-2:添加开发板配置1-1-2-1 uboot编译配置文件1-1-2-2 板子配置头文件
1-1-3 添加开发板对应的板级文件夹1-1-4 添加设备树1-1-5 图形界面配置1-1-6 编译uboot
1-2 petalinux工程准备1-3 揉一起合成一个BOOT.BIN1-4 试试BOOT.BIN能不能用
2——Linux内核&设备树2-1 Linux内核源码下载2-2 顶层makefile修改2-3 添加配置文件defconfig 目录:arch/arm/configs2-4 添加开发板对应的设备树文件-目录:arch/arm/boot/dts2-5 编译2-6 试试内核是否正常运行
3——根文件系统3-1 编译
4——大功告成
0——前言
要想启动一个普通的Linux开发板,需要三大件:uboot,Linux内核&设备树,根文件系统。 但是对于zynq来说,启动时候需要有设备描述文件,并不是简单的uboot而是BOOT.BIN,包含一堆东西,所以移植顺序从前到后分别是:
BOOT.BIN ,包含uboot内核、设备树、fsbl文件、硬件描述文件,四合一;Linux内核&设备树,就那个可以通过不管是命令行还是图形界面操作的,运行多任务的,多用户的系统,带逻辑,带脑子的,就这么简单的直观的理解把,能进了那个命令行,就意味着内核启动了,就可以运行你写的软件和驱动了;根文件系统,/下面的一切文件,下图这一堆东西,就是那个根文件系统所谓的rootfs。(并不是传统意义的什么fat,ext等文件系统,我甚至觉得这不就是系统文件?文件系统这名字起的真是误导)
zynq开发板同上,也就是把上面的uboot换成BOOT.BIN,稍微复杂点,需要把fpga的相关东西也揉进去。 下面以领航者开发板走一遍移植流程:
1——BOOT.BIN
BOOT.BIN(5MB左右),来自uboot源码编译以及petalinux编译后,合成四个文件所得,是我们第一个要移植的文件,组成如下: 1、uboot内核:uboot编译的uboot内核文件。【images/linux/u-boot.elf】 1M到几M 2、设备树:uboot编译的设备树文件【images/linux/system.dtb】10K到100K 来自petalinux: 3、fsbl文件:petalinux生成的fsbl文件【images/linux/zynq_fsbl.elf】450K左右 4、硬件描述文件:petalinux生成的硬件描述文件【project-spec/hw-description/system_wrapper.bit】4MB左右
下面我们一个个收集上面四个文件,并合成BOOT.BIN:
1-1:U-boot内核和设备树:
1-1-1源码下载
U-boot下载源码: 链接: https://github.com/Xilinx/u-boot-xlnx/releases/tag/xilinx-v2022.1(这是xilinx维护的uboot的源码,自己用的什么芯片就从对应官网找) 下载后解压,得到下列一包文件。 从这里右键打开terminal,开始下面的一系列操作:
1-1-2:添加开发板配置
一共2个【配置文件】 其中需要一个在uboot/configs文件夹下面的xxx_defconfig。我们叫他uboot编译配置文件
另一个是uboot/include/configs文件夹下,创建一个自己开发板的配置文件。我们叫他板子配置头文件
这俩配置文件,前者更多的是uboot编译的一些配置,第二个是自己开发板的更具体的配置,我们一个一个搞:
1-1-2-1 uboot编译配置文件
打开configs文件夹,看到一大堆xxx_defconfig文件,我们也如法炮制: 1、创建一个zynq_lyw_defconfig文件,或者复制一份自己板子接近的。
cd configs
cp xilinx_zynq_virt_defconfig zynq_lyw_defconfig
//这里我复制了一份和开发板接近的配置文件。zynq_lyw_defconfig
在这个基础上进行修改,要修改的部分如下图:
修改1、把里面的zynq-zc706都替换成zynq-lyw(随便起) 修改2、添加一下调试串口相关配置。(放在下面方便大家复制)
CONFIG_BOOTCOMMAND="run default_bootcmd"
CONFIG_DEBUG_UART_ZYNQ=y
CONFIG_DEBUG_UART_BASE=0xe0000000
CONFIG_DEBUG_UART_CLOCK=100000000
1-1-2-2 板子配置头文件
1、进入include/configs,创建自己的配置文件,或者复制一份:(文件名要和1-1-2-1中修改的名称相同)
cd include/configs //进入include/configs
cp zynq-common.h zynq-lyw.h //创建自己的配置文件,或者复制一份
2、编辑include/configs/zynq-lyw.h文件内容: 前两行定义名字修改:
#ifndef __CONFIG_LYW_COMMON_H
#define __CONFIG_LYW_COMMON_H
找到#define CONFIG_EXTRA_ENV_SETTINGS,将内容修改成下列
/* Default environment */
#ifndef CONFIG_EXTRA_ENV_SETTINGS
#define CONFIG_EXTRA_ENV_SETTINGS \
"fdt_high=0x20000000\0" \
"initrd_high=0x20000000\0" \
"scriptaddr=0x20000\0" \
"script_size_f=0x40000\0" \
"fdt_addr_r=0x1f00000\0" \
"pxefile_addr_r=0x2000000\0" \
"kernel_addr_r=0x2000000\0" \
"scriptaddr=0x3000000\0" \
"ramdisk_addr_r=0x3100000\0" \
"ethaddr=00:0a:35:00:01:22\0" \
"kernel_image=image.ub\0" \
"kernel_load_address=0x2008000\0" \
"ramdisk_image=uramdisk.image.gz\0" \
"ramdisk_load_address=0x4000000\0" \
"devicetree_image=devicetree.dtb\0" \
"devicetree_load_address=0x2000000\0" \
"bitstream_image=system.bit.bin\0" \
"boot_image=BOOT.bin\0" \
"loadbit_addr=0x100000\0" \
"loadbootenv_addr=0x2000000\0" \
"kernel_size=0x500000\0" \
"devicetree_size=0x20000\0" \
"mdisk_size=0x5E0000\0" \
"boot_size=0xF00000\0" \
"fdt_high=0x20000000\0" \
"initrd_high=0x20000000\0" \
"bootenv=uEnv.txt\0" \
"loadbootenv=load mmc 0 ${loadbootenv_addr} ${bootenv}\0" \
"importbootenv=echo Importing environment from SD ...; " \
"env import -t ${loadbootenv_addr} $filesize\0" \
"sd_uEnvtxt_existence_test=test -e mmc 0 /uEnv.txt\0" \
"preboot=if test $modeboot = sdboot && env run sd_uEnvtxt_existence_test; " \
"then if env run loadbootenv; " \
"then env run importbootenv; " \
"fi; " \
"fi; \0" \
"mmc_loadbit=echo Loading bitstream from SD/MMC/eMMC to RAM.. && " \
"mmcinfo && " \
"load mmc 0 ${loadbit_addr} ${bitstream_image} && " \
"fpga load 0 ${loadbit_addr} ${filesize}\0" \
"norboot=echo Copying Linux from NOR flash to RAM... && " \
"cp.b 0xE2100000 ${kernel_load_address} ${kernel_size} && " \
"cp.b 0xE2600000 ${devicetree_load_address} ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"cp.b 0xE2620000 ${ramdisk_load_address} ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"qspiboot=echo Copying Linux from QSPI flash to RAM... && " \
"sf probe 0 0 0 && " \
"sf read ${kernel_load_address} 0x100000 ${kernel_size} && " \
"sf read ${devicetree_load_address} 0x600000 ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"sf read ${ramdisk_load_address} 0x620000 ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"uenvboot=" \
"if run loadbootenv; then " \
"echo Loaded environment from ${bootenv}; " \
"run importbootenv; " \
"fi; " \
"if test -n $uenvcmd; then " \
"echo Running uenvcmd ...; " \
"run uenvcmd; " \
"fi\0" \
"sdboot=if mmcinfo; then " \
"run uenvboot; " \
"echo Copying Linux from SD to RAM... && " \
"load mmc 0 ${kernel_load_address} ${kernel_image} && " \
"bootm ${kernel_load_address}; " \
"fi\0" \
"netboot=tftpboot ${kernel_load_address} ${kernel_image} && bootm\0" \
"default_bootcmd=run sdboot;\0" \
"usbboot=if usb start; then " \
"run uenvboot; " \
"echo Copying Linux from USB to RAM... && " \
"load usb 0 ${kernel_load_address} ${kernel_image} && " \
"load usb 0 ${devicetree_load_address} ${devicetree_image} && " \
"load usb 0 ${ramdisk_load_address} ${ramdisk_image} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}; " \
"fi\0" \
"nandboot=echo Copying Linux from NAND flash to RAM... && " \
"nand read ${kernel_load_address} 0x100000 ${kernel_size} && " \
"nand read ${devicetree_load_address} 0x600000 ${devicetree_size} && " \
"echo Copying ramdisk... && " \
"nand read ${ramdisk_load_address} 0x620000 ${ramdisk_size} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"jtagboot=echo TFTPing Linux to RAM... && " \
"tftpboot ${kernel_load_address} ${kernel_image} && " \
"tftpboot ${devicetree_load_address} ${devicetree_image} && " \
"tftpboot ${ramdisk_load_address} ${ramdisk_image} && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_norboot=echo Copying Image from NOR flash to RAM... && " \
"cp.b 0xE2100000 0x100000 ${boot_size} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_nandboot=echo Copying Image from NAND flash to RAM... && " \
"nand read 0x100000 0x0 ${boot_size} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_qspiboot=echo Copying Image from QSPI flash to RAM... && " \
"sf probe 0 0 0 && " \
"sf read 0x100000 0x0 ${boot_size} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_sdboot=echo Copying Image from SD to RAM... && " \
"load mmc 0 0x100000 ${boot_image} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
"rsa_jtagboot=echo TFTPing Image to RAM... && " \
"tftpboot 0x100000 ${boot_image} && " \
"zynqrsa 0x100000 && " \
"bootm ${kernel_load_address} ${ramdisk_load_address} ${devicetree_load_address}\0" \
BOOTENV
#endif
1-1-3 添加开发板对应的板级文件夹
领航者开发板:
cd board/xilinx/zynq/
cp -r zynq-zc702 zynq-lyw
文件夹下面就一个ps7_init_gpl.c文件,这是PS(arm核部分)的初始化文件。
1-1-4 添加设备树
arch/arm/dts下面,添加一个zynq-lyw.dts 领航者开发板:
cd arch/arm/dts
cp zynq-zed.dts zynq-lyw.dts
arch/arm/dts/zynq-lyw.dts修改这个文件:可以直接复制下面这段进去
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2011 - 2015 Xilinx
* Copyright (C) 2012 National Instruments Corp.
*/
/dts-v1/;
#include "zynq-7000.dtsi"
/ {
model = "LYW board";
compatible = "avnet,zynq-altk", "xlnx,zynq-altk", "xlnx,zynq-7000";
aliases {
ethernet0 = &gem0;
serial0 = &uart0;
spi0 = &qspi;
mmc0 = &sdhci0;
};
memory@0 {
device_type = "memory";
reg = <0x0 0x40000000>;
};
chosen {
bootargs = "";
stdout-path = "serial0:115200n8";
};
usb_phy0: phy0@e0002000 {
compatible = "ulpi-phy";
#phy-cells = <0>;
reg = <0xe0002000 0x1000>;
view-port = <0x0170>;
drv-vbus;
};
};
&clkc {
ps-clk-frequency = <33333333>;
};
&gem0 {
status = "okay";
phy-mode = "rgmii-id";
phy-handle = <ðernet_phy>;
ethernet_phy: ethernet-phy@0 {
reg = <0>;
device_type = "ethernet-phy";
};
};
&qspi {
u-boot,dm-pre-reloc;
status = "okay";
is-dual = <0>;
num-cs = <1>;
flash@0 {
compatible = "spansion,s25fl256s1", "jedec,spi-nor";
reg = <0>;
spi-tx-bus-width = <1>;
spi-rx-bus-width = <4>;
spi-max-frequency = <50000000>;
m25p,fast-read;
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "qspi-fsbl-uboot";
reg = <0x0 0x100000>;
};
partition@100000 {
label = "qspi-linux";
reg = <0x100000 0x500000>;
};
partition@600000 {
label = "qspi-device-tree";
reg = <0x600000 0x20000>;
};
partition@620000 {
label = "qspi-rootfs";
reg = <0x620000 0x5E0000>;
};
partition@c00000 {
label = "qspi-bitstream";
reg = <0xC00000 0x400000>;
};
};
};
&sdhci0 {
u-boot,dm-pre-reloc;
status = "okay";
};
&uart0 {
u-boot,dm-pre-reloc;
status = "okay";
};
&usb0 {
status = "okay";
dr_mode = "host";
usb-phy = <&usb_phy0>;
};
修改完成后,要修改目录下的makefile文件:arch/arm/dts/makefile 找到dtb-$(CONFIG_ARCH_ZYNQ),加上自己的设备树 加完后如下(我的zynq-lyw.dtb夹到第二行了,毕竟抄的,就跟上学时候交作业似的,放到第一行总感觉心里有点毛):
arch/arm/dts/makefile改完片段如下
…………
dtb-$(CONFIG_ARCH_ZYNQ) += \
bitmain-antminer-s9.dtb \
zynq-lyw.dtb \
zynq-cc108.dtb \
zynq-cse-nand.dtb \
zynq-cse-nor.dtb \
…………
1-1-5 图形界面配置
arch/arm/mach-zynq/Kconfig 找到config SYS_CONFIG_NAME 改完片段如下:
config SYS_CONFIG_NAME
string "Board configuration name"
default "zynq_lyw"
help
This option contains information about board configuration name.
Based on this option include/configs/
will be used for board configuration.
1-1-6 编译uboot
这里假定你安装好了petalinux,并且编译好了适配soc平台的sdk并安装,如果没做这一步,请先读我另一篇: 安装petalinux环境 编译安装zynq SDK
创建一个编译脚本:lywmake.sh
#!/bin/bash
make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- distclean
make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- zynq_lyw_defconfig
make V=1 ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- -j8
给一个可执行权限:
sudo chmod 777 lywmake.sh
运行编译:
./lywmake.sh
得到两个文件(合成BOOT.BIN需要): 1、一个1MB大小的 u-boot.elf,在uboot根目录 2、一个10kb多的dtb文件,在/arch/arm/dts/zynq-lyw.dtb
1-2 petalinux工程准备
这里假定你安装好了petalinux一系列开发环境,如果没有请先读我另一篇: 安装petalinux环境 准备好system_wrapper.xsa文件(vivado编译出来的硬件描述文件) 开始操作: 1、配置环境
source /opt/pkg/petalinux/2022.1//settings.sh
2、创建工程
petalinux-create -t project --template zynq -n LYW-ZYNQ-driver
3、将 xsa 文件导入到 petalinux 工程当中并配置 petalinux 工程
cd LYW-ZYNQ-driver
petalinux-config --get-hw-description ../system_wrapper.xsa
Subsystem AUTO Hardware Settings-> Serial Settings 把“FSBL Serial stdin/stdout”和“DTG Serial stdin/stdout”两项中默认使用的“ps7_uart_1”改成 “ps7_uart_0”,也就是 USB 串口。 yocto settings
Add-pre-mirror-url 请确保下载了downloads文件,下面的地址请填自己解压存放的位置 file:///mnt/hgfs/share/sstate_cache/downloads Local sstate feeds settings 请确保下载了sstate文件,下面的地址请填自己解压存放的位置 /mnt/hgfs/share/sstate_arm/arm enable network sstate feeds【取消勾选’n’】 Image Packaging Configuration
root filesystem type (xx)改成EXT4
4、编译fsbl
petalinux-build -c bootloader
petalinux-build
主要是为了得到以下两个文件(合成BOOT.BIN需要): images/linux/zynq_fsbl.elf(几百k) project-spec/hw-description/system_wrapper.bit(4M左右)
1-3 揉一起合成一个BOOT.BIN
先把刚才uboot编译生成的俩文件复制到petalinux目录下面的image/linux/
#拷贝刚才编译的文件
cd ~/petalinux/LYW-ZYNQ-driver/images/linux
cp ~/uboot/u-boot-xlnx-xilinx-v2022.1/arch/arm/dts/zynq-lyw.dtb ./system.dtb
cp ~/uboot/u-boot-xlnx-xilinx-v2022.1/u-boot.elf ./
#打包生成!
petalinux-package --boot --fsbl --fpga --u-boot --force
终于得到了一个5.2MB的 BOOT.BIN
1-4 试试BOOT.BIN能不能用
找个SD卡,分区分个FAT分区,把BOOT.BIN考进去,用串口连上电脑。 启动,回车,能进入uboot命令行就说明BOOT.BIN基本没问题: 到这一步uboot肯定是成了
下面试试能不能进系统: 本小结需要等后面zImage和zynq-lyw.btb编译好了,并且放到tftpboot文件夹才能试!需要下面两个条件: 1、ubuntu主机的 /tftpboot下面需要有zImage和zynq-lyw.dtb 2、ubuntu主机的 ~/linux/nfs/下面需要有解压后的根文件系统/rootfs 依次执行下列命令:
setenv ipaddr 192.168.5.9
setenv gatewayip 192.168.5.1
setenv netmask 255.255.255.0
setenv serverip 192.168.5.11
setenv bootcmd 'tftpboot 00000000 zImage;tftpboot 05000000 zynq-lyw.dtb;bootz 00000000 - 05000000;'
setenv bootargs 'console=ttyPS0,115200 root=/dev/nfs rw nfsroot=192.168.5.11:/home/lyw/linux/nfs/rootfs,nfsvers=3 ip=192.168.5.9:192.168.5.11:192.168.5.1:255.255.255.0::eth0:off'
saveenv
boot
成功启动
2——Linux内核&设备树
2-1 Linux内核源码下载
Linux官网: 链接: https://www.kernel.org/ xilinx维护的linux内核链接:https://github.com/Xilinx/linux-xlnx/tags 复制源码,创建工作区。
2-2 顶层makefile修改
修改顶层makefile,找到ARCH ?=,并且如下修改:
ARCH ?= arm
CROSS_COMPILE ?= arm-xilinx-linux-gnueabi-
2-3 添加配置文件defconfig 目录:arch/arm/configs
进去复制一份类似的defconfig文件
cd arch/arm/configs
cp xilinx_zynq_defconfig xilinx_zynq_lyw_defconfig
2-4 添加开发板对应的设备树文件-目录:arch/arm/boot/dts
1,复制一份类似的设备树文件:
cd arch/arm/boot/dts
cp zynq-zed.dts zynq-lyw.dts
2,我们需要复制些文件到这个dts目录下: 除了上图的5个,还有个system-user.dtsi内容如下:没有的直接复制新建一个就行
#include
#include
#include
#include
/ {
model = "Alientek Navigator Zynq Development Board";
compatible = "xlnx,zynq-zc702", "xlnx,zynq-7000";
leds {
compatible = "gpio-leds";
gpio-led1 {
label = "led2";
gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
default-state = "on";
};
gpio-led2 {
label = "led1";
gpios = <&gpio0 54 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "heartbeat";
};
gpio-led3 {
label = "pl_led0";
gpios = <&axi_gpio_0 0 0 GPIO_ACTIVE_HIGH>;
default-state = "on";
};
gpio-led4 {
label = "pl_led1";
gpios = <&axi_gpio_0 1 0 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
gpio-led5 {
label = "ps_led0";
gpios = <&gpio0 7 GPIO_ACTIVE_HIGH>;
default-state = "on";
};
gpio-led6 {
label = "ps_led1";
gpios = <&gpio0 8 GPIO_ACTIVE_HIGH>;
linux,default-trigger = "timer";
};
};
keys {
compatible = "gpio-keys";
autorepeat;
gpio-key1 {
label = "pl_key0";
gpios = <&gpio0 55 GPIO_ACTIVE_LOW>;
linux,code =
gpio-key,wakeup;
autorepeat;
};
gpio-key2 {
label = "pl_key1";
gpios = <&gpio0 56 GPIO_ACTIVE_LOW>;
linux,code =
gpio-key,wakeup;
autorepeat;
};
gpio-key3 {
label = "ps_key1";
gpios = <&gpio0 12 GPIO_ACTIVE_LOW>;
linux,code =
gpio-key,wakeup;
autorepeat;
};
gpio-key4 {
label = "ps_key2";
gpios = <&gpio0 11 GPIO_ACTIVE_LOW>;
linux,code =
gpio-key,wakeup;
autorepeat;
};
touch-key {
label = "touch_key";
gpios = <&gpio0 57 GPIO_ACTIVE_HIGH>;
linux,code =
gpio-key,wakeup;
autorepeat;
};
};
beep {
compatible = "gpio-beeper";
gpios = <&gpio0 58 GPIO_ACTIVE_HIGH>;
};
usb_phy0: phy0@e0002000 {
compatible = "ulpi-phy";
#phy-cells = <0>;
reg = <0xe0002000 0x1000>;
view-port = <0x0170>;
drv-vbus;
};
};
&uart0 {
u-boot,dm-pre-reloc;
status = "okay";
};
&sdhci0 {
u-boot,dm-pre-reloc;
status = "okay";
};
&usb0 {
dr_mode = "otg";
usb-phy = <&usb_phy0>;
};
&qspi {
u-boot,dm-pre-reloc;
flash@0 { /* 16 MB */
compatible = "w25q256", "jedec,spi-nor";
reg = <0x0>;
spi-max-frequency = <50000000>;
#address-cells = <1>;
#size-cells = <1>;
partition@0x00000000 {
label = "boot";
reg = <0x00000000 0x00100000>;
};
partition@0x00100000 {
label = "bootenv";
reg = <0x00100000 0x00020000>;
};
partition@0x00120000 {
label = "bitstream";
reg = <0x00120000 0x00400000>;
};
partition@0x00520000 {
label = "device-tree";
reg = <0x00520000 0x00020000>;
};
partition@0x00540000 {
label = "kernel";
reg = <0x00540000 0x00500000>;
};
partition@0x00A40000 {
label = "space";
reg = <0x00A40000 0x00000000>;
};
};
};
&gem0 {
local-mac-address = [00 0a 35 00 8b 87];
phy-handle = <ðernet_phy>;
ethernet_phy: ethernet-phy@7 { /* yt8521 */
reg = <0x7>;
device_type = "ethernet-phy";
};
};
&gem1 {
local-mac-address = [00 0a 35 00 11 55];
phy-reset-gpio = <&gpio0 63 GPIO_ACTIVE_LOW>;
phy-reset-active-low;
phy-handle = <&pl_phy>;
pl_phy: pl_phy@4 {
reg = <0x4>;
device_type = "ethernet-phy";
};
};
&watchdog0 {
status = "okay";
reset-on-timeout; // Enable watchdog reset function
};
&adc {
status = "okay";
xlnx,channels {
#address-cells = <1>;
#size-cells = <0>;
channel@0 {
reg = <0>;
};
};
};
&i2c0 {
clock-frequency = <100000>;
eeprom@50 {
compatible = "atmel,24c64";
reg = <0x50>;
pagesize = <32>;
};
rtc@51 {
compatible = "nxp,pcf8563";
reg = <0x51>;
};
};
然后就是一顿复制。
cd arch/arm/boot/dts
cp ~/petalinux/LYW-ZYNQ-driver/components/plnx_workspace/device-tree/device-tree/system-conf.dtsi ./
cp ~/petalinux/LYW-ZYNQ-driver/components/plnx_workspace/device-tree/device-tree/system-top.dts ./
cp ~/petalinux/LYW-ZYNQ-driver/components/plnx_workspace/device-tree/device-tree/pcw.dtsi ./
cp ~/petalinux/LYW-ZYNQ-driver/components/plnx_workspace/device-tree/device-tree/pl.dtsi ./
cp ~/petalinux/LYW-ZYNQ-driver/components/plnx_workspace/device-tree/device-tree/zynq-7000.dtsi ./
cp /mnt/hgfs/share/system-user.dtsi ./
3,修改zynq-lyw.dts 修改1:在zynq-lyw.dts前后增加引用: 文件最前面:
#include "zynq-7000.dtsi"
#include "pl.dtsi"
#include "pcw.dtsi"
文件最后面:
#include "system-user.dtsi"
修改2:
1:17\98行uart1改成uart0 2:24行20000000改成40000000 3:删除&gem0 {……相关的东西
修改完之后文件整个放到下面:懒得改就直接复制吧兄弟们 zynq-lyw.dts
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2011 - 2015 Xilinx
* Copyright (C) 2012 National Instruments Corp.
*/
/dts-v1/;
#include "zynq-7000.dtsi"
#include "pl.dtsi"
#include "pcw.dtsi"
/ {
model = "Zynq Lyw Development board";
compatible = "avnet,zynq-lyw", "xlnx,zynq-lyw", "xlnx,zynq-7000";
aliases {
ethernet0 = &gem0;
serial0 = &uart0;
spi0 = &qspi;
mmc0 = &sdhci0;
};
memory@0 {
device_type = "memory";
reg = <0x0 0x40000000>;
};
chosen {
bootargs = "";
stdout-path = "serial0:115200n8";
};
usb_phy0: phy0@e0002000 {
compatible = "ulpi-phy";
#phy-cells = <0>;
reg = <0xe0002000 0x1000>;
view-port = <0x0170>;
drv-vbus;
};
};
&clkc {
ps-clk-frequency = <33333333>;
};
&qspi {
u-boot,dm-pre-reloc;
status = "okay";
is-dual = <0>;
num-cs = <1>;
flash@0 {
compatible = "spansion,s25fl256s1", "jedec,spi-nor";
reg = <0>;
spi-tx-bus-width = <1>;
spi-rx-bus-width = <4>;
spi-max-frequency = <50000000>;
m25p,fast-read;
#address-cells = <1>;
#size-cells = <1>;
partition@0 {
label = "qspi-fsbl-uboot";
reg = <0x0 0x100000>;
};
partition@100000 {
label = "qspi-linux";
reg = <0x100000 0x500000>;
};
partition@600000 {
label = "qspi-device-tree";
reg = <0x600000 0x20000>;
};
partition@620000 {
label = "qspi-rootfs";
reg = <0x620000 0x5E0000>;
};
partition@c00000 {
label = "qspi-bitstream";
reg = <0xC00000 0x400000>;
};
};
};
&sdhci0 {
u-boot,dm-pre-reloc;
status = "okay";
};
&uart0 {
u-boot,dm-pre-reloc;
status = "okay";
};
&usb0 {
status = "okay";
dr_mode = "host";
usb-phy = <&usb_phy0>;
};
#include "system-user.dtsi"
4,修改Makefile:找到CONFIG_ARCH_ZYNQ,添加自己的设备树
……
dtb-$(CONFIG_ARCH_ZYNQ) += \
zynq-lyw.dtb \
……
2-5 编译
1、创建一个编译脚本:lywmake.sh:
#!/bin/sh
make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- distclean
make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- xilinx_zynq_lyw_defconfig
# make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- menuconfig
make ARCH=arm CROSS_COMPILE=arm-xilinx-linux-gnueabi- all -j8
2、执行:
#!/bin/sh
chmod 777 lywmake.sh
./lywmake.sh
得到两个文件 1、zImage 2、arch/arm/boot/dts/zynq-lyw.dtb
2-6 试试内核是否正常运行
1、将zImage和dtb文件都复制到tftpboot根目录
cd /tftpboot
cp ~/xilinx-linux/linux-kernel-driver-develop/linux-xlnx-xlnx_rebase_v5.15_LTS_2022.1/arch/arm/boot/zImage ./
cp ~/xilinx-linux/linux-kernel-driver-develop/linux-xlnx-xlnx_rebase_v5.15_LTS_2022.1/arch/arm/boot/dts/zynq-lyw.dtb ./
2、在uboot中通过tftpboot启动: 进入uboot命令行 依次执行下列命令:
setenv ipaddr 192.168.5.9
setenv gatewayip 192.168.5.1
setenv netmask 255.255.255.0
setenv serverip 192.168.5.11
setenv bootcmd 'tftpboot 00000000 zImage;tftpboot 05000000 zynq-lyw.dtb;bootz 00000000 - 05000000;'
setenv bootargs 'console=ttyPS0,115200 root=/dev/nfs rw nfsroot=192.168.5.11:/home/lyw/linux/nfs/rootfs,nfsvers=3 ip=192.168.5.9:192.168.5.11:192.168.5.1:255.255.255.0::eth0:off'
saveenv
boot
成功启动
3——根文件系统
3-1 编译
打开1-2中的petalinux的根目录,注意yocto中去掉两个网络使能,
petalinux-config
linux内核配置:进去直接出来就行,不用改啥
petalinux-config -c kernel
进行根文件系统配置:
petalinux-config -c rootfs
1、进入patalinux package groups
i. QT:XX-qt
选择QT和qt5
ii. OpenCV:XX-opencv
选择opencv结尾的那个
iii. python:xx-python-module
选择python-module
iv. 视频工具库:v4lutils
选择xx-v4lutils
v. 添加GCC:xx-self-hosted
选择self-hosted
vi. 添加网络工具:networking-stack
选择networking stack
2、进入Image Feature,使能auto login
3、进入petalinux RootFS Setting设置root密码
多次双击Esc退出并保存
petalinux-build -c rootfs
(大约需要十几分钟) 得到一个264MB的rootfs.tar.gz
4——大功告成
复制到你的nfs目录解压,参照2-6 启动开发板
完事儿了,大功告成了。