Skip to content

Commit acbfb5d

Browse files
francescovanninidevbis
authored andcommitted
Added docker build support
1 parent 377a10b commit acbfb5d

File tree

3 files changed

+89
-2
lines changed

3 files changed

+89
-2
lines changed

Dockerfile

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Multi-stage build for z03mmc firmware using Debian
2+
FROM debian:bookworm AS builder
3+
4+
# Prevent interactive prompts
5+
ENV DEBIAN_FRONTEND=noninteractive
6+
7+
# Install build dependencies
8+
RUN apt-get update && apt-get install -y --no-install-recommends \
9+
cmake \
10+
git \
11+
gcc \
12+
g++ \
13+
make \
14+
build-essential \
15+
binutils \
16+
python3 \
17+
ca-certificates \
18+
&& rm -rf /var/lib/apt/lists/*
19+
20+
# Set build environment variables
21+
ENV BUILD_TYPE=Release \
22+
TOOLCHAIN_DIR=/workspace/tc32 \
23+
SDK_DIR=/workspace/telink_zigbee_sdk \
24+
SDK_PREFIX=/workspace/telink_zigbee_sdk/tl_zigbee_sdk
25+
26+
WORKDIR /workspace
27+
28+
# Clone the tc32 toolchain
29+
RUN git clone https://github.com/devbis/tc32.git -b linux --depth 1 ${TOOLCHAIN_DIR}
30+
31+
# Clone the Telink Zigbee SDK
32+
RUN git clone https://github.com/telink-semi/telink_zigbee_sdk.git -b V3.7.1.0 --depth 1 ${SDK_DIR}
33+
34+
# Copy project source
35+
COPY . /workspace/project/
36+
37+
WORKDIR /workspace/project
38+
39+
# Build the firmware
40+
RUN cmake -B /workspace/build \
41+
-DCMAKE_BUILD_TYPE=${BUILD_TYPE} \
42+
-DSDK_PREFIX=${SDK_PREFIX} \
43+
-DTOOLCHAIN_PREFIX=${TOOLCHAIN_DIR} && \
44+
cmake --build /workspace/build --config ${BUILD_TYPE} --target=z03mmc.zigbee
45+
46+
# Export stage - for direct artifact extraction
47+
FROM scratch AS export
48+
49+
ARG BUILD_TYPE=Release
50+
51+
# Copy firmware artifacts (only the key binaries)
52+
COPY --from=builder /workspace/build/src/z03mmc.bin /${BUILD_TYPE}/z03mmc.bin
53+
COPY --from=builder /workspace/build/src/*.zigbee /${BUILD_TYPE}/
54+
COPY --from=builder /workspace/build/src/z03mmc /${BUILD_TYPE}/z03mmc
55+
56+
# Final stage - minimal runtime image (optional, for docker run)
57+
FROM debian:bookworm-slim
58+
59+
ARG BUILD_TYPE=Release
60+
61+
WORKDIR /output
62+
63+
COPY --from=builder /workspace/build/src/ ./${BUILD_TYPE}/
64+
65+
CMD ["/bin/sh"]

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ Or write 1 to 0x0204/0x0000 (Thermostat User Interface Configuration/Temperature
121121

122122
### Building firmware
123123

124+
#### Docker
125+
126+
```sh
127+
docker buildx build --target export --output type=local,dest=build .
128+
```
129+
130+
Firmware binaries will be in `build/Release/` directory:
131+
- `z03mmc.bin` - firmware binary
132+
- `db15-0203-*.zigbee` - firmware with OTA header
133+
134+
If `docker buildx` is unavailable, use standard Docker with volume mount:
135+
```sh
136+
docker build -t z03mmc .
137+
docker run --rm -v $(pwd)/build:/output/Release z03mmc
138+
```
139+
140+
#### Native build
141+
124142
1. Clone TC32 toolchain according to your host OS:
125143
```sh
126144
git clone https://github.com/devbis/tc32.git -b linux
@@ -137,10 +155,10 @@ Or write 1 to 0x0204/0x0000 (Thermostat User Interface Configuration/Temperature
137155
```sh
138156
git clone https://github.com/devbis/z03mmc.git
139157
git clone https://github.com/telink-semi/telink_zigbee_sdk.git -b V3.7.1.0 --depth 1
140-
158+
141159
cd z03mmc
142160
```
143-
161+
144162
3. Configure and build:
145163
```sh
146164
cmake -B build -DSDK_PREFIX=$(pwd)/../telink_zigbee_sdk/tl_zigbee_sdk -DTOOLCHAIN_PREFIX=$(pwd)/../tc32 -DMANUFACTURER_CODE=0x1141

cmake/TelinkSDK.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ IF(NOT CMAKE_C_COMPILER)
1818
SET(CMAKE_C_COMPILER ${TOOLCHAIN_BIN_DIR}/${TARGET_PREFIX}-gcc${TOOL_EXECUTABLE_SUFFIX})
1919
ENDIF()
2020

21+
# Set cross-compiler tools
22+
SET(CMAKE_OBJCOPY ${TOOLCHAIN_BIN_DIR}/${TARGET_PREFIX}-objcopy CACHE FILEPATH "objcopy tool")
23+
SET(CMAKE_SIZE ${TOOLCHAIN_BIN_DIR}/${TARGET_PREFIX}-size CACHE FILEPATH "size tool")
24+
2125
set(TELINK_PLATFORM "8258")
2226

2327
SET(CMAKE_C_FLAGS "-O2 -ffunction-sections -fdata-sections -Wall -fpack-struct -fshort-enums -finline-small-functions -std=gnu99 -fshort-wchar -fms-extensions -nostdlib" CACHE INTERNAL "c compiler flags")

0 commit comments

Comments
 (0)