From 0713984ac0b94b1448faccaa6a40543ad025eb09 Mon Sep 17 00:00:00 2001 From: xumia Date: Wed, 11 Aug 2021 06:58:49 +0000 Subject: [PATCH] Support to build armhf/arm64 platforms on arm based system --- .azure-pipelines/azure-pipelines-build.yml | 1 - Makefile.work | 9 +++++---- dockers/docker-base-buster/Dockerfile.j2 | 2 +- dockers/docker-base-stretch/Dockerfile.j2 | 2 +- dockers/docker-base/Dockerfile.j2 | 2 +- slave.mk | 9 +++++++++ 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.azure-pipelines/azure-pipelines-build.yml b/.azure-pipelines/azure-pipelines-build.yml index eb3c3aa21bb8..1610843b9200 100644 --- a/.azure-pipelines/azure-pipelines-build.yml +++ b/.azure-pipelines/azure-pipelines-build.yml @@ -78,7 +78,6 @@ jobs: dbg_image: yes - name: marvell-armhf - pool: sonicbld_8c timeoutInMinutes: 2880 variables: PLATFORM_ARCH: armhf diff --git a/Makefile.work b/Makefile.work index 4a59067434fd..cfcf803329ab 100644 --- a/Makefile.work +++ b/Makefile.work @@ -47,12 +47,13 @@ SHELL = /bin/bash USER := $(shell id -un) PWD := $(shell pwd) USER_LC := $(shell echo $(USER) | tr A-Z a-z) +DOCKER_MACHINE := $(shell docker run --rm debian:buster uname -m) comma := , -ifeq ($(shell uname -m), aarch64) +ifeq ($(DOCKER_MACHINE), aarch64) COMPILE_HOST_ARCH := arm64 -else ifeq ($(shell uname -m), armv7l) +else ifeq ($(shell echo $(DOCKER_MACHINE) | grep -qE "armv7l|armv8l" && echo y),y) COMPILE_HOST_ARCH := armhf else COMPILE_HOST_ARCH := amd64 @@ -286,7 +287,7 @@ SONIC_BUILD_INSTRUCTION := make \ .DEFAULT_GOAL := all %:: -ifneq (,$(filter $(CONFIGURED_ARCH), armhf arm64)) +ifeq ($(MULTIARCH_QEMU_ENVIRON), y) @$(DOCKER_MULTIARCH_CHECK) ifneq ($(BLDENV), ) @$(DOCKER_SERVICE_MULTIARCH_CHECK) @@ -361,7 +362,7 @@ reset : if [ $$ans == y ]; then echo "Resetting local repository. Please wait..."; $(DOCKER_RUN) $(SLAVE_IMAGE):$(SLAVE_TAG) sudo rm -rf fsroot; - if [[ "$(CONFIGURED_ARCH)" == "armhf" || "$(CONFIGURED_ARCH)" == "arm64" ]]; then + if [ "$(MULTIARCH_QEMU_ENVIRON)" == y ] && [[ "$(CONFIGURED_ARCH)" == "armhf" || "$(CONFIGURED_ARCH)" == "arm64" ]]; then echo "Stopping march $(CONFIGURED_ARCH) docker" sudo kill -9 `sudo cat /var/run/march/docker.pid` || true sudo rm -f /var/run/march/docker.pid || true diff --git a/dockers/docker-base-buster/Dockerfile.j2 b/dockers/docker-base-buster/Dockerfile.j2 index a87ca31c6073..ac3fd7743e77 100644 --- a/dockers/docker-base-buster/Dockerfile.j2 +++ b/dockers/docker-base-buster/Dockerfile.j2 @@ -4,7 +4,7 @@ FROM multiarch/debian-debootstrap:armhf-buster {% elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} FROM multiarch/debian-debootstrap:arm64-buster {% else %} -FROM debian:buster +FROM {{DOCKER_BASE_ARCH}}/debian:buster {% endif %} # Clean documentation in FROM image diff --git a/dockers/docker-base-stretch/Dockerfile.j2 b/dockers/docker-base-stretch/Dockerfile.j2 index 652dec979b60..b77814bb2820 100644 --- a/dockers/docker-base-stretch/Dockerfile.j2 +++ b/dockers/docker-base-stretch/Dockerfile.j2 @@ -4,7 +4,7 @@ FROM multiarch/debian-debootstrap:armhf-stretch {% elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} FROM multiarch/debian-debootstrap:arm64-stretch {% else %} -FROM debian:stretch +FROM {{DOCKER_BASE_ARCH}}/debian:stretch {% endif %} # Clean documentation in FROM image diff --git a/dockers/docker-base/Dockerfile.j2 b/dockers/docker-base/Dockerfile.j2 index ecdbfda11a78..616a4cde7aff 100644 --- a/dockers/docker-base/Dockerfile.j2 +++ b/dockers/docker-base/Dockerfile.j2 @@ -3,7 +3,7 @@ FROM multiarch/debian-debootstrap:armhf-jessie {% elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} FROM multiarch/debian-debootstrap:arm64-jessie {% else %} -FROM debian:jessie +FROM {{DOCKER_BASE_ARCH}}/debian:jessie {% endif %} ## Remove retired jessie-updates repo diff --git a/slave.mk b/slave.mk index 655196f69ae0..ea0ffba90d88 100644 --- a/slave.mk +++ b/slave.mk @@ -51,6 +51,14 @@ CONFIGURED_ARCH := $(shell [ -f .arch ] && cat .arch || echo amd64) ifeq ($(PLATFORM_ARCH),) override PLATFORM_ARCH = $(CONFIGURED_ARCH) endif +DOCKER_BASE_ARCH := $(CONFIGURED_ARCH) +ifeq ($(CONFIGURED_ARCH),armhf) + override DOCKER_BASE_ARCH = arm32v7 +else +ifeq ($(CONFIGURED_ARCH),arm64) + override DOCKER_BASE_ARCH = arm64v8 +endif +endif ifeq ($(BLDENV),bullseye) IMAGE_DISTRO := bullseye else @@ -68,6 +76,7 @@ export PYTHON_WHEELS_PATH export IMAGE_DISTRO export IMAGE_DISTRO_DEBS_PATH export MULTIARCH_QEMU_ENVIRON +export DOCKER_BASE_ARCH ############################################################################### ## Utility rules