diff options
Diffstat (limited to 'scripts/lib/wic/plugins/source/bootimg-partition.py')
| -rw-r--r-- | scripts/lib/wic/plugins/source/bootimg-partition.py | 197 |
1 files changed, 0 insertions, 197 deletions
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py deleted file mode 100644 index 1071d1af3f..0000000000 --- a/scripts/lib/wic/plugins/source/bootimg-partition.py +++ /dev/null | |||
| @@ -1,197 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: GPL-2.0-only | ||
| 5 | # | ||
| 6 | # DESCRIPTION | ||
| 7 | # This implements the 'bootimg-partition' source plugin class for | ||
| 8 | # 'wic'. The plugin creates an image of boot partition, copying over | ||
| 9 | # files listed in IMAGE_BOOT_FILES bitbake variable. | ||
| 10 | # | ||
| 11 | # AUTHORS | ||
| 12 | # Maciej Borzecki <maciej.borzecki (at] open-rnd.pl> | ||
| 13 | # | ||
| 14 | |||
| 15 | import logging | ||
| 16 | import os | ||
| 17 | import re | ||
| 18 | |||
| 19 | from glob import glob | ||
| 20 | |||
| 21 | from wic import WicError | ||
| 22 | from wic.engine import get_custom_config | ||
| 23 | from wic.pluginbase import SourcePlugin | ||
| 24 | from wic.misc import exec_cmd, get_bitbake_var | ||
| 25 | |||
| 26 | logger = logging.getLogger('wic') | ||
| 27 | |||
| 28 | class BootimgPartitionPlugin(SourcePlugin): | ||
| 29 | """ | ||
| 30 | Create an image of boot partition, copying over files | ||
| 31 | listed in IMAGE_BOOT_FILES bitbake variable. | ||
| 32 | """ | ||
| 33 | |||
| 34 | name = 'bootimg-partition' | ||
| 35 | image_boot_files_var_name = 'IMAGE_BOOT_FILES' | ||
| 36 | |||
| 37 | @classmethod | ||
| 38 | def do_configure_partition(cls, part, source_params, cr, cr_workdir, | ||
| 39 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 40 | native_sysroot): | ||
| 41 | """ | ||
| 42 | Called before do_prepare_partition(), create u-boot specific boot config | ||
| 43 | """ | ||
| 44 | hdddir = "%s/boot.%d" % (cr_workdir, part.lineno) | ||
| 45 | install_cmd = "install -d %s" % hdddir | ||
| 46 | exec_cmd(install_cmd) | ||
| 47 | |||
| 48 | if not kernel_dir: | ||
| 49 | kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 50 | if not kernel_dir: | ||
| 51 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") | ||
| 52 | |||
| 53 | boot_files = None | ||
| 54 | for (fmt, id) in (("_uuid-%s", part.uuid), ("_label-%s", part.label), (None, None)): | ||
| 55 | if fmt: | ||
| 56 | var = fmt % id | ||
| 57 | else: | ||
| 58 | var = "" | ||
| 59 | |||
| 60 | boot_files = get_bitbake_var(cls.image_boot_files_var_name + var) | ||
| 61 | if boot_files is not None: | ||
| 62 | break | ||
| 63 | |||
| 64 | if boot_files is None: | ||
| 65 | raise WicError('No boot files defined, %s unset for entry #%d' % (cls.image_boot_files_var_name, part.lineno)) | ||
| 66 | |||
| 67 | logger.debug('Boot files: %s', boot_files) | ||
| 68 | |||
| 69 | # list of tuples (src_name, dst_name) | ||
| 70 | deploy_files = [] | ||
| 71 | for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files): | ||
| 72 | if ';' in src_entry: | ||
| 73 | dst_entry = tuple(src_entry.split(';')) | ||
| 74 | if not dst_entry[0] or not dst_entry[1]: | ||
| 75 | raise WicError('Malformed boot file entry: %s' % src_entry) | ||
| 76 | else: | ||
| 77 | dst_entry = (src_entry, src_entry) | ||
| 78 | |||
| 79 | logger.debug('Destination entry: %r', dst_entry) | ||
| 80 | deploy_files.append(dst_entry) | ||
| 81 | |||
| 82 | cls.install_task = []; | ||
| 83 | for deploy_entry in deploy_files: | ||
| 84 | src, dst = deploy_entry | ||
| 85 | if '*' in src: | ||
| 86 | # by default install files under their basename | ||
| 87 | entry_name_fn = os.path.basename | ||
| 88 | if dst != src: | ||
| 89 | # unless a target name was given, then treat name | ||
| 90 | # as a directory and append a basename | ||
| 91 | entry_name_fn = lambda name: \ | ||
| 92 | os.path.join(dst, | ||
| 93 | os.path.basename(name)) | ||
| 94 | |||
| 95 | srcs = glob(os.path.join(kernel_dir, src)) | ||
| 96 | |||
| 97 | logger.debug('Globbed sources: %s', ', '.join(srcs)) | ||
| 98 | for entry in srcs: | ||
| 99 | src = os.path.relpath(entry, kernel_dir) | ||
| 100 | entry_dst_name = entry_name_fn(entry) | ||
| 101 | cls.install_task.append((src, entry_dst_name)) | ||
| 102 | else: | ||
| 103 | cls.install_task.append((src, dst)) | ||
| 104 | |||
| 105 | if source_params.get('loader') != "u-boot": | ||
| 106 | return | ||
| 107 | |||
| 108 | configfile = cr.ks.bootloader.configfile | ||
| 109 | custom_cfg = None | ||
| 110 | if configfile: | ||
| 111 | custom_cfg = get_custom_config(configfile) | ||
| 112 | if custom_cfg: | ||
| 113 | # Use a custom configuration for extlinux.conf | ||
| 114 | extlinux_conf = custom_cfg | ||
| 115 | logger.debug("Using custom configuration file " | ||
| 116 | "%s for extlinux.conf", configfile) | ||
| 117 | else: | ||
| 118 | raise WicError("configfile is specified but failed to " | ||
| 119 | "get it from %s." % configfile) | ||
| 120 | |||
| 121 | if not custom_cfg: | ||
| 122 | # The kernel types supported by the sysboot of u-boot | ||
| 123 | kernel_types = ["zImage", "Image", "fitImage", "uImage", "vmlinux"] | ||
| 124 | has_dtb = False | ||
| 125 | fdt_dir = '/' | ||
| 126 | kernel_name = None | ||
| 127 | |||
| 128 | # Find the kernel image name, from the highest precedence to lowest | ||
| 129 | for image in kernel_types: | ||
| 130 | for task in cls.install_task: | ||
| 131 | src, dst = task | ||
| 132 | if re.match(image, src): | ||
| 133 | kernel_name = os.path.join('/', dst) | ||
| 134 | break | ||
| 135 | if kernel_name: | ||
| 136 | break | ||
| 137 | |||
| 138 | for task in cls.install_task: | ||
| 139 | src, dst = task | ||
| 140 | # We suppose that all the dtb are in the same directory | ||
| 141 | if re.search(r'\.dtb', src) and fdt_dir == '/': | ||
| 142 | has_dtb = True | ||
| 143 | fdt_dir = os.path.join(fdt_dir, os.path.dirname(dst)) | ||
| 144 | break | ||
| 145 | |||
| 146 | if not kernel_name: | ||
| 147 | raise WicError('No kernel file found') | ||
| 148 | |||
| 149 | # Compose the extlinux.conf | ||
| 150 | extlinux_conf = "default Yocto\n" | ||
| 151 | extlinux_conf += "label Yocto\n" | ||
| 152 | extlinux_conf += " kernel %s\n" % kernel_name | ||
| 153 | if has_dtb: | ||
| 154 | extlinux_conf += " fdtdir %s\n" % fdt_dir | ||
| 155 | bootloader = cr.ks.bootloader | ||
| 156 | extlinux_conf += "append root=%s rootwait %s\n" \ | ||
| 157 | % (cr.rootdev, bootloader.append if bootloader.append else '') | ||
| 158 | |||
| 159 | install_cmd = "install -d %s/extlinux/" % hdddir | ||
| 160 | exec_cmd(install_cmd) | ||
| 161 | cfg = open("%s/extlinux/extlinux.conf" % hdddir, "w") | ||
| 162 | cfg.write(extlinux_conf) | ||
| 163 | cfg.close() | ||
| 164 | |||
| 165 | |||
| 166 | @classmethod | ||
| 167 | def do_prepare_partition(cls, part, source_params, cr, cr_workdir, | ||
| 168 | oe_builddir, bootimg_dir, kernel_dir, | ||
| 169 | rootfs_dir, native_sysroot): | ||
| 170 | """ | ||
| 171 | Called to do the actual content population for a partition i.e. it | ||
| 172 | 'prepares' the partition to be incorporated into the image. | ||
| 173 | In this case, does the following: | ||
| 174 | - sets up a vfat partition | ||
| 175 | - copies all files listed in IMAGE_BOOT_FILES variable | ||
| 176 | """ | ||
| 177 | hdddir = "%s/boot.%d" % (cr_workdir, part.lineno) | ||
| 178 | |||
| 179 | if not kernel_dir: | ||
| 180 | kernel_dir = get_bitbake_var("DEPLOY_DIR_IMAGE") | ||
| 181 | if not kernel_dir: | ||
| 182 | raise WicError("Couldn't find DEPLOY_DIR_IMAGE, exiting") | ||
| 183 | |||
| 184 | logger.debug('Kernel dir: %s', bootimg_dir) | ||
| 185 | |||
| 186 | |||
| 187 | for task in cls.install_task: | ||
| 188 | src_path, dst_path = task | ||
| 189 | logger.debug('Install %s as %s', src_path, dst_path) | ||
| 190 | install_cmd = "install -m 0644 -D %s %s" \ | ||
| 191 | % (os.path.join(kernel_dir, src_path), | ||
| 192 | os.path.join(hdddir, dst_path)) | ||
| 193 | exec_cmd(install_cmd) | ||
| 194 | |||
| 195 | logger.debug('Prepare boot partition using rootfs in %s', hdddir) | ||
| 196 | part.prepare_rootfs(cr_workdir, oe_builddir, hdddir, | ||
| 197 | native_sysroot, False) | ||
