diff options
Diffstat (limited to 'bitbake/bin/bbimage')
-rwxr-xr-x | bitbake/bin/bbimage | 154 |
1 files changed, 154 insertions, 0 deletions
diff --git a/bitbake/bin/bbimage b/bitbake/bin/bbimage new file mode 100755 index 0000000000..df6caa28ed --- /dev/null +++ b/bitbake/bin/bbimage | |||
@@ -0,0 +1,154 @@ | |||
1 | #!/usr/bin/env python | ||
2 | # ex:ts=4:sw=4:sts=4:et | ||
3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
4 | # | ||
5 | # Copyright (C) 2003 Chris Larson | ||
6 | # | ||
7 | # This program is free software; you can redistribute it and/or modify it under | ||
8 | # the terms of the GNU General Public License as published by the Free Software | ||
9 | # Foundation; either version 2 of the License, or (at your option) any later | ||
10 | # version. | ||
11 | # | ||
12 | # This program is distributed in the hope that it will be useful, but WITHOUT | ||
13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||
15 | # | ||
16 | # You should have received a copy of the GNU General Public License along with | ||
17 | # this program; if not, write to the Free Software Foundation, Inc., 59 Temple | ||
18 | # Place, Suite 330, Boston, MA 02111-1307 USA. | ||
19 | |||
20 | import sys, os | ||
21 | sys.path.append(os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib')) | ||
22 | import bb | ||
23 | from bb import * | ||
24 | |||
25 | __version__ = 1.0 | ||
26 | type = "jffs2" | ||
27 | cfg_bb = data.init() | ||
28 | cfg_oespawn = data.init() | ||
29 | |||
30 | |||
31 | def usage(): | ||
32 | print "Usage: bbimage [options ...]" | ||
33 | print "Creates an image for a target device from a root filesystem," | ||
34 | print "obeying configuration parameters from the BitBake" | ||
35 | print "configuration files, thereby easing handling of deviceisms." | ||
36 | print "" | ||
37 | print " %s\t\t%s" % ("-r [arg], --root [arg]", "root directory (default=${IMAGE_ROOTFS})") | ||
38 | print " %s\t\t%s" % ("-t [arg], --type [arg]", "image type (jffs2[default], cramfs)") | ||
39 | print " %s\t\t%s" % ("-n [arg], --name [arg]", "image name (override IMAGE_NAME variable)") | ||
40 | print " %s\t\t%s" % ("-v, --version", "output version information and exit") | ||
41 | sys.exit(0) | ||
42 | |||
43 | def version(): | ||
44 | print "BitBake Build Tool Core version %s" % bb.__version__ | ||
45 | print "BBImage version %s" % __version__ | ||
46 | |||
47 | def emit_bb(d, base_d = {}): | ||
48 | for v in d.keys(): | ||
49 | if d[v] != base_d[v]: | ||
50 | data.emit_var(v, d) | ||
51 | |||
52 | def getopthash(l): | ||
53 | h = {} | ||
54 | for (opt, val) in l: | ||
55 | h[opt] = val | ||
56 | return h | ||
57 | |||
58 | import getopt | ||
59 | try: | ||
60 | (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:e:n:', [ 'version', 'root=', 'type=', 'bbfile=', 'name=' ]) | ||
61 | except getopt.GetoptError: | ||
62 | usage() | ||
63 | |||
64 | # handle opts | ||
65 | opthash = getopthash(opts) | ||
66 | |||
67 | if '--version' in opthash or '-v' in opthash: | ||
68 | version() | ||
69 | sys.exit(0) | ||
70 | |||
71 | try: | ||
72 | cfg_bb = parse.handle(os.path.join('conf', 'bitbake.conf'), cfg_bb) | ||
73 | except IOError: | ||
74 | fatal("Unable to open bitbake.conf") | ||
75 | |||
76 | # sanity check | ||
77 | if cfg_bb is None: | ||
78 | fatal("Unable to open/parse %s" % os.path.join('conf', 'bitbake.conf')) | ||
79 | usage(1) | ||
80 | |||
81 | rootfs = None | ||
82 | extra_files = [] | ||
83 | |||
84 | if '--root' in opthash: | ||
85 | rootfs = opthash['--root'] | ||
86 | if '-r' in opthash: | ||
87 | rootfs = opthash['-r'] | ||
88 | |||
89 | if '--type' in opthash: | ||
90 | type = opthash['--type'] | ||
91 | if '-t' in opthash: | ||
92 | type = opthash['-t'] | ||
93 | |||
94 | if '--bbfile' in opthash: | ||
95 | extra_files.append(opthash['--bbfile']) | ||
96 | if '-e' in opthash: | ||
97 | extra_files.append(opthash['-e']) | ||
98 | |||
99 | for f in extra_files: | ||
100 | try: | ||
101 | cfg_bb = parse.handle(f, cfg_bb) | ||
102 | except IOError: | ||
103 | print "unable to open %s" % f | ||
104 | |||
105 | if not rootfs: | ||
106 | rootfs = data.getVar('IMAGE_ROOTFS', cfg_bb, 1) | ||
107 | |||
108 | if not rootfs: | ||
109 | bb.fatal("IMAGE_ROOTFS not defined") | ||
110 | |||
111 | data.setVar('IMAGE_ROOTFS', rootfs, cfg_bb) | ||
112 | |||
113 | from copy import copy, deepcopy | ||
114 | localdata = data.createCopy(cfg_bb) | ||
115 | |||
116 | overrides = data.getVar('OVERRIDES', localdata) | ||
117 | if not overrides: | ||
118 | bb.fatal("OVERRIDES not defined.") | ||
119 | data.setVar('OVERRIDES', '%s:%s' % (overrides, type), localdata) | ||
120 | data.update_data(localdata) | ||
121 | data.setVar('OVERRIDES', overrides, localdata) | ||
122 | |||
123 | if '-n' in opthash: | ||
124 | data.setVar('IMAGE_NAME', opthash['-n'], localdata) | ||
125 | if '--name' in opthash: | ||
126 | data.setVar('IMAGE_NAME', opthash['--name'], localdata) | ||
127 | |||
128 | topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd() | ||
129 | |||
130 | cmd = data.getVar('IMAGE_CMD', localdata, 1) | ||
131 | if not cmd: | ||
132 | bb.fatal("IMAGE_CMD not defined") | ||
133 | |||
134 | outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1) | ||
135 | if not outdir: | ||
136 | bb.fatal('DEPLOY_DIR_IMAGE not defined') | ||
137 | mkdirhier(outdir) | ||
138 | |||
139 | #depends = data.getVar('IMAGE_DEPENDS', localdata, 1) or "" | ||
140 | #if depends: | ||
141 | # bb.note("Spawning bbmake to satisfy dependencies: %s" % depends) | ||
142 | # ret = os.system('bbmake %s' % depends) | ||
143 | # if ret != 0: | ||
144 | # bb.error("executing bbmake to satisfy dependencies") | ||
145 | |||
146 | bb.note("Executing %s" % cmd) | ||
147 | data.setVar('image_cmd', cmd, localdata) | ||
148 | data.setVarFlag('image_cmd', 'func', 1, localdata) | ||
149 | try: | ||
150 | bb.build.exec_func('image_cmd', localdata) | ||
151 | except bb.build.FuncFailed: | ||
152 | sys.exit(1) | ||
153 | #ret = os.system(cmd) | ||
154 | #sys.exit(ret) | ||