Esempio n. 1
0
    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.pagesize" % imgType, bootImgGenerator.getPageSize())
        self.newConfig.set("%s.img.second_size" % imgType, bootImgGenerator.getSecondSize())
        self.newConfig.set("%s.img.dt_size" % imgType, bootImgGenerator.getDeviceTreeSize())
        self.newConfig.set("%s.img.kernel" % imgType, os.path.relpath(bootImgGenerator.getKernel(), self.variantDir))
        self.newConfig.set("%s.img.ramdisk" % imgType, os.path.relpath(bootImgGenerator.getRamdisk(), self.variantDir))
        self.newConfig.set("%s.img.dt" % imgType, os.path.relpath(bootImgGenerator.getDeviceTree(), self.variantDir))

        fstab = Fstab.parseFstab(os.path.join(out, bootImgGenerator.getRamdisk(), "etc", "recovery.fstab"))

        processParts = ("boot", "system", "recovery", "cache")

        for p in processParts:
            fstabPart = fstab.getByMountPoint("/" + p)
            key = "__config__.target.mount.%s." % p
            if self.newConfig.get(key + "dev") != fstabPart.getDevice():
                self.newConfig.set(key + "dev", fstabPart.getDevice())

            if self.newConfig.get(key + "mount") != fstabPart.getMountPoint():
                self.newConfig.set(key + "mount", fstabPart.getMountPoint())

            if self.newConfig.get(key + "fs") != fstabPart.getType():
                self.newConfig.set(key + "fs", fstabPart.getType())
    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
Esempio n. 4
0
    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.pagesize" % imgType,
                           bootImgGenerator.getPageSize())
        self.newConfig.set("%s.img.second_size" % imgType,
                           bootImgGenerator.getSecondSize())
        self.newConfig.set("%s.img.dt_size" % imgType,
                           bootImgGenerator.getDeviceTreeSize())
        self.newConfig.set(
            "%s.img.kernel" % imgType,
            os.path.relpath(bootImgGenerator.getKernel(), self.variantDir))
        self.newConfig.set(
            "%s.img.ramdisk" % imgType,
            os.path.relpath(bootImgGenerator.getRamdisk(), self.variantDir))
        self.newConfig.set(
            "%s.img.dt" % imgType,
            os.path.relpath(bootImgGenerator.getDeviceTree(), self.variantDir))

        fstab = Fstab.parseFstab(
            os.path.join(out, bootImgGenerator.getRamdisk(), "etc",
                         "recovery.fstab"))

        processParts = ("boot", "system", "recovery", "cache")

        for p in processParts:
            fstabPart = fstab.getByMountPoint("/" + p)
            key = "__config__.target.mount.%s." % p
            if self.newConfig.get(key + "dev") != fstabPart.getDevice():
                self.newConfig.set(key + "dev", fstabPart.getDevice())

            if self.newConfig.get(key + "mount") != fstabPart.getMountPoint():
                self.newConfig.set(key + "mount", fstabPart.getMountPoint())

            if self.newConfig.get(key + "fs") != fstabPart.getType():
                self.newConfig.set(key + "fs", fstabPart.getType())
Esempio n. 5
0
    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
Esempio n. 6
0
    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.pagesize" % imgType,
                           bootImgGenerator.getPageSize())
        self.newConfig.set("%s.img.second_size" % imgType,
                           bootImgGenerator.getSecondSize())
        self.newConfig.set("%s.img.dt_size" % imgType,
                           bootImgGenerator.getDeviceTreeSize())
        self.newConfig.set(
            "%s.img.kernel" % imgType,
            os.path.relpath(bootImgGenerator.getKernel(), self.variantDir))
        self.newConfig.set(
            "%s.img.ramdisk" % imgType,
            os.path.relpath(bootImgGenerator.getRamdisk(), self.variantDir))
        self.newConfig.set(
            "%s.img.dt" % imgType,
            os.path.relpath(bootImgGenerator.getDeviceTree(), self.variantDir))

        etcPath = os.path.join(out, bootImgGenerator.getRamdisk(), "etc")
        fstabFilename = None
        if os.path.exists(etcPath):
            for f in os.listdir(etcPath):
                if f.endswith("fstab"):
                    fstabFilename = f

            if fstabFilename is None:
                raise ValueError("Couldn't locate fstab")

            fstab = Fstab.parseFstab(os.path.join(etcPath, fstabFilename))

            processParts = ("boot", "kernel", "system", "recovery", "cache")

            for p in processParts:
                fstabPart = fstab.getByMountPoint("/" + p)
                if not fstabPart:
                    continue
                key = "__config__.target.mount.%s." % p
                if self.newConfig.get(key + "dev") != fstabPart.getDevice():
                    self.newConfig.set(key + "dev", fstabPart.getDevice())

                if self.newConfig.get(key +
                                      "mount") != fstabPart.getMountPoint():
                    self.newConfig.set(key + "mount",
                                       fstabPart.getMountPoint())

                if self.newConfig.get(key + "fs") != fstabPart.getType():
                    self.newConfig.set(key + "fs", fstabPart.getType())

        defaultProp = DefaultPropFile(
            os.path.join(out, bootImgGenerator.getRamdisk(), "default.prop"))

        if defaultProp.getArch():
            self.newConfig.setTargetConfigValue("arch",
                                                defaultProp.getArch(),
                                                diffOnly=True)

        if defaultProp.getProductManufacturer():
            self.newConfig.setTargetConfigValue(
                "device.manufacturer",
                defaultProp.getProductManufacturer(),
                diffOnly=True)

        if defaultProp.getProductBrand():
            self.newConfig.setTargetConfigValue("device.brand",
                                                defaultProp.getProductBrand(),
                                                diffOnly=True)

        if defaultProp.getProductBoard():
            self.newConfig.setTargetConfigValue("device.board",
                                                defaultProp.getProductBoard(),
                                                diffOnly=True)

        if defaultProp.getProductDevice():
            self.newConfig.setTargetConfigValue("device.name",
                                                defaultProp.getProductDevice(),
                                                diffOnly=True)