Skip to content

Commit

Permalink
west: add native_sim flash command
Browse files Browse the repository at this point in the history
Add 'west flash' support which in the case of native_sim just start the
built application.
Reuse existing runner and rename it to be more generic as it does more
than just debugging now.

Fixes zephyrproject-rtos#36706

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
  • Loading branch information
nashif committed Feb 12, 2024
1 parent 36a497b commit 8362620
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 16 deletions.
5 changes: 3 additions & 2 deletions boards/posix/native_posix/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

set(SUPPORTED_EMU_PLATFORMS native)

board_set_debugger_ifnset(native_gdb)
board_finalize_runner_args(native_gdb)
board_set_debugger_ifnset(native)
board_set_flasher_ifnset(native)
board_finalize_runner_args(native)
5 changes: 3 additions & 2 deletions boards/posix/native_sim/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

set(SUPPORTED_EMU_PLATFORMS native)

board_set_debugger_ifnset(native_gdb)
board_finalize_runner_args(native_gdb)
board_set_debugger_ifnset(native)
board_set_flasher_ifnset(native)
board_finalize_runner_args(native)
5 changes: 3 additions & 2 deletions boards/posix/nrf_bsim/board.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

set(SUPPORTED_EMU_PLATFORMS native)

board_set_debugger_ifnset(native_gdb)
board_finalize_runner_args(native_gdb)
board_set_debugger_ifnset(native)
board_set_flasher_ifnset(native)
board_finalize_runner_args(native)
2 changes: 1 addition & 1 deletion scripts/west_commands/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _import_runner_module(runner_name):
'linkserver',
'mdb',
'misc',
'native_gdb',
'native',
'nios2',
'nrfjprog',
'nrfutil',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
# Copyright (c) 2023 Nordic Semiconductor
# SPDX-License-Identifier: Apache-2.0

"""This file provides a ZephyrBinaryRunner that launches GDB."""
"""This file provides a ZephyrBinaryRunner that launches GDB and enables
flashing (running) a native application."""

import argparse
from runners.core import ZephyrBinaryRunner, RunnerCaps, RunnerConfig

class NativeGDBBinaryRunner(ZephyrBinaryRunner):
class NativeSimBinaryRunner(ZephyrBinaryRunner):
"""Runs the ELF binary under GDB."""

@classmethod
def name(cls):
return 'native_gdb'
return 'native'

@classmethod
def capabilities(cls):
return RunnerCaps(commands={'debug'})
return RunnerCaps(commands={'debug', 'flash'})

@classmethod
def do_add_parser(cls, parser: argparse.ArgumentParser):
pass

@classmethod
def do_create(cls, cfg: RunnerConfig, args: argparse.Namespace) -> ZephyrBinaryRunner:
return NativeGDBBinaryRunner(cfg)
return NativeSimBinaryRunner(cfg)

def do_run(self, command: str, **kwargs):
assert command == 'debug'

if command == 'flash':
self.do_flash(**kwargs)
elif command == 'debug':
self.do_debug(**kwargs)
else:
assert False

def do_flash(self, **kwargs):
cmd = self.cfg.exe_file
self.check_call(cmd)

def do_debug(self, **kwargs):
# Clues to debug missing RunnerConfig values (in context of `west debug`):
# build/zephyr/runners.yaml is missing `gdb` or `elf_file`.
# board.cmake should have `board_finalize_runner_args(native_gdb)`.
# board.cmake should have `board_finalize_runner_args(native)`.
# build/CMakeCache.txt should have `CMAKE_GDB`.

if self.cfg.gdb is None:
Expand Down
2 changes: 1 addition & 1 deletion scripts/west_commands/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_runner_imports():
'mdb-nsim',
'mdb-hw',
'misc-flasher',
'native_gdb',
'native',
'nios2',
'nrfjprog',
'nrfutil',
Expand Down

0 comments on commit 8362620

Please sign in to comment.