Repository navigation
Expand file tree
/
Copy pathforce_assert.c
More file actions
118 lines (103 loc) · 2.71 KB
/
Copy pathforce_assert.c
File metadata and controls
118 lines (103 loc) · 2.71 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
/*
* Copyright 2021 Morse Micro
*/
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdint.h>
#include "portable_endian.h"
#include "command.h"
enum hartid
{
HOST_HARTID = 0,
MAC_HARTID = 1,
UPHY_HARTID = 2,
LPHY_HARTID = 3
};
struct PACKED command_force_assert_req
{
/* Target hart to crash with an intended assert */
uint32_t hart_id;
};
static void usage(struct morsectrl *mors) {
mctrl_print("\tassert <core>\t\tforces the specified core to assert" \
"- defaults to mac if no arg\n");
mctrl_print("\t\t-a\t\tApp core\n");
mctrl_print("\t\t-m\t\tMac core\n");
mctrl_print("\t\t-u\t\tUphy core\n");
mctrl_print("\t\t-l\t\tLphy core\n");
}
int force_assert(struct morsectrl *mors, int argc, char *argv[])
{
int ret = -1;
int hart_id, option;
struct command_force_assert_req *cmd;
struct morsectrl_transport_buff *cmd_tbuff;
struct morsectrl_transport_buff *rsp_tbuff;
if (argc == 0)
{
usage(mors);
return 0;
}
if (argc > 2)
{
mctrl_err("Invalid command parameters\n");
usage(mors);
return -1;
}
cmd_tbuff = morsectrl_transport_cmd_alloc(&mors->transport, sizeof(*cmd));
rsp_tbuff = morsectrl_transport_resp_alloc(&mors->transport, 0);
if (!cmd_tbuff || !rsp_tbuff)
goto exit;
cmd = TBUFF_TO_CMD(cmd_tbuff, struct command_force_assert_req);
if (argc == 1)
{
hart_id = MAC_HARTID;
}
else
{
while ((option = getopt(argc, argv, "amul")) != -1)
{
switch (option)
{
case 'a' :
hart_id = HOST_HARTID;
break;
case 'm' :
hart_id = MAC_HARTID;
break;
case 'u' :
hart_id = UPHY_HARTID;
break;
case 'l' :
hart_id = LPHY_HARTID;
break;
default:
mctrl_err("Invalid hart\n");
usage(mors);
ret = -1;
goto exit;
}
}
}
cmd->hart_id = htole32(hart_id);
ret = morsectrl_send_command(&mors->transport, MORSE_TEST_COMMAND_FORCE_ASSERT,
cmd_tbuff, rsp_tbuff);
exit:
if (ret != -110)
{
mctrl_err("Chip didn't timeout. Command failed\n");
if (ret)
mctrl_err("Wrong error code returned: %d\n", ret);
ret = -1;
}
else
{
ret = 0;
}
morsectrl_transport_buff_free(cmd_tbuff);
morsectrl_transport_buff_free(rsp_tbuff);
return ret;
}