• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## @file
2# process APRIORI file data and generate PEI/DXE APRIORI file
3#
4#  Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
5#
6#  This program and the accompanying materials
7#  are licensed and made available under the terms and conditions of the BSD License
8#  which accompanies this distribution.  The full text of the license may be found at
9#  http://opensource.org/licenses/bsd-license.php
10#
11#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13#
14
15##
16# Import Modules
17#
18from struct import *
19import Common.LongFilePathOs as os
20import StringIO
21import FfsFileStatement
22from GenFdsGlobalVariable import GenFdsGlobalVariable
23from CommonDataClass.FdfClass import AprioriSectionClassObject
24from Common.String import *
25from Common.Misc import SaveFileOnChange,PathClass
26from Common import EdkLogger
27from Common.BuildToolError import *
28
29## process APRIORI file data and generate PEI/DXE APRIORI file
30#
31#
32class AprioriSection (AprioriSectionClassObject):
33    ## The constructor
34    #
35    #   @param  self        The object pointer
36    #
37    def __init__(self):
38        AprioriSectionClassObject.__init__(self)
39        self.AprioriType = ""
40
41    ## GenFfs() method
42    #
43    #   Generate FFS for APRIORI file
44    #
45    #   @param  self        The object pointer
46    #   @param  FvName      for whom apriori file generated
47    #   @param  Dict        dictionary contains macro and its value
48    #   @retval string      Generated file name
49    #
50    def GenFfs (self, FvName, Dict = {}):
51        DXE_GUID = "FC510EE7-FFDC-11D4-BD41-0080C73C8881"
52        PEI_GUID = "1B45CC0A-156A-428A-AF62-49864DA0E6E6"
53        Buffer = StringIO.StringIO('')
54        AprioriFileGuid = DXE_GUID
55        if self.AprioriType == "PEI":
56            AprioriFileGuid = PEI_GUID
57        OutputAprFilePath = os.path.join (GenFdsGlobalVariable.WorkSpaceDir, \
58                                   GenFdsGlobalVariable.FfsDir,\
59                                   AprioriFileGuid + FvName)
60        if not os.path.exists(OutputAprFilePath) :
61            os.makedirs(OutputAprFilePath)
62
63        OutputAprFileName = os.path.join( OutputAprFilePath, \
64                                       AprioriFileGuid + FvName + '.Apri' )
65        AprFfsFileName = os.path.join (OutputAprFilePath,\
66                                    AprioriFileGuid + FvName + '.Ffs')
67
68        Dict.update(self.DefineVarDict)
69        for FfsObj in self.FfsList :
70            Guid = ""
71            if isinstance(FfsObj, FfsFileStatement.FileStatement):
72                Guid = FfsObj.NameGuid
73            else:
74                InfFileName = NormPath(FfsObj.InfFileName)
75                Arch = FfsObj.GetCurrentArch()
76
77                if Arch != None:
78                    Dict['$(ARCH)'] = Arch
79                InfFileName = GenFdsGlobalVariable.MacroExtend(InfFileName, Dict, Arch)
80
81                if Arch != None:
82                    Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClass(InfFileName, GenFdsGlobalVariable.WorkSpaceDir), Arch, GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
83                    Guid = Inf.Guid
84
85                else:
86                    Inf = GenFdsGlobalVariable.WorkSpace.BuildObject[PathClass(InfFileName, GenFdsGlobalVariable.WorkSpaceDir), 'COMMON', GenFdsGlobalVariable.TargetName, GenFdsGlobalVariable.ToolChainTag]
87                    Guid = Inf.Guid
88
89                    self.BinFileList = Inf.Module.Binaries
90                    if self.BinFileList == []:
91                        EdkLogger.error("GenFds", RESOURCE_NOT_AVAILABLE,
92                                        "INF %s not found in build ARCH %s!" \
93                                        % (InfFileName, GenFdsGlobalVariable.ArchList))
94
95
96            GuidPart = Guid.split('-')
97            Buffer.write(pack('I', long(GuidPart[0], 16)))
98            Buffer.write(pack('H', int(GuidPart[1], 16)))
99            Buffer.write(pack('H', int(GuidPart[2], 16)))
100
101            for Num in range(2):
102                Char = GuidPart[3][Num*2:Num*2+2]
103                Buffer.write(pack('B', int(Char, 16)))
104
105            for Num in range(6):
106                Char = GuidPart[4][Num*2:Num*2+2]
107                Buffer.write(pack('B', int(Char, 16)))
108
109        SaveFileOnChange(OutputAprFileName, Buffer.getvalue())
110
111        RawSectionFileName = os.path.join( OutputAprFilePath, \
112                                       AprioriFileGuid + FvName + '.raw' )
113        GenFdsGlobalVariable.GenerateSection(RawSectionFileName, [OutputAprFileName], 'EFI_SECTION_RAW')
114        GenFdsGlobalVariable.GenerateFfs(AprFfsFileName, [RawSectionFileName],
115                                         'EFI_FV_FILETYPE_FREEFORM', AprioriFileGuid)
116
117        return AprFfsFileName
118
119