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.
- Following nanoframework/nf-debugger#253.
  • Loading branch information
josesimoes committed Nov 6, 2020
1 parent dbbe723 commit 0a12ff2
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 49 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
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

0 comments on commit 0a12ff2

Please sign in to comment.