]>
git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Fd.py
9c43a62cc3d053502640d8b33111f98a703f2ffb
2 # process FD generation
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
21 import Common
.LongFilePathOs
as os
22 from io
import BytesIO
25 from .GenFdsGlobalVariable
import GenFdsGlobalVariable
26 from CommonDataClass
.FdfClass
import FDClassObject
27 from Common
import EdkLogger
28 from Common
.BuildToolError
import *
29 from Common
.Misc
import SaveFileOnChange
30 from Common
.DataType
import BINARY_FILE_TYPE_FV
35 class FD(FDClassObject
):
38 # @param self The object pointer
41 FDClassObject
.__init
__(self
)
47 # @retval string Generated FD file name
49 def GenFd (self
, Flag
= False):
50 if self
.FdUiName
.upper() + 'fd' in GenFdsGlobalVariable
.ImageBinDict
:
51 return GenFdsGlobalVariable
.ImageBinDict
[self
.FdUiName
.upper() + 'fd']
56 FdFileName
= os
.path
.join(GenFdsGlobalVariable
.FvDir
, self
.FdUiName
+ '.fd')
58 GenFdsGlobalVariable
.InfLogger("\nFd File Name:%s (%s)" %(self
.FdUiName
, FdFileName
))
61 for item
in self
.BlockSizeList
:
62 Offset
= Offset
+ item
[0] * item
[1]
63 if Offset
!= self
.Size
:
64 EdkLogger
.error("GenFds", GENFDS_ERROR
, 'FD %s Size not consistent with block array' % self
.FdUiName
)
65 GenFdsGlobalVariable
.VerboseLogger('Following Fv will be add to Fd !!!')
66 for FvObj
in GenFdsGlobalVariable
.FdfParser
.Profile
.FvDict
:
67 GenFdsGlobalVariable
.VerboseLogger(FvObj
)
69 HasCapsuleRegion
= False
70 for RegionObj
in self
.RegionList
:
71 if RegionObj
.RegionType
== 'CAPSULE':
72 HasCapsuleRegion
= True
75 TempFdBuffer
= BytesIO('')
76 PreviousRegionStart
= -1
77 PreviousRegionSize
= 1
79 for RegionObj
in self
.RegionList
:
80 if RegionObj
.RegionType
== 'CAPSULE':
82 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
84 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
86 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
88 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
89 PadRegion
= Region
.Region()
90 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
91 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
93 PadRegion
.AddToBuffer(TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFdsGlobalVariable
.ImageBinDict
, self
.DefineVarDict
)
94 PreviousRegionStart
= RegionObj
.Offset
95 PreviousRegionSize
= RegionObj
.Size
97 # Call each region's AddToBuffer function
99 if PreviousRegionSize
> self
.Size
:
101 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
102 RegionObj
.AddToBuffer (TempFdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFdsGlobalVariable
.ImageBinDict
, self
.DefineVarDict
)
104 FdBuffer
= BytesIO('')
105 PreviousRegionStart
= -1
106 PreviousRegionSize
= 1
107 for RegionObj
in self
.RegionList
:
108 if RegionObj
.Offset
+ RegionObj
.Size
<= PreviousRegionStart
:
109 EdkLogger
.error("GenFds", GENFDS_ERROR
,
110 'Region offset 0x%X in wrong order with Region starting from 0x%X, size 0x%X\nRegions in FDF must have offsets appear in ascending order.'\
111 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
112 elif RegionObj
.Offset
<= PreviousRegionStart
or (RegionObj
.Offset
>=PreviousRegionStart
and RegionObj
.Offset
< PreviousRegionStart
+ PreviousRegionSize
):
113 EdkLogger
.error("GenFds", GENFDS_ERROR
,
114 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \
115 % (RegionObj
.Offset
, PreviousRegionStart
, PreviousRegionSize
))
116 elif RegionObj
.Offset
> PreviousRegionStart
+ PreviousRegionSize
:
118 GenFdsGlobalVariable
.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart
+ PreviousRegionSize
, RegionObj
.Offset
- (PreviousRegionStart
+ PreviousRegionSize
)))
119 PadRegion
= Region
.Region()
120 PadRegion
.Offset
= PreviousRegionStart
+ PreviousRegionSize
121 PadRegion
.Size
= RegionObj
.Offset
- PadRegion
.Offset
123 PadRegion
.AddToBuffer(FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFdsGlobalVariable
.ImageBinDict
, self
.DefineVarDict
)
124 PreviousRegionStart
= RegionObj
.Offset
125 PreviousRegionSize
= RegionObj
.Size
127 # Verify current region fits within allocated FD section Size
129 if PreviousRegionStart
+ PreviousRegionSize
> self
.Size
:
130 EdkLogger
.error("GenFds", GENFDS_ERROR
,
131 'FD %s size too small to fit region with offset 0x%X and size 0x%X'
132 % (self
.FdUiName
, PreviousRegionStart
, PreviousRegionSize
))
134 # Call each region's AddToBuffer function
136 GenFdsGlobalVariable
.VerboseLogger('Call each region\'s AddToBuffer function')
137 RegionObj
.AddToBuffer (FdBuffer
, self
.BaseAddress
, self
.BlockSizeList
, self
.ErasePolarity
, GenFdsGlobalVariable
.ImageBinDict
, self
.DefineVarDict
, Flag
=Flag
)
139 # Write the buffer contents to Fd file
141 GenFdsGlobalVariable
.VerboseLogger('Write the buffer contents to Fd file')
143 SaveFileOnChange(FdFileName
, FdBuffer
.getvalue())
145 GenFdsGlobalVariable
.ImageBinDict
[self
.FdUiName
.upper() + 'fd'] = FdFileName
148 ## generate flash map file
150 # @param self The object pointer
152 def GenFlashMap (self
):