2015년 12월 28일 월요일

overscan for ODROID-C1 Ubuntu


1. search overscan values.

Read default values
root@odroid:~# cat /sys/class/graphics/fb0/window_axis
window axis is [100 100 1919 1079]
root@odroid:~#

Try to set overscan values
root@odroid:~# echo 100 100 1919 1079 > /sys/class/graphics/fb0/window_axis
root@odroid:~# echo 0x10001 > /sys/class/graphics/fb0/free_scale


2. make script(overscan.sh)

root@odroid:~# cat overscan.sh
#!/bin/bash

echo 100 100 1919 1079 > /sys/class/graphics/fb0/window_axis
echo 0x10001 > /sys/class/graphics/fb0/free_scale 

root@odroid:~#

3. Auto-start overscan shell script on Ubuntu.

root@odroid:~# cp overscan.sh /etc/init.d/
root@odroid:~# sudo update-rc.d overscan.sh defaults 



left : 10
right : 1919
top : 10
bottom : 1070

2015년 10월 12일 월요일

안드로이드 repo 특정 날짜로 돌려서 빌드하기

급하게 아래 안드로이드 project를 build 해야 할 일이 생겼다.

https://github.com/voodik/android/tree/cm-12.1_5422

오래전에 받아 놓은 소스를 repo sync 후 빌드 하니 역시나 컴파일 에러가 난다.

git log를 보면 계속 작업을 진행하였지만 release한 버전에 tag가 없다. 그래서 원하는 버전으로 돌리기가 어렵다.

아래 포럼에 보면 마지막 7월 7일이 마지막 버전이다.
http://forum.odroid.com/viewtopic.php?f=94&t=9316

googling 하여 보니 git rev-list를 통해 특정 날짜로 돌릴 수 있다. 그래서 아래와 같이 모든 프로젝트를 7월 7일로 돌렸다.

우선 manifest를 7월 7일로 돌린다.
$ cd .repo/manifsets/
$ git rev-list -n 1 --before="2015-07-07 24:00:00" default | xargs -i git reset --hard {}

돌린 default.xml을 복사하여 둔다/
$ cp default.xml ../default_0707.xml

다시 마지막으로 원복시킨다.
$ git reset --hard origin/cm-12.1_5422

그리고 7월 7일 내용을 하나의 commit으로 올린다.
$ mv ../default_0707.xml default.xml
$ git add default.xml
$ git commit
$ repo sync

위와 같이 하지 않으면 repo sync시 다시 최신 소스로 돌아가 버린다.

마지막으로 모든 프로젝트도 동일하게 7월 7일로 reset 한다.

$ repo forall -c 'git rev-list -n 1 --before="2015-07-07 24:00:00" cm-12.1_5422 | xargs -i git reset --hard {}'

빌드를 진행한다.

2015년 9월 2일 수요일

Shell Scripting: Generate or Print Range of Numbers ( Sequence of Numbers for Loop )

seq를 이용하여 범위의 값을 아래와 같이 얻어 올 수 있다.

$ seq 1 10
1
2
3
4
5
6
7
8
9
10
$

seq man page
SEQ(1)                                                                                        User Commands                                                                                        SEQ(1)

NAME
       seq - print a sequence of numbers

SYNOPSIS
       seq [OPTION]... LAST
       seq [OPTION]... FIRST LAST
       seq [OPTION]... FIRST INCREMENT LAST

DESCRIPTION


seq를 통해 얻어온 값을 for loop에 넣어서 원하는 로직을 만들 수 있다.
$ for i in $(seq 1 10)
> do
> echo $i
> done
1
2
3
4
5
6
7
8
9
10

$ for i in $(seq 1 10)
> do
> echo $i > export
> done


2015년 8월 25일 화요일

Android File Chooser and URI to File Path.

파일을 Intent.ACTION_GET_CONTENT을 이용하여 선택하고 URIFile Path로 변환하기

Image 나 Video 같은 파일을 얻어오는 예제는 많지만 일반 파일을 선택하는 예제가 없어서 며칠 찾아 보다가 직접 external.db에서 값을 얻어와야 한다는 결론을 얻었습니다.

/data/data/com.android.providers.media/databases 경로에 가면 모든 파일을 DB로 관리합니다.

root@odroidc:/data/data/com.android.providers.media/databases # ls -l
-rw-rw---- u0_a4    u0_a4      163840 2015-08-25 03:23 external.db
-rw-rw---- u0_a4    u0_a4       32768 2015-08-25 03:21 external.db-shm
-rw-rw---- u0_a4    u0_a4       28872 2015-08-25 03:21 external.db-wal
-rw-rw---- u0_a4    u0_a4      212992 2015-08-20 06:22 internal.db
-rw------- u0_a4    u0_a4       32768 2015-08-25 03:21 internal.db-shm
-rw------- u0_a4    u0_a4      453232 2015-08-25 03:21 internal.db-wal
root@odroidc:/data/data/com.android.providers.media/databases #

external.db를 sqliteman 프로그램을 이용하여 열어 보시면 아래와 같이 되어 있습니다.
files 테이블에 '_data'란 column에 실제 file path가 들어 있습니다.



private static final int FILE_SELECT_CODE = 0;

private void showFileChooser() {
    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_GET_CONTENT);

아래와 같이 할 경우 mime-type에 해당하는 파일만 선택 가능해 집니다.
    intent.setType("application/zip");
    intent.addCategory(Intent.CATEGORY_OPENABLE);

    try {
        startActivityForResult(
                Intent.createChooser(intent, "Select a File"),
                FILE_SELECT_CODE);
    } catch (android.content.ActivityNotFoundException ex) {
        // Potentially direct the user to the Market with a Dialog
        Toast.makeText(this, "Please install a File Manager.",
                Toast.LENGTH_SHORT).show();
    }
}

showFileChooser()를 실행하면 아래와 같은 file dialog가 실행 됩니다.


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case FILE_SELECT_CODE:
            if (resultCode == RESULT_OK) {
                // Get the Uri of the selected file
                Uri uri = data.getData();
URI -> real file path
                String file_path = getRealPathFromURI(uri);
            }
            break;
    }
    super.onActivityResult(requestCode, resultCode, data);
}


private String getRealPathFromURI(Uri uri) {
    String filePath = "";
    filePath = uri.getPath();
경로에 /storage가 들어가면 real file path로 판단
    if (filePath.startsWith("/storage"))
        return filePath;

    String wholeID = DocumentsContract.getDocumentId(uri);

wholeID는 파일명이 abc.zip이라면 /document/B5D7-1CE9:abc.zip와 같습니다.

    // Split at colon, use second item in the array
    String id = wholeID.split(":")[1];

    Log.e(TAG, "id = " + id);

    String[] column = { MediaStore.Files.FileColumns.DATA };

파일의 이름을 통해 where 조건식을 만듭니다.

    String sel = MediaStore.Files.FileColumns.DATA + " LIKE '%" + id + "%'";

External storage에 있는 파일의 DB를 접근하는 방법 입니다.
    Cursor cursor = getContentResolver().query(MediaStore.Files.getContentUri("external"),
            column, sel, null, null);

SQL문으로 표현하면 아래와 같이 되겠죠????
SELECT _dtat FROM files WHERE _data LIKE '%selected file name%'

    int columnIndex = cursor.getColumnIndex(column[0]);

    if (cursor.moveToFirst()) {
        filePath = cursor.getString(columnIndex);
    }
    cursor.close();
    return filePath;
}


2015년 7월 27일 월요일

How to write images without fastboot on ODROID-XU4(android)

You can not use fastboot on ODROID-XU4, because It doesn't have USB otg port.

How to write images?

First! setup adb connection or copy image to fat partition.


http://codewalkerster.blogspot.kr/2015/07/adb-connect-over-tcpip-when-multiple.html

Push image to fat partition.

$ adb push xxxx.img /storage/sdcard0/
$ adb reboot

Enter u-boot prompt.


U-Boot 2012.07-00029-g0e9204d-dirty (Jul 17 2015 - 15:38:42) for Exynos5422

CPU: Exynos5422 Rev0.1 [Samsung SOC on SMP Platform Base on ARM CortexA7]
APLL = 800MHz, KPLL = 800MHz
MPLL = 532MHz, BPLL = 825MHz

Board: HardKernel ODROID
DRAM:  2 GiB
WARNING: Caches not enabled

TrustZone Enabled BSP
BL1 version: �/� ⁁
VDD_KFC: 0x44
LDO19: 0xf2

Checking Boot Mode ... SDMMC
MMC:   S5P_MSHC2: 0, S5P_MSHC0: 1
MMC Device 0: 7.4 GiB
MMC Device 1: [ERROR] response timeout error : 00000104 cmd 1
Card did not respond to voltage select!
*** Warning - bad CRC, using default environment

In:    serial
Out:   serial
Err:   serial
Net:   No ethernet found.
Double Press 'Enter' to stop autoboot:  0
Exynos5422 #


Example for zImage-dtb

Exynos5422 # fatload mmc 0:1 40008000 zImage-dtb
there are pending interrupts 0x00000001
reading zImage-dtb

4718814 bytes read
Exynos5422 # movi write kernel 0 40008000
writing kernel..device 0 Start 1263, Count 16384
MMC write: dev # 0, block # 1263, count 16384 ... 16384 blocks write: OK
completed
Exynos5422 #

Example for system.img

Exynos5422 # fatload mmc 0:1 40000000 system.img
there are pending interrupts 0x00000001
reading system.img

355139392 bytes read
Exynos5422 # fastboot flash system 40000000 0
[Partition table on MoviNAND]
ptn 0 name='fwbl1' start=0x0 len=N/A (use hard-coded info. (cmd: movi))
ptn 1 name='bl2' start=N/A len=N/A (use hard-coded info. (cmd: movi))
ptn 2 name='bootloader' start=N/A len=N/A (use hard-coded info. (cmd: movi))
ptn 3 name='tzsw' start=N/A len=N/A (use hard-coded info. (cmd: movi))
ptn 4 name='kernel' start=N/A len=N/A (use hard-coded info. (cmd: movi))
ptn 5 name='ramdisk' start=N/A len=0x800000(~8192KB) (use hard-coded info. (cmd)
ptn 6 name='system' start=0x42B5800 len=0x40648800(~1055010KB) 
ptn 7 name='userdata' start=0x448FE000 len=0x80527800(~2102430KB) 
ptn 8 name='cache' start=0xC4E25800 len=0x1036C800(~265650KB) 
ptn 9 name='fat' start=0xD5192000 len=0x1002E5800(~4197270KB) 
flashing 'system'
Compressed ext4 image
*** erase start block 0x215ac ***
*** erase block length 0x202ff0 ***
mmc erase user 0 21800 202c00

MMC erase: dev # 0, block # 137216, count 2108416 ... START: 137216 BLOCK: 21086
high_capacity: 1
Capacity: 2
byte_addressing
before_send_cmd
start_addr
end_addr
erase_addr

Erase
........................................
........................................
........................................
........................................
........................................
..........
 1.0 GB erase Done
2108416 blocks erase: OK

MMC write: dev # 0, block # 136620, count 8 ... 8 blocks write: OK

MMC write: dev # 0, block # 136628, count 8 ... 8 blocks write: OK

MMC write: dev # 0, block # 136636, count 504 ... 504 blocks write: OK
......
.....




You can find other command to write image in this boot.ini files.

boot.ini for eMMC

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#------------------------------------------------------------------------------------------------------
#
# EMMC to EMMC Recovery boot.ini text file
#
#------------------------------------------------------------------------------------------------------
ODROIDXU-UBOOT-CONFIG
#------------------------------------------------------------------------------------------------------
# BL1 write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 bl1.bin
emmc open 0
movi w z f 0 40008000
emmc close 0
#------------------------------------------------------------------------------------------------------
# BL2 write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 bl2.bin
emmc open 0
movi w z b 0 40008000
emmc close 0
#------------------------------------------------------------------------------------------------------
# Bootloader write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 u-boot.bin
emmc open 0
movi w z u 0 40008000
emmc close 0
#------------------------------------------------------------------------------------------------------
# Turst Zone Soft Ware write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 tzsw.bin
emmc open 0
movi w z t 0 40008000
emmc close 0
#------------------------------------------------------------------------------------------------------
# UBOOT ENV Erase
#------------------------------------------------------------------------------------------------------
mmc write 0 40008000 0x4CF 0x20
#------------------------------------------------------------------------------------------------------
# Kernel Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 zImage-dtb
movi write kernel 0 40008000

#------------------------------------------------------------------------------------------------------
# System Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40000000 system.img

#------------------------------------------------------------------------------------------------------
# Userdata Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 57000000 userdata.img

#------------------------------------------------------------------------------------------------------
# Cache Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 61000000 cache.img

#------------------------------------------------------------------------------------------------------
# Partition Create to eMMC
#------------------------------------------------------------------------------------------------------
fdisk -c 0

#------------------------------------------------------------------------------------------------------
fastboot flash system 40000000 0
fastboot flash userdata 57000000 0
fastboot flash cache 61000000 0

#------------------------------------------------------------------------------------------------------
# SD/eMMC FAT Format
#------------------------------------------------------------------------------------------------------
fatformat mmc 0:1

reset
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


boot.ini for SD

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#------------------------------------------------------------------------------------------------------
#
# SD to SD Recovery boot.ini text file
#
#------------------------------------------------------------------------------------------------------
ODROIDXU-UBOOT-CONFIG

#------------------------------------------------------------------------------------------------------
# BL1 write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 bl1.bin
movi w f 0 40008000
#------------------------------------------------------------------------------------------------------
# BL2 write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 bl2.bin
movi w b 0 40008000
#------------------------------------------------------------------------------------------------------
# Bootloader write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 u-boot.bin
movi w u 0 40008000
#------------------------------------------------------------------------------------------------------
# Turst Zone Soft Ware write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 tzsw.bin
movi w t 0 40008000
#------------------------------------------------------------------------------------------------------
# UBOOT ENV Erase
#------------------------------------------------------------------------------------------------------
mmc write 0 40008000 0x4CF 0x20
#------------------------------------------------------------------------------------------------------
# Kernel Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 zImage-dtb
movi write kernel 0 40008000

#------------------------------------------------------------------------------------------------------
# System Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40000000 system.img

#------------------------------------------------------------------------------------------------------
# Userdata Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 57000000 userdata.img

#------------------------------------------------------------------------------------------------------
# Cache Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 61000000 cache.img

#------------------------------------------------------------------------------------------------------
# Partition Create to eMMC
#------------------------------------------------------------------------------------------------------
fdisk -c 0

#------------------------------------------------------------------------------------------------------
fastboot flash system 40000000 0
fastboot flash userdata 57000000 0
fastboot flash cache 61000000 0

#------------------------------------------------------------------------------------------------------
# SD/eMMC FAT Format
#------------------------------------------------------------------------------------------------------
fatformat mmc 0:1

reset
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

boot.ini for SD to eMMC

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
#------------------------------------------------------------------------------------------------------
#
# EMMC to EMMC Recovery boot.ini text file
#
#------------------------------------------------------------------------------------------------------
ODROIDXU-UBOOT-CONFIG
#------------------------------------------------------------------------------------------------------
# BL1 write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 bl1.bin
emmc open 1
movi w z f 1 40008000
emmc close 1
#------------------------------------------------------------------------------------------------------
# BL2 write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 bl2.bin
emmc open 1
movi w z b 1 40008000
emmc close 1
#------------------------------------------------------------------------------------------------------
# Bootloader write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 u-boot.bin
emmc open 1
movi w z u 1 40008000
emmc close 1
#------------------------------------------------------------------------------------------------------
# Turst Zone Soft Ware write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 tzsw.bin
emmc open 1
movi w z t 1 40008000
emmc close 1
#------------------------------------------------------------------------------------------------------
# UBOOT ENV Erase
#------------------------------------------------------------------------------------------------------
mmc write 1 40008000 0x4CF 0x20
#------------------------------------------------------------------------------------------------------
# Kernel Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40008000 zImage-dtb
movi write kernel 1 40008000

#------------------------------------------------------------------------------------------------------
# System Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 40000000 system.img

#------------------------------------------------------------------------------------------------------
# Userdata Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 57000000 userdata.img

#------------------------------------------------------------------------------------------------------
# Cache Image write to eMMC
#------------------------------------------------------------------------------------------------------
fatload mmc 0:1 61000000 cache.img

#------------------------------------------------------------------------------------------------------
# Partition Create to eMMC
#------------------------------------------------------------------------------------------------------
fdisk -c 1

#------------------------------------------------------------------------------------------------------
fastboot flash system 40000000 1
fastboot flash userdata 57000000 1
fastboot flash cache 61000000 1

#------------------------------------------------------------------------------------------------------
# SD/eMMC FAT Format
#------------------------------------------------------------------------------------------------------
fatformat mmc 1:1

fastboot poweroff
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$



Build android.

$ adb connect 192.168.x.x
$ cd out/target/products/odroidxu3/
$ adb push update.zip /storage/sdcard0/
$ adb push update.zip.md5sum /storage/sdcard0/

Run ODROID Update.


Now enable 'Validate file' button.



















2015년 7월 25일 토요일

How to recovery eMMC for ODROID-XU3/4

Download u-boot binaries from github.

$ git clone https://github.com/codewalkerster/android_device_hardkernel_odroidxu3.git
Cloning into 'android_device_hardkernel_odroidxu3'...
remote: Counting objects: 228, done.
remote: Compressing objects: 100% (17/17), done.
remote: Total 228 (delta 6), reused 0 (delta 0), pack-reused 211
Receiving objects: 100% (228/228), 36.68 MiB | 2.93 MiB/s, done.
Resolving deltas: 100% (94/94), done.
Checking connectivity... done.

$ cd android_device_hardkernel_odroidxu3/uboot/
$ ls
bl1.bin  bl2.bin  sd_fusing.sh  tzsw.bin  u-boot.bin
$ chmod +x ./sd_fusing.sh 

Prepare microSD and USB reader


$ cd android_device_hardkernel_odroidxu3/uboot/
$ chmod +x ./sd_fusing.sh

Check mounted point.
$ sudo fdisk -l

Fusing u-boot. 

$ sudo ./sd_fusing.sh /dev/sde
/dev/sde reader is identified.
BL1 fusing
30+1 records in
30+1 records out
15616 bytes (16 kB) copied, 0.109455 s, 143 kB/s
BL2 fusing
28+1 records in
28+1 records out
14592 bytes (15 kB) copied, 0.07118 s, 205 kB/s
u-boot fusing
582+1 records in
582+1 records out
298372 bytes (298 kB) copied, 1.02247 s, 292 kB/s
TrustZone S/W fusing
512+0 records in
512+0 records out
262144 bytes (262 kB) copied, 1.0057 s, 261 kB/s
U-boot image is fused successfully.
Eject SD card and insert it again.

Insert microSD card and eMMC. set switch for microSD-boot.


ODROID-XU4

 

ODROID-XU3/XU3-LITE



Connect USB-UART Module Kit and Open serial terminal.

Check last u-boot version.

U-Boot 2012.07-00029-g0e9204d-dirty (Jul 17 2015 - 15:38:42) for Exynos5422     
                                                                                
CPU: Exynos5422 Rev0.1 [Samsung SOC on SMP Platform Base on ARM CortexA7]       
APLL = 800MHz, KPLL = 800MHz                                                    
MPLL = 532MHz, BPLL = 825MHz                                                    
                                                                                
Board: HardKernel ODROID                                                        
DRAM:  2 GiB                                                                    
WARNING: Caches not enabled                                                     
                                                                                
TrustZone Enabled BSP                                                           
BL1 version: �/� �                                                            
VDD_KFC: 0x44                                                                   
LDO19: 0xf2                                                                     
                                                                                
Checking Boot Mode ... SDMMC                                                    
MMC:   S5P_MSHC2: 0, S5P_MSHC0: 1                                               
MMC Device 0: 7.4 GiB                                                           
MMC Device 1: [ERROR] response error : 00000006 cmd 8                           
[ERROR] response error : 00000006 cmd 55                                        
[ERROR] response error : 00000006 cmd 2                                         
*** Warning - bad CRC, using default environment                                
                                                                                
In:    serial                                                                   
Out:   serial                                                                   
Err:   serial                                                                   
Net:   No ethernet found.                                                       
Double Press 'Enter' to stop autoboot:  0                                       
Exynos5422 #      



                                                              
Exynos5422 # pri
baudrate=115200
bootargs=fb_x_res=1280 fb_y_res=720 vout=hdmi led_blink=1
bootcmd=    cfgload;    mmc rescan 0:1; mmc rescan 0:2;    if run loadbootscript_1;         then run bootscript;     else        if run loadbootscript_2;           then run bootscript;        else           ;
bootdelay=1
bootscript=source 40008000
copy_uboot_emmc2sd=emmc open 0;movi r z f 0 40000000;emmc close 0;movi w f 1 40000000;emmc open 0;movi r z b 0 40000000;emmc close 0;movi w b 1 40000000;emmc open 0;movi r z u 0 40000000;emmc close 0;movi w ;
copy_uboot_sd2emmc=movi r f 0 40000000;emmc open 1;movi w z f 1 40000000;emmc close 1;movi r b 0 40000000;emmc open 1;movi w z b 1 40000000;emmc close 1;movi r u 0 40000000;emmc open 1;movi w z u 1 40000000;;
default_bootcmd=echo >>> Run Default Bootcmd <<<;movi read kernel 0 40008000;movi read rootfs 0 41000000 100000;bootz 40008000 41000000
env_erase=mmc write 0 0x40008000 0x4CF 0x20;
loadbootscript_1=echo >>> Load Boot Script from mmc 0:1 <<<;fatload mmc 0:1 40008000 boot.scr
loadbootscript_2=echo >>> Load Boot Script from mmc 0:2 <<<;fatload mmc 0:2 40008000 boot.scr
loadbootscript_3=echo >>> Load Boot Script from mmc 1:1 <<<;fatload mmc 1:1 40008000 boot.scr
loadbootscript_4=echo >>> Load Boot Script from mmc 1:2 <<<;fatload mmc 1:2 40008000 boot.scr
rootfslen= 100000
stderr=serial
stdin=serial
stdout=serial

Environment size: 1657/16380 bytes






Exynos5422 # run copy_uboot_sd2emmc
reading FWBL1 ..device 0 Start 1, Count 30 
MMC read: dev # 0, block # 1, count 30 ... 30 blocks read: OK
completed
eMMC OPEN Success.!!
                        !!!Notice!!!
!You must close eMMC boot Partition after all image writing!
!eMMC boot partition has continuity at image writing time.!
!So, Do not close boot partition, Before, all images is written.!
writing FWBL1 ..device 1 Start 0, Count 30 
MMC write: dev # 1, block # 0, count 30 ... 30 blocks write: OK
completed
eMMC CLOSE Success.!!
reading BL2 ..device 0 Start 31, Count 32 
MMC read: dev # 0, block # 31, count 32 ... 32 blocks read: OK
completed
eMMC OPEN Success.!!
                        !!!Notice!!!
!You must close eMMC boot Partition after all image writing!
!eMMC boot partition has continuity at image writing time.!
!So, Do not close boot partition, Before, all images is written.!
writing BL2 ..device 1 Start 30, Count 32 
MMC write: dev # 1, block # 30, count 32 ... 32 blocks write: OK
completed
eMMC CLOSE Success.!!
reading bootloader..device 0 Start 63, Count 656 
MMC read: dev # 0, block # 63, count 656 ... 656 blocks read: OK
completed
eMMC OPEN Success.!!
                        !!!Notice!!!
!You must close eMMC boot Partition after all image writing!
!eMMC boot partition has continuity at image writing time.!
!So, Do not close boot partition, Before, all images is written.!
writing bootloader..device 1 Start 62, Count 656 
MMC write: dev # 1, block # 62, count 656 ... 656 blocks write: OK
completed
eMMC CLOSE Success.!!
reading 0 TrustZone S/W.. Start 719, Count 512 
MMC read: dev # 0, block # 719, count 512 ... 512 blocks read: OK
completed
eMMC OPEN Success.!!
                        !!!Notice!!!
!You must close eMMC boot Partition after all image writing!
!eMMC boot partition has continuity at image writing time.!
!So, Do not close boot partition, Before, all images is written.!
writing 1 TrustZone S/W.. Start 718, Count 512 
MMC write: dev # 1, block # 718, count 512 ... 512 blocks write: OK
completed
eMMC CLOSE Success.!!

MMC write: dev # 1, block # 1231, count 32 ... 32 blocks write: OK
Exynos5422 # 


Download sd to eMMC self installer image.


Recovery u-boot and android automatically.

2015년 7월 24일 금요일

adb connect over TCPIP when Multiple Devices

Get all device's IP.

shell@odroidxu3:/ $ su                                                          
root@odroidxu3:/ # netcfg                                                       
lo       UP                                   127.0.0.1/8   0x00000049 00:00:000
eth0     UP                               192.168.0.1/24  0x00001043 fa:e2:864
sit0     DOWN                                   0.0.0.0/0   0x00000080 00:00:000
ip6tnl0  DOWN                                   0.0.0.0/0   0x00000080 00:00:000
root@odroidxu3:/ # 

eth0 -> adb over Ethernet.
wlan0 -> adb over Wi-Fi.

device1 ip 192.168.0.1
device2 ip 192.168.0.2
device3 ip 192.168.0.3
......
deviceN ip 192.168.0.N

Restart adbd service at all devices.

root@odroidxu3:/ # setprop service.adb.tcp.port 5555     
root@odroidxu3:/ # stop adbd && start adbd                                      
[  286.223070] [c4] adb_release                                                 
[  286.224485] [c4] dwc3 12400000.dwc3: request de1f4f80 was not queued to ep0ot
root@odroidxu3:/ [  286.239830] [c1] adb_open                                   
[  286.242450] [c6] adb_bind_config                                             

Or Edit /system/build.prop. No more stop and start adbd.

add this line.
$ su
# mount -o rw,remount /system
# vi /system/build.prop

service.adb.tcp.port=5555

Connect device on 192.168.0.1

[~]$ adb connect 192.168.0.1
connected to 192.168.0.1:5555


[~]$ adb logcat

--------- beginning of /dev/log/main
I/installd( 2785): installd firing up
I/DEBUG   ( 2780): debuggerd: Jul  2 2015 14:27:22
I/Netd    ( 2779): Netd 1.0 starting
W/InterfaceController( 2779): Warning (dlopen failed: library "/system/lib/libnetcmdiface.so" not found) while opening the net interface command library
--------- beginning of /dev/log/system
I/Vold    ( 2774): Vold 2.1 (the revenge) firing up
E/Vold    ( 2774): boot_mode = 0
E/Vold    ( 2774): eMMC boot_mode
D/Vold    ( 2774): Volume sdcard0 state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume sdcard1 state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume usb2host state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume usb3host state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume usb3device state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume sdcard0 state changing 0 (No-Media) -> 1 (Idle-Unmounted)
W/Vold    ( 2774): Duplicate state (1)
W/Vold    ( 2774): Duplicate state (1)

On other terminal

[~]$ adb devices
List of devices attached 
192.168.0.1:5555 device

Connect deivce on 192.168.0.2

[~]$ adb connect 192.168.0.2
connected to 192.168.0.2:5555

There are multiple devices.

[~]$ adb devices
List of devices attached 
192.168.0.1:5555 device
192.168.0.2:5555 device

If you connect other device, It is impossible.

[~]$ adb logcat
- waiting for device -
error: more than one device and emulator

You can solve by option '-s'

[~]$ adb -s 192.168.0.2:5555 logcat
--------- beginning of /dev/log/main
I/installd( 2785): installd firing up
I/DEBUG   ( 2780): debuggerd: Jul  2 2015 14:27:22
I/Netd    ( 2779): Netd 1.0 starting
W/InterfaceController( 2779): Warning (dlopen failed: library "/system/lib/libnetcmdiface.so" not found) while opening the net interface command library
--------- beginning of /dev/log/system
I/Vold    ( 2774): Vold 2.1 (the revenge) firing up
E/Vold    ( 2774): boot_mode = 0
E/Vold    ( 2774): eMMC boot_mode
D/Vold    ( 2774): Volume sdcard0 state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume sdcard1 state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume usb2host state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume usb3host state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume usb3device state changing -1 (Initializing) -> 0 (No-Media)
D/Vold    ( 2774): Volume sdcard0 state changing 0 (No-Media) -> 1 (Idle-Unmounted)
W/Vold    ( 2774): Duplicate state (1)
W/Vold    ( 2774): Duplicate state (1)

2015년 7월 22일 수요일

How to use UPS on Android(ODROID-U3)

http://www.hardkernel.com/main/products/prdt_info.php?g_code=G142353865593

Auto shutdown Script on Linux


http://odroid.com/dokuwiki/doku.php?id=en:odroid-ups2

We will use UPS on Android.


Select CONFIG_GPIO_SYSFS



build kernel

$ make -j8

copy drivers

$ adb remount
$ find -name *.ko | xargs -i adb push {} /system/lib/modules/

write kernel

# fastboot flash kernel arch/arm/boot/zImage
# fastboot reboot

make ups2.sh

-------------------------------------------------------------------------------------------------------------------
#!/bin/sh
SYSFS_GPIO_DIR="/sys/class/gpio"

retval=""

gpio_export()
{
[ -e "$SYSFS_GPIO_DIR/gpio$1" ] && return 0
echo $1 > "$SYSFS_GPIO_DIR/export"
echo $1
}

gpio_getvalue()
{
echo in > "$SYSFS_GPIO_DIR/gpio$1/direction"
val=`cat "$SYSFS_GPIO_DIR/gpio$1/value"`
retval=$val
}

gpio_setvalue()
{
echo out > "$SYSFS_GPIO_DIR/gpio$1/direction"
echo $2 > "$SYSFS_GPIO_DIR/gpio$1/value"
}

AC_OK_GPIO=199
BAT_OK_GPIO=200
LATCH_GPIO=204
gpio_export $LATCH_GPIO 
gpio_setvalue $LATCH_GPIO 1

check()
{
gpio_export $AC_OK_GPIO
gpio_export $BAT_OK_GPIO
gpio_getvalue $AC_OK_GPIO

if [ $retval -eq  1 ]
then
echo "DC Input Okay"
else
echo "Power is shutdown or AC Adaptor is disconnected"
gpio_getvalue $BAT_OK_GPIO
echo $retval
if [ $retval -eq 0 ]
then
echo "battery is low than 3.7V"
poweroff -d 5

else
echo "battery is good"
fi
fi
}

while true
do check
sleep 2
done
-------------------------------------------------------------------------------------------------------------------

copy script and modify permission.

$ adb remount
$ adb push ups2.sh /system/bin
$ adb shell
# chmod 777 /system/bin/ups2.sh

register service

# mount -o rw,remount /
# vi /init.odroidu.rc
add this in end of file.

service ups /system/bin/ups2.sh                                              
    class core                                                                  
    user root                                                                
    group root                                                      
    oneshot 


                                                           
Power is shutdown or AC Adaptor is disconnected                              
1                                                                            
battery is good                                                              
Power is shutdown or AC Adaptor is disconnected                              
1                                                                            
battery is good                                                              
Power is shutdown or AC Adaptor is disconnected                              
1                                                                            
battery is good                                                              
Power is shutdown or AC Adaptor is disconnected                              
0                                                                            
battery is low than 3.7V                                                      
[   88.089377] SysRq : Emergency Remount R/O                                  
[   88.093736] EXT4-fs (mmcblk0p2): re-mounted. Opts: (null)                  
[   88.099412] EXT4-fs (mmcblk0p3): re-mounted. Opts: (null)                  
[   88.105858] EXT4-fs (mmcblk0p4): re-mounted. Opts: (null)                  
[   88.112916] Emergency Remount complete                                    
[   88.191188] exynos4_notifier_call : System Rrestart notifier call!        
[   88.191714] exynos4_notifier_call : Done!                                  
[   88.195726] REBOOT Notifier for CPUFREQ                                    
[   88.200303] Disabling non-boot CPUs ...                                    
[   88.204077] CPU1: shutdown                                                
[   88.206946] CPU2: shutdown                                                
[   88.209279] CPU3: shutdown                                                
[   88.211703] Restarting system.

2015년 6월 9일 화요일

2015년 6월 3일 수요일

How to install GAppsInstaller(Lollipop) on ODROID-XU3 CM version

Download GAppsInstaller for Lollipop.
http://dn.odroid.com/GAPPS/GAppsInstaller_lollipop.apk



Install GAppsInstaller.




But failed.


Get root permission.
Click Build number many times.


Now find Developer options.


Root access.



go back Setting and enter Privacy.


Privacy Guard.
Check 'Enabled by default and Gapps Installer item'


Now Can install.



Reboot and go 'Play Store'.



2015년 5월 19일 화요일

GIT: unpack failed: error Missing tree

git push 할 경우 아래와 같은 나오면서 안되는 경우가 있었습니다.

error: unpack failed: error Missing tree 8fe84b8d352eedc3acd46a17de0531d38d5de4c2
fatal: Unpack error, check server log
To ssh://codewalker@xxxxxx.or.kr:29418/android_external_wpa_supplicant_8
 ! [remote rejected] HEAD -> refs/for/4412_4.4.4_master (n/a (unpacker error))

딱히 googling하여도 답을 못 찾겠더군요.

https://www.google.co.kr/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#q=%22Error:+unpack+failed:+error+Missing+tree%22&newwindow=1&start=10

수정한 파일이 특이하게 아래 포맷으로 되어 있었습니다.
$ file android.config
android.config: ISO-8859 text

일반적으로 ASCII text인데 말이죠.
wifi_display.c:               C source, ASCII text
wifi_display.h:               ASCII text

그래서 파일을 지우고 다시 만들어 ASCII text로 만들고 수정하고 push 하니 문제가 없더군요.

$ file android.config
android.config: ASCII text

결론: unpack failed가 나면 file의 속성을 확인하고 ASCII text로 만들어 보자.


2015년 4월 22일 수요일

apk unpack and repack

기존에 누군가가 만들어준 GAppsInstaller_kk.apk가 문제가 있다는 글이 포럼에 올라 왔다.

http://forum.odroid.com/viewtopic.php?f=113&t=11854&start=50

여기서 링크에 있는 GAPPs를 사용하면 문제가 해결 된다는 글이 있다.

http://wiki.cyanogenmod.org/w/Google_Apps

그래서 GAppsInstaller_kk.apk 를 풀어 위에 아래 파일로 대체 하려고 한다.

https://goo.im/gapps/gapps-kk-20140105-signed.zip/

gapps-kk-20140105-signed.zip 압축을 푼다.


 system 폴더에서 모든 파일을 선택한다.


우측 클릭 메뉴에서 Compress...를 선택한다.
gapps.tar.xz로 압축한다.



gapps.tar.xz를 gapps.xz로 변경한다.

이제 apk를 풀고 묶는 툴을 설치한다.

http://ibotpeaches.github.io/Apktool/

Apktool 2.x 버전과 Java 1.7 을 사용하였다.

http://ibotpeaches.github.io/Apktool/install/

저는 안드로이드 빌드를 위하여 1.6과 1.7 두가지 모두 설치 되어 있어서 아래와 같이 openjdk로 변경합니다.

$ sudo update-alternatives --config java

There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-6-oracle/jre/bin/java          1073      auto mode
  1            /usr/lib/jvm/java-6-oracle/jre/bin/java          1073      manual mode
  2            /usr/lib/jvm/java-6-sun/jre/bin/java             63        manual mode
* 3            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode

Press enter to keep the current choice[*], or type selection number:

apktool로 압축을 푼다.

$ apktool d GAppsInstaller_kk.apk 
I: Using Apktool 2.0.0 on GAppsInstaller_kk.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/codewalker/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

그리고 gpapps.xz를 덮어쓴다.
$ cp gapps.xz GAppsInstaller_kk/res/raw/gapps.xz

기존 GAppsInstaller_kk.apk를 지운다.
$ rm -rf GAppsInstaller_kk.apk

apktool로 묶는다.
$ apktool b GAppsInstaller_kk/
I: Using Apktool 2.0.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...

새로 만든 GAppsInstaller_kk.apk
http://dn.odroid.com/GAPPS/new/GAppsInstaller_kk.apk


2015년 4월 10일 금요일

WiringPi on ODROID-C1(Android)

WiringPi on ODROID-C1(Android)



ODROID-C1 Ubuntu에서 Raspberry Pi에서 사용되는 WiringPi를 사용할 수 있도록 porting 하였습니다.

http://odroid.com/dokuwiki/doku.php?id=en:c1_tinkering

wiringPi를 사용한 example-led 예제를 Android 에서도 사용할 수 있도록 작업을 해 보았습니다.

먼저 소스를 다운 받습니다.

git clone https://github.com/codewalkerster/example-led

다운 받은 소스를 eclipse에서 import 시킵니다.


그리고 NDK를 이용하여 wiringPi를 build합니다.

$ cd example-led/jni
$ ndk-build
Android NDK: WARNING: APP_PLATFORM android-16 is larger than android:minSdkVersion 7 in /media/codewalker/92fc070a-3bc1-43e0-af27-03d08ba9dd3e/home/codewalker/workspace/xxxx/example-led/AndroidManifest.xml  
[armeabi] Compile thumb  : wiringPi <= wiringPi.c
/media/codewalker/92fc070a-3bc1-43e0-af27-03d08ba9dd3e/home/codewalker/workspace/xxxx/example-led/jni/wiringPi/wiringPi.c:147:0: warning: "PAGE_SIZE" redefined [enabled by default]
 #define PAGE_SIZE   (4*1024)
 ^
In file included from /home/codewalker/projects/android-ndk-r10d/platforms/android-21/arch-arm/usr/include/signal.h:34:0,
                 from /home/codewalker/projects/android-ndk-r10d/platforms/android-21/arch-arm/usr/include/poll.h:34,
                 from /media/codewalker/92fc070a-3bc1-43e0-af27-03d08ba9dd3e/home/codewalker/workspace/xxxx/example-led/jni/wiringPi/wiringPi.c:59:
/home/codewalker/projects/android-ndk-r10d/platforms/android-21/arch-arm/usr/include/limits.h:119:0: note: this is the location of the previous definition
 #define PAGE_SIZE 4096
 ^
/media/codewalker/92fc070a-3bc1-43e0-af27-03d08ba9dd3e/home/codewalker/workspace/xxxx/example-led/jni/wiringPi/wiringPi.c: In function 'interruptHandler':
/media/codewalker/92fc070a-3bc1-43e0-af27-03d08ba9dd3e/home/codewalker/workspace/xxxx/example-led/jni/wiringPi/wiringPi.c:1865:7: warning: return makes pointer from integer without a cast [enabled by default]
       return wiringPiFailure (WPI_FATAL, "wiringPiISR: wiringPi has not been initialised. Unable to continue.\n") ;
       ^
[armeabi] Compile thumb  : wiringPi <= wiringShift.c
[armeabi] Compile thumb  : wiringPi <= piHiPri.c
[armeabi] Compile thumb  : wiringPi <= piThread.c
[armeabi] Compile thumb  : wiringPi <= wiringPiSPI.c
[armeabi] Compile thumb  : wiringPi <= wiringPiI2C.c
[armeabi] Compile thumb  : wiringPi <= softPwm.c
[armeabi] Compile thumb  : wiringPi <= softTone.c
[armeabi] Compile thumb  : wiringPi <= mcp23008.c
[armeabi] Compile thumb  : wiringPi <= mcp23016.c
[armeabi] Compile thumb  : wiringPi <= mcp23017.c
[armeabi] Compile thumb  : wiringPi <= mcp23s08.c
[armeabi] Compile thumb  : wiringPi <= mcp23s17.c
[armeabi] Compile thumb  : wiringPi <= sr595.c
[armeabi] Compile thumb  : wiringPi <= pcf8574.c
[armeabi] Compile thumb  : wiringPi <= pcf8591.c
[armeabi] Compile thumb  : wiringPi <= mcp3002.c
[armeabi] Compile thumb  : wiringPi <= mcp3004.c
[armeabi] Compile thumb  : wiringPi <= mcp4802.c
[armeabi] Compile thumb  : wiringPi <= mcp3422.c
[armeabi] Compile thumb  : wiringPi <= max31855.c
[armeabi] Compile thumb  : wiringPi <= max5322.c
[armeabi] Compile thumb  : wiringPi <= sn3218.c
[armeabi] SharedLibrary  : libwiringPi.so
[armeabi] Install        : libwiringPi.so => libs/armeabi/libwiringPi.so
[armeabi] Compile thumb  : wiringPiDev <= ds1302.c
[armeabi] Compile thumb  : wiringPiDev <= maxdetect.c
[armeabi] Compile thumb  : wiringPiDev <= piNes.c
[armeabi] Compile thumb  : wiringPiDev <= gertboard.c
[armeabi] Compile thumb  : wiringPiDev <= piFace.c
[armeabi] Compile thumb  : wiringPiDev <= lcd128x64.c
[armeabi] Compile thumb  : wiringPiDev <= lcd.c
[armeabi] Compile thumb  : wiringPiDev <= piGlow.c
[armeabi] SharedLibrary  : libwiringPiDev.so
[armeabi] Install        : libwiringPiDev.so => libs/armeabi/libwiringPiDev.so
[armeabi] Compile thumb  : wpi_android <= wpi_android.c
[armeabi] SharedLibrary  : libwpi_android.so
[armeabi] Install        : libwpi_android.so => libs/armeabi/libwpi_android.so 



jni/Android.mk 에 libwingPi.so와 libwingPiDev.so 빌드하도록 추가 하였습니다.

include $(CLEAR_VARS)
LOCAL_C_INCLUDES += \
    $(NDK_PATH)/platforms/android-21/arch-arm/usr/include \
    $(LOCAL_PATH)/wiringPi

LOCAL_MODULE    := wiringPi
LOCAL_SRC_FILES := \
    wiringPi/wiringPi.c \
    wiringPi/wiringShift.c \
    wiringPi/piHiPri.c \
    wiringPi/piThread.c \
    wiringPi/wiringPiSPI.c \
    wiringPi/wiringPiI2C.c \
    wiringPi/softPwm.c \
    wiringPi/softTone.c \
    wiringPi/mcp23008.c \
    wiringPi/mcp23016.c \
    wiringPi/mcp23017.c \
    wiringPi/mcp23s08.c \
    wiringPi/mcp23s17.c \
    wiringPi/sr595.c \
    wiringPi/pcf8574.c \
    wiringPi/pcf8591.c \
    wiringPi/mcp3002.c \
    wiringPi/mcp3004.c \
    wiringPi/mcp4802.c \
    wiringPi/mcp3422.c \
    wiringPi/max31855.c \
    wiringPi/max5322.c \
    wiringPi/sn3218.c

LOCAL_CFLAGS    += -UNDEBUG -DANDROID

LOCAL_LDLIBS    := -ldl -llog
include $(BUILD_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_C_INCLUDES += \
    $(NDK_PATH)/platforms/android-21/arch-arm/usr/include \
    $(LOCAL_PATH)/wiringPi

LOCAL_MODULE    := wiringPiDev
LOCAL_SRC_FILES := \
    devLib/ds1302.c \
    devLib/maxdetect.c \
    devLib/piNes.c \
    devLib/gertboard.c \
    devLib/piFace.c \
    devLib/lcd128x64.c \
    devLib/lcd.c \
    devLib/piGlow.c

LOCAL_SHARED_LIBRARIES := libwiringPi

LOCAL_CFLAGS    += -UNDEBUG
include $(BUILD_SHARED_LIBRARY)

그리고 wirinPi에서 사용해야 하는 function을 jni 형식으로 만듭니다.

jint Java_com_hardkernel_wiringpi_MainActivity_analogRead(JNIEnv* env, jobject obj, jint port) {
    return analogRead(port);
}

void Java_com_hardkernel_wiringpi_MainActivity_digitalWrite(JNIEnv* env, jobject obj, jint port, jint onoff) {
    digitalWrite(port, onoff);
}

int Java_com_hardkernel_wiringpi_MainActivity_wiringPiSetupSys(JNIEnv* env, jobject obj) {
    wiringPiSetupSys();
    return 0;
}

사용한 GPIO를 선언합니다.

    private final int ledPorts[] = {
        97, // GPIOX.BIT0(#97)
        108, // GPIOX.BIT11(#108)
        100, // GPIOX.BIT3(#100)
        101, // GPIOX.BIT4(#101)
        105, // GPIOX.BIT8(#105)
        106, // GPIOX.BIT9(#106)
        107, // GPIOX.BIT10(#107)
        115,  // GPIOX.BIT18(#115)
        116,  // GPIOX.BIT19(#116)
        88,  // GPIOY.BIT8(#88)
        83,  // GPIOY.BIT3(#83)
        87,  // GPIOY.BIT7(#87)
        104,  // GPIOX.BIT7(#104)
        102,  // GPIOX.BIT5(#102)
        103,  // GPIOX.BIT6(#103)
        117, // GPIOX.BIT20(#117)
        99, // GPIOX.BIT2(#99)
        118, // GPIOX.BIT21(#118)
        98, // GPIOX.BIT1(#98)
    };

MainActivity에 jni function들을 선언합니다.

    public native int wiringPiSetupSys();
    public native int analogRead(int port);
    public native void digitalWrite(int port, int onoff);

    static {
        System.loadLibrary("wpi_android");
    }

/sys/class/gpio/export를 이용하여 GPIO sysfs 노드를 만듭니다.
sysfs 방식은 pinMode()를 사용할 수 없기 때문에 directionout으로 설정 합니다.
그리고 value, direction의 접근 권한을 바꿉니다.

    boolean exportGPIO() {
        try {
            DataOutputStream os = new DataOutputStream(mProcess.getOutputStream());
            for (int port: ledPorts) {
                os.writeBytes("echo " +  port + " > /sys/class/gpio/export\n");
                os.writeBytes("chmod 666 /sys/class/gpio/gpio" + port + "/direction\n");
                os.writeBytes("echo out > /sys/class/gpio/gpio" + port + "/direction\n");
                os.writeBytes("chmod 666 /sys/class/gpio/gpio" + port + "/value\n");
            }
            os.flush();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
            return false;
        }

        return true;
    }

wiringPi의 "/dev/mem"을 open 하여 mmap을 사용하는 방식으로 만들려고 하였으니 "/dev/mem"은 root가 아니면 접근을 제한하도록 되어 있어서 불가능합니다.
jni의 library에는 root 권한을 줄 방법이 없습니다.

그래서 wiringPiSetupSys()를 호출 하여 wiringPi library를 초기화 합니다.


주기적으로 update()를 호출 하도록 만들고 UI와 LED를 control 합니다.

    public void update() {
        int i = 0;
        int adcValue = 0;
        int ledPos = 0;
        if ((adcValue = analogRead (PORT_ADC1)) > 0) {
            ledPos = (adcValue * ledPorts.length * 1000) / 1024;
            ledPos = (ledPorts.length - (ledPos / 1000));
            mADC.setProgress(adcValue);
        } else
            ledPos = 0;

        for (i = 0; i < ledPorts.length; i++) {
            digitalWrite (ledPorts[i], 0);
            mLeds.get(i).setChecked(false);
        }

        for (i = 0; i < ledPos; i++) {
            digitalWrite (ledPorts[i], 1);
            mLeds.get(i).setChecked(true);
        }

        if (!mStop)
            handler.postDelayed(runnable, 100);
    }