linzhenxing-bit 3 lat temu
rodzic
commit
a2339cdd36

+ 3 - 1
.gitignore

@@ -34,4 +34,6 @@ ncscope.*
 #ctag files
 tags
 
-.vscode/
+.vscode/
+
+bsp/

+ 8 - 6
components/drivers/include/drivers/gpt.h

@@ -9,11 +9,13 @@
  */
 #ifndef __GPT_H
 #define __GPT_H
+
+#include <rtthread.h>
 #include <stdint.h>
-#include <drivers/mmcsd_card.h>
+
 typedef struct
 {
-    uint8_t b[16];
+    uint8_t b[16]; /* GUID 16 bytes*/
 } guid_t;
 
 #define MSDOS_MBR_SIGNATURE 0xaa55
@@ -65,8 +67,8 @@ typedef struct _gpt_header
     uint32_t header_size;
     uint32_t header_crc32;
     uint32_t reserved1;
-    uint64_t my_lba;
-    uint64_t alternate_lba;
+    uint64_t start_lba;     /*GPT head start sector*/
+    uint64_t alternate_lba; /*GPT head alternate sector*/
     uint64_t first_usable_lba;
     uint64_t last_usable_lba;
     gpt_guid_t disk_guid;
@@ -125,6 +127,6 @@ typedef struct _legacy_mbr
 #pragma pack(pop)
 
 int check_gpt(struct rt_mmcsd_card *card);
-int get_partition_param(struct rt_mmcsd_card *card, struct dfs_partition *part, uint32_t pindex);
-void gpt_free();
+int gpt_get_partition_param(struct rt_mmcsd_card *card, struct dfs_partition *part, uint32_t pindex);
+void gpt_free(void);
 #endif /*__GPT_H*/

+ 181 - 175
components/drivers/sdio/block_dev.c

@@ -39,6 +39,7 @@ struct mmcsd_blk_device
 #ifndef RT_MMCSD_MAX_PARTITION
 #define RT_MMCSD_MAX_PARTITION 16
 #endif
+#define RT_GPT_PARTITION_MAX 128
 
 rt_int32_t mmcsd_num_wr_blocks(struct rt_mmcsd_card *card)
 {
@@ -366,230 +367,235 @@ const static struct rt_device_ops mmcsd_blk_ops =
 };
 #endif
 
-rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
+rt_int32_t gpt_device_probe(struct rt_mmcsd_card *card)
 {
-    rt_int32_t err = 0;
+    rt_int32_t err = RT_EOK;
     rt_uint8_t i, status;
-    rt_uint8_t *sector;
     char dname[10];
     char sname[16];
     struct mmcsd_blk_device *blk_dev = RT_NULL;
-    int gpt_chk = 0;
 
-    LOG_D("probe mmcsd block device!");
-    gpt_chk = check_gpt(card);
-    if (gpt_chk == 1)
+    blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
+    if (!blk_dev)
     {
-        status = RT_EOK;
+        LOG_E("mmcsd:malloc memory failed!");
+        return -1;
     }
-    else
-    {
-        err = mmcsd_set_blksize(card);
-        if(err)
-        {
-            return err;
-        }
-        mmcsd_delay_ms(1);
-        /* get the first sector to read partition table */
-        sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE);
-        if (sector == RT_NULL)
-        {
-            LOG_E("allocate partition sector buffer failed!");
 
-        return -RT_ENOMEM;
-    }
+    blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
+                                        card->host->max_seg_size) >> 9,
+                                    (card->host->max_blk_count *
+                                        card->host->max_blk_size) >> 9);
+    blk_dev->part.offset = 0;
+    blk_dev->part.size   = 0;
+    rt_snprintf(sname, sizeof(sname)-1, "sem_%s%d", card->host->name,0);
+    blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
+    /* register mmcsd device */
+    blk_dev->dev.type  = RT_Device_Class_Block;
+#ifdef RT_USING_DEVICE_OPS
+    blk_dev->dev.ops  = &mmcsd_blk_ops;
+#else
+    blk_dev->dev.init = rt_mmcsd_init;
+    blk_dev->dev.open = rt_mmcsd_open;
+    blk_dev->dev.close = rt_mmcsd_close;
+    blk_dev->dev.read = rt_mmcsd_read;
+    blk_dev->dev.write = rt_mmcsd_write;
+    blk_dev->dev.control = rt_mmcsd_control;
+#endif
+    blk_dev->card = card;
 
-        status = rt_mmcsd_req_blk(card, 0, sector, 1, 0);
-    }
+    blk_dev->geometry.bytes_per_sector = 1<<9;
+    blk_dev->geometry.block_size = card->card_blksize;
+    blk_dev->geometry.sector_count =
+        card->card_capacity * (1024 / 512);
 
-    if (status == RT_EOK)
+    blk_dev->dev.user_data = blk_dev;
+
+    rt_device_register(&(blk_dev->dev), card->host->name,
+        RT_DEVICE_FLAG_RDWR);
+    rt_list_insert_after(&blk_devices, &blk_dev->list);
+
+    for (i = 0; i < RT_GPT_PARTITION_MAX; i++)
     {
         blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
         if (!blk_dev)
         {
             LOG_E("mmcsd:malloc memory failed!");
-            return -1;
+            break;
         }
-
         blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
-                                         card->host->max_seg_size) >> 9,
+                                        card->host->max_seg_size) >> 9,
                                         (card->host->max_blk_count *
-                                         card->host->max_blk_size) >> 9);
-        blk_dev->part.offset = 0;
-        blk_dev->part.size   = 0;
-        rt_snprintf(sname, sizeof(sname)-1, "sem_%s%d", card->host->name,0);
-        blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
-        /* register mmcsd device */
-        blk_dev->dev.type  = RT_Device_Class_Block;
-#ifdef RT_USING_DEVICE_OPS
-        blk_dev->dev.ops  = &mmcsd_blk_ops;
-#else
-        blk_dev->dev.init = rt_mmcsd_init;
-        blk_dev->dev.open = rt_mmcsd_open;
-        blk_dev->dev.close = rt_mmcsd_close;
-        blk_dev->dev.read = rt_mmcsd_read;
-        blk_dev->dev.write = rt_mmcsd_write;
-        blk_dev->dev.control = rt_mmcsd_control;
-#endif
-        blk_dev->card = card;
-
-        blk_dev->geometry.bytes_per_sector = 1<<9;
-        blk_dev->geometry.block_size = card->card_blksize;
-        blk_dev->geometry.sector_count =
-            card->card_capacity * (1024 / 512);
+                                        card->host->max_blk_size) >> 9);
 
-        blk_dev->dev.user_data = blk_dev;
-
-        rt_device_register(&(blk_dev->dev), card->host->name,
-            RT_DEVICE_FLAG_RDWR);
-        rt_list_insert_after(&blk_devices, &blk_dev->list);
-        if (gpt_chk == 1)
+        /* get the first partition */
+        status = gpt_get_partition_param(card, &blk_dev->part, i);
+        if (status == RT_EOK)
         {
-            for (i = 0; i < 128; i++)
-            {
-                blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
-                if (!blk_dev)
-                {
-                    LOG_E("mmcsd:malloc memory failed!");
-                    break;
-                }
-                blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
-                                                card->host->max_seg_size) >> 9,
-                                                (card->host->max_blk_count *
-                                                card->host->max_blk_size) >> 9);
-
-                /* get the first partition */
-                status = get_partition_param(card, &blk_dev->part, i);
-                if (status == RT_EOK)
-                {
-                    rt_snprintf(dname, sizeof(dname)-1, "%s%d", card->host->name,i);
-                    rt_snprintf(sname, sizeof(sname)-1, "sem_%s%d", card->host->name,i+1);
-                    blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
-
-                    /* register mmcsd device */
-                    blk_dev->dev.type = RT_Device_Class_Block;
+            rt_snprintf(dname, sizeof(dname)-1, "%s%d", card->host->name,i);
+            rt_snprintf(sname, sizeof(sname)-1, "sem_%s%d", card->host->name,i+1);
+            blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
+
+            /* register mmcsd device */
+            blk_dev->dev.type = RT_Device_Class_Block;
 #ifdef RT_USING_DEVICE_OPS
-                    blk_dev->dev.ops  = &mmcsd_blk_ops;
+            blk_dev->dev.ops  = &mmcsd_blk_ops;
 #else
-                    blk_dev->dev.init = rt_mmcsd_init;
-                    blk_dev->dev.open = rt_mmcsd_open;
-                    blk_dev->dev.close = rt_mmcsd_close;
-                    blk_dev->dev.read = rt_mmcsd_read;
-                    blk_dev->dev.write = rt_mmcsd_write;
-                    blk_dev->dev.control = rt_mmcsd_control;
+            blk_dev->dev.init = rt_mmcsd_init;
+            blk_dev->dev.open = rt_mmcsd_open;
+            blk_dev->dev.close = rt_mmcsd_close;
+            blk_dev->dev.read = rt_mmcsd_read;
+            blk_dev->dev.write = rt_mmcsd_write;
+            blk_dev->dev.control = rt_mmcsd_control;
 #endif
-                    blk_dev->card = card;
+            blk_dev->card = card;
 
-                    blk_dev->geometry.bytes_per_sector = 1<<9;
-                    blk_dev->geometry.block_size = card->card_blksize;
-                    blk_dev->geometry.sector_count = blk_dev->part.size;
+            blk_dev->geometry.bytes_per_sector = 1<<9;
+            blk_dev->geometry.block_size = card->card_blksize;
+            blk_dev->geometry.sector_count = blk_dev->part.size;
 
-                    blk_dev->dev.user_data = blk_dev;
-
-                    rt_device_register(&(blk_dev->dev), dname,
-                        RT_DEVICE_FLAG_RDWR);
-                    rt_list_insert_after(&blk_devices, &blk_dev->list);
-                }
-                else
-                {
-                    rt_free(blk_dev);
-                    blk_dev = RT_NULL;
-                    break;
-                }
-
-#ifdef RT_USING_DFS_MNTTABLE
-                if (blk_dev)
-                {
-                    LOG_I("try to mount file system!");
-                    /* try to mount file system on this block device */
-                    dfs_mount_device(&(blk_dev->dev));
-                }
-#endif
-            }
+            blk_dev->dev.user_data = blk_dev;
 
+            rt_device_register(&(blk_dev->dev), dname,
+                RT_DEVICE_FLAG_RDWR);
+            rt_list_insert_after(&blk_devices, &blk_dev->list);
         }
         else
         {
-            for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++)
-            {
-                blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
-                if (!blk_dev)
-                {
-                    LOG_E("mmcsd:malloc memory failed!");
-                    break;
-                }
-                blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
-                                                card->host->max_seg_size) >> 9,
-                                                (card->host->max_blk_count *
-                                                card->host->max_blk_size) >> 9);
-
-                /* get the first partition */
-                status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
-                if (status == RT_EOK)
-                {
-                    rt_snprintf(dname, sizeof(dname)-1, "%s%d", card->host->name,i);
-                    rt_snprintf(sname, sizeof(sname)-1, "sem_%s%d", card->host->name,i+1);
-                    blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
-
-                    /* register mmcsd device */
-                    blk_dev->dev.type = RT_Device_Class_Block;
-#ifdef RT_USING_DEVICE_OPS
-                    blk_dev->dev.ops  = &mmcsd_blk_ops;
-#else
-                    blk_dev->dev.init = rt_mmcsd_init;
-                    blk_dev->dev.open = rt_mmcsd_open;
-                    blk_dev->dev.close = rt_mmcsd_close;
-                    blk_dev->dev.read = rt_mmcsd_read;
-                    blk_dev->dev.write = rt_mmcsd_write;
-                    blk_dev->dev.control = rt_mmcsd_control;
+            rt_free(blk_dev);
+            blk_dev = RT_NULL;
+            break;
+        }
+
+#ifdef RT_USING_DFS_MNTTABLE
+        if (blk_dev)
+        {
+            LOG_I("try to mount file system!");
+            /* try to mount file system on this block device */
+            dfs_mount_device(&(blk_dev->dev));
+        }
 #endif
-                    blk_dev->card = card;
+    }
+    gpt_free();
 
-                    blk_dev->geometry.bytes_per_sector = 1<<9;
-                    blk_dev->geometry.block_size = card->card_blksize;
-                    blk_dev->geometry.sector_count = blk_dev->part.size;
+    return err;
+}
 
-                    blk_dev->dev.user_data = blk_dev;
+rt_int32_t mbr_device_probe(struct rt_mmcsd_card *card)
+{
+    rt_int32_t err = 0;
+    rt_uint8_t i, status;
+    rt_uint8_t *sector;
+    char dname[10];
+    char sname[16];
+    struct mmcsd_blk_device *blk_dev = RT_NULL;
 
-                    rt_device_register(&(blk_dev->dev), dname,
-                        RT_DEVICE_FLAG_RDWR);
-                    rt_list_insert_after(&blk_devices, &blk_dev->list);
-                }
-                else
-                {
-                    rt_free(blk_dev);
-                    blk_dev = RT_NULL;
-                    break;
-                }
+    err = mmcsd_set_blksize(card);
+    if(err)
+    {
+        return err;
+    }
+    mmcsd_delay_ms(1);
+    /* get the first sector to read partition table */
+    sector = (rt_uint8_t *)rt_malloc(SECTOR_SIZE);
+    if (sector == RT_NULL)
+    {
+        LOG_E("allocate partition sector buffer failed!");
 
-#ifdef RT_USING_DFS_MNTTABLE
-                if (blk_dev)
-                {
-                    LOG_I("try to mount file system!");
-                    /* try to mount file system on this block device */
-                    dfs_mount_device(&(blk_dev->dev));
-                }
-#endif
+        return -RT_ENOMEM;
+    }
+
+    status = rt_mmcsd_req_blk(card, 0, sector, 1, 0);
+    if (status == RT_EOK)
+    {
+        for (i = 0; i < RT_MMCSD_MAX_PARTITION; i++)
+        {
+            blk_dev = rt_calloc(1, sizeof(struct mmcsd_blk_device));
+            if (!blk_dev)
+            {
+                LOG_E("mmcsd:malloc memory failed!");
+                break;
+            }
+            blk_dev->max_req_size = BLK_MIN((card->host->max_dma_segs *
+                                            card->host->max_seg_size) >> 9,
+                                            (card->host->max_blk_count *
+                                            card->host->max_blk_size) >> 9);
+
+            /* get the first partition */
+            status = dfs_filesystem_get_partition(&blk_dev->part, sector, i);
+            if (status == RT_EOK)
+            {
+                rt_snprintf(dname, sizeof(dname)-1, "%s%d", card->host->name,i);
+                rt_snprintf(sname, sizeof(sname)-1, "sem_%s%d", card->host->name,i+1);
+                blk_dev->part.lock = rt_sem_create(sname, 1, RT_IPC_FLAG_FIFO);
+
+                /* register mmcsd device */
+                blk_dev->dev.type = RT_Device_Class_Block;
+    #ifdef RT_USING_DEVICE_OPS
+                blk_dev->dev.ops  = &mmcsd_blk_ops;
+    #else
+                blk_dev->dev.init = rt_mmcsd_init;
+                blk_dev->dev.open = rt_mmcsd_open;
+                blk_dev->dev.close = rt_mmcsd_close;
+                blk_dev->dev.read = rt_mmcsd_read;
+                blk_dev->dev.write = rt_mmcsd_write;
+                blk_dev->dev.control = rt_mmcsd_control;
+    #endif
+                blk_dev->card = card;
+
+                blk_dev->geometry.bytes_per_sector = 1<<9;
+                blk_dev->geometry.block_size = card->card_blksize;
+                blk_dev->geometry.sector_count = blk_dev->part.size;
+
+                blk_dev->dev.user_data = blk_dev;
+
+                rt_device_register(&(blk_dev->dev), dname,
+                    RT_DEVICE_FLAG_RDWR);
+                rt_list_insert_after(&blk_devices, &blk_dev->list);
+            }
+            else
+            {
+                rt_free(blk_dev);
+                blk_dev = RT_NULL;
+                break;
             }
 
+    #ifdef RT_USING_DFS_MNTTABLE
+            if (blk_dev)
+            {
+                LOG_I("try to mount file system!");
+                /* try to mount file system on this block device */
+                dfs_mount_device(&(blk_dev->dev));
+            }
+    #endif
         }
     }
     else
     {
         LOG_E("read mmcsd first sector failed");
-        err = -RT_ERROR;
+        err = -RT_ERROR;        
     }
 
-    if (gpt_chk == 1)
+    /* release sector buffer */
+    rt_free(sector);
+
+    return err;
+
+}
+
+rt_int32_t rt_mmcsd_blk_probe(struct rt_mmcsd_card *card)
+{
+    uint32_t err = 0;
+
+    LOG_D("probe mmcsd block device!");
+    if (check_gpt(card) != 0)
     {
-        gpt_free();
+        err = gpt_device_probe(card);
     }
     else
     {
-        /* release sector buffer */
-        rt_free(sector);
+        err = mbr_device_probe(card);
     }
-
     return err;
 }
 

+ 40 - 32
components/drivers/sdio/gpt.c

@@ -22,6 +22,10 @@
 
 #define min(a, b) a < b ? a : b
 static int force_gpt = 0;
+static gpt_header *_gpt;
+static gpt_entry *_ptes;
+#define GPT_TYPE 1
+#define MBR_TYPE 0
 
 static inline int efi_guidcmp (gpt_guid_t left, gpt_guid_t right)
 {
@@ -51,6 +55,7 @@ static inline int pmbr_part_valid(gpt_mbr_record *part)
 invalid:
     return 0;
 }
+
 /*
 *
 * return ret
@@ -194,7 +199,7 @@ static int is_gpt_valid(struct rt_mmcsd_card *card, size_t lba, gpt_header **gpt
     /* Check the GUID Partition Table signature */
     if ((uint64_t)((*gpt)->signature) != GPT_HEADER_SIGNATURE)
     {
-        printf("GUID Partition Table Header signature is wrong:"
+        LOG_E("GUID Partition Table Header signature is wrong:"
              "%ld != %ld\n",(uint64_t)((*gpt)->signature),(uint64_t)GPT_HEADER_SIGNATURE);
         goto fail;
     }
@@ -202,17 +207,17 @@ static int is_gpt_valid(struct rt_mmcsd_card *card, size_t lba, gpt_header **gpt
     /* Check the GUID Partition Table header size is too small */
     if ((uint32_t)((*gpt)->header_size) < sizeof(gpt_header))
     {
-        printf("GUID Partition Table Header size is too small: %u < %zu\n",
+        LOG_E("GUID Partition Table Header size is too small: %u < %zu\n",
             (uint32_t)((*gpt)->header_size),sizeof(gpt_header));
         goto fail;
     }
 
-    /* Check that the my_lba entry points to the LBA that contains
+    /* Check that the start_lba entry points to the LBA that contains
      * the GUID Partition Table */
-    if ((uint64_t)((*gpt)->my_lba) != lba)
+    if ((uint64_t)((*gpt)->start_lba) != lba)
     {
-        printf("GPT my_lba incorrect: %ld != %ld\n",
-             (uint64_t)((*gpt)->my_lba),
+        LOG_E("GPT start_lba incorrect: %ld != %ld\n",
+             (uint64_t)((*gpt)->start_lba),
              (uint64_t)lba);
         goto fail;
     }
@@ -223,7 +228,7 @@ static int is_gpt_valid(struct rt_mmcsd_card *card, size_t lba, gpt_header **gpt
     lastlba = last_lba(card);
     if ((uint64_t)((*gpt)->first_usable_lba) > lastlba)
     {
-        printf("GPT: first_usable_lba incorrect: %ld > %ld\n",
+        LOG_E("GPT: first_usable_lba incorrect: %ld > %ld\n",
              ((uint64_t)((*gpt)->first_usable_lba)),
              (size_t)lastlba);
         goto fail;
@@ -231,7 +236,7 @@ static int is_gpt_valid(struct rt_mmcsd_card *card, size_t lba, gpt_header **gpt
 
     if ((uint64_t)((*gpt)->last_usable_lba) > lastlba)
     {
-        printf("GPT: last_usable_lba incorrect: %ld > %ld\n",
+        LOG_E("GPT: last_usable_lba incorrect: %ld > %ld\n",
              (uint64_t)((*gpt)->last_usable_lba),
              (size_t)lastlba);
         goto fail;
@@ -239,14 +244,14 @@ static int is_gpt_valid(struct rt_mmcsd_card *card, size_t lba, gpt_header **gpt
 
     if ((uint64_t)((*gpt)->last_usable_lba) < (uint64_t)((*gpt)->first_usable_lba))
     {
-        printf("GPT: last_usable_lba incorrect: %ld > %ld\n",
+        LOG_E("GPT: last_usable_lba incorrect: %ld > %ld\n",
              (uint64_t)((*gpt)->last_usable_lba),
              (uint64_t)((*gpt)->first_usable_lba));
         goto fail;
     }
     /* Check that sizeof_partition_entry has the correct value */
     if ((uint32_t)((*gpt)->sizeof_partition_entry) != sizeof(gpt_entry)) {
-        printf("GUID Partition Entry Size check failed.\n");
+        LOG_E("GUID Partition Entry Size check failed.\n");
         goto fail;
     }
 
@@ -266,8 +271,8 @@ static int is_gpt_valid(struct rt_mmcsd_card *card, size_t lba, gpt_header **gpt
 
 /**
  * is_pte_valid() - tests one PTE for validity
- * @pte:pte to check
- * @lastlba: last lba of the disk
+ * pte:pte to check
+ * lastlba: last lba of the disk
  *
  * Description: returns 1 if valid,  0 on error.
  */
@@ -285,9 +290,9 @@ static inline int is_pte_valid(const gpt_entry *pte, const size_t lastlba)
 
 /**
  * compare_gpts() - Search disk for valid GPT headers and PTEs
- * @pgpt: primary GPT header
- * @agpt: alternate GPT header
- * @lastlba: last LBA number
+ * pgpt: primary GPT header
+ * agpt: alternate GPT header
+ * lastlba: last LBA number
  *
  * Description: Returns nothing.  Sanity checks pgpt and agpt fields
  * and prints warnings on discrepancies.
@@ -301,21 +306,21 @@ static void compare_gpts(gpt_header *pgpt, gpt_header *agpt, size_t lastlba)
         return;
     }
 
-    if ((uint64_t)(pgpt->my_lba) != (uint64_t)(agpt->alternate_lba))
+    if ((uint64_t)(pgpt->start_lba) != (uint64_t)(agpt->alternate_lba))
     {
         LOG_I("GPT:Primary header LBA != Alt. header alternate_lba\n");
         LOG_I("GPT:%lld != %lld\n",
-               (uint64_t)(pgpt->my_lba),
+               (uint64_t)(pgpt->start_lba),
                        (uint64_t)(agpt->alternate_lba));
         error_found++;
     }
 
-    if ((uint64_t)(pgpt->alternate_lba) != (uint64_t)(agpt->my_lba))
+    if ((uint64_t)(pgpt->alternate_lba) != (uint64_t)(agpt->start_lba))
     {
-        LOG_I("GPT:Primary header alternate_lba != Alt. header my_lba\n");
+        LOG_I("GPT:Primary header alternate_lba != Alt. header start_lba\n");
         LOG_I("GPT:%lld != %lld\n",
                (uint64_t)(pgpt->alternate_lba),
-                       (uint64_t)(agpt->my_lba));
+                       (uint64_t)(agpt->start_lba));
         error_found++;
     }
 
@@ -379,11 +384,11 @@ static void compare_gpts(gpt_header *pgpt, gpt_header *agpt, size_t lastlba)
         error_found++;
     }
 
-    if ((agpt->my_lba) != lastlba)
+    if ((agpt->start_lba) != lastlba)
     {
         LOG_I("GPT:Alternate GPT header not at the end of the disk.\n");
         LOG_I("GPT:%lld != %lld\n",
-            (uint64_t)(agpt->my_lba),
+            (uint64_t)(agpt->start_lba),
             (size_t)lastlba);
         error_found++;
     }
@@ -397,9 +402,9 @@ static void compare_gpts(gpt_header *pgpt, gpt_header *agpt, size_t lastlba)
 
 /**
  * find_valid_gpt() - Search disk for valid GPT headers and PTEs
- * @state: disk parsed partitions
- * @gpt: GPT header ptr, filled on return.
- * @ptes: PTEs ptr, filled on return.
+ * state: disk parsed partitions
+ * gpt: GPT header ptr, filled on return.
+ * ptes: PTEs ptr, filled on return.
  *
  * Description: Returns 1 if valid, 0 on error.
  * If valid, returns pointers to newly allocated GPT header and PTEs.
@@ -509,32 +514,35 @@ static int find_valid_gpt(struct rt_mmcsd_card *card, gpt_header **gpt,
         *ptes = RT_NULL;
         return 0;
 }
-static gpt_header *_gpt;
-static gpt_entry *_ptes;
+
 int check_gpt(struct rt_mmcsd_card *card)
 {
     if (!find_valid_gpt(card, &_gpt, &_ptes) || !_gpt || !_ptes)
     {
         rt_free(_gpt);
         rt_free(_ptes);
-        return 0;
+        return MBR_TYPE;
     }
-    return 1;
+    return GPT_TYPE;
 }
 
-int get_partition_param(struct rt_mmcsd_card *card, struct dfs_partition *part, uint32_t pindex)
+int gpt_get_partition_param(struct rt_mmcsd_card *card, struct dfs_partition *part, uint32_t pindex)
 {
     if (!is_pte_valid(&_ptes[pindex], last_lba(card)))
     {
         return -1;
     }
+
     part->offset = (off_t)(_ptes[pindex].starting_lba);
     part->size = (_ptes[pindex].ending_lba) - (_ptes[pindex].starting_lba) + 1ULL;
 
     rt_kprintf("found part[%d], begin(sector): %d, end(sector):%d size: ",
              pindex, _ptes[pindex].starting_lba, _ptes[pindex].ending_lba);
+
     if ((part->size >> 11) == 0)
-        rt_kprintf("%d%s", part->size >> 1, "KB\n"); /* KB */
+    {
+        rt_kprintf("%d%s", part->size >> 1, "KB\n"); /* KB */        
+    }
     else
     {
         unsigned int part_size;
@@ -547,7 +555,7 @@ int get_partition_param(struct rt_mmcsd_card *card, struct dfs_partition *part,
     return 0;
 }
 
-void gpt_free()
+void gpt_free(void)
 {
     rt_free(_ptes);
     rt_free(_gpt);