Home uboot - tftpboot
Post
Cancel

uboot - tftpboot

uboot的 tftp 功能,通过网络下载文件到ddr中,可以下载内核Image,iniitramfs等。

使用的网络文件传输协议为 tftp (udp , 21 port , default) 。

uboot环境配置

  1. 需要编译网卡对应的驱动,在Device Drivers -> Network device support 中配置相应的网卡驱动。
  2. 需要开启tftpboot功能,关键字TFTPBOOT,将相关需要的配置开启,编译到uboot中。

开发板设置

网络协议,需要IP地址,设置开发板的网卡的IP。

可以使dhcp功能自动申请(dhcp命令一般默认开启),也可以手动设置静态IP。

手动设置静态IP

执行 setenv ipaddr 192.168.2.94 ,这样将板子uboot设置为对应的 .2.94 ip地址。 可以ping一下主机,确保网络可达。

1
2
3
4
5
ZynqMP> setenv ipaddr 192.168.2.94    # 将IP 设为指定的,默认是dhcp的

ZynqMP> ping 192.168.2.220
Using ethernet@ff0d0000 device
host 192.168.2.220 is alive

网络畅通,即可从主机下载 内核镜像 或其他文件 。

使用DHCP

使用dhcp 命令直接下载文件即可。需要局域网中有dhcp服务器,一般的路由器都具备。

1
2
3
4
dhcp - boot image via network using DHCP/TFTP protocol

Usage:
dhcp [loadAddress] [[hostIPaddr:]bootfilename]

这个dhcp命令功能是dhcp 并下载,即dhcp+tftpboot,本质是一个下载,并没有启动。

可以修改uboot的 默认执行命令bootcmd=run distro_bootcmd,实现自动到指定目标下载kernel和initramfs 并启动,这个需要对uboot修改环境

主机设置

host需要设置 tftp server,并配置共享目录。这个和sftp server不同,使用udp的,而且是21端口

安装

1
$ sudo install apt-get install xinetd tftpd tftp

tftp 是依赖xinetd运行的,其使用端口未知,可能是复用的xinetd的端口

配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 配置tftp server on host
sudo vim /etc/xinetd.d/tftp 

# write in 
service tftp
{
        socket_type     = dgram
        protocol        = udp
        wait            = yes
        user            = root
        server          = /usr/sbin/in.tftpd
        server_args     = -s /var/tftpboot/
        disable         = no
        per_source      = 11
        cps             = 100 2
        flags           = IPv4
}


# 重启tftp server
systemctl restart xinetd

可以使用本地的tftp 客户端测试,server_args为共享出的目录。

补充:tftp中似乎没有目录的概念?都是直接填的文件名?

下载启动

uboot中设置

1
2
3
4
5
6
7
8
ZynqMP> setenv ipaddr 192.168.2.87    # 板卡 ip地址
ZynqMP> ping 192.168.2.220
Using ethernet@ff0d0000 device
host 192.168.2.220 is alive
ZynqMP> tftpboot 0x10000000 192.168.2.220:image.ub   # 下载文件到0x10000000,主机上先将对应文件拷贝至共享目录
ZynqMP> bootm 0x10000000
## Loading kernel from FIT Image at 10000000 ...
.....

这里zynqmp使用的是fit image 格式,配合 bootm [addr] 指令启动。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
ZynqMP> bootm 0x10000000
## Loading kernel from FIT Image at 10000000 ...
   Using 'conf@system-top.dtb' configuration
   Trying 'kernel@1' kernel subimage
     Description:  Linux kernel
     Type:         Kernel Image
     Compression:  gzip compressed
     Data Start:   0x100000f8
     Data Size:    8453515 Bytes = 8.1 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: 0x00080000
     Entry Point:  0x00080000
     Hash algo:    sha256
     Hash value:   a297f131168c49478b168b2763afc0ab6bcdbd5a21602c47440634eb91e03791
   Verifying Hash Integrity ... sha256+ OK
## Loading ramdisk from FIT Image at 10000000 ...
   Using 'conf@system-top.dtb' configuration
   Trying 'ramdisk@1' ramdisk subimage
     Description:  petalinux-image-minimal
     Type:         RAMDisk Image
     Compression:  uncompressed
     Data Start:   0x1081930c
     Data Size:    8716895 Bytes = 8.3 MiB
     Architecture: AArch64
     OS:           Linux
     Load Address: unavailable
     Entry Point:  unavailable
     Hash algo:    sha256
     Hash value:   5059262589ebde7f1341104e991cf6901a74b95f124c1fa204398fba71f51a7e
   Verifying Hash Integrity ... sha256+ OK
## Loading fdt from FIT Image at 10000000 ...
   Using 'conf@system-top.dtb' configuration
   Trying 'fdt@system-top.dtb' fdt subimage
     Description:  Flattened Device Tree blob
     Type:         Flat Device Tree
     Compression:  uncompressed
     Data Start:   0x1080ff94
     Data Size:    37542 Bytes = 36.7 KiB
     Architecture: AArch64
     Hash algo:    sha256
     Hash value:   7a120a0d9c43932a8f52a69d704c5593086c982ae4ca7dc41393743b9fe56892
   Verifying Hash Integrity ... sha256+ OK
   Booting using the fdt blob at 0x1080ff94
   Uncompressing Kernel Image
   Loading Ramdisk to 787af000, end 78fff25f ... OK
   Loading Device Tree to 000000000fff3000, end 000000000ffff2a5 ... OK

Starting kernel ...
.....

如果使用一般的 kernel ,使用 kernel+initramfs+dtb 的形式,配合使用 booti 命令。

1
2
3
4
5
6
ZynqMP> help booti       
booti - boot Linux kernel 'Image' format from memory

Usage:
booti [addr [initrd[:size]] [fdt]]

NFS

tftpboot使用tftp协议下载,uboot也支持NFS协议。 可以使用nfs命令,用法相似。

This post is licensed under CC BY 4.0 by the author.