轉自:http://blog.csdn.net/geniusmen/article/details/7892398
1.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
2.命令
2.1 升級系統
sudo fastboot flash bootloader u-boot.bin
sudo fastboot flash kernel uImage
sudo fastboot flash system system.img
sudo fastboot flash userdata userdata.img
sudo fastboot flash ramdisk ramdisk-uboot.img
sudo fastboot erase cache
fastboot flash {partition} {*.img} 例:fastboot flash boot boot.img或fastboot flash system system.img等。
fastboot flashall 注意:此命令會在當前目錄中查找所有img文件,將這些img文件燒寫到所有對應的分區中,並重新啓動手機。
一次燒寫boot,system,recovery分區:
(1)創建包含boot.img,system.img,recovery.img文件的zip包。
(2)執行:fastboot update {*.zip}
燒寫開機畫面:
fastboot flash splash1 開機畫面
2.2 重啓系統
sudo fastboot reboot
2.3 不燒寫flash情況下調試
sudo fastboot boot uImage 或者u-boot.bin
2.4 查看版本號
sudo fastboot getver:version
2.5 復位到bootloader
sudo fastboot reboot-bootloader
2.6 命令格式
主機端發送字符串的命令,字符串小於等於64個字節,客戶端首先返回四個字節的內容,是OKAY、FAIL、DATA、INFO之一,隨後跟着是信息或數數據。
2.7 清空分區
fastboot erase {partition} 例:fastboot erase boot或fastboot erase system等。
fastboot erase boot
fastboot erase system
fastboot erase data
fastboot erase cache
上面的命令也可以簡化成一條命令
fastboot erase system -w
2.8 獲取客戶端(手機端)變量信息
fastboot getvar version:version-bootloader:version-baseband:product:serialno:secure
version 客戶端支持的fastboot協議版本
version-bootloader Bootloader的版本號
version-baseband 基帶版本
product 產品名稱
serialno 產品序列號
secure 返回yes 表示在刷機時需要獲取簽名
3.支持的參數
偏移和地址在u-boot中定義,要想使用好fastboot,就必須要知道參數名稱與文件的對應關係。
name | offset | size |
xloader | 0x00000000 | 0x00080000 |
bootloader | 0x00080000 | 0x00180000 |
environment | 0x001C0000 | 0x00040000 |
kernel | 0x00200000 | 0x01D00000 |
system | 0x02000000 | 0x0A000000 |
userdata | 0x0C000000 | 0x02000000 |
cache | 0x0E000000 | 0x02000000 |
name | type of file | usual file |
xloader | xloader binary | MLO |
bootloader | uboot binary | u-boot.bin |
environment | text file | list of variables to set |
kernel | kernel or kernel + ramdisk | uImage, uMulti |
system | yaffs2 | system.img |
userdata | yaffs2 | userdata.img |
cache | yaffs2 | ? |
4.其他功能
4.1環境變量
fastboot支持環境變量文件,通常在fastboot燒寫nand flash時,會將偏移量和大小寫入環境變量中,命名格式爲:
<partition name>_nand_offset
<partition name>_nand_size
例如,內核燒寫完成後printenv可以看到:
kernel_nand_offset=0x140000
kernel_nand_size=0x1f70000
4.2查看USB設備
查看連接到OTG的USB設備情況,lsusb:
Bus 008 Device 030: ID 0451:cafe Texas Instruments, Inc. <----- fastboot
更多細節查看cat /proc/bus/usb/devices
4.3 靜態模塊地址
fastboot重用內核的nand地址分配方式,並且大部分是可以變化的,但是下面列出來的這些地址是不變的。
name offset size
xloader 0x00000000 0x00080000
bootloader 0x00080000 0x00180000
environment 0x001C0000 0x00040000
4.4 文件大小限制
最大下載文件大小爲240M。
5 參考文獻
1. Android Fastboot: http://www.omappedia.org/wiki/Android_Fastboot#Updating_system_image_on_NAND
2. fastboot_protocol.txt
1. 手機進入fastboot模式
先關機,開機時,同時按power鍵+camera或power + Home鍵,進入fastboot,紅色字體
然後將手機和HOST,用USB線連接
2. 查看fastboot用法
$ sudo ./fastboot -h
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
format <partition> format 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
continue continue with autoboot
reboot reboot device normally
reboot-bootloader reboot device into bootloader
help show this help message
options:
-w erase userdata and cache (and format
if supported by partition type)
-u do not first erase partition before
formatting
-s <specific device> specify device serial number
or path to device port
-l with "devices", lists device paths
-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
-S <size>[K|M|G] automatically sparse files greater than
size. 0 to disable
3. 查看進入fastboot模式的設備
$ sudo ./fastboot devices
20080823 fastboot
4. 燒寫image
$ sudo ./fastboot flash partition_name img_file
一般只燒boot.img, system.img和userdata.img三個鏡像
$ sudo ./fastboot flash boot boot.img
sending 'boot' (4700 KB)...
OKAY [ 4.770s]
writing 'boot'...
OKAY [ 1.849s]
finished. total time: 6.642s
$ sudo ./fastboot flash system system.img
sending 'system' (85090 KB)...
OKAY [ 86.732s]
writing 'system'...
OKAY [ 33.991s]
finished. total time: 120.723s
$ sudo ./fastboot flash userdata userdata.img
sending 'userdata' (1456 KB)...
OKAY [ 1.485s]
writing 'userdata'...
OKAY [ 1.350s]
finished. total time: 2.835s