This repository was archived by the owner on Jun 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathTinyBooter.cpp
More file actions
128 lines (99 loc) · 4.52 KB
/
TinyBooter.cpp
File metadata and controls
128 lines (99 loc) · 4.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Microsoft Corporation. All rights reserved.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "TinyBooter.h"
#include "TinyCLR_Version.h"
#include <tinybooterentry.h>
#include "ConfigurationManager.h"
extern bool WaitForTinyBooterUpload( INT32 &timeout_ms );
////////////////////////////////////////////////////////////////////////////////
//--//
Loader_Engine g_eng;
//--//
void ApplicationEntryPoint()
{
INT32 timeout = 20000; // 20 second timeout
bool enterBootMode = false;
g_eng.Initialize( HalSystemConfig.DebuggerPorts[ 0 ] );
// internal reset and stop check
enterBootMode = g_PrimaryConfigManager.IsBootLoaderRequired( timeout );
// ODM defined method to enter bootloader mode
if(!enterBootMode)
{
enterBootMode = WaitForTinyBooterUpload( timeout );
}
if(!enterBootMode)
{
if(!g_eng.EnumerateAndLaunch())
{
timeout = -1;
enterBootMode = true;
}
}
if(enterBootMode)
{
LCD_Clear();
hal_fprintf( STREAM_LCD, "TinyBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
hal_fprintf( STREAM_LCD, "%s Build Date:\r\n\t%s %s\r\n", HalName, __DATE__, __TIME__ );
DebuggerPort_Initialize( HalSystemConfig.DebuggerPorts[ 0 ] );
TinyBooter_OnStateChange( State_EnterBooterMode, NULL );
DebuggerPort_Flush( HalSystemConfig.DebugTextPort );
hal_printf( "TinyBooter v%d.%d.%d.%d\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD, VERSION_REVISION);
hal_printf( "%s Build Date: %s %s\r\n", HalName, __DATE__, __TIME__ );
#if defined(__GNUC__)
hal_printf("GNU Compiler version %d\r\n", __GNUC__);
#elif defined(_ARC)
hal_printf("ARC Compiler version %d\r\n", _ARCVER);
#elif defined(__ADSPBLACKFIN__)
hal_printf( "Blackfin Compiler version %d\r\n", __VERSIONNUM__ );
#elif defined(__RENESAS__)
hal_printf( "Renesas Compiler version %d\r\n", __RENESAS_VERSION__ );
#else
hal_printf( "ARM Compiler version %d\r\n", __ARMCC_VERSION );
#endif
DebuggerPort_Flush( HalSystemConfig.DebugTextPort );
//
// Send "presence" ping.
//
{
CLR_DBG_Commands::Monitor_Ping cmd;
cmd.m_source = CLR_DBG_Commands::Monitor_Ping::c_Ping_Source_TinyBooter;
g_eng.m_controller.SendProtocolMessage( CLR_DBG_Commands::c_Monitor_Ping, WP_Flags::c_NonCritical, sizeof(cmd), (UINT8*)&cmd );
}
UINT64 ticksStart = HAL_Time_CurrentTicks();
//
// Wait for somebody to press a button; if no button press comes in, lauch the image
//
do
{
const UINT32 c_EventsMask = SYSTEM_EVENT_FLAG_COM_IN |
SYSTEM_EVENT_FLAG_USB_IN |
SYSTEM_EVENT_FLAG_BUTTON;
UINT32 events = ::Events_WaitForEvents( c_EventsMask, timeout );
if(events != 0)
{
Events_Clear( events );
}
if(events & SYSTEM_EVENT_FLAG_BUTTON)
{
TinyBooter_OnStateChange( State_ButtonPress, (void*)&timeout );
}
if(events & (SYSTEM_EVENT_FLAG_COM_IN | SYSTEM_EVENT_FLAG_USB_IN))
{
g_eng.ProcessCommands();
}
if(LOADER_ENGINE_ISFLAGSET(&g_eng, Loader_Engine::c_LoaderEngineFlag_ValidConnection))
{
LOADER_ENGINE_CLEARFLAG(&g_eng, Loader_Engine::c_LoaderEngineFlag_ValidConnection);
TinyBooter_OnStateChange( State_ValidCommunication, (void*)&timeout );
ticksStart = HAL_Time_CurrentTicks();
}
else if((timeout != -1) && (HAL_Time_CurrentTicks()-ticksStart) > CPU_MillisecondsToTicks((UINT32)timeout))
{
TinyBooter_OnStateChange( State_Timeout, NULL );
g_eng.EnumerateAndLaunch();
}
} while(true);
}
::CPU_Reset();
}