In the previous article, how to run OKL4 based application with android emulator was introduced. Here this time I will introduce another virtualization series, EmbeddedXen running on top of qemu. 

Before diving deep into this virtualization world, I knew there are only two XEN implementations on ARM architecture , one is XEN-ARM, don't know what exact name for this project, maintained by samsung and the other is EmbeddedXen. When I investigated two candidates to test, I could not find the source code for XEN-ARM but for EmbeddedXen, there is an official web site and source code is also available so I picked up Embedded Xen to test the feasibility and performance of virtualized embedded system.

Testing environment

Host OS: Windows XP or above
Cross compiler to compile EmbeddedXen for ARM: android NDK toolchain version arm-eabi-gcc-4.2.1
Compiler to compile qemu: latest MinGW gcc.

Building EmbeddedXen

There is already a good wiki page explaining to build and test but in Windows machine, some parts should be fixed and I will explain these below. It should be noted that this image, at default, can be built to be runnable on a virtual mainstone board which can be setup with qemu.

  • Download source codes: Open cygwin shell and install git if you don't have git installed using cygwin setup application. 
$ git clone git://embeddedxen.git.sourceforge.net/gitroot/embeddedxen/embeddedxen

$ cd embeddedxen
$ patch -p1 < ../embeddedxen-cygwin-patch.diff

  • Compile the sources:

$ build-embeddedxen -u -0 -x

This script will generate an u-boot compatible image which can be loaded in the virtual machine known as mainstone. This generated image is flashable and has no debugging information. If you want to debug Xen, then there is a symbolic image named as vmlinux.xen containing full debugging information. Later I will show how to debug xen code with help of gdb.


Building custom qemu executable

qemu-0.12.5 version can be compiled under MinGW shell so open MinGW shell. configure may require to install zlib and optional SDL library. In this case, here is a useful link
Original qemu source seems to have a bug which cannot start boot loader code when this embeddedXen rom is loaded so a patch file for this should be applied. Now let's do it.

  • Download source and untar it.

$ cd {work_directory}
$ wget http://download.savannah.gnu.org/releases/qemu/qemu-0.12.5.tar.gz
$ tar xvfz qemu-0.12.5.tar.gz

  • Download a patch file enable to load and run the above xen image and apply it.

$ patch -p0 < qemu-xen-mingw.diff

  • Compile qemu

$ cd qemu-0.12.5
$ configure --target-list=arm-softmmu --enable-sdl
$ make



Running EmbeddedXen

In order to simulate mainstone board on qemu, two flash files should be provided and here is the command to create them

$ cd {work_directory}
$ mkdir images
dd if=/dev/zero of=./images/flash1 bs=32M count=1
dd if=/dev/zero of=./images/flash2 bs=32M count=1

Now it is time to launch qemu with embeddedXen image

$ qemu-0.12.5/arm-softmmu/qemu-system-arm -localtime -M mainstone -kernel embeddedxen/xen/arch/arm/boot/uImage.mainstone -pflash ./images/flash1 -pflash ./images/flash2 -m 256 -serial telnet::4444,server



Debugging EmbeddedXen with gdb

As you can see in the above picture, there seems to be some bug in the xen code around mapping I/O of mainstone. You want to debug it? No problem, here is the instruction.

1. Add -s and -S option in the above command line. "-s" option make gdb enable remote debugging through TCP::1234 and "-S" option make qemu wait until gdb connection is established.

$ qemu-0.12.5/arm-softmmu/qemu-system-arm -localtime -M mainstone -kernel embeddedxen/xen/arch/arm/boot/uImage.mainstone -pflash ./images/flash1 -pflash ./images/flash2 -m 256 -serial telnet::4444,server -s -S

2. Open telnet session with address 127.0.0.1:4444 and connect.

3. After telnet connection for serial console is made, open another shell windows and run gdb and set break point.

$ cd {work_directory}
$ arm-eabi-gdb embeddedxen/vmlinux.xen
(gdb) br __start_xen_arm
(gdb) target remote :1234
(gdb) c


Then after few second, gdb will be waiting for user input at the break point.

(gdb) br __start_xen_arm
Breakpoint 1 at 0xff0089bc: file xen/arch/arm/hypervisor/setup.c, line 550.
(gdb) c
The program is not being run.
(gdb) target remote :1234
Remote debugging using :1234
[New Thread 1]
0xa0000000 in ?? ()
(gdb) c
Continuing.

Breakpoint 1, __start_xen_arm () at xen/arch/arm/hypervisor/setup.c:550
550             mbi.mods_count = 1;
(gdb)



free counters
Posted by kevino
,
If you are very poor developer who cannot afford to buy any cheep ARM evaluation kit, then qemu arm version including Google android emulator is a very good tool to experiment any embedded sw stuffs.

Here some instruction to run a basic C application to print "hello" message on Android emulator are shown.
All information listed here are all taken from the following very useful link and I modified source a little bit to support Android serial console out. 


So I will explain my modifications only which comes from the different serial port configuation used to stdio between versatilepb and android goldfish.

#define GOLDFISH_TTY_PUT_CHAR (*(volatile unsigned int *)0xff002000)

/*
 * This does not append a newline
 */
static void putc(int c)
{
GOLDFISH_TTY_PUT_CHAR = c;

void print_uart0(const char *s) {
 while(*s != '\0') { /* Loop until end of string */
 putc(*s); /* Transmit char */
 s++; /* Next char */
 }
}

Full source code can be downloaded here and compiling it will generate test.bin. It can be compiled with google arm tool chain version 4.2.1 included in Android NDK and include that into current PATH list.
mkdir baremetal
cd baremetal
unzip ../baremetal.zip
./bd.sh

To test this bare metal app, 

export ANDROID_SDK_ROOT={path to android sdk}

emulator @fry -kernel ./test.bin










Posted by kevino
,
I do most jobs on Windows for convenience and it makes me to find a way to port some useful linux applications. Here I introduce how to compile okl4_android_3.0 and emulator application runnable on Windows. If you want linux version, then see original link. http://ertos.nicta.com.au/software/okl4htcdream/


Compile android_emulator-ok using MinGW ( Edit: Do not use this. This windows version seems to have problem in dynamic translation from ARM code to x86 ).

1. Download emulator source. android-emulator-ok.tar.gz
2. Unrar it to {emulator_path}.
3. Apply the patch. 
4. Before running build-emulator.sh to build emulator, an sdl package should be compiled but the sdl source included in the above tar file has a compile error with mingw so I recommend to find different way.
5. Download qemu package included android froyo version. http://android.git.kernel.org/?p=platform/external/qemu.git;a=summary
6. Untar qemu package to {qemu_path}
7. cd {qemu_path}/distrib/sdl-1.2.12
8. ./android-rebuild.sh --sdl-config=$LOCAL/bin/sdl-config
9. Now ready to compile emulator
10. cd {emulator_path}/qemu
11. ./android-rebuild.sh --sdl-config=$LOCAL/bin/sdl-config --install=$CURDIR/emulator


Compile qemu included in latest android version using MinGW.

2. build SDL first
cd /d/work/qemu/distrib/sdl-1.2.12
./android-configure --prefix=/d/work/local
make
make install

3. Download below patch and apply it.
4. Build qemu
cd /d/work/qemu
./android-configure.sh --sdl-config=/d/work/local/bin/sdl-config
make



Compile okl4-android_3.0 using cygwin

Build okl4_android-3.0 binary using cygwin. Because python lower version 2.6 is required to compile okl4 source tree without any compile error, we need to install cygwin with python version 2.5 and it could not be done in MinGW. Please correct me if I am wrong.

1. For successful compile, setup build environment.
2. Download android-ndk package
3. Install it somewhere
4. export PATH={ndk_root}/build\prebuilt\windows\arm-eabi-4.2.1\bin:$PATH
5. Download soruce : okl4-android-3.0.tar.bz2
6. cd {okl4_path}
7. tar xfvj okl4-android_3.0.tar.bz2
8. Download and apply the patch. 
9. cd okl4-android_3.0
10. tools/build.py machine=androidsim project=examples example=hello PYFREEZE=False TOOLCHAIN=gnu_arm_eabi_toolchain
11. The above command will generate image.elf file successfully but failed to generate image.boot file. I don't know about python and someone will help me what is wrong?



Running emulator with okl4 test app under MinGW

1. Create an avd file(here froyo) required to run android emulator
2. Run emulator with okl4 example
cd /d/work/
./qemu/objs/emulator.exe @cupcake -os-type okl4 -show-kernel -verbose -kernel ../images/image.boot.bin




Posted by kevino
,

1. How to change file ownership

ex) adb  shell chown 0.2000 /system/bin/bluetoothd


2. android_filesystem_config.h contains predefined User and Group IDs

3. What you must check when kernel panic happens:

Brad Davis  
프로필 보기  
 추가 옵션 9월4일, 오전1시45분
And read all the other "Kernel panic" threads for all the other 
suggestions. 

Again (as a summary): 

1. You need a double buffering frame-buffer driver. 
2. You need MMAP() support on the /data file system. 
3. You need all the Android specific kernel code enabled in your 
kernel. 
4. You need enough RAM to run all the Android code (start with 
192meg). 
5. You need various other features of the Linux kernel enabled and 
running (see a config file from a running Android build). 
6. You may need specific support for your board (drivers and/or 
binding subsystems to drivers). 
7. You may need specific support for your processor architecture (and 
don't assume all architectures are equal). 
8. You need a working fake (if not real) power management driver. 

You also need to be able to use logcat to see the userland log 
messages to see where the system is really dieing. 



Posted by kevino
,

1. First download latest android SDK( any version older than R06 may not work properly )
2. Add path to the tool folder of android SDK
3. Run adb server as root.
sudo adb root

4. Edit android rule file as in this link: http://developer.android.com/guide/developing/device.html

5. Check if device is listed correctly.
Posted by kevino
,

1. NDK 컴파일 방법

2. NDK로 실행파일 만드는 방법 2가지

3. 실행 파일 이나 .so파일을 쉽게 설치하기 위한 bash script 예제

   % 일반적인 폰에서는 .so파일이 설치되는 /system/lib 폴더의 용량이 여유롭지 않아 다소 많은 용량을 설치하기가 어려운데 app2sdcard 기능이 설치되어 있는 경우 추가적으로 /system/sd/expstick/lib에도 설치가 가능해졌다. 이러한 환경에서 수작업으로 파일들을 설치하기가 번거로와 이를 자동으로 처리해 주는 bash script를 작성해 보았다.

#!/bin/bash
# bash for loop

VAR="test.so"
defpath=out/apps/$1/armeabi
target_lib_path=/system/sd/expstick/lib
target_bin_path=/data/tmp
cd $defpath
echo "Current path is "  "$(pwd)"

for f in $( ls . ); do
# echo $f
if  test -f $f ; then
    echo $f "is a file"
    # search ".so"
    if [[ "$f" =~ t*.so ]]
    then
#echo $f "is dynamic library"
echo $f " Install to " $target_lib_path
        adb push ./$f $target_lib_path
    else
if test -x $f ;
then
#echo $f "is executable"
echo $f " Install to " $target_bin_path
adb push ./$f $target_bin_path
adb shell chmod 4777 $target_bin_path/$f
fi
     fi
else
     echo $f "is not a file"
fi
done 


Posted by kevino
,

Original Link: http://betelco.blogspot.com/2010/01/buildingdebugging-android-native-c.html

Building/Debugging android native C applications

In this post I will explain how to compile, install and debug an Android native "C" application.
If you are reading this post just because you have googled the magic keywords ("android" + "native code") then you should know that there is an easier way to build native applications using android makefiles ("Android.mk" and "Application.mk").
The method I'm describing here is only useful if you want to understand how things work in order to create more complexstandard GNU makefiles. This is also useful if you would like to create your own GNU autotools wrappers to compile projects using GNU configure.
I'm using Windows Vista as host machine but any other supported platforms (e.g. linux-x86 or darwin-x86) should work.

I have tested both the NDK (1.6) and SDK (2.1) on:
  • Windows XP (32-bit) and Vista (64-bit)
  • Mac OS X Snow Leopard
  • Ubuntu Intrepid
Installing Android SDK

To download the latest Android SDK, visit this address http://developer.android.com/sdk/index.html.
If you need information on how to install the SDK, visit this address http://developer.android.com/sdk/installing.html.
If the "SDK setup" fail to update the installed packages you can change the remote site URL from https://dl-ssl.google.com/android/repository/repository.xml to http://dl-ssl.google.com/android/repository/repository.xml (change the URL scheme from HTTPS to HTTP) or try to disable your anti-virus or firewall.

I have installed the SDK version 2.1 under c:/android-sdk (a.r.a /cygdrive/c/android-sdk).
Add an environment variable named ANDROID_SDK_ROOT pointing to the SDK root directory.

Important: You should add "$ANDROID_SDK_ROOT/tools" directory to the $PATH environment variable.
Under *nix:

export PATH=$ANDROID_SDK_ROOT/tools:$PATH
Under Cygwin: Open C:\Cygwin\Cygwin.bat and add:

set PATH=%ANDROID_SDK_TOOLS%;%PATH%
Installing Cygwin

If you are using Windows XP or Vista as host machine then you MUST install Cygwin Devel package with GNU Make (3.81 or later) before installing the NDK.
It should also work with MinGW.

Installing the Android NDK

To download the latest Android NDK, visit this address http://developer.android.com/sdk/ndk/1.6_r1/index.html.
I have uncompressed the NDK version 1.6 under c:/android-ndk (a.r.a /cygdrive/c/android-ndk).
Add an environment variable named ANDROID_NDK_ROOT pointing to the NDK root directory.
To install the NDK:

cd $ANDROID_NDK_ROOT
build/host-setup.sh
If all is OK then the console will print Host setup complete.
To test that the toolchain has been correctly installed you can try to build the hello-jni sample which comes with the NDK by doing this:

cd $ANDROID_NDK_ROOT
make -APP=hello-jni
If all is OK then the console will print:

Android NDK: Building for application 'hello-jni'
Compile thumb : hello-jni <= sources/samples/hello-jni/hello-jni.c SharedLibrary : libhello-jni.so Install : libhello-jni.so => apps/hello-jni/project/libs/armeabi
This mean that your native shared library (libhello-jni.so) have been successfully generated under$ANDROID_NDK_ROOT/apps/hello-jni/project/libs/armeabi folder.

Creating an AVD

AVD stands for Android Virtual Device and can be seen as a device profile (keyboard, dialing pad, skin, screen dimensions, appearance ...) to load into your emulator. You can create as many AVDs as you need.
To create an AVD named "avdtest" targeting platform 2.1 (targetID=android-7):

android create avd -n avdtest -t android-7
If all is OK the console will print:

Created AVD 'avdtest' based on Android 2.1, with the following hardware config: hw.lcd.density=160
Create test.c

Here I will create a basic test.c file under C:\tmp with the following content:

#include <stdio.h>// printf

int main(int argc, char **argv)
{
int i = 1;
i+=2;

printf("Hello, world (i=%d)!\n", i);

return 0;
}
Create makefile

Just create an empty file named makefile (without any extension) under C:\tmp (which is the same directory as test.c).
Now We will fill the makefile step by step.

Add application name, $ROOT directory, install directory and the NDK platform version:

APP := test
ROOT:=/cygdrive/c
NDK_PLATFORM_VER := 1.5
INSTALL_DIR := /data/tm
Add useful environment vars:

ANDROID_NDK_ROOT:=$(ROOT)/android-ndk
ANDROID_NDK_HOST:=windows
ANDROID_SDK_ROOT:=$(ROOT)/android-sdk
PREBUILD:=$(ANDROID_NDK_ROOT)/build/prebuilt/$(ANDROID_NDK_HOST)/arm-eabi-4.2.1
BIN := $(PREBUILD)/bin
You MUST change ANDROID_NDK_HOST value from windows to linux-x86 if you are under *nix or darwin-x86 on MAC OS X.

Add GCC options:

CPP := $(BIN)/arm-eabi-g++
CC := $(BIN)/arm-eabi-gcc
CFLAGS :=
LDFLAGS := -Wl
Add targets

all: $(APP)

OBJS += $(APP).o

$(APP): $(OBJS)
$(CPP) $(LDFLAGS) -o $@ $^

%.o: %.c
$(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@
install: $(APP)
$(ANDROID_SDK_ROOT)/tools/adb push $(APP) $(INSTALL_DIR)/$(APP)
$(ANDROID_SDK_ROOT)/tools/adb shell chmod 777 $(INSTALL_DIR)/$(APP)

shell:
$(ANDROID_SDK_ROOT)/tools/adb shell

run:
$(ANDROID_SDK_ROOT)/tools/adb shell $(INSTALL_DIR)/$(APP)

clean:
@rm -f $(APP).o $(APP)
Building the application

To build the application, switch to the directory where you have created both files and then:

make
At the output of the console you will get many errors saying that it's impossible to find stdlib.h, stdio.h etc etc.
To resolve this issue, add the Bionic header files to $CFLAGS variable like this:

CFLAGS := -I$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/include
If you retry (make) you will now get this link error:

rt0.o: No such file: No such file or directory
To avoid directly linking against the "C runtime" you must add "-nostdlib" flag to the link options like this:

LDFLAGS := -Wl -nostdlib
If you retry (make) you will now get these link errors:

test.c:(.text+0x34): undefined reference to `printf'
test.c:(.text+0x3c): undefined reference to `exit'
You get these errors because Bionic libc is missing. To add libc you MUST change $LDFLAGS like this:

LDFLAGS := -Wl -L$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib
LDFLAGS += -nostdlib -lc

If you retry (make) you will now get this link error:

/cygdrive/c/android-ndk/build/platforms/android-1.5/arch-arm/usr/lib/libc.so: undefined reference to `dl_unwind_find_exidx'
To resolve this issue you MUST specify the first set of directories into which to search the system shared libraries (*.so) . This is done by adding the "-rpath-link" option to the link options like this:

LDFLAGS := -Wl,-rpath-link=$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib -L$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib
If you retry (make) you will now get this warning:

/cygdrive/c/android-ndk/build/prebuilt/windows/arm-eabi-4.2.1/bin/../lib/gcc/arm
-eabi/4.2.1/../../../../arm-eabi/bin/ld: warning: cannot find entry symbol _start; defaulting to 000082c8
This is an Android known issue. You have this warning because the linker search "_start" as entry point. You can resolve this issue by renaming your main function. But the elegant way to resolve this issue is to specify the entry point in the link options like this:

LDFLAGS := -Wl,--entry=main,-rpath-link=$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib -L$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib
LDFLAGS += -nostdlib -lc
Now When you retry (make) your application will successfully build without any errors or warnings.

Testing your application

Before testing your application you MUST run the emulator like this:

emulator -avd avdtest
where "avdtest" is the name of the previously created avd (see "creating an avd" section).
To install the application on the emulator, open a new console and go to to directory where you have created test.c andmakefile. Install your application on the emulator like this:

make install
If all is OK the console will print:

/cygdrive/c/android-sdk/tools/adb push test /data/tmp/test
304 KB/s (2493 bytes in 0.008s)
/cygdrive/c/android-sdk/tools/adb shell chmod 777 /data/tmp/test
To run the application type:

make run
You will probably get an error message saying:

/cygdrive/c/android-sdk/tools/adb shell /data/tmp/test
/data/tmp/test: not found
This error message is a bit confusing because if you browse the /data/tmp directory you will notice that the executable is here. The question is why?
I spent hours searching and I found that this error happens because the loader fails to load the application because it cannot found a proper linker.
To specify a search directory for the dynamic linker (at run time) you MUST change the link options like this:

LDFLAGS := -Wl,--entry=main,-rpath-link=$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib,-dynamic-linker=/system/bin/linker -L$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib
LDFLAGS += -nostdlib -lc
Now rebuild and install your application (make clean && make && make install) then run it again (make run).
The console will print the expected result ("hello, world (i=3)!") but just after we have an segmentation fault error("[1] Segmentation fault /data/tmp/test").
To resolve this issue you can exit the program (exit(0);) just before the main function returns (return 0;). You should also include <stdlib.h>.
If you retry the build&&run process (make clean && make && make install && make run) then you should have:

/cygdrive/c/android-sdk/tools/adb shell /data/tmp/test
Hello, world (i=3)!
which is the expected result.

Debugging your application
Before doing anything you MUST copy the gdbserver file to the emultor.
This file is under $BIN ($ANDROID_NDK_ROOT/build/prebuilt/$ANDROID_NDK_HOST/arm-eabi-4.2.1/bin).
Copy gdbserver to the emulator like this:

adb push gdbserver $INSTALL_DIR/gdbserver
adb shell chmod 777 $INSTALL_DIR/gdbserver
where $INSTALL_DIR is the directory where you have installed your application (it's not mandatory to copy it in this directory).
Before running the server on port 1234 you MUST redirect all tcp connection to this port like this:

adb forward tcp:1234: tcp:1234
it's not mandatory to forward connections to the same port number.
Now it's time to run the server:

adb shell $INSTALL_DIR/gdbserver :1234 $INSTALL_DIR/$APP
note that only the server port is specified (no host).
If all is OK the the server will print something like this:

Process /data/tmp/test created; pid = 246
Listening on port 1234
Now to debug our application we will change the makefile by adding a new debug target like this.

GDB_CLIENT := $(BIN)/arm-eabi-gdb

debug:
$(GDB_CLIENT) $(APP)

To launch the application in debug mode type "make debug" (after make clean && make && make install of course). If you do this, you will see a warning message saying that "no debugging symbols found". No symbols ==> no debug.
To generate debug symbols you MUST change the makefile like this (should not be hard coded like this):

DEBUG = -g
CFLAGS := $(DEBUG) -I$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/include
Now rebuild and install your application (make clean && make && make install) then run it again (make debug). This (make debug) should open gdb invite command((gdb)) on the same console.
Connect to the server (from the same console) like this:

target remote :1234
Set a breakpoint on the main function and execute step by step (commands above are informational and you can use any gdb commands):

b main
c
n
p i 
#$1 = 1
n
#9 printf("Hello, world (i=%d)!\n", i);
p i 
#$2 = 3
c
#Program exited normally.

The final makefile and test.c files are shown below:

makefile

APP := test
ROOT:=/cygdrive/c
INSTALL_DIR := /data/tmp
NDK_PLATFORM_VER := 1.5

ANDROID_NDK_ROOT:=$(ROOT)/android-ndk
ANDROID_NDK_HOST:=windows
ANDROID_SDK_ROOT:=$(ROOT)/android-sdk
PREBUILD:=$(ANDROID_NDK_ROOT)/build/prebuilt/$(ANDROID_NDK_HOST)/arm-eabi-4.2.1
BIN := $(PREBUILD)/bin
GDB_CLIENT := $(BIN)/arm-eabi-gdb

DEBUG = -g

CPP := $(BIN)/arm-eabi-g++
CC := $(BIN)/arm-eabi-gcc
CFLAGS := $(DEBUG) -I$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/include
LDFLAGS := -Wl,--entry=main,-rpath-link=$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib,-dynamic-linker=/system/bin/linker -L$(ANDROID_NDK_ROOT)/build/platforms/android-$(NDK_PLATFORM_VER)/arch-arm/usr/lib
LDFLAGS += -nostdlib -lc

all: $(APP)

OBJS += $(APP).o
$(APP): $(OBJS)
$(CPP) $(LDFLAGS) -o $@ $^
%.o: %.c
$(CC) -c $(INCLUDE) $(CFLAGS) $< -o $@
install: $(APP)
$(ANDROID_SDK_ROOT)/tools/adb push $(APP) $(INSTALL_DIR)/$(APP)
$(ANDROID_SDK_ROOT)/tools/adb shell chmod 777 $(INSTALL_DIR)/$(APP)
shell:
$(ANDROID_SDK_ROOT)/tools/adb shell
run:
$(ANDROID_SDK_ROOT)/tools/adb shell $(INSTALL_DIR)/$(APP)
debug:
$(GDB_CLIENT) $(APP)
clean:
@rm -f $(APP).o $(APP)


test.c

#include <stdio.h> // printf
#include <stdlib.h> //exit

int main(int argc, char **argv)
{
int i = 1;
i+=2;

printf("Hello, world (i=%d)!\n", i);

exit(0);
return 0;
}

Posted by kevino
,
To use some native C codes in java application, we need to create a jni interface. Let's see how we can create the jni C header file using javah.


1. Set up environment for build-up
1.1. Open console windows
1.2. Check whether javah is on your path. If not, refer below command.

>set path=%ProgramFiles%\Java\jdk1.6.0_17\bin;%PATH%

2. Compile java code. If you are using Eclipse and have no problem with compiling, just ignore the below line.

>java
Natives.java

3. Create a JNI C header file
3.1. Assuming that Navices.class file is located in the foler "bin\game\emulator\util\"

>javah -classpath bin -jni game.emulator.util.Natives

4. At last, we are ready to write the C function body.
4.1. To get correct method and signature, javap is a right tool. Output of below line will show the name and signature of Java native entities which can be accessed in C.

>javap -classpath bin -s -p game.emulator.util.
Natives

Other useful link: Calling Java methods

Posted by kevino
,
http://www.blogsdna.com/2166/how-to-delete-undeletable-files-in-windows-7.htm

비스타와 windows 7으로 오면서 바뀐 보안관리 정책으로 과거 XP에서 생성되었던 파일들이 vista나 windows 7으로 오면서 삭제가 되지 않던 문제가 있는데 다음과 같은 명령어를 사용하면 쉽게 파일이나 디렉토리를 삭제할 수 있다.

잊지 말아야 할 것은 다음의 명령어를 일반 커맨드창에서 사용하면 허가권이 없다고 하면서 실패하므로 관리자 권한으로 창을 띄운 후 명령어를 입력해야 한다. 예제에서는 계정을 administrator로 하였지만 자신의 계정으로 이름을 바꿀수도 있다.

For Files:

takeown /f file_name /d y
icacls file_name /grant administrators:F

For Directories (will perform action recursively):

takeown /f directory_name /r /d y
icacls directory_name /grant administrators:F /t

Please keep in mind above syntaxes will grant full permission to administrator group hence you must be a part of administrator group to take advantage of above command.

Posted by kevino
,
Posted by kevino
,