6. OPEN SOURCE APPLICATION AND HOW TO CROSS COMPILE AND INSTALL
Figure 6. LINUX software architecture
Figure 6 shows the LINUX software architecture. Normally the chip solution company will provide Driver layer and Hardware layer code for user's reference. There are many open source codes that related to Middleware and Application layer in the internet, user can capture the code and compile it through some procedure. This chapter will introduce how to compile open source code and install in SP7021 platform.
User should prepare a LINUX OS base PC (OS is Ubuntu 18.04) for cross compile open source application code. Once compiling is ready, user has two ways to execute the application (APP).
- Copy the compiled APP to a USB stick, plug in USB stick to SP7021 platform and run the APP.
- Another method is that the user can copy the compiled APP to root file system (rootfs/initramfs/disk/usr) of SP7021 source code and compile SP7021 source code again. After boot up, user can run the APP on SP7021 platform under the folder /sys/usr.
6.1 Setup compiler Linux PC
Use Ubuntu18.04LTS to be the OS of PC. User can download it from https://www.ubuntu-tw.org/modules/tinyd0/ . It also needs to install tool packages for compiler using below commands. Make sure that your PC has ability to connect to internet because all tool packages need to be downloaded from the internet.
|
---|
Other tool packages that may be necessary for compiling APP:
|
---|
6.2 Compile tool chain
Now SP7021 use Linaro tool chain (gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf) to build linux kernel. User can download it and get detail information from https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/.
6.3 Set cross compile environment variable
Suppose the compile tool chain folder is put in Linux PC path: /home/…/tools/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf , source code of SP7021 is put in Linux PC path: /home/…/code/sp7021/.
Environment variables for cross compiler using can be set by command line with commands as below:
|
---|
6.4 Cross compile
For simple application without make file, user can compile it with gcc of compile tool chain directly. Command example is below:
arm-linux-gnueabihf-gcc –o test test.c |
---|
After being compiled, compiler will create a binary file which named test. The binary file can be executed in SP7021 platform.
6.5 APP cross compile and install
For most open source APPs, it usually needs to do three command steps to compile and get install file.
PS: (if no configure file included in APP, run ./autogen.sh to generate configure file first.) This command will auto-generate Makefile of APP.
This command will compile code base on Makefile.
This command will collect executable file and library to the same folder, then copy the folder to the specific path of system. |
---|
6.5.1 Example: libperl
User can download it from https://www.perl.org/ . Decompress and put the file in /home/…/perl-5.28.1. It needs to patch if you want to compile it for arm-linux. Patch can be downloaded from http://arsv.github.io/perl-cross/download.html . Decompress and put the file in /home/…/code/perl-cross-1.2.2. Compile and install libperl by below commands.
$ cp -rpv perl-cross-1.2.2/** perl-5.28.1/ cd perl-5.28.1 configure --prefix=$INSDIR/perl-5.28.1 --target=arm-linux-gnueabihf make make install |
---|
Copy compiled perl file (perl-5.28.1/**) to USB flash disk, then user can execute perl on SP7021. Copy compiled perl file to tool chain folder as backup by below commands.
cp -Rp perl-5.28.1/** $CPDIR/arm-linux-gnueabihf/libc/usr |
---|
6.5.2 Example: python
User can download it from https://www.python.org/ . Decompress and put file in /home/…/code/Python-2.7.16 and create specify folder for compiling using. Action commands are below:
cd /home/.../code tar zxvf Python-2.7.16.tgz mkdir Python-2.7.16_for_x86_64 mkdir Python-2.7.16_for_arm |
---|
a) It needs to generate executable file, python and pgen, those can be executed in compile PC for cross compiling python that can be executed in SP7021. Create three scripts for compiling. Actions are below:
cd Python-2.7.16_for_x86_64 nano mk1_conf.sh file content: #!/bin/bash ../Python-2.7.16/configure --prefix=`pwd` --enable-optimizations nano mk2_conf.sh file content: #!/bin/bash make -j2 nano mk3_conf.sh file content: #!/bin/bash make install |
---|
Execute three scripts sequentially. After the compiling is finished then put the file in /home/…/code/Python-2.7.16_for_x86_64.
./ mk1_conf.sh |
---|
b) Modify Makefile.pre.in. Modification makes reference to Python-2.7.13-xcompile.patch file. File can be downloaded from http://files.cnblogs.com/files/pengdonglin137/Python-2.7.13-xcompile.patch.tar.gz . The content of modification is below: shown as blue color words below.
PGEN= Parser/pgen$(EXE) #Regenerate Include/graminit.h and Python/graminit.c #from Grammar/Grammar using pgen |
---|
c) Create three scripts for compiling. Actions are below:
cd Python-2.7.16_for_arm nano mk1_conf.sh file content: #!/bin/bash export PATH=/home/…/tools/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf/bin:$PATH ../Python-2.7.16/configure --prefix=`pwd`/install \ --host=arm-linux-gnueabihf \ --build=x86_64-linux-gnu \ --enable-ipv6 \ --enable-shared \ ac_cv_file__dev_ptmx="yes" \ ac_cv_file__dev_ptc="no" nano mk2_conf.sh file content: #!/bin/bash export PATH=/home/…/tools/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf/bin:$PATH make HOSTPYTHON=../Python-2.7.16_for_x86_64/python \ HOSTPGEN=../python-2.7.16_for_x86_64/Parser/pgen \ BLDSHARED="arm-linux-gnueabihf-gcc -shared" \ CROSS_COMPILE=arm-linux-gnueabihf- \ CROSS_COMPILE_TARGET=yes \ HOSTARCH=arm-linux-gnueabihf \ BUILDARCH=x86_64-linux-gnu \ -j2 nano mk3_conf.sh file content: #!/bin/bash export PATH=/home/…/tools/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf/bin:$PATH make install HOSTPYTHON=../Python-2.7.16_for_x86_64/python \ BLDSHARED="arm-linux-gnueabihf-gcc -shared" \ CROSS_COMPILE=arm-linux-gnueabihf- \ CROSS_COMPILE_TARGET=yes \ prefix=`pwd`/install |
---|
Execute three scripts sequentially. After compiling action is finished, and then put the file in /home/…/code/Python-2.7.16_for_arm.
./ mk1_conf.sh ./ mk2_conf.sh ./ mk3_conf.sh |
---|
d) Copy compiled python file to compile tool chain folder as backup.
cp -rfp install/** $CPDIR/arm-linux-gnueabihf/libc/usr |
---|
e) One needs to copy libpython2.7.so.1.0 and libpython2.7.so to root file system of SP7021 (/home/…/code/sp7021/linux/rootfs/initramfs/disk/usr/lib ) from compile tool chain folder of compile PC (/home/…/tools/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/usr/lib).
Re-compile source code of SP7021 and update FW of SP7021. Then the necessary library files will be put in the root file system.
Note: This action needs to be done after doing "make config". Because initial configure of SP7021 code doesn't have those files.
f) Copy the compiled python file to USB stick, then user can execute python on SP7021 platform with USB stick.