]> git.proxmox.com Git - mirror_edk2.git/blame - BaseTools/Source/Python/GenFds/FvImageSection.py
Security/OpalPasswordDxe: Enhance the logic in RouteConfig/ExtractConfig
[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
63 for FileName in FileList:\r
64 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
65 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
66 OutputFileList.append(OutputFile)\r
67 return OutputFileList, self.Alignment\r
68 #\r
69 # Generate Fv\r
70 #\r
71 if self.FvName != None:\r
72 Buffer = StringIO.StringIO('')\r
73 Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
74 if Fv != None:\r
75 self.Fv = Fv\r
52302d4d
LG
76 FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict)\r
77 if Fv.FvAlignment != None:\r
78 if self.Alignment == None:\r
79 self.Alignment = Fv.FvAlignment\r
80 else:\r
81 if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r
82 self.Alignment = Fv.FvAlignment\r
30fdf114
LG
83 else:\r
84 if self.FvFileName != None:\r
85 FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
877c0a93
YZ
86 if os.path.isfile(FvFileName):\r
87 FvFileObj = open (FvFileName,'r+b')\r
88 FvFileObj.seek(0)\r
89 # PI FvHeader is 0x48 byte\r
90 FvHeaderBuffer = FvFileObj.read(0x48)\r
91 # FV alignment position.\r
92 FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
93 # FvAlignmentValue is larger than or equal to 1K\r
94 if FvAlignmentValue >= 0x400:\r
95 if FvAlignmentValue >= 0x10000:\r
96 #The max alignment supported by FFS is 64K.\r
97 self.Alignment = "64K"\r
98 else:\r
99 self.Alignment = str (FvAlignmentValue / 0x400) + "K"\r
100 else:\r
101 # FvAlignmentValue is less than 1K\r
102 self.Alignment = str (FvAlignmentValue)\r
103 FvFileObj.close()\r
30fdf114
LG
104 else:\r
105 EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
106\r
107 #\r
108 # Prepare the parameter of GenSection\r
109 #\r
110 OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
111 GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
112 OutputFileList.append(OutputFile)\r
113\r
114 return OutputFileList, self.Alignment\r