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