blob: bc2ca0f6fae3d956cee4378393d22c595c2a8051 [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
74 rm_cmd = "rm -rf %s/boot" % cr_workdir
75 exec_cmd(rm_cmd)
76
77 install_cmd = "install -d %s" % hdddir
78 exec_cmd(install_cmd)
79
80 if not bootimg_dir:
81 bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
82 if not bootimg_dir:
83 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
84
85 msger.debug('Bootimg dir: %s' % bootimg_dir)
86
87 boot_files = get_bitbake_var("IMAGE_BOOT_FILES")
88
89 if not boot_files:
90 msger.error('No boot files defined, IMAGE_BOOT_FILES unset')
91
92 msger.debug('Boot files: %s' % boot_files)
93
94 # list of tuples (src_name, dst_name)
95 deploy_files = []
96 for src_entry in re.findall(r'[\w;\-\./\*]+', boot_files):
97 if ';' in src_entry:
98 dst_entry = tuple(src_entry.split(';'))
99 if not dst_entry[0] or not dst_entry[1]:
100 msger.error('Malformed boot file entry: %s' % (src_entry))
101 else:
102 dst_entry = (src_entry, src_entry)
103
104 msger.debug('Destination entry: %r' % (dst_entry,))
105 deploy_files.append(dst_entry)
106
107 for deploy_entry in deploy_files:
108 src, dst = deploy_entry
109 install_task = []
110 if '*' in src:
111 # by default install files under their basename
112 entry_name_fn = os.path.basename
113 if dst != src:
114 # unless a target name was given, then treat name
115 # as a directory and append a basename
116 entry_name_fn = lambda name: \
117 os.path.join(dst,
118 os.path.basename(name))
119
120 srcs = glob(os.path.join(bootimg_dir, src))
121
122 msger.debug('Globbed sources: %s' % (', '.join(srcs)))
123 for entry in srcs:
124 entry_dst_name = entry_name_fn(entry)
125 install_task.append((entry,
126 os.path.join(hdddir,
127 entry_dst_name)))
128 else:
129 install_task = [(os.path.join(bootimg_dir, src),
130 os.path.join(hdddir, dst))]
131
132 for task in install_task:
133 src_path, dst_path = task
134 msger.debug('Install %s as %s' % (os.path.basename(src_path),
135 dst_path))
136 install_cmd = "install -m 0644 -D %s %s" \
137 % (src_path, dst_path)
138 exec_cmd(install_cmd)
139
140 msger.debug('Prepare boot partition using rootfs in %s' % (hdddir))
141 part.prepare_rootfs(cr_workdir, oe_builddir, hdddir,
142 native_sysroot)
143