From 72fea76ef74c4f0ec61499034dbefe81482e5474 Mon Sep 17 00:00:00 2001 From: xumia <59720581+xumia@users.noreply.github.com> Date: Fri, 15 Apr 2022 18:00:14 +0800 Subject: [PATCH] Support to build armhf/arm64 platforms on arm based system (#7731) (#10577) Why I did it Support to build armhf/arm64 platforms on arm based system without qemu simulator. When building the armhf/arm64 on arm based system, it is not necessary to use qemu simulator. How I did it Build armhf on armhf system, or build arm64 on arm64 system, by default, qemu simulator will not be used. When building armhf on arm64, and you have enabled armhf docker, then it will build images without simulator automatically. It is based how the docker service is run. Docker base image change: For amd64, change from debian:to amd64/debian: For arm64, change from multiarch/debian-debootstrap:arm64- to arm64v8/debian: For armhf, change from multiarch/debian-debootstrap:armhf- to arm32v7/debian: See https://github.com/docker-library/official-images#architectures-other-than-amd64 The mapping relations: arm32v6 --- armel arm32v7 --- armhf arm64v8 --- arm64 Docker image armhf deprecated info: https://hub.docker.com/r/armhf/debian, using arm32v7 instead. --- 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 +++++++++ 5 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Makefile.work b/Makefile.work index e750c945d8d4..ffb9c8dc5e4b 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 @@ -288,7 +289,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) @@ -363,7 +364,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 a3c61931cd93..e16a0f677b07 100644 --- a/dockers/docker-base-buster/Dockerfile.j2 +++ b/dockers/docker-base-buster/Dockerfile.j2 @@ -5,7 +5,7 @@ FROM {{ prefix }}multiarch/debian-debootstrap:armhf-buster {% elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} FROM {{ prefix }}multiarch/debian-debootstrap:arm64-buster {% else %} -FROM {{ prefix }}debian:buster +FROM {{ prefix }}{{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 c2149ba59bf0..5603dc502792 100644 --- a/dockers/docker-base-stretch/Dockerfile.j2 +++ b/dockers/docker-base-stretch/Dockerfile.j2 @@ -5,7 +5,7 @@ FROM {{ prefix }}multiarch/debian-debootstrap:armhf-stretch {% elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} FROM {{ prefix }}multiarch/debian-debootstrap:arm64-stretch {% else %} -FROM {{ prefix }}debian:stretch +FROM {{ prefix }}{{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 87a1952d5057..15df3fe8a754 100644 --- a/dockers/docker-base/Dockerfile.j2 +++ b/dockers/docker-base/Dockerfile.j2 @@ -4,7 +4,7 @@ FROM {{ prefix }}multiarch/debian-debootstrap:armhf-jessie {% elif CONFIGURED_ARCH == "arm64" and MULTIARCH_QEMU_ENVIRON == "y" %} FROM {{ prefix }}multiarch/debian-debootstrap:arm64-jessie {% else %} -FROM {{ prefix }}debian:jessie +FROM {{ prefix }}{{DOCKER_BASE_ARCH}}/debian:jessie {% endif %} ## Remove retired jessie-updates repo diff --git a/slave.mk b/slave.mk index da374a5d6f7a..9d8da353a6cf 100644 --- a/slave.mk +++ b/slave.mk @@ -49,6 +49,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 IMAGE_DISTRO := buster IMAGE_DISTRO_DEBS_PATH = $(TARGET_PATH)/debs/$(IMAGE_DISTRO) IMAGE_DISTRO_FILES_PATH = $(TARGET_PATH)/files/$(IMAGE_DISTRO) @@ -62,6 +70,7 @@ export PYTHON_WHEELS_PATH export IMAGE_DISTRO export IMAGE_DISTRO_DEBS_PATH export MULTIARCH_QEMU_ENVIRON +export DOCKER_BASE_ARCH ############################################################################### ## Utility rules