Build Android Kernel of x86 on OS X

Target Platform

nexus player, x86

Mac Hardware

MacBook Pro (Retina, 13-inch, Early 2015)

System

macOS Sierra, 10.12.3

OS X SDK

1
2
3
4
5
6
ls -ali /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs
1915385 drwxr-xr-x 5 root wheel 170 2 9 09:37 .
1914962 drwxr-xr-x 5 root wheel 170 12 16 06:44 ..
1915386 drwxr-xr-x 5 root wheel 170 9 17 2017 MacOSX.sdk
2086424 drwxr-xr-x@ 5 ice wheel 170 11 16 2015 MacOSX10.11.sdk
1948121 lrwxr-xr-x 1 root wheel 10 2 9 09:08 MacOSX10.12.sdk -> MacOSX.sdk

Issue fixing

elf.h file not found

拷贝 elf.h (二选一,两个都行)

  • GitHub
  • /Volumes/android/aosp/external/elfutils/libelf/elf.h,遇到了features.h文件未找到的错误,就将#include <features.h> 一行注释掉。
    elf.h 拷贝到 /usr/include 或者 /usr/local/include 中,推荐放在后者,放在前者的话系统升级时会覆盖。
    目前发现 libelf 不需要。

byteswap.h file not found

1
2
3
4
5
6
In file included from arch/x86/tools/relocs_32.c:1:
arch/x86/tools/relocs.h:13:10: fatal error: 'byteswap.h' file not found
#include <byteswap.h>
^
1 error generated.
make[1]: *** [arch/x86/tools/relocs_32.o] Error 1

解决:拷贝对应文件夹中的头文件

arch/x86/kernel/cpu/capflags.c:69:31: error: expected expression before ‘]’ token

[X86_FEATURE_PCLMULQDQ (432+] = “pclmulqdq (432+”,
等这一个C文件里的错误。

根据Linux的github里面的sh脚本,这个文件应该是根据
arch/x86/kernel/cpu/mkcapflags.sh
/Volumes/android/x86_64/arch/x86/include/asm/cpufeature.h 和生成的。

解决:拷贝对应文件夹中的capflags.c

下载 GNU sedstat

起初未替换sedstat, 内核编译好了,启动不了

1
brew install gnu-sed coreutils

设置环境变量PATH
按照上述安装命令中生成的提示信息设置PATH