forked from jonasblixt/punchboot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
122 lines (95 loc) · 2.43 KB
/
main.c
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
/**
* Punch BOOT
*
* Copyright (C) 2020 Jonas Blixt <[email protected]>
*
* SPDX-License-Identifier: BSD-3-Clause
*
*/
#include <stdio.h>
#include <pb/pb.h>
#include <pb/arch.h>
#include <pb/plat.h>
#include <pb/timestamp.h>
#include <pb/storage.h>
#include <pb/command.h>
#include <pb/crypto.h>
#include <pb/boot.h>
static struct pb_timestamp ts_plat_early = TIMESTAMP("Platform early");
static struct pb_timestamp ts_crypto = TIMESTAMP("Crypto");
static struct pb_timestamp ts_storage = TIMESTAMP("Storage");
static struct pb_timestamp ts_slc = TIMESTAMP("SLC");
static struct pb_timestamp ts_boot_init = TIMESTAMP("Boot init");
static struct pb_timestamp ts_total = TIMESTAMP("Total");
void pb_main(void)
{
int rc;
arch_init();
timestamp_init();
/*
* Perform really early stuff, like setup RAM and other
* arch/platform specific tasks
*/
timestamp_begin(&ts_total);
timestamp_begin(&ts_plat_early);
pb_storage_early_init();
rc = plat_early_init();
if (rc != PB_OK)
plat_reset();
timestamp_end(&ts_plat_early);
plat_console_init();
#ifdef CONFIG_ENABLE_WATCHDOG
plat_wdog_init();
#endif
#if LOGLEVEL > 0
printf("\n\r\n\rPB " PB_VERSION " starting\n\r");
#endif
timestamp_begin(&ts_crypto);
rc = plat_crypto_init();
if (rc != PB_OK)
{
LOG_ERR("Could not initialize crypto");
goto run_command_mode;
}
timestamp_end(&ts_crypto);
timestamp_begin(&ts_storage);
rc = pb_storage_init();
if (rc != PB_OK)
{
LOG_ERR("Could not initialize storage");
goto run_command_mode;
}
timestamp_end(&ts_storage);
timestamp_begin(&ts_slc);
rc = plat_slc_init();
if (rc != PB_OK)
{
LOG_ERR("Could not initialize SLC");
goto run_command_mode;
}
timestamp_end(&ts_slc);
timestamp_begin(&ts_boot_init);
rc = pb_boot_init();
if (rc != PB_OK)
{
LOG_ERR("Could not load boot state");
goto run_command_mode;
}
timestamp_end(&ts_boot_init);
if (plat_force_command_mode())
{
LOG_INFO("Forced command mode");
goto run_command_mode;
}
rc = pb_boot_load_fs(NULL);
if (rc != PB_OK)
{
LOG_ERR("Could not boot");
goto run_command_mode;
}
pb_boot(&ts_total, false, false);
LOG_INFO("Boot stopped, entering command mode");
run_command_mode:
pb_command_run();
plat_reset();
}