- int do_fastboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
- {//设置u-boot,kernel,ramdisk ,system,userdata,cache空间地址
- if (set_partition_table())
- ----------------------------------------> // set_partition_table
- //主要设置bootloader ramdisk kernel 和fdisk所分的区的起始地址和大小,保存在ptable里面。
- /* Bootloader */
- strcpy(ptable[pcount].name, "bootloader");
- ptable[pcount].start = 0;
- ptable[pcount].length = 0;
- ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MOVI_CMD;
- pcount++;
- /* Kernel */
- strcpy(ptable[pcount].name, "kernel");
- ptable[pcount].start = 0;
- ptable[pcount].length = 0;
- ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MOVI_CMD;
- pcount++;
- /* Ramdisk 3M */
- strcpy(ptable[pcount].name, "ramdisk");
- ptable[pcount].start = 0;
- ptable[pcount].length = 0x300000; //3MB,初始值,如果文件大于3M,则会使用文件大小
- //写ramdisk的命令类型标志,这里用movi命令来写
- ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MOVI_CMD;
- pcount++;
- -----------------------
- /* System */
- get_mmc_part_info("0", 2, &start, &count, &pid);
- -------------------------
- if (pid != 0x83)
- goto part_type_error;
- strcpy(ptable[pcount].name, "system");
- /*
- decode_partitionInfo(&mbr[0x1CE], &partInfo);
- *block_start = partInfo.block_start;
- *block_count = partInfo.block_count;
- *part_Id = partInfo.partitionId;
- */ //system 开始的地址
- ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- //大小,256M
- ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- //写system数据类型的标志,这里用MMC命令来写
- ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;
- pcount++;
- /* Data 350M*/
- get_mmc_part_info("0", 3, &start, &count, &pid);
- if (pid != 0x83)
- goto part_type_error;
- strcpy(ptable[pcount].name, "userdata");
- ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;
- pcount++;
- /* Cache 100 M */
- get_mmc_part_info("0", 4, &start, &count, &pid);
- if (pid != 0x83)
- goto part_type_error;
- strcpy(ptable[pcount].name, "cache");
- ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;
- pcount++;
- /* fat 剩余空间分区,剩余空间分区格式fat?标志为 0c*/
- get_mmc_part_info("0", 1, &start, &count, &pid);
- if (pid != 0xc)
- goto part_type_error;
- strcpy(ptable[pcount].name, "fat");
- ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;
- ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;
- pcount++;
- -------------->
- <PRE class=cpp name="code">---------------------------->
- //获取fdisk 对system userdata cache分区的大小
- int get_mmc_part_info(char *device_name, int part_num, int *block_start, int *block_count, unsigned char *part_Id)
- {
- int rv;
- PartitionInfo partInfo;
- unsigned char mbr[512];
- //从设备0中读取MBR主分区目录,里面定义了各个分区的信息,和起始,结束扇区
- rv = get_mmc_mbr(device_name, mbr);
- if(rv !=0)
- return -1;
- switch(part_num)
- {
- //剩余容量空间
- case 1:
- decode_partitionInfo(&mbr[0x1BE], &partInfo);
- *block_start = partInfo.block_start;
- *block_count = partInfo.block_count;
- *part_Id = partInfo.partitionId;
- break;
- //system 分区表2。fdisk给system分了256M大小
- case 2:
- decode_partitionInfo(&mbr[0x1CE], &partInfo);
- *block_start = partInfo.block_start;
- *block_count = partInfo.block_count;
- *part_Id = partInfo.partitionId; //83
- break;
- //userdata 分区
- case 3:
- decode_partitionInfo(&mbr[0x1DE], &partInfo);
- *block_start = partInfo.block_start;
- *block_count = partInfo.block_count;
- *part_Id = partInfo.partitionId;
- break;
- //cache分区
- case 4:
- decode_partitionInfo(&mbr[0x1EE], &partInfo);
- *block_start = partInfo.block_start;
- *block_count = partInfo.block_count;
- *part_Id = partInfo.partitionId;
- break;
- default:
- return -1;
- }
- return 0;
- }
- //擦除接口 fastboot erase
- if (memcmp(cmdbuf, "erase:", 6) == 0)
- {
- struct fastboot_ptentry *ptn;
- ptn = fastboot_flash_find_ptn(cmdbuf + 6);
- if (ptn == 0)
- ------------------------------------------------------------
- //获取fat system userdata cache 分区名字
- fastboot_ptentry *fastboot_flash_find_ptn(const char *name)
- {
- unsigned int n;
- for (n = 0; n < pcount; n++)
- {
- /* Make sure a substring is not accepted */
- if (strlen(name) == strlen(ptable[n].name))
- {
- if (0 == strcmp(ptable[n].name, name))
- return ptable + n;
- }
- }
- return 0;
- }
- -------------------------------------------------------
- //只有擦除userdata cache fat 这几个功能,kernel u-boot ramdisk 不能擦除
- //其实就是调用ext3format fatmot等格式命令 ,需要添加system 擦除命令
- char run_cmd[80];
- status = 1;
- if (!strcmp(ptn->name, "sytem"))
- {
- sprintf(run_cmd, "ext3format mmc 0:2");
- status = run_command(run_cmd, 0);
- }
- Else if (!strcmp(ptn->name, "userdata"))
- {
- sprintf(run_cmd, "ext3format mmc 0:3");
- status = run_command(run_cmd, 0);
- }
- else if (!strcmp(ptn->name, "cache"))
- {
- sprintf(run_cmd, "ext3format mmc 0:4");
- status = run_command(run_cmd, 0);
- }
- else if (!strcmp(ptn->name, "fat"))
- {
- sprintf(run_cmd, "fatformat mmc 0:1");
- status = run_command(run_cmd, 0);
- }
- =======================================================
- </PRE>
- <P><BR>
- </P>
- <PRE class=cpp name="code">Flash what was downloaded */
- if (memcmp(cmdbuf, "flash:", 6) == 0)
- {
- if (download_bytes == 0)
- {
- sprintf(response, "FAILno image downloaded");
- ret = 0;
- goto send_tx_status;
- }
- //从此句开始判断 kernel。 ramdisk system,获取ptable
- ptn = fastboot_flash_find_ptn(cmdbuf + 6);
- ----------------------
- if ((download_bytes > ptn->length) && (ptn->length != 0) &&
- !(ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV))
- { //注意。system写,会出现这个信息。注意检查
- //分析,只有当system文件大小小于分区大小时,是不会进入的
- sprintf(response, "FAILimage too large for partition");
- /* TODO : Improve check for yaffs write */
- }
- else
- {
- /* Normal case */
- if (write_to_ptn(ptn, (unsigned int)interface.transfer_buffer, download_bytes))
- {
- printf("flashing '%s' failed\n", ptn->name);
- sprintf(response, "FAILfailed to flash partition");
- }
- else
- {
- printf("partition '%s' flashed\n", ptn->name);
- sprintf(response, "OKAY");
- }
- }
- -------------------------------------------
http://blog.youkuaiyun.com/yunfly163/article/details/7496869