## @file\r
# process FV image section generation\r
#\r
-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
#\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
##\r
# Import Modules\r
#\r
-import Section\r
-import StringIO\r
-from Ffs import Ffs\r
+from __future__ import absolute_import\r
+from . import Section\r
+from io import BytesIO\r
+from .Ffs import SectionSuffix\r
import subprocess\r
-from GenFdsGlobalVariable import GenFdsGlobalVariable\r
+from .GenFdsGlobalVariable import GenFdsGlobalVariable\r
import Common.LongFilePathOs as os\r
from CommonDataClass.FdfClass import FvImageSectionClassObject\r
from Common import EdkLogger\r
from Common.BuildToolError import *\r
+from Common.DataType import *\r
\r
## generate FV image section\r
#\r
# @param Dict dictionary contains macro and its value\r
# @retval tuple (Generated file name, section alignment)\r
#\r
- def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}):\r
+ def GenSection(self, OutputPath, ModuleName, SecNum, KeyStringList, FfsInf = None, Dict = {}, IsMakefile = False):\r
\r
OutputFileList = []\r
- if self.FvFileType != None:\r
+ if self.FvFileType is not None:\r
FileList, IsSect = Section.Section.GetFileList(FfsInf, self.FvFileType, self.FvFileExtension)\r
if IsSect :\r
return FileList, self.Alignment\r
for FvFileName in FileList:\r
FvAlignmentValue = 0\r
if os.path.isfile(FvFileName):\r
- FvFileObj = open (FvFileName,'r+b')\r
+ FvFileObj = open (FvFileName, 'rb')\r
FvFileObj.seek(0)\r
# PI FvHeader is 0x48 byte\r
FvHeaderBuffer = FvFileObj.read(0x48)\r
# FV alignment position.\r
- FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
+ if isinstance(FvHeaderBuffer[0x2E], str):\r
+ FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)\r
+ else:\r
+ FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)\r
FvFileObj.close()\r
if FvAlignmentValue > MaxFvAlignment:\r
MaxFvAlignment = FvAlignmentValue\r
\r
- OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + Num + Ffs.SectionSuffix.get("FV_IMAGE"))\r
- GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
+ OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + Num + SectionSuffix.get("FV_IMAGE"))\r
+ GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
OutputFileList.append(OutputFile)\r
\r
# MaxFvAlignment is larger than or equal to 1K\r
if MaxFvAlignment >= 0x400:\r
- if MaxFvAlignment >= 0x10000:\r
- #The max alignment supported by FFS is 64K.\r
- self.Alignment = "64K"\r
+ if MaxFvAlignment >= 0x100000:\r
+ #The max alignment supported by FFS is 16M.\r
+ if MaxFvAlignment >= 0x1000000:\r
+ self.Alignment = "16M"\r
+ else:\r
+ self.Alignment = str(MaxFvAlignment // 0x100000) + "M"\r
else:\r
- self.Alignment = str (MaxFvAlignment / 0x400) + "K"\r
+ self.Alignment = str (MaxFvAlignment // 0x400) + "K"\r
else:\r
# MaxFvAlignment is less than 1K\r
self.Alignment = str (MaxFvAlignment)\r
#\r
# Generate Fv\r
#\r
- if self.FvName != None:\r
- Buffer = StringIO.StringIO('')\r
+ if self.FvName is not None:\r
+ Buffer = BytesIO()\r
Fv = GenFdsGlobalVariable.FdfParser.Profile.FvDict.get(self.FvName)\r
- if Fv != None:\r
+ if Fv is not None:\r
self.Fv = Fv\r
- FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict)\r
- if Fv.FvAlignment != None:\r
- if self.Alignment == None:\r
+ if not self.FvAddr and self.Fv.BaseAddress:\r
+ self.FvAddr = self.Fv.BaseAddress\r
+ FvFileName = Fv.AddToBuffer(Buffer, self.FvAddr, MacroDict = Dict, Flag=IsMakefile)\r
+ if Fv.FvAlignment is not None:\r
+ if self.Alignment is None:\r
self.Alignment = Fv.FvAlignment\r
else:\r
if GenFdsGlobalVariable.GetAlignment (Fv.FvAlignment) > GenFdsGlobalVariable.GetAlignment (self.Alignment):\r
self.Alignment = Fv.FvAlignment\r
else:\r
- if self.FvFileName != None:\r
+ if self.FvFileName is not None:\r
FvFileName = GenFdsGlobalVariable.ReplaceWorkspaceMacro(self.FvFileName)\r
if os.path.isfile(FvFileName):\r
- FvFileObj = open (FvFileName,'r+b')\r
+ FvFileObj = open (FvFileName, 'rb')\r
FvFileObj.seek(0)\r
# PI FvHeader is 0x48 byte\r
FvHeaderBuffer = FvFileObj.read(0x48)\r
# FV alignment position.\r
- FvAlignmentValue = 1 << (ord (FvHeaderBuffer[0x2E]) & 0x1F)\r
+ if isinstance(FvHeaderBuffer[0x2E], str):\r
+ FvAlignmentValue = 1 << (ord(FvHeaderBuffer[0x2E]) & 0x1F)\r
+ else:\r
+ FvAlignmentValue = 1 << (FvHeaderBuffer[0x2E] & 0x1F)\r
# FvAlignmentValue is larger than or equal to 1K\r
if FvAlignmentValue >= 0x400:\r
- if FvAlignmentValue >= 0x10000:\r
- #The max alignment supported by FFS is 64K.\r
- self.Alignment = "64K"\r
+ if FvAlignmentValue >= 0x100000:\r
+ #The max alignment supported by FFS is 16M.\r
+ if FvAlignmentValue >= 0x1000000:\r
+ self.Alignment = "16M"\r
+ else:\r
+ self.Alignment = str(FvAlignmentValue // 0x100000) + "M"\r
else:\r
- self.Alignment = str (FvAlignmentValue / 0x400) + "K"\r
+ self.Alignment = str (FvAlignmentValue // 0x400) + "K"\r
else:\r
# FvAlignmentValue is less than 1K\r
self.Alignment = str (FvAlignmentValue)\r
FvFileObj.close()\r
+ else:\r
+ if len (mws.getPkgPath()) == 0:\r
+ EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in WORKSPACE: %s" % self.FvFileName, GenFdsGlobalVariable.WorkSpaceDir)\r
+ else:\r
+ EdkLogger.error("GenFds", FILE_NOT_FOUND, "%s is not found in packages path:\n\t%s" % (self.FvFileName, '\n\t'.join(mws.getPkgPath())))\r
+\r
else:\r
EdkLogger.error("GenFds", GENFDS_ERROR, "FvImageSection Failed! %s NOT found in FDF" % self.FvName)\r
\r
#\r
# Prepare the parameter of GenSection\r
#\r
- OutputFile = os.path.join(OutputPath, ModuleName + 'SEC' + SecNum + Ffs.SectionSuffix.get("FV_IMAGE"))\r
- GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE')\r
+ OutputFile = os.path.join(OutputPath, ModuleName + SUP_MODULE_SEC + SecNum + SectionSuffix.get("FV_IMAGE"))\r
+ GenFdsGlobalVariable.GenerateSection(OutputFile, [FvFileName], 'EFI_SECTION_FIRMWARE_VOLUME_IMAGE', IsMakefile=IsMakefile)\r
OutputFileList.append(OutputFile)\r
\r
return OutputFileList, self.Alignment\r