Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pack: flash: Support flash_algos with no RW section #1716

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions pyocd/target/pack/flash_algo.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, data):
self.symbols = symbols

ro_rw_zi = self._find_sections(self.SECTIONS_TO_FIND)
ro_rw_zi = self._algo_fill_zi_if_missing(ro_rw_zi)
ro_rw_zi = self._algo_fill_rw_and_zi_if_missing(ro_rw_zi)
error_msg = self._algo_check_for_section_problems(ro_rw_zi)
if error_msg is not None:
raise FlashAlgoException(error_msg)
Expand Down Expand Up @@ -272,14 +272,14 @@ def _find_sections(self, name_type_pairs: Sequence[Tuple[str, str]]) -> Tuple[Op
sections[i] = section
return tuple(sections)

def _algo_fill_zi_if_missing(self, ro_rw_zi: RoRwZiType) -> RoRwZiType:
"""@brief Create an empty zi section if it is missing"""
def _algo_fill_rw_and_zi_if_missing(self, ro_rw_zi: RoRwZiType) -> RoRwZiType:
"""@brief Create an empty rw and/or zi sections if they are missing"""
s_ro, s_rw, s_zi = ro_rw_zi
if s_rw is None:
return ro_rw_zi
if s_zi is not None:
return ro_rw_zi
s_zi = MemoryRange(start=(s_rw.start + s_rw.length), length=0)
if s_rw is None and s_zi is None:
s_rw = MemoryRange(start=(s_ro.start + s_ro.length), length=0)
s_zi = MemoryRange(start=(s_rw.start + s_rw.length), length=0)
elif s_zi is None:
s_zi = MemoryRange(start=(s_rw.start + s_rw.length), length=0)
return s_ro, s_rw, s_zi

def _algo_check_for_section_problems(self, ro_rw_zi: RoRwZiType) -> Optional[str]:
Expand Down Expand Up @@ -308,9 +308,12 @@ def _create_algo_bin(self, ro_rw_zi: RoRwZiType):
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

# `sect_rw` may be empty and not contain any data.
if size > 0:
data = section.data
assert len(data) == size
algo_data[start:start + size] = data
return algo_data


Expand Down