def make(self, workDir, outDir): recoveryImg = self.getMakeProperty("img") with self.newTmpWorkDir() as recoveryExtractDir: with self.newTmpWorkDir() as recoveryRamdiskDir: workRamdiskDir = os.path.join(recoveryRamdiskDir, "ramdisk") if type(recoveryImg.getValue()) is str: _, unpacker = self.getHostBinary("unpackbootimg") bootImgGenerator = imgtools.unpackimg( unpacker, recoveryImg.resolveAsRelativePath(), recoveryExtractDir ) shutil.copytree( os.path.join(recoveryExtractDir, bootImgGenerator.getRamdisk()), workRamdiskDir, symlinks=True ) imgType = "recovery" self.setValue("recovery.img", {}) self.setValue("%s.img.cmdline" % imgType, bootImgGenerator.getKernelCmdLine(quote=False)) self.setValue("%s.img.base" % imgType, bootImgGenerator.getBaseAddr()) self.setValue("%s.img.ramdisk_offset" % imgType, bootImgGenerator.getRamdiskOffset()) self.setValue("%s.img.second_offset" % imgType, bootImgGenerator.getSecondOffset()) self.setValue("%s.img.tags_offset" % imgType, bootImgGenerator.getTagsOffset()) self.setValue("%s.img.pagesize" % imgType, bootImgGenerator.getPageSize()) self.setValue("%s.img.second_size" % imgType, bootImgGenerator.getSecondSize()) self.setValue("%s.img.dt_size" % imgType, bootImgGenerator.getDeviceTreeSize()) self.setValue("%s.img.kernel" % imgType, bootImgGenerator.getKernel()) self.setValue("%s.img.dt" % imgType, bootImgGenerator.getDeviceTree()) else: shutil.copytree( self.getMakeProperty("img.ramdisk").resolveAsRelativePath(), workRamdiskDir, symlinks=True ) self.setValue("recovery.img.ramdisk", workRamdiskDir) if self.getMakeValue("inject_keys", True): if not self.injectKeys(workRamdiskDir): logger.warning("key already exists in %s, not injecting" % self.__class__.PATH_KEYS) else: logger.debug("injected key in %s" % self.__class__.PATH_KEYS) self.injectBusyBox(workRamdiskDir) fstabPath = os.path.join(workRamdiskDir, "etc", "fstab") fstab = Fstab.parseFstab(os.path.join(workRamdiskDir, "etc", "recovery.fstab")) diffMounts = ConfigSyncer.diffMounts(self.getConfig(), fstab) for k, v in diffMounts.items(): self.getConfig().setRecursive(k, v) if not os.path.exists(fstabPath): self.injectFstab(fstab, workRamdiskDir) result = super(RecoveryImageMaker, self).make(workDir, outDir) self.setValue("recovery.img", recoveryImg.getValue()) return result
def make(self, workDir, outDir): recoveryImg = self.getMakeProperty("img") with self.newTmpWorkDir() as recoveryExtractDir: with self.newTmpWorkDir() as recoveryRamdiskDir: workRamdiskDir = os.path.join(recoveryRamdiskDir, "ramdisk") if type(recoveryImg.getValue()) is str: _, unpacker = self.getHostBinary("unpackbootimg") bootImgGenerator = imgtools.unpackimg(unpacker, recoveryImg.resolveAsRelativePath(), recoveryExtractDir) shutil.copytree(os.path.join(recoveryExtractDir, bootImgGenerator.getRamdisk()), workRamdiskDir, symlinks=True) imgType = "recovery" self.setValue("recovery.img", {}) self.setValue("%s.img.cmdline" % imgType, bootImgGenerator.getKernelCmdLine(quote=False)) self.setValue("%s.img.base" % imgType, bootImgGenerator.getBaseAddr()) self.setValue("%s.img.ramdisk_offset" % imgType, bootImgGenerator.getRamdiskOffset()) self.setValue("%s.img.second_offset" % imgType, bootImgGenerator.getSecondOffset()) self.setValue("%s.img.tags_offset" % imgType, bootImgGenerator.getTagsOffset()) self.setValue("%s.img.pagesize" % imgType, bootImgGenerator.getPageSize()) self.setValue("%s.img.second_size" % imgType, bootImgGenerator.getSecondSize()) self.setValue("%s.img.dt_size" % imgType, bootImgGenerator.getDeviceTreeSize()) self.setValue("%s.img.kernel" % imgType, bootImgGenerator.getKernel()) self.setValue("%s.img.dt" % imgType, bootImgGenerator.getDeviceTree()) else: shutil.copytree(self.getMakeProperty("img.ramdisk").resolveAsRelativePath(), workRamdiskDir, symlinks=True) self.setValue("recovery.img.ramdisk", workRamdiskDir) if self.getMakeValue("inject_keys", True): if not self.injectKeys(workRamdiskDir): logger.warning("key already exists in %s, not injecting" % self.__class__.PATH_KEYS) else: logger.debug("injected key in %s" % self.__class__.PATH_KEYS) self.injectBusyBox(workRamdiskDir) fstabPath = os.path.join(workRamdiskDir, "etc", "fstab") fstab = Fstab.parseFstab(os.path.join(workRamdiskDir, "etc", "recovery.fstab")) diffMounts = ConfigSyncer.diffMounts(self.getConfig(), fstab) for k, v in diffMounts.items(): self.getConfig().setRecursive(k, v) if not os.path.exists(fstabPath): self.injectFstab(fstab, workRamdiskDir) result = super(RecoveryImageMaker, self).make(workDir, outDir) self.setValue("recovery.img", recoveryImg.getValue()) return result
def make(self, workDir, outDir): recoveryImg = self.getMakeProperty("img") preprocessed = self.getMakeValue("preprocessed", False) with self.newTmpWorkDir() as recoveryExtractDir: with self.newTmpWorkDir() as recoveryRamdiskDir: workRamdiskDir = os.path.join(recoveryRamdiskDir, "ramdisk") if type(recoveryImg.getValue()) is str: if preprocessed: return super(RecoveryImageMaker, self).make(workDir, outDir) unpackerName = self.getMakeValue("unpacker", "unpackbootimg") assert unpackerName in ("unpackbootimg", "unmkbootimg") _, unpacker = self.getHostBinary(unpackerName) bootImgGenerator = imgtools.unpackimg( unpacker, recoveryImg.resolveAsRelativePath(), recoveryExtractDir, mode=imgtools.MODE_UNMKBOOTIMG if unpackerName == "unmkbootimg" else imgtools.MODE_UNPACKBOOTIMG) shutil.copytree(os.path.join( recoveryExtractDir, bootImgGenerator.getRamdisk()), workRamdiskDir, symlinks=True) imgType = "recovery" self.setValue("recovery.img", {}) self.setValue( "%s.img.cmdline" % imgType, bootImgGenerator.getKernelCmdLine(quote=False)) self.setValue("%s.img.base" % imgType, bootImgGenerator.getBaseAddr()) self.setValue("%s.img.ramdisk_offset" % imgType, bootImgGenerator.getRamdiskOffset()) self.setValue("%s.img.second_offset" % imgType, bootImgGenerator.getSecondOffset()) self.setValue("%s.img.tags_offset" % imgType, bootImgGenerator.getTagsOffset()) self.setValue("%s.img.pagesize" % imgType, bootImgGenerator.getPageSize()) self.setValue("%s.img.second_size" % imgType, bootImgGenerator.getSecondSize()) self.setValue("%s.img.dt_size" % imgType, bootImgGenerator.getDeviceTreeSize()) self.setValue("%s.img.kernel" % imgType, bootImgGenerator.getKernel()) self.setValue("%s.img.dt" % imgType, bootImgGenerator.getDeviceTree()) self.setValue("%s.img.kernel_offset" % imgType, bootImgGenerator.getKernelOffset()) else: shutil.copytree(self.getMakeProperty( "img.ramdisk").resolveAsRelativePath(), workRamdiskDir, symlinks=True) self.setValue("recovery.img.ramdisk", workRamdiskDir) if not preprocessed: if self.getMakeValue("inject_keys", True): if not self.injectKeys(workRamdiskDir): logger.warning( "key already exists in %s, not injecting" % self.__class__.PATH_KEYS) else: logger.debug("injected key in %s" % self.__class__.PATH_KEYS) self.injectBusyBox(workRamdiskDir) self.readProps(workRamdiskDir) self.overrideDmVerityHash(workRamdiskDir) fstabPath = os.path.join(workRamdiskDir, "etc", "fstab") fstab = None for fstabname in RecoveryImageMaker.FSTABS: fstabpathcheck = os.path.join(workRamdiskDir, "etc", fstabname) if os.path.exists(fstabpathcheck): fstab = Fstab.parseFstab(fstabpathcheck) break if fstab is None: raise ValueError("Couldn't parse any of /etc/{%s}" % (",".join(RecoveryImageMaker.FSTABS))) diffMounts = ConfigSyncer.diffMounts( self.getConfig(), fstab) for k, v in diffMounts.items(): self.getConfig().setRecursive(k, v) if not os.path.exists(fstabPath) and self.getMakeValue( "inject_fstab", True): self.injectFstab(fstab, workRamdiskDir) result = super(RecoveryImageMaker, self).make(workDir, outDir) self.setValue("recovery.img", recoveryImg.getValue()) return result