summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic')
-rw-r--r--scripts/lib/wic/canned-wks/directdisk-gpt.wks10
-rw-r--r--scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks23
-rw-r--r--scripts/lib/wic/canned-wks/directdisk.wks10
-rw-r--r--scripts/lib/wic/canned-wks/mkefidisk.wks11
-rw-r--r--scripts/lib/wic/canned-wks/mkgummidisk.wks11
-rw-r--r--scripts/lib/wic/canned-wks/mkhybridiso.wks7
-rw-r--r--scripts/lib/wic/canned-wks/qemux86-directdisk.wks10
-rw-r--r--scripts/lib/wic/canned-wks/sdimage-bootpart.wks6
-rw-r--r--scripts/lib/wic/config/wic.conf6
-rw-r--r--scripts/lib/wic/engine.py241
-rw-r--r--scripts/lib/wic/help.py826
11 files changed, 1161 insertions, 0 deletions
diff --git a/scripts/lib/wic/canned-wks/directdisk-gpt.wks b/scripts/lib/wic/canned-wks/directdisk-gpt.wks
new file mode 100644
index 0000000000..ea01cf3752
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/directdisk-gpt.wks
@@ -0,0 +1,10 @@
1# short-description: Create a 'pcbios' direct disk image
2# long-description: Creates a partitioned legacy BIOS disk image that the user
3# can directly dd to boot media.
4
5
6part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024 --use-uuid
8
9bootloader --ptable gpt --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0"
10
diff --git a/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks b/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks
new file mode 100644
index 0000000000..8a81f8f519
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/directdisk-multi-rootfs.wks
@@ -0,0 +1,23 @@
1# short-description: Create multi rootfs image using rootfs plugin
2# long-description: Creates a partitioned disk image with two rootfs partitions
3# using rootfs plugin.
4#
5# Partitions can use either
6# - indirect rootfs references to image recipe(s):
7# wic create directdisk-multi-indirect-recipes -e core-image-minimal \
8# --rootfs-dir rootfs1=core-image-minimal
9# --rootfs-dir rootfs2=core-image-minimal-dev
10#
11# - or paths to rootfs directories:
12# wic create directdisk-multi-rootfs \
13# --rootfs-dir rootfs1=tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/rootfs/
14# --rootfs-dir rootfs2=tmp/work/qemux86_64-poky-linux/core-image-minimal-dev/1.0-r0/rootfs/
15#
16# - or any combinations of -r and --rootfs command line options
17
18part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
19part / --source rootfs --rootfs-dir=rootfs1 --ondisk sda --fstype=ext4 --label platform --align 1024
20part /rescue --source rootfs --rootfs-dir=rootfs2 --ondisk sda --fstype=ext4 --label secondary --align 1024
21
22bootloader --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0"
23
diff --git a/scripts/lib/wic/canned-wks/directdisk.wks b/scripts/lib/wic/canned-wks/directdisk.wks
new file mode 100644
index 0000000000..af4c9eadaf
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/directdisk.wks
@@ -0,0 +1,10 @@
1# short-description: Create a 'pcbios' direct disk image
2# long-description: Creates a partitioned legacy BIOS disk image that the user
3# can directly dd to boot media.
4
5
6part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
8
9bootloader --timeout=0 --append="rootwait rootfstype=ext4 video=vesafb vga=0x318 console=tty0"
10
diff --git a/scripts/lib/wic/canned-wks/mkefidisk.wks b/scripts/lib/wic/canned-wks/mkefidisk.wks
new file mode 100644
index 0000000000..696e94e3d7
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/mkefidisk.wks
@@ -0,0 +1,11 @@
1# short-description: Create an EFI disk image
2# long-description: Creates a partitioned EFI disk image that the user
3# can directly dd to boot media.
4
5part /boot --source bootimg-efi --sourceparams="loader=grub-efi" --ondisk sda --label msdos --active --align 1024
6
7part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
8
9part swap --ondisk sda --size 44 --label swap1 --fstype=swap
10
11bootloader --timeout=10 --append="rootwait rootfstype=ext4 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0"
diff --git a/scripts/lib/wic/canned-wks/mkgummidisk.wks b/scripts/lib/wic/canned-wks/mkgummidisk.wks
new file mode 100644
index 0000000000..66a22f60bd
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/mkgummidisk.wks
@@ -0,0 +1,11 @@
1# short-description: Create an EFI disk image
2# long-description: Creates a partitioned EFI disk image that the user
3# can directly dd to boot media.
4
5part /boot --source bootimg-efi --sourceparams="loader=gummiboot" --ondisk sda --label msdos --active --align 1024
6
7part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
8
9part swap --ondisk sda --size 44 --label swap1 --fstype=swap
10
11bootloader --timeout=10 --append="rootwait rootfstype=ext4 console=ttyPCH0,115200 console=tty0 vmalloc=256MB snd-hda-intel.enable_msi=0"
diff --git a/scripts/lib/wic/canned-wks/mkhybridiso.wks b/scripts/lib/wic/canned-wks/mkhybridiso.wks
new file mode 100644
index 0000000000..9d34e9b477
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/mkhybridiso.wks
@@ -0,0 +1,7 @@
1# short-description: Create a hybrid ISO image
2# long-description: Creates an EFI and legacy bootable hybrid ISO image
3# which can be used on optical media as well as USB media.
4
5part /boot --source isoimage-isohybrid --sourceparams="loader=grub-efi,image_name=HYBRID_ISO_IMG" --ondisk cd --label HYBRIDISO --fstype=ext4
6
7bootloader --timeout=15 --append=""
diff --git a/scripts/lib/wic/canned-wks/qemux86-directdisk.wks b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks
new file mode 100644
index 0000000000..8fc38b54d0
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks
@@ -0,0 +1,10 @@
1# short-description: Create a qemu machine 'pcbios' direct disk image
2# long-description: Creates a partitioned legacy BIOS disk image that the user
3# can directly use to boot a qemu machine.
4
5
6part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
7part / --source rootfs --ondisk sda --fstype=ext4 --label platform --align 1024
8
9bootloader --timeout=0 --append="vga=0 uvesafb.mode_option=640x480-32 root=/dev/vda2 rw mem=256M ip=192.168.7.2::192.168.7.1:255.255.255.0 oprofile.timer=1 rootfstype=ext4 "
10
diff --git a/scripts/lib/wic/canned-wks/sdimage-bootpart.wks b/scripts/lib/wic/canned-wks/sdimage-bootpart.wks
new file mode 100644
index 0000000000..7ffd632f4a
--- /dev/null
+++ b/scripts/lib/wic/canned-wks/sdimage-bootpart.wks
@@ -0,0 +1,6 @@
1# short-description: Create SD card image with a boot partition
2# long-description: Creates a partitioned SD card image. Boot files
3# are located in the first vfat partition.
4
5part /boot --source bootimg-partition --ondisk mmcblk --fstype=vfat --label boot --active --align 4 --size 16
6part / --source rootfs --ondisk mmcblk --fstype=ext4 --label root --align 4
diff --git a/scripts/lib/wic/config/wic.conf b/scripts/lib/wic/config/wic.conf
new file mode 100644
index 0000000000..a51bcb55eb
--- /dev/null
+++ b/scripts/lib/wic/config/wic.conf
@@ -0,0 +1,6 @@
1[common]
2; general settings
3distro_name = OpenEmbedded
4
5[create]
6; settings for create subcommand
diff --git a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py
new file mode 100644
index 0000000000..a034841a7a
--- /dev/null
+++ b/scripts/lib/wic/engine.py
@@ -0,0 +1,241 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# Copyright (c) 2013, Intel Corporation.
5# All rights reserved.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# DESCRIPTION
21
22# This module implements the image creation engine used by 'wic' to
23# create images. The engine parses through the OpenEmbedded kickstart
24# (wks) file specified and generates images that can then be directly
25# written onto media.
26#
27# AUTHORS
28# Tom Zanussi <tom.zanussi (at] linux.intel.com>
29#
30
31import os
32import sys
33
34from wic import msger, creator
35from wic.utils import misc
36from wic.plugin import pluginmgr
37from wic.utils.oe import misc
38
39
40def verify_build_env():
41 """
42 Verify that the build environment is sane.
43
44 Returns True if it is, false otherwise
45 """
46 try:
47 builddir = os.environ["BUILDDIR"]
48 except KeyError:
49 print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
50 sys.exit(1)
51
52 return True
53
54
55CANNED_IMAGE_DIR = "lib/wic/canned-wks" # relative to scripts
56SCRIPTS_CANNED_IMAGE_DIR = "scripts/" + CANNED_IMAGE_DIR
57
58def build_canned_image_list(dl):
59 layers_path = misc.get_bitbake_var("BBLAYERS")
60 canned_wks_layer_dirs = []
61
62 if layers_path is not None:
63 for layer_path in layers_path.split():
64 path = os.path.join(layer_path, SCRIPTS_CANNED_IMAGE_DIR)
65 canned_wks_layer_dirs.append(path)
66
67 path = os.path.join(dl, CANNED_IMAGE_DIR)
68 canned_wks_layer_dirs.append(path)
69
70 return canned_wks_layer_dirs
71
72def find_canned_image(scripts_path, wks_file):
73 """
74 Find a .wks file with the given name in the canned files dir.
75
76 Return False if not found
77 """
78 layers_canned_wks_dir = build_canned_image_list(scripts_path)
79
80 for canned_wks_dir in layers_canned_wks_dir:
81 for root, dirs, files in os.walk(canned_wks_dir):
82 for file in files:
83 if file.endswith("~") or file.endswith("#"):
84 continue
85 if file.endswith(".wks") and wks_file + ".wks" == file:
86 fullpath = os.path.join(canned_wks_dir, file)
87 return fullpath
88 return None
89
90
91def list_canned_images(scripts_path):
92 """
93 List the .wks files in the canned image dir, minus the extension.
94 """
95 layers_canned_wks_dir = build_canned_image_list(scripts_path)
96
97 for canned_wks_dir in layers_canned_wks_dir:
98 for root, dirs, files in os.walk(canned_wks_dir):
99 for file in files:
100 if file.endswith("~") or file.endswith("#"):
101 continue
102 if file.endswith(".wks"):
103 fullpath = os.path.join(canned_wks_dir, file)
104 f = open(fullpath, "r")
105 lines = f.readlines()
106 for line in lines:
107 desc = ""
108 idx = line.find("short-description:")
109 if idx != -1:
110 desc = line[idx + len("short-description:"):].strip()
111 break
112 basename = os.path.splitext(file)[0]
113 print " %s\t\t%s" % (basename.ljust(30), desc)
114
115
116def list_canned_image_help(scripts_path, fullpath):
117 """
118 List the help and params in the specified canned image.
119 """
120 f = open(fullpath, "r")
121 lines = f.readlines()
122 found = False
123 for line in lines:
124 if not found:
125 idx = line.find("long-description:")
126 if idx != -1:
127 print
128 print line[idx + len("long-description:"):].strip()
129 found = True
130 continue
131 if not line.strip():
132 break
133 idx = line.find("#")
134 if idx != -1:
135 print line[idx + len("#:"):].rstrip()
136 else:
137 break
138
139
140def list_source_plugins():
141 """
142 List the available source plugins i.e. plugins available for --source.
143 """
144 plugins = pluginmgr.get_source_plugins()
145
146 for plugin in plugins:
147 print " %s" % plugin
148
149
150def wic_create(wks_file, rootfs_dir, bootimg_dir, kernel_dir,
151 native_sysroot, scripts_path, image_output_dir,
152 compressor, debug):
153 """Create image
154
155 wks_file - user-defined OE kickstart file
156 rootfs_dir - absolute path to the build's /rootfs dir
157 bootimg_dir - absolute path to the build's boot artifacts directory
158 kernel_dir - absolute path to the build's kernel directory
159 native_sysroot - absolute path to the build's native sysroots dir
160 scripts_path - absolute path to /scripts dir
161 image_output_dir - dirname to create for image
162 compressor - compressor utility to compress the image
163
164 Normally, the values for the build artifacts values are determined
165 by 'wic -e' from the output of the 'bitbake -e' command given an
166 image name e.g. 'core-image-minimal' and a given machine set in
167 local.conf. If that's the case, the variables get the following
168 values from the output of 'bitbake -e':
169
170 rootfs_dir: IMAGE_ROOTFS
171 kernel_dir: DEPLOY_DIR_IMAGE
172 native_sysroot: STAGING_DIR_NATIVE
173
174 In the above case, bootimg_dir remains unset and the
175 plugin-specific image creation code is responsible for finding the
176 bootimg artifacts.
177
178 In the case where the values are passed in explicitly i.e 'wic -e'
179 is not used but rather the individual 'wic' options are used to
180 explicitly specify these values.
181 """
182 try:
183 oe_builddir = os.environ["BUILDDIR"]
184 except KeyError:
185 print "BUILDDIR not found, exiting. (Did you forget to source oe-init-build-env?)"
186 sys.exit(1)
187
188 if debug:
189 msger.set_loglevel('debug')
190
191 cr = creator.Creator()
192
193 cr.main(["direct", native_sysroot, kernel_dir, bootimg_dir, rootfs_dir,
194 wks_file, image_output_dir, oe_builddir, compressor or ""])
195
196 print "\nThe image(s) were created using OE kickstart file:\n %s" % wks_file
197
198
199def wic_list(args, scripts_path, properties_file):
200 """
201 Print the complete list of properties defined by the image, or the
202 possible values for a particular image property.
203 """
204 if len(args) < 1:
205 return False
206
207 if len(args) == 1:
208 if args[0] == "images":
209 list_canned_images(scripts_path)
210 return True
211 elif args[0] == "source-plugins":
212 list_source_plugins()
213 return True
214 elif args[0] == "properties":
215 return True
216 else:
217 return False
218
219 if len(args) == 2:
220 if args[0] == "properties":
221 wks_file = args[1]
222 print "print properties contained in wks file: %s" % wks_file
223 return True
224 elif args[0] == "property":
225 print "print property values for property: %s" % args[1]
226 return True
227 elif args[1] == "help":
228 wks_file = args[0]
229 fullpath = find_canned_image(scripts_path, wks_file)
230 if not fullpath:
231 print "No image named %s found, exiting. "\
232 "(Use 'wic list images' to list available images, or "\
233 "specify a fully-qualified OE kickstart (.wks) "\
234 "filename)\n" % wks_file
235 sys.exit(1)
236 list_canned_image_help(scripts_path, fullpath)
237 return True
238 else:
239 return False
240
241 return False
diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
new file mode 100644
index 0000000000..cd2176d151
--- /dev/null
+++ b/scripts/lib/wic/help.py
@@ -0,0 +1,826 @@
1# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# Copyright (c) 2013, Intel Corporation.
5# All rights reserved.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2 as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# DESCRIPTION
21# This module implements some basic help invocation functions along
22# with the bulk of the help topic text for the OE Core Image Tools.
23#
24# AUTHORS
25# Tom Zanussi <tom.zanussi (at] linux.intel.com>
26#
27
28import subprocess
29import logging
30
31from wic.plugin import pluginmgr, PLUGIN_TYPES
32
33def subcommand_error(args):
34 logging.info("invalid subcommand %s" % args[0])
35
36
37def display_help(subcommand, subcommands):
38 """
39 Display help for subcommand.
40 """
41 if subcommand not in subcommands:
42 return False
43
44 hlp = subcommands.get(subcommand, subcommand_error)[2]
45 if callable(hlp):
46 hlp = hlp()
47 pager = subprocess.Popen('less', stdin=subprocess.PIPE)
48 pager.communicate(hlp)
49
50 return True
51
52
53def wic_help(args, usage_str, subcommands):
54 """
55 Subcommand help dispatcher.
56 """
57 if len(args) == 1 or not display_help(args[1], subcommands):
58 print usage_str
59
60
61def get_wic_plugins_help():
62 """
63 Combine wic_plugins_help with the help for every known
64 source plugin.
65 """
66 result = wic_plugins_help
67 for plugin_type in PLUGIN_TYPES:
68 result += '\n\n%s PLUGINS\n\n' % plugin_type.upper()
69 for name, plugin in pluginmgr.get_plugins(plugin_type).iteritems():
70 result += "\n %s plugin:\n" % name
71 if plugin.__doc__:
72 result += plugin.__doc__
73 else:
74 result += "\n %s is missing docstring\n" % plugin
75 return result
76
77
78def invoke_subcommand(args, parser, main_command_usage, subcommands):
79 """
80 Dispatch to subcommand handler borrowed from combo-layer.
81 Should use argparse, but has to work in 2.6.
82 """
83 if not args:
84 logging.error("No subcommand specified, exiting")
85 parser.print_help()
86 return 1
87 elif args[0] == "help":
88 wic_help(args, main_command_usage, subcommands)
89 elif args[0] not in subcommands:
90 logging.error("Unsupported subcommand %s, exiting\n" % (args[0]))
91 parser.print_help()
92 return 1
93 else:
94 usage = subcommands.get(args[0], subcommand_error)[1]
95 subcommands.get(args[0], subcommand_error)[0](args[1:], usage)
96
97
98##
99# wic help and usage strings
100##
101
102wic_usage = """
103
104 Create a customized OpenEmbedded image
105
106 usage: wic [--version] | [--help] | [COMMAND [ARGS]]
107
108 Current 'wic' commands are:
109 help Show help for command or one of the topics (see below)
110 create Create a new OpenEmbedded image
111 list List available values for options and image properties
112
113 Help topics:
114 overview wic overview - General overview of wic
115 plugins wic plugins - Overview and API
116 kickstart wic kickstart - wic kickstart reference
117"""
118
119wic_help_usage = """
120
121 usage: wic help <subcommand>
122
123 This command displays detailed help for the specified subcommand.
124"""
125
126wic_create_usage = """
127
128 Create a new OpenEmbedded image
129
130 usage: wic create <wks file or image name> [-o <DIRNAME> | --outdir <DIRNAME>]
131 [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
132 [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
133 [-r, --rootfs-dir] [-b, --bootimg-dir]
134 [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
135
136 This command creates an OpenEmbedded image based on the 'OE kickstart
137 commands' found in the <wks file>.
138
139 The -o option can be used to place the image in a directory with a
140 different name and location.
141
142 See 'wic help create' for more detailed instructions.
143"""
144
145wic_create_help = """
146
147NAME
148 wic create - Create a new OpenEmbedded image
149
150SYNOPSIS
151 wic create <wks file or image name> [-o <DIRNAME> | --outdir <DIRNAME>]
152 [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
153 [-r, --rootfs-dir] [-b, --bootimg-dir]
154 [-k, --kernel-dir] [-n, --native-sysroot] [-f, --build-rootfs]
155 [-c, --compress-with]
156
157DESCRIPTION
158 This command creates an OpenEmbedded image based on the 'OE
159 kickstart commands' found in the <wks file>.
160
161 In order to do this, wic needs to know the locations of the
162 various build artifacts required to build the image.
163
164 Users can explicitly specify the build artifact locations using
165 the -r, -b, -k, and -n options. See below for details on where
166 the corresponding artifacts are typically found in a normal
167 OpenEmbedded build.
168
169 Alternatively, users can use the -e option to have 'wic' determine
170 those locations for a given image. If the -e option is used, the
171 user needs to have set the appropriate MACHINE variable in
172 local.conf, and have sourced the build environment.
173
174 The -e option is used to specify the name of the image to use the
175 artifacts from e.g. core-image-sato.
176
177 The -r option is used to specify the path to the /rootfs dir to
178 use as the .wks rootfs source.
179
180 The -b option is used to specify the path to the dir containing
181 the boot artifacts (e.g. /EFI or /syslinux dirs) to use as the
182 .wks bootimg source.
183
184 The -k option is used to specify the path to the dir containing
185 the kernel to use in the .wks bootimg.
186
187 The -n option is used to specify the path to the native sysroot
188 containing the tools to use to build the image.
189
190 The -f option is used to build rootfs by running "bitbake <image>"
191
192 The -s option is used to skip the build check. The build check is
193 a simple sanity check used to determine whether the user has
194 sourced the build environment so that the -e option can operate
195 correctly. If the user has specified the build artifact locations
196 explicitly, 'wic' assumes the user knows what he or she is doing
197 and skips the build check.
198
199 The -D option is used to display debug information detailing
200 exactly what happens behind the scenes when a create request is
201 fulfilled (or not, as the case may be). It enumerates and
202 displays the command sequence used, and should be included in any
203 bug report describing unexpected results.
204
205 When 'wic -e' is used, the locations for the build artifacts
206 values are determined by 'wic -e' from the output of the 'bitbake
207 -e' command given an image name e.g. 'core-image-minimal' and a
208 given machine set in local.conf. In that case, the image is
209 created as if the following 'bitbake -e' variables were used:
210
211 -r: IMAGE_ROOTFS
212 -k: STAGING_KERNEL_DIR
213 -n: STAGING_DIR_NATIVE
214 -b: empty (plugin-specific handlers must determine this)
215
216 If 'wic -e' is not used, the user needs to select the appropriate
217 value for -b (as well as -r, -k, and -n).
218
219 The -o option can be used to place the image in a directory with a
220 different name and location.
221
222 The -c option is used to specify compressor utility to compress
223 an image. gzip, bzip2 and xz compressors are supported.
224
225 The set of properties available for a given image type can be
226 listed using the 'wic list' command.
227"""
228
229wic_list_usage = """
230
231 List available OpenEmbedded image properties and values
232
233 usage: wic list images
234 wic list <image> help
235 wic list source-plugins
236 wic list properties
237 wic list properties <wks file>
238 wic list property <property>
239 [-o <JSON PROPERTY FILE> | --outfile <JSON PROPERTY_FILE>]
240
241 This command enumerates the set of available canned images as well as
242 help for those images. It also can be used to enumerate the complete
243 set of possible values for a specified option or property needed by
244 the image creation process.
245
246 The first form enumerates all the available 'canned' images.
247
248 The second form lists the detailed help information for a specific
249 'canned' image.
250
251 The third form enumerates all the available --sources (source
252 plugins).
253
254 The fourth form enumerates all the possible values that exist and can
255 be specified in an OE kickstart (wks) file.
256
257 The fifth form enumerates all the possible options that exist for the
258 set of properties specified in a given OE kickstart (ks) file.
259
260 The final form enumerates all the possible values that exist and can
261 be specified for any given OE kickstart (wks) property.
262
263 See 'wic help list' for more details.
264"""
265
266wic_list_help = """
267
268NAME
269 wic list - List available OpenEmbedded image properties and values
270
271SYNOPSIS
272 wic list images
273 wic list <image> help
274 wic list source-plugins
275 wic list properties
276 wic list properties <wks file>
277 wic list property <property>
278 [-o <JSON PROPERTY FILE> | --outfile <JSON PROPERTY_FILE>]
279
280DESCRIPTION
281 This command enumerates the complete set of possible values for a
282 specified option or property needed by the image creation process.
283
284 This command enumerates the set of available canned images as well
285 as help for those images. It also can be used to enumerate the
286 complete set of possible values for a specified option or property
287 needed by the image creation process.
288
289 The first form enumerates all the available 'canned' images.
290 These are actually just the set of .wks files that have been moved
291 into the /scripts/lib/wic/canned-wks directory).
292
293 The second form lists the detailed help information for a specific
294 'canned' image.
295
296 The third form enumerates all the available --sources (source
297 plugins). The contents of a given partition are driven by code
298 defined in 'source plugins'. Users specify a specific plugin via
299 the --source parameter of the partition .wks command. Normally
300 this is the 'rootfs' plugin but can be any of the more specialized
301 sources listed by the 'list source-plugins' command. Users can
302 also add their own source plugins - see 'wic help plugins' for
303 details.
304
305 The third form enumerates all the possible values that exist and
306 can be specified in a OE kickstart (wks) file. The output of this
307 can be used by the third form to print the description and
308 possible values of a specific property.
309
310 The fourth form enumerates all the possible options that exist for
311 the set of properties specified in a given OE kickstart (wks)
312 file. If the -o option is specified, the list of properties, in
313 addition to being displayed, will be written to the specified file
314 as a JSON object. In this case, the object will consist of the
315 set of name:value pairs corresponding to the (possibly nested)
316 dictionary of properties defined by the input statements used by
317 the image. Some example output for the 'list <wks file>' command:
318
319 $ wic list test.ks
320 "part" : {
321 "mountpoint" : "/"
322 "fstype" : "ext3"
323 }
324 "part" : {
325 "mountpoint" : "/home"
326 "fstype" : "ext3"
327 "offset" : "10000"
328 }
329 "bootloader" : {
330 "type" : "efi"
331 }
332 .
333 .
334 .
335
336 Each entry in the output consists of the name of the input element
337 e.g. "part", followed by the properties defined for that
338 element enclosed in braces. This information should provide
339 sufficient information to create a complete user interface with.
340
341 The final form enumerates all the possible values that exist and
342 can be specified for any given OE kickstart (wks) property. If
343 the -o option is specified, the list of values for the given
344 property, in addition to being displayed, will be written to the
345 specified file as a JSON object. In this case, the object will
346 consist of the set of name:value pairs corresponding to the array
347 of property values associated with the property.
348
349 $ wic list property part
350 ["mountpoint", "where the partition should be mounted"]
351 ["fstype", "filesytem type of the partition"]
352 ["ext3"]
353 ["ext4"]
354 ["btrfs"]
355 ["swap"]
356 ["offset", "offset of the partition within the image"]
357
358"""
359
360wic_plugins_help = """
361
362NAME
363 wic plugins - Overview and API
364
365DESCRIPTION
366 plugins allow wic functionality to be extended and specialized by
367 users. This section documents the plugin interface, which is
368 currently restricted to 'source' plugins.
369
370 'Source' plugins provide a mechanism to customize various aspects
371 of the image generation process in wic, mainly the contents of
372 partitions.
373
374 Source plugins provide a mechanism for mapping values specified in
375 .wks files using the --source keyword to a particular plugin
376 implementation that populates a corresponding partition.
377
378 A source plugin is created as a subclass of SourcePlugin (see
379 scripts/lib/wic/pluginbase.py) and the plugin file containing it
380 is added to scripts/lib/wic/plugins/source/ to make the plugin
381 implementation available to the wic implementation.
382
383 Source plugins can also be implemented and added by external
384 layers - any plugins found in a scripts/lib/wic/plugins/source/
385 directory in an external layer will also be made available.
386
387 When the wic implementation needs to invoke a partition-specific
388 implementation, it looks for the plugin that has the same name as
389 the --source param given to that partition. For example, if the
390 partition is set up like this:
391
392 part /boot --source bootimg-pcbios ...
393
394 then the methods defined as class members of the plugin having the
395 matching bootimg-pcbios .name class member would be used.
396
397 To be more concrete, here's the plugin definition that would match
398 a '--source bootimg-pcbios' usage, along with an example method
399 that would be called by the wic implementation when it needed to
400 invoke an implementation-specific partition-preparation function:
401
402 class BootimgPcbiosPlugin(SourcePlugin):
403 name = 'bootimg-pcbios'
404
405 @classmethod
406 def do_prepare_partition(self, part, ...)
407
408 If the subclass itself doesn't implement a function, a 'default'
409 version in a superclass will be located and used, which is why all
410 plugins must be derived from SourcePlugin.
411
412 The SourcePlugin class defines the following methods, which is the
413 current set of methods that can be implemented/overridden by
414 --source plugins. Any methods not implemented by a SourcePlugin
415 subclass inherit the implementations present in the SourcePlugin
416 class (see the SourcePlugin source for details):
417
418 do_prepare_partition()
419 Called to do the actual content population for a
420 partition. In other words, it 'prepares' the final partition
421 image which will be incorporated into the disk image.
422
423 do_configure_partition()
424 Called before do_prepare_partition(), typically used to
425 create custom configuration files for a partition, for
426 example syslinux or grub config files.
427
428 do_install_disk()
429 Called after all partitions have been prepared and assembled
430 into a disk image. This provides a hook to allow
431 finalization of a disk image, for example to write an MBR to
432 it.
433
434 do_stage_partition()
435 Special content-staging hook called before
436 do_prepare_partition(), normally empty.
437
438 Typically, a partition will just use the passed-in
439 parameters, for example the unmodified value of bootimg_dir.
440 In some cases however, things may need to be more tailored.
441 As an example, certain files may additionally need to be
442 take from bootimg_dir + /boot. This hook allows those files
443 to be staged in a customized fashion. Note that
444 get_bitbake_var() allows you to access non-standard
445 variables that you might want to use for these types of
446 situations.
447
448 This scheme is extensible - adding more hooks is a simple matter
449 of adding more plugin methods to SourcePlugin and derived classes.
450 The code that then needs to call the plugin methods uses
451 plugin.get_source_plugin_methods() to find the method(s) needed by
452 the call; this is done by filling up a dict with keys containing
453 the method names of interest - on success, these will be filled in
454 with the actual methods. Please see the implementation for
455 examples and details.
456"""
457
458wic_overview_help = """
459
460NAME
461 wic overview - General overview of wic
462
463DESCRIPTION
464 The 'wic' command generates partitioned images from existing
465 OpenEmbedded build artifacts. Image generation is driven by
466 partitioning commands contained in an 'Openembedded kickstart'
467 (.wks) file (see 'wic help kickstart') specified either directly
468 on the command-line or as one of a selection of canned .wks files
469 (see 'wic list images'). When applied to a given set of build
470 artifacts, the result is an image or set of images that can be
471 directly written onto media and used on a particular system.
472
473 The 'wic' command and the infrastructure it's based on is by
474 definition incomplete - its purpose is to allow the generation of
475 customized images, and as such was designed to be completely
476 extensible via a plugin interface (see 'wic help plugins').
477
478 Background and Motivation
479
480 wic is meant to be a completely independent standalone utility
481 that initially provides easier-to-use and more flexible
482 replacements for a couple bits of existing functionality in
483 oe-core: directdisk.bbclass and mkefidisk.sh. The difference
484 between wic and those examples is that with wic the functionality
485 of those scripts is implemented by a general-purpose partitioning
486 'language' based on Redhat kickstart syntax).
487
488 The initial motivation and design considerations that lead to the
489 current tool are described exhaustively in Yocto Bug #3847
490 (https://bugzilla.yoctoproject.org/show_bug.cgi?id=3847).
491
492 Implementation and Examples
493
494 wic can be used in two different modes, depending on how much
495 control the user needs in specifying the Openembedded build
496 artifacts that will be used in creating the image: 'raw' and
497 'cooked'.
498
499 If used in 'raw' mode, artifacts are explicitly specified via
500 command-line arguments (see example below).
501
502 The more easily usable 'cooked' mode uses the current MACHINE
503 setting and a specified image name to automatically locate the
504 artifacts used to create the image.
505
506 OE kickstart files (.wks) can of course be specified directly on
507 the command-line, but the user can also choose from a set of
508 'canned' .wks files available via the 'wic list images' command
509 (example below).
510
511 In any case, the prerequisite for generating any image is to have
512 the build artifacts already available. The below examples assume
513 the user has already build a 'core-image-minimal' for a specific
514 machine (future versions won't require this redundant step, but
515 for now that's typically how build artifacts get generated).
516
517 The other prerequisite is to source the build environment:
518
519 $ source oe-init-build-env
520
521 To start out with, we'll generate an image from one of the canned
522 .wks files. The following generates a list of availailable
523 images:
524
525 $ wic list images
526 mkefidisk Create an EFI disk image
527 directdisk Create a 'pcbios' direct disk image
528
529 You can get more information about any of the available images by
530 typing 'wic list xxx help', where 'xxx' is one of the image names:
531
532 $ wic list mkefidisk help
533
534 Creates a partitioned EFI disk image that the user can directly dd
535 to boot media.
536
537 At any time, you can get help on the 'wic' command or any
538 subcommand (currently 'list' and 'create'). For instance, to get
539 the description of 'wic create' command and its parameters:
540
541 $ wic create
542
543 Usage:
544
545 Create a new OpenEmbedded image
546
547 usage: wic create <wks file or image name> [-o <DIRNAME> | ...]
548 [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
549 [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
550 [-r, --rootfs-dir] [-b, --bootimg-dir] [-k, --kernel-dir]
551 [-n, --native-sysroot] [-f, --build-rootfs]
552
553 This command creates an OpenEmbedded image based on the 'OE
554 kickstart commands' found in the <wks file>.
555
556 The -o option can be used to place the image in a directory
557 with a different name and location.
558
559 See 'wic help create' for more detailed instructions.
560 ...
561
562 As mentioned in the command, you can get even more detailed
563 information by adding 'help' to the above:
564
565 $ wic help create
566
567 So, the easiest way to create an image is to use the -e option
568 with a canned .wks file. To use the -e option, you need to
569 specify the image used to generate the artifacts and you actually
570 need to have the MACHINE used to build them specified in your
571 local.conf (these requirements aren't necessary if you aren't
572 using the -e options.) Below, we generate a directdisk image,
573 pointing the process at the core-image-minimal artifacts for the
574 current MACHINE:
575
576 $ wic create directdisk -e core-image-minimal
577
578 Checking basic build environment...
579 Done.
580
581 Creating image(s)...
582
583 Info: The new image(s) can be found here:
584 /var/tmp/wic/build/directdisk-201309252350-sda.direct
585
586 The following build artifacts were used to create the image(s):
587
588 ROOTFS_DIR: ...
589 BOOTIMG_DIR: ...
590 KERNEL_DIR: ...
591 NATIVE_SYSROOT: ...
592
593 The image(s) were created using OE kickstart file:
594 .../scripts/lib/wic/canned-wks/directdisk.wks
595
596 The output shows the name and location of the image created, and
597 so that you know exactly what was used to generate the image, each
598 of the artifacts and the kickstart file used.
599
600 Similarly, you can create a 'mkefidisk' image in the same way
601 (notice that this example uses a different machine - because it's
602 using the -e option, you need to change the MACHINE in your
603 local.conf):
604
605 $ wic create mkefidisk -e core-image-minimal
606 Checking basic build environment...
607 Done.
608
609 Creating image(s)...
610
611 Info: The new image(s) can be found here:
612 /var/tmp/wic/build/mkefidisk-201309260027-sda.direct
613
614 ...
615
616 Here's an example that doesn't take the easy way out and manually
617 specifies each build artifact, along with a non-canned .wks file,
618 and also uses the -o option to have wic create the output
619 somewhere other than the default /var/tmp/wic:
620
621 $ wic create ./test.wks -o ./out --rootfs-dir
622 tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/rootfs
623 --bootimg-dir tmp/sysroots/qemux86-64/usr/share
624 --kernel-dir tmp/deploy/images/qemux86-64
625 --native-sysroot tmp/sysroots/x86_64-linux
626
627 Creating image(s)...
628
629 Info: The new image(s) can be found here:
630 out/build/test-201507211313-sda.direct
631
632 The following build artifacts were used to create the image(s):
633 ROOTFS_DIR: tmp/work/qemux86_64-poky-linux/core-image-minimal/1.0-r0/rootfs
634 BOOTIMG_DIR: tmp/sysroots/qemux86-64/usr/share
635 KERNEL_DIR: tmp/deploy/images/qemux86-64
636 NATIVE_SYSROOT: tmp/sysroots/x86_64-linux
637
638 The image(s) were created using OE kickstart file:
639 ./test.wks
640
641 Here is a content of test.wks:
642
643 part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024
644 part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024
645
646 bootloader --timeout=0 --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0"
647
648
649 Finally, here's an example of the actual partition language
650 commands used to generate the mkefidisk image i.e. these are the
651 contents of the mkefidisk.wks OE kickstart file:
652
653 # short-description: Create an EFI disk image
654 # long-description: Creates a partitioned EFI disk image that the user
655 # can directly dd to boot media.
656
657 part /boot --source bootimg-efi --ondisk sda --fstype=efi --active
658
659 part / --source rootfs --ondisk sda --fstype=ext3 --label platform
660
661 part swap --ondisk sda --size 44 --label swap1 --fstype=swap
662
663 bootloader --timeout=10 --append="rootwait console=ttyPCH0,115200"
664
665 You can get a complete listing and description of all the
666 kickstart commands available for use in .wks files from 'wic help
667 kickstart'.
668"""
669
670wic_kickstart_help = """
671
672NAME
673 wic kickstart - wic kickstart reference
674
675DESCRIPTION
676 This section provides the definitive reference to the wic
677 kickstart language. It also provides documentation on the list of
678 --source plugins available for use from the 'part' command (see
679 the 'Platform-specific Plugins' section below).
680
681 The current wic implementation supports only the basic kickstart
682 partitioning commands: partition (or part for short) and
683 bootloader.
684
685 The following is a listing of the commands, their syntax, and
686 meanings. The commands are based on the Fedora kickstart
687 documentation but with modifications to reflect wic capabilities.
688
689 http://fedoraproject.org/wiki/Anaconda/Kickstart#part_or_partition
690 http://fedoraproject.org/wiki/Anaconda/Kickstart#bootloader
691
692 Commands
693
694 * 'part' or 'partition'
695
696 This command creates a partition on the system and uses the
697 following syntax:
698
699 part <mountpoint>
700
701 The <mountpoint> is where the partition will be mounted and
702 must take of one of the following forms:
703
704 /<path>: For example: /, /usr, or /home
705
706 swap: The partition will be used as swap space.
707
708 The following are supported 'part' options:
709
710 --size: The minimum partition size. Specify an integer value
711 such as 500. Multipliers k, M ang G can be used. If
712 not specified, the size is in MB.
713 You do not need this option if you use --source.
714
715 --source: This option is a wic-specific option that names the
716 source of the data that will populate the
717 partition. The most common value for this option
718 is 'rootfs', but can be any value which maps to a
719 valid 'source plugin' (see 'wic help plugins').
720
721 If '--source rootfs' is used, it tells the wic
722 command to create a partition as large as needed
723 and to fill it with the contents of the root
724 filesystem pointed to by the '-r' wic command-line
725 option (or the equivalent rootfs derived from the
726 '-e' command-line option). The filesystem type
727 that will be used to create the partition is driven
728 by the value of the --fstype option specified for
729 the partition (see --fstype below).
730
731 If --source <plugin-name>' is used, it tells the
732 wic command to create a partition as large as
733 needed and to fill with the contents of the
734 partition that will be generated by the specified
735 plugin name using the data pointed to by the '-r'
736 wic command-line option (or the equivalent rootfs
737 derived from the '-e' command-line option).
738 Exactly what those contents and filesystem type end
739 up being are dependent on the given plugin
740 implementation.
741
742 If --source option is not used, the wic command
743 will create empty partition. --size parameter has
744 to be used to specify size of empty partition.
745
746 --ondisk or --ondrive: Forces the partition to be created on
747 a particular disk.
748
749 --fstype: Sets the file system type for the partition. These
750 apply to partitions created using '--source rootfs' (see
751 --source above). Valid values are:
752
753 ext2
754 ext3
755 ext4
756 btrfs
757 squashfs
758 swap
759
760 --fsoptions: Specifies a free-form string of options to be
761 used when mounting the filesystem. This string
762 will be copied into the /etc/fstab file of the
763 installed system and should be enclosed in
764 quotes. If not specified, the default string is
765 "defaults".
766
767 --label label: Specifies the label to give to the filesystem
768 to be made on the partition. If the given
769 label is already in use by another filesystem,
770 a new label is created for the partition.
771
772 --active: Marks the partition as active.
773
774 --align (in KBytes): This option is specific to wic and says
775 to start a partition on an x KBytes
776 boundary.
777
778 --no-table: This option is specific to wic. Space will be
779 reserved for the partition and it will be
780 populated but it will not be added to the
781 partition table. It may be useful for
782 bootloaders.
783
784 --extra-space: This option is specific to wic. It adds extra
785 space after the space filled by the content
786 of the partition. The final size can go
787 beyond the size specified by --size.
788 By default, 10MB.
789
790 --overhead-factor: This option is specific to wic. The
791 size of the partition is multiplied by
792 this factor. It has to be greater than or
793 equal to 1.
794 The default value is 1.3.
795
796 --part-type: This option is specific to wic. It specifies partition
797 type GUID for GPT partitions.
798 List of partition type GUIDS can be found here:
799 http://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs
800
801 --use-uuid: This option is specific to wic. It makes wic to generate
802 random globally unique identifier (GUID) for the partition
803 and use it in bootloader configuration to specify root partition.
804
805 --uuid: This option is specific to wic. It specifies partition UUID.
806 It's useful if preconfigured partition UUID is added to kernel command line
807 in bootloader configuration before running wic. In this case .wks file can
808 be generated or modified to set preconfigured parition UUID using this option.
809
810 * bootloader
811
812 This command allows the user to specify various bootloader
813 options. The following are supported 'bootloader' options:
814
815 --timeout: Specifies the number of seconds before the
816 bootloader times out and boots the default option.
817
818 --append: Specifies kernel parameters. These will be added to
819 bootloader command-line - for example, the syslinux
820 APPEND or grub kernel command line.
821
822 Note that bootloader functionality and boot partitions are
823 implemented by the various --source plugins that implement
824 bootloader functionality; the bootloader command essentially
825 provides a means of modifying bootloader configuration.
826"""