diff options
| -rw-r--r-- | scripts/lib/mic/imager/direct.py | 18 | ||||
| -rw-r--r-- | scripts/lib/mic/plugins/imager/direct_plugin.py | 17 | ||||
| -rw-r--r-- | scripts/lib/mic/plugins/source/rootfs.py | 18 | ||||
| -rwxr-xr-x | scripts/wic | 40 |
4 files changed, 79 insertions, 14 deletions
diff --git a/scripts/lib/mic/imager/direct.py b/scripts/lib/mic/imager/direct.py index ac63c38903..2cf4c8de95 100644 --- a/scripts/lib/mic/imager/direct.py +++ b/scripts/lib/mic/imager/direct.py | |||
| @@ -84,17 +84,19 @@ class DirectImageCreator(BaseImageCreator): | |||
| 84 | self.hdddir = hdddir | 84 | self.hdddir = hdddir |
| 85 | self.staging_data_dir = staging_data_dir | 85 | self.staging_data_dir = staging_data_dir |
| 86 | 86 | ||
| 87 | def __write_fstab(self): | 87 | def __write_fstab(self, image_rootfs): |
| 88 | """overriden to generate fstab (temporarily) in rootfs. This | 88 | """overriden to generate fstab (temporarily) in rootfs. This |
| 89 | is called from mount_instroot, make sure it doesn't get called | 89 | is called from mount_instroot, make sure it doesn't get called |
| 90 | from BaseImage.mount()""" | 90 | from BaseImage.mount()""" |
| 91 | if image_rootfs is None: | ||
| 92 | return None | ||
| 91 | 93 | ||
| 92 | image_rootfs = self.rootfs_dir | 94 | fstab = image_rootfs + "/etc/fstab" |
| 95 | if not os.path.isfile(fstab): | ||
| 96 | return None | ||
| 93 | 97 | ||
| 94 | parts = self._get_parts() | 98 | parts = self._get_parts() |
| 95 | 99 | ||
| 96 | fstab = image_rootfs + "/etc/fstab" | ||
| 97 | |||
| 98 | self._save_fstab(fstab) | 100 | self._save_fstab(fstab) |
| 99 | fstab_lines = self._get_fstab(fstab, parts) | 101 | fstab_lines = self._get_fstab(fstab, parts) |
| 100 | self._update_fstab(fstab_lines, parts) | 102 | self._update_fstab(fstab_lines, parts) |
| @@ -126,6 +128,8 @@ class DirectImageCreator(BaseImageCreator): | |||
| 126 | 128 | ||
| 127 | def _restore_fstab(self, fstab): | 129 | def _restore_fstab(self, fstab): |
| 128 | """Restore the saved fstab in rootfs""" | 130 | """Restore the saved fstab in rootfs""" |
| 131 | if fstab is None: | ||
| 132 | return | ||
| 129 | shutil.move(fstab + ".orig", fstab) | 133 | shutil.move(fstab + ".orig", fstab) |
| 130 | 134 | ||
| 131 | def _get_fstab(self, fstab, parts): | 135 | def _get_fstab(self, fstab, parts): |
| @@ -235,8 +239,6 @@ class DirectImageCreator(BaseImageCreator): | |||
| 235 | 239 | ||
| 236 | self.__instimage = PartitionedMount(self._instroot) | 240 | self.__instimage = PartitionedMount(self._instroot) |
| 237 | 241 | ||
| 238 | fstab = self.__write_fstab() | ||
| 239 | |||
| 240 | for p in parts: | 242 | for p in parts: |
| 241 | # as a convenience, set source to the boot partition source | 243 | # as a convenience, set source to the boot partition source |
| 242 | # instead of forcing it to be set via bootloader --source | 244 | # instead of forcing it to be set via bootloader --source |
| @@ -263,6 +265,9 @@ class DirectImageCreator(BaseImageCreator): | |||
| 263 | p.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir, | 265 | p.prepare(self, self.workdir, self.oe_builddir, self.rootfs_dir, |
| 264 | self.bootimg_dir, self.kernel_dir, self.native_sysroot) | 266 | self.bootimg_dir, self.kernel_dir, self.native_sysroot) |
| 265 | 267 | ||
| 268 | fstab = self.__write_fstab(p.get_rootfs()) | ||
| 269 | self._restore_fstab(fstab) | ||
| 270 | |||
| 266 | self.__instimage.add_partition(int(p.size), | 271 | self.__instimage.add_partition(int(p.size), |
| 267 | p.disk, | 272 | p.disk, |
| 268 | p.mountpoint, | 273 | p.mountpoint, |
| @@ -273,7 +278,6 @@ class DirectImageCreator(BaseImageCreator): | |||
| 273 | boot = p.active, | 278 | boot = p.active, |
| 274 | align = p.align, | 279 | align = p.align, |
| 275 | part_type = p.part_type) | 280 | part_type = p.part_type) |
| 276 | self._restore_fstab(fstab) | ||
| 277 | self.__instimage.layout_partitions(self._ptable_format) | 281 | self.__instimage.layout_partitions(self._ptable_format) |
| 278 | 282 | ||
| 279 | self.__imgdir = self.workdir | 283 | self.__imgdir = self.workdir |
diff --git a/scripts/lib/mic/plugins/imager/direct_plugin.py b/scripts/lib/mic/plugins/imager/direct_plugin.py index e015256fa1..fc7c10c3df 100644 --- a/scripts/lib/mic/plugins/imager/direct_plugin.py +++ b/scripts/lib/mic/plugins/imager/direct_plugin.py | |||
| @@ -43,6 +43,19 @@ class DirectPlugin(ImagerPlugin): | |||
| 43 | name = 'direct' | 43 | name = 'direct' |
| 44 | 44 | ||
| 45 | @classmethod | 45 | @classmethod |
| 46 | def __rootfs_dir_to_dict(self, rootfs_dirs): | ||
| 47 | """ | ||
| 48 | Gets a string that contain 'connection=dir' splitted by | ||
| 49 | space and return a dict | ||
| 50 | """ | ||
| 51 | krootfs_dir = {} | ||
| 52 | for rootfs_dir in rootfs_dirs.split(' '): | ||
| 53 | k, v = rootfs_dir.split('=') | ||
| 54 | krootfs_dir[k] = v | ||
| 55 | |||
| 56 | return krootfs_dir | ||
| 57 | |||
| 58 | @classmethod | ||
| 46 | def do_create(self, subcmd, opts, *args): | 59 | def do_create(self, subcmd, opts, *args): |
| 47 | """ | 60 | """ |
| 48 | Create direct image, called from creator as 'direct' cmd | 61 | Create direct image, called from creator as 'direct' cmd |
| @@ -63,11 +76,13 @@ class DirectPlugin(ImagerPlugin): | |||
| 63 | image_output_dir = args[7] | 76 | image_output_dir = args[7] |
| 64 | oe_builddir = args[8] | 77 | oe_builddir = args[8] |
| 65 | 78 | ||
| 79 | krootfs_dir = self.__rootfs_dir_to_dict(rootfs_dir) | ||
| 80 | |||
| 66 | configmgr._ksconf = ksconf | 81 | configmgr._ksconf = ksconf |
| 67 | 82 | ||
| 68 | creator = direct.DirectImageCreator(oe_builddir, | 83 | creator = direct.DirectImageCreator(oe_builddir, |
| 69 | image_output_dir, | 84 | image_output_dir, |
| 70 | rootfs_dir, | 85 | krootfs_dir, |
| 71 | bootimg_dir, | 86 | bootimg_dir, |
| 72 | kernel_dir, | 87 | kernel_dir, |
| 73 | native_sysroot, | 88 | native_sysroot, |
diff --git a/scripts/lib/mic/plugins/source/rootfs.py b/scripts/lib/mic/plugins/source/rootfs.py index 6323811183..75999e03d2 100644 --- a/scripts/lib/mic/plugins/source/rootfs.py +++ b/scripts/lib/mic/plugins/source/rootfs.py | |||
| @@ -45,14 +45,26 @@ class RootfsPlugin(SourcePlugin): | |||
| 45 | 45 | ||
| 46 | @classmethod | 46 | @classmethod |
| 47 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | 47 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, |
| 48 | kernel_dir, rootfs_dir, native_sysroot): | 48 | kernel_dir, krootfs_dir, native_sysroot): |
| 49 | """ | 49 | """ |
| 50 | Called to do the actual content population for a partition i.e. it | 50 | Called to do the actual content population for a partition i.e. it |
| 51 | 'prepares' the partition to be incorporated into the image. | 51 | 'prepares' the partition to be incorporated into the image. |
| 52 | In this case, prepare content for legacy bios boot partition. | 52 | In this case, prepare content for legacy bios boot partition. |
| 53 | """ | 53 | """ |
| 54 | if part.rootfs: | 54 | if part.rootfs is None: |
| 55 | rootfs_dir = part.rootfs | 55 | if not 'ROOTFS_DIR' in krootfs_dir: |
| 56 | msg = "Couldn't find --rootfs-dir, exiting" | ||
| 57 | msger.error(msg) | ||
| 58 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
| 59 | else: | ||
| 60 | if part.rootfs in krootfs_dir: | ||
| 61 | rootfs_dir = krootfs_dir[part.rootfs] | ||
| 62 | elif os.path.isdir(part.rootfs): | ||
| 63 | rootfs_dir = part.rootfs | ||
| 64 | else: | ||
| 65 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
| 66 | msg += " or it is not a valid path, exiting" | ||
| 67 | msger.error(msg % part.rootfs) | ||
| 56 | 68 | ||
| 57 | part.set_rootfs(rootfs_dir) | 69 | part.set_rootfs(rootfs_dir) |
| 58 | part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | 70 | part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) |
diff --git a/scripts/wic b/scripts/wic index 824acaebd3..442334030f 100755 --- a/scripts/wic +++ b/scripts/wic | |||
| @@ -45,6 +45,30 @@ sys.path = sys.path + [lib_path] | |||
| 45 | from image.help import * | 45 | from image.help import * |
| 46 | from image.engine import * | 46 | from image.engine import * |
| 47 | 47 | ||
| 48 | def rootfs_dir_to_args(krootfs_dir): | ||
| 49 | """ | ||
| 50 | Get a rootfs_dir dict and serialize to string | ||
| 51 | """ | ||
| 52 | rootfs_dir = '' | ||
| 53 | for k, v in krootfs_dir.items(): | ||
| 54 | rootfs_dir += ' ' | ||
| 55 | rootfs_dir += '='.join([k, v]) | ||
| 56 | return rootfs_dir.strip() | ||
| 57 | |||
| 58 | def callback_rootfs_dir(option, opt, value, parser): | ||
| 59 | """ | ||
| 60 | Build a dict using --rootfs_dir connection=dir | ||
| 61 | """ | ||
| 62 | if not type(parser.values.rootfs_dir) is dict: | ||
| 63 | parser.values.rootfs_dir = dict() | ||
| 64 | |||
| 65 | if '=' in value: | ||
| 66 | (key, rootfs_dir) = value.split('=') | ||
| 67 | else: | ||
| 68 | key = 'ROOTFS_DIR' | ||
| 69 | rootfs_dir = value | ||
| 70 | |||
| 71 | parser.values.rootfs_dir[key] = rootfs_dir | ||
| 48 | 72 | ||
| 49 | def wic_create_subcommand(args, usage_str): | 73 | def wic_create_subcommand(args, usage_str): |
| 50 | """ | 74 | """ |
| @@ -60,7 +84,8 @@ def wic_create_subcommand(args, usage_str): | |||
| 60 | parser.add_option("-e", "--image-name", dest = "image_name", | 84 | parser.add_option("-e", "--image-name", dest = "image_name", |
| 61 | action = "store", help = "name of the image to use the artifacts from e.g. core-image-sato") | 85 | action = "store", help = "name of the image to use the artifacts from e.g. core-image-sato") |
| 62 | parser.add_option("-r", "--rootfs-dir", dest = "rootfs_dir", | 86 | parser.add_option("-r", "--rootfs-dir", dest = "rootfs_dir", |
| 63 | action = "store", help = "path to the /rootfs dir to use as the .wks rootfs source") | 87 | action = "callback", callback = callback_rootfs_dir, type = "string", |
| 88 | help = "path to the /rootfs dir to use as the .wks rootfs source") | ||
| 64 | parser.add_option("-b", "--bootimg-dir", dest = "bootimg_dir", | 89 | parser.add_option("-b", "--bootimg-dir", dest = "bootimg_dir", |
| 65 | action = "store", help = "path to the dir containing the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the .wks bootimg source") | 90 | action = "store", help = "path to the dir containing the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the .wks bootimg source") |
| 66 | parser.add_option("-k", "--kernel-dir", dest = "kernel_dir", | 91 | parser.add_option("-k", "--kernel-dir", dest = "kernel_dir", |
| @@ -125,11 +150,13 @@ def wic_create_subcommand(args, usage_str): | |||
| 125 | image_output_dir = options.outdir | 150 | image_output_dir = options.outdir |
| 126 | 151 | ||
| 127 | if not options.image_name: | 152 | if not options.image_name: |
| 128 | rootfs_dir = options.rootfs_dir | 153 | rootfs_dir = '' |
| 154 | if 'ROOTFS_DIR' in options.rootfs_dir: | ||
| 155 | rootfs_dir = options.rootfs_dir['ROOTFS_DIR'] | ||
| 129 | bootimg_dir = options.bootimg_dir | 156 | bootimg_dir = options.bootimg_dir |
| 130 | kernel_dir = options.kernel_dir | 157 | kernel_dir = options.kernel_dir |
| 131 | native_sysroot = options.native_sysroot | 158 | native_sysroot = options.native_sysroot |
| 132 | if not os.path.isdir(rootfs_dir): | 159 | if rootfs_dir and not os.path.isdir(rootfs_dir): |
| 133 | print "--roofs-dir (-r) not found, exiting\n" | 160 | print "--roofs-dir (-r) not found, exiting\n" |
| 134 | sys.exit(1) | 161 | sys.exit(1) |
| 135 | if not os.path.isdir(bootimg_dir): | 162 | if not os.path.isdir(bootimg_dir): |
| @@ -162,6 +189,13 @@ def wic_create_subcommand(args, usage_str): | |||
| 162 | (not_found, not_found_dir) | 189 | (not_found, not_found_dir) |
| 163 | sys.exit(1) | 190 | sys.exit(1) |
| 164 | 191 | ||
| 192 | krootfs_dir = options.rootfs_dir | ||
| 193 | if krootfs_dir is None: | ||
| 194 | krootfs_dir = {} | ||
| 195 | krootfs_dir['ROOTFS_DIR'] = rootfs_dir | ||
| 196 | |||
| 197 | rootfs_dir = rootfs_dir_to_args(krootfs_dir) | ||
| 198 | |||
| 165 | wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir, | 199 | wic_create(args, wks_file, rootfs_dir, bootimg_dir, kernel_dir, |
| 166 | native_sysroot, hdddir, staging_data_dir, scripts_path, | 200 | native_sysroot, hdddir, staging_data_dir, scripts_path, |
| 167 | image_output_dir, options.debug, options.properties_file) | 201 | image_output_dir, options.debug, options.properties_file) |
