Skip to content

Commit 73aa02f

Browse files
authored
Merge pull request #1284 from NickeZ/nickez/support-arm64-in-docker
Nickez/support arm64 in docker
2 parents 062b450 + 7ba38b1 commit 73aa02f

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

.containerversion

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

CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,12 @@ string(APPEND CMAKE_C_FLAGS " -Wno-cast-function-type")
328328

329329
# Hardening
330330
string(APPEND CMAKE_C_FLAGS " -fstack-protector-all")
331+
if(CMAKE_CROSSCOMPILING)
332+
# Path to empty dummy libssp and libssp_shared. '-llibssp -llibssp_shared' is automatically added
333+
# with '-fstack-protector-all', but we don't need them as we have our own custom
334+
# `__stack_chk_fail`. See https://wiki.osdev.org/Stack_Smashing_Protector.
335+
set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -L${CMAKE_CURRENT_SOURCE_DIR}/external/lib/ssp")
336+
endif()
331337

332338
# Disallow duplicate definitions, which is the default since GCC
333339
# 10. It was not default in gcc-arm-none-eabi-8-2018-q4.

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:

external/asf4-drivers/hal/utils/include/utils_assert.h

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
#ifndef _ASSERT_H_INCLUDED
4545
#define _ASSERT_H_INCLUDED
4646

47+
#undef assert
48+
4749
#ifdef __cplusplus
4850
extern "C" {
4951
#endif

releases/build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ fi
3535

3636

3737
# Build the Docker image (this can take a while):
38-
docker build --pull --force-rm --no-cache -t bitbox02-firmware .
38+
# - The firmware is only reproducible with the same host compiler. For now we force linux/amd64.
39+
docker build --pull --platform linux/amd64 --force-rm --no-cache -t bitbox02-firmware .
3940

4041
# Revert the above local patch to the Dockerfile again to have a clean state.
4142
git checkout -- Dockerfile

0 commit comments

Comments
 (0)