summaryrefslogtreecommitdiffstats
path: root/scripts/lib
diff options
context:
space:
mode:
authorEd Bartosh <ed.bartosh@linux.intel.com>2017-02-10 12:10:22 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-02-15 20:06:45 -0800
commitd5f42cad0ce148aa55c09ce5369202736d6dd639 (patch)
tree9bf41eeaa2c5de6ea412108904fee1a7289197b3 /scripts/lib
parent77dc8e6ef3f51c6de0a4086cf4dedd454099ff35 (diff)
downloadpoky-d5f42cad0ce148aa55c09ce5369202736d6dd639.tar.gz
wic: direct: add 'realnum' attribute to partition
Replaced call of _get_part_num method with an attribute. This eliminates the need to call the method and loop over partitions every time we need to know realnum for partition. (From OE-Core rev: 96a26b6ddf22346dafa06b00816579439e98445f) Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py46
1 files changed, 20 insertions, 26 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index d0a1cad43b..ffe6c8406d 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -74,6 +74,19 @@ class DirectPlugin(ImagerPlugin):
74 self.ptable_format = self.ks.bootloader.ptable 74 self.ptable_format = self.ks.bootloader.ptable
75 self.parts = self.ks.partitions 75 self.parts = self.ks.partitions
76 76
77 # calculate the real partition number, accounting for partitions not
78 # in the partition table and logical partitions
79 realnum = 0
80 for part in self.parts:
81 if part.no_table:
82 part.realnum = 0
83 else:
84 realnum += 1
85 if self.ptable_format == 'msdos' and realnum > 3:
86 part.realnum = realnum + 1
87 continue
88 part.realnum = realnum
89
77 def do_create(self): 90 def do_create(self):
78 """ 91 """
79 Plugin entry point. 92 Plugin entry point.
@@ -86,22 +99,6 @@ class DirectPlugin(ImagerPlugin):
86 finally: 99 finally:
87 self.cleanup() 100 self.cleanup()
88 101
89 def _get_part_num(self, num, parts):
90 """calculate the real partition number, accounting for partitions not
91 in the partition table and logical partitions
92 """
93 realnum = 0
94 for pnum, part in enumerate(parts, 1):
95 if not part.no_table:
96 realnum += 1
97 if pnum == num:
98 if part.no_table:
99 return 0
100 if self.ptable_format == 'msdos' and realnum > 3:
101 # account for logical partition numbering, ex. sda5..
102 return realnum + 1
103 return realnum
104
105 def _write_fstab(self, image_rootfs): 102 def _write_fstab(self, image_rootfs):
106 """overriden to generate fstab (temporarily) in rootfs. This is called 103 """overriden to generate fstab (temporarily) in rootfs. This is called
107 from _create, make sure it doesn't get called from 104 from _create, make sure it doesn't get called from
@@ -128,15 +125,14 @@ class DirectPlugin(ImagerPlugin):
128 def _update_fstab(self, fstab_lines, parts): 125 def _update_fstab(self, fstab_lines, parts):
129 """Assume partition order same as in wks""" 126 """Assume partition order same as in wks"""
130 updated = False 127 updated = False
131 for num, part in enumerate(parts, 1): 128 for part in parts:
132 pnum = self._get_part_num(num, parts) 129 if not part.realnum or not part.mountpoint \
133 if not pnum or not part.mountpoint \
134 or part.mountpoint in ("/", "/boot"): 130 or part.mountpoint in ("/", "/boot"):
135 continue 131 continue
136 132
137 # mmc device partitions are named mmcblk0p1, mmcblk0p2.. 133 # mmc device partitions are named mmcblk0p1, mmcblk0p2..
138 prefix = 'p' if part.disk.startswith('mmcblk') else '' 134 prefix = 'p' if part.disk.startswith('mmcblk') else ''
139 device_name = "/dev/%s%s%d" % (part.disk, prefix, pnum) 135 device_name = "/dev/%s%s%d" % (part.disk, prefix, part.realnum)
140 136
141 opts = part.fsopts if part.fsopts else "defaults" 137 opts = part.fsopts if part.fsopts else "defaults"
142 line = "\t".join([device_name, part.mountpoint, part.fstype, 138 line = "\t".join([device_name, part.mountpoint, part.fstype,
@@ -164,7 +160,7 @@ class DirectPlugin(ImagerPlugin):
164 self._image = PartitionedImage(image_path, self.ptable_format, 160 self._image = PartitionedImage(image_path, self.ptable_format,
165 self.native_sysroot) 161 self.native_sysroot)
166 162
167 for num, part in enumerate(self.parts, 1): 163 for part in self.parts:
168 # as a convenience, set source to the boot partition source 164 # as a convenience, set source to the boot partition source
169 # instead of forcing it to be set via bootloader --source 165 # instead of forcing it to be set via bootloader --source
170 if not self.ks.bootloader.source and part.mountpoint == "/boot": 166 if not self.ks.bootloader.source and part.mountpoint == "/boot":
@@ -175,8 +171,7 @@ class DirectPlugin(ImagerPlugin):
175 if self.ptable_format == 'gpt': 171 if self.ptable_format == 'gpt':
176 part.uuid = str(uuid.uuid4()) 172 part.uuid = str(uuid.uuid4())
177 else: # msdos partition table 173 else: # msdos partition table
178 part.uuid = '%0x-%02d' % (self._image.identifier, 174 part.uuid = '%0x-%02d' % (self._image.identifier, part.realnum)
179 self._get_part_num(num, self.parts))
180 175
181 fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) 176 fstab_path = self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
182 177
@@ -277,14 +272,13 @@ class DirectPlugin(ImagerPlugin):
277 272
278 Assume partition order same as in wks 273 Assume partition order same as in wks
279 """ 274 """
280 for num, part in enumerate(self.parts, 1): 275 for part in self.parts:
281 if part.mountpoint == "/": 276 if part.mountpoint == "/":
282 if part.uuid: 277 if part.uuid:
283 return "PARTUUID=%s" % part.uuid 278 return "PARTUUID=%s" % part.uuid
284 else: 279 else:
285 suffix = 'p' if part.disk.startswith('mmcblk') else '' 280 suffix = 'p' if part.disk.startswith('mmcblk') else ''
286 pnum = self._get_part_num(num, self.parts) 281 return "/dev/%s%s%-d" % (part.disk, suffix, part.realnum)
287 return "/dev/%s%s%-d" % (part.disk, suffix, pnum)
288 282
289 def cleanup(self): 283 def cleanup(self):
290 if self._image: 284 if self._image: