android系统移植emmc记录(5)-- fastboot命令分析

  1. int do_fastboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])  
  2.   
  3. {//设置u-boot,kernel,ramdisk ,system,userdata,cache空间地址   
  4.   
  5.        if (set_partition_table())  
  6.   
  7.          
  8.   
  9. ---------------------------------------->  // set_partition_table         
  10.    //主要设置bootloader ramdisk kernel 和fdisk所分的区的起始地址和大小,保存在ptable里面。   
  11.   
  12.        /* Bootloader */  
  13.   
  14.        strcpy(ptable[pcount].name, "bootloader");  
  15.   
  16.        ptable[pcount].start = 0;  
  17.   
  18.        ptable[pcount].length = 0;  
  19.   
  20.        ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MOVI_CMD;  
  21.   
  22.        pcount++;  
  23.   
  24.          
  25.   
  26.        /* Kernel */  
  27.   
  28.        strcpy(ptable[pcount].name, "kernel");  
  29.   
  30.        ptable[pcount].start = 0;  
  31.   
  32.        ptable[pcount].length = 0;  
  33.   
  34.        ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MOVI_CMD;  
  35.   
  36.        pcount++;  
  37.   
  38.    
  39.   
  40.        /* Ramdisk  3M */  
  41.   
  42.        strcpy(ptable[pcount].name, "ramdisk");  
  43.   
  44.        ptable[pcount].start = 0;  
  45.   
  46.        ptable[pcount].length = 0x300000; //3MB,初始值,如果文件大于3M,则会使用文件大小   
  47.   
  48.        //写ramdisk的命令类型标志,这里用movi命令来写   
  49.   
  50.        ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MOVI_CMD;  
  51.   
  52.        pcount++;  
  53.   
  54.        -----------------------  
  55.   
  56.        /* System */  
  57.   
  58.        get_mmc_part_info("0", 2, &start, &count, &pid);  
  59.   
  60.        -------------------------  
  61.   
  62.        if (pid != 0x83)  
  63.   
  64.               goto part_type_error;  
  65.   
  66.        strcpy(ptable[pcount].name, "system");  
  67.   
  68. /* 
  69.  
  70.                      decode_partitionInfo(&mbr[0x1CE], &partInfo); 
  71.  
  72.                      *block_start    = partInfo.block_start;    
  73.  
  74.                      *block_count  = partInfo.block_count;  
  75.  
  76.                      *part_Id        = partInfo.partitionId; 
  77.  
  78. */    //system 开始的地址   
  79.   
  80.        ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  81.   
  82.        //大小,256M   
  83.   
  84.        ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  85.   
  86.        //写system数据类型的标志,这里用MMC命令来写   
  87.   
  88.        ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;  
  89.   
  90.        pcount++;  
  91.   
  92.          
  93.   
  94.        /* Data  350M*/  
  95.   
  96.        get_mmc_part_info("0", 3, &start, &count, &pid);  
  97.   
  98.        if (pid != 0x83)  
  99.   
  100.               goto part_type_error;  
  101.   
  102.        strcpy(ptable[pcount].name, "userdata");  
  103.   
  104.        ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  105.   
  106.        ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  107.   
  108.        ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;  
  109.   
  110.        pcount++;  
  111.   
  112.          
  113.   
  114.        /* Cache  100 M */  
  115.   
  116.        get_mmc_part_info("0", 4, &start, &count, &pid);  
  117.   
  118.        if (pid != 0x83)  
  119.   
  120.               goto part_type_error;  
  121.   
  122.        strcpy(ptable[pcount].name, "cache");  
  123.   
  124.        ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  125.   
  126.        ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  127.   
  128.        ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;  
  129.   
  130.        pcount++;  
  131.   
  132.          
  133.   
  134.        /* fat 剩余空间分区,剩余空间分区格式fat?标志为 0c*/  
  135.   
  136.        get_mmc_part_info("0", 1, &start, &count, &pid);  
  137.   
  138.        if (pid != 0xc)  
  139.   
  140.               goto part_type_error;  
  141.   
  142.        strcpy(ptable[pcount].name, "fat");  
  143.   
  144.        ptable[pcount].start = start * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  145.   
  146.        ptable[pcount].length = count * CFG_FASTBOOT_SDMMC_BLOCKSIZE;  
  147.   
  148.        ptable[pcount].flags = FASTBOOT_PTENTRY_FLAGS_USE_MMC_CMD;  
  149.   
  150.        pcount++;  
  151.   
  152.          
  153.   
  154. -------------->  
  155. <PRE class=cpp name="code">---------------------------->  
  156. //获取fdisk 对system userdata  cache分区的大小   
  157. int get_mmc_part_info(char *device_name, int part_num, int *block_start, int *block_count, unsigned char *part_Id)  
  158. {  
  159.     int     rv;  
  160.     PartitionInfo   partInfo;  
  161.     unsigned char   mbr[512];  
  162.     //从设备0中读取MBR主分区目录,里面定义了各个分区的信息,和起始,结束扇区   
  163.     rv = get_mmc_mbr(device_name, mbr);  
  164.       
  165.     if(rv !=0)  
  166.         return -1;  
  167.                   
  168.     switch(part_num)  
  169.     {  
  170.         //剩余容量空间   
  171.         case 1:  
  172.             decode_partitionInfo(&mbr[0x1BE], &partInfo);  
  173.             *block_start    = partInfo.block_start;   
  174.             *block_count    = partInfo.block_count;   
  175.             *part_Id    = partInfo.partitionId;   
  176.             break;  
  177.         //system 分区表2。fdisk给system分了256M大小     
  178.         case 2:  
  179.             decode_partitionInfo(&mbr[0x1CE], &partInfo);  
  180.             *block_start    = partInfo.block_start;   
  181.             *block_count    = partInfo.block_count;   
  182.             *part_Id    = partInfo.partitionId; //83   
  183.             break;  
  184.         //userdata 分区   
  185.         case 3:  
  186.             decode_partitionInfo(&mbr[0x1DE], &partInfo);  
  187.             *block_start    = partInfo.block_start;   
  188.             *block_count    = partInfo.block_count;   
  189.             *part_Id    = partInfo.partitionId;   
  190.             break;  
  191.         //cache分区   
  192.         case 4:  
  193.             decode_partitionInfo(&mbr[0x1EE], &partInfo);  
  194.             *block_start    = partInfo.block_start;   
  195.             *block_count    = partInfo.block_count;   
  196.             *part_Id    = partInfo.partitionId;   
  197.             break;  
  198.         default:  
  199.             return -1;  
  200.     }     
  201.   
  202.     return 0;  
  203. }  
  1. //擦除接口 fastboot erase    
  2. if (memcmp(cmdbuf, "erase:", 6) == 0)  
  3.         {  
  4.             struct fastboot_ptentry *ptn;  
  5.   
  6.             ptn = fastboot_flash_find_ptn(cmdbuf + 6);  
  7.             if (ptn == 0)  
  8.   
  9. ------------------------------------------------------------  
  10. //获取fat system userdata cache 分区名字   
  11. fastboot_ptentry *fastboot_flash_find_ptn(const char *name)  
  12. {  
  13.     unsigned int n;  
  14.       
  15.     for (n = 0; n < pcount; n++)  
  16.     {  
  17.         /* Make sure a substring is not accepted */  
  18.         if (strlen(name) == strlen(ptable[n].name))  
  19.         {  
  20.             if (0 == strcmp(ptable[n].name, name))  
  21.                 return ptable + n;  
  22.         }  
  23.     }  
  24.     return 0;  
  25. }  
  26. -------------------------------------------------------  
  27.   
  28. //只有擦除userdata  cache fat 这几个功能,kernel u-boot  ramdisk 不能擦除   
  29. //其实就是调用ext3format fatmot等格式命令 ,需要添加system 擦除命令   
  30.             char run_cmd[80];  
  31.             status = 1;  
  32.   
  33.             if (!strcmp(ptn->name, "sytem"))  
  34.             {  
  35.                 sprintf(run_cmd, "ext3format mmc 0:2");  
  36.                 status = run_command(run_cmd, 0);  
  37.             }  
  38.             Else if (!strcmp(ptn->name, "userdata"))  
  39.             {  
  40.                 sprintf(run_cmd, "ext3format mmc 0:3");  
  41.                 status = run_command(run_cmd, 0);  
  42.             }  
  43.             else if (!strcmp(ptn->name, "cache"))  
  44.             {  
  45.                 sprintf(run_cmd, "ext3format mmc 0:4");  
  46.                 status = run_command(run_cmd, 0);  
  47.             }  
  48.             else if (!strcmp(ptn->name, "fat"))  
  49.             {  
  50.                 sprintf(run_cmd, "fatformat mmc 0:1");  
  51.                 status = run_command(run_cmd, 0);  
  52.             }  
  53. =======================================================  
  54. </PRE>  
  55. <P><BR>  
  56.  </P>  
  57. <PRE class=cpp name="code">Flash what was downloaded */  
  58.         if (memcmp(cmdbuf, "flash:", 6) == 0)  
  59.         {  
  60.             if (download_bytes == 0)  
  61.             {  
  62.                 sprintf(response, "FAILno image downloaded");  
  63.                 ret = 0;  
  64.                 goto send_tx_status;  
  65.             }  
  66.             //从此句开始判断 kernel。 ramdisk system,获取ptable   
  67.             ptn = fastboot_flash_find_ptn(cmdbuf + 6);  
  68.             ----------------------  
  69.             if ((download_bytes > ptn->length) && (ptn->length != 0) &&      
  70.                    !(ptn->flags & FASTBOOT_PTENTRY_FLAGS_WRITE_ENV))  
  71.             { //注意。system写,会出现这个信息。注意检查   
  72.              //分析,只有当system文件大小小于分区大小时,是不会进入的   
  73.                 sprintf(response, "FAILimage too large for partition");  
  74.                 /* TODO : Improve check for yaffs write */  
  75.             }  
  76.             else  
  77.             {  
  78.                     /* Normal case */  
  79.                     if (write_to_ptn(ptn, (unsigned int)interface.transfer_buffer, download_bytes))  
  80.                     {  
  81.                         printf("flashing '%s' failed\n", ptn->name);  
  82.                         sprintf(response, "FAILfailed to flash partition");  
  83.                     }  
  84.                     else  
  85.                     {  
  86.                         printf("partition '%s' flashed\n", ptn->name);  
  87.                         sprintf(response, "OKAY");  
  88.                     }  
  89.             }  
  90.             -------------------------------------------  

http://blog.csdn.net/yunfly163/article/details/7496869

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值