From 2c45932aa0a35a21d98342c233b2f68f054ff28c Mon Sep 17 00:00:00 2001 From: leoli Date: Wed, 21 Feb 2024 15:24:00 +0800 Subject: [PATCH] build: add Docker support for building the firmware --- Makefile | 29 ++++++++++++++++++++++++++++- README_.md | 6 ++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a5a4340..8d044c3 100644 --- a/Makefile +++ b/Makefile @@ -230,6 +230,30 @@ $(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR) $(BUILD_DIR): mkdir $@ +####################################### +# docker build +####################################### +docker: +ifeq ($(OS),Windows_NT) + @powershell -Command "$$IMAGE_NAME='jafee201153/arm-none-eabi-gcc:13.2.Rel1-ubuntu-20.04'; \ + $$DOCKER_RUN='docker run -it --rm -v $${PWD}:/share $$IMAGE_NAME'; \ + $$imageExists = docker images -q $$IMAGE_NAME; \ + if (-not $$imageExists) { \ + Write-Host 'Image $$IMAGE_NAME not found locally, pulling...'; \ + docker pull $$IMAGE_NAME; \ + }; \ + $$DOCKER_CMD = $$DOCKER_RUN + ' sh -c \"cd /share && make clean && make\"'; \ + Invoke-Expression $$DOCKER_CMD" +else + @IMAGE_NAME="jafee201153/arm-none-eabi-gcc:13.2.Rel1-ubuntu-20.04"; \ + DOCKER_RUN="docker run -it --rm -v $${PWD}:/share $$IMAGE_NAME"; \ + if [ -z "$$(docker images -q $$IMAGE_NAME)" ]; then \ + echo "Image $$IMAGE_NAME not found locally, pulling..."; \ + docker pull $$IMAGE_NAME; \ + fi; \ + $$DOCKER_RUN sh -c "cd /share && make clean && make" +endif + ####################################### # clean up ####################################### @@ -256,8 +280,11 @@ rebuild: clean all ####################################### # upgrade ####################################### -upgrade: +update: git submodule update --init --recursive + +upgrade: + make update # ifeq ($(OS),Windows_NT) # copy $(subst /,\,$(CURDIR))\assets\utility_config.h $(subst /,\,$(CURDIR))\Source\UtilityClang\utility_config.h # else diff --git a/README_.md b/README_.md index 44cf0c9..2bc6ddd 100644 --- a/README_.md +++ b/README_.md @@ -26,6 +26,12 @@ To build the firmware using Makefile, run: make clean && make ``` +or build the firmware using Docker: + +``` bash +make update && make docker +``` + ## Flashing the Firmware We use [pyOCD](https://pypi.org/project/pyocd/) for cross-platform