fastboot 教程
1.参考
http://blog.csdn.net/geniusmen/article/details/7892398
http://www.cnblogs.com/eastnapoleon/p/3270857.html
http://www.omappedia.org/wiki/Android_Fastboot#Updating_system_image_on_NAND
2.fastboot简介
fastboot是Android快速升级的一种方法,fastboot的协议fastboot_protocol.txt在源码目录./bootable/bootloader/legacy下可以找到。
fastboot客户端是作为Android系统编译的一部分,编译后位于./out/host/Linux-x86/bin/fastboot目录下。
fastboot命令实例:sudo fastboot flash kernel path-to-kernel/uImage
烧写rootfs类似:sudo fastboot flash system path-to-system/system.img
3.Android手机分区
每个分区都可以被烧写,并有相应的img文件对应:
- 开机启动画面区(splash1)
- 数据恢复区(recovery)
- 内核区(boot)
- 系统区(system)
- 数据缓存区(cache)
- 用户数据区(userdata)
4.fastboot命令
4.1 查看fastboot命令的帮助
输入fastboot,显示如下信息:
usage: fastboot [ <option> ] <command> commands: update <filename> reflash device from update.zip flashall flash boot + recovery + system flash <partition> [ <filename> ] write a file to a flash partition erase <partition> erase a flash partition getvar <variable> display a bootloader variable boot <kernel> [ <ramdisk> ] download and boot kernel flash:raw boot <kernel> [ <ramdisk> ] create bootimage and flash it devices list all connected devices reboot reboot device normally reboot-bootloader reboot device into bootloader options: -w erase userdata and cache -s <serial number> specify device serial number -p <product> specify product name -c <cmdline> override kernel commandline -i <vendor id> specify a custom USB vendor id -b <base_addr> specify a custom kernel base address -n <page size> specify the nand page size. default: 2048
4.2 擦除分区:fastboot erase <partition>
$ sudo fastboot erase boot xx/boot.img
$ sudo fastboot erase system xx/system.img
$ sudo fastboot erase userdata xx/userdata.img
$ sudo fastboot erase cache xx/cache.img
4.3 烧写指定分区:fastboot flash <partition> [*.img]
$ sudo fastboot flash boot path-to-kernel/boot.img
$ sudo fastboot flash zimage path-to-kernel/arch/arm/boot/zImage
$ sudo fastboot flash system path-to-system/system.img
$ sudo fastboot flash splash1 开机画面
4.4 烧写所有分区:fastboot flashall
注意:此命令会在当前目录中查找所有img文件,将这些img文件烧写到所有对应的分区中,并重新启动手机。
$ sudo fastboot flashall
4.5 一次烧写boot,system,recovery分区:fastboot update <*.zip>
创建包含boot.img,system.img,recovery.img文件的update.zip。
$ sudo fastboot update update.zip
4.6 重启手机
$ sudo fastboot reboot
4.7 以指定的img或bin 启动系统,通常用于调试
In addition to flashing the eMMC, Fastboot can also be used to boot from files already flashed to the eMMC. To do, so start Fastboot on the target, and then run a command on the host PC, for example to boot the u-boot:
$ sudo fastboot boot u-boot.bin
4.8 更新eMMC分区
Regions in eMMC are given names. Their offsets and sizes are set in u-boot in the mmc.c file of the board directory that you are using. For example, for the Blaze, this file is u-boot/board/omap4430sdp/mmc.c:
static struct partition partitions[] = { { "-", 128 }, { "xloader", 128 }, { "bootloader", 256 }, /* "misc" partition is required for recovery */ { "misc", 128 }, { "-", 384 }, { "efs", 16384 }, { "recovery", 8*1024 }, { "boot", 8*1024 }, { "system", 512*1024 }, { "cache", 256*1024 }, { "userdata", 0}, { 0, 0 }, };
修改上面的内容,然后执行:
$ sudo fastboot oem format
4.9 退出fastboot
- 拔usb
- ctrl+c
- 超时退出命令
# fastboot 100 或 # fastboot
4.10 获取客户端(手机端)变量信息
$sudo fastboot getvar version:version-bootloader:version-baseband:product:serialno:secure
getvar后和参数用:分开,它们的含义如下:
version | 客户端支持的fastboot协议版本 |
version-bootloader | Bootloader的版本号 |
version-baseband | 基带版本 |
product | 产品名称 |
serialno | 产品序列号 |
secure | 返回yes 表示在刷机时需要获取签名 |
4.11 如何查看fastboot是否成功
fastboot支持环境变量文件,通常在fastboot烧写nand flash时,会将偏移量和大小写入环境变量中,命名格式为:
- <partition name>_nand_offset
- <partition name>_nand_size
例如,内核烧写完成后printenv可以看到:
- kernel_nand_offset=0x140000
- kernel_nand_size=0x1f70000
4.12 u-boot中定义定义的偏移和地址
name | offset | size | type of file | usual file |
xloader | 0x00000000 | 0x00080000 | xloader binary | MLO |
bootloader | 0x00080000 | 0x00180000 | uboot binary | u-boot.bin |
environment | 0x001C0000 | 0x00040000 | text file | list of variables to set |
kernel | 0x00200000 | 0x01D00000 | kernel or kernel + ramdisk | uImage, uMulti |
system | 0x02000000 | 0x0A000000 | yaffs2 | system.img |
userdata | 0x0C000000 | 0x02000000 | yaffs2 | userdata.img |
cache | 0x0E000000 | 0x02000000 | yaffs2 | ? |
fastboot重用内核的nand地址分配方式,并且大部分是可以变化的,但是xloader、bootloader 、environment地址是不变的。
4.13 文件大小限制
最大下载文件大小为240M。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?