Skip to content

Commit

Permalink
Python 3 updates for generate_config.py script.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosperate authored and mathias-arm committed Sep 20, 2021
1 parent ae05f3f commit 8509fea
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions tools/generate_config.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
# limitations under the License.
#

from __future__ import print_function

import struct
import argparse
from intelhex import IntelHex
Expand All @@ -37,16 +39,14 @@

def create_hex(filename, addr, auto_rst, automation_allowed,
overflow_detect, detect_incompatible_target, pad_size):
file_format = 'hex'
intel_hex = IntelHex()
intel_hex.puts(addr, struct.pack(FORMAT, CFG_KEY, FORMAT_LENGTH, auto_rst,
automation_allowed, overflow_detect, detect_incompatible_target))
pad_addr = addr + FORMAT_LENGTH
pad_byte_count = pad_size - (FORMAT_LENGTH % pad_size)
pad_data = '\xFF' * pad_byte_count
intel_hex.puts(pad_addr, pad_data)
with open(filename, 'wb') as f:
intel_hex.tofile(f, file_format)
intel_hex.write_hex_file(filename)


def str_to_int(val):
Expand All @@ -66,18 +66,18 @@ def str_to_int(val):

def main():
args = parser.parse_args()
print "Output file %s" % args.output_file
print "Config Offset 0x%x" % args.addr
print("Output file %s" % args.output_file)
print("Config Offset 0x%x" % args.addr)
if args.addr % MINIMUM_ALIGN != 0:
print "WARNING! Configuration is not on a 1K boundary"
print("WARNING! Configuration is not on a 1K boundary")
if args.addr % args.pad != 0:
print "WARNING! Configuration is not aligned to pad size"
print "Settings:"
print " auto_rst: %i" % args.auto_rst
print " automation_allowed: %i" % args.automation_allowed
print " overflow_detect: %i" % args.overflow_detect
print " detect_incompatible_target: %i" % args.detect_incompatible_target
print ""
print("WARNING! Configuration is not aligned to pad size")
print("Settings:")
print(" auto_rst: %i" % args.auto_rst)
print(" automation_allowed: %i" % args.automation_allowed)
print(" overflow_detect: %i" % args.overflow_detect)
print(" detect_incompatible_target: %i" % args.detect_incompatible_target)
print("")
create_hex(args.output_file, args.addr, args.auto_rst,
args.automation_allowed, args.overflow_detect, args.detect_incompatible_target, args.pad)

Expand Down

0 comments on commit 8509fea

Please sign in to comment.