Skip to content

Commit

Permalink
Add 'bootloader' spinel reset type and otPlatResetBootloader() API
Browse files Browse the repository at this point in the history
  • Loading branch information
lmnotran committed Oct 12, 2023
1 parent 05b4a5e commit 2b36daa
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions etc/cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ ot_option(OT_NETDIAG_CLIENT OPENTHREAD_CONFIG_TMF_NETDIAG_CLIENT_ENABLE "Network
ot_option(OT_OPERATIONAL_DATASET_AUTO_INIT OPENTHREAD_CONFIG_OPERATIONAL_DATASET_AUTO_INIT "operational dataset auto init")
ot_option(OT_OTNS OPENTHREAD_CONFIG_OTNS_ENABLE "OTNS")
ot_option(OT_PING_SENDER OPENTHREAD_CONFIG_PING_SENDER_ENABLE "ping sender" ${OT_APP_CLI})
ot_option(OT_PLATFORM_BOOTLOADER_MODE OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE "platform bootloader mode")
ot_option(OT_PLATFORM_NETIF OPENTHREAD_CONFIG_PLATFORM_NETIF_ENABLE "platform netif")
ot_option(OT_PLATFORM_UDP OPENTHREAD_CONFIG_PLATFORM_UDP_ENABLE "platform UDP")
ot_option(OT_REFERENCE_DEVICE OPENTHREAD_CONFIG_REFERENCE_DEVICE_ENABLE "test harness reference device")
Expand Down
8 changes: 8 additions & 0 deletions examples/platforms/simulation/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ void otPlatReset(otInstance *aInstance)
#endif // OPENTHREAD_PLATFORM_USE_PSEUDO_RESET
}

#if OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
void otPlatResetToBootloader(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
assert(false);
}
#endif

otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
{
OT_UNUSED_VARIABLE(aInstance);
Expand Down
10 changes: 9 additions & 1 deletion include/openthread/instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ extern "C" {
* @note This number versions both OpenThread platform and user APIs.
*
*/
#define OPENTHREAD_API_VERSION (364)
#define OPENTHREAD_API_VERSION (365)

/**
* @addtogroup api-instance
Expand Down Expand Up @@ -255,6 +255,14 @@ void otRemoveStateChangeCallback(otInstance *aInstance, otStateChangedCallback a
*/
void otInstanceReset(otInstance *aInstance);

/**
* Triggers a platform reset to bootloader mode, if supported.
*
* @param[in] aInstance A pointer to an OpenThread instance.
*
*/
void otInstanceResetToBootloader(otInstance *aInstance);

/**
* Deletes all the settings stored on non-volatile memory, and then triggers a platform reset.
*
Expand Down
8 changes: 8 additions & 0 deletions include/openthread/platform/misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ extern "C" {
*/
void otPlatReset(otInstance *aInstance);

/**
* Performs a hardware reset on the platform to launch bootloader mode, if supported.
*
* @param[in] aInstance The OpenThread instance structure.
*
*/
void otPlatResetToBootloader(otInstance *aInstance);

/**
* Enumeration of possible reset reason codes.
*
Expand Down
4 changes: 4 additions & 0 deletions src/core/api/instance_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ void otInstanceFinalize(otInstance *aInstance) { AsCoreType(aInstance).Finalize(

void otInstanceReset(otInstance *aInstance) { AsCoreType(aInstance).Reset(); }

#if OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
void otInstanceResetToBootloader(otInstance *aInstance) { AsCoreType(aInstance).ResetToBootloader(); }
#endif

#if OPENTHREAD_CONFIG_UPTIME_ENABLE
uint64_t otInstanceGetUptime(otInstance *aInstance) { return AsCoreType(aInstance).Get<Uptime>().GetUptime(); }

Expand Down
4 changes: 4 additions & 0 deletions src/core/common/instance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,10 @@ Instance *Instance::Init(void *aBuffer, size_t *aBufferSize)

void Instance::Reset(void) { otPlatReset(this); }

#if OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
void Instance::ResetToBootloader(void) { otPlatResetToBootloader(this); }
#endif

#if OPENTHREAD_RADIO
void Instance::ResetRadioStack(void)
{
Expand Down
7 changes: 7 additions & 0 deletions src/core/common/instance.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,13 @@ class Instance : public otInstance, private NonCopyable
*/
void Reset(void);

#if OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
/**
* Triggers a platform reset to bootloader mode, if supported.
*/
void ResetToBootloader(void);
#endif

#if OPENTHREAD_RADIO
/**
* Resets the internal states of the radio.
Expand Down
11 changes: 7 additions & 4 deletions src/lib/spinel/spinel.h
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,9 @@ enum

enum
{
SPINEL_RESET_PLATFORM = 1,
SPINEL_RESET_STACK = 2,
SPINEL_RESET_PLATFORM = 1,
SPINEL_RESET_STACK = 2,
SPINEL_RESET_BOOTLOADER = 3,
};

enum
Expand Down Expand Up @@ -929,8 +930,10 @@ enum
* `PROP_LAST_STATUS` has been set to `STATUS_RESET_SOFTWARE`.
*
* The optional command payload specifies the reset type, can be
* `SPINEL_RESET_PLATFORM` or `SPINEL_RESET_STACK`. Defaults to stack
* reset if unspecified.
* `SPINEL_RESET_PLATFORM`, `SPINEL_RESET_STACK`, or
* `SPINEL_RESET_BOOTLOADER`.
*
* Defaults to stack reset if unspecified.
*
* If an error occurs, the value of `PROP_LAST_STATUS` will be emitted
* instead with the value set to the generated status code for the error.
Expand Down
8 changes: 8 additions & 0 deletions src/ncp/ncp_base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,6 +1211,14 @@ otError NcpBase::CommandHandler_RESET(uint8_t aHeader)
SuccessOrAssert(
error = WriteLastStatusFrame(SPINEL_HEADER_FLAG | SPINEL_HEADER_IID_0, SPINEL_STATUS_RESET_POWER_ON));
}
#if OPENTHREAD_CONFIG_PLATFORM_BOOTLOADER_MODE_ENABLE
else if (reset_type == SPINEL_RESET_BOOTLOADER)
{
// Signal a platform reset to bootloader mode. If implemented, this function
// shouldn't return.
otInstanceResetToBootloader(mInstance);
}
#endif
else
#endif
{
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/test_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ OT_TOOL_WEAK void otPlatUartReceived(const uint8_t *, uint16_t) {}

OT_TOOL_WEAK void otPlatReset(otInstance *) {}

OT_TOOL_WEAK void otPlatResetToBootloader(otInstance *) {}

OT_TOOL_WEAK otPlatResetReason otPlatGetResetReason(otInstance *) { return OT_PLAT_RESET_REASON_POWER_ON; }

OT_TOOL_WEAK void otPlatLog(otLogLevel, otLogRegion, const char *, ...) {}
Expand Down

0 comments on commit 2b36daa

Please sign in to comment.