1#
2# Arm SCP/MCP Software
3# Copyright (c) 2021-2024, Arm Limited and Contributors. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8FROM ubuntu:20.04@sha256:9fa30fcef427e5e88c76bc41ad37b7cc573e1d79cecb23035e413c4be6e476ab AS common
9
10ARG ARM_NONE_EABI_VERSION="10.3-2021.10"
11ARG AARCH64_NONE_ELF_VERSION="9.2-2019.12"
12ARG CMAKE_VERSION="3.25.2"
13ARG LLVM_VERSION="13"
14ARG CPPCHECK_VERSION="2.8"
15ARG DOXYGEN_VERSION="1.8.13"
16
17ENV DEBIAN_FRONTEND=noninteractive
18
19RUN apt-get update && \
20    apt-get dist-upgrade -y && \
21    apt-get install -y --no-install-recommends \
22        gcc \
23        g++ \
24        git \
25        make \
26        ninja-build \
27        python-is-python3 \
28        python3 \
29        python3-pip \
30        software-properties-common \
31        wget \
32        xz-utils && \
33    python3 -m pip install --upgrade pip
34
35ENV DEBIAN_FRONTEND=
36
37# Install GCC arm-none-eabi
38FROM common AS arm-none-eabi
39COPY docker/installer-scripts/install-gcc-arm-none-eabi.sh \
40    /tmp
41RUN bash /tmp/install-gcc-arm-none-eabi.sh /opt/arm-none-eabi \
42    "${ARM_NONE_EABI_VERSION}"
43
44
45
46# Install GCC aarch64-none-elf
47FROM common AS aarch64-none-elf
48COPY docker/installer-scripts/install-gcc-aarch64-none-elf.sh \
49    /tmp
50RUN bash /tmp/install-gcc-aarch64-none-elf.sh /opt/aarch64-none-elf \
51    "${AARCH64_NONE_ELF_VERSION}";
52
53
54# Install CMake, it needs to be installed before LLVM and cppcheck
55FROM common AS cmake
56COPY docker/installer-scripts/install-cmake.sh /tmp
57RUN bash /tmp/install-cmake.sh /opt/cmake ${CMAKE_VERSION};
58ENV PATH="${PATH}:/opt/cmake/bin"
59
60
61# Install LLVM compiler and build libclang_rt.builtins
62FROM common AS llvm
63COPY --from=arm-none-eabi /opt/arm-none-eabi /opt/arm-none-eabi
64COPY --from=cmake /opt/cmake /opt/cmake
65ENV PATH="${PATH}:/opt/arm-none-eabi/bin"
66ENV PATH="${PATH}:/opt/cmake/bin"
67COPY docker/installer-scripts/install-llvm.sh /tmp
68RUN bash /tmp/install-llvm.sh "${LLVM_VERSION}"
69
70
71# Build and install cppcheck tool
72FROM cmake AS cppcheck
73COPY docker/installer-scripts/install-cppcheck.sh /tmp
74RUN bash /tmp/install-cppcheck.sh /opt/cppcheck "${CPPCHECK_VERSION}"
75
76
77# Install Doxygen tool
78FROM cmake AS doxygen
79COPY docker/installer-scripts/install-doxygen.sh /tmp
80RUN bash /tmp/install-doxygen.sh /opt/doxygen "${DOXYGEN_VERSION}"
81
82
83FROM llvm AS ci
84ENV ARMLMD_LICENSE_FILE=
85ENV LM_LICENSE_FILE=
86
87VOLUME "/opt/arm-compiler-6"
88ENV PATH="${PATH}:/opt/arm-compiler-6/bin"
89
90COPY --from=arm-none-eabi /opt/arm-none-eabi /opt/arm-none-eabi
91COPY --from=aarch64-none-elf /opt/aarch64-none-elf /opt/aarch64-none-elf
92COPY --from=cmake /opt/cmake /opt/cmake
93COPY --from=cppcheck /opt/cppcheck /opt/cppcheck
94COPY --from=doxygen /opt/doxygen/source/build/bin/ /opt/doxygen/bin
95ENV PATH="${PATH}:/opt/arm-none-eabi/bin"
96ENV PATH="${PATH}:/opt/aarch64-none-elf/bin"
97ENV PATH="${PATH}:/opt/cmake/bin"
98ENV PATH="${PATH}:/opt/cppcheck/bin"
99ENV PATH="${PATH}:/opt/doxygen/bin"
100
101ENV DEBIAN_FRONTEND=noninteractive
102
103RUN apt-get update && \
104    apt-get install -y --no-install-recommends \
105        bundler \
106        bzip2 \
107        gpg-agent \
108        gosu \
109        lsb-release \
110        lcov && \
111    gem install bundler -v 2.4.22
112
113ENV DEBIAN_FRONTEND=
114
115# Install SCP-Firmware requirements
116COPY requirements.txt .
117RUN PIP_ROOT_USER_ACTION=ignore \
118    python3 -m pip install --ignore-installed  -r requirements.txt
119
120ENTRYPOINT ["sh"]
121
122
123FROM ci as user
124
125ENV DEBIAN_FRONTEND=noninteractive
126
127RUN apt-get update && \
128    apt-get dist-upgrade -y && \
129    apt-get install -y --no-install-recommends nano sudo
130
131ENV DEBIAN_FRONTEND=
132
133COPY "docker/rootfs/usr/local/bin/init" "/usr/local/bin/init"
134RUN chmod +x /usr/local/bin/init
135
136
137FROM user as dev
138
139VOLUME /scp-firmware
140WORKDIR /scp-firmware
141
142ARG USER_UID=1000
143ARG USER_GID=1000
144ARG USERNAME=user
145
146RUN groupadd -g ${USER_GID} ${USERNAME} || true && \
147    useradd -l -u ${USER_UID} -g ${USERNAME} -m ${USERNAME} || true && \
148    usermod -aG sudo ${USERNAME} && \
149    echo "$USERNAME ALL=(root) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME && \
150    chmod 0400 /etc/sudoers.d/$USERNAME
151
152ENV NOTVISIBLE="in users profile"
153RUN echo "export VISIBLE=now" >> "/etc/profile"
154
155RUN echo "\nexport USER=${USERNAME}" >> "/home/${USERNAME}/.bashrc"
156ENV PATH="/home/${USERNAME}/.local/bin:${PATH}"
157
158ENTRYPOINT [ "bash", "/usr/local/bin/init" ]
159
160
161FROM user as vagrant
162
163VOLUME /vagrant
164WORKDIR /vagrant
165
166# Set a default username argument (vagrant by default)
167ARG USERNAME=vagrant
168
169# Update package lists and install necessary packages
170
171ENV DEBIAN_FRONTEND=noninteractive
172
173RUN apt-get update && \
174    apt-get install -y \
175    sudo \
176    openssh-server
177
178ENV DEBIAN_FRONTEND=
179
180
181# Create the user and set up SSH access
182RUN adduser --disabled-password --gecos "" $USERNAME && \
183    usermod -aG sudo $USERNAME && \
184    passwd -d vagrant && \
185    mkdir -p "/home/$USERNAME/.ssh" && \
186    chmod 700 "/home/$USERNAME/.ssh"
187
188# Copy the authorized keys file
189COPY docker/rootfs/home/$USERNAME/.ssh/authorized_keys \
190    /home/$USERNAME/.ssh/authorized_keys
191
192# Set proper permissions for the authorized keys file
193RUN chmod 600 "/home/$USERNAME/.ssh/authorized_keys" && \
194    chown -R $USERNAME:$USERNAME "/home/$USERNAME/.ssh"
195
196# Set environment variables
197ENV NOTVISIBLE="in users profile" \
198    PATH="/home/$USERNAME/.local/bin:${PATH}"
199
200# Add configuration to make the environment visible
201RUN echo "export VISIBLE=now" >> "/etc/profile" && \
202    printf "\nAcceptEnv ARMLMD_LICENSE_FILE" >> "/etc/ssh/sshd_config" && \
203    printf "\ncd /$USERNAME" >> "/home/$USERNAME/.bashrc"
204
205# Expose SSH port
206EXPOSE 22
207
208# Set entrypoint to initialize services
209ENTRYPOINT [ "bash", "/usr/local/bin/init" ]
210