-
Notifications
You must be signed in to change notification settings - Fork 0
/
oemDualImgCmd.c
executable file
·196 lines (159 loc) · 4.48 KB
/
oemDualImgCmd.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/*follow pure ast2600 soc chip fmc register feature design
************************************************************
odic moduel programing:
1.open_fmc_stdin
for opening register mapping
2.read_and_write_fmc_stdin
for writing and reading register
3.close_fmc_stdin
for closing register mapping
************************************************************
function impl:
1.odic_get_boot_indicator
get now active img index
00 -> master spi
01 -> backup spi
2.odic_set_boot_indicator
set next boot image index and reset bmc
if setted next boot img index == now active img index
do nothing
else
switch to another image __NOW__
************************************************************
rm NDA info
************************************************************
EyerNi 23/11/16*/
#include <dlfcn.h>
#include <string.h>
#include <sys/mman.h>
/*rm NDA info*/
#include "oemDualImgCmd.h"
/* ami spx framework ipmi cmd config */
/*rm NDA info*/
/*rm NDA info*/
/* memery maping head address */
u8 *fmc_stdin = NULL;
/* memery device */
signed memdev = -1;
/*pre define*/
ODIC open_fmc_stdin(void);
ODIC close_fmc_stdin(void);
ODIC reverse_img(void);
ODIC clear_boot_indicator_to_0(void);
ODIC get_boot_indicator(u8 *next_boot_spi_index);
ipmi_odic_res odic_get_boot_indicator(_NEAR_ u8 *pReq, u32 ReqLen, _NEAR_ u8 *pRes, _NEAR_ int __attribute__((unused)) BMCInst);
ipmi_odic_res odic_set_boot_indicator(_NEAR_ u8 *pReq, u32 ReqLen, _NEAR_ u8 *pRes, _NEAR_ int __attribute__((unused)) BMCInst);
/*odic moduel std input open*/
ODIC
open_fmc_stdin(void)
{
memdev = open("/dev/mem", O_RDWR | O_NDELAY);
if (memdev < 0)
return ODIC_FILE_ACCESS_FILE;
fmc_stdin = (unsigned char *)mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, memdev, AST_FMC_BASE);
if (fmc_stdin == NULL)
{
close(memdev);
return ODIC_MEM_MAP_FAIL;
}
return ODIC_SUCC;
}
/*odic moduel std input close*/
ODIC
close_fmc_stdin(void)
{
close(memdev);
memdev = -1;
munmap(fmc_stdin, MAP_SIZE);
fmc_stdin = NULL;
return ODIC_SUCC;
}
/* get next boot spi index */
ODIC
get_boot_indicator(u8 *next_boot_spi_index)
{
OPEN_FMC;
*next_boot_spi_index = (read_and_write_fmc_stdin(FMC_WDT2_CRAB_IO_ADDR_OFFSET) & FMC_WDT2_BIT4_BOOT_INDICATOR) >> 4;
CLOSE_FMC;
}
/* clear boot indicator to 0 */
ODIC
clear_boot_indicator_to_0(void)
{
OPEN_FMC;
read_and_write_fmc_stdin(FMC_WDT2_CRAB_IO_ADDR_OFFSET) |= FMC_WDT2_CMD_CLEAR_BOOT_INDICATOR;
CLOSE_FMC;
}
/* goto spix = (nowspi == spi0 ? spi1 : spi0) */
ODIC
reverse_img(void)
{
OPEN_FMC;
read_and_write_fmc_stdin(FMC_WDT2_CRAB_IO_ADDR_OFFSET) |= FMC_WDT2_BIT0_ENABLE;
read_and_write_fmc_stdin(FMC_WDT2_TRVR_IO_ADDR_OFFSET) = FMC_WDT2_COUNTDOWN;
read_and_write_fmc_stdin(FMC_WDT2_TRR_IO_ADDR_OFFSET) = FMC_WDT2_TRR_KEY;
CLOSE_FMC;
}
/*odic moduel ipmi interface get active image index*/
IPMICMD_DEF(0xff,0xff-1,oem,fffff)
odic_get_boot_indicator(_NEAR_ u8 *pReq, u32 ReqLen, _NEAR_ u8 *pRes, _NEAR_ int __attribute__((unused)) BMCInst)
{
if (0)
{
pReq = pReq;
ReqLen = ReqLen;
}
u8 next_boot_spi_index = 0xff;
odic_res_e cmd_status = get_boot_indicator(&next_boot_spi_index);
if (cmd_status != ODIC_SUCC)
{
*pRes = -1 /*rm NDA info*/;
return sizeof(u8);
}
*pRes = /*rm NDA info*/ 0;
*(pRes + sizeof(u8)) = next_boot_spi_index;
return sizeof(u8) * 2;
}
/*odic moduel ipmi interface set active image index*/
IPMICMD_DEF(0xff,0xff,oem,fffff)
odic_set_boot_indicator(_NEAR_ u8 *pReq, u32 ReqLen, _NEAR_ u8 *pRes, _NEAR_ int __attribute__((unused)) BMCInst)
{
if (0)
{
ReqLen = ReqLen;
}
/* feature reqs more than just 1 spi */
/*rm NDA info*/
/* input need <= max count of spi , for now it is (0) or (1) <= (2-1) */
/*rm NDA info*/
u8 next_boot_spi_index = 0xff;
odic_res_e cmd_status = get_boot_indicator(&next_boot_spi_index);
if (cmd_status != ODIC_SUCC)
{
*pRes = /*rm NDA info*/ -1;
return sizeof(u8);
}
if (*pReq == next_boot_spi_index)
{
*pRes = /*rm NDA info*/ 0;
return sizeof(u8);
}
cmd_status = reverse_img();
if (cmd_status != ODIC_SUCC)
*pRes = /*rm NDA info*/ -1;
else
*pRes = /*rm NDA info*/ 0;
if (*pRes == /*rm NDA info*/ 0)
BMC_TAUDIT(LOG_INFO, "Reserved", "Flash%d manually switch to flash%d", next_boot_spi_index, next_boot_spi_index == 0 ? 1 : 0);
return sizeof(u8);
}
/*useless*/
ODIC __attribute__((unused))
ODIC_UNUSE(void)
{
if (0)
{
clear_boot_indicator_to_0();
}
return ODIC_SUCC;
}