树莓派进阶之路 (042) - 树莓派启动 -- usb启动系统


如果需要从usb启动,需要向树莓派的SOC里的OTP(One Time Programmable一次性编程器)设置修复位,使之支持usb boot mode模式。该过程是不可逆的。

方法一

  1. 连接树莓派,执行命令:
echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt

这行代码将program_usb_boot_mode=1插入到/boot/cinfig.txt文件的末尾。

  1. 检查设置是否成功,输入命令:
vcgencmd otp_dump | grep 17

如果输出的结果和下图一直,说明设置成功

在这里插入图片描述

方法二

在sd卡boot盘的cmdline.txt文件中追加一行命令:

program_usb_boot_mode=1

然后插入树莓派,通电60s,便设置成功了。以后就可以不使用sd卡,直接把镜像写到u盘中。

https://gitee.com/jikexianfeng/documentation/blob/master/hardware/raspberrypi/bootmodes/msd.md
https://www.raspberrypi.org/blog/pi-3-booting-part-i-usb-mass-storage-boot/

USB mass storage boot:

 1 # USB mass storage boot
 2 
 3 **Available on Raspberry Pi 2B v1.2, 3A+, 3B, 3B+, and 4B only.**
 4 
 5 This page explains how to boot your Raspberry Pi from a USB mass storage device such as a flash drive or a USB hard disk. When attaching USB devices, particularly hard disks and SSDs, be mindful of their power requirements. If you wish to attach more than one SSD or hard disk to the Pi, this normally requires external power - either a powered hard disk enclosure, or a powered USB hub. Note that models prior to the Pi 4 have known issues which prevent booting with some USB devices.
 6 
 7 See the [bootmodes documentation](README.md) for the boot sequence and alternative boot modes (network, USB device, GPIO or SD boot).
 8 
 9 Note that 'USB mass storage boot' is different from 'USB device boot mode'. [USB device boot mode](device.md) allows a Raspberry Pi connected to a computer to boot as a USB device, using files from that computer.
10 
11 If you are unable to use a particular USB device to boot your Raspberry Pi, an alternative is to use the special bootcode.bin-only boot mode as described [here](README.md). This Pi will still boot from the SD card, but `bootcode.bin` is the only file read from it.
12 
13 ## Raspberry Pi 2B v1.2, 3A+, 3B, Compute Module 3
14 
15 On the Raspberry Pi 2B v1.2, 3A+, 3B, and Compute Module 3 you must first enable [USB host boot mode](host.md). This is to allow USB mass storage boot, and [network boot](net.md). Note that network boot is not supported on the Raspberry Pi 3A+.
16 
17 To enable USB host boot mode, the Raspberry Pi needs to be booted from an SD card with a special option to set the USB host boot mode bit in the one-time programmable (OTP) memory. Once this bit has been set, the SD card is no longer required. **Note that any change you make to the OTP is permanent and cannot be undone.**
18 
19 **On the Raspberry Pi 3A+, setting the OTP bit to enable USB host boot mode will permanently prevent that Pi from booting in USB device mode.**
20 
21 You can use any SD card running Raspberry Pi OS to program the OTP bit.
22 
23 Enable USB host boot mode with this code:
24 
25 ```bash
26 echo program_usb_boot_mode=1 | sudo tee -a /boot/config.txt
27 ```
28 
29 This adds `program_usb_boot_mode=1` to the end of `/boot/config.txt`.
30 
31 Note that although the option is named `program_usb_boot_mode`, it only enables USB *host* boot mode. USB *device* boot mode is only available on certain models of Raspberry Pi - see [USB device boot mode](device.md).
32 
33 The next step is to reboot the Raspberry Pi with `sudo reboot` and check that the OTP has been programmed with:
34 
35 ```bash
36 $ vcgencmd otp_dump | grep 17:
37 17:3020000a
38 ```
39 
40 Check that the output `0x3020000a` is shown. If it is not, then the OTP bit has not been successfully programmed. In this case, go through the programming procedure again. If the bit is still not set, this may indicate a fault in the Pi hardware itself.
41 
42 If you wish, you can remove the `program_usb_boot_mode` line from `config.txt`, so that if you put the SD card into another Raspberry Pi, it won't program USB host boot mode. Make sure there is no blank line at the end of `config.txt`.
43 
44 You can now boot from a USB mass storage device in the same way as booting from an SD card - see the following section for further information.
45 
46 ## Raspberry Pi 3B+, Compute Module 3+
47 
48 The Raspberry Pi 3B+ and Compute Module 3+ support USB mass storage boot out of the box. The steps specific to previous versions of Raspberry Pi do not have to be executed.
49 
50 The [procedure](../../../installation/installing-images) is the same as for SD cards - simply image the USB storage device with the operating system image.
51 
52 After preparing the storage device, connect the drive to the Raspberry Pi and power up the Pi, being aware of the extra USB power requirements of the external drive.
53 After five to ten seconds, the Raspberry Pi should begin booting and show the rainbow splash screen on an attached display. Make sure that you do not have an SD card inserted in the Pi, since if you do, it will boot from that first.
54 
55 ## Known issues (not Pi 4)
56 
57 - The default timeout for checking bootable USB devices is 2 seconds. Some flash drives and hard disks power up too slowly. It is possible to extend this timeout to five seconds (add a new file `timeout` to the SD card), but note that some devices take even longer to respond.
58 - Some flash drives have a very specific protocol requirement that is not handled by the bootcode and may thus be incompatible.
59 
60 "pi4">
61 ## Raspberry Pi 4
62 
63 The Raspberry Pi 4 currently requires non-default firmware to enable USB mass storage boot: see the [USB mass storage boot](../bcm2711_bootloader_config.md#usbmassstorageboot) section of the Pi 4 Bootloader Configuration page for more information.

相关