wic: Updates to add vfat support and more help topics
cover wic: Updates to add vfat support and more help topics
This patchset adds vfat support as requested in YOCTO #6513, and also adds a couple new help topics: a wic overview and the start of a wic kickstart reference.
It also fixes a couple usability bugs noted along the way.
The following changes since commit 1dcdd877c7946be4c0b1203deb14e2f842f9d0c2:
bitbake: toasterui: fix build - project identification (2014-07-14 14:10:03 +0100)
are available in the git repository at:
git://git.yoctoproject.org/poky-contrib.git tzanussi/wic-vfat-updates
http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=tzanussi/wic-vfat-updates
Tom Zanussi (5):
wic: Error on parted non-zero error code
wic: Add vfat support
wic: Add wic overview to help system
wic: Add kickstart reference to help system
wic: Error on zero-sized partitions
scripts/lib/image/canned-wks/directdisk.wks | 2 +- scripts/lib/image/help.py | 323 +++++++++++++++++++++ .../lib/mic/kickstart/custom_commands/partition.py | 76 +++++ scripts/lib/mic/utils/partitionedfs.py | 2 +- scripts/wic | 24 +- 5 files changed, 416 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/5 wic: Error on parted non-zero error code
The current code uses msger.debug() to note errors, effectively squelching them if --debug isn't used. Apparently this is because it can return non-zero for some loop device failures. We don't care about loop devices, and not paying attention to the error code actually results in invalid images, so error out on parted failures as we should be.
--- scripts/lib/mic/utils/partitionedfs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/lib/mic/utils/partitionedfs.py +1 -1
@@ -272,7 +272,7 @@ class PartitionedMount(Mount): # parted always fails to reload part table with loop devices. This # prevents us from distinguishing real errors based on return # code. - msger.debug("WARNING: parted returned '%s' instead of 0" % rc) + msger.error("WARNING: parted returned '%s' instead of 0 (use --debug for details)" % rc) def __create_partition(self, device, parttype, fstype, start, size): """ Create a partition on an image described by the 'device' object. """
Signature · 1 line
1.8.3.1
PATCH 2/5 wic: Add vfat support
Add vfat as a supported rootfs type (in addition to the current ext2/3/4 and btrfs support).
vfat partitions can now be created using --source rootfs along with --fstype=vfat, or without --source but specifying a --size.
--- .../lib/mic/kickstart/custom_commands/partition.py | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+)
scripts/lib/mic/kickstart/custom_commands/partition.py +74 -0
@@ -186,6 +186,11 @@ class Wic_PartData(Mic_PartData): rootfs_dir, native_sysroot, pseudo) + elif self.fstype.startswith("vfat"): + return self.prepare_rootfs_vfat(cr_workdir, oe_builddir, + rootfs_dir, native_sysroot, + pseudo) + def prepare_rootfs_ext(self, cr_workdir, oe_builddir, rootfs_dir, native_sysroot, pseudo): """
@@ -270,6 +275,53 @@ class Wic_PartData(Mic_PartData): self.size = rootfs_size self.source_file = rootfs + def prepare_rootfs_vfat(self, cr_workdir, oe_builddir, rootfs_dir, + native_sysroot, pseudo): + """ + Prepare content for a vfat rootfs partition. + """ + image_rootfs = rootfs_dir + rootfs = "%s/rootfs_%s.%s" % (cr_workdir, self.label, self.fstype) + + du_cmd = "du -bks %s" % image_rootfs + rc, out = exec_cmd(du_cmd) + blocks = int(out.split()[0]) + + extra_blocks = self.get_extra_block_count(blocks) + + if extra_blocks < BOOTDD_EXTRA_SPACE: + extra_blocks = BOOTDD_EXTRA_SPACE + + blocks += extra_blocks + + msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ + (extra_blocks, self.mountpoint, blocks)) + + # Ensure total sectors is an integral number of sectors per + # track or mcopy will complain. Sectors are 512 bytes, and we + # generate images with 32 sectors per track. This calculation is + # done in blocks, thus the mod by 16 instead of 32. + blocks += (16 - (blocks % 16)) + + dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (rootfs, blocks) + exec_native_cmd(dosfs_cmd, native_sysroot) + + mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, image_rootfs) + rc, out = exec_native_cmd(mcopy_cmd, native_sysroot) + if rc: + msger.error("ERROR: mcopy returned '%s' instead of 0 (which you probably don't want to ignore, use --debug for details)" % rc) + + chmod_cmd = "chmod 644 %s" % rootfs + exec_cmd(chmod_cmd) + + # get the rootfs size in the right units for kickstart (Mb) + du_cmd = "du -Lbms %s" % rootfs + rc, out = exec_cmd(du_cmd) + rootfs_size = out.split()[0] + + self.set_size(rootfs_size) + self.set_source_file(rootfs) + def prepare_empty_partition(self, cr_workdir, oe_builddir, native_sysroot): """ Prepare an empty partition.
@@ -280,6 +332,9 @@ class Wic_PartData(Mic_PartData): elif self.fstype.startswith("btrfs"): return self.prepare_empty_partition_btrfs(cr_workdir, oe_builddir, native_sysroot) + elif self.fstype.startswith("vfat"): + return self.prepare_empty_partition_vfat(cr_workdir, oe_builddir, + native_sysroot) def prepare_empty_partition_ext(self, cr_workdir, oe_builddir, native_sysroot):
@@ -322,6 +377,25 @@ class Wic_PartData(Mic_PartData): return 0 + def prepare_empty_partition_vfat(self, cr_workdir, oe_builddir, + native_sysroot): + """ + Prepare an empty vfat partition. + """ + fs = "%s/fs.%s" % (cr_workdir, self.fstype) + + blocks = self.size * 1024 + + dosfs_cmd = "mkdosfs -n boot -S 512 -C %s %d" % (fs, blocks) + exec_native_cmd(dosfs_cmd, native_sysroot) + + chmod_cmd = "chmod 644 %s" % fs + exec_cmd(chmod_cmd) + + self.source_file = fs + + return 0 + def prepare_swap_partition(self, cr_workdir, oe_builddir, native_sysroot): """ Prepare a swap partition.
Signature · 1 line
1.8.3.1
PATCH 3/5 wic: Add wic overview to help system
In reply to Tom ZanussiAdd a general overview of wic to the help system as 'wic overview', along with some introductory examples.
--- scripts/lib/image/help.py | 209 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/wic | 21 +++-- 2 files changed, 221 insertions(+), 9 deletions(-)
scripts/lib/image/help.py +209 -0
@@ -88,6 +88,7 @@ wic_usage = """ list List available values for options and image properties Help topics: + overview wic overview - General overview of wic plugins wic plugins - Overview and API See 'wic help <COMMAND or HELP TOPIC>' for more information on a specific
@@ -422,3 +423,211 @@ DESCRIPTION with the actual methods. Please see the implementation for examples and details. """ + +wic_overview_help = """ + +NAME + wic overview - General overview of wic + +DESCRIPTION + The 'wic' command generates partitioned images from existing + OpenEmbedded build artifacts. Image generation is driven by + partitioning commands contained in an 'Openembedded kickstart' + (.wks) file (see 'wic help kickstart') specified either directly + on the command-line or as one of a selection of canned .wks files + (see 'wic list images'). When applied to a given set of build + artifacts, the result is an image or set of images that can be + directly written onto media and used on a particular system. + + The 'wic' command and the infrastructure it's based is by + definition incomplete - it's designed to allow the generation of + customized images, and as such was designed to be completely + extensible via a plugin interface (see 'wic help plugins'). + + Background and Motivation + + wic is meant to be a completely independent standalone utility + that initially provides easier-to-use and more flexible + replacements for a couple bits of existing functionality in + oe-core: directdisk.bbclass and mkefidisk.sh. The difference + between wic and those examples is that with wic the functionality + of those scripts is implemented by a general-purpose partitioning + 'language' based on Redhat kickstart syntax (with the underlying + code borrowed from Tizen mic, which in turn was borrowed from + Meego mic, in turn borrowed from Fedora livecd, etc.). + + The initial motivation and design considerations that lead to the + current tool are described exhaustively in Yocto Bug #3847 + (https://bugzilla.yoctoproject.org/show_bug.cgi?id=3847). + + Though the current wic tool only uses the kickstart syntax related + to partitioning and bootloaders and only for creating images, + because the code is based on the mic/pykickstart code, future + deployment efforts such as those partially described by Yocto Bug + #4106 (https://bugzilla.yoctoproject.org/show_bug.cgi?id=4106), + but also others including package selection (from e.g. binary + feeds) and deployment configuration of users/network/services, + etc, could be implemented under this framework, considering that + all of those are implemented in some form by the base system. + + Implementation and Examples + + wic can be used in two different modes, depending on how much + control the user needs in specifying the Openembedded build + artifacts that will be used in creating the image: 'raw' and + 'cooked'. + + If used in 'raw' mode, artifacts are explicitly specified via + command-line arguments (see example below). + + The more easily usable 'cooked' mode uses the current MACHINE + setting and a specified image name to automatically locate the + artifacts used to create the image. + + OE kickstart files (.wks) can of course be specified directly on + the command-line, but the user can also choose from a set of + 'canned' .wks files available via the 'wic list images' command + (example below). + + In any case, the prerequisite for generating any image is to have + the build artifacts already available. The below examples assume + the user has already build a 'core-image-minimal' for a specific + machine (future versions won't require this redundant step, but + for now that's typically how build artifacts get generated). + + The other prerequisite is to source the build environment: + + $ source oe-init-build-env + + To start out with, we'll generate an image from one of the canned + .wks files. The following generates a list of availailable + images: + + $ wic list images + mkefidisk Create an EFI disk image + directdisk Create a 'pcbios' direct disk image + + You can get more information about any of the available images by + typing 'wic list xxx help', where 'xxx' is one of the image names: + + $ wic list mkefidisk help + + Creates a partitioned EFI disk image that the user can directly dd + to boot media. + + At any time, you can get help on the 'wic' command or any + subcommand (currently 'list' and 'create'). For instance, to get + the description of 'wic create' command and its parameters: + + $ wic create + + Usage: + + Create a new OpenEmbedded image + + usage: wic create <wks file or image name> [-o <DIRNAME> | ...] + [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>] + [-e | --image-name] [-r, --rootfs-dir] [-b, --bootimg-dir] + [-k, --kernel-dir] [-n, --native-sysroot] [-s, --skip-build-check] + + This command creates an OpenEmbedded image based on the 'OE + kickstart commands' found in the <wks file>. + + The -o option can be used to place the image in a directory + with a different name and location. + + See 'wic help create' for more detailed instructions. + ... + + As mentioned in the command, you can get even more detailed + information by adding 'help' to the above: + + $ wic help create + + So, the easiest way to create an image is to use the -e option + with a canned .wks file. To use the -e option, you need to + specify the image used to generate the artifacts and you actually + need to have the MACHINE used to build them specified in your + local.conf (these requirements aren't necessary if you aren't + using the -e options.) Below, we generate a directdisk image, + pointing the process at the core-image-minimal artifacts for the + current MACHINE: + + $ wic create directdisk -e core-image-minimal + + Checking basic build environment... + Done. + + Creating image(s)... + + Info: The new image(s) can be found here: + /var/tmp/wic/build/directdisk-201309252350-sda.direct + + The following build artifacts were used to create the image(s): + + ROOTFS_DIR: ... + BOOTIMG_DIR: ... + KERNEL_DIR: ... + NATIVE_SYSROOT: ... + + The image(s) were created using OE kickstart file: + .../scripts/lib/image/canned-wks/directdisk.wks + + The output shows the name and location of the image created, and + so that you know exactly what was used to generate the image, each + of the artifacts and the kickstart file used. + + Similarly, you can create a 'mkefidisk' image in the same way + (notice that this example uses a different machine - because it's + using the -e option, you need to change the MACHINE in your + local.conf): + + $ wic create mkefidisk -e core-image-minimal + Checking basic build environment... + Done. + + Creating image(s)... + + Info: The new image(s) can be found here: + /var/tmp/wic/build/mkefidisk-201309260027-sda.direct + + ... + + Here's an example that doesn't take the easy way out and manually + specifies each build artifact, along with a non-canned .wks file, + and also uses the -o option to have wic create the output + somewhere other than the default /var/tmp/wic: + + $ wic create ~/test.wks -o /home/trz/testwic --rootfs-dir + /home/trz/yocto/build/tmp/work/crownbay/core-image-minimal/1.0-r0/rootfs + --bootimg-dir /home/trz/yocto/build/tmp/sysroots/crownbay/usr/share + --kernel-dir /home/trz/yocto/build/tmp/sysroots/crownbay/usr/src/kernel + --native-sysroot /home/trz/yocto/build/tmp/sysroots/x86_64-linux + + Creating image(s)... + + Info: The new image(s) can be found here: + /home/trz/testwic/build/test-201309260032-sda.direct + + ... + + Finally, here's an example of the actual partition language + commands used to generate the mkefidisk image i.e. these are the + contents of the mkefidisk.wks OE kickstart file: + + # short-description: Create an EFI disk image + # long-description: Creates a partitioned EFI disk image that the user + # can directly dd to boot media. + + part /boot --source bootimg-efi --ondisk sda --fstype=efi --active + + part / --source rootfs --ondisk sda --fstype=ext3 --label platform + + part swap --ondisk sda --size 44 --label swap1 --fstype=swap + + bootloader --timeout=10 --append="rootwait console=ttyPCH0,115200" + + You can get a complete listing and description of all the + kickstart commands available for use in .wks files from 'wic help + kickstart'. +"""
scripts/wic +12 -9
@@ -240,15 +240,18 @@ wic_help_topic_usage = """ """ subcommands = { - "create": [wic_create_subcommand, - wic_create_usage, - wic_create_help], - "list": [wic_list_subcommand, - wic_list_usage, - wic_list_help], - "plugins": [wic_help_topic_subcommand, - wic_help_topic_usage, - wic_plugins_help], + "create": [wic_create_subcommand, + wic_create_usage, + wic_create_help], + "list": [wic_list_subcommand, + wic_list_usage, + wic_list_help], + "plugins": [wic_help_topic_subcommand, + wic_help_topic_usage, + wic_plugins_help], + "overview": [wic_help_topic_subcommand, + wic_help_topic_usage, + wic_overview_help], }
Signature · 1 line
1.8.3.1
PATCH 4/5 wic: Add kickstart reference to help system
In reply to Tom ZanussiAdd a 'wic kickstart' help section to make it easy for users to access the kickstart reference without having to go to an external website.
--- scripts/lib/image/canned-wks/directdisk.wks | 2 +- scripts/lib/image/help.py | 114 ++++++++++++++++++++++++++++ scripts/wic | 27 ++++--- 3 files changed, 130 insertions(+), 13 deletions(-)
scripts/lib/image/canned-wks/directdisk.wks +1 -1
@@ -3,7 +3,7 @@ # can directly dd to boot media. -part /boot --source bootimg-pcbios --ondisk sda --fstype=msdos --label boot --active --align 1024 +part /boot --source bootimg-pcbios --ondisk sda --label boot --active --align 1024 part / --source rootfs --ondisk sda --fstype=ext3 --label platform --align 1024 bootloader --timeout=0 --append="rootwait rootfstype=ext3 video=vesafb vga=0x318 console=tty0"
scripts/lib/image/help.py +114 -0
117 lines not on this page · raw message
scripts/wic +15 -12
@@ -240,18 +240,21 @@ wic_help_topic_usage = """ """ subcommands = { - "create": [wic_create_subcommand, - wic_create_usage, - wic_create_help], - "list": [wic_list_subcommand, - wic_list_usage, - wic_list_help], - "plugins": [wic_help_topic_subcommand, - wic_help_topic_usage, - wic_plugins_help], - "overview": [wic_help_topic_subcommand, - wic_help_topic_usage, - wic_overview_help], + "create": [wic_create_subcommand, + wic_create_usage, + wic_create_help], + "list": [wic_list_subcommand, + wic_list_usage, + wic_list_help], + "plugins": [wic_help_topic_subcommand, + wic_help_topic_usage, + wic_plugins_help], + "overview": [wic_help_topic_subcommand, + wic_help_topic_usage, + wic_overview_help], + "kickstart": [wic_help_topic_subcommand, + wic_help_topic_usage, + wic_kickstart_help], }
Signature · 1 line
1.8.3.1
PATCH 5/5 wic: Error on zero-sized partitions
In reply to Tom ZanussiIt doesn't make sense to create zero-sized partitions so assume user error and notify the user they should be using a non-zero --size for partitions that don't specify a --source.
--- scripts/lib/mic/kickstart/custom_commands/partition.py | 2 ++ 1 file changed, 2 insertions(+)
scripts/lib/mic/kickstart/custom_commands/partition.py +2 -0
@@ -122,6 +122,8 @@ class Wic_PartData(Mic_PartData): partition command parameters. """ if not self.source: + if not self.size: + msger.error("The %s partition has a size of zero. Please specify a non-zero --size for that partition." % self.mountpoint) if self.fstype and self.fstype == "swap": self.prepare_swap_partition(cr_workdir, oe_builddir, native_sysroot)
Signature · 1 line
1.8.3.1