<div dir="ltr"><div>I understand this patch might not look good since I couldn't find a suitable way to pass the PTE_LBA from UI to GPT handling path.</div><div>But I'd like to address the problem we have, and am open to better solutions.</div><div><br></div>We'd like to use GPT partitions on an <a href="http://i.mx">i.mx</a> SoC based device. <span style="line-height:1.5">However, this SoC family loads it's bootcode from a specific fixed location - 0x400, which conflicts to a "default" location of PTE_LBA (LBA2). The following provides more context from people porting Chromium OS to Freescale SoC.</span><div><br></div><div>    <a href="https://groups.google.com/a/chromium.org/forum/#!topic/chromium-os-dev/uvoX-poonOU">https://groups.google.com/a/chromium.org/forum/#!topic/chromium-os-dev/uvoX-poonOU</a><br></div><div><br></div><div><span style="line-height:1.5">Chromium OS project added this support to its 'cgpt' utilities. But I'd like to stick with parted if possible.</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Thanks,</span></div><div><span style="line-height:1.5">Roy</span></div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Mar 21, 2016 at 11:24 AM Tzu-Jung Lee <<a href="mailto:roylee17@currant.com">roylee17@currant.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: =Tzu-Jung Lee <<a href="mailto:roylee17@currant.com" target="_blank">roylee17@currant.com</a>><br>
<br>
Some SoC requires their booting code at a specific location, which<br>
might conflict with the default layout of GPT.<br>
<br>
Supporting a specified PartitionEntryLBA is required in this case.<br>
<br>
Signed-off-by: Tzu-Jung Lee <<a href="mailto:roylee17@currant.com" target="_blank">roylee17@currant.com</a>><br>
<br>
diff --git a/include/parted/device.in.h b/include/parted/device.in.h<br>
index 82d4104..1ce7a97 100644<br>
--- a/include/parted/device.in.h<br>
+++ b/include/parted/device.in.h<br>
@@ -87,6 +87,8 @@ struct _PedDevice {<br>
         int             dirty;<br>
         int             boot_dirty;<br>
<br>
+        int             pte_lba;<br>
+<br>
         PedCHSGeometry  hw_geom;<br>
         PedCHSGeometry  bios_geom;<br>
         short           host, did;<br>
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c<br>
index d69377a..004efce 100644<br>
--- a/libparted/labels/gpt.c<br>
+++ b/libparted/labels/gpt.c<br>
@@ -499,6 +499,7 @@ gpt_probe (const PedDevice *dev)<br>
       || ped_device_read (dev, pth_raw, dev->length - 1, GPT_HEADER_SECTORS))<br>
     {<br>
       GuidPartitionTableHeader_t *gpt = pth_new_from_raw (dev, pth_raw);<br>
+      ((PedDevice*)dev)->pte_lba = gpt->PartitionEntryLBA;<br>
       if (gpt->Signature == PED_CPU_TO_LE64 (GPT_HEADER_SIGNATURE))<br>
         gpt_sig_found = 1;<br>
       pth_free (gpt);<br>
@@ -519,8 +520,8 @@ gpt_alloc (const PedDevice *dev)<br>
   if (!disk)<br>
     goto error;<br>
<br>
-  data_start = 2 + GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / dev->sector_size;<br>
-  data_end = dev->length - 2<br>
+  data_start = dev->pte_lba + GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / dev->sector_size;<br>
+  data_end = dev->length - dev->pte_lba<br>
     - GPT_DEFAULT_PARTITION_ENTRY_ARRAY_SIZE / dev->sector_size;<br>
<br>
   /* If the device is too small to accommodate GPT headers and one data<br>
@@ -743,14 +744,14 @@ _parse_header (PedDisk *disk, const GuidPartitionTableHeader_t *gpt,<br>
   last_usable = PED_LE64_TO_CPU (gpt->LastUsableLBA);<br>
<br>
   /* Need to check whether the volume has grown, the LastUsableLBA is<br>
-     normally set to disk->dev->length - 2 - ptes_size (at least for parted<br>
-     created volumes), where ptes_size is the number of entries *<br>
+     normally set to disk->dev->length - disb->dev->pte_lba - ptes_size (at least<br>
+     for parted created volumes), where ptes_size is the number of entries *<br>
      size of each entry / sector size or 16k / sector size, whatever the greater.<br>
      If the volume has grown, offer the user the chance to use the new<br>
      space or continue with the current usable area.  Only ask once per<br>
      parted invocation. */<br>
<br>
-  last_usable_if_grown = disk->dev->length - 2 - _ptes_sectors(disk, gpt);<br>
+  last_usable_if_grown = disk->dev->length - disk->dev->pte_lba - _ptes_sectors(disk, gpt);<br>
<br>
   if (last_usable <= first_usable<br>
       || disk->dev->length < last_usable)<br>
@@ -1192,7 +1193,7 @@ _generate_header (const PedDisk *disk, int alternate, uint32_t ptes_crc,<br>
     {<br>
       gpt->MyLBA = PED_CPU_TO_LE64 (1);<br>
       gpt->AlternateLBA = PED_CPU_TO_LE64 (gpt_disk_data->AlternateLBA);<br>
-      gpt->PartitionEntryLBA = PED_CPU_TO_LE64 (2);<br>
+      gpt->PartitionEntryLBA = PED_CPU_TO_LE64 (disk->dev->pte_lba);<br>
     }<br>
<br>
   gpt->FirstUsableLBA = PED_CPU_TO_LE64 (gpt_disk_data->data_area.start);<br>
@@ -1284,7 +1285,7 @@ gpt_write (const PedDisk *disk)<br>
   free (pth_raw);<br>
   if (!write_ok)<br>
     goto error_free_ptes;<br>
-  if (!ped_device_write (disk->dev, ptes, 2, ptes_sectors))<br>
+  if (!ped_device_write (disk->dev, ptes, disk->dev->pte_lba, ptes_sectors))<br>
     goto error_free_ptes;<br>
<br>
   /* Write Alternate PTH & PTEs */<br>
@@ -1962,7 +1963,7 @@ gpt_get_max_primary_partition_count (const PedDisk *disk)<br>
  *<br>
  * The number of possible partitions or supported partitions is:<br>
  * SP = FirstUsableLBA*Blocksize - 2*Blocksize / SizeOfPartitionEntry<br>
- * SP = Blocksize(FirstusableLBA - 2) / SizeOfPartitoinEntry<br>
+ * SP = Blocksize(FirstusableLBA - PartitionEntryLBA) / SizeOfPartitoinEntry<br>
  */<br>
 static bool<br>
 gpt_get_max_supported_partition_count (const PedDisk *disk, int *max_n)<br>
@@ -1986,7 +1987,7 @@ gpt_get_max_supported_partition_count (const PedDisk *disk, int *max_n)<br>
         = PED_CPU_TO_LE32 (sizeof (GuidPartitionEntry_t));<br>
     }<br>
<br>
-  *max_n = (disk->dev->sector_size * (PED_LE64_TO_CPU (pth->FirstUsableLBA) - 2)<br>
+  *max_n = (disk->dev->sector_size * (PED_LE64_TO_CPU (pth->FirstUsableLBA) - PED_LE64_TO_CPU (pth->PartitionEntryLBA))<br>
             / PED_LE32_TO_CPU (pth->SizeOfPartitionEntry));<br>
   pth_free (pth);<br>
   return true;<br>
diff --git a/parted/parted.c b/parted/parted.c<br>
index a9426c4..cfd5de8 100644<br>
--- a/parted/parted.c<br>
+++ b/parted/parted.c<br>
@@ -511,6 +511,7 @@ do_mklabel (PedDevice** dev, PedDisk** diskp)<br>
 {<br>
         PedDisk*                disk;<br>
         const PedDiskType*      type = NULL;<br>
+        int                     pte_lba = 2;<br>
<br>
         if (*diskp)<br>
                 disk = *diskp;<br>
@@ -524,6 +525,11 @@ do_mklabel (PedDevice** dev, PedDisk** diskp)<br>
         if (!command_line_get_disk_type (_("New disk label type?"), &type))<br>
                 goto error;<br>
<br>
+        if (!command_line_get_integer (_("Starting LBA of partition entry array?"), &pte_lba))<br>
+                goto error;<br>
+<br>
+        (*dev)->pte_lba = pte_lba;<br>
+<br>
         if (disk) {<br>
                 if (!_disk_warn_busy (disk))<br>
                         goto error;<br>
--<br>
2.7.3<br>
<br>
</blockquote></div>