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