Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


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.

...

  • sudo apt-get install aptitude synaptic systemtap-sdt-dev perl-cross-debian libextutils Extutils-Embed-1.14
  • sudo apt-get install perlbrew libperl-dev php-all-dev php-cli php-gd php-xml

...

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:

  • export CPDIR=/home/.../tools/gcc-linaro-7.3.1-2018.05-x86_64_arm-linux-gnueabihf
  • export CROSS_COMPILE=arm-linux-gnueabihf-
  • export PATH=$CPDIR//bin:$PATH
  • export ARCH=arm
  • export INSDIR=/home/.../code/install

...

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:

...

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.

  • configure

     PS: (if no configure file included in APP, run ./autogen.sh to generate configure file first.)

     This command will auto-generate Makefile of APP.
     Some options need to be added when doing configuratione. For example:
        Assign cross compile tool: CC=arm-linux-gnueabihf-gcc
        Assign install file putting path: --prefix=$INSDIR/perl-5.28.1
        Assign compiled file to be executed on arm-linux: --host=arm-linux-gnueabihf
        Assign compiled file to be executed on compile PC (x86): --target=arm-linux-gnueabihf
        Assign compile and link option: CFLAGS=-static LDFLAGS=-static
     For more information of LINUX configure using, you can refer to https://en.wikipedia.org/wiki/Configure_script or https://www.gnu.org/prep/standards/html_node/Configuration.html .

  • make

     This command will compile code base on Makefile. 

  • make install

     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 -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:

...

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)
HOSTPGEN= $(PGEN)$(EXE)
……………….
.PHONY: regen-grammar
regen-grammar: $(PGEN)

#Regenerate Include/graminit.h and Python/graminit.c

#from Grammar/Grammar using pgen
@$(MKDIR_P) Include
#$(PGEN) $(srcdir)/Grammar/Grammar \
$(HOSTPGEN) $(srcdir)/Grammar/Grammar \
$(srcdir)/Include/graminit.h \
$(srcdir)/Python/graminit.c
………………….
#PYTHON_FOR_BUILD HOSTPYTHON 6 place
PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(HOSTPYTHON) -Wi -tt $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(HOSTPYTHON) -Wi -tt -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST) -f \
-x 'bad_coding|badsyntax|site-packages|lib2to3/tests/data' \
$(DESTDIR)$(LIBDEST)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(HOSTPYTHON) -Wi -t $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(HOSTPYTHON) -Wi -t -O $(DESTDIR)$(LIBDEST)/compileall.py \
-d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(HOSTPYTHON) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(HOSTPYTHON) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/PatternGrammar.txt

...