summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/plugins')
-rw-r--r--scripts/lib/wic/plugins/imager/direct.py36
-rw-r--r--scripts/lib/wic/plugins/source/rootfs.py17
2 files changed, 25 insertions, 28 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
diff --git a/scripts/lib/wic/plugins/source/rootfs.py b/scripts/lib/wic/plugins/source/rootfs.py
index afb1eb9202..6fd415af5b 100644
--- a/scripts/lib/wic/plugins/source/rootfs.py
+++ b/scripts/lib/wic/plugins/source/rootfs.py
@@ -103,9 +103,9 @@ class RootfsPlugin(SourcePlugin):
103 new_rootfs = None 103 new_rootfs = None
104 new_pseudo = None 104 new_pseudo = None
105 # Handle excluded paths. 105 # Handle excluded paths.
106 if part.exclude_path or part.include_path or part.change_directory: 106 if part.exclude_path or part.include_path or part.change_directory or part.updated_fstab_path:
107 # We need a new rootfs directory we can delete files from. Copy to 107 # We need a new rootfs directory we can safely modify without
108 # workdir. 108 # interfering with other tasks. Copy to workdir.
109 new_rootfs = os.path.realpath(os.path.join(cr_workdir, "rootfs%d" % part.lineno)) 109 new_rootfs = os.path.realpath(os.path.join(cr_workdir, "rootfs%d" % part.lineno))
110 110
111 if os.path.lexists(new_rootfs): 111 if os.path.lexists(new_rootfs):
@@ -214,6 +214,17 @@ class RootfsPlugin(SourcePlugin):
214 rm_cmd = "rm -rf %s" % (full_path) 214 rm_cmd = "rm -rf %s" % (full_path)
215 exec_native_cmd(rm_cmd, native_sysroot, pseudo) 215 exec_native_cmd(rm_cmd, native_sysroot, pseudo)
216 216
217 has_fstab = os.path.exists(os.path.join(new_rootfs, "etc/fstab"))
218 if part.updated_fstab_path and has_fstab:
219 fstab_path = os.path.join(new_rootfs, "etc/fstab")
220 # Assume that fstab should always be owned by root with fixed permissions
221 install_cmd = "install -m 0644 %s %s" % (part.updated_fstab_path, fstab_path)
222 if new_pseudo:
223 pseudo = cls.__get_pseudo(native_sysroot, new_rootfs, new_pseudo)
224 else:
225 pseudo = None
226 exec_native_cmd(install_cmd, native_sysroot, pseudo)
227
217 part.prepare_rootfs(cr_workdir, oe_builddir, 228 part.prepare_rootfs(cr_workdir, oe_builddir,
218 new_rootfs or part.rootfs_dir, native_sysroot, 229 new_rootfs or part.rootfs_dir, native_sysroot,
219 pseudo_dir = new_pseudo or pseudo_dir) 230 pseudo_dir = new_pseudo or pseudo_dir)