@@ -9,7 +9,7 @@ import sys
99import subprocess
1010
1111
12- VERSION = "2.1 .0"
12+ VERSION = "2.2 .0"
1313
1414
1515IMAGE_KEYS = {"IGconf_device_class" ,
@@ -44,9 +44,7 @@ top_template = {
4444
4545partition_template = {
4646 "name" : "default" ,
47- "partition-type" : None ,
48- "in-partition-table" : "false" ,
49- "fstab" : {}
47+ "in-partition-table" : "true" ,
5048}
5149
5250
@@ -291,8 +289,10 @@ def parse_genimage_config(config_path):
291289 if "image" in pattr :
292290 piname = pattr ["image" ]
293291 if piname in images :
294- # Found. Merge
295- partitions [pname ] = {** images [piname ], ** pattr }
292+ # Found. Merge, initialising from template
293+ base = copy .deepcopy (partition_template )
294+ base ["name" ] = pname
295+ partitions [pname ] = {** base , ** images [piname ], ** pattr }
296296
297297 # Tag image type
298298 for t in gtypes :
@@ -335,6 +335,38 @@ def parse_genimage_config(config_path):
335335 for p in ptable ["partitiontable" ]["partitions" ]:
336336 p .pop ("node" , None )
337337
338+ # Populate genimage partition entries with GPT attributes
339+ def insert_gptattr (genimage_partitions , table_json ):
340+ try :
341+ label = table_json .get ("partitiontable" , {}).get ("label" , "" ).lower ()
342+ except Exception :
343+ label = ""
344+ if label != "gpt" :
345+ return genimage_partitions
346+
347+ disk_parts = table_json .get ("partitiontable" , {}).get ("partitions" , [])
348+
349+ # Relies on ordering: genimage partitions are emitted in config order
350+ # and sfdisk JSON lists partitions in on-disk order. In this flow they
351+ # correspond positionally (1-1) provided in-partition-table != false.
352+ idx = 0
353+ for _pname , pdata in genimage_partitions .items ():
354+ if idx >= len (disk_parts ):
355+ break
356+ # Only populate partitions that are indicated as present by genimage
357+ if str (pdata .get ("in-partition-table" , "true" )).lower () != "false" :
358+ gpt_name = disk_parts [idx ].get ("name" )
359+ if gpt_name :
360+ pdata ["partition-label" ] = gpt_name
361+ gpt_uuid = disk_parts [idx ].get ("uuid" )
362+ if gpt_uuid :
363+ pdata ["partition-uuid" ] = gpt_uuid
364+ idx += 1
365+
366+ return genimage_partitions
367+
368+ partitions = insert_gptattr (partitions , ptable )
369+
338370 return (disk_attr , partitions , ptable )
339371
340372
0 commit comments