summaryrefslogtreecommitdiffstats
path: root/scripts/lib/wic/plugins/source/bootimg-partition.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/wic/plugins/source/bootimg-partition.py')
-rw-r--r--scripts/lib/wic/plugins/source/bootimg-partition.py115
1 files changed, 115 insertions, 0 deletions
diff --git a/scripts/lib/wic/plugins/source/bootimg-partition.py b/scripts/lib/wic/plugins/source/bootimg-partition.py
new file mode 100644
index 0000000000..564118ad8b
--- /dev/null
+++ b/scripts/lib/wic/plugins/source/bootimg-partition.py
@@ -0,0 +1,115 @@
1# 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 *
32
33class BootimgPartitionPlugin(SourcePlugin):
34 name = 'bootimg-partition'
35
36 @classmethod
37 def do_install_disk(self, disk, disk_name, cr, workdir, oe_builddir,
38 bootimg_dir, kernel_dir, native_sysroot):
39 """
40 Called after all partitions have been prepared and assembled into a
41 disk image. Do nothing.
42 """
43 pass
44
45 @classmethod
46 def do_configure_partition(self, part, source_params, cr, cr_workdir,
47 oe_builddir, bootimg_dir, kernel_dir,
48 native_sysroot):
49 """
50 Called before do_prepare_partition(). Possibly prepare
51 configuration files of some sort.
52
53 """
54 pass
55
56 @classmethod
57 def do_prepare_partition(self, part, source_params, cr, cr_workdir,
58 oe_builddir, bootimg_dir, kernel_dir,
59 rootfs_dir, native_sysroot):
60 """
61 Called to do the actual content population for a partition i.e. it
62 'prepares' the partition to be incorporated into the image.
63 In this case, does the following:
64 - sets up a vfat partition
65 - copies all files listed in IMAGE_BOOT_FILES variable
66 """
67 hdddir = "%s/boot" % cr_workdir
68 rm_cmd = "rm -rf %s" % cr_workdir
69 exec_cmd(rm_cmd)
70
71 install_cmd = "install -d %s" % hdddir
72 exec_cmd(install_cmd)
73
74 if not bootimg_dir:
75 bootimg_dir = get_bitbake_var("DEPLOY_DIR_IMAGE")
76 if not bootimg_dir:
77 msger.error("Couldn't find DEPLOY_DIR_IMAGE, exiting\n")
78
79 msger.debug('Bootimg dir: %s' % bootimg_dir)
80
81 boot_files = get_bitbake_var("IMAGE_BOOT_FILES")
82
83 if not boot_files:
84 msger.error('No boot files defined, IMAGE_BOOT_FILES unset')
85
86 msger.debug('Boot files: %s' % boot_files)
87
88 # list of tuples (src_name, dst_name)
89 deploy_files = []
90 for src_entry in re.findall(r'[\w;\-\./]+', boot_files):
91 if ';' in src_entry:
92 dst_entry = tuple(src_entry.split(';'))
93 if not dst_entry[0] or not dst_entry[1]:
94 msger.error('Malformed boot file entry: %s' % (src_entry))
95 else:
96 dst_entry = (src_entry, src_entry)
97
98 msger.debug('Destination entry: %r' % (dst_entry,))
99 deploy_files.append(dst_entry)
100
101 for deploy_entry in deploy_files:
102 src, dst = deploy_entry
103 src_path = os.path.join(bootimg_dir, src)
104 dst_path = os.path.join(hdddir, dst)
105
106 msger.debug('Install %s as %s' % (os.path.basename(src_path),
107 dst_path))
108 install_cmd = "install -m 0644 -D %s %s" \
109 % (src_path, dst_path)
110 exec_cmd(install_cmd)
111
112 msger.debug('Prepare boot partition using rootfs in %s' % (hdddir))
113 part.prepare_rootfs(cr_workdir, oe_builddir, hdddir,
114 native_sysroot)
115