数码之家

 找回密码
 立即注册
搜索
查看: 1521|回复: 1

转载:OpenWrt通过NFS方式启动

[复制链接]
发表于 2022-8-5 13:16:53 | 显示全部楼层 |阅读模式

爱科技、爱创意、爱折腾、爱极致,我们都是技术控

您需要 登录 才可以下载或查看,没有账号?立即注册

x
OpenWrt通过NFS方式启动一、什么是NFS

Net File System。
举个例子,开发板与电脑通过网线连接,电脑的某个目录下有开发板系统所需要的文件系统,开发板直接通过网络,加载文件系统运行。
在嵌入式开发中,有很多场景会应用到这种方法,比如ROM不足,或在调试阶段直接烧写FLASH会有风险等等。

二、OpenWrt 分区

直接make V=99出来的bin可以分成3段
1. uboot :OpenWrt采用的bootloader
2. kernel :Linux Kernel,xxx-uImage.bin
3. root file system:xxx-rootfs.tar.gz
以上想生成,直接在make menuconfig中,Target Images和Boot Loaders选项下选择。

三、NFS支持

NFS加载rootfs时,OpenWrt开发板作为NFS Client端,因此make kernel_menuconfig中,将
NFS client相关项全部选择。

File systems  [color=rgb(136, 0, 0) !important]--->    Network File Systems  [color=rgb(136, 0, 0) !important]--->        <*>   NFS client support         
  •    Root file [color=rgb(0, 0, 136) !important]system on NFS
    • 1
    • 2
    • 3
    • 4

    然后编译。

    四、OpenWrt 启动a、uboot

    如果入手的是一个空flash,没办法,只能通过烧写器,或jtag线烧写。
    如果flash中已经有uboot或其他bootloader,可以根据需要,是否升级到自己编译出的uboot。

    b、kernel
    • tftp server搭建(此部分内容,度娘上有很多)
      以ubuntu为例,
      1)安装服务
      $ apt-get install xinetd tftp tftpd
      2)创建/etc/xinetd.d/tftp文件,拷贝下面内容到文件中。

      service tftp{[color=rgb(0, 153, 0) !important]socket_type = dgram[color=rgb(0, 153, 0) !important]protocol = udp[color=rgb(0, 153, 0) !important]wait = yes[color=rgb(0, 153, 0) !important]user = root[color=rgb(0, 153, 0) !important]server = /usr/sbin/in.tftpd[color=rgb(0, 153, 0) !important]server_args = -s /tftpboot[color=rgb(0, 153, 0) !important]disable = no[color=rgb(0, 153, 0) !important]per_source = 11[color=rgb(0, 153, 0) !important]cps = 100 2[color=rgb(0, 153, 0) !important]flags = IPv4}
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
      • 12
      • 13

      3)创建/tftpboot目录,这是配置文件中指定的tftp服务器主目录。
      4)重启xinetd服务器:
      $ /etc/init.d/xinetd restart
      5)将XXX-uImage.bin拷贝到/tftpboot
      6)更改权限
      $ chmod 777 -Rf /tftpboot

    • console连接
      1)安装工具minicom
      $ apt-get install minicom
      2)将TTL-USB线插在开发板console接口上,一般3跳线,Tx Rx GND,Tx线接开发板的Rx,Rx接开发板Tx。
      3)终端运行minicom,进行端口设置,一般为:

      +-----------------------------------------------------------------------+                               [color=rgb(0, 153, 0) !important]| A -    Serial Device      : /dev/ttyUSB0     (这个可以ls /dev/ttyUSB*)|                               [color=rgb(0, 153, 0) !important]| B - Lockfile Location     : /var/lock                                 |                               [color=rgb(0, 153, 0) !important]| C -   Callin Program      :                                           |                               [color=rgb(0, 153, 0) !important]| D -  Callout Program      :                                           |                               [color=rgb(0, 153, 0) !important]| E -    Bps/Par/Bits       : 115200 8N1         (波特率一般为115200)   |                                 [color=rgb(0, 153, 0) !important]| F - Hardware Flow Control : No                             (设置为No)|                               [color=rgb(0, 153, 0) !important]| G - Software Flow Control : No                             (设置为No)|                               [color=rgb(0, 153, 0) !important]|                                                                       |                               [color=rgb(0, 153, 0) !important]|    Change which setting?                                              |                               +-----------------------------------------------------------------------+                              
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8
      • 9
      • 10
      • 11
    • 加载kernel到RAM
      1)网线连接Ubuntu调试机和开发板;
      2)设置调试机IP,ubunut直接在网络里设置(以192.168.0.10为例);
      3)uboot启动后,会通过console出log,出现下面提示时,停止auto boot;
      Hit any key to stop autoboot: 2
      4)通过uboot命令setenv设置开发板IP和对端调试机IP;
      > setenv ipaddr 192.168.0.99
      > setenv serverip 192.168.0.10
      5)通过tftp加载kernel到RAM中(以加载到RAM起始地址0x81000000为例);
      > tftp 0x81000000 XXX-uImage.bin
      6)启动kernel
      > bootm

      > bootm 0x81000000

      原理:

      • uboot集成简单tftp网络支持,当然开发板上要有网络接口。
      • OpenWrt启动kernel时,也是从FLASH上将kernel加载到RAM中运行,所以当前的办法直接通过tftp加载kernel到RAM中,替代了从FLASH上read的过程。

    c、rootfs
    • 按照 2、kernel 小节,搭建tftp和minicom
    • 解压缩xxx-rootfs.tar.gz到/tftpboot/
    • 在uboot命令行,设置启动参数。
      这里只举一个例子,每个开发板的情况不同
      setenv bootargs board=AP143 console=ttyS0,115200 nfsroot=192.168.0.10:/tftpboot/rootfs rw ip=192.168.0.99:192.168.0.10:196.168.0.1:255.255.255.0::eth1:off
      解释:
      • board=AP143,板子类型最好设对,不然kernel可能启动失败;
      • nfsroot=192.168.0.10:/tftpboot/rootfs,就是tftp server ip: + rootfs路径,解压xxx-rootfs.tar.gz出来的;
      • rw设置可读可写权限;
      • ip=板子IP: tftp server ip :网关ip(都在同一网段,网关ip随意填写):掩码:板子eth接口;(这里使用的是静态IP,如果想设置成dhcp,需要在make kernel_menuconfig中,在Networking support里,打开IP: kernel level autoconfiguration的dhcp支持)

    完成以上步骤,可以加载了。

    五、问题

    在启动过程中,发现挂载成功了后,发现nfs server断开的情况,文件系统找不到了!
    其实,这跟OpenWrt自身,启动过程中,需要对eth接口再配置导致的。
    所以。OpenWrt开发过程中,需要频繁对网络进行设置,也导致NFS方式启动OpenWrt的意义不大,只在开始时,确认kernel以及rootfs加载没有问题有用。加载没有问题,最终还是需要烧写到flash中进行调试。


  • 发表于 2022-8-6 10:40:30 | 显示全部楼层
    这个太专业了,认真看看
    回复 支持 反对

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    APP|手机版|小黑屋|关于我们|联系我们|法律条款|技术知识分享平台

    闽公网安备35020502000485号

    闽ICP备2021002735号-2

    GMT+8, 2024-3-29 23:00 , Processed in 0.124800 second(s), 12 queries , Redis On.

    Powered by Discuz!

    © 2006-2023 smzj.net

    快速回复 返回顶部 返回列表