博客
关于我
Uboot 网络加载并启动Linux - 基于移植好的网络功能
阅读量:569 次
发布时间:2019-03-07

本文共 5039 字,大约阅读时间需要 16 分钟。

前言

根据前面的文章,到现在移植的DM9621网卡已经能正常工作了,接下来便是使用Uboot内置的网络命令集,进行相关的操作,如tftpboot加载内核,加载设备树等。下面将会对移植好的网络功能做个简单介绍,达到最终通过网络来加载并启动Linux的最终目标。

使能DM9621网卡

说明

因为是基于USB网卡的缘故,Uboot默认启动时是没有开启USB功能的,所以没有办法自动初始化网卡,需要手动去使能USB功能,和使能DM9621网卡。

步骤

u-boot # usb startstarting USB...USB0:   USB EHCI 1.00scanning bus 0 for devices... 1 USB Device(s) foundu-boot # usb resetresetting USB...USB0:   USB EHCI 1.00scanning bus 0 for devices...Warning: dm9601_eth using MAC address from ROM3 USB Device(s) foundu-boot # setenv ethaddr 00:d8:1c:04:55:60u-boot # saveenv

Note: 才烧写的Uboot因为环境变量没有ethaddr,出现这个打印Warning: dm9601_eth using MAC address from ROM是正常的。只需要手动设置一下ethaddr环境变量,再saveenv即可,ethaddr需要为一合法的MAC地址,示例如上面所示。

网络命令使用

说明

为了使本文尽量精简,只对使用较频繁的命令做说明,如果大家有其他想了解的,可以在评论区联系博主添加,也可以通过输入? <命令名>查询Uboot内置的使用说明。

ping命令

在上面设置成功后,便可以正常的使用网络了,可以先试用简单的ping命令来验证一下网络是否可用,示例如下所示:

u-boot # ? pingping - send ICMP ECHO_REQUEST to network hostUsage:ping pingAddressu-boot # u-boot # ping 192.168.1.1Waiting for Ethernet connection... done.Using dm9601_eth devicehost 192.168.1.1 is aliveu-boot # ping 192.168.1.141Using dm9601_eth devicehost 192.168.1.141 is aliveu-boot #

tftpboot命令

在验证好与tftp server(博主这里是192.168.1.141)之间的连通性后,便可以通过tftpboot服务加载bin文件到内存中,随后便可以做任何对该内存地址的数据操作,示例如下所示:

u-boot # ? tftpboottftpboot - boot image via network using TFTP protocolUsage:tftpboot [loadAddress] [[hostIPaddr:]bootfilename]u-boot #u-boot # tftpboot 0x40007000 uImage Using dm9601_eth deviceTFTP from server 192.168.1.140; our IP address is 192.168.1.141Filename 'uImage'.Load address: 0x40007000Loading: #################################################################	 #################################################################	 #################################################################	 #################################################################	 #################################################################	 ########################################################	 804.7 KiB/sdoneBytes transferred = 5591536 (5551f0 hex)u-boot # tftpboot 0x41000000 exynos4412-itop-elite.dtb;Using dm9601_eth deviceTFTP from server 192.168.1.140; our IP address is 192.168.1.141Filename 'exynos4412-itop-elite.dtb'.Load address: 0x41000000Loading: ###	 517.6 KiB/sdoneBytes transferred = 42955 (a7cb hex)u-boot # md.l 0x40007000 0x4040007000: 56190527 94632e5c fef5fc5d b0515500    '..V\.c.]....UQ.40007010: 00700040 00700040 6cf908d8 00020205    @.p.@.p....l....40007020: 756e694c 2e342d78 322e3431 0000002b    Linux-4.14.2+...40007030: 00000000 00000000 00000000 00000000    ................u-boot #

Note: tftpboot实际功能是通过tftp协议,将文件加载到参数指定的起始地址,只是我们常用来加载内核、DTB文件到指定的起始地址而已。上面示例最后演示了查看该起始地址起,长度为0x40的内存内容,即uImage的64字节头信息。

网络加载内核

说明

在上面的tftpboot命令示范中,已经将内核文件uImage和dtb文件exynos4412-itop-elite.dtb加载到内存中了,在本节中便不再重复说明。

bootm命令

在加载完uImage和DTB文件后,便可以通过bootm命令启动Linux,示例如下:

u-boot # bootm 0x40007000 - 0x41000000## Booting kernel from Legacy Image at 40007000 ...   Image Name:   Linux-4.14.2+   Image Type:   ARM Linux Kernel Image (uncompressed)   Data Size:    5591472 Bytes = 5.3 MiB   Load Address: 40007000   Entry Point:  40007000   Verifying Checksum ... OK## Flattened Device Tree blob at 41000000   Booting using the fdt blob at 0x41000000   Loading Kernel Image ... OK   Loading Device Tree to 4fff2000, end 4ffff7ca ... OKStarting kernel ...Uncompressing Linux... done, booting the kernel.[    0.000000] Booting Linux on physical CPU 0xa00[    0.000000] Linux version 4.14.2+ (jason@jason-vm) (gcc version 7.4.0 (Ubuntu/Linaro 7.4.0-1ubuntu1~18.04.1)) #11 SMP PREEMPT Sat Dec 21 00:25:13 CST 2019[    0.000000] CPU: ARMv7 Processor [413fc090] revision 0 (ARMv7), cr=10c5387d[    0.000000] CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache[    0.000000] OF: fdt: Machine model: TOPEET iTop 4412 Elite board based on Exynos4412[    0.000000] Memory policy: Data cache writealloc

Note: 可以通过在uboot的shell中输入? bootm查询bootm命令使用方法。

自动加载与引导

说明

每次都这样输入来加载和引导内核相比也是非常的麻烦,Uboot可以通过设置bootcmd环境变量,来达到自动加载和引导内核启动的目的,此处也把bootargs一并设置好,便可直接启动系统,不需要手动输入命令。

bootcmd

u-boot # setenv bootcmd 'usb start; usb reset; tftpboot 0x40007000 uImage; tftpboot 0x41000000 exynos4412-itop-elite.dtb; bootm 0x40007000 - 0x41000000; boot'u-boot # saveenv Saving Environment to MMC...Writing to MMC(0)... doneu-boot #

bootargs

  • EMMC挂载根文件系统模式
u-boot # setenv bootargs root=/dev/mmcblk1p1 rw rootwait rootfstype=ext4 init=/linuxrc console=ttySAC2,115200u-boot # saveenv Saving Environment to MMC...Writing to MMC(0)... doneu-boot #
  • NFS挂载根文件系统模式
u-boot # setenv bootargs root=/dev/nfs rw nfsroot=192.168.1.140:/home/jason/rootfs ip=192.168.1.141:192.168.1.140:192.168.1.1:255.255.255.0:itop:eth0:off rootfstype=ext4 init=/linuxrc console=ttySAC2,115200u-boot # saveenv                                                                                                                                                                                              Saving Environment to MMC...Writing to MMC(0)... doneu-boot #

结语

走到这里,开发板已经能够正常进入Linux最小系统,能够进行各种shell操作啦!下面便可以开始Linux相关的知识学习啦,加油吧,少年!

转载地址:http://kvdjz.baihongyu.com/

你可能感兴趣的文章
MySQL - 解读MySQL事务与锁机制
查看>>
MTTR、MTBF、MTTF的大白话理解
查看>>
mt_rand
查看>>
mysql -存储过程
查看>>
mysql /*! 50100 ... */ 条件编译
查看>>
mysql 1045解决方法
查看>>
mudbox卸载/完美解决安装失败/如何彻底卸载清除干净mudbox各种残留注册表和文件的方法...
查看>>
mysql 1264_关于mysql 出现 1264 Out of range value for column 错误的解决办法
查看>>
mysql 1593_Linux高可用(HA)之MySQL主从复制中出现1593错误码的低级错误
查看>>
mysql 5.6 修改端口_mysql5.6.24怎么修改端口号
查看>>
mui折叠面板点击事件跳转
查看>>
MySQL 8 公用表表达式(CTE)—— WITH关键字深入用法
查看>>
mysql 8 远程方位_mysql 8 远程连接注意事项
查看>>
MUI框架里的ajax的三种方法
查看>>
MySQL 8.0 恢复孤立文件每表ibd文件
查看>>
Mysql 8.0 新特性
查看>>
MultCloud – 支持数据互传的网盘管理
查看>>
MySQL 8.0.23中复制架构从节点自动故障转移
查看>>
MySQL 8.0开始Group by不再排序
查看>>
mysql ansi nulls_SET ANSI_NULLS ON SET QUOTED_IDENTIFIER ON 什么意思
查看>>