diff options
Diffstat (limited to 'scripts/lib/wic/plugins/imager')
| -rw-r--r-- | scripts/lib/wic/plugins/imager/direct.py | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/scripts/lib/wic/plugins/imager/direct.py b/scripts/lib/wic/plugins/imager/direct.py index f107e60089..7e1c1c03ab 100644 --- a/scripts/lib/wic/plugins/imager/direct.py +++ b/scripts/lib/wic/plugins/imager/direct.py | |||
| @@ -58,7 +58,7 @@ class DirectPlugin(ImagerPlugin): | |||
| 58 | self.compressor = options.compressor | 58 | self.compressor = options.compressor |
| 59 | self.bmap = options.bmap | 59 | self.bmap = options.bmap |
| 60 | self.no_fstab_update = options.no_fstab_update | 60 | self.no_fstab_update = options.no_fstab_update |
| 61 | self.original_fstab = None | 61 | self.updated_fstab_path = None |
| 62 | 62 | ||
| 63 | self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0], | 63 | self.name = "%s-%s" % (os.path.splitext(os.path.basename(wks_file))[0], |
| 64 | strftime("%Y%m%d%H%M")) | 64 | strftime("%Y%m%d%H%M")) |
| @@ -100,11 +100,8 @@ class DirectPlugin(ImagerPlugin): | |||
| 100 | finally: | 100 | finally: |
| 101 | self.cleanup() | 101 | self.cleanup() |
| 102 | 102 | ||
| 103 | def _write_fstab(self, image_rootfs): | 103 | def update_fstab(self, image_rootfs): |
| 104 | """overriden to generate fstab (temporarily) in rootfs. This is called | 104 | """Assume partition order same as in wks""" |
| 105 | from _create, make sure it doesn't get called from | ||
| 106 | BaseImage.create() | ||
| 107 | """ | ||
| 108 | if not image_rootfs: | 105 | if not image_rootfs: |
| 109 | return | 106 | return |
| 110 | 107 | ||
| @@ -114,18 +111,9 @@ class DirectPlugin(ImagerPlugin): | |||
| 114 | 111 | ||
| 115 | with open(fstab_path) as fstab: | 112 | with open(fstab_path) as fstab: |
| 116 | fstab_lines = fstab.readlines() | 113 | fstab_lines = fstab.readlines() |
| 117 | self.original_fstab = fstab_lines.copy() | ||
| 118 | |||
| 119 | if self._update_fstab(fstab_lines, self.parts): | ||
| 120 | with open(fstab_path, "w") as fstab: | ||
| 121 | fstab.writelines(fstab_lines) | ||
| 122 | else: | ||
| 123 | self.original_fstab = None | ||
| 124 | 114 | ||
| 125 | def _update_fstab(self, fstab_lines, parts): | ||
| 126 | """Assume partition order same as in wks""" | ||
| 127 | updated = False | 115 | updated = False |
| 128 | for part in parts: | 116 | for part in self.parts: |
| 129 | if not part.realnum or not part.mountpoint \ | 117 | if not part.realnum or not part.mountpoint \ |
| 130 | or part.mountpoint == "/": | 118 | or part.mountpoint == "/": |
| 131 | continue | 119 | continue |
| @@ -154,7 +142,10 @@ class DirectPlugin(ImagerPlugin): | |||
| 154 | fstab_lines.append(line) | 142 | fstab_lines.append(line) |
| 155 | updated = True | 143 | updated = True |
| 156 | 144 | ||
| 157 | return updated | 145 | if updated: |
| 146 | self.updated_fstab_path = os.path.join(self.workdir, "fstab") | ||
| 147 | with open(self.updated_fstab_path, "w") as f: | ||
| 148 | f.writelines(fstab_lines) | ||
| 158 | 149 | ||
| 159 | def _full_path(self, path, name, extention): | 150 | def _full_path(self, path, name, extention): |
| 160 | """ Construct full file path to a file we generate. """ | 151 | """ Construct full file path to a file we generate. """ |
| @@ -170,7 +161,7 @@ class DirectPlugin(ImagerPlugin): | |||
| 170 | a partitioned image. | 161 | a partitioned image. |
| 171 | """ | 162 | """ |
| 172 | if not self.no_fstab_update: | 163 | if not self.no_fstab_update: |
| 173 | self._write_fstab(self.rootfs_dir.get("ROOTFS_DIR")) | 164 | self.update_fstab(self.rootfs_dir.get("ROOTFS_DIR")) |
| 174 | 165 | ||
| 175 | for part in self.parts: | 166 | for part in self.parts: |
| 176 | # get rootfs size from bitbake variable if it's not set in .ks file | 167 | # get rootfs size from bitbake variable if it's not set in .ks file |
| @@ -283,12 +274,6 @@ class DirectPlugin(ImagerPlugin): | |||
| 283 | if os.path.isfile(path): | 274 | if os.path.isfile(path): |
| 284 | shutil.move(path, os.path.join(self.outdir, fname)) | 275 | shutil.move(path, os.path.join(self.outdir, fname)) |
| 285 | 276 | ||
| 286 | #Restore original fstab | ||
| 287 | if self.original_fstab: | ||
| 288 | fstab_path = self.rootfs_dir.get("ROOTFS_DIR") + "/etc/fstab" | ||
| 289 | with open(fstab_path, "w") as fstab: | ||
| 290 | fstab.writelines(self.original_fstab) | ||
| 291 | |||
| 292 | # remove work directory | 277 | # remove work directory |
| 293 | shutil.rmtree(self.workdir, ignore_errors=True) | 278 | shutil.rmtree(self.workdir, ignore_errors=True) |
| 294 | 279 | ||
| @@ -368,7 +353,8 @@ class PartitionedImage(): | |||
| 368 | # sizes before we can add them and do the layout. | 353 | # sizes before we can add them and do the layout. |
| 369 | part.prepare(imager, imager.workdir, imager.oe_builddir, | 354 | part.prepare(imager, imager.workdir, imager.oe_builddir, |
| 370 | imager.rootfs_dir, imager.bootimg_dir, | 355 | imager.rootfs_dir, imager.bootimg_dir, |
| 371 | imager.kernel_dir, imager.native_sysroot) | 356 | imager.kernel_dir, imager.native_sysroot, |
| 357 | imager.updated_fstab_path) | ||
| 372 | 358 | ||
| 373 | # Converting kB to sectors for parted | 359 | # Converting kB to sectors for parted |
| 374 | part.size_sec = part.disk_size * 1024 // self.sector_size | 360 | part.size_sec = part.disk_size * 1024 // self.sector_size |
