diff options
author | Joshua Watt <JPEWhacker@gmail.com> | 2020-06-02 08:42:05 -0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-06-04 13:27:32 +0100 |
commit | ba9be4bfa58efc73f1485eb5dc0dff0d23716821 (patch) | |
tree | af7a989c4e2caf3c08c2b7f77be5679c533966ca /scripts/lib/wic/ksparser.py | |
parent | 6b4299df5d86ba079e7525ad09def756359b9502 (diff) | |
download | poky-ba9be4bfa58efc73f1485eb5dc0dff0d23716821.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: 467f84e12b96bc977d57575023517dd6f8ef7f29)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/wic/ksparser.py')
-rw-r--r-- | scripts/lib/wic/ksparser.py | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py index b8befe78e3..05ae292ef5 100644 --- a/scripts/lib/wic/ksparser.py +++ b/scripts/lib/wic/ksparser.py | |||
@@ -51,26 +51,31 @@ class KickStartParser(ArgumentParser): | |||
51 | def error(self, message): | 51 | def error(self, message): |
52 | raise ArgumentError(None, message) | 52 | raise ArgumentError(None, message) |
53 | 53 | ||
54 | def sizetype(arg): | 54 | def sizetype(default): |
55 | """ | 55 | def f(arg): |
56 | Custom type for ArgumentParser | 56 | """ |
57 | Converts size string in <num>[K|k|M|G] format into the integer value | 57 | Custom type for ArgumentParser |
58 | """ | 58 | Converts size string in <num>[K|k|M|G] format into the integer value |
59 | if arg.isdigit(): | 59 | """ |
60 | return int(arg) * 1024 | 60 | try: |
61 | suffix = default | ||
62 | size = int(arg) | ||
63 | except ValueError: | ||
64 | try: | ||
65 | suffix = arg[-1:] | ||
66 | size = int(arg[:-1]) | ||
67 | except ValueError: | ||
68 | raise ArgumentTypeError("Invalid size: %r" % arg) | ||
69 | |||
70 | if suffix == "k" or suffix == "K": | ||
71 | return size | ||
72 | if suffix == "M": | ||
73 | return size * 1024 | ||
74 | if suffix == "G": | ||
75 | return size * 1024 * 1024 | ||
61 | 76 | ||
62 | if not arg[:-1].isdigit(): | ||
63 | raise ArgumentTypeError("Invalid size: %r" % arg) | 77 | raise ArgumentTypeError("Invalid size: %r" % arg) |
64 | 78 | return f | |
65 | size = int(arg[:-1]) | ||
66 | if arg.endswith("k") or arg.endswith("K"): | ||
67 | return size | ||
68 | if arg.endswith("M"): | ||
69 | return size * 1024 | ||
70 | if arg.endswith("G"): | ||
71 | return size * 1024 * 1024 | ||
72 | |||
73 | raise ArgumentTypeError("Invalid size: %r" % arg) | ||
74 | 79 | ||
75 | def overheadtype(arg): | 80 | def overheadtype(arg): |
76 | """ | 81 | """ |
@@ -136,6 +141,7 @@ class KickStart(): | |||
136 | part.add_argument('mountpoint', nargs='?') | 141 | part.add_argument('mountpoint', nargs='?') |
137 | part.add_argument('--active', action='store_true') | 142 | part.add_argument('--active', action='store_true') |
138 | part.add_argument('--align', type=int) | 143 | part.add_argument('--align', type=int) |
144 | part.add_argument('--offset', type=sizetype("K")) | ||
139 | part.add_argument('--exclude-path', nargs='+') | 145 | part.add_argument('--exclude-path', nargs='+') |
140 | part.add_argument('--include-path', nargs='+', action='append') | 146 | part.add_argument('--include-path', nargs='+', action='append') |
141 | part.add_argument('--change-directory') | 147 | part.add_argument('--change-directory') |
@@ -161,8 +167,8 @@ class KickStart(): | |||
161 | # --error, but since nesting mutually exclusive groups does not work, | 167 | # --error, but since nesting mutually exclusive groups does not work, |
162 | # ----extra-space/--overhead-factor are handled later | 168 | # ----extra-space/--overhead-factor are handled later |
163 | sizeexcl = part.add_mutually_exclusive_group() | 169 | sizeexcl = part.add_mutually_exclusive_group() |
164 | sizeexcl.add_argument('--size', type=sizetype, default=0) | 170 | sizeexcl.add_argument('--size', type=sizetype("M"), default=0) |
165 | sizeexcl.add_argument('--fixed-size', type=sizetype, default=0) | 171 | sizeexcl.add_argument('--fixed-size', type=sizetype("M"), default=0) |
166 | 172 | ||
167 | part.add_argument('--source') | 173 | part.add_argument('--source') |
168 | part.add_argument('--sourceparams') | 174 | part.add_argument('--sourceparams') |