Skip to content

Commit

Permalink
Fix or waive Python lint errors and warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Pirmin Vogel <vogelpi@lowrisc.org>
  • Loading branch information
vogelpi committed Apr 1, 2024
1 parent f4c2bb9 commit d01864e
Show file tree
Hide file tree
Showing 17 changed files with 91 additions and 104 deletions.
4 changes: 2 additions & 2 deletions hw/formal/tools/vcformal/parse-formal-report.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_summary(str_buffer):
summary["pass_rate"] = format_percentage(summary["proven"],
summary["cex"] + summary["undetermined"])
summary["cov_rate"] = format_percentage(summary["covered"],
summary["unreachable"])
summary["unreachable"])

return summary

Expand Down Expand Up @@ -125,7 +125,7 @@ def get_cov_results(logpath, dut_name):
else:
cov_results[key] = "N/A"
log.warning("Parse %s coverage error. Expect one matching value, get %s",
key, item)
key, item)
return cov_results

except IOError as err:
Expand Down
62 changes: 29 additions & 33 deletions hw/ip/clkmgr/util/clkmgr_gen_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,33 @@
r"""Clock Manager Generator
"""

import argparse
import logging as log
import sys
import subprocess
from collections import OrderedDict
from io import StringIO
from pathlib import Path

import hjson
from mako import exceptions
from mako.template import Template


# Common header for generated files
def main():

current = Path(__file__).parent.absolute()

hjson_tpl = Template(filename=str(current / '../data/clkmgr.hjson.tpl'))
rtl_tpl = Template(filename=str(current / '../data/clkmgr.sv.tpl'))
pkg_tpl = Template(filename=str(current / '../data/clkmgr_pkg.sv.tpl'))
rtl_tpl = Template(filename=str(current / '../data/clkmgr.sv.tpl'))
pkg_tpl = Template(filename=str(current / '../data/clkmgr_pkg.sv.tpl'))

hjson_out = current / '../data/clkmgr.hjson'
rtl_out = current / '../rtl/clkmgr.sv'
pkg_out = current / '../rtl/clkmgr_pkg.sv'
rtl_out = current / '../rtl/clkmgr.sv'
pkg_out = current / '../rtl/clkmgr_pkg.sv'

cfgpath = current / '../data/clkmgr.cfg.example.hjson'
cfgpath = current / '../data/clkmgr.cfg.example.hjson'

try:
with open(cfgpath, 'r') as cfg:
topcfg = hjson.load(cfg,use_decimal=True,object_pairs_hook=OrderedDict)
topcfg = hjson.load(cfg, use_decimal=True, object_pairs_hook=OrderedDict)
except ValueError:
log.error("{} not found".format(cfgpath))
raise SystemExit(sys.exc_info()[1])
Expand All @@ -48,45 +45,44 @@ def main():
sw_clks = OrderedDict()
hint_clks = OrderedDict()

ft_clks = {clk:src for grp in grps for (clk,src) in grp['clocks'].items()
if grp['name'] == 'powerup'}
ft_clks = {clk: src for grp in grps for (clk, src) in grp['clocks'].items()
if grp['name'] == 'powerup'}

# root-gate clocks
rg_clks = {clk:src for grp in grps for (clk,src) in grp['clocks'].items()
if grp['name'] != 'powerup' and grp['sw_cg'] == 'no'}
rg_clks = {clk: src for grp in grps for (clk, src) in grp['clocks'].items()
if grp['name'] != 'powerup' and grp['sw_cg'] == 'no'}

# direct sw control clocks
sw_clks = {clk:src for grp in grps for (clk,src) in grp['clocks'].items()
if grp['sw_cg'] == 'yes'}
sw_clks = {clk: src for grp in grps for (clk, src) in grp['clocks'].items()
if grp['sw_cg'] == 'yes'}

# sw hint clocks
hint_clks = {clk:src for grp in grps for (clk,src) in grp['clocks'].items()
hint_clks = {clk: src for grp in grps for (clk, src) in grp['clocks'].items()
if grp['sw_cg'] == 'hint'}


# generate hjson
hjson_out.write_text(
hjson_tpl.render(cfg=topcfg,
ft_clks=ft_clks,
rg_clks=rg_clks,
sw_clks=sw_clks,
hint_clks=hint_clks))
hjson_tpl.render(cfg=topcfg,
ft_clks=ft_clks,
rg_clks=rg_clks,
sw_clks=sw_clks,
hint_clks=hint_clks))

# generate rtl package
pkg_out.write_text(
pkg_tpl.render(cfg=topcfg,
ft_clks=ft_clks,
rg_clks=rg_clks,
sw_clks=sw_clks,
hint_clks=hint_clks))
pkg_tpl.render(cfg=topcfg,
ft_clks=ft_clks,
rg_clks=rg_clks,
sw_clks=sw_clks,
hint_clks=hint_clks))

# generate top level
rtl_out.write_text(
rtl_tpl.render(cfg=topcfg,
ft_clks=ft_clks,
rg_clks=rg_clks,
sw_clks=sw_clks,
hint_clks=hint_clks))
rtl_tpl.render(cfg=topcfg,
ft_clks=ft_clks,
rg_clks=rg_clks,
sw_clks=sw_clks,
hint_clks=hint_clks))


if __name__ == "__main__":
Expand Down
5 changes: 2 additions & 3 deletions hw/ip/flash_ctrl/util/flash_ctrl_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def check_values(self):
(self.pages_per_bank <= Flash.max_pages_per_bank))

if not pow2_check:
raise ValueError(f'flash power of 2 check failed. A supplied parameter '
raise ValueError('flash power of 2 check failed. A supplied parameter '
'is not power of 2')

if not limit_check:
raise ValueError(f'flash number of banks and pages per bank too large')
raise ValueError('flash number of banks and pages per bank too large')


# Common header for generated files
Expand All @@ -86,7 +86,6 @@ def main():
log.error("{} not found".format(cfgpath))
raise SystemExit(sys.exc_info()[1])


flash_mems = [module for module in topcfg['module'] if module['type'] == 'flash_ctrl']
if len(flash_mems) > 1:
log.error("This design does not currently support multiple flashes")
Expand Down
6 changes: 2 additions & 4 deletions hw/ip/hmac/model/hmac_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import hashlib # for comparison
import logging as log
import sys
from array import array
from io import StringIO

import numpy as np

Expand Down Expand Up @@ -57,7 +55,7 @@ def sha256(msg: bin) -> bin:

log.info("Padded message: %s" % (binascii.b2a_hex(new_msg)))
# Convert byte to 32bit array
#w_array = np.array(new_msg, dtype=np.uint32)
# w_array = np.array(new_msg, dtype=np.uint32)
dt = np.dtype(np.uint32)
dt = dt.newbyteorder('>') # bigendian
w_array = np.frombuffer(new_msg, dtype=dt)
Expand All @@ -68,7 +66,7 @@ def sha256(msg: bin) -> bin:
# create w
# 16 entry x 32 bit word
w = w_array[i:i + 16]
#for j in range(16):
# for j in range(16):

[a, b, c, d, e, f, g, h] = [h0, h1, h2, h3, h4, h5, h6, h7]
for i in range(64):
Expand Down
2 changes: 1 addition & 1 deletion hw/ip/otbn/dv/rig/rig/gens/bad_ispr.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def _gen(self,
# In the case of a randomly generated CSRRW, it is better to have
# UNIMP instead of a write to a random address since it is actually
# an instruction alias.
if self.insns[idx].mnemonic == "csrrw" and random.random() < 0.8:
if self.insns[idx].mnemonic == "csrrw" and random.random() < 0.8:
# UNIMP instruction is equivalent to CSRRW x0, 0xC00, x0
prog_insn.operands = [0, 0xC00, 0]

Expand Down
1 change: 0 additions & 1 deletion hw/ip/pinmux/util/reg_pinmux.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def main():
help='Pad attribute data width',
default = 10)


args = parser.parse_args()

# Determine output: if stdin then stdout if not then ??
Expand Down
20 changes: 10 additions & 10 deletions hw/syn/tools/dc/at-plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def main():
action='store_true',
help='semilogy plot.')

l = 0
line = 0
labels = []

# line style and color setup
Expand Down Expand Up @@ -105,7 +105,7 @@ def main():
tmp_area[1]) / args.gate_equivalent
else:
print("Error, could not find total cell area in %s" %
(report_area))
(rpt_area))
sys.exit(1)

except IOError as e:
Expand Down Expand Up @@ -148,26 +148,26 @@ def main():
if args.semilogy:
plt.semilogy(results[:, 2],
results[:, 1],
color=cmap(l),
linestyle=linestyles[l],
marker=markers[l],
color=cmap(line),
linestyle=linestyles[line],
marker=markers[line],
linewidth=1.5,
markersize=6,
markeredgecolor='k')
else:
plt.plot(results[:, 2],
results[:, 1],
color=cmap(l),
linestyle=linestyles[l],
marker=markers[l],
color=cmap(line),
linestyle=linestyles[line],
marker=markers[line],
linewidth=1.5,
markersize=6,
markeredgecolor='k')

l += 1
line += 1
labels += [report_filebase.name]

print("Parsed %d result series" % l)
print("Parsed %d result series" % line)

plt.xlabel('Period [ns]')
if args.gate_equivalent == 1.0:
Expand Down
8 changes: 7 additions & 1 deletion sw/device/tests/otbn_data/otbn_test_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,16 @@

C_DATATYPE = "static const uint8_t"


def print_array(varname: str, val: int, size_bytes: int):
print("%s %s[%d] = {%s};" % (C_DATATYPE, varname, size_bytes, ', '.join(["0x%02x" % i for i in int(val).to_bytes(size_bytes, byteorder="little")])))
print("%s %s[%d] = {%s};" % (C_DATATYPE, varname, size_bytes,
', '.join(["0x%02x" % i for i in int(val).to_bytes(size_bytes, byteorder="little")])))


def print_string(varname: str, val: str, size_bytes: int):
print("%s %s[%d] = {\"%s\"};" % (C_DATATYPE, varname, size_bytes, val))


def print_rsa_params(private_key_file: str, in_str: str) -> None:
in_bytes = in_str.encode("utf-8")
print("Using private key {}, and plaintext message {!r}".format(private_key_file, in_bytes))
Expand All @@ -45,6 +49,7 @@ def print_rsa_params(private_key_file: str, in_str: str) -> None:
print_array("kEncryptedExpected", encrypted, private_key.size_in_bytes())
print("")


def print_ecc_params(private_key_file: str, in_str: str) -> None:
in_bytes = in_str.encode("utf-8")
print("Using private key {}, and plaintext message {!r}".format(private_key_file, in_bytes))
Expand Down Expand Up @@ -106,5 +111,6 @@ def main() -> int:
else:
raise ValueError("Unknown type {!r}".format(args.type))


if __name__ == "__main__":
sys.exit(main())
1 change: 1 addition & 0 deletions util/autogen_testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import argparse
import glob
import logging
import sys
from pathlib import Path

Expand Down
2 changes: 2 additions & 0 deletions util/design/gen-mubi.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
from mubi import prim_mubi
from secded_gen import format_c_files


def main():
prim_mubi.gen()
c_path = prim_mubi.get_c_path()

format_c_files(c_path, c_path)


if __name__ == "__main__":
main()
10 changes: 5 additions & 5 deletions util/design/keccak_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,25 +43,25 @@ def main():
# Update from t=1 to t=255
r_d = ba.bitarray('0') + r
if r_d[8]:
#Flip 0,4,5,6
# Flip 0,4,5,6
r = r_d[0:8] ^ ba.bitarray('10001110')
else:
r = r_d[0:8]

rc[i] = r[0]

## Print rc
# Print rc
print(rc)

## Round
# Round

rcs = [] # Each entry represent the round
# Each entry represent the round
for rnd in range(0, args.r):
# Let RC=0
rndconst = ba.bitarray(64)
rndconst.setall(0)
# for j [0 .. L] RC[2**j-1] = rc(j+7*rnd)
for j in range(0, 7): #0 to 6
for j in range(0, 7): # 0 to 6
rndconst[2**j - 1] = rc[(j + 7 * rnd) % 255]
print("64'h{}, // Round {}".format(rndhex(rndconst), rnd))

Expand Down

0 comments on commit d01864e

Please sign in to comment.