示例#1
0
    def _generate_config_file(self):
        if self.input.sign_id.lower().endswith("ewm"):
            logger.debug(
                "Generating new config files with provided values for relocatable and image_entry..."
            )
            new_config_file = c_path.join(self.input.target_base_dir,
                                          "generated_config.xml")
            config = ConfigParser(self.input.config)

            image_type_list = config.root.parsegen.get_image_types_list()
            for image_type in image_type_list.get_image_type():
                if image_type.id == EWM_TYPE:
                    if self.input.relocatable is not None:
                        # Override relocatable setting
                        image_type.ewm_properties.relocatable = self.input.relocatable
                        logger.debug(
                            "Overrode config's relocatable value with {0}".
                            format(self.input.relocatable))
                    if self.input.image_entry is not None:
                        # Override image_entry
                        image_type.ewm_properties.image_entry = self.input.image_entry
                        logger.debug(
                            "Overrode config's image_entry value with {0}".
                            format(self.input.image_entry))

            config.generate(new_config_file)
            self.input.config = new_config_file
            logger.debug(
                "New config file generated at \"{0}\"".format(new_config_file))
示例#2
0
    def __init__(self, meta_build_path, config_dir_obj):
        assert isinstance(meta_build_path, str)
        assert isinstance(config_dir_obj, ConfigDir)

        # Initialize the BaseStager
        BaseStager.__init__(self)

        # Create internal attributes
        self._meta_build_path = meta_build_path

        # Validate that the meta_build path exists
        meta_build_path = c_path.normalize(meta_build_path)
        if not c_path.validate_dir(meta_build_path):
            raise RuntimeError('No read access to the meta build path: ' +
                               meta_build_path)

        # Get the meta lib module from the metabuild
        meta_info = self.get_meta_info(meta_build_path)

        # Create the image info list based on the meta data
        for sign_id, chipset, image_src_path, image_dest_path in self.get_image_info_from_meta(
                meta_info):
            try:
                img_config_parser = ConfigParser(
                    config_dir_obj.get_chipset_config_path(chipset))

                # Validate the sign_id
                sign_id = self._get_sign_id(
                    img_config_parser,
                    os.path.basename(image_src_path.image_path), sign_id)

                # Get the config block for the sign id
                img_config_block = img_config_parser.get_config_for_sign_id(
                    sign_id)

                # Create the one image info object
                image_info = ImageInfo('', sign_id, img_config_block,
                                       img_config_parser)

                # Set the src path
                image_info.src_image = image_src_path
                image_info.image_under_operation = image_info.src_image.image_path

                # Set the dest path
                image_info.dest_image = image_dest_path

                # Put the image info object into the list
                self._image_info_list.append(image_info)

            except Exception as e:
                logger.error(str(e))
    def _generate_config_file(self, src_config, dest_config, image_entry,
                              relocatable):
        config = ConfigParser(src_config)

        image_type_list = config.root.parsegen.get_image_types_list()
        for image_type in image_type_list.get_image_type():
            if image_type.id == EWM_TYPE:
                #Override relocatable setting
                image_type.ewm_properties.relocatable = relocatable
                if image_entry is not None:
                    #Override image_entry
                    image_type.ewm_properties.image_entry = image_entry

        config.generate(dest_config)
    def _generate_config_file(self, src_config, dest_config,
                              image_entry, relocatable):
        config = ConfigParser(src_config)

        image_type_list = config.root.parsegen.get_image_types_list()
        for image_type in image_type_list.get_image_type():
            if image_type.id == "elf_wrapped_mbn":
                #Override relocatable setting
                image_type.ewm_properties.relocatable = relocatable
                if image_entry is not None:
                    #Override image_entry
                    image_type.ewm_properties.image_entry = image_entry

        config.generate(dest_config)
    def _execute_install(self, policy):
        logger.debug("\nInstalling Sectools's output file...")
        if self.input.sectools_install_base_dir:
            path, filename = os.path.split(self.input.source)
            chipset = ConfigParser(
                self.input.config).root.metadata.get_chipset()
            src = c_path.normalize(
                c_path.join(self.input.target_base_dir, policy.id, chipset,
                            self.input.sign_id, filename))
            for install_location in policy.install_locations:
                if self.input.install_file_name:
                    dest = c_path.join(install_location,
                                       self.input.install_file_name)
                else:
                    dest = c_path.join(install_location, filename)

                # Attempt installation 3 times before failing
                installation_successful = False
                for i in range(3):
                    try:
                        c_path.create_dir(install_location)
                        copy_successful, error = c_path.copyFile(
                            src, dest, None, True)
                        if not copy_successful:
                            continue
                    except:
                        # Installation failed so retry installation
                        continue
                    installation_successful = True
                    logger.info("Installed \"{0}\" to \"{1}\"".format(
                        src, dest))
                    break
                if not installation_successful:
                    error_message = "Failed to install \"{0}\" to \"{1}\"".format(
                        src, dest)
                    logger.error(error_message)
                    raise RuntimeError(error_message)

                # pilsplit sectools's output file
                pilsplit_subdirectory = ""
                if install_location != self.input.sectools_install_base_dir:
                    pilsplit_subdirectory = install_location.replace(
                        os.path.join(self.input.sectools_install_base_dir, "",
                                     ""), "")
                pilsplit_prefix = self.input.install_file_name.split(
                    "."
                )[0] if self.input.install_file_name else filename.split(
                    ".")[0]
                self._execute_pilsplit(dest, pilsplit_prefix,
                                       pilsplit_subdirectory)
        else:
            logger.info(
                "Installation was skipped because a value for sectools_install_base_dir was not provided"
            )
            if self.input.pilsplitter_target_base_dir:
                logger.info(
                    "Pilsplitting was skipped because a value for sectools_install_base_dir was not provided"
                )
示例#6
0
    def generate_config_file(self, src_config, dest_config, args):
        config = ConfigParser(src_config)

        if args.cass is True:
            config.root.general_properties.selected_signer = 'cass'

            if args.capability:
                config.root.general_properties.cass_capability = args.capability

            #Enable test interface
            server_config = self._get_server()
            if server_config is not None:
                config.root.signing.signer_attributes.\
                    cass_signer_attributes.server = server_config
            user_identity = self._get_user_identity()
            if user_identity is not None:
                config.root.signing.signer_attributes.\
                    cass_signer_attributes.user_identity = user_identity

        sign_id = self._get_sign_id()

        image_list = config._get_image_list()
        for image in image_list:
            if image.sign_id == sign_id:
                break
        else:
            raise RuntimeError('sign_id: ' + sign_id +
                               ' not found in config file')

        image.general_properties_overrides.testsig_serialnum = self.serialnum.str if self.serialnum is not None else None
        if args.tcg_min:
            image.general_properties_overrides.object_id.min = args.tcg_min
        if args.tcg_max:
            image.general_properties_overrides.object_id.max = args.tcg_max
        if args.tcg_fix:
            image.general_properties_overrides.object_id.min = args.tcg_fix
            image.general_properties_overrides.object_id.max = args.tcg_fix

        config.generate(dest_config)
示例#7
0
    def set_config_path(self, config_path, overrides=None):
        # Log if the config_path is changed
        try:
            selected_config_path = self.config_path
            if selected_config_path:
                logger.note('Switching config_path: ' + '\n'
                            '    ' + 'from: ' + selected_config_path + '\n'
                            '    ' + ' to: ' + config_path)
        except Exception:
            pass

        # Update the config_path
        self._img_config_parser = ConfigParser(config_path, overrides)
        logger.info('Config path is set to: ' + config_path)

        # Reset the stager at this point
        if self._stager is not None:
            logger.note('Resetting image list due to config path change.')
            self._stager = None
示例#8
0
 def get_image_config_parser(self, chipset):
     return ConfigParser(
         self.config_dir_obj.get_chipset_config_path(chipset))
def get_scons_targets(input):
    # initialize target lists
    integrity_targets = list()
    sign_targets = list()
    encrypt_targets = list()
    sign_and_encrypt_targets = list()
    scons_targets = [
        integrity_targets, sign_targets, encrypt_targets,
        sign_and_encrypt_targets
    ]
    pilsplit_files_to_clean = list()
    # get chipset and filename of input file
    chipset = ConfigParser(input.config).root.metadata.get_chipset()
    path, filename = os.path.split(input.source)
    if input.build_policy:
        for policy in input.build_policy.sec_image_policies:
            target_list_to_append_to = scons_targets[target_map[
                policy.cmd_options]]
            # get path to installed image
            if input.sectools_install_base_dir:
                for install_location in policy.install_locations:
                    if input.install_file_name:
                        target = c_path.join(install_location,
                                             input.install_file_name)
                    else:
                        target = c_path.join(install_location, filename)
                    logger.debug(
                        "Added to-be-installed file \"{0}\" to SCons target list"
                        .format(target))
                    target_list_to_append_to.append(target)
                    # determine pilsplit images to cleanup
                    if input.pilsplitter_target_base_dir:
                        if install_location != input.sectools_install_base_dir:
                            pilsplit_directory = c_path.join(
                                input.pilsplitter_target_base_dir,
                                install_location.replace(
                                    os.path.join(
                                        input.sectools_install_base_dir, "",
                                        ""), ""))
                        else:
                            pilsplit_directory = input.pilsplitter_target_base_dir
                        if c_path.validate_dir_write(pilsplit_directory):
                            pilsplit_filename = input.install_file_name.split(
                                "."
                            )[0] if input.install_file_name else filename.split(
                                ".")[0]
                            # get all pil files in pilsplit target directory
                            regex = r"^" + re.escape(
                                pilsplit_filename
                            ) + r"\.((mdt)|(b[0-9][0-9]))$"
                            pil_files = [
                                c_path.join(pilsplit_directory, f)
                                for f in os.listdir(pilsplit_directory)
                                if re.match(regex, f)
                            ]
                            for pil_file in pil_files:
                                logger.debug(
                                    "Added pilsplit file \"{0}\" to SCons clean list"
                                    .format(pil_file))
                                pilsplit_files_to_clean.append(pil_file)
            # get path to uninstalled image if no installation is requested
            else:
                uninstalled_target = c_path.normalize(
                    c_path.join(input.target_base_dir, policy.id, chipset,
                                input.sign_id, filename))
                target_list_to_append_to.append(uninstalled_target)
                logger.debug("Added file \"{0}\" to SCons target list".format(
                    uninstalled_target))
    # remove duplicates from lists
    for i, targets in enumerate(scons_targets):
        scons_targets[i] = remove_duplicates(targets)
    pilsplit_files_to_clean = remove_duplicates(pilsplit_files_to_clean)
    # clean pilsplit files
    input.environment.Clean(scons_targets, pilsplit_files_to_clean)
    # return target list
    return scons_targets