2009年12月17日 星期四

To Enable NAT feature

* Edit a new script file nat.sh

vi /etc/init.d/nat.sh

#!/bin/sh
##### iptables.rule #####
EIF="eth0" # 對外的網路介面
IIF="eth1" # 對內的網路介面
INNET="192.168.5.0/24" # 內部子網域

# forwarding
# 讓內部網路的封包可以轉送到外部
echo "1" > /proc/sys/net/ipv4/ip_forward

# flush all rules
iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X

# 定義 policy
# Policy指的是當進來的封包不屬於rule中的任何一條時,所預設的動作。
iptables -P INPUT DROP
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT

# localhost
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT

# 讓主機主動建立的連線可以進來
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# 設定主機上提供的服務可讓外部網路存取
iptables -A INPUT -i $EIF -p udp --dport 22 -j ACCEPT #ssh
iptables -A INPUT -i $EIF -p udp --dport 22 -j ACCEPT
iptables -A INPUT -i $EIF -p tcp --dport 80 -j ACCEPT # http
# ... 其餘省略

# enable any connection for local LAN
iptables -A INPUT -i eth1 -j ACCEPT
iptables -A OUTPUT -o eth1 -j ACCEPT

# NAT
iptables -t nat -A POSTROUTING -o $EIF -s $INNET -j MASQUERADE


* add the file into /etc/rc.local


Reference:
http://ljhuang.pixnet.net/blog/post/15029442


To enable dhcp server for mutil-interface

Under Ubuntu 8.04.3

* get DHCP server
sudo apt-get install dhcp3-server

* enable networking interface for DHCP server
sudo vi /etc/default/dhcp3-server

# what interface provide DHCP service
INTERFACES="wlan0 eth1"


* edit the DHCP server parameter
sudo vi /etc/dhcp3/dhcpd.conf

ddns-update-style none;
log-facility local7;

subnet 192.168.5.0 netmask 255.255.255.0 {
option routers 192.168.5.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.5.255;
option domain-name-servers 172.16.100.1, 172.16.100.16;
# option ntp-servers 172.16.100.1;
# option netbios-name-servers 172.16.100.1;
option netbios-node-type 2;
default-lease-time 86400;
max-lease-time 86400;

range 192.168.5.21 192.168.5.30;
}


Reference:
https://help.ubuntu.com/community/dhcp3-server



2009年12月6日 星期日

To access USB serial port

* In order to pre-mount USB device file system when system boot-up, to add parameter to /etc/fstab (in linux kernel 2.6)
$ vi /etc/fstab

none /proc/bus/usb usbfs defaults,devmode=0666 0 0

* Auto mount it
$ mount -a


ex: you can access USB serial port by device file /dev/ttyUSB0 or ttyUSB1


2009年12月2日 星期三

The "request_suspend_state"

request_suspend_state() in kernel/power/earlysuspend.c

u-boot setting, kernel loaded from SD card or TFTP

Kernel loader from SD card, uboot setting
nand unlock
nand ecc sw
setenv bootargs console=ttyS3,115200n8 root=/dev/mmcblk0p2 rw rootdelay=1 mem=256M init=/init videoout=omap24xxvout omap_vout.video1_numbuffers=4 omap_vout.vid1_static_vrfb_alloc=y ip=192.168.5.10
setenv bootcmd 'mmcinit; fatload mmc 0 0x81c00000 uImage; bootm 0x81c00000'
saveenv

Kernel loaded from TFTP, uboot setting
nand unlock
nand ecc sw
setenv serverip 192.168.5.1
setenv ipaddr 192.168.5.10
setenv netmask 255.255.255.0
setenv bootfile 'uImage'
setenv bootargs console=ttyS3,115200n8 root=/dev/mmcblk0p2 rw rootdelay=1 mem=256M init=/init videoout=omap24xxvout omap_vout.video1_numbuffers=4 omap_vout.vid1_static_vrfb_alloc=y ip=192.168.5.10
setenv bootcmd 'tftp 81c00000 uImage;bootm'
saveenv

Print environment parameter
printenv

Boot immediately
boot


busybox's telnetd on Android

build busybox
下載 busybox source code
在busybox source code 目錄下,
$ make menuconfig

Busybox Settings -> Build Options ->
[*] Build BusyBox as a static binary (no shared libs)
Cross Compiler prefex
/opt/toolchain/arm-2008q3/bin/arm-none-linux-gnueabi-
Busybox Settings -> Installation Options->
[*] Don’t use /usr

$ make -I./opt/toolchain/arm-2008q3/arm-none-linux-gnueabi/libc/usr/include/
$ make install
$ cd _install/bin
$ tar zcvf busybox.tgz *

安裝 busybox 在 Android's myfs
$ mkdir $MYFS/data/busybox
$ cp busybox.tgz $MYFS/data/busybox
$ cd $MYFS/data/busybox
$ tar zxvf busybox.tgz

設定init.rc
$ vi /init.rc
export PATH /data/busybox:/sbin:........................

service telnetd /data/busybox/busybox telnetd -l /system/bin/sh
oneshot


reference:


2009年12月1日 星期二

重建mutil OS boot loader - GRUB

如果GRUB 原本安裝在MBR區
  • 準備WINGRUB, 在XP下將 grub 安裝到MBR
重建GRUB
  • 準備 linux live-CD, 開機進入live-CD mode
  • 在終端機執行 grub
  • grub> root (hd0,0)
    grub> setup (hd0)
    grub> quit



colinux Root FS image for ubuntu8.04

colinux Root FS image for ubuntu8.04

1. execute stable-coLinux-20080416.exe to install on c:\colinux folder or other folder.

2. extract ubuntu8colinux.rar to D:\

3. run cai.bat on d:\ubuntu8colinux folder.

4. ID/passwd is root/root

5. you can install ubuntu softwares with apt-get install xxx/apt-get update/apt-get upgrade

6. It is a tips, if you use local install ubuntu package.
Please use below steps:
(1)You can copy *.deb file to d:\ubuntu8colinux\xfs folder on the windows
(2) mv /opt/*.deb /var/cache/apt folder in the colinux command line.
(3) apt-get xxx package name to install ubuntu packages.

Detail to access http://www.colinux.org

other documents: to download ubuntu8colinux.cai.rar file from http://groups.google.com/group/iyaf site


1)ubuntu8colinux.rar下載地址http://www.fs2you.com/files/79fe4b00-13d1-11dd-9776-0014221f3995/

ubuntu8colinux.rar

2)others documents:
http://groups.google.com/group/iyaf
ubuntu8colinu.cai.rar

3)deb files:
http://www.fs2you.com/files/2c5caae1-db2b-11dc-9f83-00142218fc6e/
deb.rar
copy *.deb file to /var/cache/apt/archives and install with apt-get install xxx.



reference:

build Android under Ubuntu 9.10

  • Ubuntu 9.10 users may need to install a newer version of standard C++ library
$sudo apt-get install libstdc++6 
  • Ubuntu 9.10 users may need to add the old Jaunty repos to their /etc/apt/sources.list to install sun-java5-jdk
deb http://us.archive.ubuntu.com/ubuntu/ jaunty multiverse deb http://us.archive.ubuntu.com/ubuntu/ jaunty-updates multiverse


Reference: http://omappedia.org/wiki/Android_Getting_Started