Cross Compile C program for FATBOX G3 iMX6 edge MQTT Gateway
Last update June 2021
for OpenWRT version 18.06
In this Application Note, we will explain to setup, write, compile, install and test your own C code for our FATBOX G3 device.
The FATBOX G3 is an open Linux platform where user can deploy their own portable codes e.g. in C or Python or LUA to run on an industrial cellular (3G or 4G/LTE) and ethernet WAN connected gateway device. This will allow user to write codes to read Modbus, CANbus, RS232, RS485 serial data, Zigbee and other inputs – process onboard or sent straight to their central server.
The board runs OpenWRT on an embedded Linux board running NXP i.MX6 processor. Therefore the first task is to install the correct tool chain into your development device. A Linux development laptop (or a Windows computer running a Linux, e.g. Ubuntu 16.04 LTS as a VM or Docker container).
1. Install the C Toolchain
$ git clone git://git.openwrt.org/openwrt/openwrt.git G3
$ cd G3
$ git checkout openwrt-18.06
$ ./scripts/feeds update -a
$ ./scripts/feeds install –a
$ make menuconfig
You need to install our current build configuration file. Download the file from our Google Drive link below, rename it “.config” and save in /G3 folder
https://drive.google.com/file/d/1p6FKo9Ry2HykKBnv4SQW-2gyvY8QDHe8/view?usp=sharing
The following may be required to properly build your cross-compilation environment,
$ sudo apt-get update
$ sudo apt-get install build-essential libssl-dev libncurses5-dev unzip gawk zlib1g-dev
Next, you can customized (do not remove any modules already selected as some are critical to operation of the gateway) the build.
$ make menuconfig
Now we are going to start the bulding process. V=99 enable detailed compilation output for troubleshooting.
$ make V=99
Now you will have the correct C toolchain in your dev computer to compile executable programs in the FATBOX G3 gateway.
2. Install and configure your IDE
We choose to use Eclipse IDE with C/C++ development Tools (CDT) installed. You need to configure similar to the following as one your development system’s OpenWRT folder structure. In Eclipse, this setting is under Properties > Cross Settings
Prefix : arm-openwrt-linux-
Path : ~/G3/staging_dir/toolchain-arm_cortex-a9+neon_gcc-7.3.0_musl_eabi
3. Write and compile your C program
Now you are all set to test a simple ‘Hello’ C-program i.e. a fprintf(stderr,"HELLO!\n") in your main() or our BLINK souce code (which flashes the FATBOX G3 LEDs once when executed)
BLINK download link :
https://drive.google.com/open?id=1HJySXHFkCrfoJdvn8DJBZpDQbagd21Qt
After you run “Build All” in your IDE, you should see a cross-compiled [arm/le] executable, for Eclipse IDE as example.
4. Install and test your C executable
The executable file e.g. BLINK.exe in our example is found under the Debug sub-folder in your Eclipse project folder. The easiest way to test the file is to enable SSH and scp or (winscp) the program over to the FATBOX G3 board, then SSH over to console and just execute the program (remember to CHMOD the file to enable execution).
Done! You can now compile your own or other 3rd party Linux C codes (or SDKs) to execute on our platform.
Other articles that may interest you
Reduce the 3 costs associated with cloud data
Feedback & Control IoT applications
Connect a Schneider energy meter to AWS
A linux MQTT Gateway