summaryrefslogtreecommitdiffstats
path: root/bitbake/bin/bbimage
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/bin/bbimage')
-rwxr-xr-xbitbake/bin/bbimage154
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
20import sys, os
21sys.path.append(os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
22import bb
23from bb import *
24
25__version__ = 1.0
26type = "jffs2"
27cfg_bb = data.init()
28cfg_oespawn = data.init()
29
30
31def 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
43def version():
44 print "BitBake Build Tool Core version %s" % bb.__version__
45 print "BBImage version %s" % __version__
46
47def 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
52def getopthash(l):
53 h = {}
54 for (opt, val) in l:
55 h[opt] = val
56 return h
57
58import getopt
59try:
60 (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:e:n:', [ 'version', 'root=', 'type=', 'bbfile=', 'name=' ])
61except getopt.GetoptError:
62 usage()
63
64# handle opts
65opthash = getopthash(opts)
66
67if '--version' in opthash or '-v' in opthash:
68 version()
69 sys.exit(0)
70
71try:
72 cfg_bb = parse.handle(os.path.join('conf', 'bitbake.conf'), cfg_bb)
73except IOError:
74 fatal("Unable to open bitbake.conf")
75
76# sanity check
77if cfg_bb is None:
78 fatal("Unable to open/parse %s" % os.path.join('conf', 'bitbake.conf'))
79 usage(1)
80
81rootfs = None
82extra_files = []
83
84if '--root' in opthash:
85 rootfs = opthash['--root']
86if '-r' in opthash:
87 rootfs = opthash['-r']
88
89if '--type' in opthash:
90 type = opthash['--type']
91if '-t' in opthash:
92 type = opthash['-t']
93
94if '--bbfile' in opthash:
95 extra_files.append(opthash['--bbfile'])
96if '-e' in opthash:
97 extra_files.append(opthash['-e'])
98
99for 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
105if not rootfs:
106 rootfs = data.getVar('IMAGE_ROOTFS', cfg_bb, 1)
107
108if not rootfs:
109 bb.fatal("IMAGE_ROOTFS not defined")
110
111data.setVar('IMAGE_ROOTFS', rootfs, cfg_bb)
112
113from copy import copy, deepcopy
114localdata = data.createCopy(cfg_bb)
115
116overrides = data.getVar('OVERRIDES', localdata)
117if not overrides:
118 bb.fatal("OVERRIDES not defined.")
119data.setVar('OVERRIDES', '%s:%s' % (overrides, type), localdata)
120data.update_data(localdata)
121data.setVar('OVERRIDES', overrides, localdata)
122
123if '-n' in opthash:
124 data.setVar('IMAGE_NAME', opthash['-n'], localdata)
125if '--name' in opthash:
126 data.setVar('IMAGE_NAME', opthash['--name'], localdata)
127
128topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd()
129
130cmd = data.getVar('IMAGE_CMD', localdata, 1)
131if not cmd:
132 bb.fatal("IMAGE_CMD not defined")
133
134outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1)
135if not outdir:
136 bb.fatal('DEPLOY_DIR_IMAGE not defined')
137mkdirhier(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
146bb.note("Executing %s" % cmd)
147data.setVar('image_cmd', cmd, localdata)
148data.setVarFlag('image_cmd', 'func', 1, localdata)
149try:
150 bb.build.exec_func('image_cmd', localdata)
151except bb.build.FuncFailed:
152 sys.exit(1)
153#ret = os.system(cmd)
154#sys.exit(ret)