]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # process FD generation\r | |
3 | #\r | |
9eb87141 | 4 | # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
30fdf114 | 5 | #\r |
2e351cbe | 6 | # SPDX-License-Identifier: BSD-2-Clause-Patent\r |
30fdf114 LG |
7 | #\r |
8 | \r | |
9 | ##\r | |
10 | # Import Modules\r | |
11 | #\r | |
1ccc4d89 | 12 | from __future__ import absolute_import\r |
bfa65b61 GL |
13 | from . import Region\r |
14 | from . import Fv\r | |
1be2ed90 | 15 | import Common.LongFilePathOs as os\r |
86379ac4 | 16 | from io import BytesIO\r |
30fdf114 LG |
17 | import sys\r |
18 | from struct import *\r | |
bfa65b61 | 19 | from .GenFdsGlobalVariable import GenFdsGlobalVariable\r |
30fdf114 LG |
20 | from CommonDataClass.FdfClass import FDClassObject\r |
21 | from Common import EdkLogger\r | |
22 | from Common.BuildToolError import *\r | |
23 | from Common.Misc import SaveFileOnChange\r | |
91fa33ee | 24 | from Common.DataType import BINARY_FILE_TYPE_FV\r |
30fdf114 LG |
25 | \r |
26 | ## generate FD\r | |
27 | #\r | |
28 | #\r | |
29 | class FD(FDClassObject):\r | |
30 | ## The constructor\r | |
31 | #\r | |
32 | # @param self The object pointer\r | |
33 | #\r | |
34 | def __init__(self):\r | |
35 | FDClassObject.__init__(self)\r | |
36 | \r | |
37 | ## GenFd() method\r | |
38 | #\r | |
39 | # Generate FD\r | |
40 | #\r | |
30fdf114 LG |
41 | # @retval string Generated FD file name\r |
42 | #\r | |
37de70b7 | 43 | def GenFd (self, Flag = False):\r |
7de00838 GL |
44 | if self.FdUiName.upper() + 'fd' in GenFdsGlobalVariable.ImageBinDict:\r |
45 | return GenFdsGlobalVariable.ImageBinDict[self.FdUiName.upper() + 'fd']\r | |
fd171542 | 46 | \r |
30fdf114 LG |
47 | #\r |
48 | # Print Information\r | |
49 | #\r | |
c82fc2b5 | 50 | FdFileName = os.path.join(GenFdsGlobalVariable.FvDir, self.FdUiName + '.fd')\r |
37de70b7 YZ |
51 | if not Flag:\r |
52 | GenFdsGlobalVariable.InfLogger("\nFd File Name:%s (%s)" %(self.FdUiName, FdFileName))\r | |
c82fc2b5 | 53 | \r |
30fdf114 LG |
54 | Offset = 0x00\r |
55 | for item in self.BlockSizeList:\r | |
56 | Offset = Offset + item[0] * item[1]\r | |
57 | if Offset != self.Size:\r | |
58 | EdkLogger.error("GenFds", GENFDS_ERROR, 'FD %s Size not consistent with block array' % self.FdUiName)\r | |
59 | GenFdsGlobalVariable.VerboseLogger('Following Fv will be add to Fd !!!')\r | |
60 | for FvObj in GenFdsGlobalVariable.FdfParser.Profile.FvDict:\r | |
61 | GenFdsGlobalVariable.VerboseLogger(FvObj)\r | |
62 | \r | |
66d00b4d YZ |
63 | HasCapsuleRegion = False\r |
64 | for RegionObj in self.RegionList:\r | |
b303ea72 | 65 | if RegionObj.RegionType == 'CAPSULE':\r |
66d00b4d YZ |
66 | HasCapsuleRegion = True\r |
67 | break\r | |
68 | if HasCapsuleRegion:\r | |
d943b0c3 | 69 | TempFdBuffer = BytesIO()\r |
66d00b4d YZ |
70 | PreviousRegionStart = -1\r |
71 | PreviousRegionSize = 1\r | |
72 | \r | |
73 | for RegionObj in self.RegionList :\r | |
74 | if RegionObj.RegionType == 'CAPSULE':\r | |
75 | continue\r | |
76 | if RegionObj.Offset + RegionObj.Size <= PreviousRegionStart:\r | |
77 | pass\r | |
78 | elif RegionObj.Offset <= PreviousRegionStart or (RegionObj.Offset >=PreviousRegionStart and RegionObj.Offset < PreviousRegionStart + PreviousRegionSize):\r | |
79 | pass\r | |
80 | elif RegionObj.Offset > PreviousRegionStart + PreviousRegionSize:\r | |
37de70b7 YZ |
81 | if not Flag:\r |
82 | GenFdsGlobalVariable.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart + PreviousRegionSize, RegionObj.Offset - (PreviousRegionStart + PreviousRegionSize)))\r | |
66d00b4d YZ |
83 | PadRegion = Region.Region()\r |
84 | PadRegion.Offset = PreviousRegionStart + PreviousRegionSize\r | |
85 | PadRegion.Size = RegionObj.Offset - PadRegion.Offset\r | |
37de70b7 | 86 | if not Flag:\r |
39879ef2 | 87 | PadRegion.AddToBuffer(TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.DefineVarDict)\r |
66d00b4d YZ |
88 | PreviousRegionStart = RegionObj.Offset\r |
89 | PreviousRegionSize = RegionObj.Size\r | |
90 | #\r | |
91 | # Call each region's AddToBuffer function\r | |
92 | #\r | |
93 | if PreviousRegionSize > self.Size:\r | |
94 | pass\r | |
95 | GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')\r | |
39879ef2 | 96 | RegionObj.AddToBuffer (TempFdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.DefineVarDict)\r |
f7496d71 | 97 | \r |
d943b0c3 | 98 | FdBuffer = BytesIO()\r |
30fdf114 LG |
99 | PreviousRegionStart = -1\r |
100 | PreviousRegionSize = 1\r | |
101 | for RegionObj in self.RegionList :\r | |
102 | if RegionObj.Offset + RegionObj.Size <= PreviousRegionStart:\r | |
103 | EdkLogger.error("GenFds", GENFDS_ERROR,\r | |
104 | '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.'\\r | |
105 | % (RegionObj.Offset, PreviousRegionStart, PreviousRegionSize))\r | |
106 | elif RegionObj.Offset <= PreviousRegionStart or (RegionObj.Offset >=PreviousRegionStart and RegionObj.Offset < PreviousRegionStart + PreviousRegionSize):\r | |
107 | EdkLogger.error("GenFds", GENFDS_ERROR,\r | |
108 | 'Region offset 0x%X overlaps with Region starting from 0x%X, size 0x%X' \\r | |
109 | % (RegionObj.Offset, PreviousRegionStart, PreviousRegionSize))\r | |
110 | elif RegionObj.Offset > PreviousRegionStart + PreviousRegionSize:\r | |
37de70b7 YZ |
111 | if not Flag:\r |
112 | GenFdsGlobalVariable.InfLogger('Padding region starting from offset 0x%X, with size 0x%X' %(PreviousRegionStart + PreviousRegionSize, RegionObj.Offset - (PreviousRegionStart + PreviousRegionSize)))\r | |
30fdf114 LG |
113 | PadRegion = Region.Region()\r |
114 | PadRegion.Offset = PreviousRegionStart + PreviousRegionSize\r | |
115 | PadRegion.Size = RegionObj.Offset - PadRegion.Offset\r | |
37de70b7 | 116 | if not Flag:\r |
39879ef2 | 117 | PadRegion.AddToBuffer(FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.DefineVarDict)\r |
30fdf114 LG |
118 | PreviousRegionStart = RegionObj.Offset\r |
119 | PreviousRegionSize = RegionObj.Size\r | |
120 | #\r | |
4afd3d04 LG |
121 | # Verify current region fits within allocated FD section Size\r |
122 | #\r | |
123 | if PreviousRegionStart + PreviousRegionSize > self.Size:\r | |
124 | EdkLogger.error("GenFds", GENFDS_ERROR,\r | |
125 | 'FD %s size too small to fit region with offset 0x%X and size 0x%X'\r | |
126 | % (self.FdUiName, PreviousRegionStart, PreviousRegionSize))\r | |
127 | #\r | |
30fdf114 LG |
128 | # Call each region's AddToBuffer function\r |
129 | #\r | |
30fdf114 | 130 | GenFdsGlobalVariable.VerboseLogger('Call each region\'s AddToBuffer function')\r |
39879ef2 | 131 | RegionObj.AddToBuffer (FdBuffer, self.BaseAddress, self.BlockSizeList, self.ErasePolarity, GenFdsGlobalVariable.ImageBinDict, self.DefineVarDict, Flag=Flag)\r |
30fdf114 | 132 | #\r |
30fdf114 LG |
133 | # Write the buffer contents to Fd file\r |
134 | #\r | |
135 | GenFdsGlobalVariable.VerboseLogger('Write the buffer contents to Fd file')\r | |
37de70b7 YZ |
136 | if not Flag:\r |
137 | SaveFileOnChange(FdFileName, FdBuffer.getvalue())\r | |
138 | FdBuffer.close()\r | |
7de00838 | 139 | GenFdsGlobalVariable.ImageBinDict[self.FdUiName.upper() + 'fd'] = FdFileName\r |
30fdf114 LG |
140 | return FdFileName\r |
141 | \r | |
30fdf114 LG |
142 | ## generate flash map file\r |
143 | #\r | |
144 | # @param self The object pointer\r | |
145 | #\r | |
146 | def GenFlashMap (self):\r | |
147 | pass\r | |
148 | \r | |
149 | \r | |
150 | \r | |
151 | \r | |
152 | \r | |
153 | \r | |
154 | \r | |
155 | \r |