bbimage 4.5 KB

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