역시나 UBUNTU 18.04에서...
- SMALL TALK-
Bootcode의 이해를 위해서는 DS-5 사용해 보기가 딱이다.
커널 이해를 위해서는 디바이스 드라이버부터 시작한다. 오늘은 2편.
__0__
전 시간에는 캐릭터(c)디바이스 드라이버 모양을 알기 위해 /dev/kmsg나 dmesg -wH 로 확인 가능한 Hello, World를 실습해 보았다. devfs까지 포함된 것은 내가 더 포스팅 할 필요없이
https://www.apriorit.com/dev-blog/195-simple-driver-for-linux-os
가 완벽하다.
__1__ 주의사항
해당 포스팅에 제공되는 소스를 우분투 18.04에 컴파일 하기 위해서는 몇가지 에러를 수정해야 한다.
우선, device_file.c 에 헤더를 하나 더 추가해야 한다.
#include <linux/uaccess.h>
fatal error: asm/bitsperlong.h: No such file or directory
compilation terminated.
의 경우 export ARCH=`uname -m`으로 해결가능
CONFIG_X86_X32 enabled but no binutils support 의 경우
sudo apt-get install --reinstall linux-headers-`uname -r`
그 외 빌드 관련 파일 에러,
apt install debsums -> debsums -s 로 missing file checking 후 처리.
그러나 바닐라 커널을 받아 직접 컴파일 후 자신의 커널을 업뎃한 경우 다음이 발생할 수 있다.
/lib/modules/4.17.10/build: No such file or directory. Stop.
make modules_install 이 후 /lib 폴더에 모듈이 제대로 되었는지 확인이 필요하다.
모듈 인스톨 되었지만 해당 폴더 가보면 깨진 링크가 존재하는 경우 -> 알아서 잘...
Cannot write: Broken pipe 권한 문제 -> root로.
make[1]: Entering directory '/usr/src/linux-headers-4.10.0-32-generic'
arch/x86/Makefile:140: CONFIG_X86_X32 enabled but no binutils support
CC [M] /home/eddie/Desktop/dd/simple/src/main.o
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-mno-sse’
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-mno-mmx’
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-mno-sse2’
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-mno-3dnow’
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-m64’
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-mno-red-zone’
arm-linux-gnueabihf-gcc: error: unrecognized command line option ‘-mcmodel=kernel’
문제는
export CROSS_COMPILE=
로 해결. 임베디드 장비에 크로스 컴파일링을 많이 하다보니 크로스 컴파일러로 선언되어 있을 때 에러가 난다. Makefile 수정해도 되겠지만 환경 변수 수정이 빠르다.
__2__
root@ubuntu:~/dd2/src# cat /dev/simple-driver
Hello world from kernel mode!
오픈소스는 정말 좋다. 안 써본 사람들은 오픈소스 별거 있냐고 생각하고 써본 사람들은 대단하긴 한데 내 프로젝트에 수정없이 바로 쓸 수 있는 오픈소스는 없다고 한다. 해당 사이트의 오래된 포스팅이다 보니 그런 듯
__Fin__