scripts: west: flash: Add support for .mot file format

Add support for .mot file flash using west flash command
The RX build output .mot as binary file to flash into
board

Signed-off-by: Phi Tran <phi.tran.jg@bp.renesas.com>
Signed-off-by: Duy Nguyen <duy.nguyen.xa@renesas.com>
This commit is contained in:
Phi Tran 2024-09-13 15:32:09 +07:00 committed by Benjamin Cabé
commit 7ac89d33b1
6 changed files with 26 additions and 8 deletions

View file

@ -236,7 +236,7 @@ config SRAM_BASE_ADDRESS
/chosen/zephyr,sram in devicetree. The user should generally avoid
changing it via menuconfig or in configuration files.
if ARC || ARM || ARM64 || NIOS2 || X86 || RISCV
if ARC || ARM || ARM64 || NIOS2 || X86 || RISCV || RX
# Workaround for not being able to have commas in macro arguments
DT_CHOSEN_Z_FLASH := zephyr,flash
@ -259,7 +259,7 @@ config FLASH_BASE_ADDRESS
normally set by the board's defconfig file and the user should generally
avoid modifying it via the menu configuration.
endif # ARM || ARM64 || ARC || NIOS2 || X86 || RISCV
endif # ARM || ARM64 || ARC || NIOS2 || X86 || RISCV || RX
if ARCH_HAS_TRUSTED_EXECUTION

View file

@ -3,6 +3,5 @@
# options after "--tool-opt=" are directly passed to the tool. So instead of "--iface=JTAG" you could also write "--tool-opt=-if JTAG"
board_runner_args(jlink "--device=R5F51308" "--iface=FINE" "--speed=1000" "--tool-opt=-jtagconf -1,-1 -autoconnect 1")
board_runner_args(jlink "--use-mot")
include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake)

View file

@ -672,6 +672,7 @@ def get_runner_config(build_dir, yaml_path, runners_yaml, args=None):
output_file('hex'),
output_file('bin'),
output_file('uf2'),
output_file('mot'),
config('file'),
filetype('file_type'),
config('gdb'),

View file

@ -339,6 +339,7 @@ class FileType(Enum):
HEX = 1
BIN = 2
ELF = 3
MOT = 4
class RunnerConfig(NamedTuple):
@ -355,6 +356,7 @@ class RunnerConfig(NamedTuple):
hex_file: str | None # zephyr.hex path, or None
bin_file: str | None # zephyr.bin path, or None
uf2_file: str | None # zephyr.uf2 path, or None
mot_file: str | None # zephyr.mot path
file: str | None # binary file path (provided by the user), or None
file_type: FileType | None = FileType.OTHER # binary file type
gdb: str | None = None # path to a usable gdb
@ -581,6 +583,7 @@ class ZephyrBinaryRunner(abc.ABC):
parser.add_argument('--elf-file', help=argparse.SUPPRESS)
parser.add_argument('--hex-file', help=argparse.SUPPRESS)
parser.add_argument('--bin-file', help=argparse.SUPPRESS)
parser.add_argument('--mot-file', help=argparse.SUPPRESS)
else:
parser.add_argument('--elf-file',
metavar='FILE',
@ -600,6 +603,12 @@ class ZephyrBinaryRunner(abc.ABC):
replacement='-f/--file') if caps.file else None),
help='path to zephyr.bin'
if not caps.file else 'Deprecated, use -f/--file instead.')
parser.add_argument('--mot-file',
metavar='FILE',
action=(partial(depr_action, cls=cls,
replacement='-f/--file') if caps.file else None),
help='path to zephyr.mot'
if not caps.file else 'Deprecated, use -f/--file instead.')
parser.add_argument('--erase', '--no-erase', nargs=0,
action=_ToggleAction,

View file

@ -66,6 +66,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
self.hex_name = cfg.hex_file
self.bin_name = cfg.bin_file
self.elf_name = cfg.elf_file
self.mot_name = cfg.mot_file
self.gdb_cmd = [cfg.gdb] if cfg.gdb else None
self.device = device
self.dev_id = dev_id
@ -384,7 +385,7 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
if self.file_type == FileType.HEX:
flash_cmd = f'loadfile "{self.file}"'
elif self.file_type == FileType.BIN:
elif self.file_type == (FileType.BIN or FileType.MOT):
if self.dt_flash:
flash_addr = self.flash_address_from_build_conf(self.build_conf)
else:
@ -396,10 +397,14 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
else:
# Use hex, bin or elf file provided by the buildsystem.
# Preferring .hex over .bin and .elf
# Preferring .hex over .mot, .bin and .elf
if self.hex_name is not None and os.path.isfile(self.hex_name):
flash_file = self.hex_name
flash_cmd = f'loadfile "{self.hex_name}"'
# Preferring .mot over .bin and .elf
elif self.mot_name is not None and os.path.isfile(self.mot_name):
flash_file = self.mot_name
flash_cmd = f'loadfile {self.mot_name}'
# Preferring .bin over .elf
elif self.bin_name is not None and os.path.isfile(self.bin_name):
if self.dt_flash:
@ -411,9 +416,12 @@ class JLinkBinaryRunner(ZephyrBinaryRunner):
elif self.elf_name is not None and os.path.isfile(self.elf_name):
flash_file = self.elf_name
flash_cmd = f'loadfile "{self.elf_name}"'
elif self.mot_name is not None and os.path.isfile(self.mot_name):
flash_file = self.mot_name
flash_cmd = f'loadfile {self.mot_name}'
else:
err = 'Cannot flash; no hex ({}), bin ({}) or elf ({}) files found.'
raise ValueError(err.format(self.hex_name, self.bin_name, self.elf_name))
err = 'Cannot flash; no hex ({}), bin ({}) or mot ({}) files found.'
raise ValueError(err.format(self.hex_name, self.bin_name))
# Flash the selected build artifact
lines.append(flash_cmd)

View file

@ -14,6 +14,7 @@ RC_KERNEL_ELF = 'test-zephyr.elf'
RC_KERNEL_EXE = 'test-zephyr.exe'
RC_KERNEL_HEX = 'test-zephyr.hex'
RC_KERNEL_BIN = 'test-zephyr.bin'
RC_KERNEL_MOT = 'test-zephyr.mot'
RC_GDB = 'test-none-gdb'
RC_OPENOCD = 'test-openocd'
RC_OPENOCD_SEARCH = ['/test/openocd/search']
@ -23,6 +24,6 @@ RC_OPENOCD_SEARCH = ['/test/openocd/search']
def runner_config():
'''Fixture which provides a runners.core.RunnerConfig.'''
return RunnerConfig(RC_BUILD_DIR, RC_BOARD_DIR, RC_KERNEL_ELF, RC_KERNEL_EXE,
RC_KERNEL_HEX, RC_KERNEL_BIN, None, FileType.OTHER,
RC_KERNEL_HEX, RC_KERNEL_BIN, RC_KERNEL_MOT, None, FileType.OTHER,
gdb=RC_GDB, openocd=RC_OPENOCD,
openocd_search=RC_OPENOCD_SEARCH)