Sync EDKII BaseTools to BaseTools project r1903.
[efi/edk2/.git] / edk2 / BaseTools / Source / Python / GenFds / FvImageSection.py
1 ## @file\r
2 # process FV image section generation\r
3 #\r
4 #  Copyright (c) 2007, Intel Corporation\r
5 #\r
6 #  All rights reserved. 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 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 = {}):\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
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
83             else:\r
84                 if self.FvFileName != None:\r
85                     FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
86                 else:\r
87                     EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
88 \r
89             #\r
90             # Prepare the parameter of GenSection\r
91             #\r
92             OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
93             GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
94             OutputFileList.append(OutputFile)\r
95 \r
96             return OutputFileList, self.Alignment\r