Skip to content
This repository was archived by the owner on Jun 5, 2019. It is now read-only.

Commit 7e18234

Browse files
committed
Merge pull request #299 from NETMF/revert-298-DebugCrypto
Revert "Adding support to provide more useful and actionalble diagnos…
2 parents 49be5e9 + d243c88 commit 7e18234

File tree

15 files changed

+89
-307
lines changed

15 files changed

+89
-307
lines changed

Application/TinyBooter/Commands.cpp

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,17 +1452,6 @@ bool Loader_Engine::Monitor_CheckSignature( WP_Message* msg )
14521452
return true;
14531453
}
14541454

1455-
#ifdef DEBUG
1456-
// dumps binary block in a form useable as C code constants for isolated testing and verification
1457-
void DumpBlockDeclaration( char const* name, UINT8 const* pBlock, size_t len )
1458-
{
1459-
debug_printf( "const char %s[] = {", name );
1460-
for( int i = 0; i < len; ++i )
1461-
debug_printf( "%c%d", i == 0 ? ' ' : ',', pBlock[ i ] );
1462-
debug_printf( "};\n" );
1463-
}
1464-
#endif
1465-
14661455
bool Loader_Engine::Monitor_SignatureKeyUpdate( WP_Message* msg )
14671456
{
14681457
bool fSuccess = false;
@@ -1497,23 +1486,13 @@ bool Loader_Engine::Monitor_SignatureKeyUpdate( WP_Message* msg )
14971486
ASSERT(0);
14981487
fSuccess = true;
14991488
}
1500-
else
1501-
{
1502-
#ifdef DEBUG
1503-
debug_printf( "Failed cert check for new key:\n");
1504-
DumpBlockDeclaration( "newKey", cmd->m_newKey, sizeof(RSAKey) );
1505-
DumpBlockDeclaration( "newKeySig", cmd->m_newKeySignature, sizeof( cmd->m_newKeySignature ) );
1506-
DumpBlockDeclaration( "currentKey", g_PrimaryConfigManager.GetDeploymentKeys( cmd->m_keyIndex ), sizeof(RSAKey) );
1507-
#endif
1508-
fSuccess = false;
1509-
}
15101489
}
15111490
}
15121491
}
15131492

15141493
ReplyToCommand( msg, fSuccess, false );
15151494

1516-
return true;
1495+
return true;
15171496
}
15181497

15191498
bool Loader_Engine::Monitor_FlashSectorMap( WP_Message* msg )

Application/TinyBooter/ConfigurationManager.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ void ConfigurationSectorManager::LocateConfigurationSector( UINT32 BlockUsage )
6868

6969
void ConfigurationSectorManager::LoadConfiguration()
7070
{
71-
if (m_device ==NULL)
72-
return;
73-
71+
if (m_device ==NULL) return;
7472
if (m_fSupportsXIP)
7573
{
7674
// Get the real address
@@ -93,8 +91,7 @@ void ConfigurationSectorManager::WriteConfiguration( UINT32 writeOffset, BYTE *d
9391
BOOL eraseWrite = FALSE;
9492
UINT32 writeLengthInBytes ;
9593

96-
if (m_device ==NULL)
97-
return ;
94+
if (m_device ==NULL) return ;
9895

9996
LoadConfiguration();
10097

@@ -182,10 +179,9 @@ void ConfigurationSectorManager::EraseWriteConfigBlock( BYTE * data, UINT32 size
182179

183180
BOOL ConfigurationSectorManager::IsBootLoaderRequired( INT32 &bootModeTimeout )
184181
{
185-
const UINT32 c_Empty = 0xFFFFFFFF;
182+
const UINT32 c_Empty = 0xFFFFFFFF;
186183

187-
if(m_device == NULL)
188-
return FALSE;
184+
if(m_device == NULL) return FALSE;
189185

190186
volatile UINT32* data = (volatile UINT32*)&m_configurationSector->BooterFlagArray[ 0 ];
191187

Application/TinyBooter/CryptoInterface.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44

55
#include "CryptoInterface.h"
66
#include "ConfigurationManager.h"
7+
//--//
78

89
extern UINT8* g_ConfigBuffer;
9-
extern int g_ConfigBufferLength;
10+
extern int g_ConfigBufferLength;
11+
12+
13+
//--//
14+
1015

1116
CryptoState::CryptoState( UINT32 dataAddress, UINT32 dataLength, BYTE* sig, UINT32 sigLength, UINT32 sectorType ) :
1217
#if defined(ARM_V1_2)
@@ -38,16 +43,14 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
3843
// IF THERE IS NO CONFIG SECTOR IN THE FLASH SECTOR TABLE, THEN WE DON'T HAVE KEYS,
3944
// THEREFORE WE WILL NOT PERFORM SIGNATURE CHECKING.
4045
//
41-
if(g_PrimaryConfigManager.m_device == NULL)
42-
return true;
46+
if(g_PrimaryConfigManager.m_device == NULL) return true;
4347

4448

4549
switch(m_sectorType)
4650
{
4751
case BlockRange::BLOCKTYPE_DEPLOYMENT:
4852
// backwards compatibility
49-
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter)
50-
return true;
53+
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter) return true;
5154

5255
// if there is no key then we do not need to check the signature for the deployment sectors ONLY
5356
if(g_PrimaryConfigManager.CheckSignatureKeyEmpty( ConfigurationSector::c_DeployKeyDeployment ))
@@ -70,11 +73,10 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
7073
ASSERT(g_ConfigBufferLength > 0);
7174
ASSERT(g_ConfigBuffer != NULL);
7275

73-
if(g_ConfigBuffer == NULL || g_ConfigBufferLength <= 0)
74-
return false;
76+
if(g_ConfigBuffer == NULL || g_ConfigBufferLength <= 0) return false;
7577

7678
// the g_ConfigBuffer contains the new configuration data
77-
const ConfigurationSector* pNewCfg = (const ConfigurationSector*)g_ConfigBuffer;
79+
const ConfigurationSector* pNewCfg = (const ConfigurationSector*)g_ConfigBuffer;
7880

7981
bool fCanWrite = false;
8082
bool fRet = false;
@@ -123,8 +125,7 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
123125
// backwards compatibility
124126

125127

126-
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter)
127-
return true;
128+
if(g_PrimaryConfigManager.GetTinyBooterVersion() != ConfigurationSector::c_CurrentVersionTinyBooter) return true;
128129

129130
// if there is no key then we do not need to check the signature for the deployment sectors ONLY
130131
if (g_PrimaryConfigManager.CheckSignatureKeyEmpty( keyIndex ))
@@ -135,6 +136,7 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
135136
key = (RSAKey*)g_PrimaryConfigManager.GetDeploymentKeys( keyIndex );
136137

137138
break;
139+
138140
};
139141

140142
if(key == NULL)
@@ -149,7 +151,7 @@ bool CryptoState::VerifySignature( UINT32 keyIndex )
149151
{
150152
m_res = ::Crypto_StepRSAOperation( &m_handle );
151153
}
152-
154+
153155
return m_res == CRYPTO_SUCCESS;
154156
}
155157

Framework/Debugger/DebuggerEventSource.cs

Lines changed: 22 additions & 180 deletions
Original file line numberDiff line numberDiff line change
@@ -4,164 +4,26 @@ namespace Microsoft.SPOT.Debugger
44
{
55
using System;
66
using System.Diagnostics.Tracing;
7-
using WireProtocol;
8-
using System.Collections.Generic;
7+
using Microsoft.SPOT.Debugger.WireProtocol;
98

10-
[EventSource( Name="Microsoft-NETMF-Debugger")]
9+
[EventSource( Name="MsOpenTech-NETMF-Debugger")]
1110
internal class DebuggerEventSource : EventSource
1211
{
1312
public static DebuggerEventSource Log { get { return Log_.Value; } }
1413
private static readonly Lazy<DebuggerEventSource> Log_ = new Lazy<DebuggerEventSource>( ()=>new DebuggerEventSource() );
1514

16-
#if TRACE
17-
[Flags]
18-
enum PacketFlags
15+
[Event(1, Opcode=EventOpcode.Send )]
16+
public void WireProtocolTxHeader( uint cmd, uint flags, ushort seq, ushort seqReply )
1917
{
20-
None = 0,
21-
NonCritical = 0x0001, // This doesn't need an acknowledge.
22-
Reply = 0x0002, // This is the result of a command.
23-
BadHeader = 0x0004,
24-
BadPayload = 0x0008,
25-
Spare0010 = 0x0010,
26-
Spare0020 = 0x0020,
27-
Spare0040 = 0x0040,
28-
Spare0080 = 0x0080,
29-
Spare0100 = 0x0100,
30-
Spare0200 = 0x0200,
31-
Spare0400 = 0x0400,
32-
Spare0800 = 0x0800,
33-
Spare1000 = 0x1000,
34-
NoCaching = 0x2000,
35-
NACK = 0x4000,
36-
ACK = 0x8000,
37-
}
38-
39-
private static Dictionary<uint, string> CommandNameMap = new Dictionary<uint, string>
40-
{
41-
[ Commands.c_Monitor_Ping ] = "Ping",
42-
[ Commands.c_Monitor_Message ] = "Message",
43-
[ Commands.c_Monitor_ReadMemory ] = "ReadMemory",
44-
[ Commands.c_Monitor_WriteMemory ] = "WriteMemory",
45-
[ Commands.c_Monitor_CheckMemory ] = "CheckMemory",
46-
[ Commands.c_Monitor_EraseMemory ] = "EraseMemory",
47-
[ Commands.c_Monitor_Execute ] = "Execute",
48-
[ Commands.c_Monitor_Reboot ] = "Reboot",
49-
[ Commands.c_Monitor_MemoryMap ] = "MemoryMap",
50-
[ Commands.c_Monitor_ProgramExit ] = "ProgramExit",
51-
[ Commands.c_Monitor_CheckSignature ] = "CheckSignature",
52-
[ Commands.c_Monitor_DeploymentMap ] = "DeploymentMap",
53-
[ Commands.c_Monitor_FlashSectorMap ] = "FlashSectorMap",
54-
[ Commands.c_Monitor_SignatureKeyUpdate ] = "SignatureKeyUpdate",
55-
[ Commands.c_Monitor_OemInfo ] = "OemInfo",
56-
[ Commands.c_Debugging_Execution_BasePtr ] = "Execution_BasePtr",
57-
[ Commands.c_Debugging_Execution_ChangeConditions ] = "Execution_ChangeConditions",
58-
[ Commands.c_Debugging_Execution_SecurityKey ] = "Execution_SecurityKey",
59-
[ Commands.c_Debugging_Execution_Unlock ] = "Execution_Unlock",
60-
[ Commands.c_Debugging_Execution_Allocate ] = "Execution_Allocate",
61-
[ Commands.c_Debugging_Execution_Breakpoints ] = "Execution_Breakpoints",
62-
[ Commands.c_Debugging_Execution_BreakpointHit ] = "Execution_BreakpointHit",
63-
[ Commands.c_Debugging_Execution_BreakpointStatus ] = "Execution_BreakpointStatus",
64-
[ Commands.c_Debugging_Execution_QueryCLRCapabilities ] = "Execution_QueryCLRCapabilities",
65-
[ Commands.c_Debugging_Execution_SetCurrentAppDomain ] = "Execution_SetCurrentAppDomain",
66-
[ Commands.c_Debugging_Thread_Create ] = "Thread_Create",
67-
[ Commands.c_Debugging_Thread_List ] = "Thread_List",
68-
[ Commands.c_Debugging_Thread_Stack ] = "Thread_Stack",
69-
[ Commands.c_Debugging_Thread_Kill ] = "Thread_Kill",
70-
[ Commands.c_Debugging_Thread_Suspend ] = "Thread_Suspend",
71-
[ Commands.c_Debugging_Thread_Resume ] = "Thread_Resume",
72-
[ Commands.c_Debugging_Thread_GetException ] = "Thread_GetException",
73-
[ Commands.c_Debugging_Thread_Unwind ] = "Thread_Unwind",
74-
[ Commands.c_Debugging_Thread_CreateEx ] = "Thread_CreateEx",
75-
[ Commands.c_Debugging_Thread_Get ] = "Thread_Get",
76-
[ Commands.c_Debugging_Stack_Info ] = "Stack_Info",
77-
[ Commands.c_Debugging_Stack_SetIP ] = "Stack_SetIP",
78-
[ Commands.c_Debugging_Value_ResizeScratchPad ] = "Value_ResizeScratchPad",
79-
[ Commands.c_Debugging_Value_GetStack ] = "Value_GetStack",
80-
[ Commands.c_Debugging_Value_GetField ] = "Value_GetField",
81-
[ Commands.c_Debugging_Value_GetArray ] = "Value_GetArray",
82-
[ Commands.c_Debugging_Value_GetBlock ] = "Value_GetBlock",
83-
[ Commands.c_Debugging_Value_GetScratchPad ] = "Value_GetScratchPad",
84-
[ Commands.c_Debugging_Value_SetBlock ] = "Value_SetBlock",
85-
[ Commands.c_Debugging_Value_SetArray ] = "Value_SetArray",
86-
[ Commands.c_Debugging_Value_AllocateObject ] = "Value_AllocateObject",
87-
[ Commands.c_Debugging_Value_AllocateString ] = "Value_AllocateString",
88-
[ Commands.c_Debugging_Value_AllocateArray ] = "Value_AllocateArray",
89-
[ Commands.c_Debugging_Value_Assign ] = "Value_Assign",
90-
[ Commands.c_Debugging_TypeSys_Assemblies ] = "TypeSys_Assemblies",
91-
[ Commands.c_Debugging_TypeSys_AppDomains ] = "TypeSys_AppDomains",
92-
[ Commands.c_Debugging_Resolve_Assembly ] = "Resolve_Assembly",
93-
[ Commands.c_Debugging_Resolve_Type ] = "Resolve_Type",
94-
[ Commands.c_Debugging_Resolve_Field ] = "Resolve_Field",
95-
[ Commands.c_Debugging_Resolve_Method ] = "Resolve_Method",
96-
[ Commands.c_Debugging_Resolve_VirtualMethod ] = "Resolve_VirtualMethod",
97-
[ Commands.c_Debugging_Resolve_AppDomain ] = "Resolve_AppDomain",
98-
[ Commands.c_Debugging_MFUpdate_Start ] = "MFUpdate_Start",
99-
[ Commands.c_Debugging_MFUpdate_AddPacket ] = "MFUpdate_AddPacket",
100-
[ Commands.c_Debugging_MFUpdate_Install ] = "MFUpdate_Install",
101-
[ Commands.c_Debugging_MFUpdate_AuthCmd ] = "MFUpdate_AuthCmd",
102-
[ Commands.c_Debugging_MFUpdate_Authenticate ] = "MFUpdate_Authenticate",
103-
[ Commands.c_Debugging_MFUpdate_GetMissingPkts ] = "MFUpdate_GetMissingPkts",
104-
[ Commands.c_Debugging_UpgradeToSsl ] = "UpgradeToSsl",
105-
[ Commands.c_Debugging_Lcd_NewFrame ] = "Lcd_NewFrame",
106-
[ Commands.c_Debugging_Lcd_NewFrameData ] = "Lcd_NewFrameData",
107-
[ Commands.c_Debugging_Lcd_GetFrame ] = "Lcd_GetFrame",
108-
[ Commands.c_Debugging_Button_Report ] = "Button_Report",
109-
[ Commands.c_Debugging_Button_Inject ] = "Button_Inject",
110-
[ Commands.c_Debugging_Messaging_Query ] = "Messaging_Query",
111-
[ Commands.c_Debugging_Messaging_Send ] = "Messaging_Send",
112-
[ Commands.c_Debugging_Messaging_Reply ] = "Messaging_Reply",
113-
[ Commands.c_Debugging_Logging_GetNumberOfRecords ] = "Logging_GetNumberOfRecords",
114-
[ Commands.c_Debugging_Logging_GetRecord ] = "Logging_GetRecord",
115-
[ Commands.c_Debugging_Logging_Erase ] = "Logging_Erase",
116-
[ Commands.c_Debugging_Logging_GetRecords ] = "Logging_GetRecords",
117-
[ Commands.c_Debugging_Deployment_Status ] = "Deployment_Status",
118-
[ Commands.c_Debugging_Info_SetJMC ] = "Info_SetJMC",
119-
[ Commands.c_Profiling_Command ] = "Profiling_Command",
120-
[ Commands.c_Profiling_Stream ] = "Profiling_Stream"
121-
};
122-
123-
string GetCommandName( uint cmd )
124-
{
125-
string retVal;
126-
if( !CommandNameMap.TryGetValue( cmd, out retVal ) )
127-
retVal = $"0x{cmd:X08}";
128-
129-
return retVal;
130-
}
131-
#endif
132-
133-
[Event( 1, Opcode = EventOpcode.Send )]
134-
public void WireProtocolTxHeader( uint crcHeader, uint crcData, uint cmd, uint flags, ushort seq, ushort seqReply, uint length )
135-
{
136-
#if TRACE
137-
Trace.TraceInformation( "TX: {0} flags=[{1}] hCRC: 0x{2:X08} pCRC: 0x{3:X08} seq: 0x{4:X04} replySeq: 0x{5:X04} len={6}"
138-
, GetCommandName( cmd )
139-
, ( PacketFlags )flags
140-
, crcHeader
141-
, crcData
142-
, seq
143-
, seqReply
144-
, length
145-
);
146-
#endif
147-
WriteCustomEvent( 1, crcHeader, crcData, cmd, flags, seq, seqReply, length );
18+
Trace.TraceInformation( "TX: {0:X08} {1:X08} {2:X04} {3:X04}", cmd, flags, seq, seqReply );
19+
WriteCustomEvent( 1, cmd, flags, seq, seqReply );
14820
}
14921

15022
[Event( 2, Opcode = EventOpcode.Receive )]
151-
public void WireProtocolRxHeader( uint crcHeader, uint crcData, uint cmd, uint flags, ushort seq, ushort seqReply, uint length )
23+
public void WireProtocolRxHeader( uint cmd, uint flags, ushort seq, ushort seqReply )
15224
{
153-
#if TRACE
154-
Trace.TraceInformation( "RX: {0} flags=[{1}] hCRC: 0x{2:X08} pCRC: 0x{3:X08} seq: 0x{4:X04} replySeq: 0x{5:X04} len={6}"
155-
, GetCommandName( cmd )
156-
, ( PacketFlags )flags
157-
, crcHeader
158-
, crcData
159-
, seq
160-
, seqReply
161-
, length
162-
);
163-
#endif
164-
WriteCustomEvent( 2, crcHeader, crcData, cmd, flags, seq, seqReply, length );
25+
Trace.TraceInformation( "RX: {0:X08} {1:X08} {2:X04} {3:X04}", cmd, flags, seq, seqReply );
26+
WriteCustomEvent( 2, cmd, flags, seq, seqReply );
16527
}
16628

16729
[Event( 3 )]
@@ -173,47 +35,27 @@ public void WireProtocolReceiveState( MessageReassembler.ReceiveState state )
17335
[Event(4)]
17436
public void EngineEraseMemory( uint address, uint length )
17537
{
176-
Trace.TraceInformation( "EraseMemory: @0x{0:X08}; LEN=0x{1:X08}", address, length );
38+
Trace.TraceInformation( "EreaseMemory: @{0:X08}; LEN={1:X08}", address, length );
17739
WriteEvent( 4, ( int )address, ( int )length );
17840
}
17941

180-
[Event(5)]
181-
public void EngineWriteMemory( uint address, int length )
182-
{
183-
Trace.TraceInformation( "WriteMemory: @0x{0:X08}; LEN=0x{1:X08}", address, length );
184-
WriteEvent( 5, ( int )address, length );
185-
}
186-
18742
private DebuggerEventSource()
18843
{
18944
}
19045

19146
[NonEvent]
192-
unsafe void WriteCustomEvent( int eventId, uint crcHeader, uint crcData, uint cmd, uint flags, ushort seq, ushort seqReply, uint length )
193-
{
194-
EventData* pDataDesc = stackalloc EventData[ 7 ];
195-
pDataDesc[ 0 ].DataPointer = ( IntPtr )( &crcHeader );
196-
pDataDesc[ 0 ].Size = sizeof( uint );
197-
198-
pDataDesc[ 1 ].DataPointer = ( IntPtr )( &crcData );
199-
pDataDesc[ 1 ].Size = sizeof( uint );
200-
201-
pDataDesc[ 2 ].DataPointer = (IntPtr)( &cmd );
202-
pDataDesc[ 2 ].Size = sizeof( uint );
203-
204-
pDataDesc[ 3 ].DataPointer = ( IntPtr )( &flags );
205-
pDataDesc[ 3 ].Size = sizeof( uint );
206-
207-
pDataDesc[ 4 ].DataPointer = ( IntPtr )( &seq );
208-
pDataDesc[ 4 ].Size = sizeof( ushort );
209-
210-
pDataDesc[ 5 ].DataPointer = ( IntPtr )( &seqReply );
211-
pDataDesc[ 5 ].Size = sizeof( ushort );
212-
213-
pDataDesc[ 6 ].DataPointer = ( IntPtr )( &length );
214-
pDataDesc[ 6 ].Size = sizeof( uint );
215-
216-
WriteEventCore( eventId, 7, pDataDesc );
47+
unsafe void WriteCustomEvent(int eventId, uint cmd, uint flags, ushort seq, ushort seqReply )
48+
{
49+
EventData* pDataDesc = stackalloc EventData[ 4 ];
50+
pDataDesc[ 0 ].DataPointer = (IntPtr)( &cmd );
51+
pDataDesc[ 0 ].Size = sizeof( int );
52+
pDataDesc[ 1 ].DataPointer = ( IntPtr )( &flags );
53+
pDataDesc[ 1 ].Size = sizeof( int );
54+
pDataDesc[ 2 ].DataPointer = ( IntPtr )( &seq );
55+
pDataDesc[ 2 ].Size = sizeof( ushort );
56+
pDataDesc[ 3 ].DataPointer = ( IntPtr )( &seqReply );
57+
pDataDesc[ 3 ].Size = sizeof( ushort );
58+
WriteEventCore( eventId, 4, pDataDesc );
21759
}
21860
}
21961
}

Framework/Debugger/WireProtocol/Engine.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,6 @@ public bool WriteMemory( uint address, byte[ ] buf, int offset, int length )
16591659

16601660
cmd.PrepareForSend( address, buf, pos, len );
16611661

1662-
DebuggerEventSource.Log.EngineWriteMemory( address, len );
16631662
IncomingMessage reply = SyncMessage( Commands.c_Monitor_WriteMemory, 0, cmd );
16641663

16651664
if( !IncomingMessage.IsPositiveAcknowledge( reply ) )

0 commit comments

Comments
 (0)