assembler/qemu: support for GPT partition UUIDs

The GUID Partition Table (GPT) layout supports assigning UUIDs for
individual partitions. Add support for specifying those in the
partition description.
This commit is contained in:
Christian Kellner 2020-04-01 12:19:16 +02:00 committed by msehnout
parent c33e745252
commit d906b26372

View file

@ -85,6 +85,10 @@ STAGE_OPTS = """
"description": "The partition type (UUID or identifier)", "description": "The partition type (UUID or identifier)",
"type": "string" "type": "string"
}, },
"uuid": {
"description": "UUID of the partition (GPT)",
"type": "string"
},
"filesystem": { "filesystem": {
"description": "Description of the filesystem", "description": "Description of the filesystem",
"type": "object", "type": "object",
@ -195,6 +199,7 @@ class Filesystem:
maker(device, self.uuid, self.label) maker(device, self.uuid, self.label)
# pylint: disable=too-many-instance-attributes
class Partition: class Partition:
def __init__(self, def __init__(self,
pttype: str = None, pttype: str = None,
@ -202,12 +207,14 @@ class Partition:
size: int = None, size: int = None,
bootable: bool = False, bootable: bool = False,
name: str = None, name: str = None,
uuid: str = None,
filesystem: Filesystem = None): filesystem: Filesystem = None):
self.type = pttype self.type = pttype
self.start = start self.start = start
self.size = size self.size = size
self.bootable = bootable self.bootable = bootable
self.name = name self.name = name
self.uuid = uuid
self.filesystem = filesystem self.filesystem = filesystem
self.index = None self.index = None
@ -295,7 +302,7 @@ class PartitionTable:
command = f"label: {self.label}\nlabel-id: {self.uuid}" command = f"label: {self.label}\nlabel-id: {self.uuid}"
for partition in self.partitions: for partition in self.partitions:
fields = [] fields = []
for field in ["start", "size", "type", "name"]: for field in ["start", "size", "type", "name", "uuid"]:
value = getattr(partition, field) value = getattr(partition, field)
if value: if value:
fields += [f'{field}="{value}"'] fields += [f'{field}="{value}"']
@ -338,7 +345,8 @@ def partition_from_json(js) -> Partition:
start=js.get("start"), start=js.get("start"),
size=js.get("size"), size=js.get("size"),
bootable=js.get("bootable"), bootable=js.get("bootable"),
name=js.get("name")) name=js.get("name"),
uuid=js.get("uuid"))
fs = js.get("filesystem") fs = js.get("filesystem")
if fs: if fs:
p.filesystem = filesystem_from_json(fs) p.filesystem = filesystem_from_json(fs)