Software APIs
firmware_fi.c
1 // Copyright lowRISC contributors (OpenTitan project).
2 // Licensed under the Apache License, Version 2.0, see LICENSE for details.
3 // SPDX-License-Identifier: Apache-2.0
4 #include <stdbool.h>
5 
6 #include "sw/device/lib/base/status.h"
7 #include "sw/device/lib/crypto/drivers/entropy.h"
8 #include "sw/device/lib/testing/test_framework/check.h"
10 #include "sw/device/lib/testing/test_framework/ujson_ottf.h"
11 #include "sw/device/lib/ujson/ujson.h"
12 
13 // Include commands
14 #include "sw/device/tests/penetrationtests/json/commands.h"
15 #include "sw/device/tests/penetrationtests/json/crypto_fi_commands.h"
16 #include "sw/device/tests/penetrationtests/json/ibex_fi_commands.h"
17 #include "sw/device/tests/penetrationtests/json/lc_ctrl_fi_commands.h"
18 #include "sw/device/tests/penetrationtests/json/otp_fi_commands.h"
19 #include "sw/device/tests/penetrationtests/json/rng_fi_commands.h"
20 #include "sw/device/tests/penetrationtests/json/rom_fi_commands.h"
21 
22 // Include handlers
23 #include "fi/crypto_fi.h"
24 #include "fi/ibex_fi.h"
25 #include "fi/lc_ctrl_fi.h"
26 #include "fi/otp_fi.h"
27 #include "fi/rng_fi.h"
28 #include "fi/rom_fi.h"
29 #include "lib/extclk_sca_fi.h"
30 
31 OTTF_DEFINE_TEST_CONFIG(.enable_uart_flow_control = true);
32 
33 status_t process_cmd(ujson_t *uj) {
34  while (true) {
35  penetrationtest_cmd_t cmd;
36  TRY(ujson_deserialize_penetrationtest_cmd_t(uj, &cmd));
37  switch (cmd) {
38  case kPenetrationtestCommandCryptoFi:
39  RESP_ERR(uj, handle_crypto_fi(uj));
40  break;
41  case kPenetrationtestCommandExtClkScaFi:
42  RESP_ERR(uj, handle_extclk_sca_fi(uj));
43  break;
44  case kPenetrationtestCommandIbexFi:
45  RESP_ERR(uj, handle_ibex_fi(uj));
46  break;
47  case kPenetrationtestCommandLCCtrlFi:
48  RESP_ERR(uj, handle_lc_ctrl_fi(uj));
49  break;
50  case kPenetrationtestCommandOtpFi:
51  RESP_ERR(uj, handle_otp_fi(uj));
52  break;
53  case kPenetrationtestCommandRngFi:
54  RESP_ERR(uj, handle_rng_fi(uj));
55  break;
56  case kPenetrationtestCommandRomFi:
57  RESP_ERR(uj, handle_rom_fi(uj));
58  break;
59  default:
60  LOG_ERROR("Unrecognized command: %d", cmd);
61  RESP_ERR(uj, INVALID_ARGUMENT());
62  }
63  }
64 
65  return OK_STATUS();
66 }
67 
68 bool test_main(void) {
69  CHECK_STATUS_OK(entropy_complex_init());
70  ujson_t uj = ujson_ottf_console();
71  return status_ok(process_cmd(&uj));
72 }