2010년 5월 27일 목요일

리눅스 커널 모듈 컴파일 하기

출처 : http://www.cyberciti.biz/tips/compiling-linux-kernel-module.html

1. 우선 커널 소스 코드를 다운 받고, 다음과 같이 압축을 해제하자

$ tar -zxvf kernel* -C /usr/src

2. 커널 모듈 소스이 있는 디렉토리로 가서 Makefile을 만들자.

$ vi Makefile

3. 다음의 라인을 추가하자. (모듈 이름을 foo라고 하자)

obj-m = foo.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4. make 명령어로 모듈을 컴파일하자. (모듈 컴파일은 어떠한 사용자라도 가능하다.)

$ make

마지막으로 foo.ko이라는 모듈이 생성될 것이다.

5. 모듈 컴파일에 성공하면 insmod나 modprobe명령어를 이용해서 로드하자.
여기서 root 사용자 계정이 필요하다.

$ insmod foo.ko

예제: hello.c 모듈

1) hello.c C 소스 코드를 만들자.

$ mkdir demo; cd demo
$ vi hello.c

2) 다음의 라인을 추가하자.

#include /* Needed by all modules */
#include /* Needed by KERN_INFO */
#include /* Needed by the macros */

static int __init hello_start(void)
{
printk(KERN_INFO "Loading hello module...\n");
printk(KERN_INFO "Hello world\n");
return 0;
}

static void __exit hello_end(void)
{
printk(KERN_INFO "Goodbye Mr.\n");
}

module_init(hello_start);
module_exit(hello_end);

3) 파일을 저장하고, 새로운 Makefile을 다음과 같이 만들자.

$ vi Makefile

다음 라인들을 추가하자.

obj-m = hello.o
KVERSION = $(shell uname -r)
all:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

4) 저장하고 파일을 닫자.

5) hello.c모듈을 컴파일하자.

$ make

6) 루트 계정으로 전환하고 모듈을 로드하자.

$ sudo insmod hello.ko

7) 로드된 모듈을 확인하자.

$ lsmod | less

8) /var/log/message 파일에서 메세지를 확인하자.

9) 모듈을 언로드하자.

$ rmmod hello

10) 리눅스 시스템이 부팅할때 모듈을 로드할 수 있도록, /etc/modules 파일을 수정하자.
이파일은 부팅시 로드할 커널 모듈의 이름을 가지고 있다. 먼저 해당 모듈을 /lib/modules/$(uname -r)/kernel/drivers 에 복사하고, 다음의 단계들을 밝아 나가자.

(a) hello모듈의 디렉토리를 만들자

$ mkdir -p /lib/modules/$(uname -r)/kernel/drivers/hello

(b) 모듈을 복사하자.

$ cp hello.ko /lib/modules/$(uname -r)/kernel/drivers/hello/

(c) /etc/modules파일을 편집하자.

$ vi /etc/modules

(d) 다음 라인을 추가하자.

hello

(e) 변경된 사항을 살펴보기 위해서 재부팅하자. 그리고 lsmod나 dmesg 를 사용해서 로드된 모듈을 확인하자.

$ cat /proc/modules

OR

$ lsmod | less

2010년 5월 24일 월요일

Installing Busybox Command Line Tools on Android

출처 : http://www.omappedia.org/wiki/Android_Getting_Started#Installing_Busybox_Command_Line_Tools_.28Optional.29

안드로이드 파일 시스템에 busybox를 설치하는 방법.
좀더 자세한 사항은 www.busybox.net을 살펴보자.
  • 설정및 설치
www.busybox.net에서 busybox-1.13.3.tar.bz2 를 다운로드한다.
busybox소스의 압축을 해제한다.
$ tar jxvf busybox-1.13.3.tar.bz2
busybox의 설정을 구성한다.
$ cd busybox-1.13.3/
$ make menuconfig
설정 메뉴에서 다음 사항들을 선택하자.
$ Busybox Setting --> Build Options --> Build Busybox as a static binary (no shared libs) - Enable this option by pressing "Y"
$ Busybox Setting --> Build Options --> Cross compiler prefix - Set this option equal to "arm-none-linux-gnueabi-"
$ Busybox Setting --> Installation Option --> Don't use /usr - Enable this option by pressing "Y"
크로스 컴파일을 해야하기 때문에 크로스 컴파일러의 경로를 설정해 두어야 한다.
$ export PATH=$PATH://bin/
Busybox를 만들자.
$ make

  • Busybox를 파일 시스템에 설치하기
안드로이드 파일 시스템에 /bin 디렉토리를 만들자.
$ mkdir //bin
Busybox 바이너리들을 안드로이드 파일 시스템의 /bin 디렉토리에 복사하자.
$ cp busybox //bin
다음의 명령행을 실행해서 안드로이드 파일 시스템에 busybox command line tools을 설치하자.
$ cd /bin
$ ./busybox --install
  • Busybox의 명령어 분석기(Shell)를 시스템의 기본 명령어 분석기로 설정하기
$ vim init.rc
-service console /system/bin/sh
+service console /bin/sh
busybox 명령행 도구들의 경로를 system 경로 명에 추가하자.
-export PATH /sbin:/system/sbin:/system/bin:/system/xbin
+export PATH /bin:/sbin:/system/sbin:/system/bin:/system/xbin

2010년 5월 22일 토요일

Usage of mktarball.sh

# $1: path to fs_get_stats program
# $2: start dir
# $3: subdir to tar up (from $2)
# $4: target tar name
# $5: target tarball name (usually $(3).bz2)

example.

mktarball.sh fs_get_stats /orig_dir . zip_name zip_name.tar.bz2

2010년 5월 16일 일요일

Install 0xdroid of 0xlab in devkit8000

출처 : http://code.google.com/p/0xdroid/wiki/Source
  • 소스 코드 받기

프로젝트 홈페이지 http://gitorious.org/0xdroid.

0xdroid 소스코드 다운 받기.

build-from-scratch.

  • 준비물: Sun JDK

Donut 버전을 설치하기 위해서 Sun JDK version 1.5가 필요하지만, 현재 최신버전이 아니다.

그리고 우분투 리눅스 9.10 버전은 더이상 지원하지 않는다.

우분투 리눅스 9.10버전의 사용자들은 /etc/apt/sources.list에 다음의 두라인을 추가하자.

deb http://us.archive.ubuntu.com/ubuntu/ karmic-updates multiverse

deb-src http://us.archive.ubuntu.com/ubuntu/ karmic-updates multiverse

그리고 Sun JDK 1.5를 설치하자.

$ sudo apt-get update

$ sudo apt-get install sun-java5-jdk

Java 5를 사용하도록 설정하기 위해서 다음을 수행하자.

$ sudo update-alternatives --config java

그리고 java-1.5.0-sun을 선택하자.

  • 준비물: git 와 repo

소스코드를 다운로드 하기 위해선 git 와 repo 가 필요하다.

우분투 9.04 호스트 에선 다음과 같이 하면된다.

git:

$ sudo apt-get install git-core

repo:

$ curl -o ~/bin/repo http://android.git.kernel.org/repo

$ chmod a+x ~/bin/repo

Repo에 대한 좀더 자세한 사항들은 Using Repo and Git.

  • 0xdroid 소스코드 얻기

$ mkdir beagle-donut

$ cd beagle-donut

$ repo init -u git://gitorious.org/0xdroid/manifest.git -b BRANCH_NAME

$ repo sync

BRANCH_NAME 은 다음중 하나로 설정하자.:

* beagle-eclair - for Eclair version of 0xdroid
* beagle-donut - for Donut version 0f 0xdroid
* beagle-cupcake - for Cupcake version of 0xdroid

다른 방식으로 좀 더 빠른 속도로 받을 수 있는 git mirror를 사용하

$ repo init -u git://git.0xlab.org/manifest.git -b beagle-donut
$ sed -i -e 's#git://gitorious.org/0xdroid/#git://git.0xlab.org/#' .repo/manifests/default.xml
$ repo sync

  • 소스코드를 가지고 0xdroid 만들기

DevKit8000을 설정하고 활성화 하자.

$ echo "TARGET_PRODUCT :=devkit8000” > buildspec.mk
$ echo “INSTALL_PREBUILT_DEMO_APKS := true” >> buildspec.mk

$ make

성공적으로 만들어 졌다면, 루트 파일 시스템은 다음의 곳에 생성된다.

* out/target/product/beagleboard/root/
* out/target/product/beagleboard/system/

NAND flash를 위한 UBIFS system image은 다음과 같다.:

* out/target/product/beagleboard/system.img

좀더 세세한 것들은 scratch 에서 Linux kernel를 만들고 설정하자.

$ cd ..
$ git clone git://gitorious.org/0xlab-kernel/kernel.git
$ cd kernel
$ git checkout -b kernel_omap3 origin/omap3
$ make ARCH=arm devkit8000_defconfig # build for devkit8000
$ make ARCH=arm CROSS_COMPILE=../prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- uImage
$ make ARCH=arm CROSS_COMPILE=../prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/arm-eabi- modules

이미지를 타겟 보드에 심자.

긴 빌딩과정이 끝나면 Android kernel과 system 이미지들을 얻게 된다. happy Installer를 이용해서 SD card booting을 할 수 있다.

* SD card의 첫번째 파티션을 100MB이상을 갖는 VFAT로 포멧하자 .
* 인스톨러 uImage.bin를 다운로드하자.
* out/target/product/beagleboard/system.img 을 android-beagle.ubi으로 바꾸자.
* arch/arm/boot/uImage을 0xkernel-beagle.bin으로 바꾸자.
* 이 세파일들을 SD/MMC card의 첫번째 파티션에 복사하자.
* Beagle board의 SD slot에 SD card를 넣고 Beagleboard를 재시작하자.
* UI installer가 끝날때까지 기달리자. installer는 NAND flashing 과 u-boot 환경번수를 설정한다.
* Beagleboard에서 SD card를 제거하고 재부팅하자.
* 즐기자!
  • Uboot Update
0xdroid의 eclair-0x4버전에 알맞는 devkit8000의 flash-uboot.bin으로 uboot를 변경하자. 낮은 버전의 커널에서는 문제가 없지만 높은 버전의 리눅스 커널에서 ID를 체크하는 부분때문에 리눅스 부팅이 안되는 경우가 생긴다.
우선, SD 카드로 flash-uboot.bin 이미지를 복사한다.

$ cp ~/download/flash-uboot.bin /media/sdcard/

그리고 uboot에서

# mmcinit (uboot 버전에 따라 mmc init인 경우도 존재함)
# fatload mmc 0:1 80000000 flash-uboot.bin
reading flash-uboot.bin

$(file size) bytes read
# nand unlock
device 0 whole chip
nand_unlock: start: 00000000, length: 134217728!
NAND flash successfully unlocked
# nand ecc sw (uboot 버전에 따라 nandecc 인 경우도 존재함)
# nand erase 80000 160000

NAND erase: device 0 offset 0x80000, size 0x160000
Erasing at 0x1c0000 -- 100% complete
OK
# nand write.i 80000000 80000 160000

NAND write: device 0 offset 0x80000, size 0x160000

Writing data at 0x1df800 -- 100% complete.
1441792 bytes written: OK

  • 커널과 루트 파일시스템 이미지 설치하기
커널과 푸트 파일 시스템은 위에서 언급한데로 Happy 인스톨러로 인한 설치는 안된다. 그레서 uboot에서 설치를 시도하자.
SD 카드에 리눅스 커널 이미지와 루트 파일 시스템을 복사하자
$ cp kernel/arch/arm/boot/uImage /media/sdcard/
$ cp out/target/product/devkit8000/system.img /media/sdcard
$ sync
$ umount /media/sdcard

SD 카드를 보드에 꼽고, 전원을 올리자.
U-Boot 2009.11-00423-gb5f90cf-dirty (Mar 19 2010 - 19:16:52)

OMAP3530-GP ES3.1, CPU-OPP2 L3-165MHz
OMAP3 DevKit8000 + LPDDR/NAND
I2C: ready
DRAM: 256 MB
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Die ID #2cf2002400000000040365fa19019014
Net: dm9000
Hit any key to stop autoboot: 0
OMAP3 DevKit8000 #

그리고 uboot상에서 SD 카드의 이미지들을 설치하자.
# mmcinit (uboot 버전에 따라 mmc init인 경우도 존재함)
# fatload mmc 0:1 80000000 uImage
reading uImage

1790588 bytes read
# nand unlock
device 0 whole chip
nand_unlock: start: 00000000, length: 134217728!
NAND flash successfully unlocked
# nand ecc sw (uboot 버전에 따라 nandecc 인 경우도 존재함)
# nand erase 280000 200000

NAND erase: device 0 offset 0x280000, size 0x200000
Erasing at 0x460000 -- 100% complete
OK
# nand write.i 80000000 280000 200000

NAND write: device 0 offset 0x280000, size 0x200000

Writing data at 0x47f800 -- 100% complete.
2097152 bytes written: OK

# mmcinit
# fatload mmc 0:1 81000000 system.img
read system.img

43253760 bytes read
# nand unlock
# nand ecc sw
# nand erase 680000

NAND erase: device 0 offset 0x680000, size 0xf980000
Erasing at 0xffe0000 -- 100% complete
OK
# nand write.i 81000000 680000 2940000

NAND write: device 0 offset 0x680000, size 0x2940000
43253760 bytes written: OK

  • In uboot, bootcmd and bootargs
# setenv bootcmd 'nand read 80300000 280000 300000; bootm 80300000'
# setenv bootargs 'console=ttyS2,115200n8 ubi.mtd=4 root=ubi0:rootfs rootfstype=ubifs video=omapfb:mode:4.3inch_LCD omapfb.mode=lcd:480x272 omapfb.rotate=1 init=/init androidboot.console=ttyS2'
# saveenv
# reset


2010년 5월 9일 일요일

리눅스 /home 디렉토리 옮기기

from http://embraceubuntu.com/2006/01/29/move-home-to-its-own-partition/


먼저, 충분한 크기의 partition을 만들자.
그리고 나서, 새로운 partition을 mount시키자.
$mkdir /mnt/newhome
$sudo mount -t ext3 /dev/hda5 /mnt/newhome
그럼, 파일들을 복사하자:
“/home” 디렉토리는 hardlinks, softlinks, 파일들, nested 디렉토리를 포함하기 때문에, 일반적인 copy(cp) 명령어로는 완전히 수행할 수 없다. 그래서, Debian archiving guide:에서 배운것을 사용할 것이다.
$cd /home/
$find . -depth -print0 | cpio --null --sparse -pvd /mnt/newhome/
모두 copy가 되었는지 확인하자. 여러분의 입맛에 따라서 약간 수정하거나 가공해서 사용하자.
그리고 나서 새로운 partition을 unmount시키자.
$sudo umount /mnt/newhome
새로운 “home”을 만들수 있도록 기존의 것을 백업하자
$sudo mv /home /old_home
/home이 /old_home으로 변겨되었기 때문에, 이제 더이상 /home디렉토리가 없다. 그래서 먼저 /home 디렉토리를 다시 만들어야 한다.
sudo mkdir /home
새로운 home을 Mount하자
$sudo mount /dev/hda5 /home그럼, ubuntu가 부팅시 새로운 home을 마운트할 수 있도록 “/etc/fstab”파일에 다음 라인을 추가하자:
/dev/hda5 /home ext3 nodev,nosuid 0 2모든게 완료되면 “/old_home”디렉토리는 지우자
$sudo rm -r /old_home
Michael, Russ and Magnus posted this solution on the ubuntu-users mailing list a few months ago.

2010년 4월 26일 월요일

About Optical Coating

http://zcrcoatings.com/