Software APIs
rescue.h
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 
5 #ifndef OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXT_RESCUE_H_
6 #define OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXT_RESCUE_H_
7 
8 #include <stdbool.h>
9 #include <stdint.h>
10 
11 #include "sw/device/silicon_creator/lib/boot_data.h"
12 #include "sw/device/silicon_creator/lib/error.h"
13 #include "sw/device/silicon_creator/lib/ownership/datatypes.h"
14 
15 enum {
16  // Rescue is signalled by asserting serial break to the UART for at least
17  // 4 byte periods. At 115200 bps, one byte period is about 87us; four is
18  // about 348us. We'll wait for 350.
19  kRescueDetectTime = 350,
20 };
21 
22 typedef enum {
23  /** `BAUD` */
24  kRescueModeBaud = 0x42415544,
25  /** `BLOG` */
26  kRescueModeBootLog = 0x424c4f47,
27  /** `BRSP` */
28  kRescueModeBootSvcRsp = 0x42525350,
29  /** `BREQ` */
30  kRescueModeBootSvcReq = 0x42524551,
31  /** `KLBR` */
32  kRescueModeKlobber = 0x4b4c4252,
33  /** `OWNR` */
34  kRescueModeOwnerBlock = 0x4f574e52,
35  /** `OPG0` */
36  kRescueModeOwnerPage0 = 0x4f504730,
37  /** `OPG1` */
38  kRescueModeOwnerPage1 = 0x4f504731,
39  /** `OTID` */
40  kRescueModeOpenTitanID = 0x4f544944,
41  /** `RESQ` */
42  kRescueModeFirmware = 0x52455351,
43  /** `RESB` */
44  kRescueModeFirmwareSlotB = 0x52455342,
45  /** `REBO` */
46  kRescueModeReboot = 0x5245424f,
47  /** `WAIT` */
48  kRescueModeWait = 0x57414954,
49 } rescue_mode_t;
50 
51 typedef enum {
52  /** `115K` */
53  kRescueBaud115K = 0x4b353131,
54  /** `230K` */
55  kRescueBaud230K = 0x4b303332,
56  /** `460K` */
57  kRescueBaud460K = 0x4b303634,
58  /** `921K` */
59  kRescueBaud921K = 0x4b313239,
60  /** `1M33` */
61  kRescueBaud1M33 = 0x33334d31,
62  /** `1M50` */
63  kRescueBaud1M50 = 0x30354d31,
64 } rescue_baud_t;
65 
66 typedef struct RescueState {
67  rescue_mode_t mode;
68  // Whether to reboot automatically after an xmodem upload.
69  bool reboot;
70  // Current xmodem frame.
71  uint32_t frame;
72  // Current data offset.
73  uint32_t offset;
74  // Current flash write offset.
75  uint32_t flash_offset;
76  // Range to erase and write for firmware rescue (inclusive).
77  uint32_t flash_start;
78  uint32_t flash_limit;
79  // Rescue configuration.
80  const owner_rescue_config_t *config;
81  // Data buffer to hold xmodem upload data.
82  uint8_t data[2048];
84 
85 rom_error_t rescue_protocol(boot_data_t *bootdata,
86  const owner_rescue_config_t *rescue);
87 
88 #endif // OPENTITAN_SW_DEVICE_SILICON_CREATOR_ROM_EXT_RESCUE_H_