From: vijai kumar <vijaikumar.kanagarajan@gmail.com>
To: Henning Schild <henning.schild@siemens.com>
Cc: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>,
isar-users@googlegroups.com
Subject: Re: [PATCH v2 01/10] wic: Update to the latest wic from openembedded core
Date: Sat, 5 Sep 2020 14:51:04 +0530 [thread overview]
Message-ID: <CALLGG_+GdDJaJmaE=jkm_oLJoorDJtObj6-W5OgjfC4VUrTZSw@mail.gmail.com> (raw)
In-Reply-To: <20200905110055.6d9ce1f1@md1za8fc.ad001.siemens.net>
[-- Attachment #1: Type: text/plain, Size: 85712 bytes --]
On Sat, 5 Sep 2020 at 2:30 PM, Henning Schild <henning.schild@siemens.com>
wrote:
> I assume if i took that commit and copied it over i would end up with
>
> 100% the same patch, right?
Yes. This patch is just copying the wic from the oe core. Although, we have
one other separate patch (P9)which is cherry picked from oe core over the
top of this copy based commit.
Thanks,
Vijai Kumar K
>
>
>
>
> On Thu, 3 Sep 2020 00:26:15 +0530
>
> Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com> wrote:
>
>
>
> > Update to the latest wic from OE-core.
>
> >
>
> > OE-core Revision: 532ae127c52c9f7b1d2e4ca5cbca91881d23a2ac
>
> >
>
> > Signed-off-by: Vijai Kumar K <Vijaikumar_Kanagarajan@mentor.com>
>
> > ---
>
> > scripts/lib/scriptpath.py | 32 ++
>
> > scripts/lib/wic/__init__.py | 14 +-
>
> > scripts/lib/wic/canned-wks/common.wks.inc | 2 +-
>
> > .../directdisk-bootloader-config.cfg | 8 +-
>
> > .../lib/wic/canned-wks/efi-bootdisk.wks.in | 3 +
>
> > scripts/lib/wic/canned-wks/mkhybridiso.wks | 2 +-
>
> > scripts/lib/wic/canned-wks/qemuriscv.wks | 3 +
>
> > .../lib/wic/canned-wks/qemux86-directdisk.wks | 2 +-
>
> > .../lib/wic/canned-wks/sdimage-bootpart.wks | 4 +-
>
> > .../lib/wic/canned-wks/systemd-bootdisk.wks | 4 +-
>
> > scripts/lib/wic/engine.py | 421 +++++++++++++++-
>
> > scripts/lib/wic/filemap.py | 170 ++++---
>
> > scripts/lib/wic/help.py | 401 ++++++++++++++--
>
> > scripts/lib/wic/ksparser.py | 115 +++--
>
> > scripts/lib/wic/{utils => }/misc.py | 99 ++--
>
> > scripts/lib/wic/partition.py | 234 ++++-----
>
> > scripts/lib/wic/pluginbase.py | 36 +-
>
> > scripts/lib/wic/plugins/imager/direct.py | 175 ++++---
>
> > .../wic/plugins/source/bootimg-biosplusefi.py | 213 +++++++++
>
> > scripts/lib/wic/plugins/source/bootimg-efi.py | 111 +++--
>
> > .../wic/plugins/source/bootimg-partition.py | 153 ++++--
>
> > .../lib/wic/plugins/source/bootimg-pcbios.py | 91 ++--
>
> > scripts/lib/wic/plugins/source/fsimage.py | 56 ---
>
> > .../wic/plugins/source/isoimage-isohybrid.py | 185 +++----
>
> > scripts/lib/wic/plugins/source/rawcopy.py | 44 +-
>
> > scripts/lib/wic/plugins/source/rootfs.py | 159 ++++--
>
> > scripts/lib/wic/utils/__init__.py | 0
>
> > scripts/lib/wic/utils/runner.py | 114 -----
>
> > scripts/wic | 452
>
> > +++++++++++++----- 29 files changed, 2283 insertions(+), 1020
>
> > deletions(-) create mode 100644 scripts/lib/scriptpath.py
>
> > create mode 100644 scripts/lib/wic/canned-wks/efi-bootdisk.wks.in
>
> > create mode 100644 scripts/lib/wic/canned-wks/qemuriscv.wks
>
> > rename scripts/lib/wic/{utils => }/misc.py (70%)
>
> > create mode 100644
>
> > scripts/lib/wic/plugins/source/bootimg-biosplusefi.py delete mode
>
> > 100644 scripts/lib/wic/plugins/source/fsimage.py delete mode 100644
>
> > scripts/lib/wic/utils/__init__.py delete mode 100644
>
> > scripts/lib/wic/utils/runner.py
>
> >
>
> > diff --git a/scripts/lib/scriptpath.py b/scripts/lib/scriptpath.py
>
> > new file mode 100644
>
> > index 0000000..f32326d
>
> > --- /dev/null
>
> > +++ b/scripts/lib/scriptpath.py
>
> > @@ -0,0 +1,32 @@
>
> > +# Path utility functions for OE python scripts
>
> > +#
>
> > +# Copyright (C) 2012-2014 Intel Corporation
>
> > +# Copyright (C) 2011 Mentor Graphics Corporation
>
> > +#
>
> > +# SPDX-License-Identifier: GPL-2.0-only
>
> > +#
>
> > +
>
> > +import sys
>
> > +import os
>
> > +import os.path
>
> > +
>
> > +def add_oe_lib_path():
>
> > + basepath = os.path.abspath(os.path.dirname(__file__) + '/../..')
>
> > + newpath = basepath + '/meta/lib'
>
> > + sys.path.insert(0, newpath)
>
> > +
>
> > +def add_bitbake_lib_path():
>
> > + basepath = os.path.abspath(os.path.dirname(__file__) + '/../..')
>
> > + bitbakepath = None
>
> > + if os.path.exists(basepath + '/bitbake/lib/bb'):
>
> > + bitbakepath = basepath + '/bitbake'
>
> > + else:
>
> > + # look for bitbake/bin dir in PATH
>
> > + for pth in os.environ['PATH'].split(':'):
>
> > + if os.path.exists(os.path.join(pth, '../lib/bb')):
>
> > + bitbakepath = os.path.abspath(os.path.join(pth,
>
> > '..'))
>
> > + break
>
> > +
>
> > + if bitbakepath:
>
> > + sys.path.insert(0, bitbakepath + '/lib')
>
> > + return bitbakepath
>
> > diff --git a/scripts/lib/wic/__init__.py b/scripts/lib/wic/__init__.py
>
> > index 85876b1..8556793 100644
>
> > --- a/scripts/lib/wic/__init__.py
>
> > +++ b/scripts/lib/wic/__init__.py
>
> > @@ -1,20 +1,10 @@
>
> > -#!/usr/bin/env python -tt
>
> > +#!/usr/bin/env python3
>
> > #
>
> > # Copyright (c) 2007 Red Hat, Inc.
>
> > # Copyright (c) 2011 Intel, Inc.
>
> > #
>
> > -# This program is free software; you can redistribute it and/or
>
> > modify it -# under the terms of the GNU General Public License as
>
> > published by the Free -# Software Foundation; version 2 of the License
>
> > +# SPDX-License-Identifier: GPL-2.0-only
>
> > #
>
> > -# This program is distributed in the hope that it will be useful, but
>
> > -# WITHOUT ANY WARRANTY; without even the implied warranty of
>
> > MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>
> > General Public License -# for more details.
>
> > -#
>
> > -# You should have received a copy of the GNU General Public License
>
> > along -# with this program; if not, write to the Free Software
>
> > Foundation, Inc., 59 -# Temple Place - Suite 330, Boston, MA
>
> > 02111-1307, USA.
>
> > class WicError(Exception):
>
> > pass
>
> > diff --git a/scripts/lib/wic/canned-wks/common.wks.inc
>
> > b/scripts/lib/wic/canned-wks/common.wks.inc index 5cf2fd1..89880b4
>
> > 100644 --- a/scripts/lib/wic/canned-wks/common.wks.inc
>
> > +++ b/scripts/lib/wic/canned-wks/common.wks.inc
>
> > @@ -1,3 +1,3 @@
>
> > # This file is included into 3 canned wks files from this directory
>
> > part /boot --source bootimg-pcbios --ondisk sda --label boot
>
> > --active --align 1024 -part / --source rootfs --ondisk sda
>
> > --fstype=ext4 --label platform --align 1024 +part / --source rootfs
>
> > --use-uuid --fstype=ext4 --label platform --align 1024 diff --git
>
> > a/scripts/lib/wic/canned-wks/directdisk-bootloader-config.cfg
>
> > b/scripts/lib/wic/canned-wks/directdisk-bootloader-config.cfg index
>
> > d5a07d2..c58e74a 100644 ---
>
> > a/scripts/lib/wic/canned-wks/directdisk-bootloader-config.cfg +++
>
> > b/scripts/lib/wic/canned-wks/directdisk-bootloader-config.cfg @@
>
> > -12,16 +12,16 @@ DEFAULT Graphics console boot LABEL Graphics console
>
> > boot KERNEL /vmlinuz
>
> > -APPEND label=boot root=/dev/sda2 rootwait
>
> > +APPEND label=boot rootwait
>
> >
>
> > LABEL Serial console boot
>
> > KERNEL /vmlinuz
>
> > -APPEND label=boot root=/dev/sda2 rootwait console=ttyS0,115200
>
> > +APPEND label=boot rootwait console=ttyS0,115200
>
> >
>
> > LABEL Graphics console install
>
> > KERNEL /vmlinuz
>
> > -APPEND label=install root=/dev/sda2 rootwait
>
> > +APPEND label=install rootwait
>
> >
>
> > LABEL Serial console install
>
> > KERNEL /vmlinuz
>
> > -APPEND label=install root=/dev/sda2 rootwait console=ttyS0,115200
>
> > +APPEND label=install rootwait console=ttyS0,115200
>
> > diff --git a/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in
>
> > b/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in new file mode 100644
>
> > index 0000000..7300e65
>
> > --- /dev/null
>
> > +++ b/scripts/lib/wic/canned-wks/efi-bootdisk.wks.in
>
> > @@ -0,0 +1,3 @@
>
> > +bootloader --ptable gpt
>
> > +part /boot --source rootfs --rootfs-dir=${IMAGE_ROOTFS}/boot
>
> > --fstype=vfat --label boot --active --align 1024 --use-uuid
>
> > --overhead-factor 1.0 +part / --source rootfs --fstype=ext4 --label
>
> > root --align 1024 --exclude-path boot/ diff --git
>
> > a/scripts/lib/wic/canned-wks/mkhybridiso.wks
>
> > b/scripts/lib/wic/canned-wks/mkhybridiso.wks index 9d34e9b..48c5ac4
>
> > 100644 --- a/scripts/lib/wic/canned-wks/mkhybridiso.wks +++
>
> > b/scripts/lib/wic/canned-wks/mkhybridiso.wks @@ -2,6 +2,6 @@ #
>
> > long-description: Creates an EFI and legacy bootable hybrid ISO image
>
> > # which can be used on optical media as well as USB media.
>
> > -part /boot --source isoimage-isohybrid
>
> > --sourceparams="loader=grub-efi,image_name=HYBRID_ISO_IMG" --ondisk
>
> > cd --label HYBRIDISO --fstype=ext4 +part /boot --source
>
> > isoimage-isohybrid
>
> > --sourceparams="loader=grub-efi,image_name=HYBRID_ISO_IMG" --ondisk
>
> > cd --label HYBRIDISO bootloader --timeout=15 --append="" diff --git
>
> > a/scripts/lib/wic/canned-wks/qemuriscv.wks
>
> > b/scripts/lib/wic/canned-wks/qemuriscv.wks new file mode 100644 index
>
> > 0000000..12c68b7 --- /dev/null +++
>
> > b/scripts/lib/wic/canned-wks/qemuriscv.wks @@ -0,0 +1,3 @@
>
> > +# short-description: Create qcow2 image for RISC-V QEMU machines
>
> > +
>
> > +part / --source rootfs --fstype=ext4 --label root --align 4096
>
> > --size 5G diff --git
>
> > a/scripts/lib/wic/canned-wks/qemux86-directdisk.wks
>
> > b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks index
>
> > a6518a0..22b4521 100644 ---
>
> > a/scripts/lib/wic/canned-wks/qemux86-directdisk.wks +++
>
> > b/scripts/lib/wic/canned-wks/qemux86-directdisk.wks @@ -4,5 +4,5 @@
>
> > include common.wks.inc
>
> >
>
> > -bootloader --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 " +bootloader --timeout=0 --append="rw
>
> > oprofile.timer=1 rootfstype=ext4 " diff --git
>
> > a/scripts/lib/wic/canned-wks/sdimage-bootpart.wks
>
> > b/scripts/lib/wic/canned-wks/sdimage-bootpart.wks index
>
> > 7ffd632..63bc4da 100644 ---
>
> > a/scripts/lib/wic/canned-wks/sdimage-bootpart.wks +++
>
> > b/scripts/lib/wic/canned-wks/sdimage-bootpart.wks @@ -2,5 +2,5 @@ #
>
> > long-description: Creates a partitioned SD card image. Boot files #
>
> > are located in the first vfat partition. -part /boot --source
>
> > bootimg-partition --ondisk mmcblk --fstype=vfat --label boot --active
>
> > --align 4 --size 16 -part / --source rootfs --ondisk mmcblk
>
> > --fstype=ext4 --label root --align 4 +part /boot --source
>
> > bootimg-partition --ondisk mmcblk0 --fstype=vfat --label boot
>
> > --active --align 4 --size 16 +part / --source rootfs --ondisk mmcblk0
>
> > --fstype=ext4 --label root --align 4 diff --git
>
> > a/scripts/lib/wic/canned-wks/systemd-bootdisk.wks
>
> > b/scripts/lib/wic/canned-wks/systemd-bootdisk.wks index
>
> > 4bd9d6a..95d7b97 100644 ---
>
> > a/scripts/lib/wic/canned-wks/systemd-bootdisk.wks +++
>
> > b/scripts/lib/wic/canned-wks/systemd-bootdisk.wks @@ -2,10 +2,10 @@ #
>
> > long-description: Creates a partitioned EFI disk image that the user
>
> > # can directly dd to boot media. The selected bootloader is
>
> > systemd-boot. -part /boot --source bootimg-efi
>
> > --sourceparams="loader=systemd-boot" --ondisk sda --label msdos
>
> > --active --align 1024 +part /boot --source bootimg-efi
>
> > --sourceparams="loader=systemd-boot" --ondisk sda --label msdos
>
> > --active --align 1024 --use-uuid part / --source rootfs --ondisk sda
>
> > --fstype=ext4 --label platform --align 1024 --use-uuid -part swap
>
> > --ondisk sda --size 44 --label swap1 --fstype=swap +part swap
>
> > --ondisk sda --size 44 --label swap1 --fstype=swap --use-uuid
>
> > bootloader --ptable gpt --timeout=5 --append="rootwait
>
> > rootfstype=ext4 console=ttyS0,115200 console=tty0" diff --git
>
> > a/scripts/lib/wic/engine.py b/scripts/lib/wic/engine.py index
>
> > f59821f..018815b 100644 --- a/scripts/lib/wic/engine.py +++
>
> > b/scripts/lib/wic/engine.py @@ -1,21 +1,7 @@ -# ex:ts=4:sw=4:sts=4:et
>
> > -# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
>
> > #
>
> > # Copyright (c) 2013, Intel Corporation.
>
> > -# All rights reserved.
>
> > #
>
> > -# This program is free software; you can redistribute it and/or
>
> > modify -# it under the terms of the G
> <https://www.google.com/maps/search/the+terms+of+the+G?entry=gmail&source=g>NU
> General Public License
>
> > version 2 as -# published by the Free Software Foundation.
>
> > -#
>
> > -# This program is distributed in the hope that it will be useful,
>
> > -# but WITHOUT ANY WARRANTY; without even the implied warranty of
>
> > -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>
> > -# GNU General Public License for more details.
>
> > -#
>
> > -# You should have received a copy of the GNU General Public License
>
> > along -# with this program; if not, write to the Free Software
>
> > Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA
>
> > 02110-1301 USA. +# SPDX-License-Identifier: GPL-2.0-only
>
> > #
>
> > # DESCRIPTION
>
> >
>
> > @@ -30,10 +16,18 @@
>
> >
>
> > import logging
>
> > import os
>
> > +import tempfile
>
> > +import json
>
> > +import subprocess
>
> > +import re
>
> > +
>
> > +from collections import namedtuple, OrderedDict
>
> > +from distutils.spawn import find_executable
>
> >
>
> > from wic import WicError
>
> > +from wic.filemap import sparse_copy
>
> > from wic.pluginbase import PluginMgr
>
> > -from wic.utils.misc import get_bitbake_var
>
> > +from wic.misc import get_bitbake_var, exec_cmd
>
> >
>
> > logger = logging.getLogger('wic')
>
> >
>
> > @@ -82,7 +76,8 @@ def find_canned_image(scripts_path, wks_file):
>
> > for fname in files:
>
> > if fname.endswith("~") or fname.endswith("#"):
>
> > continue
>
> > - if fname.endswith(".wks") and wks_file + ".wks" ==
>
> > fname:
>
> > + if ((fname.endswith(".wks") and wks_file + ".wks" ==
>
> > fname) or \
>
> > + (fname.endswith(".wks.in") and wks_file +
>
> > ".wks.in" == fname)): fullpath = os.path.join(canned_wks_dir, fname)
>
> > return fullpath
>
> > return None
>
> > @@ -99,7 +94,7 @@ def list_canned_images(scripts_path):
>
> > for fname in files:
>
> > if fname.endswith("~") or fname.endswith("#"):
>
> > continue
>
> > - if fname.endswith(".wks"):
>
> > + if fname.endswith(".wks") or
>
> > fname.endswith(".wks.in"): fullpath = os.path.join(canned_wks_dir,
>
> > fname) with open(fullpath) as wks:
>
> > for line in wks:
>
> > @@ -108,7 +103,7 @@ def list_canned_images(scripts_path):
>
> > if idx != -1:
>
> > desc = line[idx +
>
> > len("short-description:"):].strip() break
>
> > - basename = os.path.splitext(fname)[0]
>
> > + basename = fname.split('.')[0]
>
> > print(" %s\t\t%s" % (basename.ljust(30), desc))
>
> >
>
> >
>
> > @@ -184,7 +179,7 @@ def wic_create(wks_file, rootfs_dir, bootimg_dir,
>
> > kernel_dir, if not os.path.exists(options.outdir):
>
> > os.makedirs(options.outdir)
>
> >
>
> > - pname = 'direct'
>
> > + pname = options.imager
>
> > plugin_class = PluginMgr.get_plugins('imager').get(pname)
>
> > if not plugin_class:
>
> > raise WicError('Unknown plugin: %s' % pname)
>
> > @@ -201,17 +196,18 @@ def wic_list(args, scripts_path):
>
> > """
>
> > Print the list of images or source plugins.
>
> > """
>
> > - if len(args) < 1:
>
> > + if args.list_type is None:
>
> > return False
>
> >
>
> > - if args == ["images"]:
>
> > + if args.list_type == "images":
>
> > +
>
> > list_canned_images(scripts_path)
>
> > return True
>
> > - elif args == ["source-plugins"]:
>
> > + elif args.list_type == "source-plugins":
>
> > list_source_plugins()
>
> > return True
>
> > - elif len(args) == 2 and args[1] == "help":
>
> > - wks_file = args[0]
>
> > + elif len(args.help_for) == 1 and args.help_for[0] == 'help':
>
> > + wks_file = args.list_type
>
> > fullpath = find_canned_image(scripts_path, wks_file)
>
> > if not fullpath:
>
> > raise WicError("No image named %s found, exiting. "
>
> > @@ -224,6 +220,381 @@ def wic_list(args, scripts_path):
>
> >
>
> > return False
>
> >
>
> > +
>
> > +class Disk:
>
> > + def __init__(self, imagepath, native_sysroot, fstypes=('fat',
>
> > 'ext')):
>
> > + self.imagepath = imagepath
>
> > + self.native_sysroot = native_sysroot
>
> > + self.fstypes = fstypes
>
> > + self._partitions = None
>
> > + self._partimages = {}
>
> > + self._lsector_size = None
>
> > + self._psector_size = None
>
> > + self._ptable_format = None
>
> > +
>
> > + # find parted
>
> > + # read paths from $PATH environment variable
>
> > + # if it fails, use hardcoded paths
>
> > + pathlist = "/bin:/usr/bin:/usr/sbin:/sbin/"
>
> > + try:
>
> > + self.paths = os.environ['PATH'] + ":" + pathlist
>
> > + except KeyError:
>
> > + self.paths = pathlist
>
> > +
>
> > + if native_sysroot:
>
> > + for path in pathlist.split(':'):
>
> > + self.paths = "%s%s:%s" % (native_sysroot, path,
>
> > self.paths) +
>
> > + self.parted = find_executable("parted", self.paths)
>
> > + if not self.parted:
>
> > + raise WicError("Can't find executable parted")
>
> > +
>
> > + self.partitions = self.get_partitions()
>
> > +
>
> > + def __del__(self):
>
> > + for path in self._partimages.values():
>
> > + os.unlink(path)
>
> > +
>
> > + def get_partitions(self):
>
> > + if self._partitions is None:
>
> > + self._partitions = OrderedDict()
>
> > + out = exec_cmd("%s -sm %s unit B print" % (self.parted,
>
> > self.imagepath))
>
> > + parttype = namedtuple("Part", "pnum start end size
>
> > fstype")
>
> > + splitted = out.splitlines()
>
> > + # skip over possible errors in exec_cmd output
>
> > + try:
>
> > + idx =splitted.index("BYT;")
>
> > + except ValueError:
>
> > + raise WicError("Error getting partition information
>
> > from %s" % (self.parted))
>
> > + lsector_size, psector_size, self._ptable_format =
>
> > splitted[idx + 1].split(":")[3:6]
>
> > + self._lsector_size = int(lsector_size)
>
> > + self._psector_size = int(psector_size)
>
> > + for line in splitted[idx + 2:]:
>
> > + pnum, start, end, size, fstype = line.split(':')[:5]
>
> > + partition = parttype(int(pnum), int(start[:-1]),
>
> > int(end[:-1]),
>
> > + int(size[:-1]), fstype)
>
> > + self._partitions[pnum] = partition
>
> > +
>
> > + return self._partitions
>
> > +
>
> > + def __getattr__(self, name):
>
> > + """Get path to the executable in a lazy way."""
>
> > + if name in ("mdir", "mcopy", "mdel", "mdeltree", "sfdisk",
>
> > "e2fsck",
>
> > + "resize2fs", "mkswap", "mkdosfs",
>
> > "debugfs","blkid"):
>
> > + aname = "_%s" % name
>
> > + if aname not in self.__dict__:
>
> > + setattr(self, aname, find_executable(name,
>
> > self.paths))
>
> > + if aname not in self.__dict__ or
>
> > self.__dict__[aname] is None:
>
> > + raise WicError("Can't find executable
>
> > '{}'".format(name))
>
> > + return self.__dict__[aname]
>
> > + return self.__dict__[name]
>
> > +
>
> > + def _get_part_image(self, pnum):
>
> > + if pnum not in self.partitions:
>
> > + raise WicError("Partition %s is not in the image" % pnum)
>
> > + part = self.partitions[pnum]
>
> > + # check if fstype is supported
>
> > + for fstype in self.fstypes:
>
> > + if part.fstype.startswith(fstype):
>
> > + break
>
> > + else:
>
> > + raise WicError("Not supported fstype:
>
> > {}".format(part.fstype))
>
> > + if pnum not in self._partimages:
>
> > + tmpf = tempfile.NamedTemporaryFile(prefix="wic-part")
>
> > + dst_fname = tmpf.name
>
> > + tmpf.close()
>
> > + sparse_copy(self.imagepath, dst_fname, skip=part.start,
>
> > length=part.size)
>
> > + self._partimages[pnum] = dst_fname
>
> > +
>
> > + return self._partimages[pnum]
>
> > +
>
> > + def _put_part_image(self, pnum):
>
> > + """Put partition image into partitioned image."""
>
> > + sparse_copy(self._partimages[pnum], self.imagepath,
>
> > + seek=self.partitions[pnum].start)
>
> > +
>
> > + def dir(self, pnum, path):
>
> > + if pnum not in self.partitions:
>
> > + raise WicError("Partition %s is not in the image" % pnum)
>
> > +
>
> > + if self.partitions[pnum].fstype.startswith('ext'):
>
> > + return exec_cmd("{} {} -R 'ls -l
>
> > {}'".format(self.debugfs,
>
> > +
>
> > self._get_part_image(pnum),
>
> > + path),
>
> > as_shell=True)
>
> > + else: # fat
>
> > + return exec_cmd("{} -i {} ::{}".format(self.mdir,
>
> > +
>
> > self._get_part_image(pnum),
>
> > + path))
>
> > +
>
> > + def copy(self, src, dest):
>
> > + """Copy partition image into wic image."""
>
> > + pnum = dest.part if isinstance(src, str) else src.part
>
> > +
>
> > + if self.partitions[pnum].fstype.startswith('ext'):
>
> > + if isinstance(src, str):
>
> > + cmd = "printf 'cd {}\nwrite {} {}\n' | {} -w {}".\
>
> > + format(os.path.dirname(dest.path), src,
>
> > os.path.basename(src),
>
> > + self.debugfs,
>
> > self._get_part_image(pnum))
>
> > + else: # copy from wic
>
> > + # run both dump and rdump to support both files and
>
> > directory
>
> > + cmd = "printf 'cd {}\ndump /{} {}\nrdump /{} {}\n' |
>
> > {} {}".\
>
> > + format(os.path.dirname(src.path), src.path,
>
> > + dest, src.path, dest, self.debugfs,
>
> > + self._get_part_image(pnum))
>
> > + else: # fat
>
> > + if isinstance(src, str):
>
> > + cmd = "{} -i {} -snop {} ::{}".format(self.mcopy,
>
> > +
>
> > self._get_part_image(pnum),
>
> > + src, dest.path)
>
> > + else:
>
> > + cmd = "{} -i {} -snop ::{} {}".format(self.mcopy,
>
> > +
>
> > self._get_part_image(pnum),
>
> > + src.path, dest)
>
> > +
>
> > + exec_cmd(cmd, as_shell=True)
>
> > + self._put_part_image(pnum)
>
> > +
>
> > + def remove_ext(self, pnum, path, recursive):
>
> > + """
>
> > + Remove files/dirs and their contents from the partition.
>
> > + This only applies to ext* partition.
>
> > + """
>
> > + abs_path = re.sub('\/\/+', '/', path)
>
> > + cmd = "{} {} -wR 'rm \"{}\"'".format(self.debugfs,
>
> > +
>
> > self._get_part_image(pnum),
>
> > + abs_path)
>
> > + out = exec_cmd(cmd , as_shell=True)
>
> > + for line in out.splitlines():
>
> > + if line.startswith("rm:"):
>
> > + if "file is a directory" in line:
>
> > + if recursive:
>
> > + # loop through content and delete them one
>
> > by one if
>
> > + # flaged with -r
>
> > + subdirs = iter(self.dir(pnum,
>
> > abs_path).splitlines())
>
> > + next(subdirs)
>
> > + for subdir in subdirs:
>
> > + dir = subdir.split(':')[1].split(" ",
>
> > 1)[1]
>
> > + if not dir == "." and not dir == "..":
>
> > + self.remove_ext(pnum, "%s/%s" %
>
> > (abs_path, dir), recursive) +
>
> > + rmdir_out = exec_cmd("{} {} -wR 'rmdir
>
> > \"{}\"'".format(self.debugfs,
>
> > +
>
> > self._get_part_image(pnum),
>
> > +
>
> > abs_path.rstrip('/'))
>
> > + , as_shell=True)
>
> > +
>
> > + for rmdir_line in rmdir_out.splitlines():
>
> > + if "directory not empty" in rmdir_line:
>
> > + raise WicError("Could not complete
>
> > operation: \n%s \n"
>
> > + "use -r to remove
>
> > non-empty directory" % rmdir_line)
>
> > + if rmdir_line.startswith("rmdir:"):
>
> > + raise WicError("Could not complete
>
> > operation: \n%s "
>
> > + "\n%s" % (str(line),
>
> > rmdir_line)) +
>
> > + else:
>
> > + raise WicError("Could not complete operation:
>
> > \n%s "
>
> > + "\nUnable to remove %s" %
>
> > (str(line), abs_path)) +
>
> > + def remove(self, pnum, path, recursive):
>
> > + """Remove files/dirs from the partition."""
>
> > + partimg = self._get_part_image(pnum)
>
> > + if self.partitions[pnum].fstype.startswith('ext'):
>
> > + self.remove_ext(pnum, path, recursive)
>
> > +
>
> > + else: # fat
>
> > + cmd = "{} -i {} ::{}".format(self.mdel, partimg, path)
>
> > + try:
>
> > + exec_cmd(cmd)
>
> > + except WicError as err:
>
> > + if "not found" in str(err) or "non empty" in
>
> > str(err):
>
> > + # mdel outputs 'File ... not found' or
>
> > 'directory .. non empty"
>
> > + # try to use mdeltree as path could be a
>
> > directory
>
> > + cmd = "{} -i {} ::{}".format(self.mdeltree,
>
> > + partimg, path)
>
> > + exec_cmd(cmd)
>
> > + else:
>
> > + raise err
>
> > + self._put_part_image(pnum)
>
> > +
>
> > + def write(self, target, expand):
>
> > + """Write disk image to the media or file."""
>
> > + def write_sfdisk_script(outf, parts):
>
> > + for key, val in parts['partitiontable'].items():
>
> > + if key in ("partitions", "device", "firstlba",
>
> > "lastlba"):
>
> > + continue
>
> > + if key == "id":
>
> > + key = "label-id"
>
> > + outf.write("{}: {}\n".format(key, val))
>
> > + outf.write("\n")
>
> > + for part in parts['partitiontable']['partitions']:
>
> > + line = ''
>
> > + for name in ('attrs', 'name', 'size', 'type',
>
> > 'uuid'):
>
> > + if name == 'size' and part['type'] == 'f':
>
> > + # don't write size for extended partition
>
> > + continue
>
> > + val = part.get(name)
>
> > + if val:
>
> > + line += '{}={}, '.format(name, val)
>
> > + if line:
>
> > + line = line[:-2] # strip ', '
>
> > + if part.get('bootable'):
>
> > + line += ' ,bootable'
>
> > + outf.write("{}\n".format(line))
>
> > + outf.flush()
>
> > +
>
> > + def read_ptable(path):
>
> > + out = exec_cmd("{} -J {}".format(self.sfdisk, path))
>
> > + return json.loads(out)
>
> > +
>
> > + def write_ptable(parts, target):
>
> > + with tempfile.NamedTemporaryFile(prefix="wic-sfdisk-",
>
> > mode='w') as outf:
>
> > + write_sfdisk_script(outf, parts)
>
> > + cmd = "{} --no-reread {} < {} ".format(self.sfdisk,
>
> > target, outf.name)
>
> > + exec_cmd(cmd, as_shell=True)
>
> > +
>
> > + if expand is None:
>
> > + sparse_copy(self.imagepath, target)
>
> > + else:
>
> > + # copy first sectors that may contain bootloader
>
> > + sparse_copy(self.imagepath, target, length=2048 *
>
> > self._lsector_size) +
>
> > + # copy source partition table to the target
>
> > + parts = read_ptable(self.imagepath)
>
> > + write_ptable(parts, target)
>
> > +
>
> > + # get size of unpartitioned space
>
> > + free = None
>
> > + for line in exec_cmd("{} -F {}".format(self.sfdisk,
>
> > target)).splitlines():
>
> > + if line.startswith("Unpartitioned space ") and
>
> > line.endswith("sectors"):
>
> > + free = int(line.split()[-2])
>
> > + # Align free space to a 2048 sector boundary.
>
> > YOCTO #12840.
>
> > + free = free - (free % 2048)
>
> > + if free is None:
>
> > + raise WicError("Can't get size of unpartitioned
>
> > space") +
>
> > + # calculate expanded partitions sizes
>
> > + sizes = {}
>
> > + num_auto_resize = 0
>
> > + for num, part in
>
> > enumerate(parts['partitiontable']['partitions'], 1):
>
> > + if num in expand:
>
> > + if expand[num] != 0: # don't resize partition if
>
> > size is set to 0
>
> > + sectors = expand[num] // self._lsector_size
>
> > + free -= sectors - part['size']
>
> > + part['size'] = sectors
>
> > + sizes[num] = sectors
>
> > + elif part['type'] != 'f':
>
> > + sizes[num] = -1
>
> > + num_auto_resize += 1
>
> > +
>
> > + for num, part in
>
> > enumerate(parts['partitiontable']['partitions'], 1):
>
> > + if sizes.get(num) == -1:
>
> > + part['size'] += free // num_auto_resize
>
> > +
>
> > + # write resized partition table to the target
>
> > + write_ptable(parts, target)
>
> > +
>
> > + # read resized partition table
>
> > + parts = read_ptable(target)
>
> > +
>
> > + # copy partitions content
>
> > + for num, part in
>
> > enumerate(parts['partitiontable']['partitions'], 1):
>
> > + pnum = str(num)
>
> > + fstype = self.partitions[pnum].fstype
>
> > +
>
> > + # copy unchanged partition
>
> > + if part['size'] == self.partitions[pnum].size //
>
> > self._lsector_size:
>
> > + logger.info("copying unchanged partition
>
> > {}".format(pnum))
>
> > + sparse_copy(self._get_part_image(pnum), target,
>
> > seek=part['start'] * self._lsector_size)
>
> > + continue
>
> > +
>
> > + # resize or re-create partitions
>
> > + if fstype.startswith('ext') or
>
> > fstype.startswith('fat') or \
>
> > + fstype.startswith('linux-swap'):
>
> > +
>
> > + partfname = None
>
> > + with
>
> > tempfile.NamedTemporaryFile(prefix="wic-part{}-".format(pnum)) as
>
> > partf:
>
> > + partfname = partf.name
>
> > +
>
> > + if fstype.startswith('ext'):
>
> > + logger.info("resizing ext partition
>
> > {}".format(pnum))
>
> > + partimg = self._get_part_image(pnum)
>
> > + sparse_copy(partimg, partfname)
>
> > + exec_cmd("{} -pf {}".format(self.e2fsck,
>
> > partfname))
>
> > + exec_cmd("{} {} {}s".format(\
>
> > + self.resize2fs, partfname,
>
> > part['size']))
>
> > + elif fstype.startswith('fat'):
>
> > + logger.info("copying content of the fat
>
> > partition {}".format(pnum))
>
> > + with
>
> > tempfile.TemporaryDirectory(prefix='wic-fatdir-') as tmpdir:
>
> > + # copy content to the temporary directory
>
> > + cmd = "{} -snompi {} ::
>
> > {}".format(self.mcopy,
>
> > +
>
> > self._get_part_image(pnum),
>
> > +
>
> > tmpdir)
>
> > + exec_cmd(cmd)
>
> > + # create new msdos partition
>
> > + label = part.get("name")
>
> > + label_str = "-n {}".format(label) if
>
> > label else '' +
>
> > + cmd = "{} {} -C {}
>
> > {}".format(self.mkdosfs, label_str, partfname,
>
> > +
>
> > part['size'])
>
> > + exec_cmd(cmd)
>
> > + # copy content from the temporary
>
> > directory to the new partition
>
> > + cmd = "{} -snompi {} {}/*
>
> > ::".format(self.mcopy, partfname, tmpdir)
>
> > + exec_cmd(cmd, as_shell=True)
>
> > + elif fstype.startswith('linux-swap'):
>
> > + logger.info("creating swap partition
>
> > {}".format(pnum))
>
> > + label = part.get("name")
>
> > + label_str = "-L {}".format(label) if label
>
> > else ''
>
> > + out = exec_cmd("{} --probe
>
> > {}".format(self.blkid, self._get_part_image(pnum)))
>
> > + uuid =
>
> > out[out.index("UUID=\"")+6:out.index("UUID=\"")+42]
>
> > + uuid_str = "-U {}".format(uuid) if uuid else
>
> > ''
>
> > + with open(partfname, 'w') as sparse:
>
> > + os.ftruncate(sparse.fileno(),
>
> > part['size'] * self._lsector_size)
>
> > + exec_cmd("{} {} {} {}".format(self.mkswap,
>
> > label_str, uuid_str, partfname))
>
> > + sparse_copy(partfname, target,
>
> > seek=part['start'] * self._lsector_size)
>
> > + os.unlink(partfname)
>
> > + elif part['type'] != 'f':
>
> > + logger.warning("skipping partition {}:
>
> > unsupported fstype {}".format(pnum, fstype)) +
>
> > +def wic_ls(args, native_sysroot):
>
> > + """List contents of partitioned image or vfat partition."""
>
> > + disk = Disk(args.path.image, native_sysroot)
>
> > + if not args.path.part:
>
> > + if disk.partitions:
>
> > + print('Num Start End Size
>
> > Fstype')
>
> > + for part in disk.partitions.values():
>
> > + print("{:2d} {:12d} {:12d} {:12d} {}".format(\
>
> > + part.pnum, part.start, part.end,
>
> > + part.size, part.fstype))
>
> > + else:
>
> > + path = args.path.path or '/'
>
> > + print(disk.dir(args.path.part, path))
>
> > +
>
> > +def wic_cp(args, native_sysroot):
>
> > + """
>
> > + Copy file or directory to/from the vfat/ext partition of
>
> > + partitioned image.
>
> > + """
>
> > + if isinstance(args.dest, str):
>
> > + disk = Disk(args.src.image, native_sysroot)
>
> > + else:
>
> > + disk = Disk(args.dest.image, native_sysroot)
>
> > + disk.copy(args.src, args.dest)
>
> > +
>
> > +
>
> > +def wic_rm(args, native_sysroot):
>
> > + """
>
> > + Remove files or directories from the vfat partition of
>
> > + partitioned image.
>
> > + """
>
> > + disk = Disk(args.path.image, native_sysroot)
>
> > + disk.remove(args.path.part, args.path.path,
>
> > args.recursive_delete) +
>
> > +def wic_write(args, native_sysroot):
>
> > + """
>
> > + Write image to a target device.
>
> > + """
>
> > + disk = Disk(args.image, native_sysroot, ('fat', 'ext',
>
> > 'linux-swap'))
>
> > + disk.write(args.target, args.expand)
>
> > +
>
> > def find_canned(scripts_path, file_name):
>
> > """
>
> > Find a file either by its path or by name in the canned files
>
> > dir. diff --git a/scripts/lib/wic/filemap.py
>
> > b/scripts/lib/wic/filemap.py index 080668e..4d9da28 100644
>
> > --- a/scripts/lib/wic/filemap.py
>
> > +++ b/scripts/lib/wic/filemap.py
>
> > @@ -1,13 +1,8 @@
>
> > +#
>
> > # Copyright (c) 2012 Intel, Inc.
>
> > #
>
> > -# This program is free software; you can redistribute it and/or
>
> > modify -# it under the terms of the GNU General Public License,
>
> > version 2, -# as published by the Free Software Foundation.
>
> > +# SPDX-License-Identifier: GPL-2.0-only
>
> > #
>
> > -# This program is distributed in the hope that it will be useful, but
>
> > -# WITHOUT ANY WARRANTY; without even the implied warranty of
>
> > -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>
> > -# General Public License for more details.
>
> >
>
> > """
>
> > This module implements python implements a way to get file block.
>
> > Two methods @@ -22,6 +17,7 @@ and returns an instance of the class.
>
> > # * Too many instance attributes (R0902)
>
> > # pylint: disable=R0902
>
> >
>
> > +import errno
>
> > import os
>
> > import struct
>
> > import array
>
> > @@ -34,14 +30,23 @@ def get_block_size(file_obj):
>
> > Returns block size for file object 'file_obj'. Errors are
>
> > indicated by the 'IOError' exception.
>
> > """
>
> > -
>
> > - from fcntl import ioctl
>
> > - import struct
>
> > -
>
> > # Get the block size of the host file-system for the image file
>
> > by calling # the FIGETBSZ ioctl (number 2).
>
> > - binary_data = ioctl(file_obj, 2, struct.pack('I', 0))
>
> > - return struct.unpack('I', binary_data)[0]
>
> > + try:
>
> > + binary_data = fcntl.ioctl(file_obj, 2, struct.pack('I', 0))
>
> > + bsize = struct.unpack('I', binary_data)[0]
>
> > + except OSError:
>
> > + bsize = None
>
> > +
>
> > + # If ioctl causes OSError or give bsize to zero failback to
>
> > os.fstat
>
> > + if not bsize:
>
> > + import os
>
> > + stat = os.fstat(file_obj.fileno())
>
> > + if hasattr(stat, 'st_blksize'):
>
> > + bsize = stat.st_blksize
>
> > + else:
>
> > + raise IOError("Unable to determine block size")
>
> > + return bsize
>
> >
>
> > class ErrorNotSupp(Exception):
>
> > """
>
> > @@ -137,15 +142,6 @@ class _FilemapBase(object):
>
> >
>
> > raise Error("the method is not implemented")
>
> >
>
> > - def block_is_unmapped(self, block): # pylint: disable=W0613,R0201
>
> > - """
>
> > - This method has has to be implemented by child classes. It
>
> > returns
>
> > - 'True' if block number 'block' of the image file is not
>
> > mapped (hole)
>
> > - and 'False' otherwise.
>
> > - """
>
> > -
>
> > - raise Error("the method is not implemented")
>
> > -
>
> > def get_mapped_ranges(self, start, count): # pylint:
>
> > disable=W0613,R0201 """
>
> > This method has has to be implemented by child classes. This
>
> > is a @@ -159,15 +155,6 @@ class _FilemapBase(object):
>
> >
>
> > raise Error("the method is not implemented")
>
> >
>
> > - def get_unmapped_ranges(self, start, count): # pylint:
>
> > disable=W0613,R0201
>
> > - """
>
> > - This method has has to be implemented by child classes. Just
>
> > like
>
> > - 'get_mapped_ranges()', but yields unmapped block ranges
>
> > instead
>
> > - (holes).
>
> > - """
>
> > -
>
> > - raise Error("the method is not implemented")
>
> > -
>
> >
>
> > # The 'SEEK_HOLE' and 'SEEK_DATA' options of the file seek system
>
> > call _SEEK_DATA = 3
>
> > @@ -185,9 +172,9 @@ def _lseek(file_obj, offset, whence):
>
> > except OSError as err:
>
> > # The 'lseek' system call returns the ENXIO if there is no
>
> > data or # hole starting from the specified offset.
>
> > - if err.errno == os.errno.ENXIO:
>
> > + if err.errno == errno.ENXIO:
>
> > return -1
>
> > - elif err.errno == os.errno.EINVAL:
>
> > + elif err.errno == errno.EINVAL:
>
> > raise ErrorNotSupp("the kernel or file-system does not
>
> > support " "\"SEEK_HOLE\" and \"SEEK_DATA\"")
>
> > else:
>
> > @@ -228,7 +215,7 @@ class FilemapSeek(_FilemapBase):
>
> > try:
>
> > tmp_obj = tempfile.TemporaryFile("w+", dir=directory)
>
> > except IOError as err:
>
> > - raise ErrorNotSupp("cannot create a temporary in \"%s\":
>
> > %s"
>
> > + raise ErrorNotSupp("cannot create a temporary in \"%s\":
>
> > %s" \ % (directory, err))
>
> >
>
> > try:
>
> > @@ -260,15 +247,10 @@ class FilemapSeek(_FilemapBase):
>
> > % (block, result))
>
> > return result
>
> >
>
> > - def block_is_unmapped(self, block):
>
> > - """Refer the '_FilemapBase' class for the documentation."""
>
> > - return not self.block_is_mapped(block)
>
> > -
>
> > def _get_ranges(self, start, count, whence1, whence2):
>
> > """
>
> > - This function implements 'get_mapped_ranges()' and
>
> > - 'get_unmapped_ranges()' depending on what is passed in the
>
> > 'whence1'
>
> > - and 'whence2' arguments.
>
> > + This function implements 'get_mapped_ranges()' depending
>
> > + on what is passed in the 'whence1' and 'whence2' arguments.
>
> > """
>
> >
>
> > assert whence1 != whence2
>
> > @@ -298,12 +280,6 @@ class FilemapSeek(_FilemapBase):
>
> > % (start, count, start + count - 1))
>
> > return self._get_ranges(start, count, _SEEK_DATA, _SEEK_HOLE)
>
> >
>
> > - def get_unmapped_ranges(self, start, count):
>
> > - """Refer the '_FilemapBase' class for the documentation."""
>
> > - self._log.debug("FilemapSeek: get_unmapped_ranges(%d,
>
> > %d(%d))"
>
> > - % (start, count, start + count - 1))
>
> > - return self._get_ranges(start, count, _SEEK_HOLE, _SEEK_DATA)
>
> > -
>
> >
>
> > # Below goes the FIEMAP ioctl implementation, which is not very
>
> > readable # because it deals with the rather complex FIEMAP ioctl. To
>
> > understand the @@ -390,12 +366,12 @@ class
>
> > FilemapFiemap(_FilemapBase): except IOError as err:
>
> > # Note, the FIEMAP ioctl is supported by the Linux
>
> > kernel starting # from version 2.6.28 (year 2008).
>
> > - if err.errno == os.errno.EOPNOTSUPP:
>
> > + if err.errno == errno.EOPNOTSUPP:
>
> > errstr = "FilemapFiemap: the FIEMAP ioctl is not
>
> > supported " \ "by the file-system"
>
> > self._log.debug(errstr)
>
> > raise ErrorNotSupp(errstr)
>
> > - if err.errno == os.errno.ENOTTY:
>
> > + if err.errno == errno.ENOTTY:
>
> > errstr = "FilemapFiemap: the FIEMAP ioctl is not
>
> > supported " \ "by the kernel"
>
> > self._log.debug(errstr)
>
> > @@ -417,10 +393,6 @@ class FilemapFiemap(_FilemapBase):
>
> > % (block, result))
>
> > return result
>
> >
>
> > - def block_is_unmapped(self, block):
>
> > - """Refer the '_FilemapBase' class for the documentation."""
>
> > - return not self.block_is_mapped(block)
>
> > -
>
> > def _unpack_fiemap_extent(self, index):
>
> > """
>
> > Unpack a 'struct fiemap_extent' structure object number
>
> > 'index' from @@ -497,23 +469,28 @@ class FilemapFiemap(_FilemapBase):
>
> > % (first_prev, last_prev))
>
> > yield (first_prev, last_prev)
>
> >
>
> > - def get_unmapped_ranges(self, start, count):
>
> > +class FilemapNobmap(_FilemapBase):
>
> > + """
>
> > + This class is used when both the 'SEEK_DATA/HOLE' and FIEMAP are
>
> > not
>
> > + supported by the filesystem or kernel.
>
> > + """
>
> > +
>
> > + def __init__(self, image, log=None):
>
> > """Refer the '_FilemapBase' class for the documentation."""
>
> > - self._log.debug("FilemapFiemap: get_unmapped_ranges(%d,
>
> > %d(%d))"
>
> > - % (start, count, start + count - 1))
>
> > - hole_first = start
>
> > - for first, last in self._do_get_mapped_ranges(start, count):
>
> > - if first > hole_first:
>
> > - self._log.debug("FilemapFiemap: yielding range (%d,
>
> > %d)"
>
> > - % (hole_first, first - 1))
>
> > - yield (hole_first, first - 1)
>
> >
>
> > - hole_first = last + 1
>
> > + # Call the base class constructor first
>
> > + _FilemapBase.__init__(self, image, log)
>
> > + self._log.debug("FilemapNobmap: initializing")
>
> >
>
> > - if hole_first < start + count:
>
> > - self._log.debug("FilemapFiemap: yielding range (%d, %d)"
>
> > - % (hole_first, start + count - 1))
>
> > - yield (hole_first, start + count - 1)
>
> > + def block_is_mapped(self, block):
>
> > + """Refer the '_FilemapBase' class for the documentation."""
>
> > + return True
>
> > +
>
> > + def get_mapped_ranges(self, start, count):
>
> > + """Refer the '_FilemapBase' class for the documentation."""
>
> > + self._log.debug("FilemapNobmap: get_mapped_ranges(%d,
>
> > %d(%d))"
>
> > + % (start, count, start + count - 1))
>
> > + yield (start, start + count -1)
>
> >
>
> > def filemap(image, log=None):
>
> > """
>
> > @@ -528,26 +505,56 @@ def filemap(image, log=None):
>
> > try:
>
> > return FilemapFiemap(image, log)
>
> > except ErrorNotSupp:
>
> > - return FilemapSeek(image, log)
>
> > + try:
>
> > + return FilemapSeek(image, log)
>
> > + except ErrorNotSupp:
>
> > + return FilemapNobmap(image, log)
>
> >
>
> > -def sparse_copy(src_fname, dst_fname, offset=0, skip=0):
>
> > - """Efficiently copy sparse file to or into another file."""
>
> > - fmap = filemap(src_fname)
>
> > +def sparse_copy(src_fname, dst_fname, skip=0, seek=0,
>
> > + length=0, api=None):
>
> > + """
>
> > + Efficiently copy sparse file to or into another file.
>
> > +
>
> > + src_fname: path to source file
>
> > + dst_fname: path
> <https://www.google.com/maps/search/dst_fname:+path?entry=gmail&source=g>
> to destination file
>
> > + skip: skip N bytes at thestart of src
>
> > + seek: seek N bytes from the start of dst
>
> > + length: read N bytes from src and write them to dst
>
> > + api: FilemapFiemap or FilemapSeek object
>
> > + """
>
> > + if not api:
>
> > + api = filemap
>
> > + fmap = api(src_fname)
>
> > try:
>
> > dst_file = open(dst_fname, 'r+b')
>
> > except IOError:
>
> > dst_file = open(dst_fname, 'wb')
>
> > - dst_file.truncate(os.path.getsize(src_fname))
>
> > + if length:
>
> > + dst_size = length + seek
>
> > + else:
>
> > + dst_size = os.path.getsize(src_fname) + seek - skip
>
> > + dst_file.truncate(dst_size)
>
> >
>
> > + written = 0
>
> > for first, last in fmap.get_mapped_ranges(0, fmap.blocks_cnt):
>
> > start = first * fmap.block_size
>
> > end = (last + 1) * fmap.block_size
>
> >
>
> > + if skip >= end:
>
> > + continue
>
> > +
>
> > if start < skip < end:
>
> > - fmap._f_image.seek(skip, os.SEEK_SET)
>
> > - else:
>
> > - fmap._f_image.seek(start, os.SEEK_SET)
>
> > - dst_file.seek(offset + start, os.SEEK_SET)
>
> > + start = skip
>
> > +
>
> > + fmap._f_image.seek(start, os.SEEK_SET)
>
> > +
>
> > + written += start - skip - written
>
> > + if length and written >= length:
>
> > + dst_file.seek(seek + length, os.SEEK_SET)
>
> > + dst_file.close()
>
> > + return
>
> > +
>
> > + dst_file.seek(seek + start - skip, os.SEEK_SET)
>
> >
>
> > chunk_size = 1024 * 1024
>
> > to_read = end - start
>
> > @@ -556,7 +563,14 @@ def sparse_copy(src_fname, dst_fname, offset=0,
>
> > skip=0): while read < to_read:
>
> > if read + chunk_size > to_read:
>
> > chunk_size = to_read - read
>
> > - chunk = fmap._f_image.read(chunk_size)
>
> > + size = chunk_size
>
> > + if length and written + size > length:
>
> > + size = length - written
>
> > + chunk = fmap._f_image.read(size)
>
> > dst_file.write(chunk)
>
> > - read += chunk_size
>
> > + read += size
>
> > + written += size
>
> > + if written == length:
>
> > + dst_file.close()
>
> > + return
>
> > dst_file.close()
>
> > diff --git a/scripts/lib/wic/help.py b/scripts/lib/wic/help.py
>
> > index 148da89..bd3a2b9 100644
>
> > --- a/scripts/lib/wic/help.py
>
> > +++ b/scripts/lib/wic/help.py
>
> > @@ -1,21 +1,6 @@
>
> > -# ex:ts=4:sw=4:sts=4:et
>
> > -# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
>
> > -#
>
> > # Copyright (c) 2013, Intel Corporation.
>
> > -# All rights reserved.
>
> > -#
>
> > -# This program is free software; you can redistribute it and/or
>
> > modify -# it under the terms of the GNU General Public License
>
> > version 2 as -# published by the Free Software Foundation.
>
> > #
>
> > -# This program is distributed in the hope that it will be useful,
>
> > -# but WITHOUT ANY WARRANTY; without even the implied warranty of
>
> > -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>
> > -# GNU General Public License for more details.
>
> > -#
>
> > -# You should have received a copy of the GNU General Public License
>
> > along -# with this program; if not, write to the Free Software
>
> > Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA
>
> > 02110-1301 USA. +# SPDX-License-Identifier: GPL-2.0-only
>
> > #
>
> > # DESCRIPTION
>
> > # This module implements some basic help invocation functions along
>
> > @@ -56,7 +41,7 @@ def wic_help(args, usage_str, subcommands):
>
> > """
>
> > Subcommand help dispatcher.
>
> > """
>
> > - if len(args) == 1 or not display_help(args[1], subcommands):
>
> > + if args.help_topic == None or not display_help(args.help_topic,
>
> > subcommands): print(usage_str)
>
> >
>
> >
>
> > @@ -82,19 +67,20 @@ def invoke_subcommand(args, parser,
>
> > main_command_usage, subcommands): Dispatch to subcommand handler
>
> > borrowed from combo-layer. Should use argparse, but has to work in
>
> > 2.6. """
>
> > - if not args:
>
> > + if not args.command:
>
> > logger.error("No subcommand specified, exiting")
>
> > parser.print_help()
>
> > return 1
>
> > - elif args[0] == "help":
>
> > + elif args.command == "help":
>
> > wic_help(args, main_command_usage, subcommands)
>
> > - elif args[0] not in subcommands:
>
> > - logger.error("Unsupported subcommand %s, exiting\n", args[0])
>
> > + elif args.command not in subcommands:
>
> > + logger.error("Unsupported subcommand %s, exiting\n",
>
> > args.command) parser.print_help()
>
> > return 1
>
> > else:
>
> > - usage = subcommands.get(args[0], subcommand_error)[1]
>
> > - subcommands.get(args[0], subcommand_error)[0](args[1:],
>
> > usage)
>
> > + subcmd = subcommands.get(args.command, subcommand_error)
>
> > + usage = subcmd[1]
>
> > + subcmd[0](args, usage)
>
> >
>
> >
>
> > ##
>
> > @@ -130,10 +116,10 @@ wic_create_usage = """
>
> > Create a new OpenEmbedded image
>
> >
>
> > usage: wic create <wks file or image name> [-o <DIRNAME> | --outdir
>
> > <DIRNAME>]
>
> > - [-i <JSON PROPERTY FILE> | --infile <JSON PROPERTY_FILE>]
>
> > [-e | --image-name] [-s, --skip-build-check] [-D,
>
> > --debug] [-r, --rootfs-dir] [-b, --bootimg-dir]
>
> > [-k, --kernel-dir] [-n, --native-sysroot] [-f,
>
> > --build-rootfs]
>
> > + [-c, --compress-with] [-m, --bmap]
>
> >
>
> > This command creates an OpenEmbedded image based on the 'OE
>
> > kickstart commands' found in the <wks file>.
>
> > @@ -154,7 +140,7 @@ SYNOPSIS
>
> > [-e | --image-name] [-s, --skip-build-check] [-D, --debug]
>
> > [-r, --rootfs-dir] [-b, --bootimg-dir]
>
> > [-k, --kernel-dir] [-n, --native-sysroot] [-f,
>
> > --build-rootfs]
>
> > - [-c, --compress-with] [-m, --bmap]
>
> > + [-c, --compress-with] [-m, --bmap] [--no-fstab-update]
>
> >
>
> > DESCRIPTION
>
> > This command creates an OpenEmbedded image based on the 'OE
>
> > @@ -226,6 +212,11 @@ DESCRIPTION
>
> >
>
> > The -m option is used to produce .bmap file for the image. This
>
> > file can be used to flash image using bmaptool utility.
>
> > +
>
> > + The --no-fstab-update option is used to doesn't change fstab
>
> > file. When
>
> > + using this option the final fstab file will be same that in
>
> > rootfs and
>
> > + wic doesn't update file, e.g adding a new mount point. User can
>
> > control
>
> > + the fstab file content in base-files recipe.
>
> > """
>
> >
>
> > wic_list_usage = """
>
> > @@ -283,6 +274,243 @@ DESCRIPTION
>
> > details.
>
> > """
>
> >
>
> > +wic_ls_usage = """
>
> > +
>
> > + List content of a partitioned image
>
> > +
>
> > + usage: wic ls <image>[:<partition>[<path>]] [--native-sysroot
>
> > <path>] +
>
> > + This command outputs either list of image partitions or directory
>
> > contents
>
> > + of vfat and ext* partitions.
>
> > +
>
> > + See 'wic help ls' for more detailed instructions.
>
> > +
>
> > +"""
>
> > +
>
> > +wic_ls_help = """
>
> > +
>
> > +NAME
>
> > + wic ls - List contents of partitioned image or partition
>
> > +
>
> > +SYNOPSIS
>
> > + wic ls <image>
>
> > + wic ls <image>:<vfat or ext* partition>
>
> > + wic ls <image>:<vfat or ext* partition><path>
>
> > + wic ls <image>:<vfat or ext* partition><path> --native-sysroot
>
> > <path> +
>
> > +DESCRIPTION
>
> > + This command lists either partitions of the image or directory
>
> > contents
>
> > + of vfat or ext* partitions.
>
> > +
>
> > + The first form it lists partitions of the image.
>
> > + For example:
>
> > + $ wic ls
>
> > tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic
>
> > + Num Start End Size Fstype
>
> > + 1 1048576 24438783 23390208 fat16
>
> > + 2 25165824 50315263 25149440 ext4
>
> > +
>
> > + Second and third form list directory content of the partition:
>
> > + $ wic ls
>
> > tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
>
> > + Volume in drive : is boot
>
> > + Volume Serial Number is 2DF2-5F02
>
> > + Directory for ::/
>
> > +
>
> > + efi <DIR> 2017-05-11 10:54
>
> > + startup nsh 26 2017-05-11 10:54
>
> > + vmlinuz 6922288 2017-05-11 10:54
>
> > + 3 files 6 922 314 bytes
>
> > + 15 818 752 bytes free
>
> > +
>
> > +
>
> > + $ wic ls
>
> >
> tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/EFI/boot/
>
> > + Volume in drive : is boot
>
> > + Volume Serial Number is 2DF2-5F02
>
> > + Directory for ::/EFI/boot
>
> > +
>
> > + . <DIR> 2017-05-11 10:54
>
> > + .. <DIR> 2017-05-11 10:54
>
> > + grub cfg 679 2017-05-11 10:54
>
> > + bootx64 efi 571392 2017-05-11 10:54
>
> > + 4 files 572 071 bytes
>
> > + 15 818 752 bytes free
>
> > +
>
> > + The -n option is used to specify the path to the native sysroot
>
> > + containing the tools(parted and mtools) to use.
>
> > +
>
> > +"""
>
> > +
>
> > +wic_cp_usage = """
>
> > +
>
> > + Copy files and directories to/from the vfat or ext* partition
>
> > +
>
> > + usage: wic cp <src> <dest> [--native-sysroot <path>]
>
> > +
>
> > + source/destination image in format <image>:<partition>[<path>]
>
> > +
>
> > + This command copies files or directories either
>
> > + - from local to vfat or ext* partitions of partitioned image
>
> > + - from vfat or ext* partitions of partitioned image to local
>
> > +
>
> > + See 'wic help cp' for more detailed instructions.
>
> > +
>
> > +"""
>
> > +
>
> > +wic_cp_help = """
>
> > +
>
> > +NAME
>
> > + wic cp - copy files and directories to/from the vfat or ext*
>
> > partitions +
>
> > +SYNOPSIS
>
> > + wic cp <src> <dest>:<partition>
>
> > + wic cp <src>:<partition> <dest>
>
> > + wic cp <src> <dest-image>:<partition><path>
>
> > + wic cp <src> <dest-image>:<partition><path> --native-sysroot
>
> > <path> +
>
> > +DESCRIPTION
>
> > + This command copies files or directories either
>
> > + - from local to vfat or ext* partitions of partitioned image
>
> > + - from vfat or ext* partitions of partitioned image to local
>
> > +
>
> > + The first form of it copies file or directory to the root
>
> > directory of
>
> > + the partition:
>
> > + $ wic cp test.wks
>
> > tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
>
> > + $ wic ls
>
> > tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
>
> > + Volume in drive : is boot
>
> > + Volume Serial Number is DB4C-FD4C
>
> > + Directory for ::/
>
> > +
>
> > + efi <DIR> 2017-05-24 18:15
>
> > + loader <DIR> 2017-05-24 18:15
>
> > + startup nsh 26 2017-05-24 18:15
>
> > + vmlinuz 6926384 2017-05-24 18:15
>
> > + test wks 628 2017-05-24 21:22
>
> > + 5 files 6 927 038 bytes
>
> > + 15 677 440 bytes free
>
> > +
>
> > + The second form of the command copies file or directory to the
>
> > specified directory
>
> > + on the partition:
>
> > + $ wic cp test
>
> > tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/efi/
>
> > + $ wic ls
>
> > tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/efi/
>
> > + Volume in drive : is boot
>
> > + Volume Serial Number is DB4C-FD4C
>
> > + Directory for ::/efi
>
> > +
>
> > + . <DIR> 2017-05-24 18:15
>
> > + .. <DIR> 2017-05-24 18:15
>
> > + boot <DIR> 2017-05-24 18:15
>
> > + test <DIR> 2017-05-24 21:27
>
> > + 4 files 0 bytes
>
> > + 15 675 392 bytes free
>
> > +
>
> > + The third form of the command copies file or directory from the
>
> > specified directory
>
> > + on the partition to local:
>
> > + $ wic cp
>
> > tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/vmlinuz
>
> > test +
>
> > + The -n option is used to specify the path to the native sysroot
>
> > + containing the tools(parted and mtools) to use.
>
> > +"""
>
> > +
>
> > +wic_rm_usage = """
>
> > +
>
> > + Remove files or directories from the vfat or ext* partitions
>
> > +
>
> > + usage: wic rm <image>:<partition><path> [--native-sysroot <path>]
>
> > +
>
> > + This command removes files or directories from the vfat or ext*
>
> > partitions of
>
> > + the partitioned image.
>
> > +
>
> > + See 'wic help rm' for more detailed instructions.
>
> > +
>
> > +"""
>
> > +
>
> > +wic_rm_help = """
>
> > +
>
> > +NAME
>
> > + wic rm - remove files or directories from the vfat or ext*
>
> > partitions +
>
> > +SYNOPSIS
>
> > + wic rm <src> <image>:<partition><path>
>
> > + wic rm <src> <image>:<partition><path> --native-sysroot <path>
>
> > + wic rm -r <image>:<partition><path>
>
> > +
>
> > +DESCRIPTION
>
> > + This command removes files or directories from the vfat or ext*
>
> > partition of the
>
> > + partitioned image:
>
> > +
>
> > + $ wic ls
>
> > ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
>
> > + Volume in drive : is boot
>
> > + Volume Serial Number is 11D0-DE21
>
> > + Directory for ::/
>
> > +
>
> > + libcom32 c32 186500 2017-06-02 15:15
>
> > + libutil c32 24148 2017-06-02 15:15
>
> > + syslinux cfg 209 2017-06-02 15:15
>
> > + vesamenu c32 27104 2017-06-02 15:15
>
> > + vmlinuz 6926384 2017-06-02 15:15
>
> > + 5 files 7 164 345 bytes
>
> > + 16 582 656 bytes free
>
> > +
>
> > + $ wic rm
>
> >
> ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1/libutil.c32
>
> > +
>
> > + $ wic ls
>
> > ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic:1
>
> > + Volume in drive : is boot
>
> > + Volume Serial Number is 11D0-DE21
>
> > + Directory for ::/
>
> > +
>
> > + libcom32 c32 186500 2017-06-02 15:15
>
> > + syslinux cfg 209 2017-06-02 15:15
>
> > + vesamenu c32 27104 2017-06-02 15:15
>
> > + vmlinuz 6926384 2017-06-02 15:15
>
> > + 4 files 7 140 197 bytes
>
> > + 16 607 232 bytes free
>
> > +
>
> > + The -n option is used to specify the path to the native sysroot
>
> > + containing the tools(parted and mtools) to use.
>
> > +
>
> > + The -r option is used to remove directories and their contents
>
> > + recursively,this only applies to ext* partition.
>
> > +"""
>
> > +
>
> > +wic_write_usage = """
>
> > +
>
> > + Write image to a device
>
> > +
>
> > + usage: wic write <image> <target device> [--expand [rules]]
>
> > [--native-sysroot <path>] +
>
> > + This command writes partitioned image to a target device (USB
>
> > stick, SD card etc). +
>
> > + See 'wic help write' for more detailed instructions.
>
> > +
>
> > +"""
>
> > +
>
> > +wic_write_help = """
>
> > +
>
> > +NAME
>
> > + wic write - write an image to a device
>
> > +
>
> > +SYNOPSIS
>
> > + wic write <image> <target>
>
> > + wic write <image> <target> --expand auto
>
> > + wic write <image> <target> --expand 1:100M,2:300M
>
> > + wic write <image> <target> --native-sysroot <path>
>
> > +
>
> > +DESCRIPTION
>
> > + This command writes an image to a target device (USB stick, SD
>
> > card etc) +
>
> > + $ wic write
>
> > ./tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.wic
>
> > /dev/sdb +
>
> > + The --expand option is used to resize image partitions.
>
> > + --expand auto expands partitions to occupy all free space
>
> > available on the target device.
>
> > + It's also possible to specify expansion rules in a format
>
> > + <partition>:<size>[,<partition>:<size>...] for one or more
>
> > partitions.
>
> > + Specifying size 0 will keep partition unmodified.
>
> > + Note: Resizing boot partition can result in non-bootable image
>
> > for non-EFI images. It is
>
> > + recommended to use size 0 for boot partition to keep image
>
> > bootable. +
>
> > + The --native-sysroot option is used to specify the path to the
>
> > native sysroot
>
> > + containing the tools(parted, resize2fs) to use.
>
> > +"""
>
> > +
>
> > wic_plugins_help = """
>
> >
>
> > NAME
>
> > @@ -308,7 +536,8 @@ DESCRIPTION
>
> >
>
> > Source plugins can also be implemented and added by external
>
> > layers - any plugins found in a scripts/lib/wic/plugins/source/
>
> > - directory in an external layer will also be made available.
>
> > + or lib/wic/plugins/source/ directory in an external layer will
>
> > + also be made available.
>
> >
>
> > When the wic implementation needs to invoke a partition-specific
>
> > implementation, it looks for the plugin that has the same name as
>
> > @@ -346,6 +575,10 @@ DESCRIPTION
>
> > partition. In other words, it 'prepares' the final
>
> > partition image which will be incorporated into the disk image.
>
> >
>
> > + do_post_partition()
>
> > + Called after the partition is created. It is useful to add
>
> > post
>
> > + operations e.g. signing the partition.
>
> > +
>
> > do_configure_partition()
>
> > Called before do_prepare_partition(), typically used to
>
> > create custom configuration files for a partition, for
>
> > @@ -632,8 +865,11 @@ DESCRIPTION
>
> > Partitions with a <mountpoint> specified will be
>
> > automatically mounted. This is achieved by wic adding entries to the
>
> > fstab during image generation. In order for a valid fstab to be
>
> > generated one of the
>
> > - --ondrive, --ondisk or --use-uuid partition options must be
>
> > used for
>
> > - each partition that specifies a mountpoint.
>
> > + --ondrive, --ondisk, --use-uuid or --use-label partition
>
> > options must
>
> > + be used for each partition that specifies a mountpoint. Note
>
> > that with
>
> > + --use-{uuid,label} and non-root <mountpoint>, including swap,
>
> > the mount
>
> > + program must understand the PARTUUID or LABEL syntax. This
>
> > currently
>
> > + excludes the busybox versions of these applications.
>
> >
>
> >
>
> > The following are supported 'part' options:
>
> > @@ -687,6 +923,8 @@ DESCRIPTION
>
> > apply to partitions created using '--source rootfs' (see
>
> > --source above). Valid values are:
>
> >
>
> > + vfat
>
> > + msdos
>
> > ext2
>
> > ext3
>
> > ext4
>
> > @@ -706,6 +944,14 @@ DESCRIPTION
>
> > label is already in use by another
>
> > filesystem, a new label is created for the partition.
>
> >
>
> > + --use-label: This option is specific to wic. It makes wic
>
> > to use the
>
> > + label in /etc/fstab to specify a partition. If
>
> > the
>
> > + --use-label and --use-uuid are used at the
>
> > same time,
>
> > + we prefer the uuid because it is less likely
>
> > to cause
>
> > + name confliction. We don't support using this
>
> > parameter
>
> > + on the root partition since it requires an
>
> > initramfs to
>
> > + parse this value and we do not currently
>
> > support that. +
>
> > --active: Marks the partition as active.
>
> >
>
> > --align (in KBytes): This option is specific to wic and says
>
> > @@ -719,11 +965,31 @@ DESCRIPTION
>
> > bootloaders.
>
> >
>
> > --exclude-path: This option is specific to wic. It excludes
>
> > the given
>
> > - absolute path from the resulting image. If
>
> > the path
>
> > + relative path from the resulting image. If
>
> > the path ends with a slash, only the content of the directory
>
> > is omitted, not the directory itself. This
>
> > option only has an effect with the rootfs source plugin.
>
> >
>
> > + --include-path: This option is specific to wic. It adds the
>
> > contents
>
> > + of the given path or a rootfs to the
>
> > resulting image.
>
> > + The option contains two fields, the origin
>
> > and the
>
> > + destination. When the origin is a rootfs,
>
> > it follows
>
> > + the same logic as the rootfs-dir argument
>
> > and the
>
> > + permissions and owners are kept. When the
>
> > origin is a
>
> > + path, it is relative to the directory in
>
> > which wic is
>
> > + running not the rootfs itself so use of an
>
> > absolute
>
> > + path is recommended, and the owner and
>
> > group is set to
>
> > + root:root. If no destination is given it is
>
> > + automatically set to the root of the
>
> > rootfs. This
>
> > + option only has an effect with the rootfs
>
> > source
>
> > + plugin.
>
> > +
>
> > + --change-directory: This option is specific to wic. It
>
> > changes to the
>
> > + given directory before copying the
>
> > files. This
>
> > + option is useful when we want to split
>
> > a rootfs in
>
> > + multiple partitions and we want to keep
>
> > the right
>
> > + permissions and usernames in all the
>
> > partitions. +
>
> > --extra-space: This option is specific to wic. It adds extra
>
> > space after the space filled by the content
>
> > of the partition. The final size can go
>
> > @@ -738,6 +1004,8 @@ DESCRIPTION
>
> > This option cannot be used with
>
> > --fixed-size option.
>
> >
>
> > + --part-name: This option is specific to wic. It specifies
>
> > name for GPT partitions. +
>
> > --part-type: This option is specific to wic. It specifies
>
> > partition type GUID for GPT partitions.
>
> > List of partition type GUIDS can be found here:
>
> > @@ -752,10 +1020,21 @@ DESCRIPTION
>
> > in bootloader configuration before running wic. In
>
> > this case .wks file can be generated or modified to set preconfigured
>
> > parition UUID using this option.
>
> > + --fsuuid: This option is specific to wic. It specifies
>
> > filesystem UUID.
>
> > + It's useful if preconfigured filesystem UUID is
>
> > added to kernel command line
>
> > + in bootloader configuration before running wic.
>
> > In this case .wks file can
>
> > + be generated or modified to set preconfigured
>
> > filesystem UUID using this option. +
>
> > --system-id: This option is specific to wic. It specifies
>
> > partition system id. It's useful for the harware that requires
>
> > non-default partition system ids. The parameter in one byte long hex
>
> > number either with 0x prefix or without it.
>
> > + --mkfs-extraopts: This option specifies extra options to
>
> > pass to mkfs utility.
>
> > + NOTE, that wic uses default options for
>
> > some filesystems, for example
>
> > + '-S 512' for mkfs.fat or '-F -i 8192' for
>
> > mkfs.ext. Those options will
>
> > + not take effect when --mkfs-extraopts is
>
> > used. This should be taken into
>
> > + account when using --mkfs-extraopts.
>
> > +
>
> > * bootloader
>
> >
>
> > This command allows the user to specify various bootloader
>
> > @@ -793,3 +1072,67 @@ DESCRIPTION
>
> > .wks files.
>
> >
>
> > """
>
> > +
>
> > +wic_help_help = """
>
> > +NAME
>
> > + wic help - display a help topic
>
> > +
>
> > +DESCRIPTION
>
> > + Specify a help topic to display it. Topics are shown above.
>
> > +"""
>
> > +
>
> > +
>
> > +wic_help = """
>
> > +Creates a customized OpenEmbedded image.
>
> > +
>
> > +Usage: wic [--version]
>
> > + wic help [COMMAND or TOPIC]
>
> > + wic COMMAND [ARGS]
>
> > +
>
> > + usage 1: Returns the current version of Wic
>
> > + usage 2: Returns detailed help for a COMMAND or TOPIC
>
> > + usage 3: Executes COMMAND
>
> > +
>
> > +
>
> > +COMMAND:
>
> > +
>
> > + list - List available canned images and source plugins
>
> > + ls - List contents of partitioned image or partition
>
> > + rm - Remove files or directories from the vfat or ext*
>
> > partitions
>
> > + help - Show help for a wic COMMAND or TOPIC
>
> > + write - Write an image to a device
>
> > + cp - Copy files and directories to the vfat or ext*
>
> > partitions
>
> > + create - Create a new OpenEmbedded image
>
> > +
>
> > +
>
> > +TOPIC:
>
> > + overview - Presents an overall overview of Wic
>
> > + plugins - Presents an overview and API for Wic plugins
>
> > + kickstart - Presents a Wic kicstart file reference
>
> > +
>
> > +
>
> > +Examples:
>
> > +
>
> > + $ wic --version
>
> > +
>
> > + Returns the current version of Wic
>
> > +
>
> > +
>
> > + $ wic help cp
>
> > +
>
> > + Returns the SYNOPSIS and DESCRIPTION for the Wic "cp" command.
>
> > +
>
> > +
>
> > + $ wic list images
>
> > +
>
> > + Returns the list of canned images (i.e. *.wks files located in
>
> > + the /scripts/lib/wic/canned-wks directory.
>
> > +
>
> > +
>
> > + $ wic create mkefidisk -e core-image-minimal
>
> > +
>
> > + Creates an EFI disk image from artifacts used in a previous
>
> > + core-image-minimal build in standard BitBake locations
>
> > + (e.g. Cooked Mode).
>
> > +
>
> > +"""
>
> > diff --git a/scripts/lib/wic/ksparser.py b/scripts/lib/wic/ksparser.py
>
> > index a039300..3453d9c 100644
>
> > --- a/scripts/lib/wic/ksparser.py
>
> > +++ b/scripts/lib/wic/ksparser.py
>
> > @@ -1,21 +1,8 @@
>
> > -#!/usr/bin/env python -tt
>
> > -# ex:ts=4:sw=4:sts=4:et
>
> > -# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
>
> > +#!/usr/bin/env python3
>
> > #
>
> > # Copyright (c) 2016 Intel, Inc.
>
> > #
>
> > -# This program is free software; you can redistribute it and/or
>
> > modify it -# under the terms of the GNU General Public License as
>
> > published by the Free -# Software Foundation; version 2 of the License
>
> > -#
>
> > -# This program is distributed in the hope that it will be useful, but
>
> > -# WITHOUT ANY WARRANTY; without even the implied warranty of
>
> > MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>
> > General Public License -# for more details.
>
> > -#
>
> > -# You should have received a copy of the GNU General Public License
>
> > along -# with this program; if not, write to the Free Software
>
> > Foundation, Inc., 59 -# Temple Place - Suite 330, Boston, MA
>
> > 02111-1307, USA. +# SPDX-License-Identifier: GPL-2.0-only
>
> > #
>
> > # DESCRIPTION
>
> > # This module provides parser for kickstart format
>
> > @@ -28,14 +15,30 @@
>
> > import os
>
> > import shlex
>
> > import logging
>
> > +import re
>
> >
>
> > from argparse import ArgumentParser, ArgumentError, ArgumentTypeError
>
> >
>
> > from wic.engine import find_canned
>
> > from wic.partition import Partition
>
> > +from wic.misc import get_bitbake_var
>
> >
>
> > logger = logging.getLogger('wic')
>
> >
>
> > +__expand_var_regexp__ = re.compile(r"\${[^{}@\n\t :]+}")
>
> > +
>
> > +def expand_line(line):
>
> > + while True:
>
> > + m = __expand_var_regexp__.search(line)
>
> > + if not m:
>
> > + return line
>
> > + key = m.group()[2:-1]
>
> > + val = get_bitbake_var(key)
>
> > + if val is None:
>
> > + logger.warning("cannot expand variable %s" % key)
>
> > + return line
>
> > + line = line[:m.start()] + val + line[m.end():]
>
> > +
>
> > class KickStartError(Exception):
>
> > """Custom exception."""
>
> > pass
>
> > @@ -48,26 +51,31 @@ class KickStartParser(ArgumentParser):
>
> > def error(self, message):
>
> > raise ArgumentError(None, message)
>
> >
>
> > -def sizetype(arg):
>
> > - """
>
> > - Custom type for ArgumentParser
>
> > - Converts size string in <num>[K|k|M|G] format into the integer
>
> > value
>
> > - """
>
> > - if arg.isdigit():
>
> > - return int(arg) * 1024
>
> > -
>
> > - if not arg[:-1].isdigit():
>
> > - raise ArgumentTypeError("Invalid size: %r" % arg)
>
> > +def sizetype(default):
>
> > + def f(arg):
>
> > + """
>
> > + Custom type for ArgumentParser
>
> > + Converts size string in <num>[K|k|M|G] format into the
>
> > integer value
>
> > + """
>
> > + try:
>
> > + suffix = default
>
> > + size = int(arg)
>
> > + except ValueError:
>
> > + try:
>
> > + suffix = arg[-1:]
>
> > + size = int(arg[:-1])
>
> > + except ValueError:
>
> > + raise ArgumentTypeError("Invalid size: %r" % arg)
>
> >
>
> > - size = int(arg[:-1])
>
> > - if arg.endswith("k") or arg.endswith("K"):
>
> > - return size
>
> > - if arg.endswith("M"):
>
> > - return size * 1024
>
> > - if arg.endswith("G"):
>
> > - return size * 1024 * 1024
>
> > + if suffix == "k" or suffix == "K":
>
> > + return size
>
> > + if suffix == "M":
>
> > + return size * 1024
>
> > + if suffix == "G":
>
> > + return size * 1024 * 1024
>
> >
>
> > - raise ArgumentTypeError("Invalid size: %r" % arg)
>
> > + raise ArgumentTypeError("Invalid size: %r" % arg)
>
> > + return f
>
> >
>
> > def overheadtype(arg):
>
> > """
>
> > @@ -114,7 +122,7 @@ def systemidtype(arg):
>
> > return arg
>
> >
>
> > class KickStart():
>
> > - """"Kickstart parser implementation."""
>
> > + """Kickstart parser implementation."""
>
> >
>
> > DEFAULT_EXTRA_SPACE = 10*1024
>
> > DEFAULT_OVERHEAD_FACTOR
> <https://www.google.com/maps/search/LT_OVERHEAD_FACTOR?entry=gmail&source=g>
> = 1.3
>
> > @@ -133,30 +141,41 @@ class KickStart():
>
> > part.add_argument('mountpoint', nargs='?')
>
> > part.add_argument('--active', action='store_true')
>
> > part.add_argument('--align', type=int)
>
> > + part.add_argument('--offset', type=sizetype("K"))
>
> > part.add_argument('--exclude-path', nargs='+')
>
> > - part.add_argument("--extra-space", type=sizetype)
>
> > + part.add_argument('--include-path', nargs='+',
>
> > action='append')
>
> > + part.add_argument('--change-directory')
>
> > + part.add_argument("--extra-space", type=sizetype("M"))
>
> > part.add_argument('--fsoptions', dest='fsopts')
>
> > - part.add_argument('--fstype')
>
> > + part.add_argument('--fstype', default='vfat',
>
> > + choices=('ext2', 'ext3', 'ext4', 'btrfs',
>
> > + 'squashfs', 'vfat', 'msdos',
>
> > 'swap'))
>
> > + part.add_argument('--mkfs-extraopts', default='')
>
> > part.add_argument('--label')
>
> > + part.add_argument('--use-label', action='store_true')
>
> > part.add_argument('--no-table', action='store_true')
>
> > part.add_argument('--ondisk', '--ondrive', dest='disk',
>
> > default='sda') part.add_argument("--overhead-factor",
>
> > type=overheadtype)
>
> > + part.add_argument('--part-name')
>
> > part.add_argument('--part-type')
>
> > part.add_argument('--rootfs-dir')
>
> > + part.add_argument('--type', default='primary',
>
> > + choices = ('primary', 'logical'))
>
> >
>
> > # --size and --fixed-size cannot be specified together;
>
> > options # ----extra-space and --overhead-factor should also raise a
>
> > parser # --error, but since nesting mutually exclusive groups does
>
> > not work, # ----extra-space/--overhead-factor are handled later
>
> > sizeexcl = part.add_mutually_exclusive_group()
>
> > - sizeexcl.add_argument('--size', type=sizetype, default=0)
>
> > - sizeexcl.add_argument('--fixed-size', type=sizetype,
>
> > default=0)
>
> > + sizeexcl.add_argument('--size', type=sizetype("M"),
>
> > default=0)
>
> > + sizeexcl.add_argument('--fixed-size', type=sizetype("M"),
>
> > default=0)
>
> > part.add_argument('--source')
>
> > part.add_argument('--sourceparams')
>
> > part.add_argument('--system-id', type=systemidtype)
>
> > part.add_argument('--use-uuid', action='store_true')
>
> > part.add_argument('--uuid')
>
> > + part.add_argument('--fsuuid')
>
> >
>
> > bootloader = subparsers.add_parser('bootloader')
>
> > bootloader.add_argument('--append')
>
> > @@ -184,6 +203,7 @@ class KickStart():
>
> > line = line.strip()
>
> > lineno += 1
>
> > if line and line[0] != '#':
>
> > + line = expand_line(line)
>
> > try:
>
> > line_args = shlex.split(line)
>
> > parsed = parser.parse_args(line_args)
>
> > @@ -191,6 +211,20 @@ class KickStart():
>
> > raise KickStartError('%s:%d: %s' % \
>
> > (confpath, lineno, err))
>
> > if line.startswith('part'):
>
> > + # SquashFS does not support filesystem UUID
>
> > + if parsed.fstype == 'squashfs':
>
> > + if parsed.fsuuid:
>
> > + err = "%s:%d: SquashFS does not
>
> > support UUID" \
>
> > + % (confpath, lineno)
>
> > + raise KickStartError(err)
>
> > + if parsed.label:
>
> > + err = "%s:%d: SquashFS does not
>
> > support LABEL" \
>
> > + % (confpath, lineno)
>
> > + raise KickStartError(err)
>
> > + if parsed.use_label and not parsed.label:
>
> > + err = "%s:%d: Must set the label with
>
> > --label" \
>
> > + % (confpath, lineno)
>
> > + raise KickStartError(err)
>
> > # using ArgumentParser one cannot easily
>
> > tell if option # was passed as argument, if said option has a default
>
> > # value; --overhead-factor/--extra-space
>
> > cannot be used @@ -219,6 +253,11 @@ class KickStart():
>
> > elif line.startswith('bootloader'):
>
> > if not self.bootloader:
>
> > self.bootloader = parsed
>
> > + # Concatenate the strings set in APPEND
>
> > + append_var = get_bitbake_var("APPEND")
>
> > + if append_var:
>
> > + self.bootloader.append = '
>
> > '.join(filter(None, \
>
> > +
>
> > (self.bootloader.append, append_var))) else:
>
> > err = "%s:%d: more than one bootloader
>
> > specified" \ % (confpath, lineno)
>
> > diff --git a/scripts/lib/wic/utils/misc.py b/scripts/lib/wic/misc.py
>
> > similarity index 70%
>
> > rename from scripts/lib/wic/utils/misc.py
>
> > rename to scripts/lib/wic/misc.py
>
> > index c941112..91975ba 100644
>
> > --- a/scripts/lib/wic/utils/misc.py
>
> > +++ b/scripts/lib/wic/misc.py
>
> > @@ -1,21 +1,7 @@
>
> > -# ex:ts=4:sw=4:sts=4:et
>
> > -# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
>
> > #
>
> > # Copyright (c) 2013, Intel Corporation.
>
> > -# All rights reserved.
>
> > #
>
> > -# This program is free software; you can redistribute it and/or
>
> > modify -# it under the terms of the GNU General Public License
>
> > version 2 as -# published by the Free Software Foundation.
>
> > -#
>
> > -# This program is distributed in the hope that it will be useful,
>
> > -# but WITHOUT ANY WARRANTY; without even the implied warranty of
>
> > -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
>
> > -# GNU General Public License for more details.
>
> > -#
>
> > -# You should have received a copy of the GNU General Public License
>
> > along -# with this program; if not, write to the Free Software
>
> > Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA
>
> > 02110-1301 USA. +# SPDX-License-Identifier: GPL-2.0-only
>
> > #
>
> > # DESCRIPTION
>
> > # This module provides a place to collect various wic-related utils
>
> > @@ -29,12 +15,12 @@
>
> > import logging
>
> > import os
>
> > import re
>
> > +import subprocess
>
> >
>
> > from collections import defaultdict
>
> > from distutils import spawn
>
> >
>
> > from wic import WicError
>
> > -from wic.utils import runner
>
> >
>
> > logger = logging.getLogger('wic')
>
> >
>
> > @@ -43,6 +29,9 @@ NATIVE_RECIPES = {"bmaptool": "bmap-tools",
>
> > "grub-mkimage": "grub-efi",
>
> > "isohybrid": "syslinux",
>
> > "mcopy"
> <https://www.google.com/maps/search/%22mcopy%22?entry=gmail&source=g>:
> "mtools",
>
> > + "mdel" : "mtools",
>
> > + "mdeltree" :
[-- Attachment #2: Type: text/html, Size: 111657 bytes --]
next prev parent reply other threads:[~2020-09-05 9:21 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-02 18:56 [PATCH v2 00/10] WIC update Vijai Kumar K
2020-09-02 18:56 ` [PATCH v2 01/10] wic: Update to the latest wic from openembedded core Vijai Kumar K
2020-09-05 9:00 ` Henning Schild
2020-09-05 9:21 ` vijai kumar [this message]
2020-09-02 18:56 ` [PATCH v2 02/10] wic/plugins: Fix wic plugins to work with the latest wic Vijai Kumar K
2020-09-02 18:56 ` [PATCH v2 03/10] wic-img: Satisfy the quirks of " Vijai Kumar K
2020-09-05 8:30 ` Henning Schild
2020-09-05 16:24 ` vijaikumar....@gmail.com
2020-09-09 14:52 ` Henning Schild
2020-09-02 18:56 ` [PATCH v2 04/10] oe.path: Add copyhardlink() helper function Vijai Kumar K
2020-09-02 18:56 ` [PATCH v2 05/10] lib/oe/path: try hardlinking instead of guessing when it might fail Vijai Kumar K
2020-09-02 18:56 ` [PATCH v2 06/10] wic_fakeroot: Handle standalone pseudo invocations Vijai Kumar K
2020-09-05 8:38 ` Henning Schild
2020-09-05 15:19 ` vijaikumar....@gmail.com
2020-09-05 9:19 ` Henning Schild
2020-09-05 15:22 ` vijaikumar....@gmail.com
2020-09-02 18:56 ` [PATCH v2 07/10] meta-isar/conf: Add provision to debug WIC Vijai Kumar K
2020-09-02 18:56 ` [PATCH v2 08/10] debian-common: Add tar as a dependency for wic Vijai Kumar K
2020-09-02 19:02 ` [PATCH v2 09/10] wic: misc: Add /bin to the list of searchpaths Vijai Kumar K
2020-09-02 19:02 ` [PATCH v2 10/10] meta-isar/canned-wks: Remove /boot mountpoint Vijai Kumar K
2020-09-05 8:58 ` Henning Schild
2020-09-05 16:06 ` vijaikumar....@gmail.com
2020-09-09 15:09 ` Henning Schild
2020-09-14 5:32 ` vijaikumar....@gmail.com
2020-09-05 8:45 ` [PATCH v2 09/10] wic: misc: Add /bin to the list of searchpaths Henning Schild
2020-09-05 9:33 ` vijai kumar
2020-09-03 5:46 ` [PATCH v2 00/10] WIC update vijaikumar....@gmail.com
2020-09-05 9:04 ` Henning Schild
2020-09-05 9:25 ` vijai kumar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CALLGG_+GdDJaJmaE=jkm_oLJoorDJtObj6-W5OgjfC4VUrTZSw@mail.gmail.com' \
--to=vijaikumar.kanagarajan@gmail.com \
--cc=Vijaikumar_Kanagarajan@mentor.com \
--cc=henning.schild@siemens.com \
--cc=isar-users@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox