summaryrefslogtreecommitdiffstats
path: root/bin/oeimage
blob: 3498ecddb73b767f85329e029b550b79d419c6b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
# ex:ts=4:sw=4:sts=4:et
# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-

import sys, os, oe
from oe import *

__version__ = 1.0
type = "jffs2"
cfg_oe = data.init()
cfg_oespawn = data.init()


def usage():
    print "Usage: oeimage [options ...]"
    print "Creates an image for a target device from a root filesystem,"
    print "obeying configuration parameters from the OpenEmbedded"
    print "configuration files, thereby easing handling of deviceisms."
    print ""
    print "  %s\t\t%s" % ("-r [arg], --root [arg]", "root directory (default=${IMAGE_ROOTFS})")
    print "  %s\t\t%s" % ("-t [arg], --type [arg]", "image type (jffs2[default], cramfs)")
    print "  %s\t\t%s" % ("-n [arg], --name [arg]", "image name (override IMAGE_NAME variable)")
    print "  %s\t\t%s" % ("-v, --version", "output version information and exit")
    sys.exit(0)

def version():
    print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
    print "OEImage version %s" % __version__

def emit_oe(d, base_d = {}):
    for v in d.keys():
        if d[v] != base_d[v]:
            data.emit_var(v, d)

def getopthash(l):
    h = {}
    for (opt, val) in l:
        h[opt] = val
    return h

import getopt
try:
    (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:e:n:', [ 'version', 'root=', 'type=', 'oefile=', 'name=' ])
except getopt.GetoptError:
    usage()

# handle opts
opthash = getopthash(opts)

if '--version' in opthash or '-v' in opthash:
    version()
    sys.exit(0)

try:
    cfg_oe = parse.handle("conf/oe.conf", cfg_oe)
except IOError:
    fatal("Unable to open oe.conf")

# sanity check
if cfg_oe is None:
    fatal("Unable to open/parse conf/oe.conf")
    usage(1)

rootfs = None
extra_files = []

if '--root' in opthash:
    rootfs = opthash['--root']
if '-r' in opthash:
    rootfs = opthash['-r']

if '--type' in opthash:
    type = opthash['--type']
if '-t' in opthash:
    type = opthash['-t']

if '--oefile' in opthash:
    extra_files.append(opthash['--oefile'])
if '-e' in opthash:
    extra_files.append(opthash['-e'])

for f in extra_files:
    try:
        cfg_oe = parse.handle(f, cfg_oe)
    except IOError:
        print "unable to open %s" % f

if not rootfs:
    rootfs = data.getVar('IMAGE_ROOTFS', cfg_oe, 1)

if not rootfs:
    oe.fatal("IMAGE_ROOTFS not defined")

data.setVar('IMAGE_ROOTFS', rootfs, cfg_oe)

from copy import copy, deepcopy
localdata = deepcopy(cfg_oe)

overrides = data.getVar('OVERRIDES', localdata)
if not overrides:
    oe.fatal("OVERRIDES not defined.")
data.setVar('OVERRIDES', '%s:%s' % (overrides, type), localdata)
data.update_data(localdata)
data.setVar('OVERRIDES', overrides, localdata)

if '-n' in opthash:
    data.setVar('IMAGE_NAME', opthash['-n'], localdata)
if '--name' in opthash:
    data.setVar('IMAGE_NAME', opthash['--name'], localdata)

topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd()

cmd = data.getVar('IMAGE_CMD', localdata, 1)
if not cmd:
    oe.fatal("IMAGE_CMD not defined")

outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1)
if not outdir:
    oe.fatal('DEPLOY_DIR_IMAGE not defined')
mkdirhier(outdir)

#depends = data.getVar('IMAGE_DEPENDS', localdata, 1) or ""
#if depends:
#       oe.note("Spawning oemake to satisfy dependencies: %s" % depends)
#       ret = os.system('oemake %s' % depends)
#       if ret != 0:
#           oe.error("executing oemake to satisfy dependencies")

oe.note("Executing %s" % cmd)
data.setVar('T', '${TMPDIR}', localdata)
data.setVar('image_cmd', cmd, localdata)
data.setVarFlag('image_cmd', 'func', 1, localdata)
try:
    oe.build.exec_func('image_cmd', localdata)
except oe.build.FuncFailed:
    sys.exit(1)
#ret = os.system(cmd)
#sys.exit(ret)