MAC OSX 10.10 Yosemite 下編譯 OP_TEE

0. 安裝一些必備文件


brew install libelf gnu-sed binutils(解決readelf)

將sed、find、readlink、xargs、readelf分別鏈接到g開頭的同名文件


1. 下載源碼


repo init -u https://github.com/OP-TEE/manifest.git -m default.xml -b master

repo sync


2. 修改toolchains


gcc-linaro-arm-linux-gnueabihf-2014.05_mac.pkg會將toolchain安裝到

/usr/local/linaro/arm-linux-gnueabihf


因此,需要:

sudo ln -s /usr/local/linaro/arm-linux-gnueabihf ~/works/optee/toolchains/aarch32


3. 修改build/toolchain.mk


ROOT                            ?= ${HOME}/works/optee


4. 解決一系列錯誤

4.1 'elf.h' 等一系列文件找不到

參照http://stackoverflow.com/questions/10018764/building-linux-kernel-on-mac-os-x


First you'll need the following files to cross-compile a kernel on an OS X box (copy them from your known-working Linux VM to your local /usr/include):

/usr/include/elf.h

/usr/include/features.h

/usr/include/stdc-predef.h

/usr/include/bits/*.h

/usr/include/gnu/*.h

/usr/include/byteswap.h

/usr/include/error.h


Next you'll need malloc.h to be in the expected location for a Linux system, so do:

sudo ln -s /usr/include/malloc/malloc.h /usr/include/malloc.h


4.2 

/usr/include/i386/_types.h:46:20: error: typedef redefinition with different types ('long long' vs 'long')

typedef long long               __int64_t;

                                ^

/usr/include/bits/types.h:43:25: note: previous definition is here

typedef signed long int __int64_t;

解決:

sudo rm /usr/include/bits/types.h

sudo ln -s /usr/include/i386/_types.h /usr/include/bits/types.h


4.3 

Undefined symbols for architecture x86_64:

  "_error", referenced from:

      _main in vdsomunge-a7211f.o

  "_error_message_count", referenced from:

      _cleanup in vdsomunge-a7211f.o

ld: symbol(s) not found for architecture x86_64


參照:https://www.assembla.com/spaces/phylogenetic-likelihood-library/messages/2592013


… had to "remove that #include <error.h> and also remove the error (...) call in …

… quick look on google suggests that this is what people do on MacOSX for error.h …


我的處理,將原來從ubuntu拷貝過來的error.h中的內容修改:

#define error(__status, __errnum, __format, ...)

//     __attribute__ ((__format__ (__printf__, 3, 4)));


#define error_at_line(__status, __errnum, __fname, \

  __lineno, __format, ...)

//     __attribute__ ((__format__ (__printf__, 5, 6)));


/* If NULL, error will flush stdout, then print on stderr the program

   name, a colon and a space.  Otherwise, error will call this

   function without parameters instead.  */

#define error_print_progname


/* This variable is incremented each time `error' is called.  */

int error_message_count = 0;


/* Sometimes we want to have at most one error per line.  This

   variable controls whether this mode is selected or not.  */

int error_one_per_line = 0;


4.4 解決 MAP_ANON 錯誤

util/oslib-posix.c:132:22: error: use of undeclared identifier 'MAP_ANON'

                     MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);

                     ^

/Users/manfeel/works/optee/qemu/include/qemu-common.h:61:23: note: expanded from macro 'MAP_ANONYMOUS'

#define MAP_ANONYMOUS MAP_ANON


實際上MAP_ANON是定義在/usr/include/sys/mman.h中的

#define MAP_ANON        0x1000  /* allocated from memory, swap space */

不知爲何出錯!

只好修改qemu-common.h中爲:

#define MAP_ANONYMOUS 0x1000


4.5 util/qemu-openpty.c:39:11: fatal error: 'pty.h' file not found

# include <pty.h>


這個問題由如下包含關係導致:

  CC    util/qemu-openpty.o

In file included from util/qemu-openpty.c:36:

In file included from /Users/manfeel/works/optee/qemu/include/qemu-common.h:120:

In file included from /Users/manfeel/works/optee/qemu/include/qemu/bswap.h:17:

In file included from /usr/include/byteswap.h:21:

/usr/include/features.h:388:10: fatal error: 'gnu/stubs.h' file not found

#include <gnu/stubs.h>


因爲gnu目錄是從linux拷貝,可能和mac系統衝突了


看來4.4的問題也應該和此有關。


原來問題在configure中(生成config-host.mak),如果存在/usr/include/features.h

則會在config-host.mak中添加 CONFIG_BYTESWAP_H=y

實際上,OSX(DARWIN)是不需要這個配置的。

找到3513行,修改爲:

# Search for bswap_32 function

byteswap_h=no

# add by Manfeel for DARWIN

if test "$darwin" != "yes"; then

cat > $TMPC << EOF

#include <byteswap.h>

int main(void) { return bswap_32(0); }

EOF

if compile_prog "" "" ; then

  byteswap_h=yes

fi

fi



5. 最後,進入build目錄

make all

你就可以在mac下愉快的和optee玩耍了,最後還有一個關於gnome-terminal的小問題,留給聰明的讀者朋友去解決吧。

###


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章