2017-05-11 221 views
2

到目前爲止,我已經在我的ubuntu系統上安裝了所有的交叉編譯軟件包,但遇到問題並且需要一些幫助。從linux到ARM-ELF(armv5tejl)的交叉編譯

Linux 2.6.28.7 #1 CST 2012 armv5tejl unknown 

$ cat /proc/cpuinfo 
Processor  : ARM926EJ-S rev 5 (v5l) 
BogoMIPS  : 199.47 
Features  : swp half fastmult edsp java 
CPU implementer : 0x41 
CPU architecture: 5TEJ 
CPU variant  : 0x0 
CPU part  : 0x926 
CPU revision : 5 

Hardware  : ServerEngines PILOT3 
Revision  : 0000 
Serial   : 0000000000000000 


[email protected]:~/code$ arm-linux-gnueabi-readelf -h xxx.bin 
ELF Header: 
    Magic: 7f 45 4c 46 01 01 01 61 00 00 00 00 00 00 00 00 
    Class:        ELF32 
    Data:        2's complement, little endian 
    Version:       1 (current) 
    OS/ABI:       ARM 
    ABI Version:      0 
    Type:        EXEC (Executable file) 
    Machine:       ARM 
    Version:       0x1 
    Entry point address:    0xa27c 
    Start of program headers:   52 (bytes into file) 
    Start of section headers:   128752 (bytes into file) 
    Flags:        0x2, GNU EABI, <unknown> 
    Size of this header:    52 (bytes) 
    Size of program headers:   32 (bytes) 
    Number of program headers:   6 
    Size of section headers:   40 (bytes) 
    Number of section headers:   25 
    Section header string table index: 24 

這是我需要交叉編譯的目標機器。編譯時應該使用哪些標誌?

arm-linux-gnueabi-gcc simple.c -march=armv5 -static -o simplev5 
arm-linux-gnueabi-gcc simple.c -mcpu=arm926ej-s -static -o simple926 

當我運行simplev5或simple926,顯示:

Segmentation fault 

遵循@Steven P的意見,我檢查了文件格式,內容如下:

[email protected]:~/code$ file simplev5 
simplev5: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=f0607da1d809a7d98636d76ee0e538fc828e3b65, not stripped 
[email protected]:~/code$ file simple926 
simple926: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, BuildID[sha1]=ed1e6fdade02c0d2c985a503dafb6efadd13522f, not stripped 
+0

可能的重複http://stackoverflow.com/questions/17336236/cross-compile-from-linux-to-arm-elf-arm926ej-s-mt7108 – lnman

+0

可能的重複從Linux到ARM-ELF的交叉編譯(ARM926EJ-S/MT7108)](http://stackoverflow.com/questions/17336236/cross-compile-from-linux-to-arm-elf-arm926ej-s-mt7108)...這個'Linux 2.6.28.7 '是相當古老的,最新的Ubuntu cross-arm可能配置爲更新的Linux。即使「靜止」成功,您仍然有可能無法映射的「swi」調用。 –

+0

[從零開始構建交叉編譯器](http://frank.harvard.edu/~coldwell/toolchain/)可能會有幫助。 [Crosstool-ng](http://crosstool-ng.github.io/)可能會很有用,但它至少會支持舊的GCC版本和可能的Linux版本。通常情況下,需要使用小補丁來使編譯器生成過時的依賴關係。 –

回答

1

你極有可能正確的編譯或者你會得到一個關於無效格式的錯誤。你能確認你有正確的文件格式,通過使用:

file simple926 

嘗試一個更簡單的程序:

int main() { return 123; } 

然後,當你運行它,以確認它做了什麼,你可以檢查結果代碼。

./simple926 
echo $? 

要解決您的分段錯誤,您可能需要退出gdb並檢查堆棧(回溯)。

+0

我檢查了上面列出的文件格式。而且,gdb不存在,無法安裝在目標機器上。我的測試代碼與您的測試代碼類似。 – user6903

+0

對不起,我無法對帖子發表評論,或者我還沒有回答。但是,基於無聊的噪音評論,您應該確保您正在構建與您的已安裝版本相匹配的工具鏈。儘可能匹配內核版本。 –