]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/CompressSection.py
BaseTools: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / CompressSection.py
1 ## @file
2 # process compress section generation
3 #
4 # Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
5 #
6 # SPDX-License-Identifier: BSD-2-Clause-Patent
7 #
8
9 ##
10 # Import Modules
11 #
12 from __future__ import absolute_import
13 from .Ffs import SectionSuffix
14 from . import Section
15 import subprocess
16 import Common.LongFilePathOs as os
17 from .GenFdsGlobalVariable import GenFdsGlobalVariable
18 from CommonDataClass.FdfClass import CompressSectionClassObject
19 from Common.DataType import *
20
21 ## generate compress section
22 #
23 #
24 class CompressSection (CompressSectionClassObject) :
25
26 ## compress types: PI standard and non PI standard
27 CompTypeDict = {
28 'PI_STD' : 'PI_STD',
29 'PI_NONE' : 'PI_NONE'
30 }
31
32 ## The constructor
33 #
34 # @param self The object pointer
35 #
36 def __init__(self):
37 CompressSectionClassObject.__init__(self)
38
39 ## GenSection() method
40 #
41 # Generate compressed section
42 #
43 # @param self The object pointer
44 # @param OutputPath Where to place output file
45 # @param ModuleName Which module this section belongs to
46 # @param SecNum Index of section
47 # @param KeyStringList Filter for inputs of section generation
48 # @param FfsInf FfsInfStatement object that contains this section data
49 # @param Dict dictionary contains macro and its value
50 # @retval tuple (Generated file name, section alignment)
51 #
52 def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):
53
54 if FfsInf is not None:
55 self.CompType = FfsInf.__ExtendMacro__(self.CompType)
56 self.Alignment = FfsInf.__ExtendMacro__(self.Alignment)
57
58 SectFiles = tuple()
59 SectAlign = []
60 Index = 0
61 MaxAlign = None
62 for Sect in self.SectionList:
63 Index = Index + 1
64 SecIndex = '%s.%d' %(SecNum, Index)
65 ReturnSectList, AlignValue = Sect.GenSection(OutputPath, ModuleName, SecIndex, KeyStringList, FfsInf, Dict, IsMakefile=IsMakefile)
66 if AlignValue is not None:
67 if MaxAlign is None:
68 MaxAlign = AlignValue
69 if GenFdsGlobalVariable.GetAlignment (AlignValue) > GenFdsGlobalVariable.GetAlignment (MaxAlign):
70 MaxAlign = AlignValue
71 if ReturnSectList != []:
72 if AlignValue is None:
73 AlignValue = "1"
74 for FileData in ReturnSectList:
75 SectFiles += (FileData,)
76 SectAlign.append(AlignValue)
77
78 OutputFile = OutputPath + \
79 os.sep + \
80 ModuleName + \
81 SUP_MODULE_SEC + \
82 SecNum + \
83 SectionSuffix['COMPRESS']
84 OutputFile = os.path.normpath(OutputFile)
85 DummyFile = OutputFile + '.dummy'
86 GenFdsGlobalVariable.GenerateSection(DummyFile, SectFiles, InputAlign=SectAlign, IsMakefile=IsMakefile)
87
88 GenFdsGlobalVariable.GenerateSection(OutputFile, [DummyFile], Section.Section.SectionType['COMPRESS'],
89 CompressionType=self.CompTypeDict[self.CompType], IsMakefile=IsMakefile)
90 OutputFileList = []
91 OutputFileList.append(OutputFile)
92 return OutputFileList, self.Alignment
93
94