Skip to main content

Setup Guide for Next-Gen Smart Homes

Creating a Linux System on the SAMA5D27 SOM1

Introduction


The Matter standard is a new way for smart home devices to communicate with each other. It was created by the Connectivity Standards Alliance (CSA) to address the interoperability challenges that designers and consumers faced with competing RF protocols. Matter works with existing smart home technologies like Thread, Wi-Fi®, and wired Ethernet protocols by adding a unifying application layer to the protocol stacks. This enables smart home devices to communicate securely and reliably with each other, regardless of the underlying protocol.

One key component of any smart home is the router. Routers enable internet access and facilitate communication between devices on different networks, connecting them wirelessly through Wi-Fi® or wired Ethernet. Integrating Matter with a Linux-enabled embedded processor, like the Microchip Technology SAMA5D27 system-on-module (SoM), can be beneficial when creating a smart home solution. The use of Matter and SoM-based approaches is increasing in border routers, which act as a gateway between the external internet and the smart home network, allowing for the enrollment of devices using Bluetooth® wireless technology and the implementation of security layers to ensure the internal network's safety.

The SAMA5D27 SOM1 features a high-performance, 32-bit Arm® Cortex®-A5 microprocessor running up to 500MHz. The SOM1 features a variety of peripheral interfaces, including Ethernet, Pmod™, SD cards, and two Mikroe Click board™ interfaces, as well as debugging options UART, JTAG, and general-purpose IO.

In this guide, we will provide you with tips on getting started with the SOM1. This guide is to provide you with the knowledge and know-how to get started with your board. We will guide you through setting up Linux to run on your device.

Bill of Materials (BOM)
The basic requirements for this project are:

References

This project will provide the jumping-off point for additional features, drivers, and peripherals for the development of a border router for a smart home project.

Set Up the VM or OS


We will be building the Linux image from the source. This will allow you to completely customize the Linux kernel configuration for the SOM1 (i.e., implementing the OpenThread software, installing peripheral drivers). To begin building the Linux image, you will need a few packages. In a terminal on your Ubuntu system, download and install the packages if you don’t already have them (Figure 1).

sudo apt-get install git make lzop lzma gettext bison flex libmpc-dev u-boot-tools libncurses5-dev:amd64 libssl-dev:amd64 build-essential

 
Figure 1: Installing the necessary packages. (Source: Author)

Next, you need to install the Arm cross compiler.
If you are using Ubuntu, use the following commands:

sudo apt install gcc-arm-linux-gnueabi

Export the environment variable:

export CC=arm-linux-gnueabi-

For all other Linux distributions, use the following commands:

wget -c https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/arm-linux-gnueabi/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi.tar.xz

Extract the file:

tar xf gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi.tar.xz

Export the environment variable:

export CROSS_COMPILE=`pwd`/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-

Use the following command to ensure you have installed the compiler correctly:

${CC}gcc --version

The output (Figure 2) should be the same regardless of the Linux distribution.

 
Figure 2: Output of the GCC compiler. (Source: Author)

Build the AT91Bootstrap


This section presents instructions for downloading the source from a git repository, customizing the configuration, and building the binary.

Clone the Git Repository
Since you installed git, use the following command to download the repository straight from the terminal:

git clone -b v3.9.3 https://github.com/linux4sam/at91bootstrap --depth=1

Open the new folder using the change directory command:

cd at91bootstrap/

Inside this folder is the root directory for your configurations and build files (Figure 3).
 


Figure 3: The at91bootstrap root directory. (Source: Author)

Customize AT91Bootstrap
If the default configuration doesn't meet your needs, use the following code to open the at91bootstrap configuration menu (Figure 4) to customize it:

 make menuconfig

Here you can further customize the hardware by easily adding or removing features.


 
Figure 4: At91bootstrap configuration window. (Source: Author)

Build AT91Bootstrap Binary
With the boot settings configured, use the following commands to build the binary:

make ARCH=arm CROSS_COMPILE=${CC} distclean
make ARCH=arm CROSS_COMPILE=${CC} sama5d27_som1_eksd_uboot_defconfig
make ARCH=arm CROSS_COMPILE=${CC}

The first command cleans the project, the second sets the U-Boot to read from the SD card, and the third builds all the necessary files and drivers.

Bootloader U-Boot


U-Boot is an open-source primary boot loader used in embedded devices to package the instructions for booting the device's operating system kernel.

Clone the Repository
Just like in the first part, you are going to clone directly from the repository. Use the following commands:

cd git clone -b v2020.04 https://github.com/u-boot/u-boot --depth=1 cd u-boot/

Once the repository has finished cloning, open the folder. This will clone the master, which has the latest version of U-Boot.

Note: We recommend using the latest versions of U-Boot (2018.07 and newer); these have a minimum requirement of GCC toolchain version 6.0.

Next, apply a patch:

wget -c https://github.com/eewiki/u-boot-patches/raw/master/v2020.04/0001-sama5dX-fixes.patch patch -p1 < 0001-sama5dX-fixes.patch

While inside the U-Boot folder, compile the source. Make sure you are in the U-Boot directory (Figure 5):

make ARCH=arm CROSS_COMPILE=${CC} distclean
make ARCH=arm CROSS_COMPILE=${CC} sama5d27_som1_ek_mmc_defconfig
make ARCH=arm CROSS_COMPILE=${CC}
 

Figure 5: Output of Cross Complier. (Source: Author)

Build the Kernel


To get the source code, you need to clone the kernel repository using a script that automatically downloads the dependencies and builds the kernel image. The script, by Robert Nelson, also generates the device tree binaries and the kernel modules, which you will use later.

cd
#user@localhost:~$

Clone the repository into a kernelbuildscripts folder.

git clone https://github.com/RobertCNelson/armv7_devel ./kernelbuildscripts cd kernelbuildscripts/

Check out kernel version 5.15.

git checkout origin/v5.15.x-sama5-armv7 -b tmp

Run the build kernel script (Figures 6 and 7).

./build_kernel.sh 

Figure 6: Building the kernel files. (Source: Author)

 
Figure 7: The completed KernelBuildScript. (Source: Author)

Partition the SD Card


While you wait for the kernel to build, create two new partitions. The first will hold your boot scripts, binary, U-Boot images, and kernel image. The second partition will contain the root file system (rootfs).

To get started:
Insert the SD card into the system that the VM or OS is installed on. Next, open the Activities overview and start Disks to create the first partition (Figure 8).

Note: If your SD card already has partitions, we recommend you delete them and start fresh. You can delete the partition by using the Minus icon on the disk to delete them. This will leave the SD card with free space.

 
Figure 8: SD Card with unallocated space. (Source: Author)

To create a new partition, click the Plus icon.
For the first partition, we recommend allocating at least 1GB (Figure 9).
 


Figure 9: Creating a 1GB boot partition. (Source: Author)

In the Format Volume window (Figure 10), enter boot in the Volume Name field. Under Type, select the radio button for FAT. Then click Create.

 
Figure 10: Formatting the boot partition. (Source: Author)

Next, you will create the rootfs partition (Figure 11). For this partition, you will allocate the remainder of the unused space.

Note: This partition should be at least 5GB.
 


Figure 11: Allocate the rest of the free space in the rootfs partition. (Source: Author)

In the Format Volume window (Figure 12), enter rootfs in the Volume Name field. Under Type, select the radio button for Ext4. Then click Create.

 
Figure 12: Formatting the rootfs partition. (Source: Author)

Download and Install Rootfs


Now that you have created the partitions, you can download the OS to run on your SOM. This section provides instructions for downloading and setting up the rootfs onto the rootfs partition you created.

Using Ubuntu 18.04, download the compressed file:

wget -c https://rcn-ee.com/rootfs/eewiki/minfs/ubuntu-18.04-minimal-armhf-2018-07-14.tar.xz

Extract the compressed file:

tar xf ubuntu-18.04-minimal-armhf-2018-07-14.tar.xz

Find the location of the mounted partition using the Disk application (Figure 13).

Figure 13: Mounted file locations for both the boot and rootfs partitions. (Source: Author)

Use the following command to extract the contents of the Arm rootfs folder into the rootfs partition. Make sure to use the location that contains your partition (Figure 14).

cd ubuntu-18.04-minimal-armhf-2018-07-14
sudo tar xfv armhf-rootfs-ubuntu-bionic.tar -C /media/sama/rootfs/
 


Figure 14: Rootfs partition. (Source: Author)

Copy the Boot Images


Open a terminal and navigate to the at91bootstrap directory. Then open the binaries folder. You must copy the sama5d27_som1_ek-sdcardboot-uboot-3.9.3.bin file and rename it BOOT.BIN.

Type the following command to create a copy and place it into the boot partition.

sudo cp -v sama5d27_som1_ek-sdcardboot-uboot-3.9.3.bin /media/sama/boot/BOOT.BIN

The command will rename the file automatically. Make sure to use the location that contains your partition.

You also need to copy the U-Boot file. Change directories to the root folder and navigate to the U-Boot folder.

Type the following command to copy the U-Boot file to the boot partition. Make sure to use the location that contains your partition.

sudo cp -v ./u-boot/u-boot.bin /media/sama/boot/

The BOOT.BIN and u-boot.bin files will appear in the boot partition (Figure 15).

 
Figure 15: Copying boot and U-Boot files into the boot partition. (Source: Author)

Copy the Kernel Image


Once the kernel has finished building, you can open the directory from the root folder. The following command will navigate to the kernelbuildscripts folder and copy the kernel image (zImage) to the boot partition and rename it as zImage (Figure 16).

#user@localhost:~$
cd kernelbuildscripts/deploy
sudo cp -v 5.15.31-sama5-armv7-r1.zImage /media/sama/boot/zImage

This file has no type and is in binary format. Make sure to use the location that contains your partition.

 
Figure 16: Copying the kernel image to the boot partition. (Source: Author)

Copy the Kernel Modules


Since you are in the kernelbuildscript/deploy folder, also copy the kernel modules to the rootfs partition.

Type the following command to extract the kernel module compressed file into the rootfs partition (Figure 17).

sudo tar xfvo 5.15.31-sama5-armv7-r1-modules.tar.gz -C /media/sama/rootfs/

Make sure to use the location that contains your partition.


Figure 17: Copying the kernel modules to the rootfs partition. (Source: Author)

Add the Device Tree


Next, you will add the device tree to your boot partition. To do so, you must create a new folder.

Type the following commands to create a new directory in the boot partition and extract the device tree binaries into this folder (Figure 18).

sudo mkdir -p /media/sama/boot/dtbs/
sudo tar xfvo ./kernelbuildscripts/deploy/5.15.31-sama5-armv7-r1-dtbs.tar.gz -C /media/sama/boot/dtbs
 

Figure 18: Extracting a device tree directory into boot partition. (Source: Author)

Set the File System Table


Type the following commands to set the file system table for the partitions in the rootfs.

sudo sh -c "echo '/dev/mmcblk0p2  /  auto  errors=remount-ro  0  1' >> /media/sama/rootfs/etc/fstab"
sudo sh -c "echo '/dev/mmcblk0p1  /boot/uboot  auto  defaults  0  2' >> /media/sama/rootfs/etc/fstab"

If everything has gone well, you should see the folder and files in the boot partition (Figure 19).
 


Figure 19: Final boot partition. (Source: Author)

You should also see the folders inside the rootfs partition (Figure 20).

 
Figure 20: Final rootfs partition. (Source: Author)

This completes the steps for setting up the SD card.

Starting Ubuntu


Eject the SD card and plug it into the SD card slot on the evaluation board. Next, plug in the power/UART (J10), which will allow you to open a serial terminal to communicate with the board.

Using the host machine, find the serial port and open a serial terminal. On the SAMA5D27 SOM1, press the NRST (PB1) switch to reset the board. You should be able to see the UART output in the serial terminal (Figure 21).

 
Figure 21: UART output on the serial terminal. (Source: Author)
 
Enter the default username and password:

arm login: Ubuntu
password: temppwd

Type the following commands to connect the board to the internet and update the system. This will download and install the latest packages.

sudo apt-get update
sudo apt-get upgrade

Ubuntu setup is now complete. From this point, you can load additional software using the links provided in the Reference section of this document to add any necessary devices and drivers required for your design.

Summary


The Matter standard was developed to address the interoperability challenges that designers and consumers faced with different RF protocols in smart homes. Matter enables seamless communication between devices using different wireless protocols, offering more flexibility and choices for designers and consumers.

Integrating Matter with a Linux-enabled embedded processor, such as the one in the SAMA5D27 SoM1, can benefit the creation of a smart home IoT border router solution. A SoM-based approach can minimize technical risk, increase Technology Readiness Levels (TRL), and save development time and effort. Soon the walls between different smart home ecosystems will be broken down and your home will have a completely open concept, physically and electronically.