博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
fastboot烧写sd卡mbr类型分区
阅读量:3561 次
发布时间:2019-05-20

本文共 11137 字,大约阅读时间需要 37 分钟。

fastboot有快速启动的意思, 但这里指的是安卓系统的线刷模式。

安卓手机刷机一般使用两种模式,  fastboot 线刷,  recovery 卡刷,

通常: 一个使用usb线连接电脑,  另一个使用sd卡。


fastboot相对更底层点, 是启动过程中进入的一种模式。 

uboot最新代码就集成了fastboot模块。故只要使用uboot作为引导程序且支持usb接口(从设备模式)的产品, 一般都能支持fastboot线刷。

查看fastboot相关代码日志, 

git log README.android-fastbootcommit 3aab70afc531d1eea0e6fcfcf49001163ad13137Author: Sebastian Siewior 
Date: Mon May 5 15:08:10 2014 -0500 usb/gadget: add the fastboot gadget This patch contains an implementation of the fastboot protocol on the device side and documentation. This is based on USB download gadget infrastructure. The fastboot function implements the getvar, reboot, download and reboot commands. What is missing is the flash handling i.e. writting the image to media.

翻到最下面, 可以看到大约是2014年5月5日合入的代码。


recovery卡刷相对运行的更高层一点。其实就类似linux电脑的恢复模式, windows电脑的安全模式。

内核是引导起来的, 只不过加载的文件系统是一个recovery分区中的文件系统, 该文件系统通常不去更改, 里面存放一些必要的软件。如busybox, gpart, 网络工具等等。

安卓手机就是利用该recovery模式进行刷机操作, 将sd卡中的数据刷入手机emmc存储介质中。


ok, 这里记录下利用uboot fastboot功能更新相应分区镜像。

1. 这里使用的环境是xilinx zynq-ultrascale开发环境, 使用sd卡做为启动存储介质。即类似树莓派, 并不使用内部emmc作为存储介质。 而使用sdio接口读写外部sd/emmc卡。

2. sd卡分区模式使用传统的mbr模式, 即前512byte为mbr, main boot record主引导记录。(其中前446字节为引导程序, 后面跟着共四个分区表信息, 每个16字节,  共64字节。 最后以0xaa55的结束符2个字节。)

之后跟着2个分区, 一个为fat32分区,存放bootloader, kernel, uboot env, dtb等等文件。灵一个为ext4分区, 就是根文件系统。

具体分区信息如下:

river@river-VirtualBox:~/image$ fdisk sdimage.imgWelcome to fdisk (util-linux 2.31.1).Changes will remain in memory only, until you decide to write them.Be careful before using the write command.Command (m for help): pDisk sdimage.img: 576 MiB, 603979776 bytes, 1179648 sectorsUnits: sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisklabel type: dosDisk identifier: 0x09dcfcefDevice       Boot  Start     End Sectors  Size Id Typesdimage.img1        2048  133120  131073   64M  b W95 FAT32sdimage.img2      133121 1179647 1046527  511M 83 LinuxCommand (m for help):

3. 启动进入uboot shell

查看mmc 信息

ZynqMP> mmc infoDevice: sdhci@ff170000Manufacturer ID: 3OEM: 5344Name: SC16G Tran Speed: 50000000Rd Block Len: 512SD version 3.0High Capacity: YesCapacity: 14.8 GiBBus Width: 4-bitErase Group Size: 512 BytesZynqMP> mmc listsdhci@ff170000: 0 (SD)ZynqMP> mmc partPartition Map for MMC device 0  --   Partition Type: DOSPart	Start Sector	Num Sectors	UUID		Type  1	2048      	131072    	a69ff1bd-01	0b  2	133120    	1048576   	a69ff1bd-02	83ZynqMP>

4. 开发板启动fastboot

ZynqMP> fastbootfastboot - use USB Fastboot protocolUsage:fastboot 
- run as a fastboot usb deviceZynqMP> fastboot usb0

 

5. windows pc端就能发现USB download gadget设备, 是的fastboot对应的usb设备驱动就是download gadget。

windows pc安装fastboot客户端可参考安卓官网攻略, 相对步骤多点。

ubuntu电脑的话apt软件仓库中就有。 sudo apt-get install fastboot即可。

常用命令有

fastboot reboot

fastboot getvar xxx

fastboot erase <partition_name>

fastboot flash <partition_name> <partition_image>

fastboot flashall

下面演示主机端操作

river@river-VirtualBox:~/image$ fastboot devices ????????????	fastbootriver@river-VirtualBox:~/image$ fastboot erase mmcsda1 erasing 'mmcsda1'...OKAY [  0.135s]finished. total time: 0.135sriver@river-VirtualBox:~/image$ river@river-VirtualBox:~/image$ river@river-VirtualBox:~/image$ fastboot flash mmcsda1 boot.imgtarget reported max download size of 100663296 bytessending 'mmcsda1' (65536 KB)...OKAY [  3.308s]writing 'mmcsda1'...OKAY [  4.781s]finished. total time: 8.089sriver@river-VirtualBox:~/image$

开发板相应log

GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645part_get_info_efi: *** ERROR: Invalid GPT ***GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645part_get_info_efi: *** ERROR: Invalid Backup GPT ***Erasing blocks 2048 to 133120 due to alignment........ erased 67108864 bytes from 'mmcsda1'request 000000007dee0400 was not queued to ep1in-bulkWARNING: unknown variable: slot-countrequest 000000007dee0400 was not queued to ep1in-bulkWARNING: unknown variable: slot-suffixesrequest 000000007dee0400 was not queued to ep1in-bulkWARNING: unknown variable: slot-suffixesrequest 000000007dee0400 was not queued to ep1in-bulkWARNING: unknown variable: has-slot:mmcsda1request 000000007dee0400 was not queued to ep1in-bulkWARNING: unknown variable: partition-type:mmcsda1request 000000007dee0400 was not queued to ep1in-bulkrequest 000000007dee0400 was not queued to ep1in-bulkStarting download of 67108864 bytesrequest 000000007dee0400 was not queued to ep1in-bulk................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................request 000000007dee0400 was not queued to ep1in-bulkdownloading of 67108864 bytes finishedGUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645part_get_info_efi: *** ERROR: Invalid GPT ***GUID Partition Table Header signature is wrong: 0x0 != 0x5452415020494645part_get_info_efi: *** ERROR: Invalid Backup GPT ***Flashing Raw Image........ wrote 67108864 bytes to 'mmcsda1'request 000000007dee0400 was not queued to ep1in-bulk

是的, 开发板上挺多警告log, 关于gpt, mbr相关。


6. fastboot 支持gpt分区,  同时也支持mbr分区。

gpt分区: 安卓系统多采用gpt分区形式, 如以下就是其中一个分区例子。

Partition#	Name#	Size#	Strat LBA-End LBR	Description#0	MBR & GPT	 	0x00000000-0x000000FF	Master Boot Record and GUID Partition Table1	x-loader(MLO)	256KB	0x00000100-0x000001FF	First stage bootloader2	bootloader(u-boot.bin)	384KB	0x00000200-0x000005FF	Second stage bootloader3	misc	128KB	0x00000600-0x000006FF	Reserved.This partition can be used for internal purpose4	recovery (zImage + recovery-ramdisk.img)	8MB	0x00000A00-0x000049FF	recovery partition5	boot (boot.img = zImage + ramdisk.img)	8MB	0x00004A00-0x000089FF	Partition contains kernel + ramdisk images.6	system (system.img)	256MB	0x00008A00-0x000889FF	android file system7	cache (cache.img)	32MB	0x00088A00-0x000989FF	Partition will be used to store application cache8	userdata (userdata.img)	32MB	0x00098A00-0x000A89FF	Partition contains userdata supplied by oem vendor like configuration files,utilities etc..9	media	Remaining	0x000A8A00-0x00762761	Partition contains media files; supplied by oem vendor

可以看到第二行, 可采用partition_name进行分区的擦除烧写等操作。

例如

fastboot erase boot

fastboot flash boot boot.img

fastboot flash system.img

 

关于mbr分区表格式,  由于没有partition_name, 该如何进行分区操作呢?  继续参考uboot/doc/README.android.fastboot

Partition Names                                                                                                                                        ===============                                                                                                                                        The Fastboot implementation in U-boot allows to write images into disk                                                                                 partitions (currently on eMMC). Target partitions are referred on the host                                                                             computer by their names.                                                                                                                                                                                                                                                                                      For GPT/EFI the respective partition name is used.                                                                                                                                                                                                                                                            For MBR the partitions are referred by generic names according to the                                                                                  following schema:                                                                                                                                                                                                                                                                                                 
Example: hda3, sdb1, usbda1 The device type is as follows: * IDE, ATAPI and SATA disks: hd * SCSI disks: sd * USB media: usbd * MMC and SD cards: mmcsd * Disk on chip: docd * other: xx The device index starts from 'a' and refers to the interface (e.g. USB controller, SD/MMC controller) or disk index. The partition index starts from 1 and describes the partition number on the particular device.

所以以上操作中使用的命令为

fastboot erase mmcsda1

fastboot flash mmcsda1 boot.img

fastboot flash mmcsda2 rootfs.img


7. 关于boot.img, rootfs.img这些景象该如何制作

sdimage中是多分区的镜像集合。可以将其拆解开。

我这里依然采用制作sdimage的方法,

sudo dd if=/dev/zero of=boot.img bs=1M count=64M

sync

losetup -f boot.img                  // -f 是find第一个可用的loop回环设备

losetup -a                                // 查看所有loop设备, 假设是/dev/loop1

mkfs.vfat /dev/loop1

sudo mount /dev/loop1 /mnt/boot/

然后拷贝相应的boot文件, 如uboot, kernel, dtb等到该目录。

即可


多镜像分区利用fdisk命令即可。

 

后续利用gdisk, parted等工具制作一个gpt分区的sd卡。并尝试运行。(mbr + gpt)

转载地址:http://nscrj.baihongyu.com/

你可能感兴趣的文章
HiKey960/970用户手册;HiKey960 Development Board User Manual
查看>>
【书籍推荐】FPGA,xilinx
查看>>
N9-SQL注入(union注入)
查看>>
N10-sql注入(information_schema注入)
查看>>
N1-Kali虚拟机中SQLmap
查看>>
N11-sql注入(http头注入)
查看>>
N2-sqlmap初使用
查看>>
N12-sql盲注原理以及boolean盲注案例实现
查看>>
N13-sqli盲注 基于时间型
查看>>
N1 技术心得 2019-6-26
查看>>
N1-环境配置
查看>>
N2-审计方法与步骤
查看>>
N3-常见的INI配置
查看>>
代码审计 N4 常见危险函数和特殊函数(一)
查看>>
MySQL笔记
查看>>
计算机运算方法之(原码 补码 反码 移码)
查看>>
计算机组成原理之(二进制与十进制互相转换,数的定点表示与浮点数表示)例题:设浮点数字长16位,其中阶码5位(含有1位阶符),尾数11位(含有1位数符)
查看>>
冒泡排序及其优化
查看>>
选择排序(java代码实现)
查看>>
插入排序
查看>>