#\r
# Copyright (c) 2010 - 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
-# which accompanies this distribution. The full text of the license may be found at\r
-# http://opensource.org/licenses/bsd-license.php\r
-#\r
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
#\r
\r
+from __future__ import absolute_import\r
import Common.LongFilePathOs as os\r
from io import BytesIO\r
from . import StringTable as st\r
import re\r
from Common.LongFilePathSupport import OpenLongFilePath as open\r
from struct import *\r
-from Common.DataType import MAX_SIZE_TYPE, MAX_VAL_TYPE\r
+from Common.DataType import MAX_SIZE_TYPE, MAX_VAL_TYPE, TAB_STAR\r
import Common.EdkLogger as EdkLogger\r
import Common.BuildToolError as BuildToolError\r
\r
# for both hexadecimal and decimal.\r
#\r
def _GenOffsetValue(self):\r
- if self.PcdOffset != "*" :\r
+ if self.PcdOffset != TAB_STAR:\r
try:\r
self.PcdBinOffset = int (self.PcdOffset)\r
except:\r
EdkLogger.error("BPDG", BuildToolError.RESOURCE_OVERFLOW,\r
"PCD value string %s is exceed to size %d(File: %s Line: %s)" % (ValueString, Size, self.FileName, self.Lineno))\r
try:\r
- self.PcdValue = pack('%ds' % Size, ValueString)\r
+ self.PcdValue = pack('%ds' % Size, ValueString.encode('utf-8'))\r
except:\r
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID,\r
"Invalid size or value for PCD %s to pack(File: %s Line: %s)." % (self.PcdCName, self.FileName, self.Lineno))\r
\r
##\r
# Parser the input file which is generated by the build tool. Convert the value of each pcd's\r
- # from string to it's real format. Also remove the useless line in the input file.\r
+ # from string to its real format. Also remove the useless line in the input file.\r
#\r
def ParserInputFile (self):\r
count = 0\r
Alignment = 1\r
\r
PCD.Alignment = Alignment\r
- if PCD.PcdOffset != '*':\r
+ if PCD.PcdOffset != TAB_STAR:\r
if PCD.PcdOccupySize % Alignment != 0:\r
if PCD.PcdUnpackValue.startswith("{"):\r
EdkLogger.warn("BPDG", "The offset value of PCD %s is not 8-byte aligned!" %(PCD.PcdCName), File=self.InputFileName)\r
EdkLogger.error("BPDG", BuildToolError.FORMAT_INVALID, 'The offset value of PCD %s should be %s-byte aligned.' % (PCD.PcdCName, Alignment))\r
else:\r
if PCD.PcdOccupySize % Alignment != 0:\r
- PCD.PcdOccupySize = (PCD.PcdOccupySize / Alignment + 1) * Alignment\r
+ PCD.PcdOccupySize = (PCD.PcdOccupySize // Alignment + 1) * Alignment\r
\r
PackSize = PCD.PcdOccupySize\r
if PCD._IsBoolean(PCD.PcdValue, PCD.PcdSize):\r
def FormatFileLine (self) :\r
\r
for eachPcd in self.FileLinesList :\r
- if eachPcd.PcdOffset != '*' :\r
+ if eachPcd.PcdOffset != TAB_STAR :\r
# Use pcd's Offset value as key, and pcd's Value as value\r
self.PcdFixedOffsetSizeList.append(eachPcd)\r
else :\r
def FixVpdOffset (self):\r
# At first, the offset should start at 0\r
# Sort fixed offset list in order to find out where has free spaces for the pcd's offset\r
- # value is "*" to insert into.\r
+ # value is TAB_STAR to insert into.\r
\r
self.PcdFixedOffsetSizeList.sort(key=lambda x: x.PcdBinOffset)\r
\r
#\r
- # Sort the un-fixed pcd's offset by it's size.\r
+ # Sort the un-fixed pcd's offset by its size.\r
#\r
self.PcdUnknownOffsetList.sort(key=lambda x: x.PcdBinSize)\r
\r
self.PcdUnknownOffsetList[index+i -1 ], self.PcdUnknownOffsetList[index+i] = self.PcdUnknownOffsetList[index+i], self.PcdUnknownOffsetList[index+i -1]\r
\r
#\r
- # Process all Offset value are "*"\r
+ # Process all Offset value are TAB_STAR\r
#\r
if (len(self.PcdFixedOffsetSizeList) == 0) and (len(self.PcdUnknownOffsetList) != 0) :\r
# The offset start from 0\r
NowOffset = 0\r
for Pcd in self.PcdUnknownOffsetList :\r
if NowOffset % Pcd.Alignment != 0:\r
- NowOffset = (NowOffset/ Pcd.Alignment + 1) * Pcd.Alignment\r
+ NowOffset = (NowOffset// Pcd.Alignment + 1) * Pcd.Alignment\r
Pcd.PcdBinOffset = NowOffset\r
Pcd.PcdOffset = str(hex(Pcd.PcdBinOffset))\r
NowOffset += Pcd.PcdOccupySize\r
eachUnfixedPcd = self.PcdUnknownOffsetList[countOfUnfixedList]\r
needFixPcdSize = eachUnfixedPcd.PcdOccupySize\r
# Not been fixed\r
- if eachUnfixedPcd.PcdOffset == '*' :\r
+ if eachUnfixedPcd.PcdOffset == TAB_STAR :\r
if LastOffset % eachUnfixedPcd.Alignment != 0:\r
- LastOffset = (LastOffset / eachUnfixedPcd.Alignment + 1) * eachUnfixedPcd.Alignment\r
+ LastOffset = (LastOffset // eachUnfixedPcd.Alignment + 1) * eachUnfixedPcd.Alignment\r
# The offset un-fixed pcd can write into this free space\r
if needFixPcdSize <= (NowOffset - LastOffset) :\r
# Change the offset value of un-fixed pcd\r
# Usually it will not enter into this thunk, if so, means it overlapped.\r
else :\r
EdkLogger.error("BPDG", BuildToolError.ATTRIBUTE_NOT_AVAILABLE,\r
- "The offset value definition has overlapped at pcd: %s, it's offset is: %s, in file: %s line: %s" % \\r
+ "The offset value definition has overlapped at pcd: %s, its offset is: %s, in file: %s line: %s" % \\r
(eachFixedPcd.PcdCName, eachFixedPcd.PcdOffset, eachFixedPcd.InputFileName, eachFixedPcd.Lineno),\r
None)\r
FixOffsetSizeListCount += 1\r
\r
NeedFixPcd.PcdBinOffset = LastPcd.PcdBinOffset + LastPcd.PcdOccupySize\r
if NeedFixPcd.PcdBinOffset % NeedFixPcd.Alignment != 0:\r
- NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset / NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment\r
+ NeedFixPcd.PcdBinOffset = (NeedFixPcd.PcdBinOffset // NeedFixPcd.Alignment + 1) * NeedFixPcd.Alignment\r
\r
NeedFixPcd.PcdOffset = str(hex(NeedFixPcd.PcdBinOffset))\r
\r
#Open an VPD file to process\r
\r
try:\r
- fVpdFile = open(BinFileName, "wb", 0)\r
+ fVpdFile = open(BinFileName, "wb")\r
except:\r
# Open failed\r
EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" % self.VpdFileName, None)\r
EdkLogger.error("BPDG", BuildToolError.FILE_OPEN_FAILURE, "File open failed for %s" % self.MapFileName, None)\r
\r
# Use a instance of BytesIO to cache data\r
- fStringIO = BytesIO('')\r
+ fStringIO = BytesIO()\r
\r
# Write the header of map file.\r
try :\r
# Write Vpd binary file\r
fStringIO.seek (eachPcd.PcdBinOffset)\r
if isinstance(eachPcd.PcdValue, list):\r
- ValueList = [chr(Item) for Item in eachPcd.PcdValue]\r
- fStringIO.write(''.join(ValueList))\r
+ for i in range(len(eachPcd.PcdValue)):\r
+ Value = eachPcd.PcdValue[i:i + 1]\r
+ if isinstance(bytes(Value), str):\r
+ fStringIO.write(chr(Value[0]))\r
+ else:\r
+ fStringIO.write(bytes(Value))\r
else:\r
fStringIO.write (eachPcd.PcdValue)\r
\r