1## @file 2# section base class 3# 4# Copyright (c) 2007-2015, Intel Corporation. All rights reserved.<BR> 5# 6# This program and the accompanying materials 7# are licensed and made available under the terms and conditions of the BSD License 8# which accompanies this distribution. The full text of the license may be found at 9# http://opensource.org/licenses/bsd-license.php 10# 11# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 12# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 13# 14 15## 16# Import Modules 17# 18from CommonDataClass.FdfClass import SectionClassObject 19from GenFdsGlobalVariable import GenFdsGlobalVariable 20import Common.LongFilePathOs as os, glob 21from Common import EdkLogger 22from Common.BuildToolError import * 23 24## section base class 25# 26# 27class Section (SectionClassObject): 28 SectionType = { 29 'RAW' : 'EFI_SECTION_RAW', 30 'FREEFORM' : 'EFI_SECTION_FREEFORM_SUBTYPE_GUID', 31 'PE32' : 'EFI_SECTION_PE32', 32 'PIC' : 'EFI_SECTION_PIC', 33 'TE' : 'EFI_SECTION_TE', 34 'FV_IMAGE' : 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', 35 'DXE_DEPEX' : 'EFI_SECTION_DXE_DEPEX', 36 'PEI_DEPEX' : 'EFI_SECTION_PEI_DEPEX', 37 'GUIDED' : 'EFI_SECTION_GUID_DEFINED', 38 'COMPRESS' : 'EFI_SECTION_COMPRESSION', 39 'UI' : 'EFI_SECTION_USER_INTERFACE', 40 'SMM_DEPEX' : 'EFI_SECTION_SMM_DEPEX' 41 } 42 43 BinFileType = { 44 'GUID' : '.guid', 45 'ACPI' : '.acpi', 46 'ASL' : '.asl' , 47 'UEFI_APP' : '.app', 48 'LIB' : '.lib', 49 'PE32' : '.pe32', 50 'PIC' : '.pic', 51 'PEI_DEPEX' : '.depex', 52 'SEC_PEI_DEPEX' : '.depex', 53 'TE' : '.te', 54 'UNI_VER' : '.ver', 55 'VER' : '.ver', 56 'UNI_UI' : '.ui', 57 'UI' : '.ui', 58 'BIN' : '.bin', 59 'RAW' : '.raw', 60 'COMPAT16' : '.comp16', 61 'FV' : '.fv' 62 } 63 64 SectFileType = { 65 'SEC_GUID' : '.sec' , 66 'SEC_PE32' : '.sec' , 67 'SEC_PIC' : '.sec', 68 'SEC_TE' : '.sec', 69 'SEC_VER' : '.sec', 70 'SEC_UI' : '.sec', 71 'SEC_COMPAT16' : '.sec', 72 'SEC_BIN' : '.sec' 73 } 74 75 ToolGuid = { 76 '0xa31280ad-0x481e-0x41b6-0x95e8-0x127f-0x4c984779' : 'TianoCompress', 77 '0xee4e5898-0x3914-0x4259-0x9d6e-0xdc7b-0xd79403cf' : 'LzmaCompress' 78 } 79 80 ## The constructor 81 # 82 # @param self The object pointer 83 # 84 def __init__(self): 85 SectionClassObject.__init__(self) 86 87 ## GenSection() method 88 # 89 # virtual function 90 # 91 # @param self The object pointer 92 # @param OutputPath Where to place output file 93 # @param ModuleName Which module this section belongs to 94 # @param SecNum Index of section 95 # @param KeyStringList Filter for inputs of section generation 96 # @param FfsInf FfsInfStatement object that contains this section data 97 # @param Dict dictionary contains macro and its value 98 # 99 def GenSection(self, OutputPath, GuidName, SecNum, keyStringList, FfsInf = None, Dict = {}): 100 pass 101 102 ## GetFileList() method 103 # 104 # Generate compressed section 105 # 106 # @param self The object pointer 107 # @param FfsInf FfsInfStatement object that contains file list 108 # @param FileType File type to get 109 # @param FileExtension File extension to get 110 # @param Dict dictionary contains macro and its value 111 # @retval tuple (File list, boolean) 112 # 113 def GetFileList(FfsInf, FileType, FileExtension, Dict = {}): 114 if FileType in Section.SectFileType.keys() : 115 IsSect = True 116 else : 117 IsSect = False 118 119 if FileExtension != None: 120 Suffix = FileExtension 121 elif IsSect : 122 Suffix = Section.SectionType.get(FileType) 123 else: 124 Suffix = Section.BinFileType.get(FileType) 125 if FfsInf == None: 126 EdkLogger.error("GenFds", GENFDS_ERROR, 'Inf File does not exist!') 127 128 FileList = [] 129 if FileType != None: 130 for File in FfsInf.BinFileList: 131 if File.Arch == "COMMON" or FfsInf.CurrentArch == File.Arch: 132 if File.Type == FileType or (int(FfsInf.PiSpecVersion, 16) >= 0x0001000A \ 133 and FileType == 'DXE_DPEX'and File.Type == 'SMM_DEPEX') \ 134 or (FileType == 'TE'and File.Type == 'PE32'): 135 if '*' in FfsInf.TargetOverrideList or File.Target == '*' or File.Target in FfsInf.TargetOverrideList or FfsInf.TargetOverrideList == []: 136 FileList.append(FfsInf.PatchEfiFile(File.Path, File.Type)) 137 else: 138 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)) 139 else: 140 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)) 141 else: 142 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)) 143 144 if Suffix != None and os.path.exists(FfsInf.EfiOutputPath): 145 # 146 # Get Makefile path and time stamp 147 # 148 MakefileDir = FfsInf.EfiOutputPath[:-len('OUTPUT')] 149 Makefile = os.path.join(MakefileDir, 'Makefile') 150 if not os.path.exists(Makefile): 151 Makefile = os.path.join(MakefileDir, 'GNUmakefile') 152 if os.path.exists(Makefile): 153 # Update to search files with suffix in all sub-dirs. 154 Tuple = os.walk(FfsInf.EfiOutputPath) 155 for Dirpath, Dirnames, Filenames in Tuple: 156 for F in Filenames: 157 if os.path.splitext(F)[1] == Suffix: 158 FullName = os.path.join(Dirpath, F) 159 if os.path.getmtime(FullName) > os.path.getmtime(Makefile): 160 FileList.append(FullName) 161 if not FileList: 162 SuffixMap = FfsInf.GetFinalTargetSuffixMap() 163 if Suffix in SuffixMap: 164 FileList.extend(SuffixMap[Suffix]) 165 166 #Process the file lists is alphabetical for a same section type 167 if len (FileList) > 1: 168 FileList.sort() 169 170 return FileList, IsSect 171 GetFileList = staticmethod(GetFileList) 172