嵌入式笔记

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_30787727/article/details/100053791

回顾:
    裸板中软件框架结构
        一系列的初始化
        while(1)
        {
            周期性事务
            ...
        }
        
            +
        异常处理过程
    以按键触发IRQ异常为例 arm中异常的处理流程 
        1)使按键能够触发IRQ异常
           中断源:管脚功能设置
                   配置了中断的触发条件(检测模式)
                   中断的使能
           中断控制器:设置中断优先级
                       中断使能
                       特性,报告给哪个核
                             以IRQ/FIQ上报
           arm core:中断使能 cpsr.I =0   
        2) ARM收到异常,自动做4件事
           备份CPSR
           修改CPSR
           保存返回地址到LR
           给PC赋值  pc=base+0x18 (跳转异常向量表)
        3)异常向量表中继续跳转
           跳转到IRQ异常处理代码irq_handler中去 
           
           irq_handler:
               保护现场 //需要压栈的寄存器压栈
               bl c_irq_handler
               恢复现场
           
           c_irq_handler:
               判断哪个硬件触发的中断
               调用该硬件中断处理函数
               处理完该硬件中断 要把中断源 中断控制器级的pending清除
--------------------------------------------------------------------
系统移植

1、什么叫移植
   将现有的代码,根据目标硬件平台的差异
   做少量的修改
   从而使得该代码可以目标硬件平台执行起来的过程
   
2、移植的内容
  2.1 uboot的移植
  2.2 linux的移植
  2.3 根文件系统镜像的制作与使用 
      ls  rm  cd ...  

3、开发板的烧写实验
   烧写完整的linux系统到开发板上去
   
   一个完整的linux系统最少包含三部分内容:
       1)bootloader (BIOS)
         uboot属于bootloader的一种
       2)kernel
         linux,
       3)rootfs 
         一号进程  cd ls rm ...
   统一分区:
      fdisk 2 3 0x100000:0x4000000 0x4100000:0x2f200000 0x33300000:0      
  3.1 uboot烧写过程
      参考arm/day01/bj01.txt
  3.2 linux烧写过程
      cp /mnt/hgfs/porting/env/uImage /tftpboot/
      tftp 48000000 uImage
      mmc write 48000000 800 3000
      
      //加载linux内核到开发板的内存
      mmc read 48000000 800 3000
      //启动linux内核 
      bootm 48000000 
      
      最终实验现象:
           Kernel panic - not syncing: VFS: Unable to mount root fs
           Rebooting in 5 seconds 。。。   
             
              
      自启动的实现
         setenv bootcmd mmc read 48000000 800 3000 \;bootm 48000000
         saveenv
         
      bootcmd,定义了uboot自动完成的工作   
  3.3 烧写根文件系统镜像
      
      cp /mnt/hgfs/porting/env/rootfs_ext4.img /tftpboot/        
      du -h /tftpboot/rootfs_ext4.img  大概100M
      
      tftp 48000000 rootfs_ext4.img
      mmc write 48000000 20800 32000
      
      setenv bootargs root=/dev/mmcblk0p2 rootfstype=ext4 
              init=/linuxrc console=ttySAC0 maxcpus=1 
              lcd=wy070ml tp=gslx680-linux  loglevel=1
             root=/dev/mmcblk0p2, 指定根文件存在于mmc第二个分区中
             rootfstype=ext4, 告诉linux内核mmc第二个分区中使用的文件系统类型
             init, 指定用户空间1号进程
             console,指定控制台
                     ttySAC0,对应是uart0控制器
             maxcpus=1, 只启动一个核
             
             lcd=wy070ml,指定lcd型号 
             tp=gslx680, 指定触摸屏型号
      saveenv
      
      bootargs, 通知linux去哪找根文件系统
                        
      用户名:root
      密码: 123456        
           
      ps
      
      kill -9 142 

4、应用程序
   vi hello.c      
   arm-cortex_a9-linux-gnueabi-gcc hello.c -o hello_arm
   file hello_arm  
   cp hello_arm  /tftpboot/
   
   开发板上执行
       cd /
       ifconfig eth0 192.168.1.6
       ping 192.168.1.8
       tftp -g -r hello_arm 192.168.1.8
          -g : get
          -r:  remote
       chmod +x hello_arm
       ./hello_arm
          
    
5、nfs方式挂载根文件系统
  nfs: net file system
  
  5.1 安装nfs server软件
      联网:
           sudo apt-get install nfs-kernel-server

      未联网: 
           cd /home/tarena/Downloads/nfs/
           sudo dpkg -i *.deb
           
           可以通过 dpkg -l | grep "nfs"检查是否安装成功
           
           ii  nfs-kernel-server
  5.2 在ubuntu系统中准备客户端需要的根文件系统
      
      cd /home/tarena/
      mkdir porting
      cd porting
      cp /mnt/hgfs/porting/env/rootfs_qt.tar.bz2 ./
      tar xf rootfs_qt.tar.bz2
  5.3 配置nfs服务器
      设置允许客户端可以通过nfs协议访问ubntu系统中的哪些目录
      
      sudo vi /etc/exports
         /home/tarena/porting/rootfs  *(rw,sync,no_root_squash)
         
         ...rootfs: 可以通过nfs协议访问的主机目录
         
         *, 所有的客户端都可以访问该目录
             192.168.1.*,IP以192.168.1.开头的客户端可以访问该目录
         rw, 客户端对该目录有读写权限
         sync, 同步
         no_root_squash, 用户角色
  5.4 重启nfs server 使得新配置生效
      sudo /etc/init.d/nfs-kernel-server restart
      
      验证方式:
          sudo exportfs//展示可以通过nfs方式访问的目录
         
  5.5 设置bootargs 
      通知linux去网络主机挂载根文件系统
      setenv bootargs root=/dev/nfs 
      nfsroot=192.168.1.8:/home/tarena/porting/rootfs 
      ip=192.168.1.110:192.168.1.8:192.168.1.1:255.255.255.0 
      init=/linuxrc console=ttySAC0 maxcpus=1 
      lcd=wy070ml tp=gslx680-linux loglevel=1
            root=/dev/nfs, 告诉内核挂载网络根文件系统
            nfsroot=IP:目录 告诉内核去哪台主机的哪个目录下去挂载根文件系统
            ip=自身IP:SERVER IP:网关:子网掩码
      saveenv  
      
      实验效果:
          在PC上执行 cp hello_arm /home/tarena/porting/rootfs 
          在串口中 ls
          
   尝试: UC课网络编程的代码 放在板子上运行
         服务器端跑在pc
         客户端程序跑开发板                 

猜你喜欢

转载自blog.csdn.net/qq_30787727/article/details/100053791