Uboot 网络加载并启动Linux

您所在的位置:网站首页 linux系统怎么启用网口功能 Uboot 网络加载并启动Linux

Uboot 网络加载并启动Linux

2024-03-14 03:51| 来源: 网络整理| 查看: 265

前言

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

使能DM9621网卡 说明

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

步骤 u-boot # usb start starting USB... USB0: USB EHCI 1.00 scanning bus 0 for devices... 1 USB Device(s) found u-boot # usb reset resetting USB... USB0: USB EHCI 1.00 scanning bus 0 for devices... Warning: dm9601_eth using MAC address from ROM 3 USB Device(s) found u-boot # setenv ethaddr 00:d8:1c:04:55:60 u-boot # saveenv

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

网络命令使用 说明

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

ping命令

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

u-boot # ? ping ping - send ICMP ECHO_REQUEST to network host Usage: ping pingAddress u-boot # u-boot # ping 192.168.1.1 Waiting for Ethernet connection... done. Using dm9601_eth device host 192.168.1.1 is alive u-boot # ping 192.168.1.141 Using dm9601_eth device host 192.168.1.141 is alive u-boot # tftpboot命令

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

u-boot # ? tftpboot tftpboot - boot image via network using TFTP protocol Usage: tftpboot [loadAddress] [[hostIPaddr:]bootfilename] u-boot # u-boot # tftpboot 0x40007000 uImage Using dm9601_eth device TFTP from server 192.168.1.140; our IP address is 192.168.1.141 Filename 'uImage'. Load address: 0x40007000 Loading: ################################################################# ################################################################# ################################################################# ################################################################# ################################################################# ######################################################## 804.7 KiB/s done Bytes transferred = 5591536 (5551f0 hex) u-boot # tftpboot 0x41000000 exynos4412-itop-elite.dtb; Using dm9601_eth device TFTP from server 192.168.1.140; our IP address is 192.168.1.141 Filename 'exynos4412-itop-elite.dtb'. Load address: 0x41000000 Loading: ### 517.6 KiB/s done Bytes transferred = 42955 (a7cb hex) u-boot # md.l 0x40007000 0x40 40007000: 56190527 94632e5c fef5fc5d b0515500 '..V\.c.]....UQ. 40007010: 00700040 00700040 6cf908d8 00020205 @[email protected].... 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 ... OK Starting 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)... done u-boot # bootargs EMMC挂载根文件系统模式 u-boot # setenv bootargs root=/dev/mmcblk1p1 rw rootwait rootfstype=ext4 init=/linuxrc console=ttySAC2,115200 u-boot # saveenv Saving Environment to MMC... Writing to MMC(0)... done u-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,115200 u-boot # saveenv Saving Environment to MMC... Writing to MMC(0)... done u-boot # 结语

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



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3