diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2020-06-02 08:42:05 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-10-06 14:15:22 +0100 |
commit | 343a7e2c61f97507d0a80ea54fb7457e28ce77e0 (patch) | |
tree | 344074389ad14762d516e0d305ffbe50f466f9c5 /meta/lib | |
parent | 0026c1475f6703a19b739cd85bcda66c0a452764 (diff) | |
download | poky-343a7e2c61f97507d0a80ea54fb7457e28ce77e0.tar.gz |
wic: Add --offset argument for partitions
Add support for an --offset argument when defining a partition. Many
SoCs require that boot partitions be located at specific offsets. Prior
to this argument, most WKS files were using the --align attribute to
specify the location of these fixed partitions but this is not ideal
because in the event that the partition couldn't be placed in the
specified location, wic would move it to the next sector with that
alignment, often preventing the device from booting. Unlike the --align
argument, wic will fail if a partition cannot be placed at the exact
offset specified with --offset.
Changes in V2:
* Fixed a small typo that prevented test_fixed_size_error from passing
(From OE-Core rev: 897aaff8961f7fe83634a3b0b94e19b43aea5857)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 467f84e12b96bc977d57575023517dd6f8ef7f29)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/wic.py | 118 |
1 files changed, 93 insertions, 25 deletions
diff --git a/meta/lib/oeqa/selftest/cases/wic.py b/meta/lib/oeqa/selftest/cases/wic.py index 626a217e69..6d4068a527 100644 --- a/meta/lib/oeqa/selftest/cases/wic.py +++ b/meta/lib/oeqa/selftest/cases/wic.py | |||
@@ -639,41 +639,50 @@ class Wic2(WicTestCase): | |||
639 | tempf.write("part " \ | 639 | tempf.write("part " \ |
640 | "--source rootfs --ondisk hda --align 4 --fixed-size %d " | 640 | "--source rootfs --ondisk hda --align 4 --fixed-size %d " |
641 | "--fstype=ext4\n" % size) | 641 | "--fstype=ext4\n" % size) |
642 | wksname = os.path.splitext(os.path.basename(wkspath))[0] | ||
643 | 642 | ||
644 | return wkspath, wksname | 643 | return wkspath |
645 | 644 | ||
646 | def test_fixed_size(self): | 645 | def _get_wic_partitions(self, wkspath, native_sysroot=None, ignore_status=False): |
647 | """ | 646 | p = runCmd("wic create %s -e core-image-minimal -o %s" % (wkspath, self.resultdir), |
648 | Test creation of a simple image with partition size controlled through | 647 | ignore_status=ignore_status) |
649 | --fixed-size flag | 648 | |
650 | """ | 649 | if p.status: |
651 | wkspath, wksname = Wic2._make_fixed_size_wks(200) | 650 | return (p, None) |
651 | |||
652 | wksname = os.path.splitext(os.path.basename(wkspath))[0] | ||
652 | 653 | ||
653 | runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
654 | % (wkspath, self.resultdir)) | ||
655 | os.remove(wkspath) | ||
656 | wicout = glob(self.resultdir + "%s-*direct" % wksname) | 654 | wicout = glob(self.resultdir + "%s-*direct" % wksname) |
657 | self.assertEqual(1, len(wicout)) | 655 | |
656 | if not wicout: | ||
657 | return (p, None) | ||
658 | 658 | ||
659 | wicimg = wicout[0] | 659 | wicimg = wicout[0] |
660 | 660 | ||
661 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | 661 | if not native_sysroot: |
662 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | ||
662 | 663 | ||
663 | # verify partition size with wic | 664 | # verify partition size with wic |
664 | res = runCmd("parted -m %s unit mib p 2>/dev/null" % wicimg, | 665 | res = runCmd("parted -m %s unit kib p 2>/dev/null" % wicimg, |
665 | native_sysroot=native_sysroot) | 666 | native_sysroot=native_sysroot) |
666 | 667 | ||
667 | # parse parted output which looks like this: | 668 | # parse parted output which looks like this: |
668 | # BYT;\n | 669 | # BYT;\n |
669 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n | 670 | # /var/tmp/wic/build/tmpfwvjjkf_-201611101222-hda.direct:200MiB:file:512:512:msdos::;\n |
670 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n | 671 | # 1:0.00MiB:200MiB:200MiB:ext4::;\n |
671 | partlns = res.output.splitlines()[2:] | 672 | return (p, res.output.splitlines()[2:]) |
672 | 673 | ||
673 | self.assertEqual(1, len(partlns), | 674 | def test_fixed_size(self): |
674 | msg="Partition list '%s'" % res.output) | 675 | """ |
675 | self.assertEqual("1:0.00MiB:200MiB:200MiB:ext4::;", partlns[0], | 676 | Test creation of a simple image with partition size controlled through |
676 | msg="Partition list '%s'" % res.output) | 677 | --fixed-size flag |
678 | """ | ||
679 | wkspath = Wic2._make_fixed_size_wks(200) | ||
680 | _, partlns = self._get_wic_partitions(wkspath) | ||
681 | os.remove(wkspath) | ||
682 | |||
683 | self.assertEqual(partlns, [ | ||
684 | "1:4.00kiB:204804kiB:204800kiB:ext4::;", | ||
685 | ]) | ||
677 | 686 | ||
678 | def test_fixed_size_error(self): | 687 | def test_fixed_size_error(self): |
679 | """ | 688 | """ |
@@ -681,13 +690,72 @@ class Wic2(WicTestCase): | |||
681 | --fixed-size flag. The size of partition is intentionally set to 1MiB | 690 | --fixed-size flag. The size of partition is intentionally set to 1MiB |
682 | in order to trigger an error in wic. | 691 | in order to trigger an error in wic. |
683 | """ | 692 | """ |
684 | wkspath, wksname = Wic2._make_fixed_size_wks(1) | 693 | wkspath = Wic2._make_fixed_size_wks(1) |
685 | 694 | p, _ = self._get_wic_partitions(wkspath, ignore_status=True) | |
686 | self.assertEqual(1, runCmd("wic create %s -e core-image-minimal -o %s" \ | ||
687 | % (wkspath, self.resultdir), ignore_status=True).status) | ||
688 | os.remove(wkspath) | 695 | os.remove(wkspath) |
689 | wicout = glob(self.resultdir + "%s-*direct" % wksname) | 696 | |
690 | self.assertEqual(0, len(wicout)) | 697 | self.assertNotEqual(p.status, 0, "wic exited successfully when an error was expected:\n%s" % p.output) |
698 | |||
699 | def test_offset(self): | ||
700 | native_sysroot = get_bb_var("RECIPE_SYSROOT_NATIVE", "wic-tools") | ||
701 | |||
702 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
703 | # Test that partitions are placed at the correct offsets, default KB | ||
704 | tempf.write("bootloader --ptable gpt\n" \ | ||
705 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ | ||
706 | "part /bar --ondisk hda --offset 102432 --fixed-size 100M --fstype=ext4\n") | ||
707 | tempf.flush() | ||
708 | |||
709 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
710 | self.assertEqual(partlns, [ | ||
711 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | ||
712 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | ||
713 | ]) | ||
714 | |||
715 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
716 | # Test that partitions are placed at the correct offsets, same with explicit KB | ||
717 | tempf.write("bootloader --ptable gpt\n" \ | ||
718 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 100M --fstype=ext4\n" \ | ||
719 | "part /bar --ondisk hda --offset 102432K --fixed-size 100M --fstype=ext4\n") | ||
720 | tempf.flush() | ||
721 | |||
722 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
723 | self.assertEqual(partlns, [ | ||
724 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | ||
725 | "2:102432kiB:204832kiB:102400kiB:ext4:primary:;", | ||
726 | ]) | ||
727 | |||
728 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
729 | # Test that partitions are placed at the correct offsets using MB | ||
730 | tempf.write("bootloader --ptable gpt\n" \ | ||
731 | "part / --source rootfs --ondisk hda --offset 32K --fixed-size 100M --fstype=ext4\n" \ | ||
732 | "part /bar --ondisk hda --offset 101M --fixed-size 100M --fstype=ext4\n") | ||
733 | tempf.flush() | ||
734 | |||
735 | _, partlns = self._get_wic_partitions(tempf.name, native_sysroot) | ||
736 | self.assertEqual(partlns, [ | ||
737 | "1:32.0kiB:102432kiB:102400kiB:ext4:primary:;", | ||
738 | "2:103424kiB:205824kiB:102400kiB:ext4:primary:;", | ||
739 | ]) | ||
740 | |||
741 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
742 | # Test that image creation fails if the partitions would overlap | ||
743 | tempf.write("bootloader --ptable gpt\n" \ | ||
744 | "part / --source rootfs --ondisk hda --offset 32 --fixed-size 100M --fstype=ext4\n" \ | ||
745 | "part /bar --ondisk hda --offset 102431 --fixed-size 100M --fstype=ext4\n") | ||
746 | tempf.flush() | ||
747 | |||
748 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) | ||
749 | self.assertNotEqual(p.status, 0, "wic exited successfully when an error was expected:\n%s" % p.output) | ||
750 | |||
751 | with NamedTemporaryFile("w", suffix=".wks") as tempf: | ||
752 | # Test that partitions are not allowed to overlap with the booloader | ||
753 | tempf.write("bootloader --ptable gpt\n" \ | ||
754 | "part / --source rootfs --ondisk hda --offset 8 --fixed-size 100M --fstype=ext4\n") | ||
755 | tempf.flush() | ||
756 | |||
757 | p, _ = self._get_wic_partitions(tempf.name, ignore_status=True) | ||
758 | self.assertNotEqual(p.status, 0, "wic exited successfully when an error was expected:\n%s" % p.output) | ||
691 | 759 | ||
692 | @only_for_arch(['i586', 'i686', 'x86_64']) | 760 | @only_for_arch(['i586', 'i686', 'x86_64']) |
693 | def test_rawcopy_plugin_qemu(self): | 761 | def test_rawcopy_plugin_qemu(self): |