]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/FvImageSection.py
BaseTools: FILE DATA to support relative path under Multiple workspace
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / FvImageSection.py
CommitLineData
30fdf114
LG
1## @file\r
2# process FV image section generation\r
3#\r
877c0a93 4# Copyright (c) 2007 - 2016, 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
18import Section\r
19import StringIO\r
20from Ffs import Ffs\r
21import subprocess\r
22from GenFdsGlobalVariable import GenFdsGlobalVariable\r
1be2ed90 23import Common.LongFilePathOs as os\r
30fdf114
LG
24from CommonDataClass.FdfClass import FvImageSectionClassObject\r
25from Common import EdkLogger\r
26from Common.BuildToolError import *\r
27\r
28## generate FV image section\r
29#\r
30#\r
31class 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 = {}):\r
54\r
55 OutputFileList = []\r
56 if self.FvFileType != 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
321151fe
YZ
63 MaxFvAlignment = 0\r
64 for FvFileName in FileList:\r
65 FvAlignmentValue = 0\r
66 if os.path.isfile(FvFileName):\r
f8db6527 67 FvFileObj = open (FvFileName,'rb')\r
321151fe
YZ
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
30fdf114
LG
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')\r
79 OutputFileList.append(OutputFile)\r
321151fe
YZ
80\r
81 # MaxFvAlignment is larger than or equal to 1K\r
82 if MaxFvAlignment >= 0x400:\r
83 if MaxFvAlignment >= 0x10000:\r
84 #The max alignment supported by FFS is 64K.\r
85 self.Alignment = "64K"\r
86 else:\r
87 self.Alignment = str (MaxFvAlignment / 0x400) + "K"\r
88 else:\r
89 # MaxFvAlignment is less than 1K\r
90 self.Alignment = str (MaxFvAlignment)\r
91\r
30fdf114
LG
92 return OutputFileList, self.Alignment\r
93 #\r
94 # Generate Fv\r
95 #\r
96 if self.FvName != None:\r
97 Buffer = StringIO.StringIO('')\r
98 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
99 if Fv != None:\r
100 self.Fv = Fv\r
52302d4d
LG
101 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict)\r
102 if Fv.FvAlignment != None:\r
103 if self.Alignment == None:\r
104 self.Alignment = Fv.FvAlignment\r
105 else:\r
106 if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r
107 self.Alignment = Fv.FvAlignment\r
30fdf114
LG
108 else:\r
109 if self.FvFileName != None:\r
110 FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
877c0a93 111 if os.path.isfile(FvFileName):\r
f8db6527 112 FvFileObj = open (FvFileName,'rb')\r
877c0a93
YZ
113 FvFileObj.seek(0)\r
114 # PI FvHeader is 0x48 byte\r
115 FvHeaderBuffer = FvFileObj.read(0x48)\r
116 # FV alignment position.\r
117 FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
118 # FvAlignmentValue is larger than or equal to 1K\r
119 if FvAlignmentValue >= 0x400:\r
120 if FvAlignmentValue >= 0x10000:\r
121 #The max alignment supported by FFS is 64K.\r
122 self.Alignment = "64K"\r
123 else:\r
124 self.Alignment = str (FvAlignmentValue / 0x400) + "K"\r
125 else:\r
126 # FvAlignmentValue is less than 1K\r
127 self.Alignment = str (FvAlignmentValue)\r
128 FvFileObj.close()\r
30fdf114
LG
129 else:\r
130 EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
131\r
132 #\r
133 # Prepare the parameter of GenSection\r
134 #\r
135 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
136 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
137 OutputFileList.append(OutputFile)\r
138\r
139 return OutputFileList, self.Alignment\r