ubuntu 在 R40e 上 還有 Debian 在 Sempron 2600 上

2011年1月11日 星期二

Android PNDK, native program

在 android/development/pdk/pndk/samples/sample 有 build native code 的 sample。 包含 Makefile。 其中的 Readme : (先照貼一下) Building native code applications and libraries STEP 1 Building an application. -------- 0) set the environment variable PREBUILT to point to the Android prebuilt directory export PREBUILT=<path_to_android_src>/prebuilt/<platform> where you type in the actual path to the android source in place of <path_to_android_src> and the platform you are using instead of <platform>: either linux-x86 or darwin-x86 1) Test the pndk install by building the hello world sample application: cd <your_pndk_base>/samples/sample make clean make The sample application uses hello.c to construct the hello binary, which you can load and run on the ARM device. To achieve proper runtime behavior, verify that: * crtbegin_dynamic.o is the first linked object file * crtend_android.o is last linked object. Both are set by the config.mk file in pndk/config. 2) Test that this works correctly by attaching your ARM-based device to the USB port and installing the application (hello) you just made by (in the commands below # is the ARM device's shell prompt): NOTE: need a development build so remount opens system permissions adb remount adb push hello system/app adb shell # cd system/app # ./hello Hello from the NDK; no user libraries. # exit 3) You may also build the c++ binary hello_cpp.cpp into an application: make -f Makefile.hello_cpp clean make -f Makefile.hello_cpp hello_cpp This uses the hello_cpp.cpp and hello_cpp.h files to construct the hello_cpp binary application, which you can load and run on the ARM device. Note that we do not provide for C++ exceptions thus you must use the -fno-exceptions flag when compiling. adb push hello_cpp system/app adb shell # cd system/app # ./hello_cpp C++ example printing message: Hello world! # exit STEP 2 Building and using a library ------- Makefile.lib in pndk/sample shows how to make either a shared library or a static library from the hellolibrary.c source. The example makes the libraries libhello-shared.so and libhello-static.a . Makefile.uselib then shows how to make an application that links against either a shared or a static library. They examples shows how to build the two applications use_hellolibrary-so and use-hellolibrary-a from the source use_hellolibrary.c. 1) To make a shared library and an application that uses it: make -f Makefile.lib clean make -f Makefile.lib sharedlib make -f Makefile.uselib clean make -f Makefile.uselib use_hellolibrary-so 2) Copy the shared library libhello-shared.so to /system/lib (or the location in which shared libraries are found by the kernel on your ARM-based device.) adb push libhello-shared.so system/lib You would not typically use the -shared or -static extensions in the filename, but the distinction is important in the case where a static and shared library are made in the same directory. Giving the files different names allows you to override the link defaults that default to a static library of the same name. 3) The application, use_hellolibrary-so, can now be tested by loading and running on the ARM device. adb push use_hellolibrary-so /system/app adb shell # cd system/app # ./use_hellolibrary-so Library printing message: Hello from the NDK. # exit 4) To make a static library: make -f Makefile.lib clean make -f Makefile.lib staticlib make -f Makefile.uselib clean make -f Makefile.uselib use_hellolibrary-a 5) Test the application use_hellolibrary-a by loading and running it on the ARM device. adb push use_hellolibrary-a system/app adb shell # cd system/app # ./use_hellolibrary-a Library printing message: Hello from the NDK. # exit SUMMARY: --------- To make everything execute the following: make clean make make -f Makefile.lib clean make -f Makefile.lib make -f Makefile.uselib clean make -f Makefile.uselib make -f Makefile.hello_cpp clean make -f Makefile.hello_cpp hello_cpp You should have: * The libraries libhello-static.a and libhello-shared.so built, the latter ready for installation, * The applications hello, use_hellolibrary-a, and use_hellolibrary-so available for installation on the ARM device. 那個設定path, toolchain. base rul 的 config.mk: # Assumes PREBUILT is defined to point to the correct flavor of the prebuilt # directory in the Android source tree CC := $(PREBUILT)/toolchain/arm-eabi-4.2.1/bin/arm-eabi-gcc AR := $(PREBUILT)/toolchain/arm-eabi-4.2.1/bin/arm-eabi-ar INC := -I$(NDK_BASE)/include/bionic/libc/arch-arm/include \ -I$(NDK_BASE)/include/kernel/include \ -I$(NDK_BASE)/include/bionic/libm/include \ -I$(NDK_BASE)/include/bionic/libm/include/arm \ -I$(NDK_BASE)/include/bionic/libc/include \ -I$(NDK_BASE)/include/bionic/libstdc++/include LINK := -nostdlib -Bdynamic \ -Wl,-T,$(NDK_BASE)/config/armelf.x \ -Wl,-dynamic-linker,/system/bin/linker \ -Wl,-z,nocopyreloc \ -L$(NDK_BASE)/lib \ -Wl,-rpath-link=$(NDK_BASE)/lib \ $(NDK_BASE)/lib/crtbegin_dynamic.o POSTLINK := $(NDK_BASE)/lib/crtend_android.o %.o: %.cpp $(CC) $(CFLAGS) -fno-exceptions -fno-rtti $(INC) -o $@ -c $< %.o: %.c $(CC) $(CFLAGS) $(INC) -o $@ -c $< NDK_BASE 在 sample/Makefile : NDK_BASE := ../.. 但是好像找不到正確的 NDK_BASE 位置..
那幾個 bionic 開頭的跟其他的 include 位置都不match。
download 官方 NDK 下來也一樣,

重新 mapping 一下好了:
INC include/bionic/libc/arch-arm/include : bionic/libc/arm-arm/include include/kernel/include : include/bionic/libm/include \ include/bionic/libm/include/arm \ include/bionic/libc/include \ include/bionic/libstdc++/include
ref 一下其他的:
target thumb C: test_pthread_mutex <= system/extras/tests/bionic/libc/common/test_pthread_mutex.c

prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-gcc  
-I system/extras/tests/bionic/libc   
-I out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates   -I system/core/include   
-I hardware/libhardware/include   
-I hardware/libhardware_legacy/include   
-I hardware/ril/include   
-I dalvik/libnativehelper/include   
-I frameworks/base/include   
-I frameworks/base/opengl/include   
-I external/skia/include   
-I out/target/product/imx51_bbg/obj/include   
-I bionic/libc/arch-arm/include   
-I bionic/libc/include   
-I bionic/libstdc++/include   
-I bionic/libc/kernel/common   
-I bionic/libc/kernel/arch-arm   
-I bionic/libm/include   
-I bionic/libm/include/arch/arm   
-I bionic/libthread_db/include  

-c  -fno-exceptions -Wno-multichar -msoft-float -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -march=armv7-a -mfloat-abi=softfp -mfpu=neon 

-include system/core/include/arch/linux-arm/AndroidConfig.h 

-I system/core/include/arch/linux-arm/ 

-mthumb-interwork -DANDROID -fmessage-length=0 
-W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64   
-D_XOPEN_SOURCE=600 -DHOST     -MD 
-o out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/common/test_pthread_mutex.o 
system/extras/tests/bionic/libc/common/test_pthread_mutex.c

target Executable: test_pthread_mutex (out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/LINKED/test_pthread_mutex)

prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi-g++ 
-nostdlib -Bdynamic 
-Wl,-T,build/core/armelf.x 
-Wl,-dynamic-linker,/system/bin/linker 
-Wl,--gc-sections 
-Wl,-z,nocopyreloc 
-o out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/LINKED/test_pthread_mutex 
-Lout/target/product/imx51_bbg/obj/lib 
-Wl,-rpath-link=out/target/product/imx51_bbg/obj/lib 
-lc -lstdc++ -lm  
out/target/product/imx51_bbg/obj/lib/crtbegin_dynamic.o         
out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/common/test_pthread_mutex.o         
-Wl,--no-undefined  
-Wl,--fix-cortex-a8  

/home/charles-chang/myandroid91/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/interwork/libgcc.a 
out/target/product/imx51_bbg/obj/lib/crtend_android.o

target Non-prelinked: test_pthread_mutex (out/target/product/imx51_bbg/symbols/system/bin/test_pthread_mutex)

out/host/linux-x86/bin/acp 
-fpt 
out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/LINKED/test_pthread_mutex out/target/product/imx51_bbg/symbols/system/bin/test_pthread_mutex

target Strip: test_pthread_mutex (out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/test_pthread_mutex)

out/host/linux-x86/bin/soslim
--strip --shady --quiet 
out/target/product/imx51_bbg/symbols/system/bin/test_pthread_mutex 
--outfile out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/test_pthread_mutex

Install: 
out/target/product/imx51_bbg/system/bin/test_pthread_mutex
out/host/linux-x86/bin/acp 
-fpt 
out/target/product/imx51_bbg/obj/EXECUTABLES/test_pthread_mutex_intermediates/test_pthread_mutex 
out/target/product/imx51_bbg/system/bin/test_pthread_mutex

install X and windows manager

$lspci | grep VGA 01:00 VGA compatible controller: ATI Technologies Inc RV350 AQ [Radeon 9600] 所以 install $sudo aptitude istall xorg xserver-xorg-video-radeon mesa-utils 然後 follow instruction.. # Xorg -configure # cp /root/xorg.conf.new /etc/X11/xorg.conf edit .xinitrc #!/bin/sh exec xterm 這樣 run startx 後,已經可以開啟 X,並且有 xterm。 但是沒有 windows manager。 所以 install 一個小的: $sudo aptitude install lwm 啟動 startx 後,再下 command : lwm& 就有 windows manager 了
ref: 後續:最後還是 install gnome (aptitude install gnome) ,然後修改 .xinitrc: exec gnome-session 就可以用 startx 進入 gnome。 可是重開機後,gdm3 就直接進 gnome 了。 比較一下當初 upgrade 完 squeeze 後,gdm login 完變成black screen (只有 mouse cursor) 好像是 video driver 的問題。從 ati 改成 radeon 就是現在的版本。

2011年1月10日 星期一

pthread

pthread 的 p 是 posix,也就是 posix 標準的 thread api。 fork 的 parent 和 child 沒有任何共用的地方。 但是 thread_create 出來的 thread 和 mother(?) process/thread 共用 所有的東西。 所以 thread 間的同步控制就更重要。 pthread 的標準就包含很多 process 間同步的物件。 從resource 共用來看 process 和 thread: thread 間要共用一個 array,就宣告一個 global array 就可以。 但是 process 間要共用一個 array,在 fork 之前就要先用 shmget,shmat 準備好。
  | Unable to migrate to dependency-based boot system                                                                                     │ 
 │                                                                                                                                       │ 
 │ Tests have determined that problems in the boot system exist which prevent migration to dependency-based boot sequencing:             │ 
 │                                                                                                                                       │ 
 │ insserv: warning: script 'S25libdevmapper1.02' missing LSB tags and overrides, insserv: warning: script 'libdevmapper1.02' missing    │ 
 │ LSB tags and overrides, , package atftpd removed but not purged, package console-tools removed but not purged, package dhcdbd         │ 
 │ removed but not purged, package fam removed but not purged, package kdm removed but not purged, package mysql-server-5.0 removed but  │ 
 │ not purged, package openvpn removed but not purged, package pcscd removed but not purged, package timidity removed but not purged     │ 
 │                                                                                                                                       │ 
 │ If the reported problem is a local modification, it needs to be fixed manually. If it's a bug in the package, it should be reported   │ 
 │ to the BTS and fixed in the package. See http://wiki.debian.org/LSBInitScripts/DependencyBasedBoot for more information about how to  │ 
 │ fix the problems preventing migration.                                                                                                │ 
 │                                                                                                                                       │ 
 │ To reattempt the migration process after the problems have been fixed, run "dpkg-reconfigure sysv-rc".       

 │ Unable to migrate to dependency-based boot system                                                                                     │ 
 │                                                                                                                                       │ 
 │ Tests have determined that problems in the boot system exist which prevent migration to dependency-based boot sequencing:             │ 
 │                                                                                                                                       │ 
 │ insserv: warning: script 'S25libdevmapper1.02' missing LSB tags and overrides, insserv: warning: script 'libdevmapper1.02' missing    │ 
 │ LSB tags and overrides, , package dhcdbd removed but not purged                                                                       │ 
 │                                                                                                                                       │ 
 │ If the reported problem is a local modification, it needs to be fixed manually. If it's a bug in the package, it should be reported   │ 
 │ to the BTS and fixed in the package. See http://wiki.debian.org/LSBInitScripts/DependencyBasedBoot for more information about how to  │ 
 │ fix the problems preventing migration.                                                                                                │ 
 │                                                                                                                                       │ 
 │ To reattempt the migration process after the problems have been fixed, run "dpkg-reconfigure sysv-rc".                                │ 
 │
在 system/extra/tests/bionic/libc 是一些bionic libc function 的 test program。
其中的 Makefile 特別寫成一個 source , 一個 executable。
readme 有說明 build 的方法:
    cd system/extras/tests/bionic/libc
    mm BIONIC_TESTS=1
特別寫的 script 是:
define device-test
  $(foreach file,$(1), \
    $(eval include $(CLEAR_VARS)) \
    $(eval LOCAL_SRC_FILES := $(file)) \
    $(eval LOCAL_MODULE := $(notdir $(file:%.c=%))) \
    $(eval LOCAL_MODULE := $(LOCAL_MODULE:%.cpp=%)) \
    $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \
    $(eval LOCAL_MODULE_TAGS := tests) \
    $(eval include $(BUILD_EXECUTABLE)) \
  ) \
  $(eval EXTRA_CFLAGS :=)
endef
使用的 command:
sources := \
    common/test_getaddrinfo.c \
    common/test_gethostbyname.c \
    common/test_gethostname.c \
    common/test_pthread_cleanup_push.c \
    common/test_pthread_getcpuclockid.c \
    common/test_pthread_join.c \
    common/test_pthread_mutex.c \
    common/test_pthread_once.c \
    common/test_semaphore.c \
    common/test_seteuid.c \
    common/test_static_cpp_mutex.cpp \
    common/test_strftime_2039.c \
    common/test_tm_zone.c \
    common/test_udp.c \

EXTRA_LDLIBS := -lpthread -lrt
EXTRA_CFLAGS := -D_XOPEN_SOURCE=600 -DHOST

$(call device-test, $(sources))

2011年1月7日 星期五

memo

bionic 有 pthread_mutex 在 system/extras/tests/bionic/libc/common 有 test program,可以當做範例。

2011年1月6日 星期四

測試一下Chrome..會轉轉轉嗎?

標籤

網誌存檔