Application source code for Embedded Android Platform based on ODROID-A4

Hardkernel has released guide book of Android platform development.

–   Basic ( Android/Bootloader/Kernel Build and Installation )
–   Intermediate ( Driver / HAL Development )
–   Advanced (GPIO/UART/I2C/ADC access from Android application )

Kernel source code can be downloaded from this link.

Kernel source code IO board >

There are also many useful Android application source code to access hardware in Android devices.

Sensor API   < Source code >

Sensor e-Compass API < Source code >

Camera API (preview)   < Source code >

Camera Application (Barcode & QR code reader)   < Source code > taken from ZXing project.

Battery gauge API < Source code >

Audio API <Source code >

WiFi & Bluetooth API < Source code >

GPIO / IRQ access <Source code >

ADC access <Source code >

ADC access (Oscilloscope) < Source code >

UART access (GSP system)  < Source code >

I2C access (Pressure & Barometer) < Source code >

I2C access (GPIO expansion) < Source code >

OpenMP test with ODROID-A4.

An example of 40 pieces of Fibonacci numbers(sequences).
If you want to know about Fibonacci sequences, refer this link.

1
2
3
5
8
13
21
34
55
89
144
233
377
610
987
1597
2584
4181
6765
10946
17711
28657
46368
75025
121393
196418
317811
514229
832040
1346269
2178309
3524578
5702887
9227465
14930352
24157817
39088169
63245986
102334155

To find 40 pieces of Fibonacci sequence, we used this code with OpenMP library on ODROID-A4.
fibonacci_omp.c
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <omp.h>
#include <unistd.h>        /* for open/close.. */
#include <fcntl.h>           /* for O_RDONLY */
#include <sys\ioctl.h>   /* for ioctl*/
#include <sys\types.h>  /* for lseek() */


int Fibonacci(int n)
{
    int x, y;
    if (n < 2)
        return n;
    else {
        x = Fibonacci(n - 1);
        y = Fibonacci(n - 2);
        return (x + y);
    }
}

int FibonacciTask(int n)
{
    int x, y;
    if (n < 2)
        return n;
    else {
#pragma omp task shared(x)
        x = Fibonacci(n - 1);
#pragma omp task shared(y)
        y = Fibonacci(n - 2);
#pragma omp taskwait
        return (x + y);
    }
}

#define MAX 41
int main(int argc, char * argv[])
{
    int FibNumber[MAX] = {0};
    struct timeval time_start, time_end;

    int i = 0;

    // omp 관련 출력
    printf(\"Number of CPUs=%d\n\", omp_get_num_procs());
    printf(\"Number of max threads=%d\n\", omp_get_max_threads());


    gettimeofday(&time_start, NULL);
#pragma omp parallel
    {
#pragma omp single private(i)
        for(i = 1; i < MAX; i++) {
            FibNumber[i] = FibonacciTask(i);
        }
    }
    gettimeofday(&time_end, NULL);

    time_end.tv_usec = time_end.tv_usec-time_start.tv_usec;
    time_end.tv_sec = time_end.tv_sec-time_start.tv_sec;
    time_end.tv_usec += (time_end.tv_sec*1000000);
    printf(\"Time of Fibonacci with OpenMP : %lf sec\n\", time_end.tv_usec / 1000000.0);

    for(i = 0; i < MAX; i++)
        printf(\"%d \", FibNumber[i]);

    printf(\"\n--------------------------------------\n\");

    return 0;

Here is a Makefile example!

GCC = /usr/local/arm/ktoolchain-cortexa9-ver2.1-20110815/bin/arm-none-linux-gnueabi-gcc 

#Fibonacci: Fibonacci.c
#    $(GCC) -o Fibonacci $< -lgomp -lpthread -fopenmp -lm -static 
Fibonacci_omp: Fibonacci_omp.c
    $(GCC) -o Fibonacci_omp $< -lgomp -lpthread -fopenmp -lm -static -O3

Please note the toolchain for OpenMP could be downloadable via in this link.
http://www.kandroid.org/board/board.php?board=toolchain&command=body&no=15

You also need to change the kernel option to activate dual-core all the time, refer Page16~17 of this document.
http://com.odroid.com/sigong/nf_file_board/nfile_board_view.php?keyword=&tag=&bid=96

Test result !
We could know the dual-core utilized calculation of Fibonacci is 1.6 times faster than single-core.

root@android:/system/bin
# ./Fibonacci                                         
Time of Fibonacci with recursion : 7.862591 sec
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269
2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986
102334155
--------------------------------------
root@android:/system/bin
# ./Fibonacci_omp                                     
Number of CPUs=2
Number of max threads=2
Time of Fibonacci with OpenMP : 4.878260 sec
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765
10946 17711 28657 46368 75025 121393 196418 317811 514229 832040 1346269
2178309 3524578 5702887 9227465 14930352 24157817 39088169 63245986
102334155
--------------------------------------

Multi-core programming (Parallel computing)

Hi everyone,

As you know well, Samsung Exynos-4210 contains TWO Cortex-A9 processors.
So all of ODROID-A, ODROID-PC and ODROID-A4 has dual-core powered computing performance.

To utilize full computing power of dual-core in Android, you need to learn Multi-thread programming.

This document explains the multi-threading in JAVA as well as Native C/C++(NDK) code.
Please note this great article has been written by Alvaro.

There are two source code packages for Java and NDK example.

labbok-Multithreading.rar contains modified graphical interface with an asynchronous task in JAVA.

labbok-NDKMultithreading.rar contains Fibonacci calculation in NDK.

Enjoy the document and example codes for your programming in multi-core world.

This screen shot shows the result of Fibonacci sequence calculation. He tried 30 numbers of sequence with ODROID-A4 ICS build.
It took 420msec with single-core and 230msec with dual-core.
So we can say the dual-core has significant boosted speed about 180% of the single-core.

Once again, really appreciate Alvaro’s sharing.

Another news!
We will release an example code with OpenMP to show you alternative approach of multi-core programming by this weekend.
So stay tuned!

Small embedded Linux root file system for ODROID-7/7E

ODROID-7에서 테스트된 리눅스 루트 파일 시스템입니다.
ODROID-E7에도 적용 가능합니다.
Auto-Login을 구현하여, SDL 및 간단한 어플까지 만들어 모두 자동으로 실행하는 실용적인 예제가 될것 같습니다.

How to make a Small embedded Linux root file !

I found a generic embedded root file system with EABI by Googling.
http://ftp.falinux.com/toolchain_ramdisk/recommendation/gcc-4.3.2/
At this moment, this link is broken.

To implement the auto login, I need to cross compile the mingetty in the Sourceforge.
http://sourceforge.net/projects/mingetty/
After compilation, the generated file must be copied in to /bin directory.

Add below line in to /etc/inittab for automatic login as a super user(root)

T0:12345:respawn:/bin/mingetty --autologin=root ttySAC2 115200 vt100

To test this root file system, I copied it to the system partition(mmcblk0p2) of Odroid-7.

And I changed bootargs as below.
For ODROID-7 (S5PC110/EXYNOS-3110)

setenv bootargs 'root=/dev/mmcblk0p2 rw rootfstype=ext4  init=/sbin/init console=ttySAC2,115200 rootdelay=1'
setevn bootcmd 'movi read kernel 30008000;bootm 30008000'
savenv

For ODROID-E7 (S5P6450 ARM11)

setenv bootargs 'root=/dev/mmcblk0p2 rw rootfstype=ext4  init=/sbin/init console=ttySAC2,115200 rootdelay=1'
setevn bootcmd 'movi read kernel E0008000;bootm E0008000'
savenv

To make a SDL and application software, I followed below sequence.

Toolchain
Sourcery G++ Lite 2010.09-50  (GNUEABI version)
https://sourcery.mentor.com/sgpp/portal/release1600
* Note: EABI version can’t compile SDL correctly. Must use the GNUEABI version.

SDL source code
http://www.libsdl.org/download-1.2.php
Source code location on host PC
/home/justin/sdl/SDL-1.2.14 (This is my working directory. It is just an example!)

Compile SDL

export CC=arm-none-linux-gnueabi-gcc
./configure --host=arm-none-linux-gnueabi --prefix=/home/justin/sdl/compiled --without-x
make -j 4
make install

* Note: Modify the SDL-1.2.14/src/video/fbcon/SDL_fbvideo.c
Comment out the mouse related code in FB_VideoInit() function.

Compile sdl test (Modify the SDL init function to 800×480 resolution and 32bit color, if the application uses graphic layer.)

./configure --host=arm-none-linux-gnueabi  --with-sdl-prefix=/home/justin/sdl/compiled --disable-sdltest
make -j 4

Compile Freetype
http://download.savannah.gnu.org/releases/freetype/freetype-2.1.10.tar.gz

./configure --host=arm-none-linux-gnueabi --without-zlib --prefix=/home/justin/sdl/compiled
make -j 4
make install

Compile SDL_ttf to display fonts.
http://www.libsdl.org/projects/SDL_ttf/SDL_ttf-2.0.10.tar.gz

./configure --host=arm-none-linux-gnueabi --prefix=/home/justin/sdl/compiled --with-freetype-prefix=/home/justin/sdl/compiled --with-sdl-prefix=/home/justin/sdl/compiled 

#undef HAVE_ICONV ==> showfont.c ( Modify this to avoid annoying error. But, this one should be fixed for proper display of 2-byte languages.)

make -j 4
make install

showfont executable file is generated in .lib directory.

SDL_ShowCursor(SDL_DISABLE);  //To hide the mouse cursor !!!

Download and Install font.
http://ftp.gnu.org/gnu/freefont/freefont-ttf-20100919.tar.gz
Uncompress and copy the fonts in to /usr/fonts/ directory.

Let’s test.

./showfont -i ../fonts/FreeSerif.ttf 30

To execute this application automatically, add below line in /root/.bashrc !!

/usr/bin/showfont -i /usr/fonts/FreeSerif.ttf 30

Finally we made a simple and useful root file system.
This is very light and fast embedded linux root file system.
Size is 35Mbyte approximately.
Get this root file system from
http://dev.odroid.com/projects/odroid-t/download/note/76

Reference.
http://www.crosscompile.org/static/pages/SDL.html