Note: Mbed Linux OS is currently in limited preview. If you would like access to the code repositories, please request to join the preview.
This tutorial creates a user application that runs on your MBL device. It is a simple "Hello, World" in C, which prints to standard output (STDOUT). MBL redirects the output to the log file
Note: Your device must already be running an MBL image. Please follow the first tutorial in this series if you don't have an MBL image yet.
Source and build mechanisms overview
The application source file,
hello_world.c, is in https://github.com/ARMmbed/mbl-core/tree/mbl-os-0.5/tutorials/helloworld/src. On the device, the application runs on a target inside an OCI container. To create the OCI container, we use dockcross to cross-compile the application, then the
opkg-utils helper scripts to package the compiled application as an IPK.
Cross-compiling toolchains in the Docker image are built using an existing dockcross Docker image for the ARMv7 architecture. The
opkg-utils helper scripts are included in the toolchain Docker container, which you can find at https://github.com/ARMmbed/mbl-core/blob/mbl-os-0.5/tutorials/helloworld/cc-env/Dockerfile.
The build commands are defined in a Makefile with three sections:
- Cross-compilation build.
- Create OCI bundle.
- Create IPK.
Each section is implemented for both release and debug variants.
Note: For more information, please refer to the reference about application containers and packages or the dockcross documentation on GitHub.
Setting up the cross-compilation tools
On a Linux Ubuntu PC, install Docker CE as described in the Docker CE for Ubuntu documentation.
git clone firstname.lastname@example.org:ARMmbed/mbl-core.git --branch mbl-os-0.5
Navigate to the
helloworldfolder in your clone:
dockcross is a Docker-based cross-compiling toolchain. We build a new Docker image with dockcross as our starting point, adding the opkg utilities. The image is defined in
cc-env/Dockerfile. You can build it with
docker build -t linux-armv7:latest ./cc-env/
The freshly built image can generate a script that makes it easy to work with. Run the image and capture the output to a file. Make the file an executable and place it in your path:
docker run --rm linux-armv7 > build-armv7 chmod +x build-armv7 sudo mv build-armv7 /usr/local/bin
Building the application with the cross-compiler
To build, invoke the Make toolchain command:
build-armv7 make release.
The build produces an IPK file at
To clean the build, run:
build-armv7 make clean
Installing and running the application on the device
To install the application on the device:
- Send the application as an over-the-air firmware update with Device Management.
- Flash the application over USB with MBL CLI.
Using the application
After installation, and after every reboot, the application runs once and writes "hello world" to the STDOUT. MBL redirects the output to the log file