맥에 버철박스를 깔아서 리눅스 커널을 빌드하는 모습이... 아름답지 않았습니다. ㅋㅋㅋㅋㅋㅋㅋㅋㅋ
그래서 리눅스 커널을 분석하는데 꼭 필요한건 아니지만, 아름다움을 추구하시는 분들이라면 반드시 갖추어야 할 팁 입니다. ㅋㅋㅋㅋㅋ
질문 있으면 질문 하시고, 더 나은 방법을 알고계시다면 우리 나누어요~ ^^
맥에서 안드로이드용 툴체인으로 리눅스 커널 빌드하기
android kernel 빌드 가이드를 많이 참고하였습니다. 약간의 트윅이 들어가긴 했으나 어쨋든 성공!!
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를 설치합니다.
- Xcode를 실행합니다.
- 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
.
추천 드리고갑니다. ^^