Cross compilation for broadband routers II



Last week, I wrote about cross compilation for broadband routers and the test result wasn't as I expected because my “Hello World” application didn't work in my router but I have been working on it for this week and I have got it. It works !!! We have to take into account some things that we'll see in this post today like the importance of bit order in memory, static and shared libraries, kernel version, etc.

First, we should check how the target processor saves words (bytes) in memory because depending on this we will compile on one way or another. There are two techniques, little-endian and big-endian, and although I have checked it, I still remember when I studied this at University. Most routers work with MIPS processors and big-endian architecture, storing the Most Significant Byte (MSB) at the lowest memory address, while most PCs and servers work with Intel and AMD processors, storing the Least Significant Byte (LSB) at the lowest memory address. Therefore, MSB, which is optimized for networking task, is the opposite of LSB. Next we can see the main difference between Little-Endian and Big-Endian:

Little-Endian vs Big-Endian
 
Another thing to take into account is the kernel version for compiling with the right libraries. Last post I installed the cross-development toolchain of the Universal Embedded Operating System which is right for new developments over new broadband routers but I want to make a new application for an old router, thus I have used the CodeSourcery toolchain this time, but I have downloaded an old one from 2012.

CodeSourcery Installation

Also, it is important to know about static and shared libraries. When we develop for a MIPS environment where the target device has few libraries and the file system is in read-only mode, like most routers, is much better to build applications with static libraries although it will be bigger than applications with shared libraries. Next we can see some linux commands (ldd, readelf and file) to check if an application has shared or static libraries.

Check libraries of a binary

Once our development platform is ready with the CodeSourcery toolchain, we can compile the “Hello World” application with Big-Endian, static libraries and the right kernel and libraries versions.

Developing and Compiling Hello World
 
Finally, we have seen that the application is a MSB executable for 32 bits MIPS microprocessor with static libraries and …. it works in my Huawei router.

Application Hello World for MIPS Architecture

Regards my friends, we'll try to build more and sophisticated applications in the future!!

Commentaires

Enregistrer un commentaire