summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/imager/direct.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/plugins/imager/direct.py')
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py61
1 files changed, 33 insertions, 28 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py
index 55db826e93..ea709e8c54 100644
--- a/scripts/lib/wic/plugins/imager/direct.py
+++ b/scripts/lib/wic/plugins/imager/direct.py
@@ -54,15 +54,16 @@ class DirectPlugin(ImagerPlugin):
54 self.native_sysroot = native_sysroot 54 self.native_sysroot = native_sysroot
55 self.oe_builddir = oe_builddir 55 self.oe_builddir = oe_builddir
56 56
57 self.debug = options.debug
57 self.outdir = options.outdir 58 self.outdir = options.outdir
58 self.compressor = options.compressor 59 self.compressor = options.compressor
59 self.bmap = options.bmap 60 self.bmap = options.bmap
60 self.no_fstab_update = options.no_fstab_update 61 self.no_fstab_update = options.no_fstab_update
61 self.original_fstab = None 62 self.updated_fstab_path = None
62 63
63 self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0], 64 self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0],
64 strftime("%Y%m%d%H%M")) 65 strftime("%Y%m%d%H%M"))
65 self.workdir = tempfile.mkdtemp(dir=self.outdir, prefix='tmp.wic.') 66 self.workdir = self.setup_workdir(options.workdir)
66 self._image = None 67 self._image = None
67 self.ptable_format = self.ks.bootloader.ptable 68 self.ptable_format = self.ks.bootloader.ptable
68 self.parts = self.ks.partitions 69 self.parts = self.ks.partitions
@@ -78,6 +79,16 @@ class DirectPlugin(ImagerPlugin):
78 self._image = PartitionedImage(image_path, self.ptable_format, 79 self._image = PartitionedImage(image_path, self.ptable_format,
79 self.parts, self.native_sysroot) 80 self.parts, self.native_sysroot)
80 81
82 def setup_workdir(self, workdir):
83 if workdir:
84 if os.path.exists(workdir):
85 raise WicError("Internal workdir '%s' specified in wic arguments already exists!" % (workdir))
86
87 os.makedirs(workdir)
88 return workdir
89 else:
90 return tempfile.mkdtemp(dir=self.outdir, prefix='tmp.wic.')
91
81 def do_create(self): 92 def do_create(self):
82 """ 93 """
83 Plugin entry point. 94 Plugin entry point.
@@ -90,11 +101,8 @@ class DirectPlugin(ImagerPlugin):
90 finally: 101 finally:
91 self.cleanup() 102 self.cleanup()
92 103
93 def _write_fstab(self, image_rootfs): 104 def update_fstab(self, image_rootfs):
94 """overriden to generate fstab (temporarily) in rootfs. This is called 105 """Assume partition order same as in wks"""
95 from _create, make sure it doesn't get called from
96 BaseImage.create()
97 """
98 if not image_rootfs: 106 if not image_rootfs:
99 return 107 return
100 108
@@ -104,18 +112,9 @@ class DirectPlugin(ImagerPlugin):
104 112
105 with open(fstab_path) as fstab: 113 with open(fstab_path) as fstab:
106 fstab_lines = fstab.readlines() 114 fstab_lines = fstab.readlines()
107 self.original_fstab = fstab_lines.copy()
108
109 if self._update_fstab(fstab_lines, self.parts):
110 with open(fstab_path, "w") as fstab:
111 fstab.writelines(fstab_lines)
112 else:
113 self.original_fstab = None
114 115
115 def _update_fstab(self, fstab_lines, parts):
116 """Assume partition order same as in wks"""
117 updated = False 116 updated = False
118 for part in parts: 117 for part in self.parts:
119 if not part.realnum or not part.mountpoint \ 118 if not part.realnum or not part.mountpoint \
120 or part.mountpoint == "/": 119 or part.mountpoint == "/":
121 continue 120 continue
@@ -144,7 +143,10 @@ class DirectPlugin(ImagerPlugin):
144 fstab_lines.append(line) 143 fstab_lines.append(line)
145 updated = True 144 updated = True
146 145
147 return updated 146 if updated:
147 self.updated_fstab_path = os.path.join(self.workdir, "fstab")
148 with open(self.updated_fstab_path, "w") as f:
149 f.writelines(fstab_lines)
148 150
149 def _full_path(self, path, name, extention): 151 def _full_path(self, path, name, extention):
150 """ Construct full file path to a file we generate. """ 152 """ Construct full file path to a file we generate. """
@@ -160,7 +162,7 @@ class DirectPlugin(ImagerPlugin):
160 a partitioned image. 162 a partitioned image.
161 """ 163 """
162 if not self.no_fstab_update: 164 if not self.no_fstab_update:
163 self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) 165 self.update_fstab(self.rootfs_dir.get("ROOTFS_DIR"))
164 166
165 for part in self.parts: 167 for part in self.parts:
166 # get rootfs size from bitbake variable if it's not set in .ks file 168 # get rootfs size from bitbake variable if it's not set in .ks file
@@ -273,14 +275,9 @@ class DirectPlugin(ImagerPlugin):
273 if os.path.isfile(path): 275 if os.path.isfile(path):
274 shutil.move(path, os.path.join(self.outdir, fname)) 276 shutil.move(path, os.path.join(self.outdir, fname))
275 277
276 #Restore original fstab 278 # remove work directory when it is not in debugging mode
277 if self.original_fstab: 279 if not self.debug:
278 fstab_path = self.rootfs_dir.get("ROOTFS_DIR") + "/etc/fstab" 280 shutil.rmtree(self.workdir, ignore_errors=True)
279 with open(fstab_path, "w") as fstab:
280 fstab.writelines(self.original_fstab)
281
282 # remove work directory
283 shutil.rmtree(self.workdir, ignore_errors=True)
284 281
285# Overhead of the MBR partitioning scheme (just one sector) 282# Overhead of the MBR partitioning scheme (just one sector)
286MBR_OVERHEAD = 1 283MBR_OVERHEAD = 1
@@ -343,6 +340,13 @@ class PartitionedImage():
343 part.fsuuid = '0x' + str(uuid.uuid4())[:8].upper() 340 part.fsuuid = '0x' + str(uuid.uuid4())[:8].upper()
344 else: 341 else:
345 part.fsuuid = str(uuid.uuid4()) 342 part.fsuuid = str(uuid.uuid4())
343 else:
344 #make sure the fsuuid for vfat/msdos align with format 0xYYYYYYYY
345 if part.fstype == 'vfat' or part.fstype == 'msdos':
346 if part.fsuuid.upper().startswith("0X"):
347 part.fsuuid = '0x' + part.fsuuid.upper()[2:].rjust(8,"0")
348 else:
349 part.fsuuid = '0x' + part.fsuuid.upper().rjust(8,"0")
346 350
347 def prepare(self, imager): 351 def prepare(self, imager):
348 """Prepare an image. Call prepare method of all image partitions.""" 352 """Prepare an image. Call prepare method of all image partitions."""
@@ -351,7 +355,8 @@ class PartitionedImage():
351 # sizes before we can add them and do the layout. 355 # sizes before we can add them and do the layout.
352 part.prepare(imager, imager.workdir, imager.oe_builddir, 356 part.prepare(imager, imager.workdir, imager.oe_builddir,
353 imager.rootfs_dir, imager.bootimg_dir, 357 imager.rootfs_dir, imager.bootimg_dir,
354 imager.kernel_dir, imager.native_sysroot) 358 imager.kernel_dir, imager.native_sysroot,
359 imager.updated_fstab_path)
355 360
356 # Converting kB to sectors for parted 361 # Converting kB to sectors for parted
357 part.size_sec = part.disk_size * 1024 // self.sector_size 362 part.size_sec = part.disk_size * 1024 // self.sector_size