2010年9月15日 星期三

移植Linux Kernel & Android

最近在移植這些...暫且叫東東吧!!
3G Module...
PPPOE
及一堆的協定
真的是發揮到極致了

有一天還在MSN看到一位內地同胞
跑來問我FFMPEG如何移植,
剛好我在一個英文網站有發表相關作法

移植真的很費精神,有興趣的人再一起討論!!
因目前此案是作為經濟部的計畫案
暫時無法公開

要問的私底下喔 ^^

打造硬體與軟體

最近剛好協助一家公司打造Android 硬體與軟體整合
與經濟部的計畫案
有空來看看我吧

我在資策會科技大樓
來之前用msn聯繫我吧 javatai@hotmail.com

2010年4月26日 星期一

面對限制的C++,你如何突破~來我教你

採用STLPort版本,編譯後會產生相關C++相關的Header & Lib , including RTTI & Exception.

Multiplatform C++ Standard Library (STL implementation). Many compilers and operational environments supported. Standard (ISO/IEC 14882) compliance. Maximum efficiency. Exception and thread safety. Debug mode.

請參考http://sourceforge.net/projects/stlport/

Andriod 如何添加自定義C++庫

Andriod 如何添加自定義C++庫
1. 底層添加模式,即要在編譯出的 sdk 包含要添加的 c++ 庫
目前使用複制模式,把 Webkit 目錄複製一份,取名為 Tunnel ,在其目錄下,分別修改 Javascripecore 和 webcore 下的 Android.mk

l 修改 LOCAL_MODULE 變量,這個變量的作用是為一個庫取一個獨立的名字,在編譯過程中腳本會判斷會不會有重複的庫,所以修改一下,分別修改為 libtunnelwebcore 和 libtunnelkjs ,這樣就和原有的庫不會有名字衝突。

l 修改 LOCAL_COPY_HEADERS_TO 變量,這個變量用於腳本 COPY 庫中的頭文件的時候用的,修改一下名字,腳本會在 out/target/product/generc/obj/include/ 目錄下建立一個“名字”的目錄,把指定的頭文件 Copy 進去。

l 修改 webcore 中的 LOCAL_STATIC_LIBRARIES 變量,此變量用戶指定需要包含的靜態庫,這裡改成前面的 lib tunnelkjs

l 動態庫需要指定 Map 信息,需要修改 build/core/prelink-linux-arm.map 中的信息。

這個 map 文件好像是製定動態庫的地址的,在前面註釋上面有一些地址範圍的信息,注意庫與庫之間的間隔數,如果指定不好的話編譯的時候會提示說地址空間衝突的問題。另外,注意排序,這裡要把數大的放到前面去,按照大小降序排序。

重新編譯即可,可以看到在 out 目錄下面的相對位置會產生剛才添加的靜動態庫。



2. 應用層添加模式,即在發布的 SDK 基礎上添加自定義的 C++ 庫。

此操作的目的就是對於一個第三方而言,要在自己寫的程序中調用自己的 C++ 庫,並且隨著安裝部署到 Android 的環境中的解決方案。

l 在工程的根目錄下,必須有一個 lib 目錄,在 lib 目錄下創建一個名字為 ” armeabi” 子目錄,並將所有用到的 so 庫文件放到該子目錄下。

l Java 編碼方式

在 Java 中裝載 so 庫時需要按以下方法進行:

a). 使用方法 System.load() ,該方法需要使用絕對的路徑。

b). 絕對路徑為 /data/data/”packageName”/lib/libXXX.so

packageName: 是調用方法 System.load() 的 java 類所在包的名字。

libXXX.so: 是所要裝載的 so 庫的名字。

l APK 打包

在對應用進行打包時,需要將前提條件中的 lib 目錄打進最終的 apk 包中,打包後的 apk 包結構為:





注:在這個過程中使用的是 ant 進行的工程構建。

3. 過程分析

這部分對分析的過程進行簡單的記錄,如果只需要知道如何將 so 動態庫隨 apk 一起部署,該部分對你沒有任何幫助。

過程涉及兩個方面:一方面是 apk 的打包,這方面涉及到的工具是 apkbuilder( 這個工具實際上是一個腳本文件,它最終調用了程序 apkbuilder.jar) 。另一方面是 android 對 apk 包的解析部分。

下面描述一個安裝 apk 包的過程。

4. 在 HostOS 中通過命令安裝一個 APK 包: adb install xxx.apk

ADB 的概述:

在 hostOS 的工具集中有一個工具 adb 。在第一次運行 adb 命令時, adb 會 fork 出一個子進程作為運行在 hostOS 中的一個服務,我們將它稱為 ADB-Server ,將運行命令的 adb 稱為 adb-commandline-tool 。每次我們在命令提示符中運行 adb 時都是運行 adb-commandline-tool ,而後 adb-commandline-tool 通過本地套接口鏈接到 ADB-Server ,並將命令行中的參數傳遞給 ADB-Server 。



在 targetOS 啟動時,會啟動一個守護進程 ADBD 。 ADB-Server 啟動時會鏈接到 targetOS 中的 ADBD 。在 ADB-Server 接收到 adb-commandline-tool 傳遞來的參數後,通過套接口將參數傳遞給 ADBD 。然後 ADBD 根據參數在 targetOS 執行不同的命令。



ADBD 接收到 ADB-Server 發送來的數據後,最終調用函數 handle_packet() 。



針對 ”adb install xxx.apk” 命令 handle_packet() 的調用過程如下:






handle_packet()

create_local_service_socket(name) // name: pm xxx.apk

service_to_fd(name) // name: pm xxx.apk

create_subprocess(SHELL_COMMAND, "-c", name + 6);

execl(cmd, cmd, arg0, arg1, NULL);

//cmd: "/system/bin/sh" // arg0: -c // arg1: install xxx.apk

// 注:此處的 xxx.apk 是 targetOS 上的路徑和文件名。

由 1的分析得知最終調用了 pm 工具。 pm 就是 package mamanger ,它是一腳本文件

內容如下:

base=/system

export CLASSPATH=$base/framework/pm.jar

exec app_process $base/bin com.android.commands.pm.Pm "$@"

給腳本實際上調用了工具 app_process ,並傳遞了四個參數:

參數 1: /system/bin

參數 2: com.android.commands.pm.Pm

參數 3: -c

參數 4: install xxx.apk



下面來考量 app_process 的調用流程,只是粗略的記錄了分析的過程。 App_process 源文件在 frameworks\base\cmds\app_process\app_main.cpp 中。

reference from: http://tony-life2000.spaces.live.com/blog/cns!7DA77E607F2B16BF!429.entry?wa=wsignin1.0&sa=78101085

YAGARTO (Yet Another GNU ARM ToolChain)

Introduction

For a complete C/C++ development system we need the following components:

1. GDB Server
2. Native GNU ARM toolchain for windows
3. Integrated Development Environment
This tutorial here will cover how to expand YAGARTO by Eclipse,
the Integrated Development Environment.

It is required that you already have installed the GNU ARM toolchain from part 2.


Note: This tutorial was made with Eclipse 3.5.1, the Galileo release.

It looks that this version has some problems to show the register view. If you need this feature, please use Eclipse 3.5.1, CDT 6.0.1 and the Zylin CDT Plugin. I will restore the tutorial for the old version in the next days. Please be patient...

^ top

What do you need?

To use Eclipse as an Integrated Development Environment for your toolchain you need:

a Java Runtime Environment (JRE) by Sun,
Eclipse itself,
and the Zylin CDT plugin to improve support for the GDB embedded debugging.
^ top

Download and install?

Only download, and do not install these files yet, I assumed you will download the files in your temp directory (c:\temp). We will install these files later.


Java Runtime Environment (JRE)

First we will check if the JRE is already installed on your PC. Therefore open a command prompt and type:
C:\>java -version

The result should look like:

java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)

If the Java Runtime Environment (JRE) is not installed on your PC, you can download the JRE from the following Sun website:

Java SE Downloads (about 16 MB)

Here you will find the "Java Runtime Environment (JRE) 6 Update 18" (that was the current version when I created this tutorial). Download the JRE and save it in the temp directory.

(Note: The Zylin plugin does not work with java 1.4.2)


Eclipse IDE for C/C++ Developers

Here we want to download the Eclipse IDE for C/C++ Developers which can be found at the Eclipse page itself, for the tutorial here I have used Galileo 3.5.1. Download the "Eclipse IDE for C/C++ Developers" package and save it in the temp directory.

At this point the following files should be downloaded in your temp directory:

1. jre-6u18-windows-i586.exe
2. eclipse-cpp-galileo-SR1-win32.zip
Let's start with the JRE (1). If the JRE was not installed on your PC, start the installer and follow the instructions. After the JRE installation you must unzip the Eclipse file (2). Assumed you had unzipped it on drive C:\, you will see a folder named C:\eclipse. In that folder you will find the eclipse application itself, please create a shortcut on your desktop now. You can use this shortcut later to start the eclispe application.

^ top

How to use?

The next section is a pretty large one. Go ahead and take a quick break. Visite the facilities or brew a fresh pot of tea. When you get back, we will start with Eclipse.

Click on the shortcut which you have created in the step before:



After the start of Eclipse you should see the following splash screen:



If not, you have a problem with the Java Runtime Environment. After a while Eclipse want to know where to store your projects:




I will use D:\Projekte\EclipseWorkspace for the Eclipse workspace. Enter your directory and press "OK". Now the following "Welcome" window will appear:



(Click inside the picture to expand)

Now you must install the Zylin Embedded CDT plugin. Zylin made some modifications in Eclipse CDT for Windows and created a plugin to improve the support for GDB embedded debugging in CDT. Therefore use "Help->Install New Software...":



The next window will be show up:



Press the "Add..." button and fill in the Repository information. Use zylincdt for the "Name" and for the "Location" use http://opensource.zylin.com/zylincdt .
Now the Eclipse window should look like:



Press "OK" and you must now select the feature you want to install. Select "Zylin Embedded CDT". The window should look like:



Press "Next" and "Next" again. Now you must accept the license agreements. Therefore select this options, and press "Finish". Now it can takes some time while the new software will be installed:



You must accept the Security Warning too:



After the software update you must restart Eclipse now:



Press the "Restart Now" button and wait while Eclipse will be restarted. After the restart you will see the start screen again:



Now click at the "Workbench" icon at the right edge of the window, and the next window will look like:



(Click inside the picture to expand)

What's next? Now let's start with a small example. Therefore I have created these examples for it. Download the example you need and expand the zip file in your temp directory.

Note: The examples are updated because the GDB-6.8 and higher need the following option: set mem inaccessible-by-default off

I will show you the next steps with the SAM7X256Test example. For this purpose, I expanded it in the following directory:

C:\temp\SAM7X256Test

To create an Eclipse project use: "File / New / C Project"



(Click inside the picture to expand)

The next window will be show up:



Here you will see that the "Location" is your workspace directory you created some steps above. Type in the "Project name" (I will use SAM7X256Test) and Select "Makefile project" and "-- Other Toolchain --", after this press the "Finish" button. Now the Eclipse window should look like:



(Click inside the picture to expand)

You just created your first Eclipse project. You now need to configure it. Use the "Projet" menu and remove the checkmark at "Build Automatically":



Use the "Project" menu again and select "Properties":



A new window will be opened:



(Click inside the picture to expand)

Use now the "Settings" under "C/C++ Build" page and select the "GNU Elf Parser":



(Click inside the picture to expand)

Press the "OK" button to finish this dialog.

Your project is empty and you must import the project files to Eclipse.
Use the "File / Import..." menu and select the "File System" as input source:



Press the "Next" button to open the "Import" dialog:



But what files? You downloaded one of the examples above and expanded the zip file into a temp directory (I used C:\temp\SAM7X256Test). Select this directory for "From directory" and select all files with the checkmark. Press "Finish" to close the dialog. Your project should now look like:



(Click inside the picture to expand)

Now let's "clean" the project. For this purpose use " Project / Clean...". Set the options according to the next window:



Remove the checkmark at "Start a build immediately", and press "OK". The "Console" will show the result of the "Clean" command:



(Click inside the picture to expand)

By the way, you can open any source file by simply double clicking on it. The editor will open up:



(Click inside the picture to expand)

But do not change the file. Now let's build the project using "Project / Build Project":



The project will be build, and the window look like:



(Click inside the picture to expand)

At the same time you will see the result of the build process inside the "Console" window. After a successful build process, an elf file was created:



Now it is time for a break again. When you get back, we will start to install and configure the debugger.

^ top

Configure the debugger
For the debug process we need to open the "Debug Perspective". For this purpose use "Window / Open Perspective / Debug":



The new perspective will be opened. It looks like:



(Click inside the picture to expand)

Now we need to configure the debugger. You can reach the configuration by clicking on the down arrow at the "insect" button. That brings up the pull-down menu:



And select "Debug Configuration...":



The next window will look like:



(Click inside the picture to expand)

(Oops, I hope my keyboard is teaproof, and I will be able to finish the tutorial)

Now you must decide what kind of GDB you have:

CygwWin, the GDB need Cygwin to work
Native, means the GDB was compiled for a Windows Host
We use the YAGARTO toolchain, where GDB is based on Windows. Select "Native" and press the "New" button to create a configuration of selected type. The "New" button look like:



The configuration window will be changed and look like



(Click inside the picture to expand)

Click at the "Search Project..." button and select the test_ram.elf file:



Press "OK" and change the project name from "SAM7X256Test Default" to "SAM7X256Test-RAM". This will help you later to identify your project if you want to debug in RAM or Flash. Your configuration window should now look like:



Note: This view is only the right part of the configuration window.

Select the "Debugger" tab and use the "Browse..." button to set the YAGARTO
"GDB debugger":



Now change to the "Commands" tab and insert the debugger commands:



A file called xxxxxx_ram.gdb is part of the example
(here: .\prj\sam7x256_ram_jlink.gdb). Copy and paste the contents of the sam7x256_ram_jlink.gdb text file into the "Initialize Commands" window.

Now you are done with the configuration and you may close the dialog with the "Close" button. Press "YES" to save the changes:



^ top

How to debug?
For debuging with Eclipse we will use the GDB, therefore we need a GDB Server which you have installed from part 1. Connect the J-Link EDU to the PC and to the target (do not forget to power the target) and start the J-Link GDB Server.

Now we can start the debug session. Eclipse should look like:



(Click inside the picture to expand)

The debugger will be started the first time using the configuration menu:



Here you will find your new configuration "SAM7X256Test-RAM":



(Click inside the picture to expand)

Press the "Debug" button to start the debugger. Eclipse should look like:



(Click inside the picture to expand)

The debugger is running, congratulation.

The window at the bottom is the "GDB Debugger" command window. The upper left window is the "Debug" window. Here you will find some icons for stepping through the code (some more info later). The highlighted line in the source window (main.c) is the actual line which will be executed in the next step.

The upper right window shows the "Variables". You can change the view to "Breakpoints", "Register" and "Modules". Don't worry about the strange values for a, b and c. That is OK at this time, because these variables are not yet initialized.

You can step through the code with the following button (in the Debug window):


Step Into


Step Over

Take a look at the "Variables" window. After three steps the windows should look like:



And the source window:



With the three steps from above, a = 1, b = 2 and c = 0 was executed. And the next line will be a = a + d.

Note: The line which is highlighted is not yet executed This will be done with the next step.

How to set a breakpoint?

Setting a breakpoint is very easy. Double click in the left gray area of the soucre window. I mean the area where the blue arrow is:



If you double click in line of c = a + b, a breakpoint will be set:



The blue checkmark with the blue dot is the new breakpoint. You can remove the breakpoint by double clicking on it again. Now we want to use the "Resume" button:



The program will be executed and it will stop at the breakpoint.



The value of the variables was changed to a = 2 and b = 3.

You can "Terminate and Remove" your debug task with a right click on
"SAM7X256Test-RAM" inside the "Debug" window:



(Click inside the picture to expand)

You can start the debugger again by the "insect", but at this time you will find an entry for SAM7X256Test-RAMt:




The End

The story is over, many thanks to: JRE, Eclipse and Zylin :o)

^ top

Trouble shooting
In case you have problem to stop / launch the debug process, close Eclipse the GDB Server and execute an RESET on the target. After this you can start Eclipse and the GDB Server again.

^ top

Support
If you need support, take a look here:

Java Runtime Environment
Eclipse
Zylin
If you have some problems with Eclipse, take a look at the Eclipse Community.
By the way, I am looking for a good book too, any hints are appreciated.
Reference From : http://yagarto.de/howto/yagarto2/index.html#download

2009年11月24日 星期二

Android SDK description

Android project is a software stack for mobile devices including an operating system, middleware and key applications.
Android project is a software stack for mobile devices including an operating system, middleware and key applications. Developers can create applications for the platform using the Android SDK. Applications are written using the Java programming language and run on Dalvik, a custom virtual machine designed for embedded use which runs on top of a Linux kernel.

If you want to know how to develop applications for Android, you're in the right place. This site provides a variety of documentation that will help you learn about Android and develop mobile applications for the platform.
An early look at the the Android SDK is also available. It includes sample projects with source code, development tools, an emulator, and of course all the libraries you'll need to build an Android application.

Android includes a set of core libraries that provides most of the functionality available in the core libraries of the Java programming language.

Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.

The Dalvik VM relies on the Linux kernel for underlying functionality such as threading and low-level memory management.

Android includes a set of C/C++ libraries used by various components of the Android system. These capabilities are exposed to developers through the Android application framework. Some of the core libraries are listed below:

· System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices
· Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG
· Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications
· LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view
· SGL - the underlying 2D graphics engine
· 3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer
· FreeType - bitmap and vector font rendering
· SQLite - a powerful and lightweight relational database engine available to all applications

Android will ship with a set of core applications including an email client, SMS program, calendar, maps, browser, contacts, and others. All applications are written using the Java programming language.

Android relies on Linux version 2.6 for core system services such as security, memory management, process management, network stack, and driver model. The kernel also acts as an abstraction layer between the hardware and the rest of the software stack.


Here are some key features of "Android SDK":

· Application framework enabling reuse and replacement of components
· Dalvik virtual machine optimized for mobile devices
· Integrated browser based on the open source WebKit engine
· Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
· SQLite for structured data storage
· Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
· GSM Telephony (hardware dependent)
· Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
· Camera, GPS, compass, and accelerometer (hardware dependent)
· Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE

HTC Hero: The first Android device with Flash

HTC Hero delivers a more complete web browsing experience and allows mobile users to access a broad variety of Adobe Flash technology based content available on the web today.
Adrian Ludwig from Adobe demos websites with Flash on the HTC Hero, the first Android smartphone with Flash



Learn more about Flash for Mobile
Optimize your Flash web content for mobile (PDF, 740k)