diff --git a/pyocd/target/pack/flash_algo.py b/pyocd/target/pack/flash_algo.py index ce8983dc0..bddfc08ab 100644 --- a/pyocd/target/pack/flash_algo.py +++ b/pyocd/target/pack/flash_algo.py @@ -305,14 +305,12 @@ def _create_algo_bin(self, ro_rw_zi: RoRwZiType) -> bytearray: """Create a binary blob of the flash algo which can execute from ram""" sect_ro, sect_rw, sect_zi = ro_rw_zi assert sect_ro and sect_rw and sect_zi - algo_size = max(sect_ro.end, sect_rw.end, sect_zi.end) + algo_size = max(sect_ro.end, sect_rw.end, sect_zi.end) + 1 algo_data = bytearray(algo_size) for section in (sect_ro, sect_rw): - start = section.start - size = section.length - data = section.data - assert len(data) == size - algo_data[start:start + size] = data + if hasattr(section, "data"): + assert len(section.data) == section.length + algo_data[section.start : section.start + section.length] = section.data return algo_data