2 # ex:ts=4:sw=4:sts=4:et
3 # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
5 # Copyright (C) 2003 Chris Larson
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
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.
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.
21 sys.path.append(os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
28 cfg_oespawn = data.init()
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."
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")
44 print "BitBake Build Tool Core version %s" % bb.__version__
45 print "BBImage version %s" % __version__
47 def emit_bb(d, base_d = {}):
60 (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:e:n:', [ 'version', 'root=', 'type=', 'bbfile=', 'name=' ])
61 except getopt.GetoptError:
65 opthash = getopthash(opts)
67 if '--version' in opthash or '-v' in opthash:
72 cfg_bb = parse.handle(os.path.join('conf', 'bitbake.conf'), cfg_bb)
74 fatal("Unable to open bitbake.conf")
78 fatal("Unable to open/parse %s" % os.path.join('conf', 'bitbake.conf'))
84 if '--root' in opthash:
85 rootfs = opthash['--root']
87 rootfs = opthash['-r']
89 if '--type' in opthash:
90 type = opthash['--type']
94 if '--bbfile' in opthash:
95 extra_files.append(opthash['--bbfile'])
97 extra_files.append(opthash['-e'])
101 cfg_bb = parse.handle(f, cfg_bb)
103 print "unable to open %s" % f
106 rootfs = data.getVar('IMAGE_ROOTFS', cfg_bb, 1)
109 bb.fatal("IMAGE_ROOTFS not defined")
111 data.setVar('IMAGE_ROOTFS', rootfs, cfg_bb)
113 from copy import copy, deepcopy
114 localdata = data.createCopy(cfg_bb)
116 overrides = data.getVar('OVERRIDES', localdata)
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)
124 data.setVar('IMAGE_NAME', opthash['-n'], localdata)
125 if '--name' in opthash:
126 data.setVar('IMAGE_NAME', opthash['--name'], localdata)
128 topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd()
130 cmd = data.getVar('IMAGE_CMD', localdata, 1)
132 bb.fatal("IMAGE_CMD not defined")
134 outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1)
136 bb.fatal('DEPLOY_DIR_IMAGE not defined')
139 #depends = data.getVar('IMAGE_DEPENDS', localdata, 1) or ""
141 # bb.note("Spawning bbmake to satisfy dependencies: %s" % depends)
142 # ret = os.system('bbmake %s' % depends)
144 # bb.error("executing bbmake to satisfy dependencies")
146 bb.note("Executing %s" % cmd)
147 data.setVar('image_cmd', cmd, localdata)
148 data.setVarFlag('image_cmd', 'func', 1, localdata)
150 bb.build.exec_func('image_cmd', localdata)
151 except bb.build.FuncFailed:
153 #ret = os.system(cmd)