emmc: upgrade gpt or ept based on priority
authorRuixuan Li <ruixuan.li@amlogic.com>
Thu, 14 Jun 2018 12:21:50 +0000 (20:21 +0800)
committerYixun Lan <yixun.lan@amlogic.com>
Fri, 10 Aug 2018 07:25:06 +0000 (00:25 -0700)
PD#168362: P211: emmc: upgrade gpt or ept based on priority

Change-Id: I0e7ea483ac5fc0a59ee24ae21d2e40e1c5d32465
Signed-off-by: Ruixuan Li <ruixuan.li@amlogic.com>
block/partition-generic.c
drivers/amlogic/mmc/emmc_partitions.c

index 298c05f8b5e38f11f0ee989c0a6cd13c101fa60b..d2582d88ebfe31ae8ab3ff05605ab6a778a61d0c 100644 (file)
@@ -24,7 +24,8 @@
 #ifdef CONFIG_BLK_DEV_MD
 extern void md_autodetect_dev(dev_t dev);
 #endif
+
+#define AMLOGIC_ADD_PARTITION
 /*
  * disk_name() is used by partition check code and the genhd driver.
  * It formats the devicename of the indicated disk into
@@ -289,7 +290,9 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
        struct disk_part_tbl *ptbl;
        const char *dname;
        int err;
-
+#ifdef AMLOGIC_ADD_PARTITION
+       char *info_name = NULL;
+#endif
        err = disk_expand_part_tbl(disk, partno);
        if (err)
                return ERR_PTR(err);
@@ -330,10 +333,25 @@ struct hd_struct *add_partition(struct gendisk *disk, int partno,
        }
 
        dname = dev_name(ddev);
+
+#ifdef AMLOGIC_ADD_PARTITION
+       if (info) {
+               info_name = (char *)info->volname;
+       }
+
+       if (info_name && (strlen(info_name) > 1)) {
+               dname = (char *)info->volname;
+               dev_set_name(pdev, "%s", dname);
+       } else if (isdigit(dname[strlen(dname) - 1]))
+               dev_set_name(pdev, "%sp%d", dname, partno);
+       else
+               dev_set_name(pdev, "%s%d", dname, partno);
+#else
        if (isdigit(dname[strlen(dname) - 1]))
                dev_set_name(pdev, "%sp%d", dname, partno);
        else
                dev_set_name(pdev, "%s%d", dname, partno);
+#endif
 
        device_initialize(pdev);
        pdev->class = &block_class;
index 00c496233593a130b4fae680048c8a7c64ea8d40..b6340aa760264b66468a9afa3526164b58e5fca9 100644 (file)
@@ -51,6 +51,8 @@
 #define        MAX_TRANS_SIZE          (MAX_TRANS_BLK * DTB_BLK_SIZE)
 #define stamp_after(a, b)      ((int)(b) - (int)(a)  < 0)
 
+#define GPT_HEADER_SIGNATURE 0x5452415020494645ULL
+
 struct aml_dtb_rsv {
        u8 data[DTB_BLK_SIZE*DTB_BLK_CNT - 4*sizeof(unsigned int)];
        unsigned int magic;
@@ -64,6 +66,27 @@ struct aml_dtb_info {
        u8 valid[2];
 };
 
+struct  efi_guid_t {
+       u8 b[16];
+};
+
+struct gpt_header {
+       __le64 signature;
+       __le32 revision;
+       __le32 header_size;
+       __le32 header_crc32;
+       __le32 reserved1;
+       __le64 my_lba;
+       __le64 alternate_lba;
+       __le64 first_usable_lba;
+       __le64 last_usable_lba;
+       struct efi_guid_t disk_guid;
+       __le64 partition_entry_lba;
+       __le32 num_partition_entries;
+       __le32 sizeof_partition_entry;
+       __le32 partition_entry_array_crc32;
+};
+
 static dev_t amlmmc_dtb_no;
 struct cdev amlmmc_dtb;
 struct device *dtb_dev;
@@ -1150,23 +1173,53 @@ int aml_emmc_partition_ops(struct mmc_card *card, struct gendisk *disk)
        struct disk_part_iter piter;
        struct hd_struct *part;
        struct class *aml_store_class = NULL;
+       struct gpt_header *gpt_h = NULL;
+       unsigned char *buffer = NULL;
+       unsigned int pgcnt;
+       struct page *page = NULL;
 
        pr_info("Enter %s\n", __func__);
 
-       if (!is_card_emmc(card)) /* not emmc, nothing to do */
+       if (is_card_emmc(card) == 0) /* not emmc, nothing to do */
+               return 0;
+
+       pgcnt = PAGE_ALIGN(512) >> PAGE_SHIFT;
+       page = dma_alloc_from_contiguous(NULL, pgcnt, get_order(512));
+
+       if (!page)
+               return -ENOMEM;
+       buffer = page_address(page);
+
+       mmc_claim_host(card->host);
+
+       /*self adapting*/
+       ret = mmc_read_internal(card, 1, 1, buffer);
+       if (ret) {
+               pr_err("%s: save dtb error", __func__);
+               goto out;
+       }
+
+       gpt_h = (struct gpt_header *) buffer;
+
+       if (le64_to_cpu(gpt_h->signature) == GPT_HEADER_SIGNATURE) {
+               dma_release_from_contiguous(NULL, page, pgcnt);
+               mmc_release_host(card->host);
                return 0;
+       }
+
+       dma_release_from_contiguous(NULL, page, pgcnt);
 
        store_device = host->storage_flag;
+
        pt_fmt = kmalloc(sizeof(struct mmc_partitions_fmt), GFP_KERNEL);
        if (pt_fmt == NULL) {
                /*      pr_info(
                 *      "[%s] malloc failed for struct mmc_partitions_fmt!\n",
                 *      __func__);
                 */
+               mmc_release_host(card->host);
                return -ENOMEM;
        }
-
-       mmc_claim_host(card->host);
        disk_part_iter_init(&piter, disk, DISK_PITER_INCL_EMPTY);
 
        while ((part = disk_part_iter_next(&piter))) {