示例#1
0
    def _generate_default_hash_segment(self, secboot_version):
        # Get the hash table
        hash_table = self.get_hash_table()

        # Create the header
        mbn_version = SECBOOT_MBN_HDR[secboot_version]
        mbn = ParseGenMbn(header_size=MbnHdr40B.get_size(),
                          version=mbn_version)
        mbn.code = hash_table
        header = mbn.header
        header.image_id = self.image_type
        image_dest_ptr = self._compute_hash_address(
            self._elf_parsegen) + MbnHdr40B.get_size()
        header.image_size = ALIGNED_IMAGE_SIZE(len(hash_table))
        header.code_size = len(hash_table)
        header.sig_ptr = image_dest_ptr + header.code_size
        header.sig_size = 0
        header.cert_chain_ptr = header.sig_ptr + header.sig_size
        header.cert_chain_size = 0
        mbn.invalidate_pointers = True
        if mbn_version == MBN_HDR_VERSION_3:
            header.flash_parti_ver = MBN_HDR_VERSION_3
            header.image_src = 0
            header.image_dest_ptr = image_dest_ptr
        elif mbn_version == MBN_HDR_VERSION_5:
            header.version = MBN_HDR_VERSION_5
            header.sig_size_qc = 0
            header.cert_chain_size_qc = 0
        else:
            raise RuntimeError('Unsupported MBN header version: ' +
                               str(mbn_version))

        return mbn.get_data()
示例#2
0
 def _generate_default_hash_segment(self):
     # Get the hash table
     hash_table = self.get_hash_table()
     
     # Create the header
     header = MbnHdr40B('\0' * MbnHdr40B.get_size())
     header.image_id = self.image_type
     header.flash_parti_ver = FLASH_PARTI_VERSION
     header.image_src = 0
     header.image_dest_ptr = self._compute_hash_address(self._elf_parsegen) + MbnHdr40B.get_size()
     header.image_size = ALIGNED_IMAGE_SIZE(len(hash_table))
     header.code_size = len(hash_table)
     header.sig_ptr = header.image_dest_ptr + header.code_size
     header.sig_size = 0
     header.cert_chain_ptr = header.sig_ptr + header.sig_size
     header.cert_chain_size = 0
     
     return header.pack() + hash_table
示例#3
0
    def _generate_default_hash_segment(self):
        # Get the hash table
        hash_table = self.get_hash_table()

        # Create the header
        mbn = ParseGenMbn(header_size=MbnHdr40B.get_size())
        mbn.code = hash_table
        header = mbn.header
        header.image_id = self.image_type
        header.flash_parti_ver = FLASH_PARTI_VERSION
        header.image_src = 0
        header.image_dest_ptr = self._compute_hash_address(self._elf_parsegen) + MbnHdr40B.get_size()
        header.image_size = ALIGNED_IMAGE_SIZE(len(hash_table))
        header.code_size = len(hash_table)
        header.sig_ptr = header.image_dest_ptr + header.code_size
        header.sig_size = 0
        header.cert_chain_ptr = header.sig_ptr + header.sig_size
        header.cert_chain_size = 0
        mbn.invalidate_pointers = True

        return mbn.get_data()
示例#4
0
    def generate(self, args):
        infile = open(args.input_file, "rb")
        infile_data = infile.read()
        infile.close()

        if self.is_mbn_file(infile_data, args.input_file) is not None:
            logger.warning(
                "WARNING! {0} appears to already have an MBN header!".format(
                    args.input_file))

        # sectools will update these values when it inputs the cert chain and sig
        # but in this feature just set them to zero
        code_size = ALIGNED_IMAGE_SIZE(os.path.getsize(args.input_file))
        signature_size = 0
        signature_ptr = 0
        cert_chain_ptr = 0
        cert_chain_size = 0
        image_size = code_size + signature_size + cert_chain_size

        header = None
        if args.header_length == 40:
            header = MbnHdr40B()
            header._unpack_data_list([
                args.image_id, args.header_version, args.image_src,
                args.image_dest_ptr, image_size, code_size, signature_ptr,
                signature_size, cert_chain_ptr, cert_chain_size
            ])

        elif args.header_length == 80:
            header = MbnHdr80B()
            # todo: verify magic and codeword are correct
            header._unpack_data_list([
                MBN_80_CODEWORD,  # codeword I pulled from given file
                MBN_80_MAGIC,  # magic I pulled from given file
                args.image_id,
                0xffffffff,
                0xffffffff,
                args.image_src,
                args.image_dest_ptr,
                image_size,
                code_size,
                signature_ptr,
                signature_size,
                cert_chain_ptr,
                cert_chain_size,
                0,  # this has a value of 1 in a file I was given. what does it mean?
                0,
                0,
                0,
                0,
                0,
                0
            ])
        else:
            raise RuntimeError(
                "received invalid MBN header length in generate. This should never happen"
            )

        outfile_name = os.path.basename(args.input_file) + ".mbn"
        if not c_path.validate_dir_write(args.output_dir):
            os.makedirs(args.output_dir)

        outfile = open(c_path.join(args.output_dir, outfile_name), "wb")
        outfile.write(header.pack())
        outfile.write(infile_data)
        outfile.close()
        infile.close()
        logger.info("output \"{0}\" has been successfully generated".format(
            c_path.join(args.output_dir, outfile_name)))