This repository was archived by the owner on Apr 14, 2023. It is now read-only.
forked from Xilinx/bootgen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
executable file
·158 lines (144 loc) · 4.97 KB
/
main.cpp
File metadata and controls
executable file
·158 lines (144 loc) · 4.97 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/******************************************************************************
* Copyright 2015-2019 Xilinx, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
******************************************************************************/
/*
-------------------------------------------------------------------------------
*********************************************** H E A D E R F I L E S ***
-------------------------------------------------------------------------------
*/
#include <stdio.h>
#include <string>
#include <time.h>
#include <signal.h>
#include "bootimage.h"
#include "bootgenexception.h"
#include "options.h"
#include "bifoptions.h"
#include "stringutils.h"
#include "version.h"
#include "readimage-zynq.h"
#include "readimage-zynqmp.h"
#include "encryption-zynqmp.h"
#ifdef _WIN32
#include "openssl/ms/applink.c"
#endif
static const char* time_stamp = __TIME__;
static const char* date_stamp = __DATE__;
/*
-------------------------------------------------------------------------------
***************************************************** F U N C T I O N S ***
-------------------------------------------------------------------------------
*/
/******************************************************************************/
static void DisplayBanner()
{
char version[64], *year;
strncpy(version, RDI_VERSION, sizeof version);
version[sizeof version - 1] = '\0';
year = strtok(version, ".");
LOG_MSG("\n");
LOG_MSG("****** %s v%s", PROGRAMNAME, RDI_VERSION);
LOG_MSG(" **** Build date : %s-%s", date_stamp, time_stamp);
LOG_MSG(" ** Copyright 1986-%s Xilinx, Inc. All Rights Reserved.\n", year ? year : "2018");
}
/******************************************************************************/
class BootGenApp
{
public:
void Run(int argc, const char* argv[])
{
Options options;
options.ParseArgs(argc, argv);
std::string readFile = options.GetReadImageFile();
if (options.archType != Arch::ZYNQMP)
{
if (options.GetVerifyImageOption())
{
LOG_ERROR("'-verify' option supported only for ZynqMP architecture, '-arch zynqmp'.");
}
if (options.GetKDFTestVectorFile() != "")
{
LOG_ERROR("'-verify_kdf' option supported only for ZynqMp architecture, '-arch zynqmp'.");
}
}
if (options.archType == Arch::ZYNQ)
{
if (readFile != "")
{
ZynqReadImage* readImage = new ZynqReadImage(readFile);
readImage->DisplayImageDetails(options.GetReadImageOption(), options.GetDumpOption());
delete readImage;
return;
}
}
else if (options.archType == Arch::ZYNQMP)
{
if (options.GetVerifyImageOption())
{
ZynqMpReadImage* readImage = new ZynqMpReadImage(readFile);
readImage->VerifyAuthentication(options.GetVerifyImageOption());
delete readImage;
return;
}
else if (options.GetKDFTestVectorFile() != "")
{
ZynqMpEncryptionContext* encryptCtx = new ZynqMpEncryptionContext;
encryptCtx->CAVPonCounterModeKDF(options.GetKDFTestVectorFile());
delete encryptCtx;
return;
}
if (readFile != "")
{
ZynqMpReadImage* readImage = new ZynqMpReadImage(readFile);
readImage->DisplayImageDetails(options.GetReadImageOption(), options.GetDumpOption());
delete readImage;
return;
}
}
std::string bifFile = options.GetBifFilename();
LOG_TRACE("BIF File: %s", bifFile.c_str());
if (bifFile.length() > 0)
{
BIF_File bif(bifFile);
bif.Process(options);
}
}
};
/******************************************************************************/
int main(int argc, const char* argv[])
{
try
{
BootGenApp app;
DisplayBanner();
app.Run(argc,argv);
return 0;
}
catch(std::exception& ex)
{
std::cerr << "[ERROR] : " << ex.what() << std::endl;
return 1;
}
catch(const char* msg)
{
std::cerr << "FATAL: Internal Assertion: " << msg << std::endl;
return 2;
}
catch(...)
{
std::cerr << "FATAL: Unknown Exception caught."<< std::endl;
return 3;
}
}