Skip to content

Commit

Permalink
Use droidtools.mkbootimg to create boot images
Browse files Browse the repository at this point in the history
refs #30 build python c extensions for some of the binaries
  • Loading branch information
tgalal committed Aug 6, 2015
1 parent 34fae08 commit 03ea715
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 36 deletions.
8 changes: 4 additions & 4 deletions inception/argparsers/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,10 @@ def unpackimg(self, img, out, unpacker, imgType):
bootImgGenerator = imgtools.unpackimg(unpacker, img, out)

self.newConfig.set("%s.img.cmdline" % imgType, bootImgGenerator.getKernelCmdLine(quote=False))
self.newConfig.set("%s.img.base" % imgType, bootImgGenerator.getBaseAddr())
self.newConfig.set("%s.img.ramdisk_offset" % imgType, bootImgGenerator.getRamdiskOffset())
self.newConfig.set("%s.img.second_offset" % imgType, bootImgGenerator.getSecondOffset())
self.newConfig.set("%s.img.tags_offset" % imgType, bootImgGenerator.getTagsOffset())
self.newConfig.set("%s.img.base" % imgType, hex(bootImgGenerator.getBaseAddr()))
self.newConfig.set("%s.img.ramdisk_offset" % imgType, hex(bootImgGenerator.getRamdiskOffset()))
self.newConfig.set("%s.img.second_offset" % imgType, hex(bootImgGenerator.getSecondOffset()))
self.newConfig.set("%s.img.tags_offset" % imgType, hex(bootImgGenerator.getTagsOffset()))
self.newConfig.set("%s.img.pagesize" % imgType, bootImgGenerator.getPageSize())
self.newConfig.set("%s.img.second_size" % imgType, bootImgGenerator.getSecondSize())
self.newConfig.set("%s.img.dt_size" % imgType, bootImgGenerator.getDeviceTreeSize())
Expand Down
4 changes: 1 addition & 3 deletions inception/argparsers/makers/maker_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ def make(self, workDir, outDir):
shutil.copy(bootConfigProp.resolveAsRelativePath(), os.path.join(outDir, self.imageName))
return

key, mkbootbin = self.getHostBinary("mkbootimg")
assert mkbootbin, "%s is not set" % key
gen = BootImgGenerator(mkbootbin)
gen = BootImgGenerator()
gen.setWorkDir(workDir)

ramdisk = self.getMakeProperty("img.ramdisk_dir").resolveAsRelativePath()
Expand Down
52 changes: 28 additions & 24 deletions inception/generators/bootimg.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from .generator import Generator
import os, tempfile
import os, tempfile, sys
from droidtools import mkbootimg

if sys.version_info >= (3,0):
unicode = str

class BootImgGenerator(Generator):
def __init__(self, mkbootBin):
def __init__(self):
super(BootImgGenerator, self).__init__()
self.bin = mkbootBin
self.base = None
self.ramdiskaddr = None
self.pagesize = 2048
Expand Down Expand Up @@ -47,25 +51,25 @@ def getRamdisk(self):
return self.ramdisk

def setDeviceTreeSize(self, size):
self.devicetreesize = size
self.devicetreesize = int(size)

def getDeviceTreeSize(self):
return self.devicetreesize

def setSecondSize(self, size):
self.secondsize = size
self.secondsize = int(size)

def getSecondSize(self):
return self.secondsize

def setTagsOffset(self, tagsOffset):
self.tags_offset = tagsOffset
self.tags_offset = int(tagsOffset, 16) if type(tagsOffset) in (str,unicode) else tagsOffset

def getTagsOffset(self):
return self.tags_offset

def setSecondOffset(self, second_offset):
self.second_offset = second_offset
self.second_offset = int(second_offset, 16) if type(second_offset) in (str, unicode) else second_offset

def getSecondOffset(self):
return self.second_offset
Expand All @@ -85,7 +89,7 @@ def getDeviceTree(self):
return self.dt

def setRamdiskAddr(self, addr):
self.ramdiskaddr = addr
self.ramdiskaddr = int(addr, 16) if type(addr) in (str,unicode) else addr

def getRamdiskAddr(self):
return self.ramdiskaddr
Expand All @@ -97,7 +101,7 @@ def getKernel(self):
return self.kernel

def setBaseAddr(self, addr):
self.base = addr
self.base = int(addr, 16) if type(addr) in (str, unicode) else addr

def getBaseAddr(self):
return self.base
Expand All @@ -116,21 +120,11 @@ def getSignature(self):
return self.signature

def setRamdiskOffset(self, offset):
self.ramdisk_offset = offset
self.ramdisk_offset = int(offset, 16) if type(offset) in (str, unicode) else offset

def getRamdiskOffset(self):
return self.ramdisk_offset

def createArgs(self):
args = ()
for arg, getter in self.argsMap.items():
val = getter()
if val:
args += ("--%s" % arg, str(val))
return args



def generate(self, out):
ramdisk = self.getRamdisk()
if os.path.isdir(ramdisk):
Expand All @@ -152,7 +146,17 @@ def generate(self, out):
fCpio.close()
fRamdisk.close()

args = self.createArgs()
cmd = (self.bin,) + args + ("--output", out)
#cmd = self.bin + " " + self.createArgs() + " --output " + out
self.execCmd(*cmd)
mkbootimg.build(
out,
None,
self.getBaseAddr(),
self.getKernelCmdLine(False),
self.getPageSize(),
None,
self.getRamdiskOffset(),
self.getSecondOffset(),
self.getTagsOffset(),
self.getKernel(),
self.getRamdisk(),
None,
self.getDeviceTree())
10 changes: 5 additions & 5 deletions inception/tools/imgtools.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def unpackimg(unpackerBin, img, out):

#process unpacker output
resultList = unpackResult.split('\n')
bootImgGenerator = BootImgGenerator(None)
bootImgGenerator = BootImgGenerator()

for l in resultList:
try:
Expand All @@ -46,13 +46,13 @@ def unpackimg(unpackerBin, img, out):
if key == "BOARD_KERNEL_CMDLINE":
bootImgGenerator.setKernelCmdLine(value)
elif key == "BOARD_KERNEL_BASE":
bootImgGenerator.setBaseAddr("0x" + value)
bootImgGenerator.setBaseAddr(value)
elif key == "BOARD_RAMDISK_OFFSET":
bootImgGenerator.setRamdiskOffset("0x" + value)
bootImgGenerator.setRamdiskOffset(value)
elif key == "BOARD_SECOND_OFFSET":
bootImgGenerator.setSecondOffset("0x" + value)
bootImgGenerator.setSecondOffset(value)
elif key == "BOARD_TAGS_OFFSET":
bootImgGenerator.setTagsOffset("0x" + value)
bootImgGenerator.setTagsOffset(value)
elif key == "BOARD_PAGE_SIZE":
bootImgGenerator.setPageSize(int(value))
elif key == "BOARD_SECOND_SIZE":
Expand Down

0 comments on commit 03ea715

Please sign in to comment.