Omega2 Docker for Cross Compilation
In my repositories ( GitHub and DockerHub ) I have an automated Dockerfile build based on borromeotlhs', but his is currently broken, and doesn't automate all the process.
Now you only need to pull from my Docker Hub with the command:
docker pull jlcs/omega2-sdk
and then run make
to finish the build (will take a long time).
Or use this other one with the toolchain already built (see Edit 2 below):
docker pull jlcs/omega2-docker-built
To run it use:
docker run -it --name omega2-sdk-app -v /my_host_dir:/remote jlcs/omega2-sdk bash
or the bigger one (see Edit 2)
docker run -it --name omega2-sdk-app -v /my_host_dir:/remote jlcs/omega2-docker-built bash
where the container is given a name, shared directory and opens a terminal.
How to compile C code
Once you are in the Docker container, some environment variables are set (maybe not depending on current dockerfile) for you to use:
mipsel-openwrt-linux-gcc [options]
The compiler binaries are generated inside the directory:
/lede/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl-1.1.15/bin/
Note: The 'el' in mipsel indicates it is a Little Endian version of MIPS.
Another option is to create a package, and install with opkg, as explained here (step 6b).
Edits
Edit 1: What to change for Omega2+
If you read the Dockerfile you will notice the lines
# Set SDK environment for Omega2
# For Omega2+ change the third echo line with: (notice the 'p' for plus)
# echo "CONFIG_TARGET_ramips_mt7688_DEVICE_omega2p=y" > .config && \
RUN echo "CONFIG_TARGET_ramips=y" > .config && \
echo "CONFIG_TARGET_ramips_mt7688=y" >> .config && \
echo "CONFIG_TARGET_ramips_mt7688_DEVICE_omega2=y" >> .config && \
make defconfig
So before running make, you can run
echo "CONFIG_TARGET_ramips=y" > .config && \
echo "CONFIG_TARGET_ramips_mt7688=y" >> .config && \
echo "CONFIG_TARGET_ramips_mt7688_DEVICE_omega2p=y" >> .config && \
make defconfig
And then run make
.
Edit 2: Added docker image with prebuilt SDK (Omega2)
In this second Docker Hub repository I simply run make tools/install
and make toolchain/install
from my previous image.
The download is about 2GB.
Use
docker pull jlcs/omega2-docker-built
to download it.
Edit 3: Added CMake support.
You can update your image with CMake 3.7.2, and use this Toolchain-omega2-mipsel.cmake
file to configure your cross-compilation:
# this one is important
SET(CMAKE_SYSTEM_NAME Linux)
#this one not so much
SET(CMAKE_SYSTEM_VERSION 1)
# specify the cross compiler
SET(CMAKE_C_COMPILER /lede/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl/bin/mipsel-openwrt-linux-gcc)
SET(CMAKE_CXX_COMPILER /lede/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl/bin/mipsel-openwrt-linux-g++)
# where is the target environment
SET(CMAKE_FIND_ROOT_PATH /lede/staging_dir/toolchain-mipsel_24kc_gcc-5.4.0_musl)
# search for programs in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
# for libraries and headers in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
# From:
# http://www.vtk.org/Wiki/CMake_Cross_Compiling
# Use the commands:
# mkdir build
# cd build
# cmake -DCMAKE_TOOLCHAIN_FILE=Toolchain-omega2-mipsel.cmake ..
# make
Edit 4: A Docker micro-reference
Check this cheat sheet and this other one.
Some definitions:
- Image – a read-only layer that is the base of your container. It can have a parent image to abstract away the more basic filesystem snapshot. So a Java image would inherit from a linux image with the preinstalled utilities. A tomcat image will have a Java image as the parent because it depends on Java to run Tomcat.
- Container – a runnable instance of the image, basically it is a process isolated by docker that runs on top of the filesystem that an image provides.
Some commands:
- Download an image, and all its parents, from the registry:
docker pull image-name
- Run a shell command inside a freshly created and started container:
docker run -ti --name container-name image-name /command
- Start and stop a container, duh!
docker start container-name
docker stop container-name
- Run a command inside a container from the image and remove the container when command is done.
docker run --rm -ti image-name /command
Simplified vision of Docker:
Sharing host folders as a mounted volume:
Images from dotnetcurry