INTRODUCTION

Figure 1. Architecture of Our Embedded Linux Gateway.

BACKGROUND

In many scenarios, we need to collect data within an area, such as temperature in a city, or fire alarms in a building. With the rapid popularization of the Internet of Things technology, more and more terminal devices support the data networking function. Therefore, we can quickly network in an area. However, in the face of various types of terminal devices with different standards, the data platform cannot be compatible with every type of device. The gateway can help us solve this problem. It acts as a bridge between the node and the data platform. It reloads the received node data and accesses it to the data platform in the format required by the data platform.

MOTIVATION & GOALS

Based on mature wireless communication technologies, multiple networking modes are available, such as Wi-Fi, Bluetooth, ZigBee, LoRa, and NB-IoT. In regional networking, we need to pay attention to parameters such as cost, maximum transmission distance, power consumption, and penetration rate. In comparison, LoRa excels in all of these areas. Therefore, in this work, we design a LoRa gateway that can cover a radius of no more than 15 km (ideal theoretical value) and reload node data to the data platform through the 4G cellular network in the format required by the data platform.

Technology Frequency Band Max. Trans. Distance Max. Trans. Rate Network Topology Safety
LoRaWAN 868MHz, 915MHz 15km 300bps to 5.5kpbs Start or Mix AES-128
ZigBee 2.4GHz 100m 250kbps Mesh AES-128
WiFi 2.4GHz, 5GHz 100m 10Mbps to 1Gbps P2P WPA2
NB-IoT 800MHz to 2.2GHz 10km 250kbps Start AES

METHOD

This is my first experience with embedded Linux systems, so Linux system porting takes up most of the work. This chapter consists of two parts. The first part explains how we build an embedded Linux system, and the second part describes how we build a gateway application. Note that the following is based on the NXP.iMX6ULL processor.

Embedded Linux Operating System

From the perspective of developers, Linux consists of three parts: Boot Loader, Linux Kernel, and Root File System. The Boot Loader and Linux Kernel are closely related to hardware.

1. U-Boot

Figure 2. Uboot Components.

The BootLoader we use is U-Boot, which is short for Universal Boot Loader. It is an open-source project that complies with the GPL and is maintained by Wolfgang Denk of the DENX software work center in Germany. It supports multiple processors, including ARM, x86, MIPS, and RISCV. U-Boot is essentially a bare-metal program, which is similar to a single-chip microcomputer program. U-Boot uses assembly language and C language to operate some registers to initialize some peripherals, such as serial ports, networks, and DDR, and then loads the kernel program from the flash memory to the DDR to start the kernel. At the same time, control of the CPU is handed over to the kernel program, and its life cycle ends. It's just a complex and huge bare-metal program.

Figure 3. NXP.iMX6ULL Memory Addresses and Corresponding Runs.

A. Why initialize these peripherals?

During development, we need to change the image system frequently. However, we do not always need to burn the kernel to the flash memory for debugging. We can directly load the kernel program from the PC to the DDR through the network (TFTP protocol) and start the system.

B. What are the U-Boot boot modes?

The U-Boot supports three boot modes, which are determined by the BOOT_MODE register. The BOOT_MODE can be controlled by the I/O pin. In the internal boot mode, the BOOT_CFG register controls the flash memory and some parameters.

C. How does the CPU start the U-Boot?

U-Boot is not the first program to be started after the CPU is powered on. The NXP.iMX6ULL processor has a 96K ROM and 128K RAM. The ROM contains a program that cannot be modified after delivery. The program is located at 0x00000000. Therefore, it is the first program specified after power-up. It initializes the flash interface, USB interface, and DDR. SoC vendors may use different DDR peripherals. Therefore, the BOOT ROM program loads the DDR information from the flash memory, initializes the DDR, and loads the U-Boot from the flash memory to the DDR.

2. Kernel

The Linux kernel is a free and open-source: 4  monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU operating system, which was written to be a free (libre) replacement for Unix.

We ported the current relatively new Linux kernel, version number 5.4.70.Our compilation environment is Ubuntu 22.04, and we configured the Linaro cross-compiler, which is version number 7.5.0.

Figure 4. Components and Roles of the Linux Kernel.

3. Root File System

Cite Article Ubuntu Base

Ubuntu Base is a minimal rootfs for use in the creation of custom images for specific needs. Ubuntu Base strives to create a suitable minimal environment for use in Board Support Packages, constrained or integrated environments, as the basis for application demonstration images, or Linux containers such as LXC or Docker (For OCI/docker container images, see also the Ubuntu OCI project). It is available for the i386, amd64, armhf, arm64, powerpc and ppc64el architectures.

Ubuntu Base delivers a functional user-space environment, with full support for installation of additional software from the Ubuntu repositories, through the use of the apt-get command.

1. Downlaod Ubuntu-base-22.04


wget https://cdimage.ubuntu.com/ubuntu-base/releases/22.04/release/ubuntu-base-22.04-base-arm64.tar.gz
mkdir ubuntu_base_rootfs
sudo tar xzf ubuntu-base-22.04-base-arm64.tar.gz -C ./ubuntu_base_rootfs/
cd ubuntu_base_rootfs/

2. Install qeumu, a generic and open source machine emulator and virtualizer.


sudo apt install qemu-user-static
sudo cp /usr/bin/qemu-arm-static ./usr/bin/
sudo cp /etc/resolv.conf ./etc/resolv.conf

3. Mount the Ubuntu-base filesystem on the host computer.


sudo mount -t proc /proc ./proc
sudo mount -t sysfs /sysfs ./sys
sudo mount -o bind /dev ./dev
sudo mount -o bind /dev/pts ./dev/pts
sudo chroot ./

4. Installing frequently used software to the ubuntu-base filesystem.


apt update
apt install sudo vim kmod net-tools ethtool ifupdown language-pack-en-base rsyslog iputils-ping
passwd root
echo "linux" > /etc/hostname
echo "127.0.0.1 localhost" >> /etc/hosts
echo "127.0.0.1 linux" >> /etc/hosts
ln -s /lib/systemd/system/getty@.service /etc/systemd/system/getty.target.wants/getty@ttymxc0.service

5. Unmount Ubuntu-base from the host computer.


exit
sudo umount ./proc
sudo umount ./sys
sudo umount ./dev/pts
sudo umount ./dev

Gateway Applications

The main role of our gateway is to be a centralizer for different protocols, including LoRa, 485 and others. It also integrates 4G module for internet communication.

1. LoRaWAN Integrator Application


git clone https://github.com/Lora-net/lora_gateway
make
# change pin number to 123
./reset_lgw.sh


git clone https://github.com/Lora-net/packet_forwarder.git
make
# change server ip to bohao.de
./lora_pkt_fwd/lora_pkt_fwd

KEYWORDS

Edge Computing Sensor Kit, Information Fusion, Machine Learning, Real-time Activity Recognition, Digital Twin, Data Visualization.

MATERIALS

HARDWARE

Figure 5. Linux Gateway Physical Drawing.

Figure 6. Schematic diagram of IMX6ULL core connection.

Figure 7. Schematic diagram of lora module connection.

Figure 8. Schematic diagram of 4G module connection.

Figure 6. Schematic diagram of 485 module connection.