-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
58 lines (49 loc) · 1.28 KB
/
main.cpp
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
#include <stdio.h>
#include <stdlib.h>
#include "hidapi.h"
#include "bootloader.h"
#include <iostream>
#define MAX_STR 255
int main(int argc, char *argv[])
{
if (argc < 2)
{
std::cout << "Argument error, usage: blapp <path_to_hex_file>" << std::endl;
exit(EXIT_FAILURE);
}
Bootloader bl;
std::string pathToHexFile(argv[1]);
if (!bl.Initialize(pathToHexFile))
{
std::cout << "Initialize failed, aborting program" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Querying bootloader info..." << std::endl;
if (!bl.GetInfo())
{
std::cout << "Getting bootloader info failed, aborting program" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Erasing..." << std::endl;
if (!bl.Erase())
{
std::cout << "Erasing application flash failed, aborting program" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Programming..." << std::endl;
if (!bl.Program())
{
std::cout << "Programming application flash failed, aborting program" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Verifying..." << std::endl;
if (!bl.Verify())
{
std::cout << "Verifying application flash failed, aborting program" << std::endl;
exit(EXIT_FAILURE);
}
std::cout << "Jumping to app..." << std::endl;
bl.JumpToApp();
std::cout << "Complete" << std::endl;
exit(EXIT_SUCCESS);
}