blob: b76c1211ae63162c6e73b90d479f3b87d4c9cd68 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# ex:ts=4:sw=4:sts=4:et
2# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
3#
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License version 2 as
6# published by the Free Software Foundation.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License along
14# with this program; if not, write to the Free Software Foundation, Inc.,
15# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16#
17# DESCRIPTION
18# This implements the 'bootimg-partition' source plugin class for
19# 'wic'. The plugin creates an image of boot partition, copying over
20# files listed in IMAGE_BOOT_FILES bitbake variable.
21#
22# AUTHORS
23# Maciej Borzecki <maciej.borzecki (at] open-rnd.pl>
24#
25
26import os
27import re
28
29from wic import msger
30from wic.pluginbase import SourcePlugin
31from wic.utils.oe.misc import exec_cmd, get_bitbake_var
32from glob import glob
33
34class BootimgPartitionPlugin(SourcePlugin):
35 """
36 Create an image of boot partition, copying over files
37 listed in IMAGE_BOOT_FILES bitbake variable.
38 """
39
40 name = 'bootimg-partition'
41
42 @classmethod
43 def do_install_disk(cls, disk, disk_name, cr, workdir, oe_builddir,
44 bootimg_dir, kernel_dir, native_sysroot):
45 """
46 Called after all partitions have been prepared and assembled into a
47 disk image. Do nothing.
48 """
49 pass
50
51 @classmethod
52 def do_configure_partition(cls, part, source_params, cr, cr_workdir,
53 oe_builddir, bootimg_dir, kernel_dir,
54 native_sysroot):
55 """
56 Called before do_prepare_partition(). Possibly prepare
57 configuration files of some sort.
58
59 """
60 pass
61
62 @classmethod
63 def do_prepare_partition(cls, part, source_params, cr, cr_workdir,
64 oe_builddir, bootimg_dir, kernel_dir,
65 rootfs_dir, native_sysroot):
66 """
67 Called to do the actual content population for a partition i.e. it
68 'prepares' the partition to be incorporated into the image.
69 In this case, does the following:
70 - sets up a vfat partition
71 - copies all files listed in IMAGE_BOOT_FILES variable
72 """
73 hdddir = "%s/boot" % cr_workdir
Patrick Williamsc124f4f2015-09-15 14:41:29 -050074 install_cmd = "install -d %s" % hdddir
75 exec_cmd(install_cmd)
76
77 if not bootimg_dir:
78 bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
79 if not bootimg_dir:
80 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
81
82 msger.debug('Bootimg dir: %s' % bootimg_dir)
83
84 boot_files = get_bitbake_var("IMAGE_BOOT_FILES")
85
86 if not boot_files:
87 msger.error('No boot files defined, IMAGE_BOOT_FILES unset')
88
89 msger.debug('Boot files: %s' % boot_files)
90
91 # list of tuples (src_name, dst_name)
92 deploy_files = []
93 for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files):
94 if ';' in src_entry:
95 dst_entry = tuple(src_entry.split(';'))
96 if not dst_entry[0] or not dst_entry[1]:
97 msger.error('Malformed boot file entry: %s' % (src_entry))
98 else:
99 dst_entry = (src_entry, src_entry)
100
101 msger.debug('Destination entry: %r' % (dst_entry,))
102 deploy_files.append(dst_entry)
103
104 for deploy_entry in deploy_files:
105 src, dst = deploy_entry
106 install_task = []
107 if '*' in src:
108 # by default install files under their basename
109 entry_name_fn = os.path.basename
110 if dst != src:
111 # unless a target name was given, then treat name
112 # as a directory and append a basename
113 entry_name_fn = lambda name: \
114 os.path.join(dst,
115 os.path.basename(name))
116
117 srcs = glob(os.path.join(bootimg_dir, src))
118
119 msger.debug('Globbed sources: %s' % (', '.join(srcs)))
120 for entry in srcs:
121 entry_dst_name = entry_name_fn(entry)
122 install_task.append((entry,
123 os.path.join(hdddir,
124 entry_dst_name)))
125 else:
126 install_task = [(os.path.join(bootimg_dir, src),
127 os.path.join(hdddir, dst))]
128
129 for task in install_task:
130 src_path, dst_path = task
131 msger.debug('Install %s as %s' % (os.path.basename(src_path),
132 dst_path))
133 install_cmd = "install -m 0644 -D %s %s" \
134 % (src_path, dst_path)
135 exec_cmd(install_cmd)
136
137 msger.debug('Prepare boot partition using rootfs in %s' % (hdddir))
138 part.prepare_rootfs(cr_workdir, oe_builddir, hdddir,
139 native_sysroot)
140