在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 libi n 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?- mainmenu "Handawei OS Configuration"
- config CONFIG_NAME
- string "System Name String"
- default "Handawei config-demo"
- help
- just write you config-name bravly!
- config NO_WPTR
- def_bool y
- choice
- prompt "Choice your CPU arch"
- config ARM_T
- bool "ARM_Samsung"
- config MIPS_T
- bool "MIPS_Cavium"
- config POWERPC_T
- bool "Power PC"
- config X86_T
- bool "Intel X86"
- endchoice
- choice
- prompt "Target Platform Model"
- config ARM_S3C2410_T
- bool "s3c2410"
- depends on ARM_T
- config ARM_S3C6410_T
- bool "s3c6410"
- depends on ARM_T
- config ARM_EXYNOS4412_T
- bool "Exynos4412"
- depends on ARM_T
- config ARM_EXYNOS5410_T
- bool "Exynos5410"
- depends on ARM_T
- config MIPS_CAVM_OCTEON1_T
- bool "Cavium OCTEON I"
- depends on MIPS_T
- config MIPS_CAVM_OCTEON2_T
- bool "Cavium OCTEON II"
- depends on MIPS_T
- config MCU_51_T
- bool "MCU ATMEL 51"
- depends on MCU_T
- endchoice
- menu "Hardware settings"
- config SUPPORT_LINUX
- bool "Support Linux"
- default y if ARM_T || MIPS_T || X86_T || POWERPC_T || SH_T
- config MCPU
- int "CPU numbers used in MCPU platform"
- default y if ARM_T || MIPS_T
- config CPU_NUM
- int "CPU numbers used in MCPU platform"
- default 2
- depends on MCPU
- config CORE_NUM
- int "Cores per CPU"
- range 1 12 if MIPS_CAVM_OCTEON1_T
- range 1 12 if MIPS_CAVM_OCTEON2_T
- default "12" if MIPS_T
- range 1 8 if ARM_T
- default "4" if ARM_EXYNOS4412_T
- default "8" if ARM_EXYNOS5410_T
- config ARENA_MEM_SIZE
- int "Default memory size of arena manager"
- default "500000000"
- config GPIO_MASK_CPU
- hex "GPIO mask of CPU"
- default 0x1 if ARM_S3C2410_T || ARM_S3C6410_T
- depends on MCPU
- config HFA
- bool "Enable Hyper Finite Automata"
- default y if MIPS_CAVM_OCTEON1_T || MIPS_CAVM_OCTEON2_T
- depends on MIPS_T
- if HFA
- menu "HFA hardware configure"
- config HFA_BUF_NUM
- int "HFA input/temp buffers's number"
- default 400
- config HFA_THD_NUM
- int "HFA thread buffers's number"
- default 400
- config HFA_MEM_SIZE
- int "HFA memory size (in mega bytes)"
- default 1024
- endmenu
- endif
- if MIPS_T
- config ETHERNET_PORT
- int "Ethernet port number (range 1 50)"
- default 2
- range 1 50
- config GPIO_PORT
- int "GPIO port number (range 1 1000)"
- default 100
- range 1 1000
- endif
- endmenu
生成的介面如下:
如果在退出時選擇了yse,會將配置儲存到.config 裡.
之後就可以make了.