2 # process APRIORI file data and generate PEI/DXE APRIORI file
4 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
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
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.
18 from __future__
import absolute_import
20 import Common
.LongFilePathOs
as os
21 from io
import BytesIO
22 from . import FfsFileStatement
23 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
24 from CommonDataClass
.FdfClass
import AprioriSectionClassObject
25 from Common
.StringUtils
import *
26 from Common
.Misc
import SaveFileOnChange
, PathClass
27 from Common
import EdkLogger
28 from Common
.BuildToolError
import *
29 from Common
.DataType
import TAB_COMMON
31 ## process APRIORI file data and generate PEI/DXE APRIORI file
34 class AprioriSection (AprioriSectionClassObject
):
37 # @param self The object pointer
40 AprioriSectionClassObject
.__init
__(self
)
45 # Generate FFS for APRIORI file
47 # @param self The object pointer
48 # @param FvName for whom apriori file generated
49 # @param Dict dictionary contains macro and its value
50 # @retval string Generated file name
52 def GenFfs (self
, FvName
, Dict
= {}, IsMakefile
= False):
53 DXE_GUID
= "FC510EE7-FFDC-11D4-BD41-0080C73C8881"
54 PEI_GUID
= "1B45CC0A-156A-428A-AF62-49864DA0E6E6"
56 AprioriFileGuid
= DXE_GUID
57 if self
.AprioriType
== "PEI":
58 AprioriFileGuid
= PEI_GUID
59 OutputAprFilePath
= os
.path
.join (GenFdsGlobalVariable
.WorkSpaceDir
, \
60 GenFdsGlobalVariable
.FfsDir
,\
61 AprioriFileGuid
+ FvName
)
62 if not os
.path
.exists(OutputAprFilePath
) :
63 os
.makedirs(OutputAprFilePath
)
65 OutputAprFileName
= os
.path
.join( OutputAprFilePath
, \
66 AprioriFileGuid
+ FvName
+ '.Apri' )
67 AprFfsFileName
= os
.path
.join (OutputAprFilePath
,\
68 AprioriFileGuid
+ FvName
+ '.Ffs')
70 Dict
.update(self
.DefineVarDict
)
72 for FfsObj
in self
.FfsList
:
74 if isinstance(FfsObj
, FfsFileStatement
.FileStatement
):
75 Guid
= FfsObj
.NameGuid
77 InfFileName
= NormPath(FfsObj
.InfFileName
)
78 Arch
= FfsObj
.GetCurrentArch()
81 Dict
['$(ARCH)'] = Arch
82 InfFileName
= GenFdsGlobalVariable
.MacroExtend(InfFileName
, Dict
, Arch
)
85 Inf
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[PathClass(InfFileName
, GenFdsGlobalVariable
.WorkSpaceDir
), Arch
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
89 Inf
= GenFdsGlobalVariable
.WorkSpace
.BuildObject
[PathClass(InfFileName
, GenFdsGlobalVariable
.WorkSpaceDir
), TAB_COMMON
, GenFdsGlobalVariable
.TargetName
, GenFdsGlobalVariable
.ToolChainTag
]
92 self
.BinFileList
= Inf
.Module
.Binaries
93 if self
.BinFileList
== []:
94 EdkLogger
.error("GenFds", RESOURCE_NOT_AVAILABLE
,
95 "INF %s not found in build ARCH %s!" \
96 % (InfFileName
, GenFdsGlobalVariable
.ArchList
))
99 GuidPart
= Guid
.split('-')
100 Buffer
.write(pack('I', long(GuidPart
[0], 16)))
101 Buffer
.write(pack('H', int(GuidPart
[1], 16)))
102 Buffer
.write(pack('H', int(GuidPart
[2], 16)))
105 Char
= GuidPart
[3][Num
*2:Num
*2+2]
106 Buffer
.write(pack('B', int(Char
, 16)))
109 Char
= GuidPart
[4][Num
*2:Num
*2+2]
110 Buffer
.write(pack('B', int(Char
, 16)))
112 SaveFileOnChange(OutputAprFileName
, Buffer
.getvalue())
114 RawSectionFileName
= os
.path
.join( OutputAprFilePath
, \
115 AprioriFileGuid
+ FvName
+ '.raw' )
120 MakefilePath
= InfFileName
, Arch
121 GenFdsGlobalVariable
.GenerateSection(RawSectionFileName
, [OutputAprFileName
], 'EFI_SECTION_RAW', IsMakefile
=IsMakefile
)
122 GenFdsGlobalVariable
.GenerateFfs(AprFfsFileName
, [RawSectionFileName
],
123 'EFI_FV_FILETYPE_FREEFORM', AprioriFileGuid
, MakefilePath
=MakefilePath
)
125 return AprFfsFileName