def InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly, ModuleList): # # Extract other files under current module path in content Zip file but not listed in the description # if ContentZipFile: for FileName in ContentZipFile.GetZipFile().namelist(): FileName = os.path.normpath(FileName) CheckPath = os.path.normpath(os.path.join(FromPath, ModulePath)) if FileUnderPath(FileName, CheckPath): if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE%FileName) FromFile = FileName ToFile = os.path.normpath(os.path.join(WorkspaceDir, ConvertPath(FileName.replace(FromPath, NewPath, 1)))) CheckList = copy.copy(Module.FileList) if Package: CheckList += Package.FileList for Item in CheckList: if Item[0] == ToFile: break else: Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) ModuleList.append((Module, Package))
def ValidatePS1(Package): # # Check DistributionPackage -> PackageSurfaceArea -> Header # XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'Header'] CheckDict = Sdict() CheckDict['Name'] = Package.GetName() CheckDict['BaseName'] = Package.GetBaseName() CheckDict['GUID'] = Package.GetGuid() CheckDict['Version'] = Package.GetVersion() CheckDict['PackagePath'] = Package.GetPackagePath() IsRequiredItemListNull(CheckDict, XmlTreeLevel) if not IsValidInstallPath(Package.GetPackagePath()): Logger.Error("UPT", FORMAT_INVALID, ERR_FILE_NAME_INVALIDE % Package.GetPackagePath()) # # Check DistributionPackage -> PackageSurfaceArea -> ClonedFrom # XmlTreeLevel = ['DistributionPackage', 'PackageSurfaceArea', 'ClonedFrom'] for Item in Package.GetClonedFromList(): if Item is None: CheckDict = Sdict() CheckDict['GUID'] = '' IsRequiredItemListNull(CheckDict, XmlTreeLevel) CheckDict = Sdict() CheckDict['GUID'] = Item.GetPackageGuid() CheckDict['Version'] = Item.GetPackageVersion() IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check DistributionPackage -> PackageSurfaceArea -> LibraryClassDeclarations -> LibraryClass # XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations' ] for Item in Package.GetLibraryClassList(): if Item is None: CheckDict = {'LibraryClass': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'LibraryClassDeclarations', 'LibraryClass' ] for Item in Package.GetLibraryClassList(): CheckDict = { 'Keyword': Item.GetLibraryClass(), 'HeaderFile': Item.GetIncludeHeader() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check DistributionPackage -> PackageSurfaceArea -> IndustryStandardIncludes -> IndustryStandardHeader # XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes' ] for Item in Package.GetStandardIncludeFileList(): if Item is None: CheckDict = {'IndustryStandardHeader': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'IndustryStandardIncludes', 'IndustryStandardHeader' ] for Item in Package.GetStandardIncludeFileList(): CheckDict = {'HeaderFile': Item.GetFilePath()} IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check DistributionPackage -> PackageSurfaceArea -> PackageIncludes -> PackageHeader # XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'PackageIncludes' ] for Item in Package.GetPackageIncludeFileList(): if Item is None: CheckDict = {'PackageHeader': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = [ 'DistributionPackage', 'PackageSurfaceArea', 'PackageIncludes', 'PackageHeader' ] for Item in Package.GetPackageIncludeFileList(): CheckDict = {'HeaderFile': Item.GetFilePath()} IsRequiredItemListNull(CheckDict, XmlTreeLevel)
def ValidateMS2(Module, TopXmlTreeLevel): # # Check Header # XmlTreeLevel = TopXmlTreeLevel + ['Header'] CheckDict = Sdict() CheckDict['Name'] = Module.GetName() CheckDict['BaseName'] = Module.GetBaseName() CheckDict['GUID'] = Module.GetGuid() CheckDict['Version'] = Module.GetVersion() IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check ModuleProperties # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] CheckDict = { 'ModuleType': Module.GetModuleType(), 'Path': Module.GetModulePath() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) if not IsValidInstallPath(Module.GetModulePath()): Logger.Error("UPT", FORMAT_INVALID, ERR_FILE_NAME_INVALIDE % Module.GetModulePath()) # # Check ModuleProperties->BootMode # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['BootMode'] for Item in Module.GetBootModeList(): CheckDict = { 'Usage': Item.GetUsage(), 'SupportedBootModes': Item.GetSupportedBootModes() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check ModuleProperties->Event # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['Event'] for Item in Module.GetEventList(): CheckDict = { 'Usage': Item.GetUsage(), 'EventType': Item.GetEventType() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # Check ModuleProperties->Hob # XmlTreeLevel = TopXmlTreeLevel + ['ModuleProperties'] + ['HOB'] for Item in Module.GetHobList(): CheckDict = {'Usage': Item.GetUsage(), 'HobType': Item.GetHobType()} IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # The UDP Specification supports the module type of UEFI_RUNTIME_DRIVER, which is not present in the EDK II INF # File Specification v. 1.23, so UPT must perform the following translation that include the generation of a # [Depex] section. # if Module.ModuleType == "UEFI_RUNTIME_DRIVER": Module.ModuleType = "DXE_RUNTIME_DRIVER" DxeObj = DepexObject() DxeObj.SetDepex("gEfiBdsArchProtocolGuid AND \ngEfiCpuArchProtocolGuid AND\n" + \ "gEfiMetronomeArchProtocolGuid AND \ngEfiMonotonicCounterArchProtocolGuid AND\n" + \ "gEfiRealTimeClockArchProtocolGuid AND \ngEfiResetArchProtocolGuid AND\n" + \ "gEfiRuntimeArchProtocolGuid AND \ngEfiSecurityArchProtocolGuid AND\n" + \ "gEfiTimerArchProtocolGuid AND \ngEfiVariableWriteArchProtocolGuid AND\n" + \ "gEfiVariableArchProtocolGuid AND \ngEfiWatchdogTimerArchProtocolGuid") DxeObj.SetModuleType(['DXE_RUNTIME_DRIVER']) Module.PeiDepex = [] Module.DxeDepex = [] Module.SmmDepex = [] Module.DxeDepex.append(DxeObj) # # Check LibraryClassDefinitions -> LibraryClass # XmlTreeLevel = TopXmlTreeLevel + ['LibraryClassDefinitions'] for Item in Module.GetLibraryClassList(): if Item is None: CheckDict = {'LibraryClass': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = TopXmlTreeLevel + [ 'LibraryClassDefinitions', 'LibraryClass' ] IsLibraryModule = False LibrarySupModList = [] for Item in Module.GetLibraryClassList(): CheckDict = { 'Keyword': Item.GetLibraryClass(), 'Usage': Item.GetUsage() } IsRequiredItemListNull(CheckDict, XmlTreeLevel) # # If the LibraryClass:SupModList is not "UNDEFINED" the LIBRARY_CLASS entry must have the list # appended using the format: # LIBRARY_CLASS = <ClassName> ["|" <Edk2ModuleTypeList>] # # Edk2ModuleTypeList ::= <ModuleType> [" " <ModuleType>]{0,} # <ModuleTypes> ::= {"BASE"} {"SEC"} {"PEI_CORE"} {"PEIM"} # {"DXE_CORE"} {"DXE_DRIVER"} {"SMM_CORE"} # {"DXE_SMM_DRIVER"} {"DXE_RUNTIME_DRIVER"} # {"DXE_SAL_DRIVER"} {"UEFI_DRIVER"} # {"UEFI_APPLICATION"} {"USER_DEFINED"} # if len(Item.SupModuleList) > 0: for SupModule in Item.SupModuleList: if not IsValidInfMoudleType(SupModule): Logger.Error('\nUPT', PARSER_ERROR, ERR_XML_INVALID_LIB_SUPMODLIST % (Item.LibraryClass, str(SupModule)), RaiseError=True) if Item.Usage == 'PRODUCES' or Item.Usage == 'SOMETIMES_PRODUCES': IsLibraryModule = True LibrarySupModList = Item.SupModuleList # # For Library modules (indicated by a LIBRARY_CLASS statement in the [Defines] section) # If the SupModList attribute of the CONSTRUCTOR or DESTRUCTOR element does not match the Supported Module # Types listed after "LIBRARY_CLASS = <Keyword> |", the tool should gracefully exit with an error message # stating that there is a conflict in the module types the CONSTRUCTOR/DESTRUCTOR is to be used with and # the Module types this Library supports. # if IsLibraryModule: for Item in Module.GetExternList(): if Item.Constructor or Item.Destructor: if hasattr(Item, 'SupModList') and len(Item.SupModList) > 0 and \ not IsEqualList(Item.SupModList, LibrarySupModList): Logger.Error( '\nUPT', PARSER_ERROR, ERR_XML_INVALID_EXTERN_SUPMODLIST % (str(Item.SupModList), str(LibrarySupModList)), RaiseError=True) # # If the module is not a library module, the MODULE_TYPE listed in the ModuleSurfaceArea.Header must match the # SupModList attribute. If these conditions cannot be met, the tool must exit gracefully, informing the user # that the EDK II Build system does not currently support the features required by this Module. # if not IsLibraryModule: for Item in Module.GetExternList(): if hasattr(Item, 'SupModList') and len(Item.SupModList) > 0 and \ not IsEqualList(Item.SupModList, [Module.ModuleType]): Logger.Error('\nUPT', PARSER_ERROR, ERR_XML_INVALID_EXTERN_SUPMODLIST_NOT_LIB % (str(Module.ModuleType), str(Item.SupModList)), RaiseError=True) # # Check SourceFiles # XmlTreeLevel = TopXmlTreeLevel + ['SourceFiles'] for Item in Module.GetSourceFileList(): if Item is None: CheckDict = {'Filename': ''} IsRequiredItemListNull(CheckDict, XmlTreeLevel) XmlTreeLevel = TopXmlTreeLevel + ['SourceFiles'] for Item in Module.GetSourceFileList(): CheckDict = {'Filename': Item.GetSourceFile()} IsRequiredItemListNull(CheckDict, XmlTreeLevel) for ItemCount in range(len(Module.GetBinaryFileList())): Item = Module.GetBinaryFileList()[ItemCount] if Item and len(Item.FileNamList ) > 0 and Item.FileNamList[0].FileType == 'FREEFORM': Item.FileNamList[0].FileType = 'SUBTYPE_GUID' Module.GetBinaryFileList()[ItemCount] = Item
def InstallPackageContent(FromPath, ToPath, Package, ContentZipFile, Dep, WorkspaceDir, ModuleList, ReadOnly=False): if Dep: pass Package.FileList = [] if ToPath.startswith("\\") or ToPath.startswith("/"): ToPath = ToPath[1:] if not IsValidInstallPath(ToPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % ToPath) if FromPath.startswith("\\") or FromPath.startswith("/"): FromPath = FromPath[1:] if not IsValidInstallPath(FromPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FromPath) PackageFullPath = os.path.normpath(os.path.join(WorkspaceDir, ToPath)) for MiscFile in Package.GetMiscFileList(): for Item in MiscFile.GetFileList(): FileName = Item.GetURI() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FileName) FromFile = os.path.join(FromPath, FileName) Executable = Item.GetExecutable() ToFile = (os.path.join(PackageFullPath, ConvertPath(FileName))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable) if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) PackageIncludeArchList = [] for Item in Package.GetPackageIncludeFileList(): FileName = Item.GetFilePath() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FileName) FromFile = os.path.join(FromPath, FileName) ToFile = os.path.normpath( os.path.join(PackageFullPath, ConvertPath(FileName))) RetFile = ContentZipFile.UnpackFile(FromFile, ToFile) if RetFile == '': # # a non-exist path in Zipfile will return '', which means an include directory in our case # save the information for later DEC creation usage and also create the directory # PackageIncludeArchList.append( [Item.GetFilePath(), Item.GetSupArchList()]) CreateDirectory(ToFile) continue if ReadOnly: chmod(ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) else: chmod( ToFile, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH) Md5Sigature = md5.new(__FileHookOpen__(str(ToFile), 'rb').read()) Md5Sum = Md5Sigature.hexdigest() if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) Package.SetIncludeArchList(PackageIncludeArchList) for Item in Package.GetStandardIncludeFileList(): FileName = Item.GetFilePath() if FileName.startswith("\\") or FileName.startswith("/"): FileName = FileName[1:] if not IsValidInstallPath(FileName): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % FileName) FromFile = os.path.join(FromPath, FileName) ToFile = os.path.normpath( os.path.join(PackageFullPath, ConvertPath(FileName))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if (ToFile, Md5Sum) not in Package.FileList: Package.FileList.append((ToFile, Md5Sum)) # # Update package # Package.SetPackagePath(Package.GetPackagePath().replace( FromPath, ToPath, 1)) Package.SetFullPath( os.path.normpath( os.path.join(PackageFullPath, ConvertPath(Package.GetName()) + '.dec'))) # # Install files in module # Module = None ModuleDict = Package.GetModuleDict() for ModuleGuid, ModuleVersion, ModuleName, ModulePath in ModuleDict: Module = ModuleDict[ModuleGuid, ModuleVersion, ModuleName, ModulePath] InstallModuleContent(FromPath, ToPath, ModulePath, Module, ContentZipFile, WorkspaceDir, ModuleList, Package, ReadOnly)
def InstallModuleContent(FromPath, NewPath, ModulePath, Module, ContentZipFile, WorkspaceDir, ModuleList, Package=None, ReadOnly=False): if NewPath.startswith("\\") or NewPath.startswith("/"): NewPath = NewPath[1:] if not IsValidInstallPath(NewPath): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % NewPath) NewModuleFullPath = os.path.normpath( os.path.join(WorkspaceDir, NewPath, ConvertPath(ModulePath))) Module.SetFullPath( os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(Module.GetName()) + '.inf'))) Module.FileList = [] for MiscFile in Module.GetMiscFileList(): if not MiscFile: continue for Item in MiscFile.GetFileList(): File = Item.GetURI() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % File) FromFile = os.path.join(FromPath, ModulePath, File) Executable = Item.GetExecutable() ToFile = os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly, Executable) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) for Item in Module.GetSourceFileList(): File = Item.GetSourceFile() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % File) FromFile = os.path.join(FromPath, ModulePath, File) ToFile = os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) for Item in Module.GetBinaryFileList(): FileNameList = Item.GetFileNameList() for FileName in FileNameList: File = FileName.GetFilename() if File.startswith("\\") or File.startswith("/"): File = File[1:] if not IsValidInstallPath(File): Logger.Error("UPT", FORMAT_INVALID, ST.ERR_FILE_NAME_INVALIDE % File) FromFile = os.path.join(FromPath, ModulePath, File) ToFile = os.path.normpath( os.path.join(NewModuleFullPath, ConvertPath(File))) Md5Sum = InstallFile(ContentZipFile, FromFile, ToFile, ReadOnly) if Package and ((ToFile, Md5Sum) not in Package.FileList): Package.FileList.append((ToFile, Md5Sum)) elif Package: continue elif (ToFile, Md5Sum) not in Module.FileList: Module.FileList.append((ToFile, Md5Sum)) InstallModuleContentZipFile(ContentZipFile, FromPath, ModulePath, WorkspaceDir, NewPath, Module, Package, ReadOnly, ModuleList)