1. 程式人生 > >在Mac上編譯uboot,linux kernel

在Mac上編譯uboot,linux kernel

在OSX上交叉編譯

Macports

The Kernel source requires a case-sensitive filesystem. If you do not have a HFS+ Case-sensitive partition that can be used, create a disk image with the appropriate format. Ensure latest Xcode and command line tools are installed from Apple Developer Connection Install macports

port install arm-none-eabi-gcc
port install arm-none-eabi-binutils

If you get an error message that elf.h is missing

sudo port install libelf && sudo ln -s /opt/local/include/libelf /usr/include/libelf

From opensource.apple.com, download and copy elf.h and elftypes.h to /usr/include

Edit elf.h and add

#define R_386_NONE        0
#define R_386_32          1
#define R_386_PC32        2
#define R_ARM_NONE        0
#define R_ARM_PC24        1
#define R_ARM_ABS32       2
#define R_MIPS_NONE       0
#define R_MIPS_16         1
#define R_MIPS_32         2
#define R_MIPS_REL32      3
#define R_MIPS_26         4
#define R_MIPS_HI16       5
#define R_MIPS_LO16       6

If you get a "SEGMENT_SIZE is undeclared" error open the Makefile and change the line:

NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)

to

NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include) -Dlinux

Complete script requires raspberrypi.config to be in the same folder that you execute from

sudo port install arm-none-eabi-gcc
sudo port install arm-none-eabi-binutils
sudo port install libelf && sudo ln -s /opt/local/include/libelf /usr/include/libelf
sudo curl http://opensource.apple.com/source/dtrace/dtrace-48/sys/elftypes.h?txt -o  /usr/include/elftypes.h
sudo curl http://opensource.apple.com/source/dtrace/dtrace-48/sys/elf.h?txt -o /usr/include/elf.h
#code to append to elf.h
echo "
#define R_386_NONE 0
#define R_386_32 1
#define R_386_PC32 2
#define R_ARM_NONE 0
#define R_ARM_PC24 1
#define R_ARM_ABS32 2
#define R_MIPS_NONE 0
#define R_MIPS_16 1
#define R_MIPS_32 2
#define R_MIPS_REL32 3
#define R_MIPS_26 4
#define R_MIPS_HI16 5
#define R_MIPS_LO16 6" > elf-append.h
sudo -s 'cat elf-append.h >> /usr/include/elf.h'

因為mac沒有elf.h這個標頭檔案,在編譯核心的時候需要。

做完這些後編譯

:make ARCH=arm CROSS_COMPILE=arm-none-eabi- menuconfig

會出現下面的錯誤:

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

於是網上找到下面的解決方法

本文目的:

一, 解決在mac 系統裡make menuconfig 報錯:  lcd: symbol(s) not found for architecture x86_64 的bug

二,  使用mconf, 自定義實現一個make menuconfig的介面

一, 在MAC 系統下使用make menuconfig 呼叫圖形介面做config時,  可能會有如下報錯:

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

一般地, 編譯busybox或者uboot或者linux核心等軟體包之前,  還是使用圖形介面來做配置最為最直觀.  實現這一目的自然是執行make menuconfig. 

make menuconfig 實際上就是拿 mconf 這個工具去解析config檔案裡的描述資訊, 進而轉換為圖形介面, 當然, config 檔案有自動定義的語法格式, 詳細見本文最下放. 

第一次執行make menuconfig時, 需要先生成 mconf 這個工具, 在預編譯 scripts/kconfig/mconf.c 生成scripts/kconfig/mconf.o 之後的連線階段,   

需要ldconfig引數給出所需要連線的庫的位置,  所說的庫為字尾為.a 或.so 或 .dylib 的ncursesw ncurses curses庫, 

生成ldflags的的指令碼為: scripts/kconfig/lxdialog/check-lxdialog.sh

上面報錯的原因就是,   MAC 系統下  ncursesw ncurses curses 這些庫檔案的位置不能通過 check-lxdialog.sh 裡給出命令來找到, 所以生成的 ldflags 不對, 進而無法生成mconf. 

該bug的解決辦法如下:

以編譯 busybox 為例子:

開啟 scripts/kconfig/lxdialog/check-lxdialog.sh  檔案. 

vi scripts/kconfig/lxdialog/check-lxdialog.sh


將紅色部分新增進去即可. 

ldflags()

{

for extin so a dylib;do

for libn ncursesw ncurses curses ;do

$cc-print-file-name=lib${lib}.${ext} | grep-q /

if [$?-eq0];then

echo"-l${lib}"

exit

fi

done

for lib in ncursesw ncurses curses ; do

if [ -f /usr/lib/lib${lib}.${ext} ];then

echo"-l${lib}"

exit

fi

done

done

exit1

}


之後回到 busybox的目錄下:

make menuconfig :

在進行uboot , 或者linux 的編譯時, 如果make menuconfig 也出現該問題: 

ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)


同樣的解決辦法即可生效. 

二,  在生成了mconf之後,  我們可以按特定的語法寫出config 檔案, 進而自定義make menuconfig介面:

以下是我的config 檔案, 語法是簡單而且通用的, 您可以仿照如下程式碼自定義出自己的介面:

[plain] view plaincopyprint?在CODE上檢視程式碼片派生到我的程式碼片
  1. mainmenu "Handawei OS Configuration"  
  2. config CONFIG_NAME  
  3.     string "System Name String"  
  4.     default "Handawei config-demo"  
  5.     help   
  6.         just write you config-name bravly!  
  7. config NO_WPTR  
  8.     def_bool y  
  9. choice  
  10.     prompt "Choice your CPU arch"  
  11.     config ARM_T  
  12.         bool "ARM_Samsung"  
  13.     config MIPS_T  
  14.         bool "MIPS_Cavium"  
  15.     config POWERPC_T  
  16.         bool "Power PC"  
  17.     config X86_T  
  18.         bool "Intel X86"  
  19. endchoice  
  20. choice  
  21.     prompt "Target Platform Model"  
  22.     config  ARM_S3C2410_T  
  23.         bool "s3c2410"  
  24.         depends on ARM_T  
  25.     config ARM_S3C6410_T  
  26.         bool "s3c6410"  
  27.         depends on ARM_T  
  28.     config ARM_EXYNOS4412_T  
  29.         bool "Exynos4412"  
  30.         depends on ARM_T  
  31.     config ARM_EXYNOS5410_T  
  32.         bool "Exynos5410"  
  33.         depends on ARM_T  
  34.     config MIPS_CAVM_OCTEON1_T  
  35.         bool "Cavium OCTEON I"  
  36.         depends on MIPS_T  
  37.     config MIPS_CAVM_OCTEON2_T  
  38.         bool "Cavium OCTEON II"  
  39.         depends on MIPS_T  
  40.     config MCU_51_T  
  41.         bool "MCU ATMEL 51"  
  42.         depends on MCU_T  
  43. endchoice  
  44. menu "Hardware settings"  
  45.     config SUPPORT_LINUX  
  46.         bool "Support Linux"  
  47.         default y if ARM_T || MIPS_T || X86_T || POWERPC_T || SH_T  
  48.     config MCPU  
  49.         int "CPU numbers used in MCPU platform"  
  50.         default y if ARM_T || MIPS_T  
  51.     config CPU_NUM  
  52.         int "CPU numbers used in MCPU platform"  
  53.         default 2  
  54.         depends on MCPU  
  55.     config CORE_NUM  
  56.         int "Cores per CPU"  
  57.         range 1 12 if MIPS_CAVM_OCTEON1_T  
  58.         range 1 12 if MIPS_CAVM_OCTEON2_T  
  59.         default "12" if MIPS_T  
  60.         range 1 8 if ARM_T  
  61.         default "4" if ARM_EXYNOS4412_T  
  62.         default "8" if ARM_EXYNOS5410_T  
  63.     config ARENA_MEM_SIZE  
  64.         int "Default memory size of arena manager"  
  65.         default "500000000"  
  66.     config GPIO_MASK_CPU  
  67.         hex "GPIO mask of CPU"  
  68.         default 0x1 if ARM_S3C2410_T || ARM_S3C6410_T  
  69.         depends on MCPU  
  70.     config HFA  
  71.         bool "Enable Hyper Finite Automata"  
  72.         default y if MIPS_CAVM_OCTEON1_T || MIPS_CAVM_OCTEON2_T  
  73.         depends on MIPS_T  
  74.         if HFA  
  75.         menu "HFA hardware configure"  
  76.         config HFA_BUF_NUM  
  77.             int "HFA input/temp buffers's number"  
  78.             default 400  
  79.         config HFA_THD_NUM  
  80.             int "HFA thread buffers's number"  
  81.             default 400  
  82.         config HFA_MEM_SIZE  
  83.             int "HFA memory size (in mega bytes)"  
  84.             default 1024  
  85.         endmenu  
  86.         endif  
  87.     if MIPS_T  
  88.     config ETHERNET_PORT  
  89.         int "Ethernet port number (range 1 50)"  
  90.         default 2  
  91.         range 1 50  
  92.     config GPIO_PORT  
  93.         int "GPIO port number (range 1 1000)"  
  94.         default 100  
  95.         range 1 1000  
  96.     endif  
  97. endmenu  

生成的介面如下:


如果在退出時選擇了yse,會將配置儲存到.config 裡. 

之後就可以make了.