Building the Unify Matter Protocol Controller

This build guide cross-compiles for arm64 architecture to be run on Unify’s reference platform - a Raspberry Pi 4 (RPi4) with the 64-bit version of Debian bookworm.

Note: In the following subsections the commands should either be run on your local development machine or inside a running Docker container, as distinguished by the structure of the example.

  • some-command should be executed on your local machine.

    • dev-machine:~$ some-command

  • some-other-command should be executed inside the Docker container.

    • root@docker:/<dir>$ some-other-command

Check Out Submodules

🔴 Assuming you have cloned the unify-matter-pc repo in ~/unify-matter-pc

Check out the necessary submodules with the following command.

dev-machine:~/unify-matter-pc$ ./scripts/build_essentials.sh

Build the Docker Container (arm64 compilation)

dev-machine:~/unify-matter-pc$ docker build -t unify-matter docker/

Start the docker:

dev-machine:~/unify-matter-pc$ docker run -it -v $PWD:/unify-matter-pc -v ./linux/third_party/UnifySDK:/uic unify-matter

If you want to be able to use Zap to generate code from Unify XML files you need to export UCL_XML_PATH as well.

root@docker:/uic$ export UCL_XML_PATH=/uic/components/uic_dotdot/dotdot-xml

Activate Matter development environment

Once you have all the necessary submodules, source the Matter environment with the following command. This loads a number of build tools and makes sure the correct toolchains and compilers are used for compiling the Unify Matter Protocol Controller.

Make sure you are in /unify-matter-pc/linux/third_party/connectedhomeip directory

root@docker:/unify-matter-pc$ cd /unify-matter-pc/linux/third_party/connectedhomeip
root@docker:/unify-matter-pc/linux/third_party/connectedhomeip$ git config --global --add safe.directory /unify-matter-pc/linux/third_party/connectedhomeip
root@docker:/unify-matter-pc/linux/third_party/connectedhomeip$ git config --global --add safe.directory /unify-matter-pc/linux/third_party/connectedhomeip/third_party/pigweed/repo
root@docker:/unify-matter-pc/linux/third_party/connectedhomeip$ source ./scripts/activate.sh

Generate Zap Code

This step is optional for normal build, only to be done for changes in Zap files.

To use Zap to generate code from Unify XML files you need to export UCL_XML_PATH as well.

root@docker:/unify-matter-pc$ cd /uic
root@docker:/uic$ export UCL_XML_PATH=/uic/components/uic_dotdot/dotdot-xml

Run below Zap script to generate zap files for unify matter pc.

root@docker:/unify-matter-pc$ cd /unify-matter-pc/linux/templates
root@docker:/unify-matter-pc/linux/templates$ ./run_all_zap.sh

Compile the Unify Matter Protocol Controller

Make sure you are in /unify-matter-pc/linux/ directory

root@docker:/unify-matter-pc$ cd /unify-matter-pc/linux
root@docker:/unify-matter-pc/linux$ gn gen out/arm64 --args='target_cpu="arm64"'
root@docker:/unify-matter-pc/linux$ ninja -C out/arm64 debian

🔴 After building, the unify-matter-pc binary is located at /unify-matter-pc/linux/out/arm64/obj/bin/unify-matter-pc and the debian package is located at /unify-matter-pc/linux/out/arm64/packages/.

Compile the chip-tool

The chip-tool is a CLI tool that can be used to commission the pc and to control end devices.

root@docker:/unify-matter-pc/linux/third_party/connectedhomeip$ cd examples/chip-tool

root@docker:/unify-matter-pc/linux/third_party/connectedhomeip/examples/chip-tool$ gn gen out/arm64 --args='target_cpu="arm64"'

root@docker:/unify-matter-pc/linux/third_party/connectedhomeip/examples/chip-tool$ ninja -C out/arm64

🔴 After building, the chip-tool binary is located at /unify-matter-pc/linux/third_party/connectedhomeip/examples/chip-tool/out/arm64/chip-tool.

Troubleshooting

  1. If you do not source the connectedhomeip/scripts/activate.sh as described above in Activate Matter development environment, gn and other common build tools will not be found.

  2. If you are compiling unit tests, do not try to compile the Unify Matter Protocol Controller at the same time. This will not work as when compiling unit tests you are also compiling unit tests for all other sub-components.

  3. Encountering problems with the submodules can be due to trying to check out the submodules inside the docker container.