Macbook搭建交叉編譯工具以及區別
內容均為實踐所得。
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.
此時就說明我們可以正常使用macports安裝軟體了,下面開始正式操作:
callondeMacBook-Pro:~ callon$ sudo port install libelf
出現:
---> 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
此時我們的裸機編譯環境其實就搭建好了,但是我們需要把裸機makefile的所有之前用的arm-linux-xxx換成現在的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-工具鏈,也能編譯裸機程式碼:
callondeMacBook-Pro:s3c-linux-2.6.28.6-Real6410 callon$ sudo port install arm-none-eabi-gcc
但是編譯不了核心,總會出現莫名其妙的問題。
***最後現象總結:***
arm-none-eabi- 能夠編譯核心模組,能夠編譯裸機程式碼,但是在編譯應用程式會出錯:
callondeMacBook-Pro:key_irq_misc callon$ arm-none-eabi-gcc -static key_app.c -o key_app
key_app.c: 在函式‘main’中:
key_app.c:9:8: 警告:隱式宣告函式‘open’ [-Wimplicit-function-declaration]
fd = open("/dev/6410key",0);
^
key_app.c:11:3: 警告:隱式宣告函式‘read’ [-Wimplicit-function-declaration]
read(fd, &key_num, 4);
^
key_app.c:15:3: 警告:隱式宣告函式‘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: 錯誤:ld 返回 1
arm-elf- 能夠編譯出應用程式和裸機程式碼:
callondeMacBook-Pro:key_irq_misc callon$ arm-elf-gcc -static key_app.c -o key_app
callondeMacBook-Pro:key_irq_misc callon$ ls
但是編譯不了核心模組:
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
新建一個磁碟映像:
磁碟工具->檔案->新建映像->空白映像
有時你的磁碟映像還是不區分大小寫,你可以在磁碟映像下建立兩個readme和Readme資料夾來測試,如果的確還是不區分,就磁碟工具選擇:磁碟映像->抹掉
再操作一次就完全正確了,你可以進行測試。
然後將下載好的ARMx-2009q3-67.tar.bz2,連結在參考的blog中有提到,這裡再囉嗦一下:
https://github.com/downloads/UnhandledException/ARMx/ARMx-2009q3-67.tar.bz2
拷貝到磁碟映像下,執行命令:
最後修改/etc/profile把path環境變數修改了,然後source /etc/profile即可!
最後修改核心程式碼中.config或者Makefile裡對CROSS_COMPILE的定義,改成arm-none-linux-gnueabi-即可,此時就可以進行核心程式碼編譯了:
編譯完核心再編譯核心模組也就不會有莫名其妙的問題了:
成功!
但是裸機程式碼拿arm-none-linux-gnueabi- 編譯會有問題。
此博文得到的結論均為實踐與查詢資料所得,僅供參考。