]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Source/Python/GenFds/Section.py
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / BaseTools / Source / Python / GenFds / Section.py
1 ## @file
2 # section base class
3 #
4 # Copyright (c) 2007-2018, 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 CommonDataClass.FdfClass import SectionClassObject
14 from .GenFdsGlobalVariable import GenFdsGlobalVariable
15 import Common.LongFilePathOs as os, glob
16 from Common import EdkLogger
17 from Common.BuildToolError import *
18 from Common.DataType import *
19
20 ## section base class
21 #
22 #
23 class Section (SectionClassObject):
24 SectionType = {
25 'RAW' : 'EFI_SECTION_RAW',
26 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID',
27 BINARY_FILE_TYPE_PE32 : 'EFI_SECTION_PE32',
28 BINARY_FILE_TYPE_PIC : 'EFI_SECTION_PIC',
29 BINARY_FILE_TYPE_TE : 'EFI_SECTION_TE',
30 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE',
31 'COMPAT16' : 'EFI_SECTION_COMPATIBILITY16',
32 BINARY_FILE_TYPE_DXE_DEPEX : 'EFI_SECTION_DXE_DEPEX',
33 BINARY_FILE_TYPE_PEI_DEPEX : 'EFI_SECTION_PEI_DEPEX',
34 'GUIDED' : 'EFI_SECTION_GUID_DEFINED',
35 'COMPRESS' : 'EFI_SECTION_COMPRESSION',
36 BINARY_FILE_TYPE_UI : 'EFI_SECTION_USER_INTERFACE',
37 BINARY_FILE_TYPE_SMM_DEPEX : 'EFI_SECTION_SMM_DEPEX'
38 }
39
40 BinFileType = {
41 BINARY_FILE_TYPE_GUID : '.guid',
42 'ACPI' : '.acpi',
43 'ASL' : '.asl' ,
44 BINARY_FILE_TYPE_UEFI_APP : '.app',
45 BINARY_FILE_TYPE_LIB : '.lib',
46 BINARY_FILE_TYPE_PE32 : '.pe32',
47 BINARY_FILE_TYPE_PIC : '.pic',
48 BINARY_FILE_TYPE_PEI_DEPEX : '.depex',
49 'SEC_PEI_DEPEX' : '.depex',
50 BINARY_FILE_TYPE_TE : '.te',
51 BINARY_FILE_TYPE_UNI_VER : '.ver',
52 BINARY_FILE_TYPE_VER : '.ver',
53 BINARY_FILE_TYPE_UNI_UI : '.ui',
54 BINARY_FILE_TYPE_UI : '.ui',
55 BINARY_FILE_TYPE_BIN : '.bin',
56 'RAW' : '.raw',
57 'COMPAT16' : '.comp16',
58 BINARY_FILE_TYPE_FV : '.fv'
59 }
60
61 SectFileType = {
62 'SEC_GUID' : '.sec' ,
63 'SEC_PE32' : '.sec' ,
64 'SEC_PIC' : '.sec',
65 'SEC_TE' : '.sec',
66 'SEC_VER' : '.sec',
67 'SEC_UI' : '.sec',
68 'SEC_COMPAT16' : '.sec',
69 'SEC_BIN' : '.sec'
70 }
71
72 ToolGuid = {
73 '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompress',
74 '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompress'
75 }
76
77 ## The constructor
78 #
79 # @param self The object pointer
80 #
81 def __init__(self):
82 SectionClassObject.__init__(self)
83
84 ## GenSection() method
85 #
86 # virtual function
87 #
88 # @param self The object pointer
89 # @param OutputPath Where to place output file
90 # @param ModuleName Which module this section belongs to
91 # @param SecNum Index of section
92 # @param KeyStringList Filter for inputs of section generation
93 # @param FfsInf FfsInfStatement object that contains this section data
94 # @param Dict dictionary contains macro and its value
95 #
96 def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = None):
97 pass
98
99 ## GetFileList() method
100 #
101 # Generate compressed section
102 #
103 # @param self The object pointer
104 # @param FfsInf FfsInfStatement object that contains file list
105 # @param FileType File type to get
106 # @param FileExtension File extension to get
107 # @param Dict dictionary contains macro and its value
108 # @retval tuple (File list, boolean)
109 #
110 def GetFileList(FfsInf, FileType, FileExtension, Dict = None, IsMakefile=False, SectionType=None):
111 IsSect = FileType in Section.SectFileType
112
113 if FileExtension is not None:
114 Suffix = FileExtension
115 elif IsSect :
116 Suffix = Section.SectionType.get(FileType)
117 else:
118 Suffix = Section.BinFileType.get(FileType)
119 if FfsInf is None:
120 EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!')
121
122 FileList = []
123 if FileType is not None:
124 for File in FfsInf.BinFileList:
125 if File.Arch == TAB_ARCH_COMMON or FfsInf.CurrentArch == File.Arch:
126 if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \
127 and FileType == 'DXE_DPEX' and File.Type == BINARY_FILE_TYPE_SMM_DEPEX) \
128 or (FileType == BINARY_FILE_TYPE_TE and File.Type == BINARY_FILE_TYPE_PE32):
129 if TAB_STAR in FfsInf.TargetOverrideList or File.Target == TAB_STAR or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []:
130 FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type))
131 else:
132 GenFdsGlobalVariable.InfLogger ("\nBuild Target \'%s\' of File %s is not in the Scope of %s specified by INF %s in FDF" %(File.Target, File.File, FfsInf.TargetOverrideList, FfsInf.InfFileName))
133 else:
134 GenFdsGlobalVariable.VerboseLogger ("\nFile Type \'%s\' of File %s in %s is not same with file type \'%s\' from Rule in FDF" %(File.Type, File.File, FfsInf.InfFileName, FileType))
135 else:
136 GenFdsGlobalVariable.InfLogger ("\nCurrent ARCH \'%s\' of File %s is not in the Support Arch Scope of %s specified by INF %s in FDF" %(FfsInf.CurrentArch, File.File, File.Arch, FfsInf.InfFileName))
137
138 elif FileType is None and SectionType == BINARY_FILE_TYPE_RAW:
139 for File in FfsInf.BinFileList:
140 if File.Ext == Suffix:
141 FileList.append(File.Path)
142
143 if (not IsMakefile and Suffix is not None and os.path.exists(FfsInf.EfiOutputPath)) or (IsMakefile and Suffix is not None):
144 if not FileList:
145 SuffixMap = FfsInf.GetFinalTargetSuffixMap()
146 if Suffix in SuffixMap:
147 FileList.extend(SuffixMap[Suffix])
148
149 #Process the file lists is alphabetical for a same section type
150 if len (FileList) > 1:
151 FileList.sort()
152
153 return FileList, IsSect
154 GetFileList = staticmethod(GetFileList)