Skip to content

Commit

Permalink
treewide: use print function instead of statement
Browse files Browse the repository at this point in the history
This enables better compat between python2.7 and python3.x

Without this change, building with python3.x (python3.5 tested) as
/usr/bin/python will result in the following error:

File: "sbe/src/build/security/securityRegListGen.py", line 64
    -v, --verbose            enable verbose traces"
                                                  ^
SyntaxError: Missing parentheses in call to 'print'

Signed-off-by: Marty E. Plummer <hanetzer@startmail.com>

Change-Id: Id617f54096fca5cc5fcd829767595a85350e343d
Reviewed-on: http://rchgit01.rchland.ibm.com/gerrit1/89618
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Reviewed-by: RAJA DAS <rajadas2@in.ibm.com>
  • Loading branch information
hanetzer authored and RAJA DAS committed Jan 16, 2020
1 parent 54f3205 commit e0e6c72
Show file tree
Hide file tree
Showing 68 changed files with 644 additions and 585 deletions.
31 changes: 16 additions & 15 deletions src/boot/sbeCompression.py
Expand Up @@ -23,6 +23,7 @@
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
from __future__ import print_function
import os
import subprocess
import re
Expand All @@ -40,17 +41,17 @@ def compress(inputFile, compressedFile):
try:
f = open(inputFile, "rb")
except IOError as e :
print "I/O error File for File to be compressed."
print("I/O error File for File to be compressed.")
sys.exit(1)

try:
fW = open(compressedFile, "wb")
except IOError as e :
print "I/O error File for compressed file."
print("I/O error File for compressed file.")
sys.exit(1)

if os.stat(inputFile).st_size < 4 :
print "File is less than four bytes."
print("File is less than four bytes.")
sys.exit(1)

instDict = dict()
Expand Down Expand Up @@ -132,21 +133,21 @@ def compress(inputFile, compressedFile):
fW.close()

def usage():
print "usage: sbeCompression.py [-h] [-l <path>] [-i <image>]"
print "SBE Compression Parser"
print "Arguments:"
print "-h, --help\t\tshow this help message and exit"
print "-l, --imageLoc\t\tSeeprom Binary Location"
print "-i, --image\t\tSeeprom Binary"
print "-p, --p9_xip_tool\t\tp9_xip_tool path"
print("usage: sbeCompression.py [-h] [-l <path>] [-i <image>]")
print("SBE Compression Parser")
print("Arguments:")
print("-h, --help\t\tshow this help message and exit")
print("-l, --imageLoc\t\tSeeprom Binary Location")
print("-i, --image\t\tSeeprom Binary")
print("-p, --p9_xip_tool\t\tp9_xip_tool path")
return 1

def main( argv ):

try:
opts, args = getopt.getopt(argv[1:], "l:i:p:h", ['imageLoc=', 'image=', 'p9_xip_tool=', 'help'])
except getopt.GetoptError as err:
print str(err)
print(str(err))
usage()
exit(1)

Expand All @@ -169,14 +170,14 @@ def main( argv ):
cmd1 = "cp " + imagePath + "/" + image + " " + imagePath + "/" + image + ".orig"
rc = os.system(cmd1)
if rc:
print "Unable to make copy of seeprom binary"
print("Unable to make copy of seeprom binary")
sys.exit(1)

#Extract base from SEEPROM binary.
cmd2 = p9_xip_tool + " " + imagePath + "/" + image + " extract .base " + imagePath + "/" + image + ".base"
rc = os.system(cmd2)
if rc:
print "Unable to extract the base from seeprom binary"
print("Unable to extract the base from seeprom binary")
sys.exit(1)

#Compress the base section
Expand All @@ -186,14 +187,14 @@ def main( argv ):
cmd3 = p9_xip_tool + " " + imagePath + "/" + image + " delete .base"
rc = os.system(cmd3)
if rc:
print "Unable to delete base section from seeprom binary"
print("Unable to delete base section from seeprom binary")
sys.exit(1)

#Append the base section from SEEPEOM binary.
cmd4 = p9_xip_tool + " " + imagePath + "/" + image + " append .base " + imagePath + "/" + image + ".base.compressed"
rc = os.system(cmd4)
if rc:
print "Unable to append the base section"
print("Unable to append the base section")
sys.exit(1)

if __name__ == "__main__":
Expand Down
9 changes: 5 additions & 4 deletions src/build/parsAndCutElf.py
Expand Up @@ -23,6 +23,7 @@
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
from __future__ import print_function
import os
import subprocess
import re
Expand All @@ -36,7 +37,7 @@ def parserElf(argv):
outdir = argv[2]
img = argv[3]
except:
print "Missing argument : arg[0] ddlevel; arg[1] output directory; arg[2] img (seeprom/pibmem)"
print("Missing argument : arg[0] ddlevel; arg[1] output directory; arg[2] img (seeprom/pibmem)")
exit(-1)
SBE_OUT = outdir+"/sbe_"+img+"_"+ddlevel+".out"
SBE_BIN = outdir+"/sbe_"+img+"_"+ddlevel+".bin"
Expand All @@ -53,7 +54,7 @@ def parserElf(argv):
if( (line.find(firstSection) != -1) ):
tokens = line.split();
startSize = int( tokens[5], 16 )
print startSize
print(startSize)
break;

# Get the location of sbe end
Expand All @@ -64,15 +65,15 @@ def parserElf(argv):
endSize = int( tokens[0], 16 );
break;

print endSize;
print(endSize)
if( (startSize == 0) or (endSize == 0)):
exit(-1)

# cut the image
cmd1 = "dd skip=" + str(startSize) + " count=" + str(endSize) + " if="+SBE_OUT+" of="+SBE_BIN+" bs=1"
rc = os.system(cmd1)
if ( rc ):
print "ERROR running %s: %d "%( cmd1, rc )
print("ERROR running %s: %d "%( cmd1, rc ))
exit(-1)

parserElf(sys.argv)
9 changes: 5 additions & 4 deletions src/build/sbeOpDistribute.py
Expand Up @@ -22,24 +22,25 @@
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
from __future__ import print_function
import os
import sys
import getopt

def usage():
print "usage:sbeOpDistribute.py [--sbe_binary_dir] <sbe binary path> [--img_dir] <images path>"
print("usage:sbeOpDistribute.py [--sbe_binary_dir] <sbe binary path> [--img_dir] <images path>")

def run_system_cmd(cmd):
print 'Cmd:<'+cmd+'>'
print('Cmd:<'+cmd+'>')
if(os.system(cmd)):
print "ERROR running cmd:<"+cmd+">"
print("ERROR running cmd:<"+cmd+">")
exit(1)

def main(argv):
try:
opts, args = getopt.getopt(sys.argv[1:], "", ['sbe_binary_dir=', 'img_dir=', 'buildSbePart=', 'hw_ref_image=', 'sbe_binary_filename=', 'scratch_dir=', 'install', 'help'])
except getopt.GetoptError as err:
print str(err)
print(str(err))
usage()
exit(1)

Expand Down
94 changes: 48 additions & 46 deletions src/build/security/securityRegListGen.py
Expand Up @@ -22,6 +22,7 @@
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
from __future__ import print_function
import getopt
import sys
import os
Expand Down Expand Up @@ -52,29 +53,30 @@
TAG_NAME_BLACKLIST = 'read_blacklist'

def usage():
print "usage: p9_security_list_gen.py [-h] [-f <security_list_path>] [-0 <output directory] [i] [-d] [-v]\n\
print(
'''usage: p9_security_list_gen.py [-h] [-f <security_list_path>] [-0 <output directory] [i] [-d] [-v]
arguments:\n\
-h, --help show this help message and exit\n\
-f, --file path to the security list csv file\n\
-o, --output output directory\n\
-w, --whitelist print whitelist read from csv\n\
-b, --blacklist print blacklist read from csv\n\
-g, --greylist print greylist read from csv\n\
-i, --info get version info of the security list\n\
-d, --debug enable debug traces\n\
-v, --verbose enable verbose traces"
-h, --help show this help message and exit
-f, --file path to the security list csv file
-o, --output output directory
-w, --whitelist print whitelist read from csv
-b, --blacklist print blacklist read from csv
-g, --greylist print greylist read from csv
-i, --info get version info of the security list
-d, --debug enable debug traces
-v, --verbose enable verbose traces''')

def exit(error, msg = ''):
if(error == SUCCESS):
return 0
elif(error == INVALID_USAGE):
print msg
print(msg)
usage()
elif(error == PRINT_AND_EXIT):
print msg
print(msg)
else:
if(DEBUG):
print "unknown error:exiting"
print("unknown error:exiting")
sys.exit(1)

def remove_duplicates(xlist):
Expand Down Expand Up @@ -466,16 +468,16 @@ def get_tables(id, list):
# for each range and key combination in order
table3 += temp_keys
if(VERBOSE):
print id+" table3 keys len ["+s_list_len(table3)+"]"
print(id+" table3 keys len ["+s_list_len(table3)+"]")

if(VERBOSE):
print id,"table1:", ['0x%04x:0x%02x' % ele for ele in table1]
print id,"table2:", ['0x%02x:0x%02x' % ele for ele in table2]
print id,"table3:", ['0x%04x' % ele for ele in table3]
print(id,"table1:", ['0x%04x:0x%02x' % ele for ele in table1])
print(id,"table2:", ['0x%02x:0x%02x' % ele for ele in table2])
print(id,"table3:", ['0x%04x' % ele for ele in table3])
if(DEBUG):
print id,"table1 len ["+s_list_len(table1)+"]"
print id,"table2 len ["+s_list_len(table2)+"]"
print id+" table3 len ["+s_list_len(table3)+"]"
print(id,"table1 len ["+s_list_len(table1)+"]")
print(id,"table2 len ["+s_list_len(table2)+"]")
print(id+" table3 len ["+s_list_len(table3)+"]")

return (table1, table2, table3)

Expand All @@ -491,8 +493,8 @@ def s_table1_gen(id, table):
str_table1 += '\n'
str_table1 = str_table1[:-1]
if(VERBOSE):
print id+" generated table1"
print str_table1
print(id+" generated table1")
print(str_table1)
return str_table1

def s_table2_gen(id, table):
Expand All @@ -505,8 +507,8 @@ def s_table2_gen(id, table):
str_table2 += '\n'
str_table2 = str_table2[:-1]
if(VERBOSE):
print id+" generated table2"
print str_table2
print(id+" generated table2")
print(str_table2)
return str_table2

def s_table3_gen(id, table):
Expand All @@ -519,8 +521,8 @@ def s_table3_gen(id, table):
str_table3 += '\n'
str_table3 = str_table3[:-1]
if(VERBOSE):
print id+" generated table3"
print str_table3
print(id+" generated table3")
print(str_table3)
return str_table3

def s_greylist_table_gen( greyList):
Expand All @@ -530,8 +532,8 @@ def s_greylist_table_gen( greyList):
str_table += '{0x%08x, 0x%016xull}, ' % (ele[0], ele[1])
str_table = str_table[:-1]
if(VERBOSE):
print " greylist table"
print str_table
print(" greylist table")
print(str_table)
return str_table
def main(argv):

Expand Down Expand Up @@ -578,8 +580,8 @@ def main(argv):
GEN_FILE = str(arg)+"/"+GEN_FILE

if(DEBUG):
print "file ["+str(SECURITY_LIST)+"]"
print "output ["+str(GEN_FILE)+"]"
print("file ["+str(SECURITY_LIST)+"]")
print("output ["+str(GEN_FILE)+"]")

# Read the security list file
version = 'unknown'
Expand All @@ -599,7 +601,7 @@ def main(argv):
base_addr = base_addr[len(base_addr)-8:]
base_addr = int(base_addr, 16)
if(VERBOSE):
print "base["+'0x%08x' % base_addr + "]"
print("base["+'0x%08x' % base_addr + "]")
bit_mask = row[TAG_BIT_MASK].strip()
if not bit_mask:
bit_mask = 0
Expand All @@ -612,9 +614,9 @@ def main(argv):
exit(PRINT_AND_EXIT, "Missing chiplet id range")
if(chiplet_range[0].strip().lower() != '0x00'):
if(chiplet_range[0].strip().lower() != '0x%02x' % (get_chiplet(base_addr))):
print "base_addr",hex(base_addr)
print "get_chiplet(base_addr)",hex(get_chiplet(base_addr))
print "chiplet_range[0]", chiplet_range[0]
print("base_addr",hex(base_addr))
print("get_chiplet(base_addr)",hex(get_chiplet(base_addr)))
print("chiplet_range[0]", chiplet_range[0])
exit(PRINT_AND_EXIT, "Base address is not consistent")
base_addr = base_addr & 0x00FFFFFF
chiplet_range = [int(ele, 16) for ele in chiplet_range]
Expand All @@ -625,29 +627,29 @@ def main(argv):
expanded_line = [(base_addr + ele) for ele in expanded_range]
expanded_line = get_effective_address(row[TAG_CHIPLET], expanded_line)
if(VERBOSE):
print s_list_hex("range:", expanded_range, 8)
print(s_list_hex("range:", expanded_range, 8))
if(row[TAG_TYPE].strip().lower() == TAG_NAME_GREYLIST):
if(( bit_mask == 0 ) or ( bit_mask == 0xffffffffffffffff)):
exit(PRINT_AND_EXIT, "Wrong mask for Greylist")
greylist_line = expanded_line
if(VERBOSE):
print s_list_hex("greylist_line:", greylist_line, 8)
print "mask:", bit_mask
print(s_list_hex("greylist_line:", greylist_line, 8))
print("mask:", bit_mask)
for ele in greylist_line:
greylist.append((ele, bit_mask))
elif(row[TAG_TYPE].strip().lower() == TAG_NAME_WHITELIST):
whitelist_line = expanded_line
if(VERBOSE):
print s_list_hex("whitelist_line:", whitelist_line, 8)
print(s_list_hex("whitelist_line:", whitelist_line, 8))
whitelist += whitelist_line
elif(row[TAG_TYPE].strip().lower() == TAG_NAME_BLACKLIST):
blacklist_line = expanded_line
if(VERBOSE):
print s_list_hex("blacklist_line:", blacklist_line, 8)
print(s_list_hex("blacklist_line:", blacklist_line, 8))
blacklist += blacklist_line

except:
print "Error in line ["+str(idx+2)+"]"
print("Error in line ["+str(idx+2)+"]")
exit(PRINT_AND_EXIT, sys.exc_info()[0])

whitelist = remove_duplicates(whitelist)
Expand All @@ -669,13 +671,13 @@ def main(argv):
exit(PRINT_AND_EXIT, greylist)

if(VERBOSE):
print s_list_hex("whitelist:", whitelist, 8)
print s_list_hex("blacklist:", blacklist, 8)
print(s_list_hex("whitelist:", whitelist, 8))
print(s_list_hex("blacklist:", blacklist, 8))
if(DEBUG):
print "security list version ["+version+"]"
print "Whitelist len ["+s_list_len(whitelist)+"]"
print "Blacklist len ["+s_list_len(blacklist)+"]"
print "Greylist len ["+s_list_len(greylist)+"]"
print("security list version ["+version+"]")
print("Whitelist len ["+s_list_len(whitelist)+"]")
print("Blacklist len ["+s_list_len(blacklist)+"]")
print("Greylist len ["+s_list_len(greylist)+"]")

whitelist_tables = get_tables("Whitelist", whitelist)
blacklist_tables = get_tables("Blacklist", blacklist)
Expand Down
4 changes: 2 additions & 2 deletions src/build/updateBuildTag.py
Expand Up @@ -23,7 +23,7 @@
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG

from __future__ import print_function
import os
import sys
import subprocess
Expand All @@ -38,7 +38,7 @@ def updateBuildTag(argv):
image_dir = argv[2]
seeprom_name = argv[3]
except:
print "Missing Xip Tool Path/Image Directory/Seeprom Binary Name"
print("Missing Xip Tool Path/Image Directory/Seeprom Binary Name")
exit(-1)

# Commandline cmds getting formed here
Expand Down

0 comments on commit e0e6c72

Please sign in to comment.