Docker搭建petalinux2022.1开发环境

Docker搭建petalinux2022.1开发环境

petalinux-docker

系统环境

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
cat /etc/os-release
PRETTY_NAME="Ubuntu 24.04 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
uname -a
Linux VM-4-13-ubuntu 6.8.0-71-generic #71-Ubuntu SMP PREEMPT_DYNAMIC Tue Jul 22 16:52:38 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux

准备docker构建petalinux环境

可以将构建环境上传到github仓库或者gitee仓库,需要的时候直接克隆下来使用就可以了

目录结构
1
2
3
4
5
6
7
8
9
# tree
.
├── accept-eula.sh
├── Dockerfile
├── LICENSE
├── petalinux-v2022.1-04191534-installer.run
└── README.md

1 directory, 5 files

注意:petalinux-v2022.1-04191534-installer.run,需要自行准备并拷贝到当前目录下,下载的文件要检验md5sum值与官方是否一致

准备构建文件
Dockerfile
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
cat - > Dockerfile <<'EOF'
FROM ubuntu:18.04

MAINTAINER z4yx <z4yx@users.noreply.github.com>

# build with "docker build --build-arg PETA_VERSION=2020.2 --build-arg PETA_RUN_FILE=petalinux-v2020.2-final-installer.run -t petalinux:2020.2 ."

# install dependences:

ARG UBUNTU_MIRROR
RUN [ -z "${UBUNTU_MIRROR}" ] || sed -i.bak s/archive.ubuntu.com/${UBUNTU_MIRROR}/g /etc/apt/sources.list 

RUN apt-get update &&  DEBIAN_FRONTEND=noninteractive apt-get install -y -q \
  autoconf \
  automake \
  bc \
  bison \
  build-essential \
  chrpath \
  cpio \
  debianutils \
  diffstat \
  expect \
  flex \
  g++ \
  gawk \  
  gcc \
  gcc-multilib \
  git \
  gnupg \
  gzip \
  kmod \
  iproute2 \
  iputils-ping \
  libegl1-mesa \
  libglib2.0-dev \  
  libgtk2.0-0 \
  libidn11 \
  libncurses5-dev \
  libsdl1.2-dev \
  libselinux1 \
  libssl-dev \
  libtinfo5 \
  libtool \
  libtool-bin \
  locales \
  lib32z1-dev \
  make \
  net-tools \
  pax \
  pxelinux \
  python \  
  python3 \
  python3-git \
  python3-jinja2 \
  python3-pexpect \
  python3-pip \
  rsync \
  screen \
  socat \
  sudo \
  tar \
  texinfo \
  tftp-hpa \
  tftpd-hpa \
  tofrodos \
  unzip \
  wget \
  xterm \
  xz-utils \
  zlib1g-dev \  
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*

RUN dpkg --add-architecture i386 &&  apt-get update &&  \
      DEBIAN_FRONTEND=noninteractive apt-get install -y -q \
      zlib1g:i386 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*


ARG PETA_VERSION
ARG PETA_RUN_FILE

RUN locale-gen en_US.UTF-8 && update-locale

#make a Vivado user
RUN adduser --disabled-password --gecos '' vivado && \
  usermod -aG sudo vivado && \
  echo "vivado ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers

COPY accept-eula.sh ${PETA_RUN_FILE} /

# run the install
RUN chmod a+rx /${PETA_RUN_FILE} && \
  chmod a+rx /accept-eula.sh && \
  mkdir -p /opt/Xilinx && \
  chmod 777 /tmp /opt/Xilinx && \
  cd /tmp && \
  sudo -u vivado -i /accept-eula.sh /${PETA_RUN_FILE} /opt/Xilinx/petalinux && \
  rm -f /${PETA_RUN_FILE} /accept-eula.sh

# make /bin/sh symlink to bash instead of dash:
RUN echo "dash dash/sh boolean false" | debconf-set-selections
RUN DEBIAN_FRONTEND=noninteractive dpkg-reconfigure dash

USER vivado
ENV HOME /home/vivado
ENV LANG en_US.UTF-8
RUN mkdir /home/vivado/project
WORKDIR /home/vivado/project

#add vivado tools to path
RUN echo "source /opt/Xilinx/petalinux/settings.sh" >> /home/vivado/.bashrc
EOF
accept-eula.sh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
cat - > accept-eula.sh <<'EOF'
#!/usr/bin/expect
set timeout -1
set install_dir [lindex $argv 1]
set installer [lindex $argv 0]

spawn $installer -d $install_dir
set timeout 2
expect {
    "ERROR: Invalid options:" {spawn $installer -d $install_dir }
    timeout { }
}

set timeout 600
expect "Press Enter to display the license agreements"
send "\r"
set timeout 2

expect {
    "* >*" {send "y\r"}
    timeout { send "q"; sleep 1; exp_continue}
}
expect {
    "* >*" {send "y\r"}
    timeout { send "q"; sleep 1; exp_continue}
}
expect {
    "*Installing PetaLinux...*" {}
    "* >*" {send "y\r"}
    timeout { send "q"; sleep 1; exp_continue}
}

set timeout -1
expect "INFO: Checking PetaLinux installer integrity..."
expect "INFO: PetaLinux SDK has been installed"
#interact
EOF

构建与运行

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 我已将相关文件上传到github并导入到gitee仓库
git clone -b petalinux-2022.1 https://gitee.com/yenao/petalinux-docker.git
cd petalinux-docker
# 将petalinux-v2022.1-04191534-installer.run拷贝到当前目录

# 构建
docker build --build-arg PETA_VERSION=2022.1 --build-arg PETA_RUN_FILE=petalinux-v2022.1-04191534-installer.run -t petalinux:2022.1 .

# 运行
docker run -ti --rm -e DISPLAY=$DISPLAY --net="host" -v /tmp/.X11-unix:/tmp/.X11-unix -v $HOME/.Xauthority:/home/vivado/.Xauthority -v $HOME/Projects:/home/vivado/project  petalinux:2022.1 /bin/bash

# 清理构建缓存
docker system prune

# 需要在项目目录内执行,
petalinux-util --webtalk off
<<'CONTENT'
WebTalk 是 Xilinx/AMD 的遥测功能,会收集你使用 PetaLinux 工具的匿名数据并发送给 AMD。
关闭它的原因:
1. 隐私 ― 不想被收集使用数据
2. 避免构建错误 ― WebTalk 需要联网,在很多环境下会失败,报错如:
      webtalk failed:Failed to get PetaLinux usage statistics!
3. 老旧功能 ― 从 PetaLinux 2022.2 开始,WebTalk 已被 AMD 移除
你用的 2022.1 版本还有这个功能,所以建议关闭。如果你确定不会遇到网络问题,也可以不关,不会影响核心功能。
注意:你现在已经在容器内了,运行 petalinux-util --webtalk off 需要在项目目录内执行,而不是全局设置。
CONTENT
comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计