Skip to content

Commit 2e38134

Browse files
committed
dockerfile: Add support for linux/arm64
linux/arm64 is the default on newer macbooks with the apple cpu. The toolchain GCC 8 2018 q4 is not available for linux/arm64. So we go with the latest available, which is GCC 13.3.
1 parent 94dc4a0 commit 2e38134

File tree

3 files changed

+36
-20
lines changed

3 files changed

+36
-20
lines changed

.containerversion

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
41
1+
42

Dockerfile

+34-18
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,43 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
# Latest Ubuntu LTS
16+
# If you are building for a foreign target and you get segfaults, try the latest version of qemu
17+
# $ docker pull tonistiigi/binfmt:latest
18+
# $ docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-*
19+
# $ docker run --privileged --rm tonistiigi/binfmt --install arm64
20+
1721
FROM ubuntu:22.04
1822
ENV DEBIAN_FRONTEND noninteractive
1923

20-
RUN apt-get update && apt-get upgrade -y && apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2
24+
# These are automatically provided by docker (no need for --build-arg)
25+
ARG TARGETPLATFORM
26+
ARG TARGETARCH
27+
28+
RUN apt-get update && apt-get upgrade -y && apt-get install -y wget nano rsync curl gnupg2 jq unzip bzip2 xz-utils
2129

2230
# for clang-*-15, see https://apt.llvm.org/
2331
RUN echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
2432
echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" >> /etc/apt/sources.list && \
2533
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
2634

2735
# Install gcc8-arm-none-eabi
28-
RUN mkdir ~/Downloads &&\
29-
cd ~/Downloads &&\
30-
wget -O gcc.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2?revision=d830f9dd-cd4f-406d-8672-cca9210dd220?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,8-2018-q4-major &&\
31-
echo "fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 gcc.tar.bz2" | sha256sum -c &&\
32-
cd ~/Downloads &&\
33-
tar -xjvf gcc.tar.bz2 &&\
34-
rm -f gcc.tar.bz2 &&\
35-
cd ~/Downloads && rsync -a gcc-arm-none-eabi-8-2018-q4-major/ /usr/local/
36+
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
37+
GNU_TOOLCHAIN=https://developer.arm.com/-/media/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-aarch64-arm-none-eabi.tar.xz \
38+
GNU_TOOLCHAIN_HASH=c8824bffd057afce2259f7618254e840715f33523a3d4e4294f471208f976764 \
39+
GNU_TOOLCHAIN_FORMAT=xz; \
40+
else \
41+
GNU_TOOLCHAIN=https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2018q4/gcc-arm-none-eabi-8-2018-q4-major-linux.tar.bz2 \
42+
GNU_TOOLCHAIN_HASH=fb31fbdfe08406ece43eef5df623c0b2deb8b53e405e2c878300f7a1f303ee52 \
43+
GNU_TOOLCHAIN_FORMAT=bz2; \
44+
fi; \
45+
wget -O gcc.tar.${GNU_TOOLCHAIN_FORMAT} ${GNU_TOOLCHAIN} &&\
46+
echo "$GNU_TOOLCHAIN_HASH gcc.tar.${GNU_TOOLCHAIN_FORMAT}" | sha256sum -c &&\
47+
tar -xvf gcc.tar.${GNU_TOOLCHAIN_FORMAT} -C /usr/local --strip-components=1 &&\
48+
rm -f gcc.tar.${GNU_TOOLCHAIN_FORMAT}
3649

3750
# Tools for building
3851
RUN apt-get update && apt-get install -y \
39-
build-essential \
52+
make \
4053
llvm-18 \
4154
gcc-10 \
4255
binutils \
@@ -49,9 +62,6 @@ RUN apt-get update && apt-get install -y \
4962
libtool \
5063
pkg-config \
5164
libcmocka-dev \
52-
libc6-i386 \
53-
lib32stdc++6 \
54-
lib32z1 \
5565
libusb-1.0-0-dev \
5666
libudev-dev \
5767
libhidapi-dev
@@ -96,9 +106,15 @@ RUN python3 -m pip install --upgrade \
96106
twine==1.15.0
97107

98108
#Install protoc from release, because the version available on the repo is too old
99-
RUN mkdir -p /opt/protoc && \
100-
curl -L0 https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-x86_64.zip -o /tmp/protoc-21.2-linux-x86_64.zip && \
101-
unzip /tmp/protoc-21.2-linux-x86_64.zip -d /opt/protoc
109+
RUN if [ "${TARGETPLATFORM}" = "linux/arm64" ]; then \
110+
PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-aarch_64.zip; \
111+
else \
112+
PROTOC_URL=https://github.com/protocolbuffers/protobuf/releases/download/v21.2/protoc-21.2-linux-x86_64.zip; \
113+
fi; \
114+
mkdir -p /opt/protoc && \
115+
curl -L0 ${PROTOC_URL} -o /tmp/protoc-21.2.zip && \
116+
unzip /tmp/protoc-21.2.zip -d /opt/protoc && \
117+
rm /tmp/protoc-21.2.zip
102118
ENV PATH /opt/protoc/bin:$PATH
103119

104120
# Make Python3 the default
@@ -115,7 +131,7 @@ ENV GOPATH /opt/go
115131
ENV GOROOT /opt/go_dist/go
116132
ENV PATH $GOROOT/bin:$GOPATH/bin:$PATH
117133
RUN mkdir -p /opt/go_dist && \
118-
curl https://dl.google.com/go/go1.19.3.linux-amd64.tar.gz | tar -xz -C /opt/go_dist
134+
curl https://dl.google.com/go/go1.19.3.linux-${TARGETARCH}.tar.gz | tar -xz -C /opt/go_dist
119135

120136
# Install lcov from release (the one from the repos is too old).
121137
RUN cd /opt && wget https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz && tar -xf lcov-1.14.tar.gz

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jlink-flash-factory-setup: | build
129129
jlink-flash-firmware-semihosting: | build-semihosting
130130
JLinkExe -if SWD -device ATSAMD51J20 -speed 4000 -autoconnect 1 -CommanderScript ./build-semihosting/scripts/firmware.jlink
131131
dockerinit:
132-
./scripts/container.sh build --pull --platform linux/amd64 --force-rm --no-cache -t shiftcrypto/firmware_v2:$(shell cat .containerversion) .
132+
./scripts/container.sh build --pull --force-rm --no-cache -t shiftcrypto/firmware_v2:$(shell cat .containerversion) .
133133
dockerpull:
134134
./scripts/container.sh pull shiftcrypto/firmware_v2:$(shell cat .containerversion)
135135
dockerdev:

0 commit comments

Comments
 (0)