Пример #1
0
    def configure(self, data_model):
        '''
        configures fuse/fields based on name/value
        '''
        if not self.entries:
            return

        encryption_key = None

        try:
            for entry in self.entries:
                if entry['name'] == self.encryption_key:
                    encryption_key = entry['value']
                elif entry['name'] == self.encryption_file:
                    encryption_file = entry['value']
                    encryption_key = get_keydata_from_file(encryption_file)

            if len(encryption_key) > 32:
                raise RuntimeError(
                    str(self.encryption_key) +
                    ' is more than 128 bits [ 32 chars], len = ' +
                    str(len(encryption_key)))

            encryption_key = int(encryption_key, 16)

            if encryption_key == 0:
                logger.debug2('encryption_key is all 0, skipping')
                return

            encryption_key_old = hex(encryption_key)[2:].rstrip('L').rjust(
                32, '0')
            encryption_key = ''
            for idx in range(len(encryption_key_old) / 2):
                encryption_key += encryption_key_old[-2:]
                encryption_key_old = encryption_key_old[:-2]
            encryption_key = int(encryption_key, 16)

            custkey_row0 = encryption_key & FEC_DATA_56BIT_MASK
            custkey_row1 = (encryption_key >> 56) & FEC_DATA_56BIT_MASK
            custkey_row2 = (encryption_key >> 112) & 0xFFFF

            # merge into data model
            set_field_value(data_model,
                            region_id=self.region_name,
                            field_id=self.row0,
                            value=custkey_row0)
            set_field_value(data_model,
                            region_id=self.region_name,
                            field_id=self.row1,
                            value=custkey_row1)
            set_field_value(data_model,
                            region_id=self.region_name,
                            field_id=self.row2,
                            value=custkey_row2)

            # Generate FEC bits
            row0 = generate_fec(data_model, region_id=self.region_name, row=0)
            row1 = generate_fec(data_model, region_id=self.region_name, row=1)
            row2 = generate_fec(data_model, region_id=self.region_name, row=2)

            # Lastly, set FEC_EN bit
            # some chipsets have the FEC_EN bit in the row instead of having FEC_EN region
            if self.chipset in FEC_IN_ROW:
                if int(row0, 16):
                    set_field_value(data_model,
                                    region_id=self.region_name,
                                    field_id='CUSTKEY1_ROW0_FEC_EN0',
                                    value=0x1)
                if int(row1, 16):
                    set_field_value(data_model,
                                    region_id=self.region_name,
                                    field_id='CUSTKEY1_ROW1_FEC_EN1',
                                    value=0x1)
                if int(row2, 16):
                    set_field_value(data_model,
                                    region_id=self.region_name,
                                    field_id='CUSTKEY1_ROW2_FEC_EN2',
                                    value=0x1)

            elif self.chipset in DIFF_FEC_REG:
                if self.row0 == 'CUSTKEY1_L1_ROW0':
                    if self.chipset in KP_FEC_REG:
                        # set FEC_EN region bit for SPARE 19, 20, 21 REGION
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION19_FEC_EN',
                                        value=0x1)
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION20_FEC_EN',
                                        value=0x1)
                    else:
                        # set FEC_EN region bit for SPARE 21, 22, 23 REGION
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION22_FEC_EN',
                                        value=0x1)
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION23_FEC_EN',
                                        value=0x1)

                    set_field_value(data_model,
                                    region_id='QFPROM_RAW_FEC_EN',
                                    field_id='REGION21_FEC_EN',
                                    value=0x1)

                else:
                    if self.chipset in KP_FEC_REG:
                        # set FEC_EN region bit for SPARE 22, 23, 24 REGION
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION22_FEC_EN',
                                        value=0x1)
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION23_FEC_EN',
                                        value=0x1)
                    else:
                        # set FEC_EN region bit for SPARE 24, 25, 26 REGION
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION25_FEC_EN',
                                        value=0x1)
                        set_field_value(data_model,
                                        region_id='QFPROM_RAW_FEC_EN',
                                        field_id='REGION26_FEC_EN',
                                        value=0x1)

                    set_field_value(data_model,
                                    region_id='QFPROM_RAW_FEC_EN',
                                    field_id='REGION24_FEC_EN',
                                    value=0x1)

            else:
                # set FEC_EN region bit for Region31 (CUST_KEY1 region)
                set_field_value(data_model,
                                region_id='QFPROM_RAW_FEC_EN',
                                field_id='REGION31_FEC_EN',
                                value=0x1)

        except Exception, e:
            raise RuntimeError(
                'Error from configure(): %s, error=%s' +
                self.__class__.__name__, str(e))
Пример #2
0
    def configure(self, data_model):
        '''
        configures fuse/fields based on name/value
        '''
        if not self.entries:
            return

        oem_image_encr_key = None

        try:
            for entry in self.entries:
                if entry['name'] == 'oem_image_encr_key':
                    oem_image_encr_key = entry['value']
                elif entry['name'] == 'oem_image_encr_key_file':
                    oem_image_encr_key_file = entry['value']
                    oem_image_encr_key = get_keydata_from_file(
                        oem_image_encr_key_file)

            if len(oem_image_encr_key) > 32:
                raise RuntimeError(
                    'oem_image_encr_key is more than 128 bits [ 32 chars], len = '
                    + str(len(oem_image_encr_key)))

            oem_image_encr_key = int(oem_image_encr_key, 16)

            if oem_image_encr_key == 0:
                logger.debug2('oem_image_encr_key is all 0, skipping')
                return

            oem_image_encr_key_old = hex(oem_image_encr_key)[2:].rstrip(
                'L').rjust(32, '0')
            oem_image_encr_key = ''
            for idx in range(len(oem_image_encr_key_old) / 2):
                oem_image_encr_key += oem_image_encr_key_old[-2:]
                oem_image_encr_key_old = oem_image_encr_key_old[:-2]
            oem_image_encr_key = int(oem_image_encr_key, 16)

            oem_imageencrkey_row0 = oem_image_encr_key & FEC_DATA_56BIT_MASK
            oem_imageencrkey_row1 = (
                oem_image_encr_key >> 56) & FEC_DATA_56BIT_MASK
            oem_imageencrkey_row2 = (oem_image_encr_key >> 112) & 0xFFFF

            # merge into data model
            set_field_value(data_model,
                            region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                            field_id='ENCR_KEY_ROW0',
                            value=oem_imageencrkey_row0)
            set_field_value(data_model,
                            region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                            field_id='ENCR_KEY_ROW1',
                            value=oem_imageencrkey_row1)
            set_field_value(data_model,
                            region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                            field_id='ENCR_KEY_ROW2',
                            value=oem_imageencrkey_row2)

            # Generate FEC bits
            row0 = generate_fec(data_model,
                                region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                                row=0)
            row1 = generate_fec(data_model,
                                region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                                row=1)
            row2 = generate_fec(data_model,
                                region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                                row=2)

            # Lastly, set FEC_EN bit
            # some chipsets have the FEC_EN bit in the row instead of having FEC_EN region
            if self.chipset in FEC_IN_ROW:
                if int(row0, 16):
                    set_field_value(data_model,
                                    region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                                    field_id='OEMIMAGEENCRKEY_ROW0_FEC_EN0',
                                    value=0x1)
                if int(row1, 16):
                    set_field_value(data_model,
                                    region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                                    field_id='OEMIMAGEENCRKEY_ROW1_FEC_EN1',
                                    value=0x1)
                if int(row2, 16):
                    set_field_value(data_model,
                                    region_id='QFPROM_RAW_OEM_IMAGE_ENCR_KEY',
                                    field_id='OEMIMAGEENCRKEY_ROW2_FEC_EN2',
                                    value=0x1)

            elif self.chipset == '8998':
                # set FEC_EN region bit for Region19 (OEM_IMAGE_ENCR_KEY region)
                set_field_value(data_model,
                                region_id='QFPROM_RAW_FEC_EN',
                                field_id='REGION19_FEC_EN',
                                value=0x1)

            else:
                # set FEC_EN region bit for Region23 (OEM_IMAGE_ENCR_KEY region)
                set_field_value(data_model,
                                region_id='QFPROM_RAW_FEC_EN',
                                field_id='REGION23_FEC_EN',
                                value=0x1)

        except Exception, e:
            raise RuntimeError(
                'Error from configure(): %s, error=%s' +
                self.__class__.__name__, str(e))