]>
Commit | Line | Data |
---|---|---|
30fdf114 LG |
1 | ## @file\r |
2 | # process FV image section generation\r | |
3 | #\r | |
1dc287c3 | 4 | # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r |
30fdf114 | 5 | #\r |
40d841f6 | 6 | # This program and the accompanying materials\r |
30fdf114 LG |
7 | # are licensed and made available under the terms and conditions of the BSD License\r |
8 | # which accompanies this distribution. The full text of the license may be found at\r | |
9 | # http://opensource.org/licenses/bsd-license.php\r | |
10 | #\r | |
11 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | #\r | |
14 | \r | |
15 | ##\r | |
16 | # Import Modules\r | |
17 | #\r | |
18 | import Section\r | |
86379ac4 | 19 | from io import BytesIO\r |
30fdf114 LG |
20 | from Ffs import Ffs\r |
21 | import subprocess\r | |
22 | from GenFdsGlobalVariable import GenFdsGlobalVariable\r | |
1be2ed90 | 23 | import Common.LongFilePathOs as os\r |
30fdf114 LG |
24 | from CommonDataClass.FdfClass import FvImageSectionClassObject\r |
25 | from Common import EdkLogger\r | |
26 | from Common.BuildToolError import *\r | |
8bb63e37 | 27 | from Common.DataType import *\r |
30fdf114 LG |
28 | \r |
29 | ## generate FV image section\r | |
30 | #\r | |
31 | #\r | |
32 | class FvImageSection(FvImageSectionClassObject):\r | |
33 | \r | |
34 | ## The constructor\r | |
35 | #\r | |
36 | # @param self The object pointer\r | |
37 | #\r | |
38 | def __init__(self):\r | |
39 | FvImageSectionClassObject.__init__(self)\r | |
40 | \r | |
41 | ## GenSection() method\r | |
42 | #\r | |
43 | # Generate FV image section\r | |
44 | #\r | |
45 | # @param self The object pointer\r | |
46 | # @param OutputPath Where to place output file\r | |
47 | # @param ModuleName Which module this section belongs to\r | |
48 | # @param SecNum Index of section\r | |
49 | # @param KeyStringList Filter for inputs of section generation\r | |
50 | # @param FfsInf FfsInfStatement object that contains this section data\r | |
51 | # @param Dict dictionary contains macro and its value\r | |
52 | # @retval tuple (Generated file name, section alignment)\r | |
53 | #\r | |
37de70b7 | 54 | def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):\r |
30fdf114 LG |
55 | \r |
56 | OutputFileList = []\r | |
4231a819 | 57 | if self.FvFileType is not None:\r |
30fdf114 LG |
58 | FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)\r |
59 | if IsSect :\r | |
60 | return FileList, self.Alignment\r | |
61 | \r | |
62 | Num = SecNum\r | |
63 | \r | |
321151fe YZ |
64 | MaxFvAlignment = 0\r |
65 | for FvFileName in FileList:\r | |
66 | FvAlignmentValue = 0\r | |
67 | if os.path.isfile(FvFileName):\r | |
ccaa7754 | 68 | FvFileObj = open (FvFileName, 'rb')\r |
321151fe YZ |
69 | FvFileObj.seek(0)\r |
70 | # PI FvHeader is 0x48 byte\r | |
71 | FvHeaderBuffer = FvFileObj.read(0x48)\r | |
72 | # FV alignment position.\r | |
73 | FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r | |
74 | FvFileObj.close()\r | |
75 | if FvAlignmentValue > MaxFvAlignment:\r | |
76 | MaxFvAlignment = FvAlignmentValue\r | |
77 | \r | |
8bb63e37 | 78 | OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r |
37de70b7 | 79 | GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r |
30fdf114 | 80 | OutputFileList.append(OutputFile)\r |
321151fe YZ |
81 | \r |
82 | # MaxFvAlignment is larger than or equal to 1K\r | |
83 | if MaxFvAlignment >= 0x400:\r | |
e921f58d YZ |
84 | if MaxFvAlignment >= 0x100000:\r |
85 | #The max alignment supported by FFS is 16M.\r | |
1dc287c3 | 86 | if MaxFvAlignment >= 0x1000000:\r |
e921f58d YZ |
87 | self.Alignment = "16M"\r |
88 | else:\r | |
89 | self.Alignment = str(MaxFvAlignment / 0x100000) + "M"\r | |
321151fe YZ |
90 | else:\r |
91 | self.Alignment = str (MaxFvAlignment / 0x400) + "K"\r | |
92 | else:\r | |
93 | # MaxFvAlignment is less than 1K\r | |
94 | self.Alignment = str (MaxFvAlignment)\r | |
95 | \r | |
30fdf114 LG |
96 | return OutputFileList, self.Alignment\r |
97 | #\r | |
98 | # Generate Fv\r | |
99 | #\r | |
4231a819 | 100 | if self.FvName is not None:\r |
86379ac4 | 101 | Buffer = BytesIO('')\r |
30fdf114 | 102 | Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r |
4231a819 | 103 | if Fv is not None:\r |
30fdf114 | 104 | self.Fv = Fv\r |
37de70b7 | 105 | FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile)\r |
4231a819 CJ |
106 | if Fv.FvAlignment is not None:\r |
107 | if self.Alignment is None:\r | |
52302d4d LG |
108 | self.Alignment = Fv.FvAlignment\r |
109 | else:\r | |
110 | if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r | |
111 | self.Alignment = Fv.FvAlignment\r | |
30fdf114 | 112 | else:\r |
4231a819 | 113 | if self.FvFileName is not None:\r |
30fdf114 | 114 | FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r |
877c0a93 | 115 | if os.path.isfile(FvFileName):\r |
ccaa7754 | 116 | FvFileObj = open (FvFileName, 'rb')\r |
877c0a93 YZ |
117 | FvFileObj.seek(0)\r |
118 | # PI FvHeader is 0x48 byte\r | |
119 | FvHeaderBuffer = FvFileObj.read(0x48)\r | |
120 | # FV alignment position.\r | |
121 | FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r | |
122 | # FvAlignmentValue is larger than or equal to 1K\r | |
123 | if FvAlignmentValue >= 0x400:\r | |
e921f58d YZ |
124 | if FvAlignmentValue >= 0x100000:\r |
125 | #The max alignment supported by FFS is 16M.\r | |
126 | if FvAlignmentValue >= 0x1000000:\r | |
127 | self.Alignment = "16M"\r | |
128 | else:\r | |
129 | self.Alignment = str(FvAlignmentValue / 0x100000) + "M"\r | |
877c0a93 YZ |
130 | else:\r |
131 | self.Alignment = str (FvAlignmentValue / 0x400) + "K"\r | |
132 | else:\r | |
133 | # FvAlignmentValue is less than 1K\r | |
134 | self.Alignment = str (FvAlignmentValue)\r | |
135 | FvFileObj.close()\r | |
75135cc6 YZ |
136 | else:\r |
137 | if len (mws.getPkgPath()) == 0:\r | |
138 | EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in WORKSPACE: %s" % self.FvFileName, GenFdsGlobalVariable.WorkSpaceDir)\r | |
139 | else:\r | |
140 | EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in packages path:\n\t%s" % (self.FvFileName, '\n\t'.join(mws.getPkgPath())))\r | |
141 | \r | |
30fdf114 LG |
142 | else:\r |
143 | EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r | |
144 | \r | |
145 | #\r | |
146 | # Prepare the parameter of GenSection\r | |
147 | #\r | |
8bb63e37 | 148 | OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r |
37de70b7 | 149 | GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r |
30fdf114 LG |
150 | OutputFileList.append(OutputFile)\r |
151 | \r | |
152 | return OutputFileList, self.Alignment\r |