2011年12月16日 星期五

2011年10月26日 星期三

get free memory size in kernel

Just paste this section to where you want to check:

{
#define K(x) ((x) << (PAGE_SHIFT - 10))
struct sysinfo si; \
si_meminfo(&si); \
printk("free=%lu k\n", K(si.freeram)); \
}

may need to include linux/mm.h

2011年6月26日 星期日

Use vim/cscope/ctags to navigate linux kernel

Install cscope:

sudo apt-get install cscope exuberant-ctags

Generate cscope and ctag file for x86:

##################################

#!/bin/bash
# File name: genctags.sh
# Usage: genctags.sh x86

LNX=.
ARCH=x86

if [ ! -z "$1" ];then
ARCH="$1"
fi

if [ "$2" != "tag" ];then

echo "Gen cscope file for $ARCH ..."
find $LNX \
-path "$LNX/arch/*" ! -path "$LNX/arch/$ARCH*" -prune -o \
-path "$LNX/include/asm-*" ! -path "$LNX/include/asm-$ARCH*" -prune -o \
-path "$LNX/tmp*" -prune -o \
-path "$LNX/Documentation*" -prune -o \
-path "$LNX/scripts*" -prune -o \
-path "$LNX/drivers*" -prune -o \
-name "*.[chxsS]" -print > cscope.files

cscope -b -q -k
fi

echo "Gen ctags file ($ARCH)..."

EXCLUDE_PATH=`find . -path "$LNX/arch/*" ! -path "$LNX/arch/$ARCH*" -prune`
EXCLUDE_PATH2=

for path in $EXCLUDE_PATH
do
EXCLUDE_PATH2="$EXCLUDE_PATH2 --exclude=$path"
done

ctags -R $EXCLUDE_PATH2

###############################################

For vim:


try it:
vim ./init/main.c

move the cursor to a symbol then...

ctrl + ] -- goto definition
[ + d -- show macro definition (if it is a macro)
ctrl + o -- goto previous position
ctrl + i -- goto next position
ctrl + \ s -- list usages
ctrl + shift + space -- list usages and pops a select to a new window (ctrl+w o to close)

search tag "main":
: ta main

search tags including "main":
:ta /main

search tags beginning with "main":
:ta /^main

Ref:

2011年6月9日 星期四

2011年5月19日 星期四

gcc include paths and their order

robert@debian-rbt:~$ `gcc -print-prog-name=cc1` -v -I/home/robert/
ignoring nonexistent directory "/usr/local/include/i486-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/i486-linux-gnu/4.4.5/../../../../i486-linux-gnu/include"
ignoring nonexistent directory "/usr/include/i486-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
/home/robert/
/usr/local/include
/usr/lib/gcc/i486-linux-gnu/4.4.5/include
/usr/lib/gcc/i486-linux-gnu/4.4.5/include-fixed
/usr/include

End of search list.

Ref:

2011年3月1日 星期二

install ubcd to usb disk

1. Mount ubcd503.iso to /mnt
-> sudo mount -o loop ubcd503.iso /mnt

(Read /mnt/ubcd/tools/linux/ubcd2usb/readme.txt)

2. Create mbr:
-> cd /mnt/ubcd/tools/linux/ubcd2usb
-> sudo dd if=mbr.bin of=/dev/sdX

(replacing X with your USB key drive letter)

3. Format your usb disk to fat32
-> sudo mkfs.vfat -F 32 /dev/sdX1

4. Mount your usb disk and copy all files of the extracted UBCD iso to your USB thumb drive
-> sudo mount /dev/sdX1 /usbmnt
-> sudo cp -rf /mnt/* /usbmnt

5. Install bootloader syslinux:
-> cd /mnt/ubcd/tools/linux/ubcd2usb
-> sudo ./syslinux -s -d /boot/syslinux /dev/sdX1
(install syslinux to a directory relative to /boot/syslinux on the device)

6. make the partition bootable:
-> sudo parted /dev/sdX set 1 boot on

Ref:
ubcd-extracted/ubcd/tools/linux/ubcd2usb/readme.txt

2011年2月21日 星期一

java jar signing

以下用top-down的方式講述如何對一個 jar 簽章:

keystore & key 說明:
=============

java 將用來簽章的key存在keystore中,每個key包含private key(密秘)和 public-key certificate(公開)。

一個 keystore檔案就是一個專存這些key的資料庫,而用 alias 來索引其中的一個 key。

keystore檔有一個密碼保護,而其中的每個key也可以有(也可以不設)自己的密碼保護。


簽章操作:
=======

-> jarsigner -keystore my.keystore -storepass 123456 myprogram.jar myprogram

(若這個key有設密碼保護,會再要求輸入密碼;或是直接在 jarsigner 後多加參數-keypass xxxx)

這樣就可以用 my.keystore 中的那個 alias 為 myprogram 的key,對 myprogram.jar 簽章。


如何產生keystore 和 key:
================


-> keytool -genkey -alias myprogram -keystore my.keystore -storepass 123456 -validity 1800 < myprogram.keyconf


(如果沒有先做好myprogram.keyconf,則輸手動輸入key的資訊)
這樣會產生一個 keystore 檔 my.keystore,裡面有一個 alias 叫 myprogram 的 key,此 key 的有效期限為1800天。

Ref:
Signing and Verifying JAR FilesJAR Signing

2011年2月17日 星期四

map dir to msys

Hot to map a dir from host Windows to msys ?
Ans:

Edit msys/1.0/etc/fstab, for example:

f:/mingw /mingw
f:/jdk21 /java

You also need to create the corresponding dir in msys. In this example,
mkdir /mingw
mkdir /java

2011年1月13日 星期四

Run jnlp program as root (sudo)

In Linux, a non-root user usually clicks a jnlp link in a web browser or double-clicks a jnlp file to run a Java Web Start program.
The program has no root privilege.

How to run it as root ?
-> sudo javaws http://your-website/link.jnlp

or download the jnlp file and
-> sudo javaws ~/Test/link.jnlp

Reference: