Merge pull request #524 from bongbui321/improve_getactiveslot

Improve `getactiveslot` command
This commit is contained in:
Bjoern Kerler 2024-03-29 10:46:22 +01:00 committed by GitHub
commit 81d30c9039
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -643,18 +643,22 @@ class firehose_client(metaclass=LogBase):
else:
return self.firehose.cmd_setbootablestoragedrive(int(options["<lun>"]))
elif cmd == "getactiveslot":
res = self.firehose.detect_partition(options, "boot_a")
res = self.firehose.detect_partition(options, "boot_a", send_full=True)
if res[0]:
lun = res[1]
partition = res[2]
prim_guid_gpt = res[3]
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
partition = backup_guid_gpt.partentries["boot_a"]
active = ((partition.flags >> (AB_FLAG_OFFSET*8))&0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
if active:
self.printer("Current active slot: a")
return True
res = self.firehose.detect_partition(options, "boot_b")
res = self.firehose.detect_partition(options, "boot_b", send_full=True)
if res[0]:
lun = res[1]
partition = res[2]
prim_guid_gpt = res[3]
_, backup_guid_gpt = self.firehose.get_gpt(lun, 0, 0, 0, prim_guid_gpt.header.backup_lba)
partition = backup_guid_gpt.partentries["boot_b"]
active = ((partition.flags >> (AB_FLAG_OFFSET*8))&0xFF) & AB_PARTITION_ATTR_SLOT_ACTIVE == AB_PARTITION_ATTR_SLOT_ACTIVE
if active:
self.printer("Current active slot: b")