Пример #1
0
    def _GetPcd(self, Type):
        Pcds = sdict()
        #
        # tdict is a special kind of dict, used for selecting correct
        # PCD declaration for given ARCH
        #
        PcdDict = tdict(True, 3)
        # for summarizing PCD
        PcdSet = []
        # find out all PCDs of the 'type'

        StrPcdSet = []
        RecordList = self._RawData[Type, self._Arch]
        for TokenSpaceGuid, PcdCName, Setting, Arch, PrivateFlag, Dummy1, Dummy2 in RecordList:
            PcdDict[Arch, PcdCName, TokenSpaceGuid] = (Setting, Dummy2)
            if not (PcdCName, TokenSpaceGuid) in PcdSet:
                PcdSet.append((PcdCName, TokenSpaceGuid))

        for PcdCName, TokenSpaceGuid in PcdSet:
            #
            # limit the ARCH to self._Arch, if no self._Arch found, tdict
            # will automatically turn to 'common' ARCH and try again
            #
            Setting, LineNo = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]
            if Setting == None:
                continue

            DefaultValue, DatumType, TokenNumber = AnalyzePcdData(Setting)
            if DatumType not in [
                    TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID,
                    "BOOLEAN"
            ]:
                StructPattern = re.compile(r'[_a-zA-Z][0-9A-Za-z_]*$')
                if StructPattern.match(DatumType) == None:
                    EdkLogger.error(
                        'build',
                        FORMAT_INVALID,
                        "DatumType only support BOOLEAN, UINT8, UINT16, UINT32, UINT64, VOID* or a valid struct name.",
                        File=self.MetaFile,
                        Line=LineNo)

            validateranges, validlists, expressions = self._RawData.GetValidExpression(
                TokenSpaceGuid, PcdCName)
            PcdObj = PcdClassObject(PcdCName, TokenSpaceGuid,
                                    self._PCD_TYPE_STRING_[Type], DatumType,
                                    DefaultValue, TokenNumber, '', {},
                                    False, None, list(validateranges),
                                    list(validlists), list(expressions))
            if "." in TokenSpaceGuid:
                StrPcdSet.append((PcdObj, LineNo))
            else:
                Pcds[PcdCName, TokenSpaceGuid,
                     self._PCD_TYPE_STRING_[Type]] = PcdObj

        StructurePcds = self.ProcessStructurePcd(StrPcdSet)
        for pcd in StructurePcds:
            Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName,
                 self._PCD_TYPE_STRING_[Type]] = pcd

        return Pcds
Пример #2
0
    def _GetPcd(self, Type):
        Pcds = sdict()
        #
        # tdict is a special kind of dict, used for selecting correct
        # PCD declaration for given ARCH
        #
        PcdDict = tdict(True, 3)
        # for summarizing PCD
        PcdSet = []
        # find out all PCDs of the 'type'

        StrPcdSet = []
        RecordList = self._RawData[Type, self._Arch]
        for TokenSpaceGuid, PcdCName, Setting, Arch, PrivateFlag, Dummy1, Dummy2 in RecordList:
            PcdDict[Arch, PcdCName, TokenSpaceGuid] = (Setting,Dummy2)
            if not (PcdCName, TokenSpaceGuid) in PcdSet:
                PcdSet.append((PcdCName, TokenSpaceGuid))

        for PcdCName, TokenSpaceGuid in PcdSet:
            #
            # limit the ARCH to self._Arch, if no self._Arch found, tdict
            # will automatically turn to 'common' ARCH and try again
            #
            Setting,LineNo = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]
            if Setting == None:
                continue

            DefaultValue, DatumType, TokenNumber = AnalyzePcdData(Setting)
            validateranges, validlists, expressions = self._RawData.GetValidExpression(TokenSpaceGuid, PcdCName)
            PcdObj = PcdClassObject(
                                        PcdCName,
                                        TokenSpaceGuid,
                                        self._PCD_TYPE_STRING_[Type],
                                        DatumType,
                                        DefaultValue,
                                        TokenNumber,
                                        '',
                                        {},
                                        False,
                                        None,
                                        list(validateranges),
                                        list(validlists),
                                        list(expressions)
                                        )
            if "." in TokenSpaceGuid:
                StrPcdSet.append((PcdObj,LineNo))
            else:
                Pcds[PcdCName, TokenSpaceGuid, self._PCD_TYPE_STRING_[Type]] = PcdObj

        StructurePcds = self.ProcessStructurePcd(StrPcdSet)
        for pcd in StructurePcds:
            Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName, self._PCD_TYPE_STRING_[Type]] = pcd

        return Pcds
Пример #3
0
    def _GetPcd(self, Type):
        Pcds = OrderedDict()
        #
        # tdict is a special kind of dict, used for selecting correct
        # PCD declaration for given ARCH
        #
        PcdDict = tdict(True, 3)
        # for summarizing PCD
        PcdSet = []
        # find out all PCDs of the 'type'

        StrPcdSet = []
        RecordList = self._RawData[Type, self._Arch]
        for TokenSpaceGuid, PcdCName, Setting, Arch, PrivateFlag, Dummy1, Dummy2 in RecordList:
            PcdDict[Arch, PcdCName, TokenSpaceGuid] = (Setting, Dummy2)
            if not (PcdCName, TokenSpaceGuid) in PcdSet:
                PcdSet.append((PcdCName, TokenSpaceGuid))

        DefinitionPosition = {}
        for PcdCName, TokenSpaceGuid in PcdSet:
            #
            # limit the ARCH to self._Arch, if no self._Arch found, tdict
            # will automatically turn to 'common' ARCH and try again
            #
            Setting, LineNo = PcdDict[self._Arch, PcdCName, TokenSpaceGuid]
            if Setting is None:
                continue

            DefaultValue, DatumType, TokenNumber = AnalyzePcdData(Setting)
            validateranges, validlists, expressions = self._RawData.GetValidExpression(
                TokenSpaceGuid, PcdCName)
            PcdObj = PcdClassObject(PcdCName, TokenSpaceGuid,
                                    self._PCD_TYPE_STRING_[Type], DatumType,
                                    DefaultValue, TokenNumber, '', {},
                                    False, None, list(validateranges),
                                    list(validlists), list(expressions))
            DefinitionPosition[PcdObj] = (self.MetaFile.File, LineNo)
            if "." in TokenSpaceGuid:
                StrPcdSet.append((PcdObj, LineNo))
            else:
                Pcds[PcdCName, TokenSpaceGuid,
                     self._PCD_TYPE_STRING_[Type]] = PcdObj

        StructurePcds = self.ProcessStructurePcd(StrPcdSet)
        for pcd in StructurePcds:
            Pcds[pcd.TokenCName, pcd.TokenSpaceGuidCName,
                 self._PCD_TYPE_STRING_[Type]] = pcd
        StructPattern = compile(r'[_a-zA-Z][0-9A-Za-z_]*$')
        for pcd in Pcds.values():
            if pcd.DatumType not in [
                    TAB_UINT8, TAB_UINT16, TAB_UINT32, TAB_UINT64, TAB_VOID,
                    "BOOLEAN"
            ]:
                if not pcd.IsAggregateDatumType():
                    EdkLogger.error(
                        'build', FORMAT_INVALID,
                        "DatumType only support BOOLEAN, UINT8, UINT16, UINT32, UINT64, VOID* or a valid struct name.",
                        DefinitionPosition[pcd][0], DefinitionPosition[pcd][1])
                elif not pcd.IsArray() and not pcd.StructuredPcdIncludeFile:
                    EdkLogger.error(
                        "build", PCD_STRUCTURE_PCD_ERROR,
                        "The structure Pcd %s.%s header file is not found in %s line %s \n"
                        %
                        (pcd.TokenSpaceGuidCName, pcd.TokenCName,
                         pcd.DefinitionPosition[0], pcd.DefinitionPosition[1]))
        return Pcds
Пример #4
0
    def _GetPcd(self, Type):
        Pcds = OrderedDict()
        PcdDict = tdict(True, 4)
        PcdList = []
        RecordList = self._RawData[Type, self._Arch, self._Platform]
        for TokenSpaceGuid, PcdCName, Setting, Arch, Platform, Id, LineNo in RecordList:
            PcdDict[Arch, Platform, PcdCName,
                    TokenSpaceGuid] = (Setting, LineNo)
            PcdList.append((PcdCName, TokenSpaceGuid))
            # get the guid value
            if TokenSpaceGuid not in self.Guids:
                Value = GuidValue(TokenSpaceGuid, self.Packages,
                                  self.MetaFile.Path)
                if Value is None:
                    PackageList = "\n\t".join(str(P) for P in self.Packages)
                    EdkLogger.error(
                        'build',
                        RESOURCE_NOT_AVAILABLE,
                        "Value of Guid [%s] is not found under [Guids] section in"
                        % TokenSpaceGuid,
                        ExtraData=PackageList,
                        File=self.MetaFile,
                        Line=LineNo)
                self.Guids[TokenSpaceGuid] = Value
                self._GuidsUsedByPcd[TokenSpaceGuid] = Value
            CommentRecords = self._RawData[MODEL_META_DATA_COMMENT, self._Arch,
                                           self._Platform, Id]
            Comments = []
            for CmtRec in CommentRecords:
                Comments.append(CmtRec[0])
            self._PcdComments[TokenSpaceGuid, PcdCName] = Comments

        # resolve PCD type, value, datum info, etc. by getting its definition from package
        _GuidDict = self.Guids.copy()
        for PcdCName, TokenSpaceGuid in PcdList:
            PcdRealName = PcdCName
            Setting, LineNo = PcdDict[self._Arch, self.Platform, PcdCName,
                                      TokenSpaceGuid]
            if Setting is None:
                continue
            ValueList = AnalyzePcdData(Setting)
            DefaultValue = ValueList[0]
            Pcd = PcdClassObject(PcdCName, TokenSpaceGuid, '', '',
                                 DefaultValue, '', '', {}, False,
                                 self.Guids[TokenSpaceGuid])
            if Type == MODEL_PCD_PATCHABLE_IN_MODULE and ValueList[1]:
                # Patch PCD: TokenSpace.PcdCName|Value|Offset
                Pcd.Offset = ValueList[1]

            if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
                for Package in self.Packages:
                    for key in Package.Pcds:
                        if (Package.Pcds[key].TokenCName,
                                Package.Pcds[key].TokenSpaceGuidCName) == (
                                    PcdRealName, TokenSpaceGuid):
                            for item in GlobalData.MixedPcd[(PcdRealName,
                                                             TokenSpaceGuid)]:
                                Pcd_Type = item[0].split('_')[-1]
                                if Pcd_Type == Package.Pcds[key].Type:
                                    Value = Package.Pcds[key]
                                    Value.TokenCName = Package.Pcds[
                                        key].TokenCName + '_' + Pcd_Type
                                    if len(key) == 2:
                                        newkey = (Value.TokenCName, key[1])
                                    elif len(key) == 3:
                                        newkey = (Value.TokenCName, key[1],
                                                  key[2])
                                    del Package.Pcds[key]
                                    Package.Pcds[newkey] = Value
                                    break
                                else:
                                    pass
                        else:
                            pass

            # get necessary info from package declaring this PCD
            for Package in self.Packages:
                #
                # 'dynamic' in INF means its type is determined by platform;
                # if platform doesn't give its type, use 'lowest' one in the
                # following order, if any
                #
                #   TAB_PCDS_FIXED_AT_BUILD, TAB_PCDS_PATCHABLE_IN_MODULE, TAB_PCDS_FEATURE_FLAG, TAB_PCDS_DYNAMIC, TAB_PCDS_DYNAMIC_EX
                #
                _GuidDict.update(Package.Guids)
                PcdType = self._PCD_TYPE_STRING_[Type]
                if Type == MODEL_PCD_DYNAMIC:
                    Pcd.Pending = True
                    for T in PCD_TYPE_LIST:
                        if (PcdRealName,
                                TokenSpaceGuid) in GlobalData.MixedPcd:
                            for item in GlobalData.MixedPcd[(PcdRealName,
                                                             TokenSpaceGuid)]:
                                if str(item[0]).endswith(T) and (
                                        item[0], item[1], T) in Package.Pcds:
                                    PcdType = T
                                    PcdCName = item[0]
                                    break
                                else:
                                    pass
                            break
                        else:
                            if (PcdRealName, TokenSpaceGuid,
                                    T) in Package.Pcds:
                                PcdType = T
                                break

                else:
                    Pcd.Pending = False
                    if (PcdRealName, TokenSpaceGuid) in GlobalData.MixedPcd:
                        for item in GlobalData.MixedPcd[(PcdRealName,
                                                         TokenSpaceGuid)]:
                            Pcd_Type = item[0].split('_')[-1]
                            if Pcd_Type == PcdType:
                                PcdCName = item[0]
                                break
                            else:
                                pass
                    else:
                        pass

                if (PcdCName, TokenSpaceGuid, PcdType) in Package.Pcds:
                    PcdInPackage = Package.Pcds[PcdCName, TokenSpaceGuid,
                                                PcdType]
                    Pcd.Type = PcdType
                    Pcd.TokenValue = PcdInPackage.TokenValue

                    #
                    # Check whether the token value exist or not.
                    #
                    if Pcd.TokenValue is None or Pcd.TokenValue == "":
                        EdkLogger.error(
                            'build',
                            FORMAT_INVALID,
                            "No TokenValue for PCD [%s.%s] in [%s]!" %
                            (TokenSpaceGuid, PcdRealName, str(Package)),
                            File=self.MetaFile,
                            Line=LineNo,
                            ExtraData=None)
                    #
                    # Check hexadecimal token value length and format.
                    #
                    ReIsValidPcdTokenValue = re.compile(
                        r"^[0][x|X][0]*[0-9a-fA-F]{1,8}$", re.DOTALL)
                    if Pcd.TokenValue.startswith(
                            "0x") or Pcd.TokenValue.startswith("0X"):
                        if ReIsValidPcdTokenValue.match(
                                Pcd.TokenValue) is None:
                            EdkLogger.error(
                                'build',
                                FORMAT_INVALID,
                                "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid:"
                                % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName,
                                   str(Package)),
                                File=self.MetaFile,
                                Line=LineNo,
                                ExtraData=None)

                    #
                    # Check decimal token value length and format.
                    #
                    else:
                        try:
                            TokenValueInt = int(Pcd.TokenValue, 10)
                            if (TokenValueInt < 0
                                    or TokenValueInt > 4294967295):
                                EdkLogger.error(
                                    'build',
                                    FORMAT_INVALID,
                                    "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, as a decimal it should between: 0 - 4294967295!"
                                    % (Pcd.TokenValue, TokenSpaceGuid,
                                       PcdRealName, str(Package)),
                                    File=self.MetaFile,
                                    Line=LineNo,
                                    ExtraData=None)
                        except:
                            EdkLogger.error(
                                'build',
                                FORMAT_INVALID,
                                "The format of TokenValue [%s] of PCD [%s.%s] in [%s] is invalid, it should be hexadecimal or decimal!"
                                % (Pcd.TokenValue, TokenSpaceGuid, PcdRealName,
                                   str(Package)),
                                File=self.MetaFile,
                                Line=LineNo,
                                ExtraData=None)

                    Pcd.DatumType = PcdInPackage.DatumType
                    Pcd.MaxDatumSize = PcdInPackage.MaxDatumSize
                    Pcd.InfDefaultValue = Pcd.DefaultValue
                    if not Pcd.DefaultValue:
                        Pcd.DefaultValue = PcdInPackage.DefaultValue
                    else:
                        try:
                            Pcd.DefaultValue = ValueExpressionEx(
                                Pcd.DefaultValue, Pcd.DatumType,
                                _GuidDict)(True)
                        except BadExpression as Value:
                            EdkLogger.error('Parser',
                                            FORMAT_INVALID,
                                            'PCD [%s.%s] Value "%s", %s' %
                                            (TokenSpaceGuid, PcdRealName,
                                             Pcd.DefaultValue, Value),
                                            File=self.MetaFile,
                                            Line=LineNo)
                    break
            else:
                EdkLogger.error(
                    'build',
                    FORMAT_INVALID,
                    "PCD [%s.%s] in [%s] is not found in dependent packages:" %
                    (TokenSpaceGuid, PcdRealName, self.MetaFile),
                    File=self.MetaFile,
                    Line=LineNo,
                    ExtraData="\t%s" %
                    '\n\t'.join(str(P) for P in self.Packages))
            Pcds[PcdCName, TokenSpaceGuid] = Pcd

        return Pcds