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