zoukankan      html  css  js  c++  java
  • 【嵌入式】交叉编译环境排错记

    Preface

       把学校的事忙得差不多了,又可以搞这板子了。。。

       minicom的使用操作,前面已经写得很详细,但是下载程序到开发板的过程中,还是有些地方是需要注意的,另外第一次接触,少不了会遇上各种问题


    Step1

       连结好开发板与PC机的串口线与USB下载线


    Step2

       给板子上电,在minicom中选择linux启动

    NAND Flash Boot                                                                  
    
    Please select function :                                                        
    0 : USB download file                                                            
    1 : Uart download file                                                          
    2 : Write Nand flash with download file                                          
    3 : Load Pragram from Nand flash and run                                        
    4 : Erase Nand flash regions                                                    
    5 : Write NOR flash with download file                                          
    6 : Set boot params                                                              
    7 : Set AutoBoot parameter,1:linux 2:wince                                      
    8 : Set Lcd Display,1:DH3.5' 2:DH4.3' 3:QC7.0' 4:QC8.0' 5:VGA                    
    
    3                                                                                
    
    Set boot params = root=1f02 init=/linuxrc console=ttyS0,115200 devfs=mount disp0
    Linux version 2.6.8.1-ptx1 (root@localhost.localdomain) (gcc version 3.3.2) #252
    CPU: ARM920Tid(wb) [41129200] revision 0 (ARMv4T)                                
    CPU: D VIVT write-back cache                                                    
    CPU: I cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets              
    CPU: D cache: 16384 bytes, associativity 64, 32 byte lines, 8 sets              
    Machine: SMDK2410                                                                

    Step3

       进入tmp目录

    [root@(none) /]# cd /tmp                                                        
    
    [root@(none) tmp]# ls                                                            
    Applications            images                  qtembedded-unknown              
    Documents               mplayer                 sdcard                          
    Settings                qcop-msg-qpe            udisk                            
    flashdisk               qcop-msg-quicklauncher                                  

     


    Step4

       输入rz命令

    [root@(none) tmp]# rz
    
    樊[root@(none) tmp]# e.**B0100000023be50                                        

     <注意1>rz 是非常古老的zmodem协议使用的上传下载命令,输入后可以看到下面出现等待接收信息

     


    Step5

       这时输入minicom命令:先按下ctrl+a,然后松开,再按s,即发送命令,出现协议选择,如上,选zmodem

    <注意2>这里是按下ctrl+a,松开后再按s,其它命令也是

    | zmodem    |                                      
    | ymodem    |                                      
    | xmodem    |                                      
    | kermit    |    
    | ascii     |      
    +-----------+

    Step6

       然后进入文件选择

    [r+-------------------[Select one or more files for upload]-------------------+  
    
    [r|Directory: /home/mystery                                                   |  
    Ap| [.gnome2]                                                                 |  
    Do| [.gphoto]                                                                 |  
    Se| [.gstreamer-0.10]                                                         |  
    fl| [.ibus]                                                                   |  
    [r| [.local]                                                                  || [.mission-control]                                                        |  
    [r| [.mozilla]                                                                |  
    Ap| [.onboard]                                                                |  
    Do| [.pki]                                                                    |  
    Se| [.pulse]                                                                  |  
    fl| [.thumbnails]                                                             |  
    [r| [.thunderbird]                                                            |  
    ba| [.xinput.d]                                                               |y
    [r| [Desktop]                                                                 |  
    ba| [Documents]                                                               |y
    [r|              ( Escape to exit, Space to tag )                             |  
    ba+---------------------------------------------------------------------------+y
    [root@(none) tmp]# Cannot suspend - no APM support in kernel                    
                    [Goto]  [Prev]  [Show]   [Tag]  [Untag] [Okay]                 

    <注意3>这里是按两下空格健进入选择,并且是半角状态

     

    Step7

       选择好要下载的文件,回车确认

    +-----------[zmodem upload - Press CTRL-C to quit]------------+        
    
    |Sending: hello.out                                           |        
    |sz: skipped: hello.out                                       |        
    |                                                             |        
    |Transfer complete                                            |        
    |                                                             |        
    | READY: press any key to continue...                         |        
    |                                                             |        
    +-------------------------------------------------------------+      

    Step8

       查看并运行文件

    [root@(none) tmp]# ls                                                            
    
    Applications            hello.out               qcop-msg-quicklauncher          
    Documents               images                  qtembedded-unknown              
    Settings                mplayer                 sdcard                          
    flashdisk               qcop-msg-qpe            udisk                            
    [root@(none) tmp]# ./hello.out                                                  
    bash: ./hello.out:

    Error1

    /lib/ld-linux.so.3: bad ELF interpreter: No such file or diry  

       没有/lib/ld-linux.so.3 ?

    <注意4>ld-linux.so.3是进行动态链接时的连接器


    Solution1

       我估计是我搭建的目标平台下缺少该库,于是我在PC机的交叉编译工具中找到了该文件

    mystery@lcw:/usr/local/arm-4.5.1/arm-none-linux-gnueabi/lib$ ls -l ld-linux*
    
    lrwxrwxrwx 1 mystery mystery 10 Sep 28  2010 ld-linux.so.3 -> ld-2.11.so

       可以看到,该文件只是一个符号链接文件,目标指向ld-2.11.so

       于是我把ld-2.11.so拷贝到目标板中,不过问题又来了

    [root@(none) tmp]# rz                                                          
    [root@(none) tmp]# .**B0100000023be50                                        
    [root@(none) tmp]# ls                                                          
    
    Applications            hello2.out              qcop-msg-quicklauncher          
    Documents               images                  qtembedded-unknown              
    Settings                ld-2.11.so              sdcard                          
    flashdisk               mplayer                 udisk                          
    hello.out               qcop-msg-qpe
    
    [root@(none) tmp]# ./hello2.out                                                
    bash: ./hello2.out: /lib/ld-linux.so.3: bad ELF interpreter: No such file or diy
    
    [root@(none) tmp]# ls /lib/ld-*                                                  
    /lib/ld-2.3.2.so    /lib/ld-linux.so.2                                          
    
    [root@(none) tmp]# mv /tmp/ld-2.11.so /lib/                                      
    mv: unable to open `/lib/ld-2.11.so': Read-only file system      

       只读文件系统。。。好吧,为了和书上保持一致,文件系统我先不动,所以我只能另外想办法 


    Solution2

       既然是解决动态链接问题,那我静态编译,应该就不会调用链接器了吧

    [root@(none) tmp]# rz                                                            
    �[root@(none) tmp]# ls*B0100000023be50                                          
    
    Applications            hello.out               qtembedded-unknown              
    Documents               images                  sdcard                          
    Settings                mplayer                 udisk                            
    flashdisk               qcop-msg-qpe                                            
    hello-s.out             qcop-msg-quicklauncher                                  
    
    [root@(none) tmp]# ./hello-s.out                                                
    Segmentation fault                                                              

       虽然链接问题解决了,但是代价也是相当大的,首先就体现在文件大小上

    mystery@lcw:~/Desktop/arm-gcc-c/hello$ ls -l
    
    total 608
    -rw-rw-r-- 1 mystery mystery     94 Apr 12 09:23 hello.c
    -rwxrwxr-x 1 mystery mystery   7816 Apr 12 09:30 hello.out
    -rwxrwxr-x 1 mystery mystery 607564 Apr 12 16:41 hello-s.out

       文件比都接近100倍了,晕,传输时间自然就增加了,还有其它的问题


    Error2

    [root@(none) tmp]# ./hello-s.out                                                
    
    Segmentation fault  

       纳尼,段错误。。。不会吧,回pc验证下

    mystery@lcw:~/Desktop/arm-gcc-c/hello$ gcc hello.c -o hello-gcc.out
    
    mystery@lcw:~/Desktop/arm-gcc-c/hello$ ls
    hello.c  hello-gcc.out  hello.out  hello-s.out
    mystery@lcw:~/Desktop/arm-gcc-c/hello$ ./hello-gcc.out  
    hello,welcome to arm-linux !  

       呃,PC下正确,该纠结呢,看看源代码

    <code-1>

     #include <stdio.h>
                                                                     
    int main(void)                                                              
    {                                                                            
          printf("hello,welcome to arm-linux ! 
    ");                          
          return 0;                                                            
    }  

       第一次嘛,当然是最经典的hello代码了,但这么短的代码也段错误。。。看看有没有警告

    mystery@lcw:~/Desktop/arm-gcc-c/hello$ arm-linux-gcc hello.c -o hello-debug.out -Wall
    mystery@lcw:~/Desktop/arm-gcc-c/hello$ ls
    hello.c  hello-debug.out  hello-gcc.out  hello.out  hello-s.out

       也木有警告啊


    Try

       哎,慢慢搞吧,什么事,总是会有第一次的

       段错误,意思就是访问了不该访问的内存,这里就一个printf函数,嗯

       据说有的编译器会对printf的参数中的字符串进行分析,改一下

    <code-2>

    #include <stdio.h>
    
    int main(void)
    
    {
    
       char *s = "hello,welcome to arm-linux !
    ";
    
       printf(s);
    
       return 0;
    
    }

       还是不行,依然段错误

    <code-3>

    #include <stdio.h>
    
    int main(void)
    
    {
    
       //char *s = "hello,welcome to arm-linux !
    ";
    
       char s[]="heool,welcome to arm-linux !
    ";
    
       printf("%s",s);
    
       return 0;
    
    }

       照样错误,是目标板上的环境有问题吗?太纠结了,这个问题下回分解吧

       网上查了下,错误分析链接如下,暂时等待解决

       http://www.friendlyarm.net/forum/topic/246

       排除各种可能性,好吧,内核不匹配,从头开始。。。。。。。。。。。。。。。。。


    补充

       历时好几天,分别用arm-linux-gcc,4.5.1,4.4.3,4.3.2,3.4.1,3.2.3版本编译过linux内核3.4.40,2.4.14版本下s3c2410,smdk2410内核,cramfs只读文件系统,改写过bootloader源代码,遇到过N个问题,尝试过N种方法,终于搞好啦。

      


    总结 

       虽然kernel很complex,但终究不过是一段裸机代码,Bootloader进行所谓的“kernel引导”,其过程不过是从bootloader里的一句跳转代码,跳转到kernel代码处(执行kernel中的第一个函数),所谓传递参数也不过是bootloader和kernel约定一个内存地点存放。在这个过程中,bootloader和kernel虽然都处于同一个内存里,但是它们除了“引导”与“传递有限的参数”这样的关系,并无其它关系,完全是两个独立的程序。另外在内核中必须读出所有写入内核的硬件配置信息,开始就是NAND分区信息错误,搞得始终无法挂载根文件系统,MTD都读不出来,几经尝试,加上网友的建议和强大的谷歌,通过分析arm引导过程,黑盒子又清楚一点啦!

       纳尼?新手伤不起。。。。

  • 相关阅读:
    Linux学习笔记(二):实战-根据微服务端口号关闭进程
    Linux学习笔记(一):文件操作命令
    算法-Java组合
    Springboot学习笔记(六)-配置化注入
    Springboot学习笔记(五)-条件化注入
    Springboot学习笔记(四)-配置相关
    Springboot学习笔记(三)-常用注入组件方式
    CentOS7安装MySQL
    扫二维码下载apk并统计被扫描次数(及微信屏蔽下载解决方案)
    Java jacob调用打印机打印word文档
  • 原文地址:https://www.cnblogs.com/lcw/p/3159426.html
Copyright © 2011-2022 走看看