ILD

Raspberry Pi 3 Ethernet booting
作者:Herbert Yuan 邮箱:yuanjp@hust.edu.cn
发布时间:2018-6-9 站点:Inside Linux Development

1 修改启动模式

使用官方固件,往config.txt添加一行:

1
program_usb_boot_mode=1


重启,查看OTP是否被修改:

1
2
$ vcgencmd otp_dump | grep 17:
17:3020000a


2 使用带debug的bootcode.bin

使用1中的方法,设置OTP后,不需要SD卡,即可支持network boot。但是启动时间较慢,而且无法调试。参考资料3,下载带调试版本的bootcode.bin,将其放在sd卡的boot分区,同时boot分区添加一个空的UART文件。其它文件全部删除。bootcode.bin发现boot分区没有start.elf等文件,就尝试USB和网络启动,log如下:

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
Raspberry Pi Bootcode
 
Found SD card, config.txt = 0, start.elf = 0, recovery.elf = 0, timeout = 0
Trying USB
Hub device found at addr 4, enumerating HUB
Initialise hub
Found 5 ports, multi_tt = 1
Setting interface 0
Enabling PORT POWER on port 1
Enabling PORT POWER on port 2
Enabling PORT POWER on port 3
Enabling PORT POWER on port 4
Enabling PORT POWER on port 5
Waiting for devices to respond to reset
Found device on port 1
Found highspeed device
Device found: type = Ethernet adapter, addr = 5
Trying booting from Ethernet device addr 5
Initialise ethernet with MAC b8:27:eb:fd:0d:e8
Wait for Link up
Link up
Sending DHCP request
Waiting for dhcp_reply
Done ARP for 20.3.168.192 got 74:d4:35:19:8f:9c
Read File: config.txt, 1605 (bytes)
 
 
 
 
Raspberry Pi Bootcode
Read File: config.txt, 1605
Read File: start.elf, 2823204 (bytes)


3 搭建DHCP & TFTP服务器

PI会发出DHCP请求,DHCP请求中待PXE参数,通过官方的dnsmasq教程,抓包分析。我写了一个DHCP & TFTP二合一服务器。代码:https://github.com/yuanjianpeng/rpi_netbootd

使用方法:

1
sudo /work/proj/pinetbootd/pinetbootd eno1 -c 192.168.3.21 -C /work/pi/tftpboot/

第一个参数eno1是PC接口的名称。-c选项是分配给树莓派的IP,如果你的环境中有DHCP服务器(如有开启DHCP服务器的路由器)则可省略此选项。-C选项是存放tftp文件的目录,有下面这些文件:

1
2
$ ls /work/pi/tftpboot/
bcm2710-rpi-3-b.dtb  bootcode.bin  cmdline.txt  config.txt  kernel8.img  start.elf


4 搭建NFS服务器

安装:

1
sudo apt install nfs-kernel-server


配置:

1
2
cat /etc/exports 
/work/pi/pi3_dev/output/fs.root *(rw,sync,no_root_squash,no_subtree_check,insecure)


修改cmdline.txt,添加相关选项:

1
2
3
4
5
root=/dev/nfs 
nfsroot=192.168.3.20:/work/pi/pi3_dev/output/fs.root,nfsvers=3 
nfsrootdebug 
rw
ip=192.168.3.21:::255.255.255.0::eth0

rw表示挂载为可读写。ip=dhcp,如果想使用dhcp分配IP。


参考资料

【1】INETWORK BOOT YOUR RASPBERRY PI.

https://www.raspberrypi.org/documentation/hardware/raspberrypi/bootmodes/net_tutorial.md

【2】boot modes. https://github.com/raspberrypi/documentation/tree/master/hardware/raspberrypi/bootmodes

【3】debug bootcode.bin. https://github.com/raspberrypi/firmware/wiki/USB-MSD-and-network-boot-debugging


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.