手把手教你搭建Macbook交叉編譯工具
具體內(nèi)容: ?
首先需要安裝macports
安裝完成后我們使用命令:
callondeMacBook-Pro:~?callon$?sudo?port?install?libelf Password: Error:?Port?libelf?not?found
居然是沒有找到,原因是我們需要更新macports:
callondeMacBook-Pro:~?callon$?sudo?port?-v?selfupdate --->??Updating?MacPorts?base?sources?using?rsync receiving?file?list?...?done base.tar sent?31276?bytes??received?223560?bytes??8090.03?bytes/sec total?size?is?27013120??speedup?is?106.00 receiving?file?list?...?done --->??MacPorts?base?is?already?the?latest?version The?ports?tree?has?been?updated.?To?upgrade?your?installed?ports,?you?should?run ??port?upgrade?outdated callondeMacBook-Pro:~?callon$? callondeMacBook-Pro:~?callon$?sudo?port?upgrade?outdated Password: Nothing?to?upgrade. callondeMacBook-Pro:~?callon$?sudo?port?search?libelf libelf?@0.8.13_2?(devel) ????ELF?object?file?access?library py-pylibelf?@0.1.20110915?(python,?devel) ????Pythonic?wrapper?for?the?libelf?library. py27-pylibelf?@0.1.20110915?(python,?devel) ????Pythonic?wrapper?for?the?libelf?library. Found?3?ports.
此時(shí)就說明我們可以正常使用macports安裝軟件了,下面開始正式操作:
callondeMacBook-Pro:~?callon$?sudo?port?install?libelf
出現(xiàn):
--->??Installing?libelf?@0.8.13_2 --->??Activating?libelf?@0.8.13_2 --->??Cleaning?libelf --->??Updating?database?of?binaries --->??Scanning?binaries?for?linking?errors??????????????? --->??No?broken?files?found.
即為安裝成功。
同理:
callondeMacBook-Pro:~?callon$?sudo?port?install?gsed callondeMacBook-Pro:~?callon$?sudo?port?install?arm-elf-binutils callondeMacBook-Pro:~?callon$?sudo?port?install?arm-elf-gcc
此時(shí)我們的裸機(jī)編譯環(huán)境其實(shí)就搭建好了,但是我們需要把裸機(jī)makefile的所有之前用的arm-linux-xxx換成現(xiàn)在的arm-elf-xxx即可!
callondeMacBook-Pro:hkl-continue?callon$?make?clean rm?-f?*.o?*.elf?*.bin make?-C?dev?clean rm?-f?*.o??????? make?-C?lib?clean rm?-f?*.o??????? callondeMacBook-Pro:hkl-continue?callon$?make arm-elf-gcc?-g?-c?start.S arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?main.c make?-C?dev?all arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?mmu.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?interrupt.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?gpio.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?uart.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?nandflash.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?lcd.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?dma.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?bmp.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?bmpp.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?timer.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?touch.c arm-elf-ld?-r?-o?dev.o?mmu.o?interrupt.o?gpio.o?uart.o?nandflash.o?lcd.o?dma.o?bmp.o?bmpp.o?timer.o?touch.o arm-elf-gcc?-g?-c?mem.S make?-C?lib?all arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?div64.S arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?lib1funcs.S arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?ctype.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?muldi3.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?printf.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?string.c arm-elf-gcc?-g?-fno-builtin?-I/Users/callon/Desktop/hkl-continue/include?-c?vsprintf.c arm-elf-ld?-r?-o?lib.o?div64.o?lib1funcs.o?ctype.o?muldi3.o?printf.o?string.o?vsprintf.o arm-elf-ld?-Thkl.lds?-o?hkl_boot.elf?start.o?main.o?dev/dev.o?mem.o?lib/lib.o arm-elf-objcopy?-O?binary?hkl_boot.elf?hkl_boot.bin arm-elf-objdump?-D?-S?hkl_boot.elf?>?dump callondeMacBook-Pro:hkl-continue?callon$?ls Makefile????hkl.lds?????include?????main.o??????start.S dev?????hkl_boot.bin????lib?????mem.S???????start.S~ dump????????hkl_boot.elf????main.c??????mem.o???????start.o
同樣的嘗試了安裝arm-none-eabi-工具鏈,也能編譯裸機(jī)代碼:
callondeMacBook-Pro:s3c-linux-2.6.28.6-Real6410?callon$?sudo?port?install?arm-none-eabi-gcc
但是編譯不了內(nèi)核,總會出現(xiàn)莫名其妙的問題。
***最后現(xiàn)象總結(jié):***
arm-none-eabi- 能夠編譯內(nèi)核模塊,能夠編譯裸機(jī)代碼,但是在編譯應(yīng)用程序會出錯(cuò):
callondeMacBook-Pro:key_irq_misc?callon$?arm-none-eabi-gcc?-static?key_app.c?-o?key_app key_app.c:?在函數(shù)‘main’中: key_app.c:9:8:?警告:隱式聲明函數(shù)‘open’?[-Wimplicit-function-declaration] ???fd?=?open("/dev/6410key",0); ????????^ key_app.c:11:3:?警告:隱式聲明函數(shù)‘read’?[-Wimplicit-function-declaration] ???read(fd,?&key_num,?4); ???^ key_app.c:15:3:?警告:隱式聲明函數(shù)‘close’?[-Wimplicit-function-declaration] ???close(fd); ???^ /opt/local/lib/gcc/arm-none-eabi/5.1.0/../../../../arm-none-eabi/bin/ld:?cannot?find?crt0.o:?No?such?file?or?directory collect2:?錯(cuò)誤:ld?返回?1
arm-elf- 能夠編譯出應(yīng)用程序和裸機(jī)代碼:
callondeMacBook-Pro:key_irq_misc?callon$?arm-elf-gcc?-static?key_app.c?-o?key_app callondeMacBook-Pro:key_irq_misc?callon$?ls
但是編譯不了內(nèi)核模塊:
callondeMacBook-Pro:key_irq_misc?callon$?make make?-C?/Users/callon/Documents/s3c-linux-2.6.28.6-Real6410?M=/Users/callon/Desktop/key_irq_misc?modules?CROSS_COMPILE=arm-elf-?ARCH=arm ??CC?[M]??/Users/callon/Desktop/key_irq_misc/key.o /Users/callon/Desktop/key_irq_misc/key.c:1:0:?error:?FPA?is?unsupported?in?the?AAPCS make[2]:?***?[/Users/callon/Desktop/key_irq_misc/key.o]?Error?1 make[1]:?***?[_module_/Users/callon/Desktop/key_irq_misc]?Error?2 make:?***?[all]?Error?2
最后還有一種交叉編譯工具:
參考http://blog.csdn.net/rk2900/article/details/8738442
新建一個(gè)磁盤映像:
磁盤工具->文件->新建映像->空白映像
有時(shí)你的磁盤映像還是不區(qū)分大小寫,你可以在磁盤映像下建立兩個(gè)readme和Readme文件夾來測試,如果的確還是不區(qū)分,就磁盤工具選擇:磁盤映像->抹掉
再操作一次就完全正確了,你可以進(jìn)行測試。
然后將下載好的ARMx-2009q3-67.tar.bz2,鏈接在參考的blog中有提到,這里再啰嗦一下:
https://github.com/downloads/UnhandledException/ARMx/ARMx-2009q3-67.tar.bz2
拷貝到磁盤映像下,執(zhí)行命令:
最后修改/etc/profile把path環(huán)境變量修改了,然后source /etc/profile即可!
最后修改內(nèi)核代碼中.config或者M(jìn)akefile里對CROSS_COMPILE的定義,改成arm-none-linux-gnueabi-即可,此時(shí)就可以進(jìn)行內(nèi)核代碼編譯了:
編譯完內(nèi)核再編譯內(nèi)核模塊也就不會有莫名其妙的問題了:
成功!
但是裸機(jī)代碼拿arm-none-linux-gnueabi- 編譯會有問題。
此博文得到的結(jié)論均為實(shí)踐與查找資料所得,僅供參考。