diff options
author | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
---|---|---|
committer | Tudor Florea <tudor.florea@enea.com> | 2014-10-16 03:05:19 +0200 |
commit | c527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch) | |
tree | bb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /scripts/lib/mic/plugins/source/uboot.py | |
download | poky-daisy-140929.tar.gz |
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch
Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'scripts/lib/mic/plugins/source/uboot.py')
-rw-r--r-- | scripts/lib/mic/plugins/source/uboot.py | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/scripts/lib/mic/plugins/source/uboot.py b/scripts/lib/mic/plugins/source/uboot.py new file mode 100644 index 0000000000..57cb3cf8fe --- /dev/null +++ b/scripts/lib/mic/plugins/source/uboot.py | |||
@@ -0,0 +1,173 @@ | |||
1 | # ex:ts=4:sw=4:sts=4:et | ||
2 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
3 | # | ||
4 | # Copyright (c) 2014, Enea AB. | ||
5 | # All rights reserved. | ||
6 | # | ||
7 | # This program is free software; you can redistribute it and/or modify | ||
8 | # it under the terms of the GNU General Public License version 2 as | ||
9 | # published by the Free Software Foundation. | ||
10 | # | ||
11 | # This program is distributed in the hope that it will be useful, | ||
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | # GNU General Public License for more details. | ||
15 | # | ||
16 | # You should have received a copy of the GNU General Public License along | ||
17 | # with this program; if not, write to the Free Software Foundation, Inc., | ||
18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
19 | # | ||
20 | # DESCRIPTION | ||
21 | # This implements the 'uboot' source plugin class for 'wic' | ||
22 | # | ||
23 | # AUTHORS | ||
24 | # Adrian Calianu <adrian.calianu (at] enea.com> | ||
25 | # | ||
26 | |||
27 | import os | ||
28 | import shutil | ||
29 | import re | ||
30 | import tempfile | ||
31 | |||
32 | from mic import kickstart, chroot, msger | ||
33 | from mic.utils import misc, fs_related, errors, runner, cmdln | ||
34 | from mic.conf import configmgr | ||
35 | from mic.plugin import pluginmgr | ||
36 | from mic.utils.partitionedfs import PartitionedMount | ||
37 | import mic.imager.direct as direct | ||
38 | from mic.pluginbase import SourcePlugin | ||
39 | from mic.utils.oe.misc import * | ||
40 | from mic.imager.direct import DirectImageCreator | ||
41 | |||
42 | def create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot): | ||
43 | # In order to have a full control over rootfs we will make a local copy under workdir | ||
44 | # and change rootfs_dir to new location. | ||
45 | # In this way we can install more than one ROOTFS_DIRs and/or use | ||
46 | # an empty rootfs to install packages, so a rootfs could be generated only from pkgs | ||
47 | # TBD: create workdir/rootfs ; copy rootfs-> workdir/rootfs; set rootfs=workdir/rootfs | ||
48 | |||
49 | cr_workdir = os.path.abspath(cr_workdir) | ||
50 | new_rootfs_dir = "%s/rootfs_%s" % (cr_workdir, creator.name) | ||
51 | |||
52 | rootfs_exists = 1 | ||
53 | if part.rootfs is None: | ||
54 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
55 | msg = "Couldn't find --rootfs-dir, exiting, " | ||
56 | msger.info(msg) | ||
57 | rootfs_exists = 0 | ||
58 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
59 | creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir | ||
60 | else: | ||
61 | if part.rootfs in krootfs_dir: | ||
62 | rootfs_dir = krootfs_dir[part.rootfs] | ||
63 | creator.rootfs_dir[part.rootfs] = new_rootfs_dir | ||
64 | elif os.path.isdir(part.rootfs): | ||
65 | rootfs_dir = part.rootfs | ||
66 | part.rootfs = new_rootfs_dir | ||
67 | else: | ||
68 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
69 | msg += " or it is not a valid path, exiting" | ||
70 | msger.info(msg % part.rootfs) | ||
71 | rootfs_exists = 0 | ||
72 | creator.rootfs_dir['ROOTFS_DIR'] = new_rootfs_dir | ||
73 | |||
74 | pseudox = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot | ||
75 | pseudox += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % new_rootfs_dir | ||
76 | pseudox += "export PSEUDO_PASSWD=%s;" % new_rootfs_dir | ||
77 | pseudox += "export PSEUDO_NOSYMLINKEXP=1;" | ||
78 | pseudox += "%s/usr/bin/pseudo " % native_sysroot | ||
79 | |||
80 | mkdir_cmd = "mkdir %s" % (new_rootfs_dir) | ||
81 | # rc, out = exec_native_cmd(pseudox + mkdir_cmd, native_sysroot) | ||
82 | rc, out = exec_cmd(mkdir_cmd, True) | ||
83 | |||
84 | if rootfs_exists == 1 and os.path.isdir(rootfs_dir): | ||
85 | defpath = os.environ['PATH'] | ||
86 | os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" | ||
87 | |||
88 | rootfs_dir = os.path.abspath(rootfs_dir) | ||
89 | |||
90 | pseudoc = "export PSEUDO_PREFIX=%s/usr;" % native_sysroot | ||
91 | pseudoc += "export PSEUDO_LOCALSTATEDIR=%s/../pseudo;" % rootfs_dir | ||
92 | pseudoc += "export PSEUDO_PASSWD=%s;" % rootfs_dir | ||
93 | pseudoc += "export PSEUDO_NOSYMLINKEXP=1;" | ||
94 | pseudoc += "%s/usr/bin/pseudo " % native_sysroot | ||
95 | |||
96 | tarc_cmd = "tar cvpf %s/rootfs.tar -C %s ." % (cr_workdir, rootfs_dir) | ||
97 | rc, out = exec_native_cmd(pseudoc + tarc_cmd, native_sysroot) | ||
98 | |||
99 | tarx_cmd = "tar xpvf %s/rootfs.tar -C %s" % (cr_workdir, new_rootfs_dir) | ||
100 | rc, out = exec_native_cmd(pseudox + tarx_cmd, native_sysroot) | ||
101 | |||
102 | rm_cmd = "rm %s/rootfs.tar" % cr_workdir | ||
103 | rc, out = exec_cmd(rm_cmd, True) | ||
104 | |||
105 | os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" | ||
106 | |||
107 | return new_rootfs_dir | ||
108 | |||
109 | class UBootPlugin(SourcePlugin): | ||
110 | name = 'uboot' | ||
111 | |||
112 | @classmethod | ||
113 | def do_install_pkgs(self, part, creator, cr_workdir, oe_builddir, krootfs_dir, | ||
114 | bootimg_dir, kernel_dir, native_sysroot): | ||
115 | """ | ||
116 | Called before all partitions have been prepared and assembled into a | ||
117 | disk image. Intall packages based on wic configuration. | ||
118 | """ | ||
119 | |||
120 | # set new rootfs_dir | ||
121 | rootfs_dir = create_local_rootfs(part, creator, cr_workdir, krootfs_dir, native_sysroot) | ||
122 | |||
123 | # wks file parsing | ||
124 | packages = kickstart.get_packages(creator.ks) | ||
125 | |||
126 | # wic.conf file parsing = found under 'creator' | ||
127 | local_pkgs_path = creator._local_pkgs_path | ||
128 | repourl = creator.repourl | ||
129 | pkgmgr = creator.pkgmgr_name | ||
130 | |||
131 | # install packages | ||
132 | if packages and pkgmgr in ["opkg"]: | ||
133 | if len(repourl) > 0 : | ||
134 | part.install_pkgs_ipk(cr_workdir, oe_builddir, rootfs_dir, native_sysroot, | ||
135 | packages, repourl) | ||
136 | else: | ||
137 | msger.error("No packages repository provided in wic.conf") | ||
138 | |||
139 | @classmethod | ||
140 | def do_prepare_partition(self, part, cr, cr_workdir, oe_builddir, bootimg_dir, | ||
141 | kernel_dir, krootfs_dir, native_sysroot): | ||
142 | """ | ||
143 | Called to do the actual content population for a partition i.e. it | ||
144 | 'prepares' the partition to be incorporated into the image. | ||
145 | In this case, prepare content for legacy bios boot partition. | ||
146 | """ | ||
147 | if part.rootfs is None: | ||
148 | if not 'ROOTFS_DIR' in krootfs_dir: | ||
149 | msg = "Couldn't find --rootfs-dir, exiting" | ||
150 | msger.error(msg) | ||
151 | rootfs_dir = krootfs_dir['ROOTFS_DIR'] | ||
152 | else: | ||
153 | if part.rootfs in krootfs_dir: | ||
154 | rootfs_dir = krootfs_dir[part.rootfs] | ||
155 | elif os.path.isdir(part.rootfs): | ||
156 | rootfs_dir = part.rootfs | ||
157 | else: | ||
158 | msg = "Couldn't find --rootfs-dir=%s connection" | ||
159 | msg += " or it is not a valid path, exiting" | ||
160 | msger.error(msg % part.rootfs) | ||
161 | |||
162 | part.set_rootfs(rootfs_dir) | ||
163 | |||
164 | # change partition label wich will reflect into the final rootfs image name | ||
165 | part.label = "%s_%s" % (part.label, cr.name) | ||
166 | |||
167 | defpath = os.environ['PATH'] | ||
168 | os.environ['PATH'] = native_sysroot + "/usr/bin/" + ":/bin:/usr/bin:" | ||
169 | |||
170 | part.prepare_rootfs(cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | ||
171 | part.prepare_for_uboot(cr.target_arch,cr_workdir, oe_builddir, rootfs_dir, native_sysroot) | ||
172 | |||
173 | os.environ['PATH'] += defpath + ":" + native_sysroot + "/usr/bin/" | ||