From 0f7892ccc44b14d3433ec05c867937fde58adeb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20=C5=A0tetiar?= Date: Sat, 30 Nov 2024 10:32:08 +0000 Subject: [PATCH] Add Makefile providing container based build workflow MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently it needs a lot of steps to build single firmware, so lets streamline this workflow by using container. Usage: make [all|build_container|build_firmware] Targets: all Build container and firmware build_container Build container build_firmware Build firmware help Show this help message Options: build_firmware MANIFESTS= Override default manifest files (default: all .yaml/.yml files in manifests/) Examples: # Build the container image make build_container # Build all firmware manifests make build_firmware # Build a specific firmware manifest make build_firmware MANIFESTS=manifests/nabucasa/yellow_bootloader.yaml Signed-off-by: Petr Štetiar --- Makefile | 73 ++++++++++++++++++++++++++++++++++ README.md | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..10230c30 --- /dev/null +++ b/Makefile @@ -0,0 +1,73 @@ +TOPDIR = $(shell pwd) +DOCKER_CHECK := $(shell command -v docker 2> /dev/null) +PODMAN_CHECK := $(shell command -v podman 2> /dev/null) + +ifdef PODMAN_CHECK + CONTAINER_ENGINE ?= podman +else ifdef DOCKER_CHECK + CONTAINER_ENGINE ?= docker +endif + +CONTAINER_NAME ?= silabs-firmware-builder +CONTAINER_USER_GROUP ?= $(shell id -u):$(shell id -g) + +ifeq ($(CONTAINER_ENGINE),docker) + VOLUME_OPTS= +else + VOLUME_OPTS=:z +endif + +define run_in_container + $(CONTAINER_ENGINE) \ + run --rm -it \ + --user $(CONTAINER_USER_GROUP) \ + -v $(TOPDIR):/build$(VOLUME_OPTS) \ + -v $(TOPDIR)/outputs:/outputs$(VOLUME_OPTS) \ + -v $(TOPDIR)/build_dir:/build_dir$(VOLUME_OPTS) \ + $(CONTAINER_NAME) +endef + +MANIFESTS ?= $(shell find manifests -type f \( -name "*.yaml" -o -name "*.yml" \) -print) + +all: build_container build_firmware + +help: + @echo "Usage: make [all|build_container|build_firmware]" + @echo "" + @echo "Targets:" + @echo " all Build container and firmware" + @echo " build_container Build container" + @echo " build_firmware Build firmware" + @echo " help Show this help message" + @echo "" + @echo "Options:" + @echo " build_firmware MANIFESTS= Override default manifest files (default: all .yaml/.yml files in manifests/)" + @echo "" + @echo "Examples:" + @echo " # Build the container image" + @echo " make build_container" + @echo "" + @echo " # Build all firmware manifests" + @echo " make build_firmware" + @echo "" + @echo " # Build a specific firmware manifest" + @echo " make build_firmware MANIFESTS=manifests/nabucasa/yellow_bootloader.yaml" + @echo "" + +./outputs ./build_dir: + mkdir -p $@ +ifneq ($(CONTAINER_ENGINE),docker) + $(CONTAINER_ENGINE) unshare chown -R $(shell id -u):$(shell id -g) $@ +endif + +build_container: + $(CONTAINER_ENGINE) build -t $(CONTAINER_NAME) . + +build_firmware: ./outputs ./build_dir + $(run_in_container) \ + bash -c " \ + build_firmware.sh \ + --build-dir /build_dir \ + --output-dir /outputs \ + $(foreach manifest,$(MANIFESTS),--manifest $(manifest)) \ + " diff --git a/README.md b/README.md index dfc212c5..b7e5ccc3 100644 --- a/README.md +++ b/README.md @@ -90,3 +90,117 @@ python tools/build_project.py \ ``` Once the build is complete, the firmwares will be in the `output` directory. + +## Building with a container (for development) + +This is a convenience GNU Make based wrapper around the build process that is being used on the GitHub Actions CI pipeline, but can also be used for local development. + +### Prerequisites + +- [GNU Make](https://www.gnu.org/software/make/) +- [Docker](https://docs.docker.com/get-docker/) or [Podman](https://podman-desktop.io/) + +| Prerequisite | macOS | Windows | Debian/Ubuntu | Fedora | +|-------------|--------|---------|---------------|---------| +| GNU Make | `brew install make` | Via [Chocolatey](https://chocolatey.org/): `choco install make` | `sudo apt install make` | `sudo dnf install make` | +| Docker | Download [Docker Desktop](https://www.docker.com/products/docker-desktop/) | Download [Docker Desktop](https://www.docker.com/products/docker-desktop/) | `sudo apt install docker.io` | `sudo dnf install docker-ce docker-ce-cli containerd.io` | +| Podman | `brew install podman` | Download [Podman Desktop](https://podman-desktop.io/downloads) | `sudo apt install podman` | `sudo dnf install podman` | + +### Usage + +#### Help + +Provides a list of commands and options. + +```bash +make help + +Usage: make [all|build_container|build_firmware] + +Targets: + all Build container and firmware + build_container Build container + build_firmware Build firmware + help Show this help message + +Options: + build_firmware MANIFESTS= Override default manifest files (default: all .yaml/.yml files in manifests/) + +Examples: + # Build the container image + make build_container + + # Build all firmware manifests + make build_firmware + + # Build a specific firmware manifest + make build_firmware MANIFESTS=manifests/nabucasa/yellow_bootloader.yaml +``` + +#### Build everything + +Builds the container image and all available firmware manifests. + +```bash +make +``` + +Once this command completes, the firmwares will be in the `outputs` directory. + +```bash +ls -w 80 outputs | head -3 +skyconnect_bootloader_2.4.2.gbl +skyconnect_bootloader_2.4.2.hex +skyconnect_bootloader_2.4.2.out +``` + +#### Build the container + +Builds only the container image. + +```bash +make build_container +``` + +#### Build all available firmware manifests + +Builds all available firmware manifests in the `manifests` directory. + +```bash +make build_firmware +``` + +#### Build a specific firmware manifest + +Builds a specific firmware manifest by providing the path to the manifest file. + +```bash +make build_firmware MANIFESTS=manifests/nabucasa/yellow_openthread_ncp.yaml +``` + +Once this command completes, the firmwares will be in the `outputs` directory. + +```bash +ls -w 80 outputs +yellow_openthread_rcp_2.4.4.0_GitHub-7074a43e4_gsdk_4.4.4.gbl +yellow_openthread_rcp_2.4.4.0_GitHub-7074a43e4_gsdk_4.4.4.hex +yellow_openthread_rcp_2.4.4.0_GitHub-7074a43e4_gsdk_4.4.4.out +``` + +#### Build with a custom container image + +Builds the firmware with a custom container image by providing the container image name. + +```bash +make build_firmware CONTAINER_NAME=ghcr.io/nabucasa/silabs-firmware-builder +``` + +### Makefile variables + +The following variables can be customized when running make commands: + +| Variable | Default Value | Description | +|----------|---------------|-------------| +| CONTAINER_NAME | silabs-firmware-builder | Name of the container image to build/use | +| CONTAINER_ENGINE | docker | Container engine to use (docker or podman) | +| MANIFESTS | every file in `manifests` directory| Which firmware manifests to build | \ No newline at end of file