From 2a32f788f353b277c98146f68de25ebe2c03fd97 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Tue, 1 Apr 2025 23:50:05 +0200 Subject: [PATCH] docker: Fix build. Signed-off-by: iabdalkader --- docker/Dockerfile | 49 +++++++++++++++++++++++++++++++---------------- docker/Makefile | 35 +++++++++++++++++++++++---------- docker/README.md | 2 +- docker/build.sh | 16 ++++++++-------- src/Makefile | 3 +++ 5 files changed, 69 insertions(+), 36 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 3d398f3ed..236d44890 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,23 +1,38 @@ -FROM ubuntu:22.04 AS dapper -ARG DAPPER_HOST_ARCH -ENV DAPPER_ENV TARGET -ENV ARCH $DAPPER_HOST_ARCH -ENV DAPPER_OUTPUT ./docker/build -ENV DAPPER_DOCKER_SOCKET true -ENV DAPPER_TARGET dapper -RUN apt update && apt install -y build-essential wget git python3 python-is-python3 +FROM ubuntu:24.04 -RUN mkdir -p /source/gcc -ENV GCC_URL="https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz" -RUN wget --no-check-certificate -O - ${GCC_URL} | tar --strip-components=1 -Jx -C /source/gcc +# Install dependencies +RUN apt update && apt install -y \ + build-essential \ + wget \ + git \ + python3 \ + python-is-python3 -RUN mkdir -p /source/llvm +# Download and extract GCC +RUN mkdir -p /workspace/gcc +ENV GCC_URL="https://developer.arm.com/-/media/Files/downloads/gnu/13.2.rel1/binrel/arm-gnu-toolchain-13.2.rel1-x86_64-arm-none-eabi.tar.xz" +RUN wget --no-check-certificate -O - ${GCC_URL} | tar --strip-components=1 -Jx -C /workspace/gcc + +# Download and extract LLVM +RUN mkdir -p /workspace/llvm ENV LLVM_URL="https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/releases/download/release-18.1.3/LLVM-ET-Arm-18.1.3-Linux-x86_64.tar.xz" -RUN wget --no-check-certificate -O - ${LLVM_URL} | tar --strip-components=1 -Jx -C /source/llvm +RUN wget --no-check-certificate -O - ${LLVM_URL} | tar --strip-components=1 -Jx -C /workspace/llvm -RUN mkdir -p /source/cmake +# Download and extract CMake +RUN mkdir -p /workspace/cmake ENV CMAKE_URL="https://github.com/Kitware/CMake/releases/download/v3.30.2/cmake-3.30.2.tar.gz" -RUN wget --no-check-certificate -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C /source/cmake +RUN wget --no-check-certificate -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C /workspace/cmake -WORKDIR /source -ENTRYPOINT ["./docker/build.sh"] +# Download, build, and install Make +RUN mkdir -p /workspace/make +ENV MAKE_URL="https://ftp.gnu.org/gnu/make/make-4.4.1.tar.gz" +RUN wget --no-check-certificate -O - ${MAKE_URL} | tar --strip-components=1 -xz -C /workspace/make +RUN cd /workspace/make && ./configure && make -j$(nproc) + +# Set up directories +WORKDIR /workspace + +COPY . . + +RUN git config --global --add safe.directory '*' +ENV PATH="/workspace/gcc/bin:/workspace/llvm/bin:/workspace/cmake/bin:/workspace/make:$PATH" diff --git a/docker/Makefile b/docker/Makefile index a67c559eb..84371aa18 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -1,12 +1,27 @@ -.PHONY: default -default: in-docker-build +DOCKER_IMAGE_NAME = firmware-builder +DOCKER_TAG = latest +CONTAINER_NAME = firmware-container +DOCKERFILE_PATH = Dockerfile -./.dapper: - @echo Downloading dapper - @curl -sL https://releases.rancher.com/dapper/v0.5.0/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp - @@chmod +x .dapper.tmp - @./.dapper.tmp -v - @mv .dapper.tmp .dapper +# Build the Docker image +build-image: + docker build \ + -t $(DOCKER_IMAGE_NAME):$(DOCKER_TAG) \ + -f $(DOCKERFILE_PATH) ../ -in-docker-build: .dapper - ./.dapper -C ../ -f docker/Dockerfile --target dapper make +# Run the container with a volume mount to build the firmware +build-firmware: build-image + docker run --rm \ + -e TARGET=$(TARGET) \ + -v $(PWD)/build:/workspace/build \ + --name $(CONTAINER_NAME) \ + $(DOCKER_IMAGE_NAME):$(DOCKER_TAG) docker/build.sh + +# Run an interactive shell in the container +shell: + docker run --rm -it \ + -e shell="true" \ + -v $(PWD)/build:/workspace/build \ + $(DOCKER_IMAGE_NAME):$(DOCKER_TAG) bash + +.DEFAULT_GOAL := build-firmware diff --git a/docker/README.md b/docker/README.md index e643f3fce..12983323a 100644 --- a/docker/README.md +++ b/docker/README.md @@ -3,7 +3,7 @@ To build the firmware using docker, follow the following steps: ``` -git clone https://github.com/openmv/openmv.git --depth=50 +git clone https://github.com/openmv/openmv.git --depth=1 cd openmv/docker make TARGET= ``` diff --git a/docker/build.sh b/docker/build.sh index b11508d23..dba10fac9 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -1,15 +1,15 @@ #!/bin/bash set -e -x -cd $(dirname $0)/.. - - -export PATH=/source/gcc/bin:/source/cmake/bin:$PATH +git config --global --add safe.directory '*' git submodule update --init --depth=1 -git -C src/lib/micropython/ submodule update --init --depth=1 +make -C src -j$(nproc) TARGET=$TARGET submodules # Build the firmware. +make -j$(nproc) -C src clean make -j$(nproc) -C src/lib/micropython/mpy-cross -make -j$(nproc) TARGET=$TARGET LLVM_PATH=/source/llvm/bin -C src -mkdir -p ./docker/build/$TARGET -cp -r src/build/bin/* ./docker/build/$TARGET +make -j$(nproc) -C src TARGET=$TARGET LLVM_PATH=/workspace/llvm/bin + +rm -fr /workspace/build/$TARGET +mkdir -p /workspace/build/$TARGET +cp -r src/build/bin/* /workspace/build/$TARGET diff --git a/src/Makefile b/src/Makefile index 81a2e1932..c7cb115a9 100755 --- a/src/Makefile +++ b/src/Makefile @@ -225,3 +225,6 @@ jlink: ${JLINK_GDB_SERVER} -speed ${JLINK_SPEED} -nogui 1 \ -if ${JLINK_INTERFACE} -halt -cpu cortex-m \ -device ${JLINK_DEVICE} -novd ${JLINK_SCRIPT} + +submodules: + $(MAKE) -C $(MICROPY_DIR)/ports/$(PORT) BOARD=$(TARGET) submodules