맥에서 리눅스 커널 빌드하기

K 2013.06.30 09:00 조회 수 : 24820 추천:4

맥에 버철박스를 깔아서 리눅스 커널을 빌드하는 모습이... 아름답지 않았습니다. ㅋㅋㅋㅋㅋㅋㅋㅋㅋ

그래서 리눅스 커널을 분석하는데 꼭 필요한건 아니지만, 아름다움을 추구하시는 분들이라면 반드시 갖추어야 할 팁 입니다. ㅋㅋㅋㅋㅋ


질문 있으면 질문 하시고, 더 나은 방법을 알고계시다면 우리 나누어요~ ^^



맥에서 안드로이드용 툴체인으로 리눅스 커널 빌드하기

android kernel 빌드 가이드를 많이 참고하였습니다. 약간의 트윅이 들어가긴 했으나 어쨋든 성공!! LOL

Case-sensitive partition 생성

맥의 기본 파일시스템은 case-preserving but case-insensitive 인데, git을 사용하려면 case-sensitive 파일시스템이 필요하므로 아래 명령어로 생성합니다.

$ hdiutil create -fs 'Case-sensitive Journaled HFS+' -size 40g ~/kernel.dmg

~/.bash_profile나 ~/.profile 등에 아래의 function을 등록해두면 필요할 때 간편하게 mount할 수 있습니다.

# mount the kernel file image
function mountKernel { hdiutil attach ~/kernel.dmg -mountpoint ~/kernel; }

만일 umount 하려면 우선 df나 mount 명령어로 장치명을 확인한 이후에 아래 명령으로 합니다.

$ mount
...
/dev/disk6s2 on /Users/kiban18/kernel (hfs, local, nodev, nosuid, journaled, noowners, mounted by kiban18)

$ hdiutil detach /dev/disk6s2
"disk6" unmounted.
"disk6" ejected.

MacPorts 설치

www.macports.org에 가서 Mac OS X Package (.pkg) Installer를 받아 설치합니다.

설치가 완료되면 MacPorts 자체를 업그레이드 하고 target을 업데이트 및 싱크 해야 합니다.

sudo port selfupdate
sudo port sync

Xcode 설치

Mac App Store에서 Xcode Developer Tools를 설치합니다.

Command Line Developer Tools를 설치합니다.

  1. Xcode를 실행합니다.
  2. Xcode > Preferences를 실행하고, Downloads 탭의 Components 에서 Command Line Tools를 설치합니다.

Xcode EULA를 승인합니다.

xcodebuild -license

(Optional) X11을 설치합니다.

sudo port install xorg-server

필요한 패키지 설치

필요한 툴들은 port install을 통해 설치합니다.

$ POSIXLY_CORRECT=1 sudo port install gmake libsdl git-core gnupg ctags cscops

툴체인 다운로드

http://goo.gl/nTbUa 에서 적당한 툴체인을 선택하여 git clone 합니다. (저는 arm-linux-androideabi-4.7을 다운로드 받았습니다.)

~/kernel/android/toolchain $ git clone https://android.googlesource.com/platform/prebuilts/gcc/darwin-x86/arm/arm-linux-androideabi-4.7

linux_host_include.tar.gz 파일을 다운받아서 적절한 위치에 풀어둡니다. 이것은 추후 발생할 elf.h 에러를 처리하기 위함입니다.

~/kernel $ tar xvzf linux_host_include.tar.gz

커널 소스 내려받기

아무거나 하나 내려받습니다.

커널 빌드

빌드 스크립트를 하나 만들어둡니다.

~/kernel/linux-3.9.7 $ vim ./build.sh
#!/bin/bash
 
export CROSS_COMPILE=~/kernel/android/toolchain/arm-linux-androideabi-4.7/bin/arm-linux-androideabi-
export ARCH=arm
export HOST_EXTRACFLAGS="-I ~/kernel/linux_host_include"
 
make clean
make exynos4_defconfig
make -j16 2>&1 | tee make.log

빌드를 시작합니다.

~/kernel/linux-3.9.7 $ ./build.sh
...
In file included from scripts/sortextable.c:31:
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:4:25: error: linux/types.h: No such file or directory
In file included from scripts/sortextable.c:31:
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:6: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__get_unaligned_be16’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:11: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__get_unaligned_be32’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘__get_unaligned_be64’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:22: error: expected ‘)’ before ‘val’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:28: error: expected ‘)’ before ‘val’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:34: error: expected ‘)’ before ‘val’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:40: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘get_unaligned_be16’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:45: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘get_unaligned_be32’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:50: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘get_unaligned_be64’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:55: error: expected ‘)’ before ‘val’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:60: error: expected ‘)’ before ‘val’
/Users/kiban18/kernel/linux-3.9.7/tools/include/tools/be_byteshift.h:65: error: expected ‘)’ before ‘val’
...
make[1]: *** [scripts/sortextable] Error 1
make: *** [scripts] Error 2

흠.. 열심히 찾아보았습니다. http://goo.gl/S7YYj 이때부터 에러가 나기 시작했더군요.. (mac에서의 에러입니다. linux에서는 에러가 나는지 확인하지 않았습니다. ㅠㅠ)

s/select BUILDTIME_EXTABLE_SORT if MMU/select BUILDTIME_EXTABLE_SORT if (!MMU)

arch/arm/Kconfig를 위와같이 살짝 수정해서 빌드를 해봅니다.

~/kernel/linux-3.9.7 $ ./build.sh
...
  Kernel: arch/arm/boot/Image is ready
  AS      arch/arm/boot/compressed/head.o
  GZIP    arch/arm/boot/compressed/piggy.gzip
  CC      arch/arm/boot/compressed/misc.o
  CC      arch/arm/boot/compressed/decompress.o
  CC      arch/arm/boot/compressed/string.o
  AS      arch/arm/boot/compressed/hyp-stub.o
  SHIPPED arch/arm/boot/compressed/lib1funcs.S
  SHIPPED arch/arm/boot/compressed/ashldi3.S
  AS      arch/arm/boot/compressed/lib1funcs.o
  AS      arch/arm/boot/compressed/ashldi3.o
  AS      arch/arm/boot/compressed/piggy.gzip.o
  LD      arch/arm/boot/compressed/vmlinux
  OBJCOPY arch/arm/boot/zImage
  Kernel: arch/arm/boot/zImage is ready

ㅋㅋㅋ 당분간 이렇게 쓰면서 시간날때 에러를 잡아봐야겠습니다.


위 글의 원본 위키문서 링크 : 

http://iamroot.org/wiki/doku.php?id=스터디:cross_compiling_linux_kernel_on_mac_os_x


번호 제목 글쓴이 날짜 조회 수
공지 [공지] 강좌, 팁, 정보등에 대해 올리는 게시판입니다. woos 2016.04.09 246
129 Pro Git 2장, 3장 요약입니다. 아폴로 2013.11.05 52110
128 포토샵 웹버전입니다. [1] 강진성 2010.05.14 40685
» 맥에서 리눅스 커널 빌드하기 [2] K 2013.06.30 24820
126 #pragma에 관련해서.. [2] 원민수 2006.07.19 20782
125 kernel 2.6의 kzalloc함수 (원민수 씀) 백창우 2007.02.23 19337
124 태훈님에 이어. ARM kernel 참고자료 백창우 2007.11.05 19014
123 리눅스 커널 스터디 참고자료 (x86) [4] 리누즈박 2013.05.06 18396
122 누가 나를 호출했는지 찾기 + 포인터를 심볼 이름으로 변환하여 출력하기 [1] 지현구 2007.02.27 17863
121 systemtap 관련 간단한 소개입니다. 남용우 2007.11.06 17057
120 허접 영어 사전입니다. [3] 백창우 2008.04.22 16092
119 define을 사용한 version 처리. 원민수 2008.02.09 15026
118 여기는 팁, 기타 정보를 올리는 곳입니다. 백창우 2006.06.05 14751
117 커널 분석용 vim 플러그인 설치하기 (Rev.4) [21] 리누즈박 2013.06.30 13973
116 막강 디버깅 매크로 DM_PRINT() [4] file 배상경 2010.11.23 12045
115 if문에 사용하는 likely와 unlikely 함수의 용도 [1] 아폴로 2014.03.05 11173
114 조금은 묵직한 시스템, 뇌감시장치 김성현2 2011.11.17 10585
113 리눅스 커널 코딩 스타일입니다. [1] 아폴로 2013.09.13 10147
112 xen 4.1 설치 방법(우분투 11.04) [2] 이상철 2012.11.14 10109
111 Kernel 소스코드 github에 복사하는 법 [6] 리누즈박 2013.06.16 9836
110 돈되는 이야기?! 삼성 손가락 혈압계 [1] 김성현2 2011.10.20 9493
XE Login