提高PetaLinux/Yocto的编译速度,暨整合Open Source U-Boot/Linux编译 -- PetaLinux 2021/2022版本

作者:付汉杰 hankf@amd.com

总结

通过使用本地文件、Open Source U-Boot/Linux编译,既能适应部分开发人员的工作习惯,也能提高U-Boot/Linux的编译速度。

概述

PetaLinux是Xilinx基于Yocto推出的Linux开发工具,可以一键编译出一个完整的嵌入式Linux发行版,包括上百万源代码文件,数千个应用程序。但是完整的一次PetaLinux/Yocto编译,可能需要从网络下载上GB的文件,可能需要几十分钟。即使只更改一行代码,也需要数分钟时间。

如果在调试单板时,仅仅改动一行代码,也需要执行这些操作,显得冗余,也影响开发效率。

为了适应开发人员的工作习惯,也为了提高速度,可以使用本地文件编译,还可以可以整合OpenSource U-Boot/Linux编译。

3年前,我写了整合Xilinx PetaLinux工程编译和Open Source U- Boot/Linux编译。相比3年前,PetaLinux已经做了很多更新。因此基于PetaLinux 2021/2022版本更新,以提供更准确的办法。另外,本文中提供了完整的脚本,从PetaLinux工程自动获取U-Boot/Linux源代码,以及从PetaLinux工程目录以Open Source流程编译U-Boot/Linux并更新PetaLinux工程的BOOT.BIN、image、image.ub。

PetaLinux的安装

对于PetaLinux的安装,请参考Xilinx文档UG1144 PetaLinux Tools Reference Guide, 和 一键离线安装PetaLinux依赖包

提高PetaLinux的编译速度

使用本地SState cache

在Xilinx下载网站嵌入式工具下载区 下载sstate cache。 目前SState cache已经分为Arm64(AArch64), Arm, mbfull, mblite四个文件。 2021.1版的AArch64 sstate cache的大小是11.84 GB,Arm sstate cache的大小是5.09 GB。 下载前,需要注册Xilinx网站的帐号。 登录后,选择aarch64 sstate-cache等,从类似于sstate_aarch64_2022.2_10071807.tar.gz 的地址下载SState cache文件。

下载后解压,以AArch64为例,可以看到类似下面的目录结构。

hankf@XSZGS4:aarch64$ ls 
00  06  0c  12  18  1e  24  2a  30  36  3c  42  48  4e  54  5a  60  66  6c  72  78  7e  84  8a  90  96  9c  a2  a8  ae  b4  ba  c0  c6  cc  d2  d8  de  e4  ea  f0  f6  fc
01  07  0d  13  19  1f  25  2b  31  37  3d  43  49  4f  55  5b  61  67  6d  73  79  7f  85  8b  91  97  9d  a3  a9  af  b5  bb  c1  c7  cd  d3  d9  df  e5  eb  f1  f7  fd
02  08  0e  14  1a  20  26  2c  32  38  3e  44  4a  50  56  5c  62  68  6e  74  7a  80  86  8c  92  98  9e  a4  aa  b0  b6  bc  c2  c8  ce  d4  da  e0  e6  ec  f2  f8  fe
03  09  0f  15  1b  21  27  2d  33  39  3f  45  4b  51  57  5d  63  69  6f  75  7b  81  87  8d  93  99  9f  a5  ab  b1  b7  bd  c3  c9  cf  d5  db  e1  e7  ed  f3  f9  ff
04  0a  10  16  1c  22  28  2e  34  3a  40  46  4c  52  58  5e  64  6a  70  76  7c  82  88  8e  94  9a  a0  a6  ac  b2  b8  be  c4  ca  d0  d6  dc  e2  e8  ee  f4  fa  universal
05  0b  11  17  1d  23  29  2f  35  3b  41  47  4d  53  59  5f  65  6b  71  77  7d  83  89  8f  95  9b  a1  a7  ad  b3  b9  bf  c5  cb  d1  d7  dd  e3  e9  ef  f5  fb

在PetaLinux工程目录下执行命令petalinux-config,在菜单Yocto Settings->Local sstate feeds settings->local sstate feeds url设置本地SState cache的目录。

图1.png

本地SState cache设置界面

对于MPSoC,使用aarch64,比如/opt/Xilinx/peta/2021.1/sstate/aarch64。对于Zynq-7000,使用arm,比如/opt/Xilinx/peta/2021.1/sstate/arm。设置后,文件project-spec/configs/config会包含指定的目录,比如下行:

CONFIG_YOCTO_LOCAL_SSTATE_FEEDS_URL="/opt/Xilinx/peta/2021.1/sstate/aarch64"

对于sstate的使用,可以参考Xilinx下载网站嵌入式工具下载区的README for state-cache

使用本地Downloads文件包

在Xilinx下载网站嵌入式工具下载区 下载 Downloads文件包。 2021.1的Downloads文件包有39.75GB。

Downloads文件包里,还有很多常用软件的压缩包。下载后解压,可以看到类似下面的目录结构。

hankf@XSZGS4:downloads$ ls
acl-2.2.53.tar.gz                    git2_github.com.tpm2-software.tpm2-tss-engine.git.tar.gz           libxml2-2.9.10.tar.gz
acpica-unix-20200717.tar.gz          git2_github.com.troglobit.sysklogd.git.tar.gz                      libXmu-1.1.3.tar.bz2
adwaita-icon-theme-3.36.1.tar.xz     git2_github.com.ucb-bar.berkeley-softfloat-3.git.tar.gz            libXrandr-1.5.2.tar.bz2
alsa-lib-1.2.3.2.tar.bz2             git2_github.com.uclouvain.openjpeg.git.tar.gz                      libXrender-0.9.10.tar.bz2
alsa-plugins-1.2.2.tar.bz2           git2_github.com.vim.vim.git.tar.gz                                 libXres-1.2.0.tar.bz2
alsa-tools-1.2.2.tar.bz2                                              
......

在petalinux-config的配置菜单" -> Yocto Settings -> Add pre-mirror url "里,输入上述文件所在的目录“file://path/downloads”。

重用下载文件

PetaLinux在编译过程中下载所需要的文件。编译结束后,目录build/downloads/下可能含有额外下载的文件。如果来源是上述的本地downloads,那么只是文件链接。如果是从网络下载,那么就是真实的文件。可以使用命令“ls -l | grep -v ">" | grep -v done”排除链接和后缀为done的标志文件,从而只显示从网络下载的文件。

建议把真实的文件件拷贝到上述的本地downloads目录。以后编译PetaLinux工程,可以重用本地的这些文件。后续的编译,就不会从网络下载,速度会更快。

$ ls build/downloads/*.xz
build/downloads/atk-2.28.1.tar.xz                    build/downloads/grep-3.1.tar.xz                build/downloads/netbase_5.4.tar.xz
build/downloads/at-spi2-atk-2.26.2.tar.xz            build/downloads/gst-rtsp-server-1.14.4.tar.xz  build/downloads/ofono-1.24.tar.xz
build/downloads/at-spi2-core-2.28.0.tar.xz           build/downloads/gtk+-2.24.32.tar.xz            build/downloads/pango-1.42.4.tar.xz
... ...

$ ls build/downloads/*.bz2
build/downloads/alsa-lib-1.1.6.tar.bz2         build/downloads/libassuan-2.5.1.tar.bz2       build/downloads/pcre-8.42.tar.bz2
build/downloads/alsa-plugins-1.1.6.tar.bz2     build/downloads/libgpg-error-1.32.tar.bz2     build/downloads/pixman-0.34.0.tar.bz2
build/downloads/alsa-tools-1.1.6.tar.bz2       build/downloads/libICE-1.0.9.tar.bz2          build/downloads/sysvinit-2.88dsf.tar.bz2
... ...

离线编译

如果确信所有软件包都已经在本地,可以去掉网络连接,执行离线编译,会提高编译速度。
在菜单Yocto Settings里,去掉“Enable Network sstate feeds”,选择“Enable BB NO NETWORK”。

PetaLinux编译Linux和U-Boot

PetaLinux在编译工程中,会自动编译Linux和U-Boot。

使用命令“petalinux-build -c kernel”, 只编译Linux; 使用命令“petalinux-build -c u-boot”, 只编译U-Boot。。

在build目录下的子目录kernel-build-artifacts也保存了Linux的配置文件.config。对于PetaLinux 2021.1的ZCU106 BSP工程,Linux的配置文件.config在build/tmp/work-shared/zynqmp-generic/kernel-build-artifacts/。

如果使用了image.ub格式,build目录下也有创建image.ub文件的its文件。对于PetaLinux 2021.1的ZCU106 BSP工程,its文件是build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+gitAUTOINC+c830a552a6-r0/linux-zynqmp_generic-standard-build/fit-image-petalinux-initramfs-image.its。

在build目录下的子目录build下,保存了UBoot的配置文件.config. 对于PetaLinux 2021.1的ZCU106 BSP工程,UBoot的配置文件.config在build/tmp/work/zynqmp_generic-xilinx-linux/u-boot-xlnx/v2021.01-xilinx-v2021.1+gitAUTOINC+41fc08b3fe-r0/build/。

devtool取得Linux和UBoot源代码

PetaLinux也提供Yocto的devtool工具,通过devtool能直接取得Linux和UBoot源代码。在2021及之后的版本里,PetaLinux直接提供命令petalinux-devtool,实现Yocto的devtool的功能。在2021之前的版本里,导入目录components/yocto/下的“environment-setup-aarch64-xilinx-linux” 和 “layers/core/oe-init-build-env”的环境,能使用Yocto的devtool工具。

通过执行命令“petalinux-devtool modify linux-xlnx”, Linux源代码会被保存至"components/yocto/workspace/sources/linux-xlnx"目录下。

通过执行命令“petalinux-devtool modify u-boot-xlnx”, Linux源代码会被保存至"components/yocto/workspace/sources/u-boot-xlnx"目录下。

工程师修改上述的Linux和UBoot源代码后,直接编译PetaLinux工程,修改就会生效。

调试完成后,再执行命令“petalinux-devtool finish linux-xlnx project-spec/meta-user”,能为Linux创建patch,并且不再使用上述代码。所以使用petalinux-devtool的方式获取代码,能更容易的创建patch,把修改合并回PetaLinux工程。

Open Source流程编译Linux和UBoot

结合devtool取得的Linux和UBoot源代码, 和build目录下的配置文件.config,可以整合Linux和UBoot的PetaLinux编译流程与Open Source 编译流程。

注意,在以Open Source流程编译Linux和UBoot之前,请先成功编译PetaLinux工程。

获取源代码和配置文件

下述脚本通过devtool取得的Linux和UBoot源代码, 并复制build目录下的Linux和UBoot配置文件.config到各自的源代码目录中。

#!/bin/bash
# Author: Hank FU, hankf@amd.com; hankf@xilinx.com; 
# osl-fetch-source.sh
# Execute osl-fetch-source.sh in PetaLinux project directory. 

if [ ! -d ./project-spec/meta-user/recipes-bsp/ ]; then 
    echo "Not PetaLinux project directory."
    echo "No directory: ./project-spec/meta-user/recipes-bsp "
    echo "Exit."
    exit 1
fi 

echo "Check image of PetaLinux project."
ls -l ./images/linux/u-boot.elf 
ls -l ./images/linux/Image
if [ ! -f ./images/linux/u-boot.elf ] || [ ! -f ./images/linux/Image ]; then 
    echo "PetaLinux project is not built successfully."
    echo "Please build it first."
    exit 1
fi 

peta_dir=`pwd`

# check petalinux tool
echo "check petalinux tool:"  
which petalinux-build    
which petalinux-devtool  

petalinux_devtool=`which petalinux-devtool` 
echo "petalinux devtool:  $petalinux_devtool"  

# PetaLinux 2020.1: no petalinux-devtool
# source /opt/pkg/petalinux/settings.sh
# source <plnx-proj-root>/components/yocto/environment-setup-aarch64-xilinx-linux
# source <plnx-proj-root>/components/yocto/layers/core/oe-init-build-env
if [ "$petalinux_devtool" = "" ]; then
    echo "Source yocto environment"  

    # source components/yocto/environment-setup-aarch64-xilinx-linux  
    # source components/yocto/layers/core/oe-init-build-env          

    # No output re-direction, command "devtool" in the current bash after "source".
    if [ -f ./components/yocto/environment-setup-aarch64-xilinx-linux ]; then 
        echo "Source yocto environment: aarch64"  
        source ./components/yocto/environment-setup-aarch64-xilinx-linux         
    elif [ -f ./components/yocto/environment-setup-cortexa72-cortexa53-xilinx-linux ]; then
        echo "Source yocto environment: cortexa72"  
        source ./components/yocto/environment-setup-cortexa72-cortexa53-xilinx-linux         
    fi 

    source components/yocto/layers/core/oe-init-build-env    
        # It enter directory "build"  
        echo -e "\nShow current directory: "   
        pwd                                    
    if [ -d ../components/yocto/ ]; then 
        cd .. 
    fi 

    if [ ! -d ./components/yocto/ ]; then 
        echo -e "\nError current directory: "  
        pwd 
        exit
    fi 

    petalinux_devtool=`which devtool`
    echo "petalinux devtool:  $petalinux_devtool"  
    devtool create-workspace ./components/yocto/workspace/sources  
fi

if [ "$petalinux_devtool" = "" ]; then
    echo "Error: petalinux devtool is invalid"  
    exit
fi

echo -e "\nShow current directory: "   
pwd                                    

sources_dir=$peta_dir/components/yocto/workspace/sources
echo -e "\nTry to modify components into directory: $sources_dir\n"  

# ug1144 Table 42: petalinux-build -c Components
# 
# Get the source code from git url specifi ed  in meta-layers:
#     petalinux-devtool modify <recipe-name>
# 
# Creates a patch for the committed  changes in recipe sources directory.
#     petalinux-devtool finish <recipe-name> <destination layer path>

echo -e "\nTry to modify linux-xlnx"    
$petalinux_devtool modify linux-xlnx     

linux_kernel_config_file=`find -name ".config"     | grep -i kernel-build-artifacts`
if [ "$linux_kernel_config_file" = "" ]; then
    echo "Failed to findLinux-kernel .config file.";   
    exit 1
fi

echo -e "\nLinux-kernel .config file: $linux_kernel_config_file"      
if [ -d $sources_dir/linux-xlnx/ ]; then
    cp $linux_kernel_config_file  $sources_dir/linux-xlnx/config_file_used_by_petalinux   
    # only one arch config files is valid.
    cp $linux_kernel_config_file  $sources_dir/linux-xlnx/arch/arm64/configs/xilinx_peta_defconfig   
    cp $linux_kernel_config_file  $sources_dir/linux-xlnx/arch/arm/configs/xilinx_peta_defconfig    
    cp $linux_kernel_config_file  $sources_dir/linux-xlnx/   
else
    echo -e "\nNo Linux-kernel source code directory"          
fi

linux_kernel_its_file=`find -name "fit-image-petalinux*.its" | grep -i build `
if [ "$linux_kernel_its_file" = "" ]; then
    echo "Failed to find Linux-kernel image.ub its file.";   
    exit 1
fi

echo -e "\nLinux-kernel image.ub its file: $linux_kernel_its_file"      
if [ -d $sources_dir/linux-xlnx/ ]; then
    cp $linux_kernel_its_file  $sources_dir/linux-xlnx/   
else
    echo -e "\nNo Linux-kernel source code directory"          
fi

echo -e "\nTry to modify u-boot-xlnx"    
$petalinux_devtool modify u-boot-xlnx     

u_boot_config_file=`find -name ".config" | grep -i u-boot-xlnx | grep -i build `
if [ "$u_boot_config_file" = "" ]; then
    echo "Failed to find U-Boot .config file.";   
    exit 1
fi

echo -e "\nU-boot .config file: $u_boot_config_file"          
if [ -d $sources_dir/u-boot-xlnx/ ]; then
    cp $u_boot_config_file  $sources_dir/u-boot-xlnx/config_file_used_by_petalinux   
    cp $u_boot_config_file  $sources_dir/u-boot-xlnx/configs/xilinx_peta_defconfig   
    cp $u_boot_config_file  $sources_dir/u-boot-xlnx/ 
else
    echo -e "\nNo U-boot source code directory"          
fi

echo -e "\nShow current directory: "   
pwd                                    

if [ -d $sources_dir/ ]; then 
    echo -e "\nShow components that can be modified in $sources_dir/"   
     ls -l $sources_dir/          
else
        echo -e "\nNo components that can be modified in $sources_dir/"   
fi 

# petalinux-devtool finish <recipe-name> <destination layer path>
# 
# petalinux-devtool reset <recipe-name> to remove the source directory for the recipe from workspace.

Open Source流程编译UBoot

在上面脚本取得的UBoot目录中,编译UBoot,得到u-boot.elf文件,再借用PetaLinux工程生成的其它文件,生成BOOT.bin,可以启动并引导Linux。

在PetalLinux工程目录中执行下列脚本,能以Open Source流程编译UBoot,并自动生成BOOT.bin。

#!/bin/bash
# Author: Hank FU, hankf@amd.com
# osl-make-uboot.sh
# Execute osl-make-uboot.sh in PetaLinux project directory. 
# Usage: osl-make-uboot.sh uboot_source_dir [ Default: components/yocto/workspace/sources/u-boot-xlnx]

if [ ! -d ./project-spec/meta-user/recipes-bsp/ ]; then 
    echo "Not PetaLinux project directory."
    echo "No directory: ./project-spec/meta-user/recipes-bsp "
    echo "Exit."
    exit 1
fi 

peta_dir=`pwd`
echo "Current directory: $peta_dir"

petalinux_tool=`which petalinux-build` 
if [ "$petalinux_tool" = "" ]; then
    echo "Error: petalinux-build is invalid"
    exit 1
fi

# Check PetaLinux building environment variable settings.
if [ "$ARCH" != "arm" ]; then
    if [ "$ARCH" != "arm64" ]; then
        echo "ARCH is not set correctly.";
        exit 1
    fi
fi

if [ "$CROSS_COMPILE" = "" ]; then
    echo "CROSS_COMPILE is not set.";
    exit 1
fi
echo "PetaLinux building environment variable is set.";
echo "ARCH: $ARCH"
echo -e "CROSS_COMPILE: $CROSS_COMPILE\n"

uboot_dir=$1
if [ "$uboot_dir" = "" ]; then

    if [ -d ./components/yocto/workspace/sources/u-boot-xlnx/arch/arm/ ]; then
            uboot_dir=./components/yocto/workspace/sources/u-boot-xlnx
    else
            uboot_dir=
    fi
fi

if [ ! -d  $uboot_dir ]; then 
    echo "No U-Boot source directory: $uboot_dir"
    echo "Usage: $0 uboot_source_dir [ Default: components/yocto/workspace/sources/u-boot-xlnx]"
    exit 1
fi 

cd $uboot_dir
echo "U-Boot source directory: "
pwd

if [ ! -f  .config ]; then 
    echo "Has no config file: .config."
    echo "U-Boot source code not configured."
    exit 1
fi 

make -j 
ls -l -h u-boot.elf

if [ ! -f  u-boot.elf ]; then 
    echo "Failed to build U-Boot in directory: $peta_dir/$uboot_dir"
    exit 1
fi 

cd  $peta_dir
rm -f images/linux/BOOT.BIN
cp  $uboot_dir/u-boot.elf ./images/linux/
petalinux-package --boot --u-boot $uboot_dir/u-boot.elf --force
ls -l -h images/linux/BOOT.BIN

Open Source流程编译Linux

在上面脚本取得的Linux目录中,编译Linux,得到Image文件,直接可以和system.dtb、rootfs.cpio.gz.u-boot一起启动。

还可以根据上述的its文件,创建image.ub。但是PetaLinux的its文件引用dtb文件、rootfs文件时,使用了内部的绝对路径,建议改成PetaLinux工程的images/linux目录。 注意下面的its文件,system-top.dtb被改为了system.dtb,petalinux-initramfs-image-zynqmp-generic.cpio.gz改为了rootfs.cpio.gz, 而且路径也改到了PetaLinux的images/linux目录。总之,要保证its文件中的设备树文件路径正确,文件系统的cpio.gz文件路径正确。

/dts-v1/;

/ {
        description = "U-Boot fitImage for PetaLinux/5.10+gitAUTOINC+c830a552a6/zynqmp-generic";
        #address-cells = <1>;

        images {
                kernel-1 {
                        description = "Linux kernel";
                        data = /incbin/("linux.bin");
                        type = "kernel";
                        arch = "arm64";
                        os = "linux";
                        compression = "gzip";
                        load = <0x80000>;
                        entry = <0x80000>;
                        hash-1 {
                                algo = "sha256";
                        };
                };
                fdt-system-top.dtb {
                        description = "Flattened Device Tree blob";
                        
                        /* data = /incbin/("/proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+gitAUTOINC+c830a552a6-r0/recipe-sysroot/boot/devicetree/system-top.dtb"); */
                        
                        data = /incbin/("/proj/hankf/v211/zcu106-bsp-peta/images/linux/system.dtb");
                        
                        type = "flat_dt";
                        arch = "arm64";
                        compression = "none";
                        
                        hash-1 {
                                algo = "sha256";
                        };
                };
                ramdisk-1 {
                        description = "petalinux-initramfs-image";
                        
                        /* data = /incbin/("/proj/hankf/v211/zcu106-bsp-peta/build/tmp/deploy/images/zynqmp-generic/petalinux-initramfs-image-zynqmp-generic.cpio.gz"); */
                        
                        data = /incbin/("/proj/hankf/v211/zcu106-bsp-peta/images/linux/rootfs.cpio.gz");
                        type = "ramdisk";
                        arch = "arm64";
                        os = "linux";
                        compression = "none";
                        
                        
                        hash-1 {
                                algo = "sha256";
                        };
                };
    };

        configurations {
                default = "conf-system-top.dtb";
                conf-system-top.dtb {
            description = "1 Linux kernel, FDT blob, ramdisk";
            kernel = "kernel-1";
            fdt = "fdt-system-top.dtb";
            ramdisk = "ramdisk-1";
            
                        hash-1 {
                                algo = "sha256";
                        };
                };
    };
};

在PetalLinux工程目录中执行下列脚本,能以Open Source流程编译Linux,并将Image、Image.ub文件复制到PetalLinux 工程目录中的目录“images/linux/”。

#!/bin/bash
# Author: Hank FU, hankf@amd.com
# osl-make-linux.sh
# Execute osl-make-linux.sh in PetaLinux project directory. 
# Usage: osl-make-linux.sh linux_source_dir [ Default: components/yocto/workspace/sources/linux-xlnx]

if [ ! -d ./project-spec/meta-user/recipes-bsp/ ]; then 
    echo "Not PetaLinux project directory."
    echo "No directory: ./project-spec/meta-user/recipes-bsp "
    echo "Exit."
    exit 1
fi 

peta_dir=`pwd`
echo "Current directory: $peta_dir"

petalinux_tool=`which petalinux-build` 
if [ "$petalinux_tool" = "" ]; then
    echo "Error: petalinux-build is invalid"
    exit 1
fi

# Check PetaLinux building environment variable settings.
if [ "$ARCH" != "arm" ]; then
    if [ "$ARCH" != "arm64" ]; then
        echo "ARCH is not set correctly.";
        exit 1
    fi
fi

if [ "$CROSS_COMPILE" = "" ]; then
    echo "CROSS_COMPILE is not set.";
    exit 1
fi
echo "PetaLinux building environment variable is set.";
echo "ARCH: $ARCH"
echo -e "CROSS_COMPILE: $CROSS_COMPILE\n"

linux_dir=$1
if [ "$linux_dir" = "" ]; then

    if [ -d ./components/yocto/workspace/sources/linux-xlnx/arch/arm/ ]; then
            linux_dir=./components/yocto/workspace/sources/linux-xlnx
    else
            linux_dir=
    fi
fi

if [ ! -d  $linux_dir ]; then 
    echo "No Linux kernel directory: $linux_dir"
    echo "Usage: $0 linux_source_dir [ Default: components/yocto/workspace/sources/linux-xlnx]"
    exit 1
fi 

cd $linux_dir
echo "Linux kernel directory: "
pwd
echo ""

if [ ! -f  .config ]; then 
    echo "Has no config file: .config."
    echo "Linux kernel source code not configured."
    exit 1
fi 

make -j 
ls -l -h ./arch/arm64/boot/Image
ls -l -h vmlinux
if [ ! -f ./arch/arm64/boot/Image ]; then 
    echo "Failed to build Linux in directory: $peta_dir/$linux_dir"
    exit 1
fi 

# Build image.ub
if [ -f vmlinux ]; then
    
    echo "Linux vmlinux in directory: $peta_dir/$linux_dir:: "
    ls -l vmlinux

    linux_kernel_its_file=` find -name "fit-image-petalinux*.its" `
    if [ ! "$linux_kernel_its_file" = "" ]; then

        echo "Create image.ub by using its file: $linux_kernel_its_file."
        rm -f linux_objcopy.bin
        rm -f linux.bin
        rm -f image.ub
        aarch64-linux-gnu-objcopy -O binary -R .note -R .comment -S vmlinux linux_objcopy.bin
        gzip -9 linux_objcopy.bin
        mv -f linux_objcopy.bin.gz linux.bin
        mkimage -f $linux_kernel_its_file image.ub 
    else        
        echo "No image.ub its file in directory: $peta_dir/$linux_dir"    
    fi
else        
    echo "Failed to build Linux vmlinux in directory: $peta_dir/$linux_dir"    
fi

# Copy Image and image.ub to PetaLinux project's directory: images/linux/
cd  $peta_dir
rm -f images/linux/Image
rm -f images/linux/image.ub
cp  $linux_dir/arch/arm64/boot/Image ./images/linux/
cp  $linux_dir/image.ub ./images/linux/
ls -l -h images/linux/Image
ls -l -h images/linux/image.ub

已知问题

错误"Failed to find U-Boot .config file."

使用上述脚本osl-fetch-source.sh,获取Linux和UBoot源代码时,找不到UBoot的配置文件.config,得到错误"Failed to find U-Boot .config file."。

请在project-spec/meta-user/conf/petalinuxbsp.conf里,添加如下内容,保留Linux和UBoot源代码和配置文件.config。 修改后,删除build目录下的所有文件,再编译,就能找到UBoot的配置文件.config。

RM_WORK_EXCLUDE += "linux-xlnx"
RM_WORK_EXCLUDE += "u-boot-xlnx"

错误"The source tree is not clean"

在使用OpenSource Linux编译流程后,再回到Petalinux的编译,执行petalinux-build会得到下列错误。需要在Linux的源代码目录,执行命令“make mrproper”,清理Linux的源代码目录。

NOTE: Executing Tasks
NOTE: linux-xlnx: compiling from external source tree /proj/hankf/v211/zcu106-bsp-peta/components/yocto/workspace/sources/linux-xlnx
ERROR: linux-xlnx-5.10+git999-r0 do_compile: oe_runmake failed
ERROR: linux-xlnx-5.10+git999-r0 do_compile: Execution of '/proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655' failed with exit code 1:
***
*** The source tree is not clean, please run 'make mrproper'
*** in /proj/hankf/v211/zcu106-bsp-peta/components/yocto/workspace/sources/linux-xlnx
***
make[1]: *** [/proj/hankf/v211/zcu106-bsp-peta/components/yocto/workspace/sources/linux-xlnx/Makefile:547: outputmakefile] Error 1
make: *** [/proj/hankf/v211/zcu106-bsp-peta/components/yocto/workspace/sources/linux-xlnx/Makefile:185: __sub-make] Error 2
WARNING: /proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655:306 exit 1 from 'exit 1'
WARNING: Backtrace (BB generated script): 
	#1: bbfatal_log, /proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655, line 306
	#2: die, /proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655, line 286
	#3: oe_runmake, /proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655, line 161
	#4: kernel_do_compile, /proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655, line 197
	#5: do_compile, /proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655, line 152
	#6: main, /proj/hankf/v211/zcu106-bsp-peta/build/tmp/work/zynqmp_generic-xilinx-linux/linux-xlnx/5.10+git999-r0/temp/run.do_compile.49655, line 310

Backtrace (metadata-relative locations):
	#1: bbfatal_log, /proj/hankf/v211/zcu106-bsp-peta/components/yocto/layers/core/meta/classes/logging.bbclass, line 72
	#2: die, /proj/hankf/v211/zcu106-bsp-peta/components/yocto/layers/core/meta/classes/base.bbclass, line 56
	#3: oe_runmake, /proj/hankf/v211/zcu106-bsp-peta/components/yocto/layers/core/meta/classes/base.bbclass, line 65
	#4: kernel_do_compile, /proj/hankf/v211/zcu106-bsp-peta/components/yocto/layers/meta-petalinux/oe-core/meta/classes/kernel.bbclass, line 349
	#5: do_compile, autogenerated, line 2

错误devtool_post_patch

在执行命令“petalinux-devtool reset”,停止使用外部源代码后,再通过命令“petalinux-devtool modify”获取源代码,可能得到下列错误。请删除Petalinux工程的build目录下的所有文件,再重新编译Petalinux工程,再通过命令“petalinux-devtool modify”获取源代码。

NOTE: Executing Tasks
ERROR: Error executing a python function in exec_python_func() autogenerated:

The stack trace of python calls that resulted in this exception/failure was:
File: 'exec_python_func() autogenerated', lineno: 2, function: <module>
     0001:
 *** 0002:devtool_post_patch(d)
     0003:
File: '/proj/hankf/v211/zcu106-bsp-peta/components/yocto/layers/core/meta/classes/devtool-source.bbclass', lineno: 226, function: devtool_post_patch
     0222:                bb.build.exec_func('do_patch', localdata)
     0223:                rm_patches()
     0224:                # Now we need to reconcile the new branch with the no-overrides one
     0225:                # (otherwise we'd likely be left with identical commits that have different hashes)
 *** 0226:                bb.process.run('git rebase devtool-no-overrides', cwd=srcsubdir)
     0227:        bb.process.run('git checkout %s' % devbranch, cwd=srcsubdir)
     0228:    bb.process.run('git tag -f devtool-patched', cwd=srcsubdir)
     0229:}
     0230:
File: '/proj/hankf/v211/zcu106-bsp-peta/components/yocto/layers/core/bitbake/lib/bb/process.py', lineno: 184, function: run
     0180:        if not stderr is None:
     0181:            stderr = stderr.decode("utf-8")
     0182:
     0183:    if pipe.returncode != 0:
 *** 0184:        raise ExecutionError(cmd, pipe.returncode, stdout, stderr)
     0185:    return stdout, stderr
Exception: bb.process.ExecutionError: Execution of 'git rebase devtool-no-overrides' failed with exit code 128:
fatal: It seems that there is already a rebase-apply directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
	git rebase (--continue | --abort | --skip)
If that is not the case, please
	rm -fr ".git/rebase-apply"
and run me again.  I am stopping in case you still have something
valuable there.

测试环境

  • Ubuntu 18.04

  • PetaLinux 2021.1/2022.1

  • PetaLinux 2021.1/2022.1 ZCU106 BSP

  • PetaLinux 2021.1/2022.1 KR260 BSP

  • ZCU106

  • KR260

文章转载自: 博客园

最新文章

最新文章