blob: ce1ad7cb23a289454b5fac7c80e3803e58d0f412 [file] [log] [blame]
Tom Rini04549e92021-03-15 13:19:01 -04001# SPDX-License-Identifier: GPL-2.0+
2# This Dockerfile is used to build an image containing basic stuff to be used
3# to build U-Boot and run our test suites.
4
Tom Rinie0c84c82024-08-21 09:41:20 -06005FROM ubuntu:jammy-20240808
Tom Rini92160da2024-08-19 15:07:19 -06006LABEL org.opencontainers.image.authors="Tom Rini <trini@konsulko.com>"
7LABEL org.opencontainers.image.description=" This image is for building U-Boot inside a container"
Tom Rini04549e92021-03-15 13:19:01 -04008
Simon Glass7aafac02024-11-27 11:17:26 -06009# Used by docker to set the target platform: valid values are linux/arm64/v8
10# and linux/amd64
11ARG TARGETPLATFORM
12
13# Used by docker to set the build platform: the only valid value is linux/amd64
14ARG BUILDPLATFORM
15
Tom Rini04549e92021-03-15 13:19:01 -040016# Make sure apt is happy
17ENV DEBIAN_FRONTEND=noninteractive
18
Simon Glassef4ca582024-11-27 11:17:29 -060019# Set architectures to build for (leaving out ARM which is an exception)
20ENV ARCHS="aarch64 arc i386 m68k mips microblaze nios2 powerpc riscv64 riscv32 sh2 x86_64"
21
22# Mirror containing the toolchains
23ENV MIRROR=https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin
24
25# Toolchain version
26ENV TCVER=13.2.0
27
Simon Glass7aafac02024-11-27 11:17:26 -060028RUN echo "Building on $BUILDPLATFORM, for target $TARGETPLATFORM"
29
Tom Rini04549e92021-03-15 13:19:01 -040030# Add LLVM repository
Tom Rini3f88c792024-11-27 11:17:25 -060031RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
32 --mount=type=cache,target=/var/lib/apt,sharing=locked \
33 apt-get update && apt-get install -y gnupg2 wget xz-utils
Tom Rini04549e92021-03-15 13:19:01 -040034RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
Tom Rinie752a3a2024-03-10 15:59:28 -040035RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main | tee /etc/apt/sources.list.d/llvm.list
Tom Rini04549e92021-03-15 13:19:01 -040036
Simon Glassef4ca582024-11-27 11:17:29 -060037# Create a list of URLs to process, then pass them into a 'while read' loop
38RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then HOSTARCH=x86_64; else HOSTARCH=arm64; fi; ( \
39 # Manually install the kernel.org "Crosstool"-based toolchains
40 for arch in $ARCHS; do \
41 echo $MIRROR/$HOSTARCH/$TCVER/${HOSTARCH}-gcc-$TCVER-nolibc-${arch}-linux.tar.xz; \
42 done; \
43 \
44 # Deal with ARM, which has a 'gnueabi' suffix
45 echo $MIRROR/${HOSTARCH}/$TCVER/${HOSTARCH}-gcc-$TCVER-nolibc-arm-linux-gnueabi.tar.xz; \
46 \
47 ) | while read url; do \
48 # Read the URL and unpack it into /opt
49 wget -O - $url | tar -C /opt -xJ; \
50 done
Tom Rini04549e92021-03-15 13:19:01 -040051
52# Manually install other toolchains
Simon Glassef4ca582024-11-27 11:17:29 -060053RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
54 wget -O - https://github.com/foss-xtensa/toolchain/releases/download/2020.07/x86_64-2020.07-xtensa-dc233c-elf.tar.gz | tar -C /opt -xz; \
55 fi
Tom Rini04549e92021-03-15 13:19:01 -040056
57# Update and install things from apt now
Tom Rini3f88c792024-11-27 11:17:25 -060058RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
59 --mount=type=cache,target=/var/lib/apt,sharing=locked \
60 apt-get update && apt-get install -y \
Tom Rini04549e92021-03-15 13:19:01 -040061 automake \
62 autopoint \
63 bc \
64 binutils-dev \
65 bison \
66 build-essential \
Simon Glassbe17cb32023-08-24 13:55:46 -060067 cgpt \
Tom Rinie752a3a2024-03-10 15:59:28 -040068 clang-17 \
Tom Rini04549e92021-03-15 13:19:01 -040069 coreutils \
70 cpio \
Tom Rini04549e92021-03-15 13:19:01 -040071 curl \
72 device-tree-compiler \
73 dosfstools \
74 e2fsprogs \
75 efitools \
Huang Jianan11e04432022-02-26 15:05:51 +080076 erofs-utils \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +010077 expect \
Tom Rini04549e92021-03-15 13:19:01 -040078 fakeroot \
79 flex \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +010080 gawk \
Tom Rini04549e92021-03-15 13:19:01 -040081 gdisk \
Tom Rini12248ed2024-11-27 11:17:23 -060082 gettext \
Tom Rini04549e92021-03-15 13:19:01 -040083 git \
84 gnu-efi \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +010085 gnutls-dev \
Tom Rini04549e92021-03-15 13:19:01 -040086 graphviz \
Tom Rini04549e92021-03-15 13:19:01 -040087 help2man \
88 iasl \
89 imagemagick \
90 iputils-ping \
Bin Mengf551a532021-08-26 23:33:33 +080091 libconfuse-dev \
Tom Rinic8982d22021-06-10 10:57:36 -040092 libgit2-dev \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +010093 libjson-glib-dev \
Tom Rini04549e92021-03-15 13:19:01 -040094 libguestfs-tools \
AKASHI Takahiro3edc3472022-02-01 10:32:36 +090095 libgnutls28-dev \
96 libgnutls30 \
Tom Rini04549e92021-03-15 13:19:01 -040097 liblz4-tool \
98 libpixman-1-dev \
Tom Rinic8982d22021-06-10 10:57:36 -040099 libpython3-dev \
Tom Rini04549e92021-03-15 13:19:01 -0400100 libsdl1.2-dev \
101 libsdl2-dev \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +0100102 libseccomp-dev \
Tom Rini83da2322023-07-13 10:16:28 -0400103 libslirp-dev \
Tom Rini04549e92021-03-15 13:19:01 -0400104 libssl-dev \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +0100105 libtool \
Tom Rini04549e92021-03-15 13:19:01 -0400106 libudev-dev \
107 libusb-1.0-0-dev \
Simon Glass86baff12024-11-27 11:17:27 -0600108 linux-image-generic \
Tom Rini04549e92021-03-15 13:19:01 -0400109 lzma-alone \
110 lzop \
111 mount \
112 mtd-utils \
113 mtools \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +0100114 net-tools \
Bin Meng00afccd2021-08-26 23:33:32 +0800115 ninja-build \
Tom Rini04549e92021-03-15 13:19:01 -0400116 openssl \
117 picocom \
118 parted \
119 pkg-config \
Tom Rinic8982d22021-06-10 10:57:36 -0400120 python-is-python3 \
121 python2.7 \
122 python3 \
123 python3-dev \
Tom Rini04549e92021-03-15 13:19:01 -0400124 python3-pip \
Simon Glassb955cd22022-10-13 06:25:57 -0600125 python3-pyelftools \
Tom Rini04549e92021-03-15 13:19:01 -0400126 python3-sphinx \
Tom Rinic8982d22021-06-10 10:57:36 -0400127 python3-virtualenv \
Tom Rini04549e92021-03-15 13:19:01 -0400128 rpm2cpio \
129 sbsigntool \
Heinrich Schuchardt4e202672021-11-09 19:51:20 +0100130 socat \
131 softhsm2 \
Tom Rini04549e92021-03-15 13:19:01 -0400132 sparse \
133 srecord \
134 sudo \
135 swig \
Heinrich Schuchardtc2c98ea2022-12-30 05:41:01 +0100136 texinfo \
Tom Rini04549e92021-03-15 13:19:01 -0400137 util-linux \
138 uuid-dev \
139 virtualenv \
Simon Glassbe17cb32023-08-24 13:55:46 -0600140 vboot-kernel-utils \
141 vboot-utils \
Heinrich Schuchardt905d0752024-02-28 08:23:09 +0100142 xilinx-bootgen \
Tom Rini0a78bc32021-07-02 10:41:58 -0400143 xxd \
Tom Rini3f88c792024-11-27 11:17:25 -0600144 zip
Tom Rini04549e92021-03-15 13:19:01 -0400145
Alper Nebi Yasak5d249e92021-06-21 21:51:54 +0300146# Make kernels readable for libguestfs tools to work correctly
147RUN chmod +r /boot/vmlinu*
148
Tom Rini04549e92021-03-15 13:19:01 -0400149# Build GRUB UEFI targets for ARM & RISC-V, 32-bit and 64-bit
150RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \
151 cd /tmp/grub && \
Tom Rini12248ed2024-11-27 11:17:23 -0600152 git checkout grub-2.12 && \
Tom Rini77d48f12022-11-22 12:31:58 -0500153 git config --global user.name "GitLab CI Runner" && \
154 git config --global user.email trini@konsulko.com && \
Tom Rini04549e92021-03-15 13:19:01 -0400155 ./bootstrap && \
156 mkdir -p /opt/grub && \
157 ./configure --target=aarch64 --with-platform=efi \
158 CC=gcc \
Tom Rini3bd5ed72023-08-25 13:21:26 -0400159 TARGET_CC=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc \
160 TARGET_OBJCOPY=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-objcopy \
161 TARGET_STRIP=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-strip \
162 TARGET_NM=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-nm \
163 TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/aarch64-linux/bin/aarch64-linux-ranlib && \
Tom Rini4bac0392024-11-27 11:17:22 -0600164 make -j$(nproc) && \
Tom Rini04549e92021-03-15 13:19:01 -0400165 ./grub-mkimage -O arm64-efi -o /opt/grub/grubaa64.efi --prefix= -d \
166 grub-core cat chain configfile echo efinet ext2 fat halt help linux \
167 lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \
168 search search_fs_file search_fs_uuid search_label serial sleep test \
169 true && \
170 make clean && \
171 ./configure --target=arm --with-platform=efi \
172 CC=gcc \
Tom Rini3bd5ed72023-08-25 13:21:26 -0400173 TARGET_CC=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc \
174 TARGET_OBJCOPY=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-objcopy \
175 TARGET_STRIP=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-strip \
176 TARGET_NM=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-nm \
177 TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ranlib && \
Tom Rini4bac0392024-11-27 11:17:22 -0600178 make -j$(nproc) && \
Tom Rini04549e92021-03-15 13:19:01 -0400179 ./grub-mkimage -O arm-efi -o /opt/grub/grubarm.efi --prefix= -d \
180 grub-core cat chain configfile echo efinet ext2 fat halt help linux \
181 lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \
182 search search_fs_file search_fs_uuid search_label serial sleep test \
183 true && \
184 make clean && \
185 ./configure --target=riscv64 --with-platform=efi \
186 CC=gcc \
Tom Rini3bd5ed72023-08-25 13:21:26 -0400187 TARGET_CC=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc \
188 TARGET_OBJCOPY=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-objcopy \
189 TARGET_STRIP=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-strip \
190 TARGET_NM=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-nm \
191 TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/riscv64-linux/bin/riscv64-linux-ranlib && \
Tom Rini4bac0392024-11-27 11:17:22 -0600192 make -j$(nproc) && \
Tom Rini04549e92021-03-15 13:19:01 -0400193 ./grub-mkimage -O riscv64-efi -o /opt/grub/grubriscv64.efi --prefix= -d \
194 grub-core cat chain configfile echo efinet ext2 fat halt help linux \
195 lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \
196 search search_fs_file search_fs_uuid search_label serial sleep test \
197 true && \
Tom Rinie8403a92024-11-27 11:17:24 -0600198 make clean && \
199 ./configure --target=i386 --with-platform=efi \
200 CC=gcc \
201 TARGET_CC=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-gcc \
202 TARGET_OBJCOPY=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-objcopy \
203 TARGET_STRIP=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-strip \
204 TARGET_NM=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-nm \
205 TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/i386-linux/bin/i386-linux-ranlib && \
206 make -j$(nproc) && \
207 ./grub-mkimage -O i386-efi -o /opt/grub/grub_x86.efi --prefix= -d \
208 grub-core normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd && \
209 make clean && \
210 ./configure --target=x86_64 --with-platform=efi \
211 CC=gcc \
212 TARGET_CC=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-gcc \
213 TARGET_OBJCOPY=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-objcopy \
214 TARGET_STRIP=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-strip \
215 TARGET_NM=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-nm \
216 TARGET_RANLIB=/opt/gcc-13.2.0-nolibc/x86_64-linux/bin/x86_64-linux-ranlib && \
217 make -j$(nproc) && \
218 ./grub-mkimage -O x86_64-efi -o /opt/grub/grub_x64.efi --prefix= -d \
219 grub-core normal echo lsefimmap lsefi lsefisystab efinet tftp minicmd && \
Tom Rini04549e92021-03-15 13:19:01 -0400220 rm -rf /tmp/grub
221
Tom Rinib60c1d72023-02-07 12:50:13 -0500222RUN git clone https://gitlab.com/qemu-project/qemu.git /tmp/qemu && \
Tom Rini04549e92021-03-15 13:19:01 -0400223 cd /tmp/qemu && \
Heinrich Schuchardt24069c22024-01-12 03:17:57 +0100224 git checkout v8.2.0 && \
Bin Meng00afccd2021-08-26 23:33:32 +0800225 # config user.name and user.email to make 'git am' happy
226 git config user.name u-boot && \
227 git config user.email u-boot@denx.de && \
Heinrich Schuchardt24069c22024-01-12 03:17:57 +0100228 git format-patch 0c7ffc977195~..0c7ffc977195 && \
229 git am 0001-hw-net-cadence_gem-Fix-MDIO_OP_xxx-values.patch && \
Tom Rini139e9952024-03-11 10:02:43 -0400230 git cherry-pick d3c79c3974 && \
Tom Rini26a41832023-03-21 15:28:00 -0400231 ./configure --prefix=/opt/qemu --target-list="aarch64-softmmu,arm-softmmu,i386-softmmu,m68k-softmmu,mips-softmmu,mips64-softmmu,mips64el-softmmu,mipsel-softmmu,ppc-softmmu,riscv32-softmmu,riscv64-softmmu,sh4-softmmu,x86_64-softmmu,xtensa-softmmu" && \
Tom Rini04549e92021-03-15 13:19:01 -0400232 make -j$(nproc) all install && \
233 rm -rf /tmp/qemu
234
Heinrich Schuchardt2b4a6562024-02-28 08:43:11 +0100235# Build fiptool
236RUN git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git /tmp/tf-a && \
237 cd /tmp/tf-a/ && \
238 git checkout v2.10.0 && \
239 cd tools/fiptool && \
Tom Rini4bac0392024-11-27 11:17:22 -0600240 make -j$(nproc) && \
Heinrich Schuchardt2b4a6562024-02-28 08:43:11 +0100241 mkdir -p /usr/local/bin && \
242 cp fiptool /usr/local/bin && \
243 rm -rf /tmp/tf-a
244
Bin Mengf551a532021-08-26 23:33:33 +0800245# Build genimage (required by some targets to generate disk images)
246RUN wget -O - https://github.com/pengutronix/genimage/releases/download/v14/genimage-14.tar.xz | tar -C /tmp -xJ && \
247 cd /tmp/genimage-14 && \
248 ./configure && \
249 make -j$(nproc) && \
250 make install && \
251 rm -rf /tmp/genimage-14
252
Heinrich Schuchardt4e202672021-11-09 19:51:20 +0100253# Build libtpms
254RUN git clone https://github.com/stefanberger/libtpms /tmp/libtpms && \
255 cd /tmp/libtpms && \
256 ./autogen.sh && \
257 ./configure && \
258 make -j$(nproc) && \
259 make install && \
260 ldconfig && \
261 rm -rf /tmp/libtpms
262
263# Build swtpm
264RUN git clone https://github.com/stefanberger/swtpm /tmp/swtpm && \
265 cd /tmp/swtpm && \
266 ./autogen.sh && \
267 ./configure && \
268 make -j$(nproc) && \
269 make install && \
270 rm -rf /tmp/swtpm
271
Simon Glass523cb6d2023-01-15 14:15:59 -0700272# Build trace-cmd
273RUN mkdir /tmp/trace && \
274 git clone https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git /tmp/trace/libtraceevent && \
275 cd /tmp/trace/libtraceevent && \
276 make -j$(nproc) && \
277 sudo make install && \
278 git clone https://git.kernel.org/pub/scm/libs/libtrace/libtracefs.git /tmp/trace/libtracefs && \
279 cd /tmp/trace/libtracefs && \
280 make -j$(nproc) && \
281 sudo make install && \
282 git clone https://github.com/rostedt/trace-cmd.git /tmp/trace/trace-cmd && \
283 cd /tmp/trace/trace-cmd && \
284 make -j$(nproc) && \
285 sudo make install && \
286 rm -rf /tmp/trace
287
Tom Rini9e2b09e2024-02-13 09:39:26 -0500288# Build coreboot
Simon Glass78b9c8a2024-10-14 16:32:05 -0600289RUN wget -O - https://coreboot.org/releases/coreboot-24.08.tar.xz | tar -C /tmp -xJ && \
290 cd /tmp/coreboot-24.08 && \
Tom Rini9e2b09e2024-02-13 09:39:26 -0500291 make crossgcc-i386 CPUS=$(nproc) && \
292 make -C payloads/coreinfo olddefconfig && \
293 make -C payloads/coreinfo && \
294 make olddefconfig && \
Simon Glass78b9c8a2024-10-14 16:32:05 -0600295 echo CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y | tee -a .config && \
296 echo CONFIG_USE_OPTION_TABLE=y | tee -a .config && \
297 make olddefconfig && \
Tom Rini9e2b09e2024-02-13 09:39:26 -0500298 make -j $(nproc) && \
299 sudo mkdir /opt/coreboot && \
300 sudo cp build/coreboot.rom build/cbfstool /opt/coreboot/
301
Tom Rini04549e92021-03-15 13:19:01 -0400302# Create our user/group
303RUN echo uboot ALL=NOPASSWD: ALL > /etc/sudoers.d/uboot
304RUN useradd -m -U uboot
305USER uboot:uboot
306
Tom Rini54573e02023-03-23 14:57:58 -0400307# Populate the cache for pip to use. Get these via wget as the
308# COPY / ADD directives don't work as we need them to.
309RUN wget -O /tmp/pytest-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/test/py/requirements.txt
310RUN wget -O /tmp/sphinx-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/doc/sphinx/requirements.txt
Tom Rini763160f2024-01-18 12:10:07 -0500311RUN wget -O /tmp/buildman-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/tools/buildman/requirements.txt
Tom Rini54573e02023-03-23 14:57:58 -0400312RUN virtualenv -p /usr/bin/python3 /tmp/venv && \
313 . /tmp/venv/bin/activate && \
314 pip install -r /tmp/pytest-requirements.txt \
Tom Rini763160f2024-01-18 12:10:07 -0500315 -r /tmp/sphinx-requirements.txt \
316 -r /tmp/buildman-requirements.txt && \
Tom Rini54573e02023-03-23 14:57:58 -0400317 deactivate && \
Tom Rini763160f2024-01-18 12:10:07 -0500318 rm -rf /tmp/venv /tmp/*-requirements.txt
Tom Rini54573e02023-03-23 14:57:58 -0400319
Tom Rini04549e92021-03-15 13:19:01 -0400320# Create the buildman config file
321RUN /bin/echo -e "[toolchain]\nroot = /usr" > ~/.buildman
Tom Rini3bd5ed72023-08-25 13:21:26 -0400322RUN /bin/echo -e "kernelorg = /opt/gcc-13.2.0-nolibc/*" >> ~/.buildman
Tom Rini0a78bc32021-07-02 10:41:58 -0400323RUN /bin/echo -e "\n[toolchain-prefix]\nxtensa = /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-" >> ~/.buildman;
Tom Rini04549e92021-03-15 13:19:01 -0400324RUN /bin/echo -e "\n[toolchain-alias]\nsh = sh2" >> ~/.buildman
Tom Rini04549e92021-03-15 13:19:01 -0400325RUN /bin/echo -e "\nx86 = i386" >> ~/.buildman;
Safae Ouajihaaa366f2023-02-06 00:50:21 +0100326
327# Add mkbootimg tool
328RUN git clone https://android.googlesource.com/platform/system/tools/mkbootimg /home/uboot/mkbootimg
Simon Glassf8e20122024-11-27 11:17:28 -0600329ENV PYTHONPATH="${PYTHONPATH}:/home/uboot/mkbootimg"