bbimage 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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
  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. import sys, os
  20. sys.path.insert(0,os.path.join(os.path.dirname(os.path.dirname(sys.argv[0])), 'lib'))
  21. import bb
  22. from bb import *
  23. __version__ = 1.1
  24. type = "jffs2"
  25. cfg_bb = data.init()
  26. cfg_oespawn = data.init()
  27. bb.msg.set_debug_level(0)
  28. def usage():
  29. print "Usage: bbimage [options ...]"
  30. print "Creates an image for a target device from a root filesystem,"
  31. print "obeying configuration parameters from the BitBake"
  32. print "configuration files, thereby easing handling of deviceisms."
  33. print ""
  34. print " %s\t\t%s" % ("-r [arg], --root [arg]", "root directory (default=${IMAGE_ROOTFS})")
  35. print " %s\t\t%s" % ("-t [arg], --type [arg]", "image type (jffs2[default], cramfs)")
  36. print " %s\t\t%s" % ("-n [arg], --name [arg]", "image name (override IMAGE_NAME variable)")
  37. print " %s\t\t%s" % ("-v, --version", "output version information and exit")
  38. sys.exit(0)
  39. def version():
  40. print "BitBake Build Tool Core version %s" % bb.__version__
  41. print "BBImage version %s" % __version__
  42. def emit_bb(d, base_d = {}):
  43. for v in d.keys():
  44. if d[v] != base_d[v]:
  45. data.emit_var(v, d)
  46. def getopthash(l):
  47. h = {}
  48. for (opt, val) in l:
  49. h[opt] = val
  50. return h
  51. import getopt
  52. try:
  53. (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:e:n:', [ 'version', 'root=', 'type=', 'bbfile=', 'name=' ])
  54. except getopt.GetoptError:
  55. usage()
  56. # handle opts
  57. opthash = getopthash(opts)
  58. if '--version' in opthash or '-v' in opthash:
  59. version()
  60. sys.exit(0)
  61. try:
  62. cfg_bb = parse.handle(os.path.join('conf', 'bitbake.conf'), cfg_bb)
  63. except IOError:
  64. fatal("Unable to open bitbake.conf")
  65. # sanity check
  66. if cfg_bb is None:
  67. fatal("Unable to open/parse %s" % os.path.join('conf', 'bitbake.conf'))
  68. usage(1)
  69. rootfs = None
  70. extra_files = []
  71. if '--root' in opthash:
  72. rootfs = opthash['--root']
  73. if '-r' in opthash:
  74. rootfs = opthash['-r']
  75. if '--type' in opthash:
  76. type = opthash['--type']
  77. if '-t' in opthash:
  78. type = opthash['-t']
  79. if '--bbfile' in opthash:
  80. extra_files.append(opthash['--bbfile'])
  81. if '-e' in opthash:
  82. extra_files.append(opthash['-e'])
  83. for f in extra_files:
  84. try:
  85. cfg_bb = parse.handle(f, cfg_bb)
  86. except IOError:
  87. print "unable to open %s" % f
  88. if not rootfs:
  89. rootfs = data.getVar('IMAGE_ROOTFS', cfg_bb, 1)
  90. if not rootfs:
  91. bb.fatal("IMAGE_ROOTFS not defined")
  92. data.setVar('IMAGE_ROOTFS', rootfs, cfg_bb)
  93. from copy import copy, deepcopy
  94. localdata = data.createCopy(cfg_bb)
  95. overrides = data.getVar('OVERRIDES', localdata)
  96. if not overrides:
  97. bb.fatal("OVERRIDES not defined.")
  98. data.setVar('OVERRIDES', '%s:%s' % (overrides, type), localdata)
  99. data.update_data(localdata)
  100. data.setVar('OVERRIDES', overrides, localdata)
  101. if '-n' in opthash:
  102. data.setVar('IMAGE_NAME', opthash['-n'], localdata)
  103. if '--name' in opthash:
  104. data.setVar('IMAGE_NAME', opthash['--name'], localdata)
  105. topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd()
  106. cmd = data.getVar('IMAGE_CMD', localdata, 1)
  107. if not cmd:
  108. bb.fatal("IMAGE_CMD not defined")
  109. outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1)
  110. if not outdir:
  111. bb.fatal('DEPLOY_DIR_IMAGE not defined')
  112. mkdirhier(outdir)
  113. #depends = data.getVar('IMAGE_DEPENDS', localdata, 1) or ""
  114. #if depends:
  115. # bb.note("Spawning bbmake to satisfy dependencies: %s" % depends)
  116. # ret = os.system('bbmake %s' % depends)
  117. # if ret != 0:
  118. # bb.error("executing bbmake to satisfy dependencies")
  119. bb.note("Executing %s" % cmd)
  120. data.setVar('image_cmd', cmd, localdata)
  121. data.setVarFlag('image_cmd', 'func', 1, localdata)
  122. try:
  123. bb.build.exec_func('image_cmd', localdata)
  124. except bb.build.FuncFailed:
  125. sys.exit(1)
  126. #ret = os.system(cmd)
  127. #sys.exit(ret)