petalinux版本:2020.1
petalinux编译uboot和kernel时是从压缩包解压后放在临时目录中编译的,修改代码官方推荐用打补丁的方法,但感觉这样不方便,好在petalinux中可以指定使用用外部的uboot和kernel。
1.下载源码
先在官方的github中下载对应版本的uboot和kernel。
2.配置
petalinux-conifg -> Linux Components Selection
选择 ext-local-src
External u-boot local source path中填写源码的路径
External u-boot license checksum中填写licenses和md5值
然后重新编译就可以了。
3.uboot配置和源码修改
当修改uboot配置时,会生成u-boot-xlnx-xilinx-v2020.1/oe-local-files/devtool-fragment.cfg文件,将这个文件复制到project-spec/meta-user/recipes-bsp/u-boot/files下,然后在u-boot-xlnx_%.bbappend文件中添加这个补丁。
如果是源码的修改,因为前面已经用的外部的源码,所以直接修改上传即可。
4.kernel配置和源码修改
kernel配置的修改我原以为和uboot一样,但参考下面的教程怎么搞都不成功。
Patch the Linux Kernel using PetaLinux 2020.2, Boot on QEMU, and Debug with GDB
然后我发现uboot在编译时会运行build/tmp/work/zynqmp_generic-xilinx-linux/u-boot-xlnx/v2020.01-xilinx-v2020.1+git999-r0/temp/run.do_configure这个脚本,这个脚本中会运行merge_config.sh这个脚本,把上一节说的devtool-fragment.cfg文件合入到.config中,但在build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.4+git999-r0/temp/run.do_configure中没看到有这一步,但仔细看run.do_configure脚本中的do_configure()函数会发现,它会先把linux-xlnx-xilinx-v2020.1/arch/arm64/configs/xilinx_zynqmp_defconfig复制为defconfig,然后又会把defconfig重命名为.config,所以直接修改xilinx_zynqmp_defconfig就行。
源码的修改因为用的外部的源码,所以直接修改上传即可。