正点原子-ZYNQ7020 开发笔记
一、配置petalinux 工程安装petalinuxpetalinux 下载https://www.xilinx.com/support/download/index.html/content/xilinx/en/downloadNav/embedded-design-tools/2022-2.html安装虚拟机安装Ubuntu 22.04的虚拟机安装依赖sudo apt-get install gawk xterm \ gcc-multilib \ zlib1g:i386 \ autoconf \ libtool \ texinfo \ zlib1g-dev \ build-essential \ libncurses5-devsudo apt install net-tools安装sudo chmod 755 petalinux-v2022.2-10141622-installer.run mkdir -p ~/petalinux/2022.2 ./petalinux-v2022.2-10141622-installer.run --dir ~/petalinux/2022.2 # 1. 设置环境每次新终端都要执行 source ~/petalinux/2022.2/petalinux/settings.sh # 2. 创建工程这时才会生成完整的工程结构 petalinux-create -t project --template zynq -n my_first_project # 3. 进入工程目录 cd my_first_project # 4. 此时工程内部才有完整的组件目录 # project-spec/ - 配置规格内核、rootfs、设备树 # components/ - 软链接到 U-Boot/Kernel 源码 # build/ - 编译输出创建后为空build 后才生成 # images/ - 最终镜像输出目录遇到阅读就按下 enter阅读后点击q退出按照提示安装。配置PetaLinux工作环境sudo gedit ~/.bashrc然后翻页到末尾在末尾添加这句话# ~ /home/你的用户名 source ~/petalinux/2022.2/settings.sh保存之后重启终端之后运行echo $PETALINUX二、使用petalinuxpetalinux-config --help?petalinux-config --get-hw-description ~/hdf/Navigator_7020.sdk1.图像界面操作打开之前的工程的配置界面使用petalinux-config2.选择Linux Components Selection3. 配置U-Boot 源码来源为正点原子提供的U-Boot源码选择u-boot---选择ext-local-src4.配置内核源码来源为正点原子提供的内核源码5. 配置根文件系统的类型为SD Card三、配置设备树将相应的设备树文件 system-user.dtsiproject-spec/meta-user/recipes-bsp/device-tree/files/system-user.dtsi四、编译petalinux 工程在petalinux 工程目录下运行petalinux-build五、将镜像文件和根文件系统拷贝到SD启动卡petalinux-package --boot --fsbl --fpga --uboot --force参数全称/含义说明--bootBoot Image指定进入 **生成启动镜像** 模式输出 BOOT.BIN--fsbl fileFirst Stage Boot Loader指定 FSBL ELF 文件路径Zynq/ZynqMP或 PLMVersal--fpga fileFPGA Bitstream指定 bitstream 文件.bit 或 .bin**可选**--uboot fileU-Boot ELF指定 U-Boot ELF 文件作为第二级启动加载器--forceForce Overwrite强制覆盖已存在的 BOOT.BIN不提示确认六、说明PetaLinux 完全支持分别启动 U-Boot 和 Linux Kernel 原生的 menuconfig 配置界面无需手动进入源码目录操作。核心操作命令‌启动 U-Boot menuconfig‌在 PetaLinux 项目根目录执行petalinux-config -c u-boot即可直接打开 U-Boot 的图形化配置界面自定义启动相关参数、硬件驱动等选项。‌启动 Kernel menuconfig‌在项目根目录执行petalinux-config -c kernel就能进入 Linux 内核的标准 menuconfig 界面调整内核功能开关、驱动支持、编译选项等内容。组件最终生效配置路径(构建后)用户修改推荐路径(持久化)‌Linux Kernel‌build/tmp/work-shared/machine/kernel-build-artifacts/.configproject-spec/meta-user/conf/user-config.cfg‌U-Boot‌build/tmp/work/machine-xilinx-linux/u-boot-xlnx/ver/build/.configproject-spec/meta-user/recipes-bsp/u-boot/files/*.cfgpetalinux-config -c u-boot后会进入menuconfig 退出后保存文件名为user-boot.cfg‌提示输入文件名‌系统会弹窗要求你输入一个配置文件名例如uboot.config或.config。当你退出 menuconfig 并执行petalinux-build -c u-boot后PetaLinux 会将你的修改与默认配置合并生成最终用于编译的.config文件。命令作用petalinux-build非交互式全量构建不会进入任何 menuconfigpetalinux-config进入 RootFS / 系统级** menuconfigpetalinux-config -c kernel进入 Kernel menuconfigpetalinux-config -c u-boot进入 U-Boot menuconfigpetalinux-config -c rootfs进入 RootFS 软件包 menuconfig完整工作流示例1. 先配置后构建# 进入项目目录 cd plnx-proj-root # 配置 Kernel会弹出 menuconfig petalinux-config -c kernel # → 修改配置 → Save → Exit # 配置 U-Boot会弹出 menuconfig petalinux-config -c u-boot # → 修改配置 → Save → Exit # 非交互式构建使用刚才保存的配置 petalinux-buildplnx-proj-root/ ├── project-spec/ │ ├── configs/ │ │ └── config # 系统级配置 │ └── meta-user/ │ └── recipes-kernel/ │ └── linux/ │ └── linux-xlnx/ # Kernel 配置片段 │ └── user_*.cfg # 你的 Kernel 修改 │ └── recipes-bsp/ │ └── u-boot/ │ └── u-boot-xlnx/ # U-Boot 配置片段 │ └── user_*.cfg # 你的 U-Boot 修改关键点PetaLinux 不会直接修改 U-Boot / Kernel 源码树里的.config而是把你的 menuconfig 变更生成.cfg片段文件通过bbappend机制注入到 Yocto 构建中。