]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - BaseTools/Source/Python/GenFds/FvImageSection.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
... / ...
CommitLineData
1## @file\r
2# process FV image section generation\r
3#\r
4# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
5#\r
6# SPDX-License-Identifier: BSD-2-Clause-Patent\r
7#\r
8\r
9##\r
10# Import Modules\r
11#\r
12from __future__ import absolute_import\r
13from . import Section\r
14from io import BytesIO\r
15from .Ffs import SectionSuffix\r
16import subprocess\r
17from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
18import Common.LongFilePathOs as os\r
19from CommonDataClass.FdfClass import FvImageSectionClassObject\r
20from Common.MultipleWorkspace import MultipleWorkspace as mws\r
21from Common import EdkLogger\r
22from Common.BuildToolError import *\r
23from Common.DataType import *\r
24\r
25## generate FV image section\r
26#\r
27#\r
28class 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
50 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = None, IsMakefile = False):\r
51\r
52 OutputFileList = []\r
53 if Dict is None:\r
54 Dict = {}\r
55 if self.FvFileType is not None:\r
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
62 MaxFvAlignment = 0\r
63 for FvFileName in FileList:\r
64 FvAlignmentValue = 0\r
65 if os.path.isfile(FvFileName):\r
66 FvFileObj = open (FvFileName, 'rb')\r
67 FvFileObj.seek(0)\r
68 # PI FvHeader is 0x48 byte\r
69 FvHeaderBuffer = FvFileObj.read(0x48)\r
70 # FV alignment position.\r
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
75 FvFileObj.close()\r
76 if FvAlignmentValue > MaxFvAlignment:\r
77 MaxFvAlignment = FvAlignmentValue\r
78\r
79 OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get("FV_IMAGE"))\r
80 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
81 OutputFileList.append(OutputFile)\r
82\r
83 # MaxFvAlignment is larger than or equal to 1K\r
84 if MaxFvAlignment >= 0x400:\r
85 if MaxFvAlignment >= 0x100000:\r
86 #The max alignment supported by FFS is 16M.\r
87 if MaxFvAlignment >= 0x1000000:\r
88 self.Alignment = "16M"\r
89 else:\r
90 self.Alignment = str(MaxFvAlignment // 0x100000) + "M"\r
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
97 return OutputFileList, self.Alignment\r
98 #\r
99 # Generate Fv\r
100 #\r
101 if self.FvName is not None:\r
102 Buffer = BytesIO()\r
103 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
104 if Fv is not None:\r
105 self.Fv = Fv\r
106 if not self.FvAddr and self.Fv.BaseAddress:\r
107 self.FvAddr = self.Fv.BaseAddress\r
108 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile)\r
109 if Fv.FvAlignment is not None:\r
110 if self.Alignment is None:\r
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
115 else:\r
116 if self.FvFileName is not None:\r
117 FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
118 if os.path.isfile(FvFileName):\r
119 FvFileObj = open (FvFileName, 'rb')\r
120 FvFileObj.seek(0)\r
121 # PI FvHeader is 0x48 byte\r
122 FvHeaderBuffer = FvFileObj.read(0x48)\r
123 # FV alignment position.\r
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
128 # FvAlignmentValue is larger than or equal to 1K\r
129 if FvAlignmentValue >= 0x400:\r
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
135 self.Alignment = str(FvAlignmentValue // 0x100000) + "M"\r
136 else:\r
137 self.Alignment = str (FvAlignmentValue // 0x400) + "K"\r
138 else:\r
139 # FvAlignmentValue is less than 1K\r
140 self.Alignment = str (FvAlignmentValue)\r
141 FvFileObj.close()\r
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
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
154 OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get("FV_IMAGE"))\r
155 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
156 OutputFileList.append(OutputFile)\r
157\r
158 return OutputFileList, self.Alignment\r