Skip to content

Commit

Permalink
Work on capability flags
Browse files Browse the repository at this point in the history
- Add implementation of new capability flags in CLR and booter for all targets that implement it.
- Rename fields in ping reply and command.
- Remove flags from CLR_DBG_Commands.
- Move some implementation to targets.
- Provide weak implementations for most capabilities.
- Following nanoframework/nf-debugger#253.
  • Loading branch information
josesimoes committed Nov 6, 2020
1 parent dbbe723 commit dd65d45
Show file tree
Hide file tree
Showing 16 changed files with 156 additions and 64 deletions.
38 changes: 28 additions & 10 deletions src/CLR/Debugger/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void CLR_DBG_Debugger::Debugger_Discovery()

// Send "presence" ping.
Monitor_Ping_Command cmd;
cmd.m_source = Monitor_Ping_c_Ping_Source_NanoCLR;
cmd.Source = Monitor_Ping_c_Ping_Source_NanoCLR;

while (true)
{
Expand Down Expand Up @@ -381,35 +381,53 @@ bool CLR_DBG_Debugger::Monitor_Ping(WP_Message *msg)
Monitor_Ping_Command *cmd = (Monitor_Ping_Command *)msg->m_payload;

// default is to stop the debugger (backwards compatibility)
fStopOnBoot = (cmd != NULL) && (cmd->m_dbg_flags & Monitor_Ping_c_Ping_DbgFlag_Stop);
fStopOnBoot = (cmd != NULL) && (cmd->Flags & Monitor_Ping_c_Ping_DbgFlag_Stop);

cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoCLR;
cmdReply.Source = Monitor_Ping_c_Ping_Source_NanoCLR;

cmdReply.m_dbg_flags = CLR_EE_DBG_IS(StateProgramExited) != 0 ? Monitor_Ping_c_Ping_DbgFlag_AppExit : 0;
// now fill in the flags
cmdReply.Flags = CLR_EE_DBG_IS(StateProgramExited) != 0 ? Monitor_Ping_c_Ping_DbgFlag_AppExit : 0;

#if defined(WP_IMPLEMENTS_CRC32)
cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
cmdReply.Flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
#endif

// Wire Protocol packet size
#if (WP_PACKET_SIZE == 512)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0512;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0512;
#elif (WP_PACKET_SIZE == 256)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0256;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0256;
#elif (WP_PACKET_SIZE == 128)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0128;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0128;
#elif (WP_PACKET_SIZE == 1024)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_1024;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_1024;
#endif

// capability flags
if (::Target_HasProprietaryBooter())
{
cmdReply.Flags |= Monitor_Ping_c_HasProprietaryBooter;
}

if (::Target_IFUCapable())
{
cmdReply.Flags |= Monitor_Ping_c_IFUCapable;
}

if (::Target_ConfigUpdateRequiresErase())
{
cmdReply.Flags |= Monitor_Ping_c_ConfigBlockRequiresErase;
}

// done, send reply
WP_ReplyToCommand(msg, true, false, &cmdReply, sizeof(cmdReply));
}
else
{
Monitor_Ping_Reply *cmdReply = (Monitor_Ping_Reply *)msg->m_payload;

// default is to stop the debugger (backwards compatibility)
fStopOnBoot = (cmdReply != NULL) && (cmdReply->m_dbg_flags & Monitor_Ping_c_Ping_DbgFlag_Stop);
fStopOnBoot = (cmdReply != NULL) && (cmdReply->Flags & Monitor_Ping_c_Ping_DbgFlag_Stop);
}

if (CLR_EE_DBG_IS_MASK(StateInitialize, StateMask))
Expand Down
40 changes: 30 additions & 10 deletions src/CLR/Include/WireProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// See LICENSE file in the project root for full license information.
//

// clang-format off

#ifndef _WIREPROTOCOL_H_
#define _WIREPROTOCOL_H_

Expand Down Expand Up @@ -150,21 +152,37 @@ typedef struct WP_Message
///////////////////////////////////////////////////////////////////////
typedef enum Monitor_Ping_Source_Flags
{
Monitor_Ping_c_Ping_Source_NanoCLR = 0x00010000,
Monitor_Ping_c_Ping_Source_NanoBooter = 0x00010001,
Monitor_Ping_c_Ping_Source_Host = 0x00010002,
///////////////////////////////////////////////////////

Monitor_Ping_c_Ping_Source_NanoCLR = 0x00010000,
Monitor_Ping_c_Ping_Source_NanoBooter = 0x00010001,
Monitor_Ping_c_Ping_Source_Host = 0x00010002,

Monitor_Ping_c_Ping_DbgFlag_Stop = 0x00000001,
Monitor_Ping_c_Ping_DbgFlag_AppExit = 0x00000004,
Monitor_Ping_c_Ping_DbgFlag_Stop = 0x00000001,
Monitor_Ping_c_Ping_DbgFlag_AppExit = 0x00000004,

///////////////////////////////////////////////////////
// flags specific to Wire Protocol capabilities
Monitor_Ping_c_Ping_WPFlag_SupportsCRC32 = 0x00000010,

Monitor_Ping_c_Ping_WPFlag_SupportsCRC32 = 0x00000010,

// Wire Protocol packet size (3rd position)
Monitor_Ping_c_PacketSize_1024 = 0x00000100,
Monitor_Ping_c_PacketSize_0512 = 0x00000200,
Monitor_Ping_c_PacketSize_0256 = 0x00000300,
Monitor_Ping_c_PacketSize_0128 = 0x00000400,
Monitor_Ping_c_PacketSize_1024 = 0x00000100,
Monitor_Ping_c_PacketSize_0512 = 0x00000200,
Monitor_Ping_c_PacketSize_0256 = 0x00000300,
Monitor_Ping_c_PacketSize_0128 = 0x00000400,

///////////////////////////////////////////////////////
// flags related with device capabilities

// This flag indicates that the device has a proprietary bootloader.
Monitor_Ping_c_HasProprietaryBooter = 0x00010000,

// This flag indicates that the target device is IFU capable.
Monitor_Ping_c_IFUCapable = 0x00020000,

// This flag indicates that the device requires that the configuration block to be erased before updating it.
Monitor_Ping_c_ConfigBlockRequiresErase = 0x00040000,

}Monitor_Ping_Source_Flags;

Expand Down Expand Up @@ -211,3 +229,5 @@ struct WP_CompileCheck
};

#endif // _WIREPROTOCOL_H_

// clang-format on
10 changes: 4 additions & 6 deletions src/CLR/Include/WireProtocol_MonitorCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,18 @@ typedef enum MemoryMap_Options
// typedefs

// structure for Monitor Ping Reply
// backwards compatible with .NETMF
typedef struct Monitor_Ping_Reply
{
uint32_t m_source;
uint32_t m_dbg_flags;
uint32_t Source;
uint32_t Flags;

} Monitor_Ping_Reply;

// structure for command Monitor Ping
// backwards compatible with .NETMF
typedef struct Monitor_Ping_Command
{
uint32_t m_source;
uint32_t m_dbg_flags;
uint32_t Source;
uint32_t Flags;

} Monitor_Ping_Command;

Expand Down
7 changes: 5 additions & 2 deletions src/CLR/Include/nanoCLR_Debugging.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,12 @@ struct CLR_DBG_Commands
static const CLR_UINT32 c_CapabilityFlags_Profiling_Calls = 0x00000100;
static const CLR_UINT32 c_CapabilityFlags_ThreadCreateEx = 0x00000400;
static const CLR_UINT32 c_CapabilityFlags_ConfigBlockRequiresErase = 0x00000800;

/////////////////////////////////////////////////////////////////////////////////
// THIS FLAG IS DEPRECATED AND WILL BE REMOVED IN A FUTURE VERSION
// USE Monitor_Ping_Source_Flags INSTEAD
static const CLR_UINT32 c_CapabilityFlags_HasNanoBooter = 0x00001000;
static const CLR_UINT32 c_CapabilityFlags_HasProprietaryBooter = 0x00002000;
static const CLR_UINT32 c_CapabilityFlags_IFUCapable = 0x00004000;
/////////////////////////////////////////////////////////////////////////////////

static const CLR_UINT32 c_CapabilityFlags_PlatformCapabiliy_0 = 0x01000000;
static const CLR_UINT32 c_CapabilityFlags_PlatformCapabiliy_1 = 0x02000000;
Expand Down
3 changes: 0 additions & 3 deletions src/HAL/Include/nanoHAL_Capabilites.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,16 @@ extern "C"
// Information on whether updating a configuration block requires previous erase.
// This is relevant for targets that store the configuration block in flash,
// which requires erasing before changing the content.
// No default implementation provided to make sure the platform/target esplicitly declares it
bool Target_ConfigUpdateRequiresErase();

// Information on whether the target implements nano booter
// No default implementation provided to make sure the platform/target esplicitly declares it
bool Target_HasNanoBooter();

// Information on whether the target has a proprietary bootloader
// No default implementation provided to make sure the platform/target esplicitly declares it
bool Target_HasProprietaryBooter();

// Information on whether the target is capable of IFU
// No default implementation provided to make sure the platform/target esplicitly declares it
bool Target_IFUCapable();

#ifdef __cplusplus
Expand Down
29 changes: 29 additions & 0 deletions src/HAL/nanoHAL_Capabilites.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,32 @@ __nfweak uint32_t GetTargetCapabilities()
{
return 0;
}

// Returns the target capabilities coded as an uint32_t.
// Implemented as "weak" to allow it to be replaced with "hard" implementation at target level.
__nfweak uint32_t GetTargetCapabilities()
{
return 0;
}

// Information on whether updating a configuration block requires previous erase.
// Implemented as "weak" to allow it to be replaced with "hard" implementation at target level.
__nfweak bool Target_ConfigUpdateRequiresErase()
{
return true;
}

// Information on whether the target has a proprietary bootloader
// Implemented as "weak" to allow it to be replaced with "hard" implementation at target level.
__nfweak bool Target_HasProprietaryBooter()
{
return false;
}

// Information on whether the target is capable of IFU
// Implemented as "weak" to allow it to be replaced with "hard" implementation at target level.
__nfweak bool Target_IFUCapable()

{
return false;
}
3 changes: 2 additions & 1 deletion targets/CMSIS-OS/ChibiOS/MBN_QUAIL/target_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ HAL_SYSTEM_CONFIG HalSystemConfig = {
HAL_TARGET_CONFIGURATION g_TargetConfiguration;

// this target uses DFU for updates
GET_TARGET_CAPABILITIES(TargetCapabilities_DfuUpdate)
inline GET_TARGET_CAPABILITIES(TargetCapabilities_DfuUpdate)
inline TARGET_HAS_PROPRITARY_BOOTER(true);
1 change: 1 addition & 0 deletions targets/CMSIS-OS/ChibiOS/NETDUINO3_WIFI/target_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ HAL_TARGET_CONFIGURATION g_TargetConfiguration;

// this target uses DFU for updates
inline GET_TARGET_CAPABILITIES(TargetCapabilities_DfuUpdate);
inline TARGET_HAS_PROPRITARY_BOOTER(true);
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ HAL_TARGET_CONFIGURATION g_TargetConfiguration;

// this target can use both JTAG and DFU for updates
inline GET_TARGET_CAPABILITIES(TargetCapabilities_JtagUpdate | TargetCapabilities_DfuUpdate);
inline TARGET_HAS_PROPRITARY_BOOTER(true);
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ HAL_TARGET_CONFIGURATION g_TargetConfiguration;

// this target can use both JTAG and DFU for updates
inline GET_TARGET_CAPABILITIES(TargetCapabilities_JtagUpdate | TargetCapabilities_DfuUpdate);
inline TARGET_HAS_PROPRITARY_BOOTER(true);
2 changes: 0 additions & 2 deletions targets/CMSIS-OS/ChibiOS/common/targetHAL.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ void HARD_Breakpoint()
#endif // !defined(BUILD_RTM)

// provide platform level "weak" implementations for all capabilities
__nfweak TARGET_CONFIG_UPDATE_REQUIRES_ERASE(true);
__nfweak TARGET_HAS_NANOBOOTER(true);
__nfweak TARGET_HAS_PROPRITARY_BOOTER(false);
__nfweak TARGET_IFU_CAPABLE(false);

// STM32 default capabiliy is JTAG update
Expand Down
30 changes: 23 additions & 7 deletions targets/CMSIS-OS/ChibiOS/nanoBooter/WireProtocol_MonitorCommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,40 @@ int Monitor_Ping(WP_Message *message)
if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0)
{
Monitor_Ping_Reply cmdReply;
cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoBooter;
cmdReply.m_dbg_flags = 0;
cmdReply.Source = Monitor_Ping_c_Ping_Source_NanoBooter;
cmdReply.Flags = 0;

// fill in the flags
#if defined(WP_IMPLEMENTS_CRC32)
cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
cmdReply.Flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
#endif

// Wire Protocol packet size
#if (WP_PACKET_SIZE == 512)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0512;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0512;
#elif (WP_PACKET_SIZE == 256)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0256;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0256;
#elif (WP_PACKET_SIZE == 128)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0128;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0128;
#elif (WP_PACKET_SIZE == 1024)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_1024;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_1024;
#endif

if (Target_HasProprietaryBooter())
{
cmdReply.Flags |= Monitor_Ping_c_HasProprietaryBooter;
}

if (Target_IFUCapable())
{
cmdReply.Flags |= Monitor_Ping_c_IFUCapable;
}

if (Target_ConfigUpdateRequiresErase())
{
cmdReply.Flags |= Monitor_Ping_c_ConfigBlockRequiresErase;
}

WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,22 @@ int Monitor_Ping(WP_Message *message)
if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0)
{
Monitor_Ping_Reply cmdReply;
cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoBooter;
cmdReply.m_dbg_flags = 0;
cmdReply.Source = Monitor_Ping_c_Ping_Source_NanoBooter;
cmdReply.Flags = 0;

#if defined(WP_IMPLEMENTS_CRC32)
cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
cmdReply.Flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
#endif

// Wire Protocol packet size
#if (WP_PACKET_SIZE == 512)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0512;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0512;
#elif (WP_PACKET_SIZE == 256)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0256;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0256;
#elif (WP_PACKET_SIZE == 128)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0128;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0128;
#elif (WP_PACKET_SIZE == 1024)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_1024;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_1024;
#endif

WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply));
Expand Down
29 changes: 22 additions & 7 deletions targets/FreeRTOS/NXP/nanoBooter/WireProtocol_MonitorCommands.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,39 @@ int Monitor_Ping(WP_Message *message)
if ((message->m_header.m_flags & WP_Flags_c_Reply) == 0)
{
Monitor_Ping_Reply cmdReply;
cmdReply.m_source = Monitor_Ping_c_Ping_Source_NanoBooter;
cmdReply.m_dbg_flags = 0;
cmdReply.Source = Monitor_Ping_c_Ping_Source_NanoBooter;
cmdReply.Flags = 0;

#if defined(WP_IMPLEMENTS_CRC32)
cmdReply.m_dbg_flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
cmdReply.Flags |= Monitor_Ping_c_Ping_WPFlag_SupportsCRC32;
#endif

// Wire Protocol packet size
#if (WP_PACKET_SIZE == 512)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0512;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0512;
#elif (WP_PACKET_SIZE == 256)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0256;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0256;
#elif (WP_PACKET_SIZE == 128)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_0128;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_0128;
#elif (WP_PACKET_SIZE == 1024)
cmdReply.m_dbg_flags |= Monitor_Ping_c_PacketSize_1024;
cmdReply.Flags |= Monitor_Ping_c_PacketSize_1024;
#endif

if (Target_HasProprietaryBooter())
{
cmdReply.Flags |= Monitor_Ping_c_HasProprietaryBooter;
}

if (Target_IFUCapable())
{
cmdReply.Flags |= Monitor_Ping_c_IFUCapable;
}

if (Target_ConfigUpdateRequiresErase())
{
cmdReply.Flags |= Monitor_Ping_c_ConfigBlockRequiresErase;
}

WP_ReplyToCommand(message, true, false, &cmdReply, sizeof(cmdReply));
}

Expand Down
Loading

0 comments on commit dd65d45

Please sign in to comment.