[IMX6DL]fastboot erase SD分区实现

来源:互联网 发布:业绩查询系统源码 编辑:程序博客网 时间:2024/05/16 17:16

u-boot: v2009.08


系统默认只支持nand的fastboot erase功能,而我们用的是SD,当使用fastboot erase时,会提示:

“Not support erase command for EMMC”


SD和EMMC都是基于MMC,u-boot本身有实现mmc的block erase功能,

因此我们利用它来擦写对应的块即可。

在擦写之前,我们需要对应的分区信息,fastboot init那会需要将partition
的信息添加到partition table中,这里是添加userdata分区的例子:

diff --git a/drivers/fastboot/fastboot.c b/drivers/fastboot/fastboot.cindex cb1d176..e7606e0 100644--- a/drivers/fastboot/fastboot.c+++ b/drivers/fastboot/fastboot.c@@ -84,6 +84,8 @@ enum {     PTN_KERNEL_INDEX,     PTN_URAMDISK_INDEX,     PTN_SYSTEM_INDEX,+    /*Kris, 20160701, add userdata partition. */+    PTN_USERDATA_INDEX,     PTN_RECOVERY_INDEX }; @@ -406,6 +408,12 @@ static int fastboot_init_mmc_sata_ptable(void)                                   user_partition,                                   "system", dev_desc, ptable); +       /*Kris, 20160701, add userdata partition. */+       setup_ptable_mmc_partition(PTN_USERDATA_INDEX,+                                  CONFIG_ANDROID_USERDATA_PARTITION_MMC,+                                  user_partition,+                                  "userdata", dev_desc, ptable);+        for (i = 0; i <= PTN_RECOVERY_INDEX; i++)                fastboot_flash_add_ptn(&ptable[i]); diff --git a/include/configs/mx6_tek_android.h b/include/configs/mx6_tek_android.hindex e9ea67f..20a515c 100644--- a/include/configs/mx6_tek_android.h+++ b/include/configs/mx6_tek_android.h@@ -59,6 +59,9 @@ #define CONFIG_ANDROID_RECOVERY_PARTITION_MMC 2 #define CONFIG_ANDROID_CACHE_PARTITION_MMC 6 +/*Kris, 20160701, add userdata partition. */+#define CONFIG_ANDROID_USERDATA_PARTITION_MMC  4+
这里的CONFIG_ANDROID_USERDATA_PARTITION_MMC的值一定要和你的具体分区信息对应,
比如我的userdata分区是/dev/block/mmcblk0p4, 因此是分区4.

接着就可以实现fastboot erase功能了,对应的fastboot命令接收函数是rx_handler(),
改动如下:
diff --git a/common/cmd_fastboot.c b/common/cmd_fastboot.cindex 900ed1a..eff8d8a 100644--- a/common/cmd_fastboot.c+++ b/common/cmd_fastboot.c@@ -939,8 +939,55 @@ static int rx_handler (const unsigned char *buffer, unsigned int buffer_size)                        }                        ret = 0; #else+/*Kris,20160701, support erase partition. {*/+#if 0                        printf("Not support erase command for EMMC\n");                        ret = -1;+#else+                       struct fastboot_ptentry *ptn;+                       char slot_no[32], offset[32],  length[32], part_no[32];+                       unsigned int temp;++                       /* Next is the partition name */+                       ptn = fastboot_flash_find_ptn(cmdbuf + 6);+                       if (ptn == 0) {+                               printf("Partition:'%s' does not exist\n",cmdbuf + 6);+                               sprintf(response, "FAILpartition does not exist");+                       }++                       printf("erase partition '%s'\n", ptn->name);+                       char *mmc_erase[4] = {"mmc", "erase", NULL, NULL};+                       char *mmc_dev[4] = {"mmc", "dev", NULL, NULL};++                       mmc_dev[2] = slot_no;+                       mmc_dev[3] = part_no;+                       mmc_erase[2] = offset;+                       mmc_erase[3] = length;++                       sprintf(offset, "0x%x", ptn->start);+                       temp = (ptn->length +MMC_SATA_BLOCK_SIZE - 1) / MMC_SATA_BLOCK_SIZE;+                       sprintf(length, "0x%x", temp);+                       sprintf(slot_no, "%d", fastboot_devinfo.dev_id);+                       sprintf(part_no, "%d", ptn->partition_id);++                       printf("Initializing '%s'\n", ptn->name);+                       if (do_mmcops(NULL, 0, 4, mmc_dev))+                               sprintf(response, "FAIL:Init of MMC card");+                       else+                               sprintf(response, "OKAY");++                       printf("Erasing '%s'\n", ptn->name);+                       if (do_mmcops(NULL, 0, 4, mmc_erase)) {+                               printf("Erasing '%s' FAILED!\n", ptn->name);+                               sprintf(response, "FAIL: Write partition");+                       } else {+                               printf("Erasing '%s' DONE!\n", ptn->name);+                               sprintf(response, "OKAY");+                       }+                       ret = 0;+#endif+/*Kris,20160701, support erase partition. }*/+ #endif
这样就可以erase了(其他分区也通用),userdata比较大,所以erase有一会儿:
[kris@ecovacs:~]$ sudo fastboot erase userdata
erasing 'userdata'...
OKAY [126.140s]
finished. total time: 126.140s

当然erase之后还需要将useradata image download进去,否则会因无文件系统而挂载失败。
编译了个5M大小的image,主要用它的文件系统。
[kris@ecovacs:~]$ sudo fastboot flash userdata userdata.img
sending 'userdata' (5120 KB)...
OKAY [  4.915s]
writing 'userdata'...
OKAY [  0.586s]
finished. total time: 5.501s

1 0
原创粉丝点击