docker: install riscv32 toolchain
[platform/kernel/u-boot.git] / tools / docker / Dockerfile
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.
4
5 FROM ubuntu:jammy-20221003
6 MAINTAINER Tom Rini <trini@konsulko.com>
7 LABEL Description=" This image is for building U-Boot inside a container"
8
9 # Make sure apt is happy
10 ENV DEBIAN_FRONTEND=noninteractive
11
12 # Add LLVM repository
13 RUN apt-get update && apt-get install -y gnupg2 wget xz-utils && rm -rf /var/lib/apt/lists/*
14 RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
15 RUN echo deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-13 main | tee /etc/apt/sources.list.d/llvm.list
16
17 # Manually install the kernel.org "Crosstool" based toolchains for gcc-11.1.0
18 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-aarch64-linux.tar.xz | tar -C /opt -xJ
19 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-arm-linux-gnueabi.tar.xz | tar -C /opt -xJ
20 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-i386-linux.tar.xz | tar -C /opt -xJ
21 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-m68k-linux.tar.xz | tar -C /opt -xJ
22 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-mips-linux.tar.xz | tar -C /opt -xJ
23 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-microblaze-linux.tar.xz | tar -C /opt -xJ
24 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-nios2-linux.tar.xz | tar -C /opt -xJ
25 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-powerpc-linux.tar.xz | tar -C /opt -xJ
26 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-riscv64-linux.tar.xz | tar -C /opt -xJ
27 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-riscv32-linux.tar.xz | tar -C /opt -xJ
28 RUN wget -O - https://mirrors.edge.kernel.org/pub/tools/crosstool/files/bin/x86_64/11.1.0/x86_64-gcc-11.1.0-nolibc-sh2-linux.tar.xz | tar -C /opt -xJ
29
30 # Manually install other toolchains
31 RUN 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
32 RUN wget -O - https://github.com/foss-for-synopsys-dwc-arc-processors/toolchain/releases/download/arc-2021.03-release/arc_gnu_2021.03_prebuilt_uclibc_le_archs_linux_install.tar.gz | tar --no-same-owner -C /opt -xz
33
34 # Update and install things from apt now
35 RUN apt-get update && apt-get install -y \
36         automake \
37         autopoint \
38         bc \
39         binutils-dev \
40         bison \
41         build-essential \
42         clang-13 \
43         coreutils \
44         cpio \
45         cppcheck \
46         curl \
47         device-tree-compiler \
48         dosfstools \
49         e2fsprogs \
50         efitools \
51         erofs-utils \
52         expect \
53         fakeroot \
54         flex \
55         gawk \
56         gdisk \
57         git \
58         gnu-efi \
59         gnutls-dev \
60         graphviz \
61         grub-efi-amd64-bin \
62         grub-efi-ia32-bin \
63         help2man \
64         iasl \
65         imagemagick \
66         iputils-ping \
67         libconfuse-dev \
68         libgit2-dev \
69         libjson-glib-dev \
70         libguestfs-tools \
71         libgnutls28-dev \
72         libgnutls30 \
73         liblz4-tool \
74         libpixman-1-dev \
75         libpython3-dev \
76         libsdl1.2-dev \
77         libsdl2-dev \
78         libseccomp-dev \
79         libssl-dev \
80         libtool \
81         libudev-dev \
82         libusb-1.0-0-dev \
83         linux-image-kvm \
84         lzma-alone \
85         lzop \
86         mount \
87         mtd-utils \
88         mtools \
89         net-tools \
90         ninja-build \
91         openssl \
92         picocom \
93         parted \
94         pkg-config \
95         python-is-python3 \
96         python2.7 \
97         python3 \
98         python3-dev \
99         python3-pip \
100         python3-sphinx \
101         python3-virtualenv \
102         rpm2cpio \
103         sbsigntool \
104         sloccount \
105         socat \
106         softhsm2 \
107         sparse \
108         srecord \
109         sudo \
110         swig \
111         util-linux \
112         uuid-dev \
113         virtualenv \
114         xxd \
115         zip \
116         && rm -rf /var/lib/apt/lists/*
117
118 # Make kernels readable for libguestfs tools to work correctly
119 RUN chmod +r /boot/vmlinu*
120
121 # Build GRUB UEFI targets for ARM & RISC-V, 32-bit and 64-bit
122 RUN git clone git://git.savannah.gnu.org/grub.git /tmp/grub && \
123         cd /tmp/grub && \
124         git checkout grub-2.06 && \
125         ./bootstrap && \
126         mkdir -p /opt/grub && \
127         ./configure --target=aarch64 --with-platform=efi \
128         CC=gcc \
129         TARGET_CC=/opt/gcc-11.1.0-nolibc/aarch64-linux/bin/aarch64-linux-gcc \
130         TARGET_OBJCOPY=/opt/gcc-11.1.0-nolibc/aarch64-linux/bin/aarch64-linux-objcopy \
131         TARGET_STRIP=/opt/gcc-11.1.0-nolibc/aarch64-linux/bin/aarch64-linux-strip \
132         TARGET_NM=/opt/gcc-11.1.0-nolibc/aarch64-linux/bin/aarch64-linux-nm \
133         TARGET_RANLIB=/opt/gcc-11.1.0-nolibc/aarch64-linux/bin/aarch64-linux-ranlib && \
134         make && \
135         ./grub-mkimage -O arm64-efi -o /opt/grub/grubaa64.efi --prefix= -d \
136         grub-core cat chain configfile echo efinet ext2 fat halt help linux \
137         lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \
138         search search_fs_file search_fs_uuid search_label serial sleep test \
139         true && \
140         make clean && \
141         ./configure --target=arm --with-platform=efi \
142         CC=gcc \
143         TARGET_CC=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc \
144         TARGET_OBJCOPY=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-objcopy \
145         TARGET_STRIP=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-strip \
146         TARGET_NM=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-nm \
147         TARGET_RANLIB=/opt/gcc-11.1.0-nolibc/arm-linux-gnueabi/bin/arm-linux-gnueabi-ranlib && \
148         make && \
149         ./grub-mkimage -O arm-efi -o /opt/grub/grubarm.efi --prefix= -d \
150         grub-core cat chain configfile echo efinet ext2 fat halt help linux \
151         lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \
152         search search_fs_file search_fs_uuid search_label serial sleep test \
153         true && \
154         make clean && \
155         ./configure --target=riscv64 --with-platform=efi \
156         CC=gcc \
157         TARGET_CC=/opt/gcc-11.1.0-nolibc/riscv64-linux/bin/riscv64-linux-gcc \
158         TARGET_OBJCOPY=/opt/gcc-11.1.0-nolibc/riscv64-linux/bin/riscv64-linux-objcopy \
159         TARGET_STRIP=/opt/gcc-11.1.0-nolibc/riscv64-linux/bin/riscv64-linux-strip \
160         TARGET_NM=/opt/gcc-11.1.0-nolibc/riscv64-linux/bin/riscv64-linux-nm \
161         TARGET_RANLIB=/opt/gcc-11.1.0-nolibc/riscv64-linux/bin/riscv64-linux-ranlib && \
162         make && \
163         ./grub-mkimage -O riscv64-efi -o /opt/grub/grubriscv64.efi --prefix= -d \
164         grub-core cat chain configfile echo efinet ext2 fat halt help linux \
165         lsefisystab loadenv lvm minicmd normal part_msdos part_gpt reboot \
166         search search_fs_file search_fs_uuid search_label serial sleep test \
167         true && \
168         rm -rf /tmp/grub
169
170 RUN git clone git://git.qemu.org/qemu.git /tmp/qemu && \
171         cd /tmp/qemu && \
172         git submodule update --init dtc && \
173         git checkout v6.1.0 && \
174         # config user.name and user.email to make 'git am' happy
175         git config user.name u-boot && \
176         git config user.email u-boot@denx.de && \
177         # manually apply the bug fix for QEMU 6.1.0 Xilinx Zynq UART emulation codes
178         wget -O - http://patchwork.ozlabs.org/project/qemu-devel/patch/20210823020813.25192-2-bmeng.cn@gmail.com/mbox/ | git am && \
179         ./configure --prefix=/opt/qemu --target-list="aarch64-softmmu,arm-softmmu,i386-softmmu,mips-softmmu,mips64-softmmu,mips64el-softmmu,mipsel-softmmu,ppc-softmmu,riscv32-softmmu,riscv64-softmmu,sh4-softmmu,x86_64-softmmu,xtensa-softmmu" && \
180         make -j$(nproc) all install && \
181         rm -rf /tmp/qemu
182
183 # Build genimage (required by some targets to generate disk images)
184 RUN wget -O - https://github.com/pengutronix/genimage/releases/download/v14/genimage-14.tar.xz | tar -C /tmp -xJ && \
185         cd /tmp/genimage-14 && \
186         ./configure && \
187         make -j$(nproc) && \
188         make install && \
189         rm -rf /tmp/genimage-14
190
191 # Build libtpms
192 RUN git clone https://github.com/stefanberger/libtpms /tmp/libtpms && \
193         cd /tmp/libtpms && \
194         ./autogen.sh && \
195         ./configure && \
196         make -j$(nproc) && \
197         make install && \
198         ldconfig && \
199         rm -rf /tmp/libtpms
200
201 # Build swtpm
202 RUN git clone https://github.com/stefanberger/swtpm /tmp/swtpm && \
203         cd /tmp/swtpm && \
204         ./autogen.sh && \
205         ./configure && \
206         make -j$(nproc) && \
207         make install && \
208         rm -rf /tmp/swtpm
209
210 # Create our user/group
211 RUN echo uboot ALL=NOPASSWD: ALL > /etc/sudoers.d/uboot
212 RUN useradd -m -U uboot
213 USER uboot:uboot
214
215 # Create the buildman config file
216 RUN /bin/echo -e "[toolchain]\nroot = /usr" > ~/.buildman
217 RUN /bin/echo -e "kernelorg = /opt/gcc-11.1.0-nolibc/*" >> ~/.buildman
218 RUN /bin/echo -e "arc = /opt/arc_gnu_2021.03_prebuilt_uclibc_le_archs_linux_install" >> ~/.buildman
219 RUN /bin/echo -e "\n[toolchain-prefix]\nxtensa = /opt/2020.07/xtensa-dc233c-elf/bin/xtensa-dc233c-elf-" >> ~/.buildman;
220 RUN /bin/echo -e "\n[toolchain-alias]\nsh = sh2" >> ~/.buildman
221 RUN /bin/echo -e "\nsandbox = x86_64" >> ~/.buildman
222 RUN /bin/echo -e "\nx86 = i386" >> ~/.buildman;