fastboot
概述
fastboot 是一种主要用于 Android 设备的通信协议。它是在同名的命令行工具中实现的,并作为 bootloader 的一种模式。该工具主要用于主机(host PC)通过 USB 通信更新设备 flash 文件系统。它要求设备需要先进入 fastboot 模式。进入 fastboot 模式后,设备可以接收来自主机的命令。
工作原理
- uboot 的 fastboot 的命令将开发板伪装成一个 usb 设备。开发板本身并不是一个 usb 设备,所以开发板直接插到电脑是没有反应的。
- 主机的 fastboot 软件和开发板的 fastboot 程序通信来工作。平时工作时,开发板端只要执行了 fastboot 命令进入 fastboot 模式即可,剩下的就不用管了。主机端通过运行 fastboot 命令,传递不同的参数来实现主机端和开发板端的通信。 譬如主机端执行 fastboot devices,则这个命令通过usb线被传递到开发板中被开发板的 fastboot 程序接收,接收后去处理向主机端发送发聩信息,主机端接收到反馈信息后显示出来。
- uboot 这边的 fastboot 是通过 rx_handler 函数来处理主机端 fastboot 软件发送过来的信息的。
- rx_handler 函数中通过 if 和 else 分成了两部分,if 部分负责处理 download,else 部分负责处理命令。usb 传输单次传输最大只能有限个字节(64、256),因此当发送比较小的东西(比如命令)时可以单词传输完毕;当发送比较大的东西时(比如文件)就必须要分包发送。
- uboot 通过 fastboot_tx_status 函数向主机发送响应,主机显示这个响应。
参数
- devices,列出所有设备
- getvar all,列出设备所有信息
- download,下载
- flash <partition> [ <filename> ],将文件烧录到指定分区
- erase,擦除
- boot,启动内核
- reboot,重启设备
- oem,用户自定义命令
实例
列出设备
liyongjun@box:~$ fastboot devices
sigiriya uboot fastboot
liyongjun@box:~$ fastboot devices -l
sigiriya uboot fastboot usb:1-2
选择 Nor flash 设备(烧录 MCU 使用的 Nor flash)
liyongjun@box:~$ fastboot oem interface:mtd
...
OKAY [ 0.001s]
finished. total time: 0.001s
选择 eMMC 设备(烧录 Acore 使用的 eMMC)
liyongjun@box:~$ fastboot oem interface:blk
...
OKAY [ 0.001s]
finished. total time: 0.002s
烧录 MCU
liyongjun@box:~$ fastboot oem interface:mtd
...
OKAY [ 0.002s]
finished. total time: 0.002s
liyongjun@box:~$ fastboot flash MCU_a MCU_J6M_SIP_Matrix_V1.1.img
target reported max download size of 117440512 bytes
sending 'MCU_a' (1024 KB)...
OKAY [ 0.087s]
writing 'MCU_a'...
OKAY [ 10.022s]
finished. total time: 10.109s
重启
liyongjun@box:~$ fastboot reboot
rebooting...
finished. total time: 0.152s