在Ubuntu 20.04上搞定PetaLinux 2020.1:从依赖安装到环境配置的完整避坑指南
在Ubuntu 20.04上搞定PetaLinux 2020.1:从依赖安装到环境配置的完整避坑指南
如果你正在Ubuntu 20.04上尝试安装PetaLinux 2020.1,可能会发现官方文档中明确支持的Ubuntu版本只到18.04。这种版本错配带来的依赖冲突和配置问题,往往让开发者陷入无休止的调试循环。本文将带你绕过这些坑,从底层依赖调整到环境验证,手把手完成这个"非官方支持"的组合配置。
1. 环境准备:解决Ubuntu 20.04的兼容性问题
PetaLinux 2020.1官方明确支持的最高Ubuntu版本是18.04 LTS,而20.04 LTS带来了诸多底层库的更新,这会导致直接安装时出现各种依赖冲突。我们需要先解决这些基础兼容性问题。
1.1 关键依赖库的版本降级
Ubuntu 20.04默认的Python 3.8和部分库的新版本会导致PetaLinux工具链出现问题。执行以下命令安装特定版本依赖:
sudo apt install python3.6 python3.6-dev sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1 sudo update-alternatives --config python3 # 选择3.6版本对于其他关键库,我们需要手动添加Ubuntu 18.04的软件源来获取兼容版本:
echo "deb http://archive.ubuntu.com/ubuntu bionic main universe" | sudo tee /etc/apt/sources.list.d/bionic.list sudo apt update sudo apt install -t bionic libssl1.0-dev zlib1g:i3861.2 Shell环境配置
PetaLinux工具链对shell环境有特殊要求,需要将默认的dash切换为bash:
sudo dpkg-reconfigure dash # 选择"No",保持使用bash同时设置正确的locale环境,避免后续构建时出现编码错误:
sudo locale-gen en_US.UTF-8 sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 export LANG=en_US.UTF-82. 完整依赖安装清单
除了基础库外,PetaLinux还需要一系列开发工具和库文件。以下是在Ubuntu 20.04上验证可用的完整安装命令:
sudo apt-get install -y \ iproute2 gcc g++ net-tools libncurses5-dev zlib1g:i386 \ libssl-dev flex bison libselinux1 xterm autoconf libtool \ texinfo zlib1g-dev gcc-multilib build-essential screen \ pax gawk python3 python3-pexpect python3-pip python3-git \ python3-jinja2 xz-utils debianutils iputils-ping libegl1-mesa \ libsdl1.2-dev pylint3 rsync cpio unzip texinfo chrpath socat \ libtool-bin locales libx11-dev libxext-dev libsdl2-dev \ libglib2.0-dev libgtk2.0-dev libc6:i386 libncurses5:i386 \ libstdc++6:i386 lib32z1 lib32ncurses5 lib32stdc++6 \ libc6-dev-i386 libtinfo5对于网络引导相关功能,还需要配置TFTP服务器:
sudo apt install -y tftp-hpa tftpboot-hpa mkdir ~/tftpboot chmod 777 ~/tftpboot编辑TFTP配置文件/etc/default/tftpd-hpa,确保包含以下内容:
TFTP_USERNAME="tftp" TFTP_DIRECTORY="/home/$(whoami)/tftpboot" TFTP_ADDRESS=":69" TFTP_OPTIONS="--secure -l -c -s"重启服务使配置生效:
sudo systemctl restart tftpd-hpa3. PetaLinux 2020.1安装与验证
3.1 安装程序准备
下载PetaLinux 2020.1安装包后,先确保其具有可执行权限:
chmod +x petalinux-v2020.1-final-installer.run建议在用户主目录下创建专用安装目录,避免权限问题:
mkdir -p ~/petalinux/2020.13.2 执行安装
运行安装程序并指定目标目录:
./petalinux-v2020.1-final-installer.run --dir ~/petalinux/2020.1安装过程中可能会提示一些警告信息,主要是关于操作系统版本不匹配,只要依赖库已正确安装,这些警告可以忽略。
3.3 环境变量配置
安装完成后,需要设置环境变量才能使用PetaLinux工具链:
source ~/petalinux/2020.1/settings.sh为了方便后续使用,可以将这行命令添加到~/.bashrc文件中:
echo "source ~/petalinux/2020.1/settings.sh" >> ~/.bashrc4. 常见问题排查与解决方案
4.1 构建时的Python兼容性问题
如果遇到Python相关错误,检查默认Python版本是否为3.6:
python3 --version如果不是,重新配置alternatives系统:
sudo update-alternatives --config python34.2 内存不足问题
PetaLinux构建过程对内存要求较高,如果遇到内存不足的情况,可以尝试:
- 增加swap空间:
sudo fallocate -l 8G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile- 或者限制并行构建任务数:
echo 'PARALLEL_MAKE = "-j 4"' >> project-spec/meta-user/conf/petalinuxbsp.conf4.3 网络代理设置
如果公司网络需要代理,需要配置PetaLinux使用代理:
export http_proxy=http://proxy.example.com:8080 export https_proxy=http://proxy.example.com:8080 export ftp_proxy=http://proxy.example.com:8080 export no_proxy=localhost,127.0.0.14.4 验证安装成功
执行以下命令验证PetaLinux是否安装正确:
petalinux-create -t project --template zynq --name test_project cd test_project petalinux-build如果能够成功创建项目并完成构建,说明环境配置正确。构建完成后,可以在images/linux目录下找到生成的启动文件。
