Skip to content

Commit

Permalink
Add Makefile providing container based build workflow
Browse files Browse the repository at this point in the history
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=<path>  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 <[email protected]>
  • Loading branch information
ynezz committed Dec 1, 2024
1 parent 3eae968 commit 0f7892c
Show file tree
Hide file tree
Showing 2 changed files with 187 additions and 0 deletions.
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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=<path> 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)) \
"
114 changes: 114 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<path> 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 |

0 comments on commit 0f7892c

Please sign in to comment.