From 12ae89839b4d8ef51bb37ab33f82be3bc839c822 Mon Sep 17 00:00:00 2001 From: Ivan-Velickovic Date: Thu, 8 Jun 2023 16:40:39 +1000 Subject: [PATCH] WIP of AArch64 container Building seL4 projects and CAmkES projects should work now. The l4v container is not tested. --- Makefile | 16 +++++++++++++--- build.sh | 14 ++++++++++++-- scripts/camkes.sh | 9 ++++++--- scripts/sel4.sh | 16 +++++++++++++--- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 064be58..bde6960 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,17 @@ endif ETC_LOCALTIME := $(realpath /etc/localtime) +HOST_ARCH := $(shell arch) +ifeq ($(HOST_ARCH),x86_64) + DOCKER_PLATFORM := "linux/amd64" +else ifeq ($(HOST_ARCH),arm64) + # We assume ARMv8 as the platform + DOCKER_PLATFORM := "linux/arm64/v8" +else + @echo "Unsupported host architecture: $HOST_ARCH" + @exit 1 +endif + # Extra arguments to pass to `docker run` if it is or is not `podman` - these # are constructed in a very verbose way to be obvious about why we want to do # certain things under regular `docker` vs` podman` @@ -136,7 +147,6 @@ user_run: --group-add sudo \ -v $(HOST_DIR):/host:z \ -v $(DOCKER_VOLUME_HOME):/home/$(shell whoami) \ - -v $(ETC_LOCALTIME):/etc/localtime:ro \ $(USER_IMG) $(EXEC) .PHONY: user_run_l4v @@ -171,12 +181,12 @@ endif .PHONY: build_user build_user: run_checks - $(DOCKER_BUILD) $(DOCKER_FLAGS) \ + $(DOCKER_BUILD) --platform $(DOCKER_PLATFORM) $(DOCKER_FLAGS) \ --build-arg=USER_BASE_IMG=$(DOCKERHUB)$(USER_BASE_IMG) \ -f dockerfiles/extras.Dockerfile \ -t $(EXTRAS_IMG) \ . - $(DOCKER_BUILD) $(DOCKER_FLAGS) \ + $(DOCKER_BUILD) --platform $(DOCKER_PLATFORM) $(DOCKER_FLAGS) \ --build-arg=EXTRAS_IMG=$(EXTRAS_IMG) \ --build-arg=UNAME=$(shell whoami) \ --build-arg=UID=$(shell id -u) \ diff --git a/build.sh b/build.sh index 6a087de..bf89d38 100755 --- a/build.sh +++ b/build.sh @@ -35,6 +35,16 @@ set -ef DOCKER_BUILD="docker build" DOCKER_FLAGS="--force-rm=true" +HOST_ARCH=`arch` +if [[ $HOST_ARCH == "x86_64" ]]; then + DOCKER_PLATFORM="linux/amd64" +elif [[ $HOST_ARCH == "arm64" ]]; then + DOCKER_PLATFORM="linux/arm64/v8" +else + echo "Unsupported host architecture: $HOST_ARCH" + exit 1 +fi + # Special variables to be passed through Docker to the build scripts : "${SCM}" @@ -61,7 +71,7 @@ build_internal_image() build_args_to_pass_to_docker=$(echo "$build_args" | grep "=" | awk '{print "--build-arg", $1}') # shellcheck disable=SC2086 - $DOCKER_BUILD $DOCKER_FLAGS \ + $DOCKER_BUILD --platform $DOCKER_PLATFORM $DOCKER_FLAGS \ --build-arg BASE_IMG="$base_img" \ --build-arg SCM="$SCM" \ $build_args_to_pass_to_docker \ @@ -91,7 +101,7 @@ apply_software_to_image() # NOTE: it's OK to supply docker build-args that aren't requested in the Dockerfile - $DOCKER_BUILD $DOCKER_FLAGS \ + $DOCKER_BUILD --platform $DOCKER_PLATFORM $DOCKER_FLAGS \ --build-arg BASE_BUILDER_IMG="$DOCKERHUB$prebuilt_img" \ --build-arg BASE_IMG="$DOCKERHUB$orig_img" \ --build-arg SCM="$SCM" \ diff --git a/scripts/camkes.sh b/scripts/camkes.sh index fd41a24..62777c3 100644 --- a/scripts/camkes.sh +++ b/scripts/camkes.sh @@ -35,6 +35,7 @@ possibly_toggle_apt_snapshot # Get dependencies as_root dpkg --add-architecture i386 +as_root dpkg --add-architecture arm64 as_root apt-get update -q as_root apt-get install -y --no-install-recommends \ acl \ @@ -43,7 +44,6 @@ as_root apt-get install -y --no-install-recommends \ linux-libc-dev:i386 \ pkg-config \ spin \ - lib32stdc++-10-dev \ # end of list # Required for testing @@ -84,8 +84,11 @@ as_root pip3 install --no-cache-dir \ # end of list # Get stack -wget -O - https://get.haskellstack.org/ | sh -echo "export PATH=\"\$PATH:\$HOME/.local/bin\"" >> "$HOME/.bashrc" +curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \ + BOOTSTRAP_HASKELL_GHC_VERSION=latest \ + BOOTSTRAP_HASKELL_CABAL_VERSION=latest \ + BOOTSTRAP_HASKELL_INSTALL_STACK=1 \ + BOOTSTRAP_HASKELL_ADJUST_BASHRC=P sh # Pick a random group ID, one that won't clash with common user GIDs as_root groupadd -g "$STACK_GID" stack diff --git a/scripts/sel4.sh b/scripts/sel4.sh index 737e5c9..aaf8e63 100644 --- a/scripts/sel4.sh +++ b/scripts/sel4.sh @@ -28,8 +28,11 @@ test -d "$DIR" || DIR=$PWD # Add additional architectures for cross-compiled libraries. # Install the tools required to compile seL4. as_root apt-get update -q +as_root dpkg --add-architecture amd64 +as_root dpkg --add-architecture i386 as_root dpkg --add-architecture armhf as_root dpkg --add-architecture armel +as_root dpkg --add-architecture arm64 as_root apt-get install -y --no-install-recommends \ astyle=3.1-2+b1 \ build-essential \ @@ -55,16 +58,17 @@ as_root apt-get install -y --no-install-recommends \ u-boot-tools \ clang-11 \ g++-10 \ - g++-10-aarch64-linux-gnu \ g++-10-arm-linux-gnueabi \ g++-10-arm-linux-gnueabihf \ gcc-10 \ - gcc-10-aarch64-linux-gnu \ gcc-10-arm-linux-gnueabi \ gcc-10-arm-linux-gnueabihf \ gcc-10-base \ - gcc-10-multilib \ gcc-riscv64-unknown-elf \ + gcc-10-x86-64-linux-gnu:arm64 \ + g++-10-x86-64-linux-gnu:arm64 \ + gcc-10-i686-linux-gnu:arm64 \ + g++-10-i686-linux-gnu:arm64 \ libclang-11-dev \ qemu-system-arm \ qemu-system-misc @@ -97,6 +101,12 @@ if [ "$DESKTOP_MACHINE" = "no" ] ; then gcc-${compiler_version}-arm-linux-gnueabihf \ cpp-${compiler_version}-arm-linux-gnueabihf \ g++-${compiler_version}-arm-linux-gnueabihf \ + gcc-${compiler_version}-x86-64-linux-gnu \ + cpp-${compiler_version}-x86-64-linux-gnu \ + g++-${compiler_version}-x86-64-linux-gnu \ + gcc-${compiler_version}-i686-linux-gnu \ + cpp-${compiler_version}-i686-linux-gnu \ + g++-${compiler_version}-i686-linux-gnu \ # end of list do echo ${compiler}