make building recovery and boot images optional
If the source target-files zip omits files needed to build the recovery and/or boot images, leave them out instead of dying with an error. This lets build like "generic-userdebug" work.
This commit is contained in:
@@ -63,18 +63,29 @@ def LoadBoardConfig(fn):
|
|||||||
def BuildAndAddBootableImage(sourcedir, targetname, output_zip):
|
def BuildAndAddBootableImage(sourcedir, targetname, output_zip):
|
||||||
"""Take a kernel, cmdline, and ramdisk directory from the input (in
|
"""Take a kernel, cmdline, and ramdisk directory from the input (in
|
||||||
'sourcedir'), and turn them into a boot image. Put the boot image
|
'sourcedir'), and turn them into a boot image. Put the boot image
|
||||||
into the output zip file under the name 'targetname'."""
|
into the output zip file under the name 'targetname'. Returns
|
||||||
|
targetname on success or None on failure (if sourcedir does not
|
||||||
|
appear to contain files for the requested image)."""
|
||||||
|
|
||||||
print "creating %s..." % (targetname,)
|
print "creating %s..." % (targetname,)
|
||||||
|
|
||||||
img = BuildBootableImage(sourcedir)
|
img = BuildBootableImage(sourcedir)
|
||||||
|
if img is None:
|
||||||
|
return None
|
||||||
|
|
||||||
CheckSize(img, targetname)
|
CheckSize(img, targetname)
|
||||||
ZipWriteStr(output_zip, targetname, img)
|
ZipWriteStr(output_zip, targetname, img)
|
||||||
|
return targetname
|
||||||
|
|
||||||
def BuildBootableImage(sourcedir):
|
def BuildBootableImage(sourcedir):
|
||||||
"""Take a kernel, cmdline, and ramdisk directory from the input (in
|
"""Take a kernel, cmdline, and ramdisk directory from the input (in
|
||||||
'sourcedir'), and turn them into a boot image. Return the image data."""
|
'sourcedir'), and turn them into a boot image. Return the image
|
||||||
|
data, or None if sourcedir does not appear to contains files for
|
||||||
|
building the requested image."""
|
||||||
|
|
||||||
|
if (not os.access(os.path.join(sourcedir, "RAMDISK"), os.F_OK) or
|
||||||
|
not os.access(os.path.join(sourcedir, "kernel"), os.F_OK)):
|
||||||
|
return None
|
||||||
|
|
||||||
ramdisk_img = tempfile.NamedTemporaryFile()
|
ramdisk_img = tempfile.NamedTemporaryFile()
|
||||||
img = tempfile.NamedTemporaryFile()
|
img = tempfile.NamedTemporaryFile()
|
||||||
@@ -89,15 +100,25 @@ def BuildBootableImage(sourcedir):
|
|||||||
assert p1.returncode == 0, "mkbootfs of %s ramdisk failed" % (targetname,)
|
assert p1.returncode == 0, "mkbootfs of %s ramdisk failed" % (targetname,)
|
||||||
assert p2.returncode == 0, "minigzip of %s ramdisk failed" % (targetname,)
|
assert p2.returncode == 0, "minigzip of %s ramdisk failed" % (targetname,)
|
||||||
|
|
||||||
cmdline = open(os.path.join(sourcedir, "cmdline")).read().rstrip("\n")
|
cmd = ["mkbootimg", "--kernel", os.path.join(sourcedir, "kernel")]
|
||||||
p = Run(["mkbootimg",
|
|
||||||
"--kernel", os.path.join(sourcedir, "kernel"),
|
fn = os.path.join(sourcedir, "cmdline")
|
||||||
"--cmdline", cmdline,
|
if os.access(fn, os.F_OK):
|
||||||
"--ramdisk", ramdisk_img.name,
|
cmd.append("--cmdline")
|
||||||
"--output", img.name],
|
cmd.append(open(fn).read().rstrip("\n"))
|
||||||
stdout=subprocess.PIPE)
|
|
||||||
|
fn = os.path.join(sourcedir, "base")
|
||||||
|
if os.access(fn, os.F_OK):
|
||||||
|
cmd.append("--base")
|
||||||
|
cmd.append(open(fn).read().rstrip("\n"))
|
||||||
|
|
||||||
|
cmd.extend(["--ramdisk", ramdisk_img.name,
|
||||||
|
"--output", img.name])
|
||||||
|
|
||||||
|
p = Run(cmd, stdout=subprocess.PIPE)
|
||||||
p.communicate()
|
p.communicate()
|
||||||
assert p.returncode == 0, "mkbootimg of %s image failed" % (targetname,)
|
assert p.returncode == 0, "mkbootimg of %s image failed" % (
|
||||||
|
os.path.basename(sourcedir),)
|
||||||
|
|
||||||
img.seek(os.SEEK_SET, 0)
|
img.seek(os.SEEK_SET, 0)
|
||||||
data = img.read()
|
data = img.read()
|
||||||
|
@@ -310,8 +310,12 @@ def WriteFullOTAPackage(input_zip, output_zip):
|
|||||||
|
|
||||||
script.ShowProgress(0.1, 0)
|
script.ShowProgress(0.1, 0)
|
||||||
|
|
||||||
common.ZipWriteStr(output_zip, "radio.img", input_zip.read("RADIO/image"))
|
try:
|
||||||
script.WriteFirmwareImage("radio", "radio.img")
|
common.ZipWriteStr(output_zip, "radio.img", input_zip.read("RADIO/image"))
|
||||||
|
script.WriteFirmwareImage("radio", "radio.img")
|
||||||
|
except KeyError:
|
||||||
|
print "warning: no radio image in input target_files; not flashing radio"
|
||||||
|
|
||||||
script.ShowProgress(0.5, 0)
|
script.ShowProgress(0.5, 0)
|
||||||
|
|
||||||
if OPTIONS.wipe_user_data:
|
if OPTIONS.wipe_user_data:
|
||||||
@@ -324,9 +328,10 @@ def WriteFullOTAPackage(input_zip, output_zip):
|
|||||||
symlinks = CopySystemFiles(input_zip, output_zip)
|
symlinks = CopySystemFiles(input_zip, output_zip)
|
||||||
script.MakeSymlinks(symlinks)
|
script.MakeSymlinks(symlinks)
|
||||||
|
|
||||||
common.BuildAndAddBootableImage(os.path.join(OPTIONS.input_tmp, "RECOVERY"),
|
if common.BuildAndAddBootableImage(
|
||||||
"system/recovery.img", output_zip)
|
os.path.join(OPTIONS.input_tmp, "RECOVERY"),
|
||||||
Item.Get("system/recovery.img", dir=False)
|
"system/recovery.img", output_zip):
|
||||||
|
Item.Get("system/recovery.img", dir=False)
|
||||||
|
|
||||||
FixPermissions(script)
|
FixPermissions(script)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user