1 # 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.
5 FROM ubuntu:jammy-20240808
7 LABEL org.opencontainers.image.description=" This image is for building U-Boot inside a container"
9 # Used by docker to set the target platform: valid values are linux/arm64/v8
13 # Used by docker to set the build platform: the only valid value is linux/amd64
16 # Make sure apt is happy
17 ENV DEBIAN_FRONTEND=noninteractive
19 # Set architectures to build for (leaving out ARM which is an exception)
20 ENV ARCHS="aarch64 arc i386 m68k mips microblaze nios2 powerpc riscv64 riscv32 sh2 x86_64"
22 # Mirror containing the toolchains
23 ENV MIRROR=https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin
28 RUN echo "Building on $BUILDPLATFORM, for target $TARGETPLATFORM"
31 RUN --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
34 RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
35 RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main | tee /etc/apt/sources.list.d/llvm.list
37 # Create a list of URLs to process, then pass them into a 'while read' loop
38 RUN 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; \
44 # Deal with ARM, which has a 'gnueabi' suffix
45 echo $MIRROR/${HOSTARCH}/$TCVER/${HOSTARCH}-gcc-$TCVER-nolibc-arm-linux-gnueabi.tar.xz; \
47 ) | while read url; do \
48 # Read the URL and unpack it into /opt
49 wget -O - $url | tar -C /opt -xJ; \
52 # Manually install other toolchains
53 RUN 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; \
57 # Update and install things from apt now
58 RUN --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 \
72 device-tree-compiler \
108 linux-image-generic \
146 # Make kernels readable for libguestfs tools to work correctly
147 RUN chmod +r /boot/vmlinu*
149 # Build GRUB UEFI targets for ARM & RISC-V, 32-bit and 64-bit
150 RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \
152 git checkout grub-2.12 && \
153 git config --global user.name "GitLab CI Runner" && \
156 mkdir -p /opt/grub && \
157 ./configure --target=aarch64 --with-platform=efi \
159 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 && \
165 ./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 \
171 ./configure --target=arm --with-platform=efi \
173 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 && \
179 ./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 \
185 ./configure --target=riscv64 --with-platform=efi \
187 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 && \
193 ./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 \
199 ./configure --target=i386 --with-platform=efi \
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 && \
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 && \
210 ./configure --target=x86_64 --with-platform=efi \
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 && \
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 && \
222 RUN git clone https://gitlab.com/qemu-project/qemu.git /tmp/qemu && \
224 git checkout v8.2.0 && \
225 # config user.name and user.email to make 'git am' happy
226 git config user.name u-boot && \
228 git format-patch 0c7ffc977195~..0c7ffc977195 && \
229 git am 0001-hw-net-cadence_gem-Fix-MDIO_OP_xxx-values.patch && \
230 git cherry-pick d3c79c3974 && \
231 ./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" && \
232 make -j$(nproc) all install && \
236 RUN git clone https://git.trustedfirmware.org/TF-A/trusted-firmware-a.git /tmp/tf-a && \
238 git checkout v2.10.0 && \
239 cd tools/fiptool && \
241 mkdir -p /usr/local/bin && \
242 cp fiptool /usr/local/bin && \
245 # Build genimage (required by some targets to generate disk images)
246 RUN wget -O - https://github.com/pengutronix/genimage/releases/download/v14/genimage-14.tar.xz | tar -C /tmp -xJ && \
247 cd /tmp/genimage-14 && \
251 rm -rf /tmp/genimage-14
254 RUN git clone https://github.com/stefanberger/libtpms /tmp/libtpms && \
264 RUN git clone https://github.com/stefanberger/swtpm /tmp/swtpm && \
273 RUN mkdir /tmp/trace && \
274 git clone https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git /tmp/trace/libtraceevent && \
275 cd /tmp/trace/libtraceevent && \
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 && \
281 sudo make install && \
282 git clone https://github.com/rostedt/trace-cmd.git /tmp/trace/trace-cmd && \
283 cd /tmp/trace/trace-cmd && \
285 sudo make install && \
289 RUN wget -O - https://coreboot.org/releases/coreboot-24.08.tar.xz | tar -C /tmp -xJ && \
290 cd /tmp/coreboot-24.08 && \
291 make crossgcc-i386 CPUS=$(nproc) && \
292 make -C payloads/coreinfo olddefconfig && \
293 make -C payloads/coreinfo && \
294 make olddefconfig && \
295 echo CONFIG_GENERIC_LINEAR_FRAMEBUFFER=y | tee -a .config && \
296 echo CONFIG_USE_OPTION_TABLE=y | tee -a .config && \
297 make olddefconfig && \
298 make -j $(nproc) && \
299 sudo mkdir /opt/coreboot && \
300 sudo cp build/coreboot.rom build/cbfstool /opt/coreboot/
302 # Create our user/group
303 RUN echo uboot ALL=NOPASSWD: ALL > /etc/sudoers.d/uboot
304 RUN useradd -m -U uboot
307 # 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.
309 RUN wget -O /tmp/pytest-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/test/py/requirements.txt
310 RUN wget -O /tmp/sphinx-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/doc/sphinx/requirements.txt
311 RUN wget -O /tmp/buildman-requirements.txt https://source.denx.de/u-boot/u-boot/-/raw/master/tools/buildman/requirements.txt
312 RUN virtualenv -p /usr/bin/python3 /tmp/venv && \
313 . /tmp/venv/bin/activate && \
314 pip install -r /tmp/pytest-requirements.txt \
315 -r /tmp/sphinx-requirements.txt \
316 -r /tmp/buildman-requirements.txt && \
318 rm -rf /tmp/venv /tmp/*-requirements.txt
320 # Create the buildman config file
321 RUN /bin/echo -e "[toolchain]\nroot = /usr" > ~/.buildman
322 RUN /bin/echo -e "kernelorg = /opt/gcc-13.2.0-nolibc/*" >> ~/.buildman
323 RUN /bin/echo -e "\n[toolchain-prefix]\nxtensa = /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-" >> ~/.buildman;
324 RUN /bin/echo -e "\n[toolchain-alias]\nsh = sh2" >> ~/.buildman
325 RUN /bin/echo -e "\nx86 = i386" >> ~/.buildman;
328 RUN git clone https://android.googlesource.com/platform/system/tools/mkbootimg /home/uboot/mkbootimg
329 ENV PYTHONPATH="${PYTHONPATH}:/home/uboot/mkbootimg"