[환경 : linux 2.4 board]

디렉토리는 3개를 사용한다.
하나는 target의 커널 모듈 두는 디렉토리 :    ~/linux/drivers/char/
두번째는 target의 menuconfig 하는 디렉토리 : ~/linux/
다른 하나는 그냥 루트 ~

<zImage에 커널 모듈 등록하기>

커널 모듈 소스 복사
[root@linux2 fnd_rw]# cp fnd.c ~/linux/drivers/char/

menuconfig 보이게 하기.
[root@linux2 linux]# make menuconfig



character deivce->standard/generic
커널에 두거나, 모듈단위로 설치하는 거..
스페이스를 두르면, 이런 모드를 변환할 수 있는 것을 확인한다.


zImage에 넣기 위해서 menuconfig의 메뉴에 항목을 추가한다. 
menuconfig 파일은 Config.in 파일에 영향을 준다. 
[root@linux2 char]# ls -al Config.in
-r--r--r--  1 root root 10230  6월 16  2003 Config.in

소스 수정
[root@linux2 char]# gedit Config.in &


#
# Character device configuration
#
mainmenu_option next_comment
comment 'Character devices'

바로 밑에  이거를 둔다.

tristate 'FND Device Support' CONFIG_FND



그리고 저장한다. 

make menuconfig 한다.

character device로 이동 (스페이스로 선택)



Config.in에 수정된 것을 확인할 수 있다.



 menuconfig 에서 FND Device Support 한 것을 스페이스를 눌러 [*] 모드로 바꾼다.

 


[root@linux2 char]# gedit Makefile

...

obj-$(CONFIG_FND) += fnd.o

// 이런 라인 위에 위의 fnd파일을 적는다.
obj-$(CONFIG_MAGIC_SYSRQ) += sysrq.o



소스를 수정한다.


[root@linux2 char]# gedit fnd.c

int fnd_init(void)
-> int __init fnd_init(void)

void fnd_exit(void)
-> void __exit fnd_exit(void)


이유는..
__init은 자동으로 register 하는 역할을 한다. 따로 insmod를 해야 한다.
최신 linux 2.6 후반 커널에서는 __init을 쓰지 않아도 된다.
 __exit 의 의미는 메인 메모리에서 내려버리라는 의미이다.  중간에 rmmod할 필요가 없는다. 쓸데없이 메모리 사용하지 않도록 정리한다.
zImage 코드 사이즈는 영향이 없다.



컴파일 한다. 

dependency를 체크한다.
[root@linux2 linux]# make dep
clean 한다. 
[root@linux2 linux]# make clean
zimage 생성한다.
[root@linux2 linux]# make zImage

그리고, drives/char 디렉토리안에서 제대로 컴파일 되었는지 확인
[root@linux2 char]# ls fnd.o
fnd.o


이미지를 tftp를 통해서 전달해야 하니 다음과 같이 zImage를 복사한다. 

[root@linux2 linux]# cp arch/arm/boot/zImage /tftpboot/zImage_my


이미지 다운로드를 준비한다. 
 
ip선을 꼽고.. bootp에 정상적으로 붙기위해서 테스트한다. 
[root@linux2 linux]# ifconfig eth0 192.168.1.51

미니컴에서 bootp를 실행한다.
XHYPER255B> bootp
Our Ethernet address is 1234 5678 9A00.
        Sending bootp packet...
.
Bootp Packet received.
        Host   (server) Ethernet : 000C 29F2 5EB0
        Host   (server) IP       : 192.168.1.51
        Client (target) Ethernet : 1234 5678 9A00
        Client (target) IP       : 192.168.1.50


XHYPER255B> tftp zImage_my kernel
TFTP Start...
        Host   (server) IP       : 192.168.1.51
        Client (target) IP       : 192.168.1.50
        Loading Filename         : zImage_my
        Save Address             : 0xA0008000

Loading start...
        0x000E2EB4 (929460) bytes received.
        tftp done.

플래쉬에 굽는다.
XHYPER255B> flash kernel

target 보드를 컸다 키고. 파일시스템으로 들어간다. 

lsmod에는 모듈이 없고.ㅣ /proc/devices에 있는 거 확인 가능 (254 fnd)

 [root@Xhyper255 /root]$lsmod
Module                  Size  Used by
[root@Xhyper255 /root]$cat /proc/devices
Character devices:
  1 mem
  2 pty
  3 ttyp
  4 ttyS
  5 cua
  7 vcs
 10 misc
 11 ads7843
 14 sound
 29 fb
 90 mtd
128 ptm
136 pts
162 raw
253 pcmcia
254 fnd

Block devices:
 31 mtdblock
241 mmc_block



<zimage가 아닌 동적 모듈로 추가하는 것을 이용한다>



menuconfig ui에서 스페이스를 여러번 눌러 <M>으로 선택
위와 동일하게 컴파일 한다. 

make dep
make clean
make zImage

driver들이 실제 컴파일이 일어났는지 확인한다. 
[root@linux2 char]# ls fnd.o
ls: fnd.o: 그런 파일이나 디렉토리가 없음

그러면 어떻게 모듈을 등록하지.. 바로 커널 모듈 컴파일이 필요하다.

우선 zImage를 tftp를 통해서 복사할 수 있도록 복사한다.
[root@linux2 linux]# cp arch/arm/boot/zImage /tftpboot/zImage_my2

모듈을 컴파일한다. 
[root@linux2 linux]# make modules

모듈이 컴파일 되었다. 
[root@linux2 char]# ls fnd.o
fnd.o

그러면 이걸 어떻게 올리지? 
그것은 따로 target의 file system에 해당 커널 모듈을 올리고 나서, /etc/inittab에 insmod를 추가하면 되는 것이다.


[root@linux2 Filesystem]# ls -al
합계 14740
drwxrwxrwx  2 root root    4096  2월 18  2010 .
drwxrwxrwx  8 root root    4096  2월 19  2010 ..
-rwxrwxrwx  1 root root   42087  4월 25  2008 mkfs.jffs2
-rwxrwxrwx  1 root root      73  4월 25  2008 r.sh
-rwxrwxrwx  1 root root 6620848 10월  6  2009 root_xhyper255.tar.gz
-rw-r--r--  1 root root 8388608  2월 18  2010 rootfs.img
 
[root@linux2 Filesystem]# pwd
/root/DD_MULTI/XHyper255B/Filesystem

target에 들어갈 파일 시스템 에 추가하면 된다.
압축을 풀고.. 
[root@linux2 Filesystem]# tar zxvf root_xhyper255.tar.gz  -C ~
[root@linux2 root_xhyper255]# pwd
/root/root_xhyper255

이것이 target 보드의 filesystem 구조이다. 
[root@linux2 root_xhyper255]# ls -al
합계 68
dr-xr-xr-x  15 root root 4096  4월 25  2008 .
drwxr-x---  22 root root 4096  4월 22 11:05 ..
dr-xr-xr-x   2 root root 4096  4월 25  2008 bin
dr-xr-xr-x   2 root root 4096  4월 25  2008 conf
dr-xr-xr-x   4 root root 4096  4월 25  2008 dev
dr-xr-xr-x   7 root root 4096  4월 25  2008 etc
dr-xr-xr-x   2 root root 4096  4월 25  2008 home
dr-xr-xr-x   3 root root 4096  4월 25  2008 lib
-r-xr-xr-x   1 root root  269  4월 25  2008 linuxrc
dr-xr-xr-x   2 root root 4096  4월 25  2008 lost+found
dr-xr-xr-x   5 root root 4096  4월 25  2008 mnt
dr-xr-xr-x   2 root root 4096  4월 25  2008 proc
dr-xr-xr-x   2 root root 4096  4월 25  2008 rd
dr-xr-xr-x   5 root root 4096  4월 25  2008 root
dr-xr-xr-x   2 root root 4096  4월 25  2008 sbin
lrwxrwxrwx   1 root root    8  4월 22 11:05 tmp -> /etc/tmp
dr-xr-xr-x   7 root root 4096  4월 25  2008 usr
lrwxrwxrwx   1 root root    8  4월 22 11:05 var -> /etc/var


그냥 적절한 곳에다가 둔다.
[root@linux2 char]# cp fnd.o ~/root_xhyper255/etc

[root@linux2 etc]# ls fnd.o
fnd.o

파일시스템만들어주는 코드들을 복사한다.
[root@linux2 Filesystem]# ls -al
합계 14744
drwxrwxrwx   3 root root    4096  4월 22 11:05 .
drwxrwxrwx   8 root root    4096  2월 19  2010 ..
-rwxrwxrwx   1 root root   42087  4월 25  2008 mkfs.jffs2
-rwxrwxrwx   1 root root      73  4월 25  2008 r.sh
dr-xr-xr-x  15 root root    4096  4월 25  2008 root_xhyper255
-rwxrwxrwx   1 root root 6620848 10월  6  2009 root_xhyper255.tar.gz
-rw-r--r--   1 root root 8388608  2월 18  2010 rootfs.img
[root@linux2 Filesystem]# cp mkfs.jffs2 ~
[root@linux2 Filesystem]# cp r.sh ~

커널 모듈이 추가된 디렉토리를 압축해야 한다. r.sh를 사용한면 된다. 
내용을 보면, mkfs.jiffs2를 사용했다.. 

[root@linux2 ~]# ./r.sh
   내용
   #!/bin/sh
   ./mkfs.jffs2 -o rootfs.img -e 0x40000 -r root_xhyper255 -p -l


[root@linux2 ~]# ls rootfs.img
rootfs.img

이렇게 만든 root fs을 tftp로 복사한다.
[root@linux2 ~]# cp rootfs.img  /tftpboot/rootfs.img.my

target 보드를  컸다킨다.

kernel을 복사하고 굽는다.
XHYPER255B> tftp zImage_my2 kernel
No IP. Bootp start...
Our Ethernet address is 1234 5678 9A00.
        Sending bootp packet...
..
Bootp Packet received.
        Host   (server) Ethernet : 000C 29F2 5EB0
        Host   (server) IP       : 192.168.1.51
        Client (target) Ethernet : 1234 5678 9A00
        Client (target) IP       : 192.168.1.50

TFTP Start...
        Host   (server) IP       : 192.168.1.51
        Client (target) IP       : 192.168.1.50
        Loading Filename         : zImage_my2
        Save Address             : 0xA0008000

Loading start...
        0x000E2BC0 (928704) bytes received.
        tftp done.


XHYPER255B> flash kernel
Saving kernel to flash...
Erase flash blocks from 0x000C0000 to 0x001BFFFF.
        Erase Block at : 0x00180000.
        Done.
Write to flash...
        Writing at 0x001C0000...
        Done
XHYPER255B>

root fs을 복사하고 굽는다.
XHYPER255B> tftp rootfs.img.my root
TFTP Start...
        Host   (server) IP       : 192.168.1.51
        Client (target) IP       : 192.168.1.50
        Loading Filename         : rootfs.img.my
        Save Address             : 0xA0000000

Loading start...
        0x00800000 (8388608) bytes received.
        tftp done.

XHYPER255B> flash root
Saving root to flash...
Erase flash blocks from 0x001C0000 to 0x01FBFFFF.
        Erase Block at : 0x00340000.


참고로..
target 보드에서 리스타트를 하고 shell 접근하면.
/etc/fnd.o가 있는 것을 확인한다. 

보드에서 등록해 본다. 

[root@Xhyper255 /root]$insmod /etc/fnd.o
 fnd Module id Up....
 fnd:register_chrdev() ok! => major_num:253
fnd Module Insert Done!!
[root@Xhyper255 /root]$mknod /dev/FND c 253 0
[root@Xhyper255 /root]$lsmod
Module                  Size  Used by
fnd                     1648   0  (unused)


이 방법을 응용하면, /etc/initab을 이용하면 된다.

(운영체제 초기화 마지막단에 프로세스 작업을 /etc/inittab에서 진행한다.)
 참고로 /etc/inittab은  pid 0을 띄우고, pid 1, 2,3,4를 띄운다.

 
[root@linux2 etc]# pwd
/root/root_xhyper255/etc
[root@linux2 etc]# ls -al inittab
-r--r--r--  1 root root 1660  4월 25  2008 inittab


이미지를 굽기 전에 마지막에 여기에다가 insmod를 추가하면 될 것이다....
 




'c or linux' 카테고리의 다른 글

[공부중] Memory fs 테스트  (0) 2011.04.22
개념 정리  (0) 2011.04.22
[공부중] mmap 예제  (0) 2011.04.21
/proc 커널 모듈 테스트  (0) 2011.04.21
/proc/interrupts  (0) 2011.04.21
Posted by '김용환'
,