2013年2月18日 星期一

Start Build TI AM335X Android JB DevKit BSP in Fedora 16.

最近比較有空 (等PCB 回來驗證修改部份 ) , 所以在看看 TI 的 Android 吧 !!
發現 , TI release 的 Android JB for AM335x  的 BSP 了 .

一樣 在 FC16 上 build 看看吧 !! 我的 PC 還是 FC16 , 所以應該缺少的 東西不多 !
想說可以順利build 完畢 , 沒想到 .... 第一步就有問題 !!


Cross Compile 給我用 64 bit 的 ..... 我的 FC16 是 32bit 啦 !!!!
不想使用 VM machine (build 太慢) , 並且有舊的 project toolchain (32Bit ) .
好吧 , 試試看是否能 在 32 bit build .

PS. 這篇文章會陸續增加 修正的項目 .


A.先改 ./prebuilts/tools/gcc-sdk/gcc 吧.
  原始檔案使用 file -L "$SHELL" 的方式再次檢查是否 64 bit. 感覺有點多餘.
  每次都用同樣方式檢查不就可以了 ?? 修改後的 diff 如下:

--------------------------------- gcc-sdk/gcc ---------------------------------
index eac1c47..38f6317 100755
@@ -1,4 +1,5 @@
 #!/bin/bash
+# vi:set ts=4 :

 HOST_OS=`uname -s | tr '[:upper:]' '[:lower:]'`
 if [ "$HOST_OS" != "linux" ] ; then
@@ -14,27 +15,13 @@ PREFIX64=../../gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/bin/x86_64-linux

 options=" ${@} "   # sentinel prefix/suffix space to simplify pattern match below

-suffix_m32=${options##* -m32 }    # suffix after the last -m32
-suffix_m64=${options##* -m64 }    # suffix after the last -m64
-
-len_m32=${#suffix_m32}            # length of suffix after the last -m32
-len_m64=${#suffix_m64}            # length of suffix after the last -m64
-
-if [ $len_m32 -ge $len_m64 ] ; then
-  # Choose 64-bit if -m64 only, -m64 appears after -m32, or neither exist (-eq)
-  MY_TOOL=`dirname $0`/${PREFIX64}-${PROGNAME}
-  # Make sure host is running 64-bit OS.
-  # Note that "uname -m" only show host CPU is capable of.  Use the following technique
-  # from ndk/build/core/ndk-common.sh instead
-  file -L "$SHELL" | grep -q "x86[_-]64"
-  if [ $? != 0 ]; then
-    # $SHELL is not a 64-bit executable, so assume our userland is too.
-    echo "ERROR: $MY_TOOL only run on 64-bit linux"
-    exit 1
-  fi
+
+file -L "$SHELL" | grep -q "x86[_-]64"
+
+if [ $? != 0 ]; then
+    MY_TOOL=`dirname $0`/${PREFIX32}-${PROGNAME}
 else
-  # Otherwise, choose 32-bit
-  MY_TOOL=`dirname $0`/${PREFIX32}-${PROGNAME}
+    MY_TOOL=`dirname $0`/${PREFIX64}-${PROGNAME}
 fi

 $MY_TOOL "$@"


這一版本沒有 32bit 的 target toolchain , 所以由 ICS 的 版本內將的 toolchain
arm-linux-androideabi-4.4.x 複製到
./prebuild/linux-x86/toolchain/ 目錄下!!
原本應該在 ./prebuilds 下 , 不過擔心 ICS 的 toolchain 會有內部指定位置 , 所以放在和
ICS 一樣的 ./prebuild/ 目錄下.
本篇最後會有一個 env.sh 的 file , 內容會說明如何將 toolchain 指定到這邊 !!



B.Java VM 沒有辦法開啟 .
只細看一下 error message , 好像 jave 的 heap memory 太大 , 修正 下面這個檔案
./build/core/definitions.mk , diff 內容如下:

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
make: *** [out/host/common/obj/JAVA_LIBRARIES/core-hostdex_intermediates/classes.dex] Error 1
make: *** Waiting for unfinished jobs....



index 9fe0a11..2750bed 100644
@@ -1547,7 +1547,7 @@ define transform-classes.jar-to-dex
 @echo "target Dex: $(PRIVATE_MODULE)"
 @mkdir -p $(dir $@)
 $(hide) $(DX) \
-    $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx2048M) \
+    $(if $(findstring windows,$(HOST_OS)),,-JXms16M -JXmx1024M) \
     --dex --output=$@ \
     $(incremental_dex) \
     $(if $(NO_OPTIMIZE_DX), \



C.修正 TOOLCHAIN 的位置.
   這版本內部使用 64bit 的 complier , 雖然可以由環境參數設定 TARGET_TOOLS_PREFIX 的方式來解決 , 不過我的系統都是 32bit , 所以就用固定的方式吧 !
修改後的 diff 內容如下:

------------------------ core/combo/TARGET_linux-arm.mk ------------------------
index 4a461f8..569001a 100644
@@ -43,8 +43,10 @@ include $(TARGET_ARCH_SPECIFIC_MAKEFILE)

 # You can set TARGET_TOOLS_PREFIX to get gcc from somewhere else
 ifeq ($(strip $(TARGET_TOOLS_PREFIX)),)
-TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.6
-TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/arm-linux-androideabi-
+## TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.6
+## TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/arm-linux-androideabi-
+TARGET_TOOLCHAIN_ROOT := prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-eabi-4.6
+TARGET_TOOLS_PREFIX := $(TARGET_TOOLCHAIN_ROOT)/bin/arm-eabi-
 endif

 # Only define these if there's actually a gcc in there.



D.因為我的 uname -m 是 i686 , Compile 的時候會尋找 system/core/include/arch/linux-i686 和 system/core/include/arch/target_linux-i686 的內容 , 所以
就將 linux-x86 和 target_linux-x86 個別複製一份為 linux-i686 & target_linux-i686

C.修正 ./external/webkit/Source/WebCore/make-hash-tools.pl file.
    請參考前一版 ICS 的修正方式.主要是 Fedora 16  的版本比較新 , 沒有 switch 功能.


E.Make 過程如果發現 libbfd 的問題 , 就需要更改./external/oprofile/common.mk ,
   因為我們使用 i686 的 toolchain , 所以沒有 libbfd , HAVE_LIBBFD需要為 false.
   更改後的 diff 如下:


---------------------------------- common.mk ----------------------------------
index f5578b1..cc79eef 100644
@@ -45,9 +45,13 @@ HAVE_LIBBFD := true
 common_host_cflags += -DMISSING_MREMAP
 common_host_ldlibs_libiconv := -liconv
 else
+ifeq ($(shell uname -m),i686)
+HAVE_LIBBFD := false
+else
 ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
 HAVE_LIBBFD := true
 endif
 endif
+endif

 endif


D.build 到 qemu 的時候會出錯
  主要是 非 standalone 的時候會去 build 64bit 的 library , 這時候就出錯 !!
  參考一下 Makefile.common 發現設定BUILD_STANDALONE_EMULATOR 會排除
  64 bit 的 library 部份 , 先設定吧 , 到時候 qemu 要用的時候再來修正.
  diff 後的 內容如下:

---------------------------------- Android.mk ----------------------------------
index 0b02fdb..abbab01 100644
@@ -2,8 +2,11 @@
 # through the 'm' or 'mm' build commands. if not, we use the
 # standard QEMU Makefile
 #
+# vi: set ts =4 :
+
 ifeq ($(DEFAULT_GOAL),droid)
     LOCAL_PATH:= $(call my-dir)
+    BUILD_STANDALONE_EMULATOR=true
     include $(LOCAL_PATH)/Makefile.android
 else
     include Makefile.qemu



E.編譯到一半 會發現沒有 LIBBFD 
 LIBBFD 我不知道是啥東西 , 不過確定32bit 的 toolchain 沒有 , 所以修改./external/oprofile/common.mk , 這個 mk file中有指定toolchain 目錄 , 所以順便一起更改 . 只要 uname -m 是i686 就關閉 LIBBFD 和設定 32 bit 的 toolchain 位置 , diff 內容如下:

---------------------------------- common.mk ----------------------------------
index f5578b1..4b1ff6c 100644
@@ -35,7 +35,12 @@ common_target_cflags := $(common_cflags)
 HAVE_LIBBFD := false

 ifeq ($(TARGET_ARCH),arm)
+ifneq ($(shell uname -m),i686)
 toolchain := prebuilts/gcc/$(HOST_PREBUILT_TAG)/arm/arm-linux-androideabi-4.6
+else
+toolchain := prebuilts/gcc/$(HOST_PREBUILT_TAG)/toolchain/arm-linux-androideabi-4.4.x
+endif
+
 common_host_c_includes := $(common_c_includes) $(toolchain)/include
 common_host_cflags := $(common_cflags) -fexceptions -DANDROID_HOST -DHAVE_XCALLOC
 common_host_ldlibs_libiconv :=
@@ -46,8 +51,10 @@ common_host_cflags += -DMISSING_MREMAP
 common_host_ldlibs_libiconv := -liconv
 else
 ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
+ifneq ($(shell uname -m),i686)
 HAVE_LIBBFD := true
 endif
 endif
+endif

 endif


F. 編譯到 frameworks/native/libs/utils  目錄的時後會出錯
   原因是會去編譯 64 bit 的 static library.
   檢查一下 Android.mk file 發現 , default 會編譯 64 bit static library ,
   修改成不要編譯 (使用 uname -m 區別).
    Diff 的內容如下:

---------------------------- libs/utils/Android.mk ----------------------------
index ddfb83e..503126a 100644
@@ -81,6 +81,7 @@ include $(BUILD_HOST_STATIC_LIBRARY)

 # For the host, 64-bit
 # =====================================================
+ifneq ($(shell uname -m),i686)
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES:= $(commonSources)
 ifeq ($(HOST_OS), linux)
@@ -93,7 +94,7 @@ LOCAL_C_INCLUDES := \
 LOCAL_CFLAGS += $(host_commonCflags) -m64
 LOCAL_LDLIBS += $(host_commonLdlibs)
 include $(BUILD_HOST_STATIC_LIBRARY)
-
+endif

 # For the device
 # =====================================================


G.編譯到 system/core/libcutils 和 system/core/liblog 的時候會有相同錯誤
   一樣發現要 編譯 64 bit 的 static lib , 分別修正 Android.mk (使用 uname -m) .
   diff  內容分別如下:

----------------------------- libcutils/Android.mk -----------------------------
index 5c227b6..22b86bf 100644
@@ -97,6 +97,7 @@ include $(BUILD_HOST_STATIC_LIBRARY)

 # Static library for host, 64-bit
 # ========================================================
+ifneq ($(shell uname -m),i686)
 include $(CLEAR_VARS)
 LOCAL_MODULE := lib64cutils
 LOCAL_SRC_FILES := $(commonSources) $(commonHostSources) dlmalloc_stubs.c
@@ -104,7 +105,7 @@ LOCAL_LDLIBS := -lpthread
 LOCAL_STATIC_LIBRARIES := lib64log
 LOCAL_CFLAGS += $(hostSmpFlag) -m64
 include $(BUILD_HOST_STATIC_LIBRARY)
-
+endif

 # Shared and static library for target
 # ========================================================

------------------------------ liblog/Android.mk ------------------------------
index be5cec2..7fcc6bf 100644
@@ -57,6 +57,7 @@ include $(BUILD_HOST_SHARED_LIBRARY)

 # Static library for host, 64-bit
 # ========================================================
+ifneq ($(shell uname -m),i686)
 include $(CLEAR_VARS)
 LOCAL_MODULE := lib64log
 LOCAL_SRC_FILES := $(liblog_host_sources)
@@ -64,6 +65,7 @@ LOCAL_LDLIBS := -lpthread
 LOCAL_CFLAGS := -DFAKE_LOG_DEVICE=1 -m64
 include $(BUILD_HOST_STATIC_LIBRARY)

+endif

 # Shared and static library for target
 # ========================================================



H.增加環境參數設定
為了容易設定環境參數 ,增加了一個 ./env.sh file 來協助整個環境的設定.
內容如下:

#!/bin/sh
# vi: set ts=4 :

## ==== Setting PATH.
JDK_BIN_DIR=${HOME}/bin/jdk1.6.0_34/bin

TOOLCHAIN_BIN_DIR=${PWD}/prebuilts/gcc/linux-x86/arm/arm-eabi-4.6/bin

PATH1=`echo ${PATH} | sed "s|[:]${JDK_BIN_DIR}||g"`
PATH2=`echo ${PATH1} | sed "s|${JDK_BIN_DIR}[:]||g"`

PATH3=`echo ${PATH2} | sed "s|[:]${TOOLCHAIN_BIN_DIR}||g"`
PATH4=`echo ${PATH3} | sed "s|${TOOLCHAIN_BIN_DIR}[:]||g"`

PATH_E=${PATH4}

export PATH=${TOOLCHAIN_BIN_DIR}:${JDK_BIN_DIR}:${PATH_E}

export TARGET_TOOLS_PREFIX=${PWD}/prebuilt/linux-x86/toolchain/arm-linux-androideabi-4.4.x/bin/arm-linux-androideabi-
## ====

export TARGET_PRODUCT=am335xevm_sk
export OMAPES=4.x
export USE_CCACHE=1

## ==== for u-boot or kernel used.

export ARCH=arm
export CROSS_COMPILE=arm-eabi-

source ${PWD}/build/envsetup.sh

## ==================================



Some Reference Web Address:
    https://groups.google.com/forum/?fromgroups=#!topic/android-building/Rq6bS2C47S8 

    http://forum.xda-developers.com/showthread.php?p=37568464&postcount=54


目前已經可以build 完畢 , 接著要試試看有沒有問題.......

沒有想像的那樣容易  , 不能 working .
後來發現 64 bit 的系統可以跑32bit 的程式,只要安裝 所需要的 32bit library即可 !!
舊的 Project 因為 code 的關係(int 大小不, 整個 struct 也會不對 ) 不能編譯成為 64 bit !!
不過可以在 CFLAGS & LDFLAGS 額外加上 -m32 就可以編譯成為
32 bit 的程式 , 當然對應的 32bit library 也要安裝 (ex zlib-devel.i686.....等)

乖乖的轉換 64 bit system , 並且不需要修改很多東西就可以了!!

沒有留言:

張貼留言