From 1a86bc0ae48a4aef26e1273b2760193a547a4495 Mon Sep 17 00:00:00 2001 From: Marek Szyprowski Date: Thu, 28 Mar 2024 20:23:46 +0100 Subject: [PATCH] tizen: sd_fusing.py: add support for partition start & size specified in sectors Add support for specifying partition's start & size in sectors and adjust lba-start parameter (first allowed sector of the first partition) to 34, what is the minimal possible value for the GPT layout. This doesn't affect any start or size of the partitions specified in MBytes, because according to sfdisk manual, they are always aligned to 1MB. Signed-off-by: Marek Szyprowski Change-Id: I8fdccb896072a9cddfe7e185f6650eb0471caae2 --- sd_fusing.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/sd_fusing.py b/sd_fusing.py index 5c8b47b..ceecb0c 100755 --- a/sd_fusing.py +++ b/sd_fusing.py @@ -60,14 +60,30 @@ class Partition: def __init__(self, name, size, start=None, ptype=None, fstype="raw", bootable=False, **kwargs): self.name = name self.size = size + self.size_sectors = kwargs.get("size_sectors", None) self.start = start + self.start_sector = kwargs.get("start_sector", None) self.ptype = ptype self.bootable = bootable + if type(self.size_sectors) == int and self.size_sectors >= 0: + if type(self.size) == int and self.size >= 0: + logging.warning(f"partition:{name} overriding size to the value obtained from size_sectors") + # size is used to calculate free space, so adjust it here + self.size = (self.size_sectors * 512 - 1) / (1024*1024) + 1 + if type(self.start_sector) == int and self.start_sector >= 0: + if type(self.start) == int and self.start >= 0: + logging.warning(f"partition:{name} overriding start to the value obtained from start_sector") + self.size = None + def __str__(self): output = [] - if self.start: + if self.start_sector: + output.append(f"start={self.start_sector}") + elif self.start: output.append(f"start={self.start}MiB") - if type(self.size) == int and self.size >= 0: + if type(self.size_sectors) == int and self.size_sectors >= 0: + output.append(f"size={self.size_sectors}") + elif type(self.size) == int and self.size >= 0: output.append(f"size={self.size}MiB") if self.name: output.append(f"name={self.name}") @@ -89,6 +105,8 @@ class Label: self.part_table.append(Partition(**part)) def __str__(self): output = f"label: {self.ltype}\n" + if self.ltype == 'gpt': + output += f"first-lba: 34\n" for part in self.part_table: output += str(part) return output -- 2.34.1