From 7ac11088df63b873ad5a91e3791ce7643fb163be Mon Sep 17 00:00:00 2001 From: Royyan Zahir Date: Sun, 5 Jul 2026 21:44:26 +0400 Subject: [PATCH] gpt: add qbootctl A/B slot flags as named GPT attributes Add active/successful/unbootable partition options (gen_partition --active/--successful/--unbootable) mapping to the qbootctl A/B attribute bits 50/54/55 (gpt-utils.h). ptool builds Attributes from these named flags; no raw attribute value is written. Signed-off-by: Royyan Zahir --- qcom_ptool/gen_partition.py | 12 ++++++++++++ qcom_ptool/ptool.py | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/qcom_ptool/gen_partition.py b/qcom_ptool/gen_partition.py index b6449d0..b2343bf 100755 --- a/qcom_ptool/gen_partition.py +++ b/qcom_ptool/gen_partition.py @@ -66,6 +66,9 @@ def usage() -> NoReturn: "readonly": "true", "filename": "", "sparse": "false", + "active": "false", + "successful": "false", + "unbootable": "false", } ################################################################## @@ -135,6 +138,12 @@ def partition_options(argv): partition_entry["readonly"] = "true" else: partition_entry["readonly"] = "false" + elif opt in ["--active"]: + partition_entry["active"] = arg + elif opt in ["--successful"]: + partition_entry["successful"] = arg + elif opt in ["--unbootable"]: + partition_entry["unbootable"] = arg elif opt in ["--filename"]: partition_entry["filename"] = arg elif opt in ["--sparse"]: @@ -162,6 +171,9 @@ def parse_partition_entries(partition_entries): "type-guid=", "filename=", "attributes=", + "active=", + "successful=", + "unbootable=", "sparse=", ], ) diff --git a/qcom_ptool/ptool.py b/qcom_ptool/ptool.py index cbf8f8f..4acea75 100755 --- a/qcom_ptool/ptool.py +++ b/qcom_ptool/ptool.py @@ -1004,9 +1004,7 @@ def CreateGPTPartitionTable(PhysicalPartitionNumber, UserProvided=False): % (FirstLBA, LastLBA, LastLBA - FirstLBA + 1) ) - # Attributes Attributes = 0x0 - # import pdb; pdb.set_trace() if PhyPartition[k][j]["readonly"] == "true": Attributes |= 1 << 60 ## Bit 60 is read only @@ -1020,6 +1018,13 @@ def CreateGPTPartitionTable(PhysicalPartitionNumber, UserProvided=False): Attributes |= PhyPartition[k][j]["tries_remaining"] << 52 if PhyPartition[k][j]["priority"] > 0: Attributes |= PhyPartition[k][j]["priority"] << 48 + # qbootctl A/B slot flags (qbootctl gpt-utils.h) + if PhyPartition[k][j]["active"] == "true": + Attributes |= 1 << 50 + if PhyPartition[k][j]["successful"] == "true": + Attributes |= 1 << 54 + if PhyPartition[k][j]["unbootable"] == "true": + Attributes |= 1 << 55 print("Attributes\t\t0x%X" % Attributes) @@ -2002,6 +2007,9 @@ def ParseXML(XMLFile): Partition["readbackverify"] = "false" Partition["tries_remaining"] = 0 Partition["priority"] = 0 + Partition["active"] = "false" + Partition["successful"] = "false" + Partition["unbootable"] = "false" ##import pdb; pdb.set_trace()