From 96dad770dd32676e3e3478ef68e8b4c2f59a57df Mon Sep 17 00:00:00 2001 From: Guillaume Galeazzi Date: Thu, 18 Dec 2025 14:18:44 +0100 Subject: [PATCH] Add option to not fill binary up to max address --- bincopy.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bincopy.py b/bincopy.py index c7d911d..fca6d7a 100755 --- a/bincopy.py +++ b/bincopy.py @@ -1517,7 +1517,8 @@ def as_verilog_vmem(self): def as_binary(self, minimum_address=None, maximum_address=None, - padding=None): + padding=None, + fill=True): """Return a byte string of all data within given address range. `minimum_address` is the absolute minimum address of the @@ -1534,6 +1535,9 @@ def as_binary(self, bits, and so on. By default the padding is ``b'\\xff' * word_size_bytes``. + `fill` fill the binary up to `maximum_address`. By default + this is True. + >>> binfile.as_binary() bytearray(b'!F\\x016\\x01!G\\x016\\x00~\\xfe\\t\\xd2\\x19\\x01!F\\x01~\\x17\\xc2\\x00\\x01 \\xff_\\x16\\x00!H\\x01\\x19\\x19Ny#F#\\x96Wx#\\x9e\\xda?\\x01\\xb2\\xca?\\x01Vp+^q+r+s! @@ -1580,7 +1584,8 @@ def as_binary(self, data = data[:size] length = len(data) // self.word_size_bytes elif maximum_address >= current_maximum_address: - binary += padding * (maximum_address - current_maximum_address) + if fill: + binary += padding * (maximum_address - current_maximum_address) break binary += padding * (address - current_maximum_address)