| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: UTF-8 -*- |
| 3 |
# |
| 4 |
# Copyright 2016-2018 Martin Olejar |
| 5 |
# Copyright 2019-2024 NXP |
| 6 |
# |
| 7 |
# SPDX-License-Identifier: BSD-3-Clause |
| 8 |
|
| 9 |
"""Exceptions used in the MBoot module.""" |
| 10 |
|
| 11 |
from ..exceptions import SPSDKError |
| 12 |
from .error_codes import StatusCode |
| 13 |
|
| 14 |
######################################################################################################################## |
| 15 |
# McuBoot Exceptions |
| 16 |
######################################################################################################################## |
| 17 |
|
| 18 |
|
| 19 |
class McuBootError(SPSDKError): |
| 20 |
"""MBoot Module: Base Exception.""" |
| 21 |
|
| 22 |
fmt = "MBoot: {description}" |
| 23 |
|
| 24 |
|
| 25 |
class McuBootCommandError(McuBootError): |
| 26 |
"""MBoot Module: Command Exception.""" |
| 27 |
|
| 28 |
fmt = "MBoot: {cmd_name} interrupted -> {description}" |
| 29 |
|
| 30 |
def __init__(self, cmd: str, value: int) -> None: |
| 31 |
"""Initialize the Command Error exception. |
| 32 |
|
| 33 |
:param cmd: Name of the command causing the exception |
| 34 |
:param value: Response value causing the exception |
| 35 |
""" |
| 36 |
super().__init__() |
| 37 |
self.cmd_name = cmd |
| 38 |
self.error_value = value |
| 39 |
self.description = ( |
| 40 |
StatusCode.get_description(value) |
| 41 |
if value in StatusCode.tags() |
| 42 |
else f"Unknown Error 0x{value:08X}" |
| 43 |
) |
| 44 |
|
| 45 |
def __str__(self) -> str: |
| 46 |
return self.fmt.format(cmd_name=self.cmd_name, description=self.description) |
| 47 |
|
| 48 |
|
| 49 |
class McuBootDataAbortError(McuBootError): |
| 50 |
"""MBoot Module: Data phase aborted by sender.""" |
| 51 |
|
| 52 |
fmt = "Mboot: Data aborted by sender" |
| 53 |
|
| 54 |
|
| 55 |
class McuBootConnectionError(McuBootError): |
| 56 |
"""MBoot Module: Connection Exception.""" |
| 57 |
|
| 58 |
fmt = "MBoot: Connection issue -> {description}" |