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