2014年4月1日 星期二

Monitor dd progress

When we flash an image to a SD card through dd command,
we won't be able to know the progress by default.
 
If you need type sudo kill -USR1 $(pgrep ^dd) 
and you will see the progress.
 

2014年1月20日 星期一

Steps to mount .img

Ok, you may have a image with multi-partitions(for example, boot and rootfs )and you may need to access the data under rootfs, and, you don't want to flash this image.

The concept is you mount the partition inside the image you want and the following are steps.

1. find partition information
fdisk -l xxx.img
2. mount the partition as block device and have to specify the start address in bytes
 sudo losetup /dev/loop0 xxx.img -o $((Start Sectors*512))
3. mount it
sudo mount -t ext3 /dev/loop0 /mount/point

mount -o loop /path/to/image won't work in this case since the start byte does not contain file system information in this image type

2013年11月7日 星期四

Build OpenNI apk in Ubuntu shell

You should have AndroidManifest.xml in the APK root first and use the following command to generate build.xml

~/ADT/android-sdk-linux/tools/android update project --target android-18 -p .
Now you can build

 ant debug/release -Dsdk.dir=/home/stevenchiu/ADT/android-sdk-linux/

Easy~

To run OpenNI Simple Viewer wth Kinect in BeagleBone Black Android

 1. Build OpenNI
git clone git://github.com/OpenNI/OpenNI
git checkout -b 1.5.4.0 Unstable-1.5.4.0
 checkout to tag 1.5.4.0, only this tag works for me
cd Platform/Android/jni
${NDK_ROOT}/ndk-build
 You have to define your NDK_ROOT of course. I use NDK r7

 If you encountered cpu_set_t can not be recognized in  NiSkeletonBenchmark.cpp, simply ignore this behaviour

 -#if (XN_PLATFORM != XN_PLATFORM_MACOSX)       
+#if (XN_PLATFORM != XN_PLATFORM_MACOSX && XN_PLATFORM != XN_PLATFORM_ANDROID_ARM)      ^M
     //we want out benchmark application will be running only on one CPU core
     cpu_set_t mask;



 2. Build SensorKinect 
export NDK_MODULE_PATH=/path/to/openni/Platform/Android/jni
git clone git://github.com/avin2/SensorKinect.git
git checkout -b unstable origin/unstable
cd Platform/Android/jni
${NDK_ROOT}/ndk-build

 3. Upload your libraries and binary to Android
    Now we have to upload the libraries located in Platform/Android/libs/armeabi-v7a/*.so to android /system/libs. We have to upload OpenNI libraries first and then SensorKinect since some libraries should be replaced according to the HW.


i.e. Kinect in this case.
    
    Please remember to upload the Sample-SimpleRead binary to /system/bin/



 4. Mount USBFS to grant USB device permission
   mount -o devmode=0666 -t usbfs none /proc/bus/usb


 5. Push xmls to /Data/ni
     adb push SamplesConfig.xml /Data/ni
      adb push modules /Data/ni
      adb push GlobalDefaultskinect.ini /Data/ni
      adb push License.xml /Data/ni

6. Run Sample-Read under /Data/ni
    You should be able to see the middle point and frame rate

#Trouble shooting
    USB open fail => sudo rmmod  gpsca_kinect

2013年10月30日 星期三

To run Nite samples in Ubuntu 13.10 (Nite + OpenNI + SensorKinect)

1. Build OpenNI
git clone git://github.com/OpenNI/OpenNI
git checkout -b 1.5.4.0 Unstable-1.5.4.0
 checkout to tag 1.5.4.0, only this tag works for me
cd Platform/Linux/CreateRedist
./RedistMaker
cd ../Redist/$(Openni Version)/
In my case, it's OpenNI-Bin-Dev-Linux-x64-v1.5.4.0
sudo install.sh

2. Build SensorKinect
git clone git://github.com/avin2/SensorKinect.git
git checkout -b unstable origin/unstable
cd Platform/Linux/CreateRedist
./RedistMaker
 cd ../Redist/$(Sensor Kinect Version)/
In my case, it's  Sensor-Bin-Linux-x64-v5.1.2.1
sudo install.sh
It's that simple.

now you can download NITE-Bin-Dev-Linux-x64-v1.5.2.21.tar.zip and run samples under Samples/Bin/x64-Release

2013年10月28日 星期一

[BBB] memo of configuring BeagleBone Black network

manually add a gateway
route add default gw 192.168.1.1 dev eth0 => add default gateway 
 
 
The following configuration in /etc/network/interfaces does all above:
#iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.2
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 192.168.1.1 
 
Finally, add nameserver in /etc/resolf.conf
echo "nameserver 192.168.1.1" > /etc/resolv.conf 

Restart network now:
/etc/init.d/networking restart =>  restart network or 
ifdown eth0; ifup eth0
 
toolchain for BBB is arm-linux-gnueabihf


Problem solved! 
 
extract and cross compiled with CC=arm-linux-gnueabihf-gcc ./configue --target=arm-linux 


2013年10月21日 星期一

Build OpenCV from souce


sudo apt-get install libgtk2.0-dev
I only encounter this problem. please google the error message you see to get the corresponding solutions
git clone https://github.com/Itseez/opencv.git
cd opencv
git checkout 2.4.6.2 -b 2.4.6.2
default is master branch and I manually checkout to 2.4.6.2 tag.
mkdir build(whatever name you want)
cd build
cmake-gui ..
(to generate the configurations you want and generate make file. sudo apt-get install cmake-gui if you don't have it.)
make; sudo mak install

2013年7月24日 星期三

Generate patches for specific user

To generate my own patches by the following command:

for commit in `git log --author=XXX --pretty=oneline | awk '{print $1}'`; do git format-patch -1 "$commit"; done

2012年12月18日 星期二

command line access windows share

無法查看此摘要。請 按這裡查看文章。

2012年3月22日 星期四

some string related tips

0. replace strings for all files in a folder
find ./ | xargs grep -l "$STRING_TO_BE_REPLACED" | xargs sed -i -e "s/$STRING_TO_BE_REPLACED/$STRING_TO_REPLACE/g"

0. find files and then grep som key word
find ./ -iname '$FILE_NAMES*' | xargs grep $SEARCH_KEY_WORDS

0. find files and then remove
find ./ -iname '$FILE_NAMES*' | xargs rm -rf

0. find and push multiple files from adb
find ./ -iname *.ko  | xargs -t -i adb push {} /system/lib/modules/

0. Search multiple words in VIM
/\(kernel\|panic\);  you will search both kernel and panic at the same time

0. Copy and rename multiple filse
for i in `find ./ -iname "*file_name*"`; do cp $i `echo $i | sed "s/$STRING_TO_BE_REPLACED/$STRING_TO_REPLACE/g"`; done

2011年12月26日 星期一

Note about kobjects, ksets, and ktypes.

kobject, quoted form kernek documentation: (example in samples/kobject/kobject-example.c)
1. A kobject must be initialized. for example
void kobject_init(struct kobject *kobj, struct kobj_type *ktype);
The ktype is required for a kobject to be created properly, as every kobject
must have an associated kobj_type.

2. After calling kobject_init(), to regsiter the kobject with sysfs, kobject_add() must be called
int kobject_add(struct kobject *kobj, struct kobject *parent, const char *fmt, ...);
This setup the parrent of the kobject and the name for the kobject properly. If the kobject is to be associated with a specific kset, kobj->kset must be assigned before calling kobject_add(). If a kset is associated with a kobject, then the parent for the kobject can be set to NULL in the call to kobject_add() andthen the kobject's parent will be the kset itself.
or call int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype,
struct kobject *parent, const char *fmt, ...); to init and add kobject to the kernel at the same time.

3. To inform userspace that a kobj has been created, call
int kobject_uevent(struct kobject *kobj, enum kobject_action action);

4. To create a simple directory in the sysfs hierarchy and not to mess with the whole complication of ksets, show and store functions, call
struct kobject *kobject_create_and_add(char *name, struct kobject *parent);
It creates a kobject and place it in sysfs in the location underneath the specified parent kobject.

5. To release a kobject, don't do kfree() but kobject_put(). A good practice is to use kobject_put() as an error check after kobject_init() to avoid errors creeping in.

6. Every kobject must have a release() method and the release() method is not stored in the kobject itself but associated with the ktype. for example:
struct kobj_type {
void (*release)(struct kobject *);
const struct sysfs_ops *sysfs_ops;
struct attribute **default_attrs;
};
This structure must be referenced when you call kobject_init() or kobject_init_and_add()..

2011年11月23日 星期三

git remote; github

Commands help you manage remotes:

add:
git remote add project git://github.com/user/project.git
This will create "project" pointing to git://githun.com/user/project.git

rename:
git remote rename project test
This renames "project" to "test" in a remote and it's remote-tracking branches

rm:
git remote rm project
This deletes "project" remote and any remote-tracking branches we've fetched.

change url:
git remote set-url example git://github.com/user/test.git
This sets the URL of the remote named "example" to git://github.com/user/test.git


git shortcut

git diff --staged; git diff --cached
0. To diff HEAD and added but not committed files

git format-patch -1 SHA1
0. To patch only this commit

git --abbrev-commit --pretty=oneline
0. To shorten SHA1 number and show only one line of commit logs

2010年6月1日 星期二

VIM 修改 ^M 換行的指令

在windows版本的gvim/vim底下
:% s/\r//g

在linux based的vim底下
:% s/^M//g

其中^M 的输入用 Ctrl+v, Ctrl+m。

會有這樣的不同是因為Ctrl+v在windows是貼上@@

2010年4月14日 星期三

cross compile ssh daemon(dropbear) for arm

1. Get zlib(included by dropbear)
#wget http://www.zlib.net/zlib-1.2.3.tar.gz
#tar zxvf zlib-1.2.3.tar.gz
#mkdir zlib
#cd zlib-1.2.3/
#CC=arm-none-linux-gnueabi-gcc ./configure --prefix=/zlib
#make
#make install

2. Get dropbear source
#wget http://matt.ucc.asn.au/dropbear/releases/dropbear-0.51.tar.gz
#tar zxvf dropbear-0.51.tar.gz
#mkdir dropbear-build
#cd dropbear-build/
#mkdir build
#../dropbear-0.51/configure --prefix=/build/ \
--with-zlib=/zlib/ CC=arm-none-linux-gnueabi-gcc --host=arm-none-linux-gnueabi LDFLAGS=-static
#make
#sudo make install

3. Copy dbclient, dropbearconvert, dropbearkey, and dropbear binarys to your file system and generate the cpio.gz file(Under build/bin and build/sbin, if you are not using a emulator, do not generate cpio.gz file :))

4. In target,
#cd /etc
#mkdir dropbear
#cd dropbear
#dropbearkey -t rsa -f dropbear_rsa_host_key

if indicate "Exited: couldn't open random device", do the following
#mknod -m=666 /dev/random c 1 8
#mknod -m=666 /dev/urandom c 1 9

#dropbear(assume the binary is under /sbin)

5. Done, you should be able to run ssh client to access this machine.
(May add password if it's originally none, otherwise ssh will complain permission denied)

PS. If you encountered the following error when ssh to the target.
"PTY allocation request failed on channel 0"
"shell request failed on channel 0"
do the following:

# mkdir /dev/pts
# mknod /dev/ptmx c 5 2
# mount -t devpts devpts /dev/pts

2010年4月9日 星期五

Cross Compile gdb for x86 and gdbserver for ARM

1. Download GDB source code
2. Download toolchain. ex, you can download the toolchain binary from codesourcery.
3. you will have GDB for x86 host machine after the following:
#./configure --target=arm-none-linux-gnueabi LDFLAGS=-static --with-build-libsubdir=/usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/lib --disable-werror
#make
4. enter gdb/gdbserver, you will have gdbserver for ARM after the following:
#./configure --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi LDFLAGS=-static --with-build-libsubdir=/usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/lib --disable-werror
#make

ps.
If make complains about no termcap library, do the following
1. Download ncurses (search the web)
2. Do the following
#./configure --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi --prefix="$HOME/install"
#make && make install
#sudo cp ~/install/lib/libncurses.a /usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/lib
#sudo cp ~/install/include/ncurses/ /usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/include -rf

Beaware that this is because that the toolchain is not aware of the libncurses.a library though you've probably install it in the regular path. We need it for the toolchain and which is for ARM machine.
You can do
#file libncurses.a
to check if it's for your machine or for the target. The format should match to cease the complaining.

2009年10月21日 星期三

幾個好用的線上訂房網站

expedia-->全美最大。
priceline-->有個好玩的功能是可以自己去競標旅館。
hotwire-->用匿名的方式去預約旅館,一直到最後一刻才會知道你住的是哪一間,不過如果熟門熟路的已經知道那附近有哪些旅館的話,幾乎可以百發百中。

每一個網站的價格可能稍有不同,多多比較囉。

至於租車的話可以從這裡
http://www.4travelcoupons.com/car-rentals.html
裡面有各大租車公司的coupon

2009年10月6日 星期二

ARM BL instruction

syntax:
   bl function_A;
簡單說就是把下一個要執行的位置(i.e. the return address),
存到LR(r13)之後,
把function_A的位置,
存到PC中。
這樣就會跳到callee function
然後把return address存給caller function。

2009年10月3日 星期六

Businuss trip in San Diego

莫名的就來到了聖地牙哥,
大概是上禮拜三吧,

"你有美簽嗎?"
"有阿" 我說
"那麻煩你下禮拜一去一趟QualComm"
"....."

總之禮拜一的晚上我就到了QualComm在聖地牙哥的總部了。

這次是我第一次來美國出差有租車的經驗
之前都是做人家便車的,

公司規定只能租economic和compact兩種車型,
雖然說我也搞不太清楚有什麼差異
特別跟櫃台強調了要一台日本車
結果他給了我一台 Nissan Versa

我只能說車子還滿可愛的
感覺也還滿好開的
只是不太穩

感忙著去租車是因為周末有一個同事要來
所以要去接機
這個我必須要抱怨一下
為什麼不一起來就好了呢??

為了他我還特地繞了一下機場
看要怎嚜過去
探路ㄟ
又不是大學參加社團@@

下午想去逛個mall的
只是好累我就睡著了@@
不過可能也還好
因為發現要去的那個交流道車好多
大家都忙裡偷閒去買東西就對了

明天再看看吧

2009年9月29日 星期二

防止資料被初始化 in ARM environment

有的時候,資料並不想被初始化,這時候我們需要特別的指定section。在code裡面我們可以用
#pragma arm section zidata = "non_init"
int i, j;    //uninit (in non_init section)
#pragma arm section zidata   //back to default (.bss section)
int k=0, l=0;  //zero-init (in .bss section)
這樣我們就會有一個自己的section名子叫做non_init。之後在execution region中我們可以把它指定成UNINIT,好比說

LOAD_1 0x0{

EXEC_1 +0


{



* (+RO)


* (+RW)


* (+ZI) ;ZI data will be initialized to zero



}



EXEC_2 +0 UNINIT


{



* (non_init) ;ZI data will not be initialized to zero



}



}

這樣我們的i和j就不會就算不給值也不會被初始成0了。