📄 jlinkserver.cpp
字号:
// JLinkServer.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
SOCKET server;
char* image = NULL;
int flash = 1;
int port = 11444;
int nodownload = 1;
int run = 0;
cerr.setf(ios_base::hex); cout.setf(ios_base::hex);
for (int i = 1; i < argc; i++) {
if (strcmp(argv[i], "-flash") == 0) {
flash = 1;
}
else if (strcmp(argv[i], "-ram") == 0) {
flash = 0;
}
else if (strcmp(argv[i], "-port") == 0) {
port = strtol(argv[i+1], NULL, 10);
i++;
}
else if (strcmp(argv[i], "-nodownload") == 0) {
nodownload = 1;
}
else if (strcmp(argv[i], "-run") == 0) {
run = 1;
}
else if (argv[i][0] == '-') {
cerr << "usage: " << argv[0] << " [-flash] [-ram] [-run] [-port <port>] [-nodownload] <image>" << endl;
goto failed;
}
else if (image == NULL) {
image = argv[i];
nodownload = 0;
}
else {
cerr << "Cannot specifiy image multiple times" << endl;
goto failed;
}
}
if (!nodownload && (image == NULL)) {
cerr << "Must specify the image" << endl;
goto failed;
}
JTAG* jtag = new JTAG();
if (!nodownload) {
ELF* elffile = new ELF(image);
// jtag->StartLogging();
if (flash) {
jtag->FlashDownload(elffile);
}
else {
jtag->RamDownload(elffile);
}
}
else {
jtag->Initialise();
jtag->MapRam(!flash);
}
if (run) {
jtag->Go();
}
else {
// jtag->StartLogging();
server = CreateServerSocket(port);
if (server == INVALID_SOCKET) {
cerr << "Failed to create server socket: " << GetLastError() << endl;
goto failed;
}
while (1) {
SOCKADDR_IN addr;
int len = sizeof(addr);
SOCKET client = accept(server, (sockaddr*)&addr, &len);
if (client == INVALID_SOCKET) {
cerr << "Failed to accept connection: " << GetLastError() << endl;
goto failed;
}
// Create and run the server
GdbServer* debugger = new GdbServer(client, jtag);
debugger->Run();
delete debugger;
printf("Session finished - preparing next one\n");
// Get ready for next time
jtag->Initialise();
jtag->MapRam(!flash);
}
}
return 0;
failed:
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -