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

生成的界面如下:




如果在退出时选择了yse,会将配置保存到.config 里. 

之后就可以make了. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值