Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions qcom_ptool/loaders/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ def disk_options(argv: list[tuple[str, str]]) -> DiskParams:
return disk


def to_bool(arg: str) -> str:
return "true" if arg.strip().lower() in ("1", "y", "yes", "true") else "false"


def partition_options(
argv: list[tuple[str, str]],
image_map: Mapping[str, str] | None = None,
Expand All @@ -98,6 +102,12 @@ def partition_options(
image_map = {}
entry: PartitionEntry = PARTITION_ENTRY_DEFAULTS.copy()
phys_part: str = "0"
# Intentional: --attributes first so a named flag always wins.
for opt, arg in argv:
if opt == "--attributes":
attribute_bits = int(arg, 16)
entry["bootable"] = "true" if attribute_bits & (1 << 2) else "false"
entry["readonly"] = "true" if attribute_bits & (1 << 60) else "false"
for opt, arg in argv:
if opt in ("--lun", "--phys-part"):
phys_part = arg
Expand All @@ -107,14 +117,24 @@ def partition_options(
entry["size_in_kb"] = str(partition_size_in_kb(arg))
elif opt == "--type-guid":
entry["type"] = arg
elif opt == "--attributes":
attribute_bits = int(arg, 16)
entry["bootable"] = "true" if attribute_bits & (1 << 2) else "false"
entry["readonly"] = "true" if attribute_bits & (1 << 60) else "false"
elif opt == "--bootable":
entry["bootable"] = to_bool(arg)
elif opt == "--readonly":
entry["readonly"] = to_bool(arg)
elif opt == "--priority":
entry["priority"] = str(int(arg) & 0x03)
elif opt == "--tries-remaining":
entry["triesremaining"] = str(int(arg) & 0x07)
elif opt == "--active":
entry["active"] = to_bool(arg)
elif opt == "--successful":
entry["successful"] = to_bool(arg)
elif opt == "--unbootable":
entry["unbootable"] = to_bool(arg)
elif opt == "--filename":
entry["filename"] = arg
elif opt == "--sparse":
entry["sparse"] = arg
entry["sparse"] = to_bool(arg)
if entry["label"] in image_map:
entry["filename"] = image_map[entry["label"]]
return phys_part, entry
Expand Down Expand Up @@ -142,6 +162,13 @@ def partition_options(
"type-guid=",
"filename=",
"attributes=",
"bootable=",
"readonly=",
"priority=",
"tries-remaining=",
"active=",
"successful=",
"unbootable=",
"sparse=",
]

Expand Down
12 changes: 10 additions & 2 deletions qcom_ptool/ptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,9 +1003,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
Expand All @@ -1020,6 +1018,13 @@ def CreateGPTPartitionTable(PhysicalPartitionNumber, UserProvided=False):
Attributes |= PhyPartition[k][j]["tries_remaining"] << 51
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)

Expand Down Expand Up @@ -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()

Expand Down
6 changes: 5 additions & 1 deletion qcom_ptool/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
DiskParams = dict[str, str]

# Parsed ``--partition`` line normalised for the XML attribute set.
# Expected keys: label, size_in_kb, type, bootable, readonly, filename, sparse.
# Expected keys: label, size_in_kb, type, bootable, readonly, filename, sparse,
# active, successful, unbootable.
# See PARTITION_ENTRY_DEFAULTS for the canonical set.
PartitionEntry = dict[str, str]

Expand Down Expand Up @@ -63,6 +64,9 @@
"readonly": "true",
"filename": "",
"sparse": "false",
"active": "false",
"successful": "false",
"unbootable": "false",
}


Expand Down
Loading
Loading