summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChee Yang Lee <chee.yang.lee@intel.com>2019-11-21 14:28:52 +0800
committerRichard Purdie <richard.purdie@linuxfoundation.org>2019-11-27 13:25:18 +0000
commit89288705c682bceea52302cc607ff221ca30f3d1 (patch)
tree8a1a42dffbd49ed7fd82c7c9665575e80225c30e
parent4d6a9708e6e1e1aadca7e9eb50841778d391a456 (diff)
downloadpoky-89288705c682bceea52302cc607ff221ca30f3d1.tar.gz
wic: 'wic cp' to copy from image
currently 'wic cp' only works for copy file from local storage to wic image. enhance 'wic cp' to copy file/directory from wic image to local storage. include selftest and 'wic help' updates. [YOCTO#12169] (From OE-Core rev: bd669c1809a378f93580eb9e0679a26ec6746cb8) Signed-off-by: Chee Yang Lee <chee.yang.lee@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oeqa/selftest/cases/wic.py17
-rw-r--r--scripts/lib/wic/engine.py35
-rw-r--r--scripts/lib/wic/help.py29
-rwxr-xr-xscripts/wic16
4 files changed, 76 insertions, 21 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py
index 0c03b4b02d..3c5be2f501 100644
--- a/meta/lib/oeqa/selftest/cases/wic.py
+++ b/meta/lib/oeqa/selftest/cases/wic.py
@@ -866,6 +866,13 @@ class Wic2(WicTestCase):
866 self.assertEqual(8, len(result.output.split('\n'))) 866 self.assertEqual(8, len(result.output.split('\n')))
867 self.assertTrue(os.path.basename(testdir) in result.output) 867 self.assertTrue(os.path.basename(testdir) in result.output)
868 868
869 # copy the file from the partition and check if it success
870 dest = '%s-cp' % testfile.name
871 runCmd("wic cp %s:1/%s %s -n %s" % (images[0],
872 os.path.basename(testfile.name), dest, sysroot))
873 self.assertTrue(os.path.exists(dest))
874
875
869 def test_wic_rm(self): 876 def test_wic_rm(self):
870 """Test removing files and directories from the the wic image.""" 877 """Test removing files and directories from the the wic image."""
871 runCmd("wic create mkefidisk " 878 runCmd("wic create mkefidisk "
@@ -1005,6 +1012,16 @@ class Wic2(WicTestCase):
1005 newdirs = set(line.split()[-1] for line in result.output.split('\n') if line) 1012 newdirs = set(line.split()[-1] for line in result.output.split('\n') if line)
1006 self.assertEqual(newdirs.difference(dirs), set([os.path.basename(testfile.name)])) 1013 self.assertEqual(newdirs.difference(dirs), set([os.path.basename(testfile.name)]))
1007 1014
1015 # check if the file to copy is in the partition
1016 result = runCmd("wic ls %s:2/etc/ -n %s" % (images[0], sysroot))
1017 self.assertTrue('fstab' in [line.split()[-1] for line in result.output.split('\n') if line])
1018
1019 # copy file from the partition, replace the temporary file content with it and
1020 # check for the file size to validate the copy
1021 runCmd("wic cp %s:2/etc/fstab %s -n %s" % (images[0], testfile.name, sysroot))
1022 self.assertTrue(os.stat(testfile.name).st_size > 0)
1023
1024
1008 def test_wic_rm_ext(self): 1025 def test_wic_rm_ext(self):
1009 """Test removing files from the ext partition.""" 1026 """Test removing files from the ext partition."""
1010 runCmd("wic create mkefidisk " 1027 runCmd("wic create mkefidisk "
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
index 7e6620747d..24797511e5 100644
--- a/scripts/lib/wic/engine.py
+++ b/scripts/lib/wic/engine.py
@@ -323,16 +323,31 @@ class Disk:
323 self._get_part_image(pnum), 323 self._get_part_image(pnum),
324 path)) 324 path))
325 325
326 def copy(self, src, pnum, path): 326 def copy(self, src, dest):
327 """Copy partition image into wic image.""" 327 """Copy partition image into wic image."""
328 pnum = dest.part if isinstance(src, str) else src.part
329
328 if self.partitions[pnum].fstype.startswith('ext'): 330 if self.partitions[pnum].fstype.startswith('ext'):
329 cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\ 331 if isinstance(src, str):
330 format(path, src, os.path.basename(src), 332 cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
333 format(os.path.dirname(dest.path), src, os.path.basename(src),
331 self.debugfs, self._get_part_image(pnum)) 334 self.debugfs, self._get_part_image(pnum))
335 else: # copy from wic
336 # run both dump and rdump to support both files and directory
337 cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' | {} {}".\
338 format(os.path.dirname(src.path), src.path,
339 dest, src.path, dest, self.debugfs,
340 self._get_part_image(pnum))
332 else: # fat 341 else: # fat
333 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy, 342 if isinstance(src, str):
343 cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
344 self._get_part_image(pnum),
345 src, dest.path)
346 else:
347 cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
334 self._get_part_image(pnum), 348 self._get_part_image(pnum),
335 src, path) 349 src.path, dest)
350
336 exec_cmd(cmd, as_shell=True) 351 exec_cmd(cmd, as_shell=True)
337 self._put_part_image(pnum) 352 self._put_part_image(pnum)
338 353
@@ -551,11 +566,15 @@ def wic_ls(args, native_sysroot):
551 566
552def wic_cp(args, native_sysroot): 567def wic_cp(args, native_sysroot):
553 """ 568 """
554 Copy local file or directory to the vfat partition of 569 Copy file or directory to/from the vfat/ext partition of
555 partitioned image. 570 partitioned image.
556 """ 571 """
557 disk = Disk(args.dest.image, native_sysroot) 572 if isinstance(args.dest, str):
558 disk.copy(args.src, args.dest.part, args.dest.path) 573 disk = Disk(args.src.image, native_sysroot)
574 else:
575 disk = Disk(args.dest.image, native_sysroot)
576 disk.copy(args.src, args.dest)
577
559 578
560def wic_rm(args, native_sysroot): 579def wic_rm(args, native_sysroot):
561 """ 580 """
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
index 812ebe3ec8..29c4e436d8 100644
--- a/scripts/lib/wic/help.py
+++ b/scripts/lib/wic/help.py
@@ -341,12 +341,15 @@ DESCRIPTION
341 341
342wic_cp_usage = """ 342wic_cp_usage = """
343 343
344 Copy files and directories to the vfat or ext* partition 344 Copy files and directories to/from the vfat or ext* partition
345 345
346 usage: wic cp <src> <image>:<partition>[<path>] [--native-sysroot <path>] 346 usage: wic cp <src> <dest> [--native-sysroot <path>]
347 347
348 This command copies local files or directories to the vfat or ext* partitions 348 source/destination image in format <image>:<partition>[<path>]
349of partitioned image. 349
350 This command copies files or directories either
351 - from local to vfat or ext* partitions of partitioned image
352 - from vfat or ext* partitions of partitioned image to local
350 353
351 See 'wic help cp' for more detailed instructions. 354 See 'wic help cp' for more detailed instructions.
352 355
@@ -355,16 +358,18 @@ of partitioned image.
355wic_cp_help = """ 358wic_cp_help = """
356 359
357NAME 360NAME
358 wic cp - copy files and directories to the vfat or ext* partitions 361 wic cp - copy files and directories to/from the vfat or ext* partitions
359 362
360SYNOPSIS 363SYNOPSIS
361 wic cp <src> <image>:<partition> 364 wic cp <src> <dest>:<partition>
362 wic cp <src> <image>:<partition><path> 365 wic cp <src>:<partition> <dest>
363 wic cp <src> <image>:<partition><path> --native-sysroot <path> 366 wic cp <src> <dest-image>:<partition><path>
367 wic cp <src> <dest-image>:<partition><path> --native-sysroot <path>
364 368
365DESCRIPTION 369DESCRIPTION
366 This command copies files and directories to the vfat or ext* partition of 370 This command copies files or directories either
367 the partitioned image. 371 - from local to vfat or ext* partitions of partitioned image
372 - from vfat or ext* partitions of partitioned image to local
368 373
369 The first form of it copies file or directory to the root directory of 374 The first form of it copies file or directory to the root directory of
370 the partition: 375 the partition:
@@ -397,6 +402,10 @@ DESCRIPTION
397 4 files 0 bytes 402 4 files 0 bytes
398 15 675 392 bytes free 403 15 675 392 bytes free
399 404
405 The third form of the command copies file or directory from the specified directory
406 on the partition to local:
407 $ wic cp tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/vmlinuz test
408
400 The -n option is used to specify the path to the native sysroot 409 The -n option is used to specify the path to the native sysroot
401 containing the tools(parted and mtools) to use. 410 containing the tools(parted and mtools) to use.
402""" 411"""
diff --git a/scripts/wic b/scripts/wic
index ea614100c2..24700f380f 100755
--- a/scripts/wic
+++ b/scripts/wic
@@ -392,9 +392,9 @@ def imgpathtype(arg):
392 392
393def wic_init_parser_cp(subparser): 393def wic_init_parser_cp(subparser):
394 subparser.add_argument("src", 394 subparser.add_argument("src",
395 help="source spec") 395 help="image spec: <image>:<vfat partition>[<path>] or <file>")
396 subparser.add_argument("dest", type=imgpathtype, 396 subparser.add_argument("dest",
397 help="image spec: <image>:<vfat partition>[<path>]") 397 help="image spec: <image>:<vfat partition>[<path>] or <file>")
398 subparser.add_argument("-n", "--native-sysroot", 398 subparser.add_argument("-n", "--native-sysroot",
399 help="path to the native sysroot containing the tools") 399 help="path to the native sysroot containing the tools")
400 400
@@ -522,6 +522,16 @@ def main(argv):
522 hlpt[0](hlpt[1], hlpt[2]) 522 hlpt[0](hlpt[1], hlpt[2])
523 return 0 523 return 0
524 524
525 # validate wic cp src and dest parameter to identify which one of it is
526 # image and cast it into imgtype
527 if args.command == "cp":
528 if ":" in args.dest:
529 args.dest = imgtype(args.dest)
530 elif ":" in args.src:
531 args.src = imgtype(args.src)
532 else:
533 raise argparse.ArgumentTypeError("no image or partition number specified.")
534
525 return hlp.invoke_subcommand(args, parser, hlp.wic_help_usage, subcommands) 535 return hlp.invoke_subcommand(args, parser, hlp.wic_help_usage, subcommands)
526 536
527 537