Clone repository with documentation and OpenWrt patch for gateway.
Updating sources tree.
If you use this guide first time omit this step and move to “Building image from sources”. For using this patch first you need to discard changes from older patch by following command:
Now you can apply fresh new patch
Building image from sources.
First you need to download source code of openwrt build tools from official repository by using following command
Move to path with sources
Flashing first time.
First you need to write image to microSD card
Loading from FTP- or HTTP-server
Put image file to the path of your FTP/HTTP server. For FTP use anonymous user for file loading using this protocol. For example, your server’s IP address is 192.168.1.100. Download image file in /tmp directory of your device using following command (для FTP)
Loading using SCP
Lets consider that IP address of your device 192.168.1.1. Copy image file via scp:
For full image upgrade in a case of changes in DTB tree or Uboot while OS configuration storing doesn’t required – use way described above. If you need to store configuration after image updating you need to rewrite DTB/Uboot manually. To update Uboot download openwrt-sunxi-cortexa7-sun8i-h2-plus-orangepi-zero-squashfs-uboot.bin file on your device (via SCP or using FTP/HTTP server) in /tmp directory and run following:
OpenWrt params by default.
IP-address, default access way, user and password.
On first boot device configured to get IP-address using DHCP. You can check for it on DHCP server. Remote access available using SSH. Username to access is root. No password required.
Lorawan gateway configuration.
Configuration file of packet-forwarder library placed in /etc. Path to access it: /etc/global_conf.json
Control mechanism typical for openwrt. To launch daemon manually enter following:
List of source files modified by patch with short description:
Config file with supporting of OrangePi Zero. Booting from SPI-NOR flash IC. LoraWan packets added by default.
Uboot makefile for OrangePi Zero.
Patch for Uboot to support linux kernel booting from SPI-NOR flash IC.
Linux kernel patch with support of SPI-NOR flash IC. Second SPI interface added to communicate with SX1301 (/dev/spidev1.1).
Linux kernel configuration. Added support for SPI interface and SPI-NOR IC partitions checking.
Auto configuration of raw image to write on microSD card.
Main makefile. Added link to OrangePi’s makefile.Description of steps to compile resulted images.
Description of steps to compile resulted images.
Script used for image upgrade using sysupgrade. Allows remotely upgrade image without overwriting configuration.
qsort_r function added to musl library. As lora-gateway packet uses this function but this function presents only in GLIBC or uClibc adding this function mandatory.
LoRaWAN packets directory.
Semtech’s packet-forwarder packet.
Default config files directory.
Detailed description of patch.
Sources used by patch.
All changes in patch were maid manually except following.
To support booting from SPI-NOR flash IC Sunxi’s official repository was used. Branch that was used is sunxi-spi. Pin mux (gpio configuration) supporting added in patch. DTB tree changes for flash partitions configuration.
Lorawan packets was ported from xueliu repository. Changes for local compilation. Manual sources update without using external resources. Patch from repository was applied manually. Patches were moved in applied-patches-to-src directory. You don“t need to use it anymore. Lora Packages chapter was added to menuconfig to simplify navigation.
SPI-NOR flash IC partitions.
Openwrt allows you to dynamically change the structure of flash IC when the system boots. This is done for the convenience of the main subsystems, file-size requirements, technical limitations of working with NOR flash drives (no wear-leveling and inability to work as with a conventional block device). Main filesystem in OpenWrt for linux kernel is squashfs, secondary filesystem, used by OpenWRT – JFFS2. Squashfs doesn’t support write mode (static) and is formed at the time of image compiling, has better compression parameters. JFFS2 supports write operations and wear-leveling to reduce the wear of flash drives, but because of this has significantly worse compression characteristics.
The basic set of partitions of the flash drive is the uboot partition and firmware partition for the main system. For simplicity of porting and compatibility of all firmware images ( for SD-card and for SPI-NOR IC) a separate section for DTB on SPI-NOR is required. It is called DTB.
The base partitions are mentioned in the corresponding dts files for UBoot and the linux kernel.
With each download of Openwrt, there are two splits of partitions. The first partition is based on the name of the partition with the firmware (in the firmware section it is assumed that there is a linux kernel packed in a special image format uImage, created by the mkimage utility from UBoot, and squashfs), in which the linux kernel size is read, at the end of which the erasesize the minimum amount of erasure) of the flash drive is searched for a sign (MAGIC combination of bytes) of the beginning of squashfs. If the file system is found, the system dynamically creates the kernel and rootfs partitions. The kernel section corresponds exactly to the boundaries of the linux kernel, and rootfs occupies the rest of the region.
The second partition occurs when the rootfs section appears, at the end of which the kernel looks for (at the erasesize boundary) a pointer to the start of JFFS2. The pointer is placed during image compilation and is aligned to the size of the flash block size. After that, the kernel creates another partition called rootfs_data.
When the system is subsequently booted, the available partitions are mounted in the required order. The executable file mount_root is responsible for this. At the very first loading of the device, the JFFS2 file system is created on the rootfs_data partition.
For the usual work in an openwrt environment with the ability to write and delete files, the subsystem of the OverlayFS kernel is used. This file system allows you to emulate the behavior of standard systems using only one file system available for writing, all changes in the structure are stored in it.
For the convenience of updating and initial recording on the flash, the factory section is also presented, covering the entire volume of the SPI-NOR flash drive (8MiB).
A visual representation of the sections on SPI-NOR is presented below:
Some useful links to work with GW-01: