blob: 812ebe3ec88a8cedc85792a3ebcff71f714fb3b1 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Copyright (c) 2013, Intel Corporation.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002#
Brad Bishopc342db32019-05-15 21:57:59 -04003# SPDX-License-Identifier: GPL-2.0-only
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004#
5# DESCRIPTION
6# This module implements some basic help invocation functions along
7# with the bulk of the help topic text for the OE Core Image Tools.
8#
9# AUTHORS
10# Tom Zanussi <tom.zanussi (at] linux.intel.com>
11#
12
13import subprocess
14import logging
15
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016from wic.pluginbase import PluginMgr, PLUGIN_TYPES
17
18logger = logging.getLogger('wic')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019
20def subcommand_error(args):
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021 logger.info("invalid subcommand %s", args[0])
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
23
24def display_help(subcommand, subcommands):
25 """
26 Display help for subcommand.
27 """
28 if subcommand not in subcommands:
29 return False
30
31 hlp = subcommands.get(subcommand, subcommand_error)[2]
32 if callable(hlp):
33 hlp = hlp()
34 pager = subprocess.Popen('less', stdin=subprocess.PIPE)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035 pager.communicate(hlp.encode('utf-8'))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050036
37 return True
38
39
40def wic_help(args, usage_str, subcommands):
41 """
42 Subcommand help dispatcher.
43 """
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044 if args.help_topic == None or not display_help(args.help_topic, subcommands):
Patrick Williamsc0f7c042017-02-23 20:41:17 -060045 print(usage_str)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
47
48def get_wic_plugins_help():
49 """
50 Combine wic_plugins_help with the help for every known
51 source plugin.
52 """
53 result = wic_plugins_help
54 for plugin_type in PLUGIN_TYPES:
55 result += '\n\n%s PLUGINS\n\n' % plugin_type.upper()
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056 for name, plugin in PluginMgr.get_plugins(plugin_type).items():
Patrick Williamsc124f4f2015-09-15 14:41:29 -050057 result += "\n %s plugin:\n" % name
58 if plugin.__doc__:
59 result += plugin.__doc__
60 else:
61 result += "\n %s is missing docstring\n" % plugin
62 return result
63
64
65def invoke_subcommand(args, parser, main_command_usage, subcommands):
66 """
67 Dispatch to subcommand handler borrowed from combo-layer.
68 Should use argparse, but has to work in 2.6.
69 """
Brad Bishopd7bf8c12018-02-25 22:55:05 -050070 if not args.command:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050071 logger.error("No subcommand specified, exiting")
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072 parser.print_help()
73 return 1
Brad Bishopd7bf8c12018-02-25 22:55:05 -050074 elif args.command == "help":
Patrick Williamsc124f4f2015-09-15 14:41:29 -050075 wic_help(args, main_command_usage, subcommands)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050076 elif args.command not in subcommands:
77 logger.error("Unsupported subcommand %s, exiting\n", args.command)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 parser.print_help()
79 return 1
80 else:
Brad Bishopd7bf8c12018-02-25 22:55:05 -050081 subcmd = subcommands.get(args.command, subcommand_error)
82 usage = subcmd[1]
83 subcmd[0](args, usage)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084
85
86##
87# wic help and usage strings
88##
89
90wic_usage = """
91
92 Create a customized OpenEmbedded image
93
94 usage: wic [--version] | [--help] | [COMMAND [ARGS]]
95
96 Current 'wic' commands are:
97 help Show help for command or one of the topics (see below)
98 create Create a new OpenEmbedded image
99 list List available canned images and source plugins
100
101 Help topics:
102 overview wic overview - General overview of wic
103 plugins wic plugins - Overview and API
104 kickstart wic kickstart - wic kickstart reference
105"""
106
107wic_help_usage = """
108
109 usage: wic help <subcommand>
110
111 This command displays detailed help for the specified subcommand.
112"""
113
114wic_create_usage = """
115
116 Create a new OpenEmbedded image
117
118 usage: wic create <wks file or image name> [-o <DIRNAME> | --outdir <DIRNAME>]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
120 [-r, --rootfs-dir] [-b, --bootimg-dir]
121 [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500122 [-c, --compress-with] [-m, --bmap]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123
124 This command creates an OpenEmbedded image based on the 'OE kickstart
125 commands' found in the <wks file>.
126
127 The -o option can be used to place the image in a directory with a
128 different name and location.
129
130 See 'wic help create' for more detailed instructions.
131"""
132
133wic_create_help = """
134
135NAME
136 wic create - Create a new OpenEmbedded image
137
138SYNOPSIS
139 wic create <wks file or image name> [-o <DIRNAME> | --outdir <DIRNAME>]
140 [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
141 [-r, --rootfs-dir] [-b, --bootimg-dir]
142 [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500143 [-c, --compress-with] [-m, --bmap] [--no-fstab-update]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500144
145DESCRIPTION
146 This command creates an OpenEmbedded image based on the 'OE
147 kickstart commands' found in the <wks file>.
148
149 In order to do this, wic needs to know the locations of the
150 various build artifacts required to build the image.
151
152 Users can explicitly specify the build artifact locations using
153 the -r, -b, -k, and -n options. See below for details on where
154 the corresponding artifacts are typically found in a normal
155 OpenEmbedded build.
156
157 Alternatively, users can use the -e option to have 'wic' determine
158 those locations for a given image. If the -e option is used, the
159 user needs to have set the appropriate MACHINE variable in
160 local.conf, and have sourced the build environment.
161
162 The -e option is used to specify the name of the image to use the
163 artifacts from e.g. core-image-sato.
164
165 The -r option is used to specify the path to the /rootfs dir to
166 use as the .wks rootfs source.
167
168 The -b option is used to specify the path to the dir containing
169 the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the
170 .wks bootimg source.
171
172 The -k option is used to specify the path to the dir containing
173 the kernel to use in the .wks bootimg.
174
175 The -n option is used to specify the path to the native sysroot
176 containing the tools to use to build the image.
177
178 The -f option is used to build rootfs by running "bitbake <image>"
179
180 The -s option is used to skip the build check. The build check is
181 a simple sanity check used to determine whether the user has
182 sourced the build environment so that the -e option can operate
183 correctly. If the user has specified the build artifact locations
184 explicitly, 'wic' assumes the user knows what he or she is doing
185 and skips the build check.
186
187 The -D option is used to display debug information detailing
188 exactly what happens behind the scenes when a create request is
189 fulfilled (or not, as the case may be). It enumerates and
190 displays the command sequence used, and should be included in any
191 bug report describing unexpected results.
192
193 When 'wic -e' is used, the locations for the build artifacts
194 values are determined by 'wic -e' from the output of the 'bitbake
195 -e' command given an image name e.g. 'core-image-minimal' and a
196 given machine set in local.conf. In that case, the image is
197 created as if the following 'bitbake -e' variables were used:
198
199 -r: IMAGE_ROOTFS
200 -k: STAGING_KERNEL_DIR
201 -n: STAGING_DIR_NATIVE
202 -b: empty (plugin-specific handlers must determine this)
203
204 If 'wic -e' is not used, the user needs to select the appropriate
205 value for -b (as well as -r, -k, and -n).
206
207 The -o option can be used to place the image in a directory with a
208 different name and location.
209
210 The -c option is used to specify compressor utility to compress
211 an image. gzip, bzip2 and xz compressors are supported.
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600212
213 The -m option is used to produce .bmap file for the image. This file
214 can be used to flash image using bmaptool utility.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500215
216 The --no-fstab-update option is used to doesn't change fstab file. When
217 using this option the final fstab file will be same that in rootfs and
218 wic doesn't update file, e.g adding a new mount point. User can control
219 the fstab file content in base-files recipe.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500220"""
221
222wic_list_usage = """
223
224 List available OpenEmbedded images and source plugins
225
226 usage: wic list images
227 wic list <image> help
228 wic list source-plugins
229
230 This command enumerates the set of available canned images as well as
231 help for those images. It also can be used to list of available source
232 plugins.
233
234 The first form enumerates all the available 'canned' images.
235
236 The second form lists the detailed help information for a specific
237 'canned' image.
238
239 The third form enumerates all the available --sources (source
240 plugins).
241
242 See 'wic help list' for more details.
243"""
244
245wic_list_help = """
246
247NAME
248 wic list - List available OpenEmbedded images and source plugins
249
250SYNOPSIS
251 wic list images
252 wic list <image> help
253 wic list source-plugins
254
255DESCRIPTION
256 This command enumerates the set of available canned images as well
257 as help for those images. It also can be used to list available
258 source plugins.
259
260 The first form enumerates all the available 'canned' images.
261 These are actually just the set of .wks files that have been moved
262 into the /scripts/lib/wic/canned-wks directory).
263
264 The second form lists the detailed help information for a specific
265 'canned' image.
266
267 The third form enumerates all the available --sources (source
268 plugins). The contents of a given partition are driven by code
269 defined in 'source plugins'. Users specify a specific plugin via
270 the --source parameter of the partition .wks command. Normally
271 this is the 'rootfs' plugin but can be any of the more specialized
272 sources listed by the 'list source-plugins' command. Users can
273 also add their own source plugins - see 'wic help plugins' for
274 details.
275"""
276
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500277wic_ls_usage = """
278
279 List content of a partitioned image
280
281 usage: wic ls <image>[:<partition>[<path>]] [--native-sysroot <path>]
282
283 This command outputs either list of image partitions or directory contents
284 of vfat and ext* partitions.
285
286 See 'wic help ls' for more detailed instructions.
287
288"""
289
290wic_ls_help = """
291
292NAME
293 wic ls - List contents of partitioned image or partition
294
295SYNOPSIS
296 wic ls <image>
297 wic ls <image>:<vfat or ext* partition>
298 wic ls <image>:<vfat or ext* partition><path>
299 wic ls <image>:<vfat or ext* partition><path> --native-sysroot <path>
300
301DESCRIPTION
302 This command lists either partitions of the image or directory contents
303 of vfat or ext* partitions.
304
305 The first form it lists partitions of the image.
306 For example:
307 $ wic ls tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic
308 Num Start End Size Fstype
309 1 1048576 24438783 23390208 fat16
310 2 25165824 50315263 25149440 ext4
311
312 Second and third form list directory content of the partition:
313 $ wic ls tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
314 Volume in drive : is boot
315 Volume Serial Number is 2DF2-5F02
316 Directory for ::/
317
318 efi <DIR> 2017-05-11 10:54
319 startup nsh 26 2017-05-11 10:54
320 vmlinuz 6922288 2017-05-11 10:54
321 3 files 6 922 314 bytes
322 15 818 752 bytes free
323
324
325 $ wic ls tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/EFI/boot/
326 Volume in drive : is boot
327 Volume Serial Number is 2DF2-5F02
328 Directory for ::/EFI/boot
329
330 . <DIR> 2017-05-11 10:54
331 .. <DIR> 2017-05-11 10:54
332 grub cfg 679 2017-05-11 10:54
333 bootx64 efi 571392 2017-05-11 10:54
334 4 files 572 071 bytes
335 15 818 752 bytes free
336
337 The -n option is used to specify the path to the native sysroot
338 containing the tools(parted and mtools) to use.
339
340"""
341
342wic_cp_usage = """
343
344 Copy files and directories to the vfat or ext* partition
345
346 usage: wic cp <src> <image>:<partition>[<path>] [--native-sysroot <path>]
347
348 This command copies local files or directories to the vfat or ext* partitions
349of partitioned image.
350
351 See 'wic help cp' for more detailed instructions.
352
353"""
354
355wic_cp_help = """
356
357NAME
358 wic cp - copy files and directories to the vfat or ext* partitions
359
360SYNOPSIS
361 wic cp <src> <image>:<partition>
362 wic cp <src> <image>:<partition><path>
363 wic cp <src> <image>:<partition><path> --native-sysroot <path>
364
365DESCRIPTION
366 This command copies files and directories to the vfat or ext* partition of
367 the partitioned image.
368
369 The first form of it copies file or directory to the root directory of
370 the partition:
371 $ wic cp test.wks tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
372 $ wic ls tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
373 Volume in drive : is boot
374 Volume Serial Number is DB4C-FD4C
375 Directory for ::/
376
377 efi <DIR> 2017-05-24 18:15
378 loader <DIR> 2017-05-24 18:15
379 startup nsh 26 2017-05-24 18:15
380 vmlinuz 6926384 2017-05-24 18:15
381 test wks 628 2017-05-24 21:22
382 5 files 6 927 038 bytes
383 15 677 440 bytes free
384
385 The second form of the command copies file or directory to the specified directory
386 on the partition:
387 $ wic cp test tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/efi/
388 $ wic ls tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/efi/
389 Volume in drive : is boot
390 Volume Serial Number is DB4C-FD4C
391 Directory for ::/efi
392
393 . <DIR> 2017-05-24 18:15
394 .. <DIR> 2017-05-24 18:15
395 boot <DIR> 2017-05-24 18:15
396 test <DIR> 2017-05-24 21:27
397 4 files 0 bytes
398 15 675 392 bytes free
399
400 The -n option is used to specify the path to the native sysroot
401 containing the tools(parted and mtools) to use.
402"""
403
404wic_rm_usage = """
405
406 Remove files or directories from the vfat or ext* partitions
407
408 usage: wic rm <image>:<partition><path> [--native-sysroot <path>]
409
410 This command removes files or directories from the vfat or ext* partitions of
411 the partitioned image.
412
413 See 'wic help rm' for more detailed instructions.
414
415"""
416
417wic_rm_help = """
418
419NAME
420 wic rm - remove files or directories from the vfat or ext* partitions
421
422SYNOPSIS
423 wic rm <src> <image>:<partition><path>
424 wic rm <src> <image>:<partition><path> --native-sysroot <path>
Brad Bishop6dbb3162019-11-25 09:41:34 -0500425 wic rm -r <image>:<partition><path>
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500426
427DESCRIPTION
428 This command removes files or directories from the vfat or ext* partition of the
429 partitioned image:
430
431 $ wic ls ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
432 Volume in drive : is boot
433 Volume Serial Number is 11D0-DE21
434 Directory for ::/
435
436 libcom32 c32 186500 2017-06-02 15:15
437 libutil c32 24148 2017-06-02 15:15
438 syslinux cfg 209 2017-06-02 15:15
439 vesamenu c32 27104 2017-06-02 15:15
440 vmlinuz 6926384 2017-06-02 15:15
441 5 files 7 164 345 bytes
442 16 582 656 bytes free
443
444 $ wic rm ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/libutil.c32
445
446 $ wic ls ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
447 Volume in drive : is boot
448 Volume Serial Number is 11D0-DE21
449 Directory for ::/
450
451 libcom32 c32 186500 2017-06-02 15:15
452 syslinux cfg 209 2017-06-02 15:15
453 vesamenu c32 27104 2017-06-02 15:15
454 vmlinuz 6926384 2017-06-02 15:15
455 4 files 7 140 197 bytes
456 16 607 232 bytes free
457
458 The -n option is used to specify the path to the native sysroot
459 containing the tools(parted and mtools) to use.
Brad Bishop6dbb3162019-11-25 09:41:34 -0500460
461 The -r option is used to remove directories and their contents
462 recursively,this only applies to ext* partition.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500463"""
464
465wic_write_usage = """
466
467 Write image to a device
468
469 usage: wic write <image> <target device> [--expand [rules]] [--native-sysroot <path>]
470
471 This command writes partitioned image to a target device (USB stick, SD card etc).
472
473 See 'wic help write' for more detailed instructions.
474
475"""
476
477wic_write_help = """
478
479NAME
480 wic write - write an image to a device
481
482SYNOPSIS
483 wic write <image> <target>
484 wic write <image> <target> --expand auto
Brad Bishop64c979e2019-11-04 13:55:29 -0500485 wic write <image> <target> --expand 1:100M,2:300M
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500486 wic write <image> <target> --native-sysroot <path>
487
488DESCRIPTION
489 This command writes an image to a target device (USB stick, SD card etc)
490
491 $ wic write ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic /dev/sdb
492
493 The --expand option is used to resize image partitions.
494 --expand auto expands partitions to occupy all free space available on the target device.
495 It's also possible to specify expansion rules in a format
Brad Bishop64c979e2019-11-04 13:55:29 -0500496 <partition>:<size>[,<partition>:<size>...] for one or more partitions.
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500497 Specifying size 0 will keep partition unmodified.
498 Note: Resizing boot partition can result in non-bootable image for non-EFI images. It is
499 recommended to use size 0 for boot partition to keep image bootable.
500
501 The --native-sysroot option is used to specify the path to the native sysroot
502 containing the tools(parted, resize2fs) to use.
503"""
504
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500505wic_plugins_help = """
506
507NAME
508 wic plugins - Overview and API
509
510DESCRIPTION
511 plugins allow wic functionality to be extended and specialized by
512 users. This section documents the plugin interface, which is
513 currently restricted to 'source' plugins.
514
515 'Source' plugins provide a mechanism to customize various aspects
516 of the image generation process in wic, mainly the contents of
517 partitions.
518
519 Source plugins provide a mechanism for mapping values specified in
520 .wks files using the --source keyword to a particular plugin
521 implementation that populates a corresponding partition.
522
523 A source plugin is created as a subclass of SourcePlugin (see
524 scripts/lib/wic/pluginbase.py) and the plugin file containing it
525 is added to scripts/lib/wic/plugins/source/ to make the plugin
526 implementation available to the wic implementation.
527
528 Source plugins can also be implemented and added by external
529 layers - any plugins found in a scripts/lib/wic/plugins/source/
530 directory in an external layer will also be made available.
531
532 When the wic implementation needs to invoke a partition-specific
533 implementation, it looks for the plugin that has the same name as
534 the --source param given to that partition. For example, if the
535 partition is set up like this:
536
537 part /boot --source bootimg-pcbios ...
538
539 then the methods defined as class members of the plugin having the
540 matching bootimg-pcbios .name class member would be used.
541
542 To be more concrete, here's the plugin definition that would match
543 a '--source bootimg-pcbios' usage, along with an example method
544 that would be called by the wic implementation when it needed to
545 invoke an implementation-specific partition-preparation function:
546
547 class BootimgPcbiosPlugin(SourcePlugin):
548 name = 'bootimg-pcbios'
549
550 @classmethod
551 def do_prepare_partition(self, part, ...)
552
553 If the subclass itself doesn't implement a function, a 'default'
554 version in a superclass will be located and used, which is why all
555 plugins must be derived from SourcePlugin.
556
557 The SourcePlugin class defines the following methods, which is the
558 current set of methods that can be implemented/overridden by
559 --source plugins. Any methods not implemented by a SourcePlugin
560 subclass inherit the implementations present in the SourcePlugin
561 class (see the SourcePlugin source for details):
562
563 do_prepare_partition()
564 Called to do the actual content population for a
565 partition. In other words, it 'prepares' the final partition
566 image which will be incorporated into the disk image.
567
Brad Bishop316dfdd2018-06-25 12:45:53 -0400568 do_post_partition()
569 Called after the partition is created. It is useful to add post
570 operations e.g. signing the partition.
571
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500572 do_configure_partition()
573 Called before do_prepare_partition(), typically used to
574 create custom configuration files for a partition, for
575 example syslinux or grub config files.
576
577 do_install_disk()
578 Called after all partitions have been prepared and assembled
579 into a disk image. This provides a hook to allow
580 finalization of a disk image, for example to write an MBR to
581 it.
582
583 do_stage_partition()
584 Special content-staging hook called before
585 do_prepare_partition(), normally empty.
586
587 Typically, a partition will just use the passed-in
588 parameters, for example the unmodified value of bootimg_dir.
589 In some cases however, things may need to be more tailored.
590 As an example, certain files may additionally need to be
591 take from bootimg_dir + /boot. This hook allows those files
592 to be staged in a customized fashion. Note that
593 get_bitbake_var() allows you to access non-standard
594 variables that you might want to use for these types of
595 situations.
596
597 This scheme is extensible - adding more hooks is a simple matter
598 of adding more plugin methods to SourcePlugin and derived classes.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500599 Please see the implementation for details.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500600"""
601
602wic_overview_help = """
603
604NAME
605 wic overview - General overview of wic
606
607DESCRIPTION
608 The 'wic' command generates partitioned images from existing
609 OpenEmbedded build artifacts. Image generation is driven by
610 partitioning commands contained in an 'Openembedded kickstart'
611 (.wks) file (see 'wic help kickstart') specified either directly
612 on the command-line or as one of a selection of canned .wks files
613 (see 'wic list images'). When applied to a given set of build
614 artifacts, the result is an image or set of images that can be
615 directly written onto media and used on a particular system.
616
617 The 'wic' command and the infrastructure it's based on is by
618 definition incomplete - its purpose is to allow the generation of
619 customized images, and as such was designed to be completely
620 extensible via a plugin interface (see 'wic help plugins').
621
622 Background and Motivation
623
624 wic is meant to be a completely independent standalone utility
625 that initially provides easier-to-use and more flexible
626 replacements for a couple bits of existing functionality in
627 oe-core: directdisk.bbclass and mkefidisk.sh. The difference
628 between wic and those examples is that with wic the functionality
629 of those scripts is implemented by a general-purpose partitioning
630 'language' based on Redhat kickstart syntax).
631
632 The initial motivation and design considerations that lead to the
633 current tool are described exhaustively in Yocto Bug #3847
634 (https://bugzilla.yoctoproject.org/show_bug.cgi?id=3847).
635
636 Implementation and Examples
637
638 wic can be used in two different modes, depending on how much
639 control the user needs in specifying the Openembedded build
640 artifacts that will be used in creating the image: 'raw' and
641 'cooked'.
642
643 If used in 'raw' mode, artifacts are explicitly specified via
644 command-line arguments (see example below).
645
646 The more easily usable 'cooked' mode uses the current MACHINE
647 setting and a specified image name to automatically locate the
648 artifacts used to create the image.
649
650 OE kickstart files (.wks) can of course be specified directly on
651 the command-line, but the user can also choose from a set of
652 'canned' .wks files available via the 'wic list images' command
653 (example below).
654
655 In any case, the prerequisite for generating any image is to have
656 the build artifacts already available. The below examples assume
657 the user has already build a 'core-image-minimal' for a specific
658 machine (future versions won't require this redundant step, but
659 for now that's typically how build artifacts get generated).
660
661 The other prerequisite is to source the build environment:
662
663 $ source oe-init-build-env
664
665 To start out with, we'll generate an image from one of the canned
666 .wks files. The following generates a list of availailable
667 images:
668
669 $ wic list images
670 mkefidisk Create an EFI disk image
671 directdisk Create a 'pcbios' direct disk image
672
673 You can get more information about any of the available images by
674 typing 'wic list xxx help', where 'xxx' is one of the image names:
675
676 $ wic list mkefidisk help
677
678 Creates a partitioned EFI disk image that the user can directly dd
679 to boot media.
680
681 At any time, you can get help on the 'wic' command or any
682 subcommand (currently 'list' and 'create'). For instance, to get
683 the description of 'wic create' command and its parameters:
684
685 $ wic create
686
687 Usage:
688
689 Create a new OpenEmbedded image
690
691 usage: wic create <wks file or image name> [-o <DIRNAME> | ...]
692 [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
693 [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
694 [-r, --rootfs-dir] [-b, --bootimg-dir] [-k, --kernel-dir]
695 [-n, --native-sysroot] [-f, --build-rootfs]
696
697 This command creates an OpenEmbedded image based on the 'OE
698 kickstart commands' found in the <wks file>.
699
700 The -o option can be used to place the image in a directory
701 with a different name and location.
702
703 See 'wic help create' for more detailed instructions.
704 ...
705
706 As mentioned in the command, you can get even more detailed
707 information by adding 'help' to the above:
708
709 $ wic help create
710
711 So, the easiest way to create an image is to use the -e option
712 with a canned .wks file. To use the -e option, you need to
713 specify the image used to generate the artifacts and you actually
714 need to have the MACHINE used to build them specified in your
715 local.conf (these requirements aren't necessary if you aren't
716 using the -e options.) Below, we generate a directdisk image,
717 pointing the process at the core-image-minimal artifacts for the
718 current MACHINE:
719
720 $ wic create directdisk -e core-image-minimal
721
722 Checking basic build environment...
723 Done.
724
725 Creating image(s)...
726
727 Info: The new image(s) can be found here:
728 /var/tmp/wic/build/directdisk-201309252350-sda.direct
729
730 The following build artifacts were used to create the image(s):
731
732 ROOTFS_DIR: ...
733 BOOTIMG_DIR: ...
734 KERNEL_DIR: ...
735 NATIVE_SYSROOT: ...
736
737 The image(s) were created using OE kickstart file:
738 .../scripts/lib/wic/canned-wks/directdisk.wks
739
740 The output shows the name and location of the image created, and
741 so that you know exactly what was used to generate the image, each
742 of the artifacts and the kickstart file used.
743
744 Similarly, you can create a 'mkefidisk' image in the same way
745 (notice that this example uses a different machine - because it's
746 using the -e option, you need to change the MACHINE in your
747 local.conf):
748
749 $ wic create mkefidisk -e core-image-minimal
750 Checking basic build environment...
751 Done.
752
753 Creating image(s)...
754
755 Info: The new image(s) can be found here:
756 /var/tmp/wic/build/mkefidisk-201309260027-sda.direct
757
758 ...
759
760 Here's an example that doesn't take the easy way out and manually
761 specifies each build artifact, along with a non-canned .wks file,
762 and also uses the -o option to have wic create the output
763 somewhere other than the default /var/tmp/wic:
764
765 $ wic create ./test.wks -o ./out --rootfs-dir
766 tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/rootfs
767 --bootimg-dir tmp/sysroots/qemux86-64/usr/share
768 --kernel-dir tmp/deploy/images/qemux86-64
769 --native-sysroot tmp/sysroots/x86_64-linux
770
771 Creating image(s)...
772
773 Info: The new image(s) can be found here:
774 out/build/test-201507211313-sda.direct
775
776 The following build artifacts were used to create the image(s):
777 ROOTFS_DIR: tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/rootfs
778 BOOTIMG_DIR: tmp/sysroots/qemux86-64/usr/share
779 KERNEL_DIR: tmp/deploy/images/qemux86-64
780 NATIVE_SYSROOT: tmp/sysroots/x86_64-linux
781
782 The image(s) were created using OE kickstart file:
783 ./test.wks
784
785 Here is a content of test.wks:
786
787 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
788 part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024
789
790 bootloader --timeout=0 --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0"
791
792
793 Finally, here's an example of the actual partition language
794 commands used to generate the mkefidisk image i.e. these are the
795 contents of the mkefidisk.wks OE kickstart file:
796
797 # short-description: Create an EFI disk image
798 # long-description: Creates a partitioned EFI disk image that the user
799 # can directly dd to boot media.
800
801 part /boot --source bootimg-efi --ondisk sda --fstype=efi --active
802
803 part / --source rootfs --ondisk sda --fstype=ext3 --label platform
804
805 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
806
807 bootloader --timeout=10 --append="rootwait console=ttyPCH0,115200"
808
809 You can get a complete listing and description of all the
810 kickstart commands available for use in .wks files from 'wic help
811 kickstart'.
812"""
813
814wic_kickstart_help = """
815
816NAME
817 wic kickstart - wic kickstart reference
818
819DESCRIPTION
820 This section provides the definitive reference to the wic
821 kickstart language. It also provides documentation on the list of
822 --source plugins available for use from the 'part' command (see
823 the 'Platform-specific Plugins' section below).
824
825 The current wic implementation supports only the basic kickstart
826 partitioning commands: partition (or part for short) and
827 bootloader.
828
829 The following is a listing of the commands, their syntax, and
830 meanings. The commands are based on the Fedora kickstart
831 documentation but with modifications to reflect wic capabilities.
832
833 http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition
834 http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader
835
836 Commands
837
838 * 'part' or 'partition'
839
840 This command creates a partition on the system and uses the
841 following syntax:
842
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500843 part [<mountpoint>]
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500844
845 The <mountpoint> is where the partition will be mounted and
846 must take of one of the following forms:
847
848 /<path>: For example: /, /usr, or /home
849
850 swap: The partition will be used as swap space.
851
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500852 If a <mountpoint> is not specified the partition will be created
853 but will not be mounted.
854
855 Partitions with a <mountpoint> specified will be automatically mounted.
856 This is achieved by wic adding entries to the fstab during image
857 generation. In order for a valid fstab to be generated one of the
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800858 --ondrive, --ondisk, --use-uuid or --use-label partition options must
859 be used for each partition that specifies a mountpoint. Note that with
860 --use-{uuid,label} and non-root <mountpoint>, including swap, the mount
861 program must understand the PARTUUID or LABEL syntax. This currently
862 excludes the busybox versions of these applications.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500863
864
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500865 The following are supported 'part' options:
866
867 --size: The minimum partition size. Specify an integer value
868 such as 500. Multipliers k, M ang G can be used. If
869 not specified, the size is in MB.
870 You do not need this option if you use --source.
871
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500872 --fixed-size: Exact partition size. Value format is the same
873 as for --size option. This option cannot be
874 specified along with --size. If partition data
875 is larger than --fixed-size and error will be
876 raised when assembling disk image.
877
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500878 --source: This option is a wic-specific option that names the
879 source of the data that will populate the
880 partition. The most common value for this option
881 is 'rootfs', but can be any value which maps to a
882 valid 'source plugin' (see 'wic help plugins').
883
884 If '--source rootfs' is used, it tells the wic
885 command to create a partition as large as needed
886 and to fill it with the contents of the root
887 filesystem pointed to by the '-r' wic command-line
888 option (or the equivalent rootfs derived from the
889 '-e' command-line option). The filesystem type
890 that will be used to create the partition is driven
891 by the value of the --fstype option specified for
892 the partition (see --fstype below).
893
894 If --source <plugin-name>' is used, it tells the
895 wic command to create a partition as large as
896 needed and to fill with the contents of the
897 partition that will be generated by the specified
898 plugin name using the data pointed to by the '-r'
899 wic command-line option (or the equivalent rootfs
900 derived from the '-e' command-line option).
901 Exactly what those contents and filesystem type end
902 up being are dependent on the given plugin
903 implementation.
904
905 If --source option is not used, the wic command
906 will create empty partition. --size parameter has
907 to be used to specify size of empty partition.
908
909 --ondisk or --ondrive: Forces the partition to be created on
910 a particular disk.
911
912 --fstype: Sets the file system type for the partition. These
913 apply to partitions created using '--source rootfs' (see
914 --source above). Valid values are:
915
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500916 vfat
917 msdos
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500918 ext2
919 ext3
920 ext4
921 btrfs
922 squashfs
923 swap
924
925 --fsoptions: Specifies a free-form string of options to be
926 used when mounting the filesystem. This string
927 will be copied into the /etc/fstab file of the
928 installed system and should be enclosed in
929 quotes. If not specified, the default string is
930 "defaults".
931
932 --label label: Specifies the label to give to the filesystem
933 to be made on the partition. If the given
934 label is already in use by another filesystem,
935 a new label is created for the partition.
936
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800937 --use-label: This option is specific to wic. It makes wic to use the
938 label in /etc/fstab to specify a partition. If the
939 --use-label and --use-uuid are used at the same time,
940 we prefer the uuid because it is less likely to cause
941 name confliction. We don't support using this parameter
942 on the root partition since it requires an initramfs to
943 parse this value and we do not currently support that.
944
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500945 --active: Marks the partition as active.
946
947 --align (in KBytes): This option is specific to wic and says
948 to start a partition on an x KBytes
949 boundary.
950
951 --no-table: This option is specific to wic. Space will be
952 reserved for the partition and it will be
953 populated but it will not be added to the
954 partition table. It may be useful for
955 bootloaders.
956
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500957 --exclude-path: This option is specific to wic. It excludes the given
958 relative path from the resulting image. If the path
959 ends with a slash, only the content of the directory
960 is omitted, not the directory itself. This option only
961 has an effect with the rootfs source plugin.
962
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500963 --extra-space: This option is specific to wic. It adds extra
964 space after the space filled by the content
965 of the partition. The final size can go
966 beyond the size specified by --size.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500967 By default, 10MB. This option cannot be used
968 with --fixed-size option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500969
970 --overhead-factor: This option is specific to wic. The
971 size of the partition is multiplied by
972 this factor. It has to be greater than or
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500973 equal to 1. The default value is 1.3.
974 This option cannot be used with --fixed-size
975 option.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500976
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500977 --part-name: This option is specific to wic. It specifies name for GPT partitions.
978
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500979 --part-type: This option is specific to wic. It specifies partition
980 type GUID for GPT partitions.
981 List of partition type GUIDS can be found here:
982 http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs
983
984 --use-uuid: This option is specific to wic. It makes wic to generate
985 random globally unique identifier (GUID) for the partition
986 and use it in bootloader configuration to specify root partition.
987
988 --uuid: This option is specific to wic. It specifies partition UUID.
989 It's useful if preconfigured partition UUID is added to kernel command line
990 in bootloader configuration before running wic. In this case .wks file can
991 be generated or modified to set preconfigured parition UUID using this option.
992
Brad Bishop316dfdd2018-06-25 12:45:53 -0400993 --fsuuid: This option is specific to wic. It specifies filesystem UUID.
994 It's useful if preconfigured filesystem UUID is added to kernel command line
995 in bootloader configuration before running wic. In this case .wks file can
996 be generated or modified to set preconfigured filesystem UUID using this option.
997
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600998 --system-id: This option is specific to wic. It specifies partition system id. It's useful
999 for the harware that requires non-default partition system ids. The parameter
1000 in one byte long hex number either with 0x prefix or without it.
1001
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001002 --mkfs-extraopts: This option specifies extra options to pass to mkfs utility.
1003 NOTE, that wic uses default options for some filesystems, for example
1004 '-S 512' for mkfs.fat or '-F -i 8192' for mkfs.ext. Those options will
1005 not take effect when --mkfs-extraopts is used. This should be taken into
1006 account when using --mkfs-extraopts.
1007
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001008 * bootloader
1009
1010 This command allows the user to specify various bootloader
1011 options. The following are supported 'bootloader' options:
1012
1013 --timeout: Specifies the number of seconds before the
1014 bootloader times out and boots the default option.
1015
1016 --append: Specifies kernel parameters. These will be added to
1017 bootloader command-line - for example, the syslinux
1018 APPEND or grub kernel command line.
1019
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001020 --configfile: Specifies a user defined configuration file for
1021 the bootloader. This file must be located in the
1022 canned-wks folder or could be the full path to the
1023 file. Using this option will override any other
1024 bootloader option.
1025
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001026 Note that bootloader functionality and boot partitions are
1027 implemented by the various --source plugins that implement
1028 bootloader functionality; the bootloader command essentially
1029 provides a means of modifying bootloader configuration.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001030
1031 * include
1032
1033 This command allows the user to include the content of .wks file
1034 into original .wks file.
1035
1036 Command uses the following syntax:
1037
1038 include <file>
1039
1040 The <file> is either path to the file or its name. If name is
1041 specified wic will try to find file in the directories with canned
1042 .wks files.
1043
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001044"""
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001045
1046wic_help_help = """
1047NAME
1048 wic help - display a help topic
1049
1050DESCRIPTION
1051 Specify a help topic to display it. Topics are shown above.
1052"""
Brad Bishop1d80a2e2019-11-15 16:35:03 -05001053
1054
1055wic_help = """
1056Creates a customized OpenEmbedded image.
1057
1058Usage: wic [--version]
1059 wic help [COMMAND or TOPIC]
1060 wic COMMAND [ARGS]
1061
1062 usage 1: Returns the current version of Wic
1063 usage 2: Returns detailed help for a COMMAND or TOPIC
1064 usage 3: Executes COMMAND
1065
1066
1067COMMAND:
1068
1069 list - List available canned images and source plugins
1070 ls - List contents of partitioned image or partition
1071 rm - Remove files or directories from the vfat or ext* partitions
1072 help - Show help for a wic COMMAND or TOPIC
1073 write - Write an image to a device
1074 cp - Copy files and directories to the vfat or ext* partitions
1075 create - Create a new OpenEmbedded image
1076
1077
1078TOPIC:
1079 overview - Presents an overall overview of Wic
1080 plugins - Presents an overview and API for Wic plugins
1081 kickstart - Presents a Wic kicstart file reference
1082
1083
1084Examples:
1085
1086 $ wic --version
1087
1088 Returns the current version of Wic
1089
1090
1091 $ wic help cp
1092
1093 Returns the SYNOPSIS and DESCRIPTION for the Wic "cp" command.
1094
1095
1096 $ wic list images
1097
1098 Returns the list of canned images (i.e. *.wks files located in
1099 the /scripts/lib/wic/canned-wks directory.
1100
1101
1102 $ wic create mkefidisk -e core-image-minimal
1103
1104 Creates an EFI disk image from artifacts used in a previous
1105 core-image-minimal build in standard BitBake locations
1106 (e.g. Cooked Mode).
1107
1108"""