25 #ifndef LIBSWITCHTEC_MFG_H
26 #define LIBSWITCHTEC_MFG_H
29 #define SPI_QUAD_MODE (0U)
30 #define INLINE_ECC_MODE (1U)
31 #define SPI_3B_4B_MODE (8U)
33 #define WATCHDOG_EN (10U)
34 #define TWI_RCVRY_ADDR0 (12U)
35 #define TWI_RCVRY_ADDR1 (13U)
36 #define SEC_BOOT_DRY_RUN (14U)
37 #define PE_MODE_EN (15U)
38 #define MEMBIST_EN (16U)
39 #define MEMBIST_CPU_RESET (17U)
41 #define PCI100X_STRAP_STAT(strap, bit) ((((strap >> bit) & 0x01) == 0x01) ? "Enabled" : "Disabled")
43 #define SWITCHTEC_MB_LOG_LEN 32
45 #define SWITCHTEC_PUB_KEY_LEN 512
46 #define SWITCHTEC_SIG_LEN 512
47 #define SWITCHTEC_KMSK_LEN 64
48 #define SWITCHTEC_KMSK_NUM 4
50 #define SWITCHTEC_SECURITY_SPI_RATE_MAX_NUM 16
52 #define OTP_SJTAG_UUID_LENGTH 10
53 #define OTP_SJTAG_KEY_LENGTH 16
54 #define OTP_SELF_TEST_POLICY_LENGTH 4
55 #define OTP_DIE_TRACE_LENGTH 16
56 #define OTP_CONFIG_DATA_MAX_LEN 1020
58 #define OTP_CONFIG_START 0x1800
59 #define OTP_MAX_SIZE 0x3FFF
61 #define SKU_NO_OF_BLOCKS 4
63 #define SJTAG_SERVER_IP "10.40.56.34"
64 #define SJTAG_SERVER_PORT (5001)
65 #define SJTAG_SERVER_HEADER_LEN (4)
66 #define SJTAG_IDCODE_LEN (4)
67 #define SJTAG_HR_LEN (32)
68 #define SJTAG_DEBUG_TOKEN_LEN (32)
69 #define SJTAG_HMAC_MSG_LEN (22)
70 #define SJTAG_UUID_LEN (10)
71 #define SJTAG_UNLOCK_STR_LEN (18)
73 #define SJTAG_NONCE_LEN (32)
74 #define SJTAG_SHA256_MSG_LEN (SJTAG_DEBUG_TOKEN_LEN + SJTAG_NONCE_LEN)
77 #define SJTAG_SERVER_CMD_INDEX (0)
78 #define SJTAG_SERVER_CMD_RESP_INDICATOR_INDEX (1)
79 #define SJTAG_SERVER_RESPONSE_STATUS_INDEX (2)
82 #define SJTAG_SERVER_CMD_MSK (0x00)
83 #define SJTAG_SERVER_RESP_MSK (0x40)
86 #define SJTAG_SERVER_CMD_CHAL_RESP (0x01)
89 #define SERVER_STATUS_SUCCESS (0x00)
90 #define SERVER_STATUS_INVALID_SJTAGID (0x02)
91 #define SERVER_STATUS_INVALID_HEADER (0x01)
92 #define SERVER_STATUS_DIGEST_COMPUTE_FAIL (0x03)
94 #define MAX_LENGTH 256
96 #define KEY_BUF_SIZE (16*1024)
97 #define CONFIG_SECTION_NAME "OTPGEN_CONFIG"
100 #define KEY_XDATA_WRITE "XWRE_"
101 #define KEY_XDATA_SET "XSET_"
102 #define KEY_XDATA_CLEAR "XCLR_"
103 #define KEY_PATCH_CODE "CODE_"
105 #define KEY_ID_SIZE 5
106 #define SET_XDATA_ADDRESS 0x80
108 #define TV_TAG_SKIP_CMD_MASK 0x80
109 #define TV_TAG_SKIP_LEN_MASK_ 0x7F
110 #define TV_TAG_DATA_LEN_MASK_ 0x7F
112 #define CUSTOM_COMMAND 0xFE
114 #define SET_XMODE_NONE 0x55
116 typedef unsigned long DWORD_PTR, *PDWORD_PTR;
118 #define LOBYTE(w) ((BYTE)(((DWORD_PTR)(w)) & 0xff))
119 #define HIBYTE(w) ((BYTE)((((DWORD_PTR)(w)) >> 8) & 0xff))
120 #define LOWORD(l) ((WORD)(((DWORD_PTR)(l)) & 0xffff))
121 #define HIWORD(l) ((WORD)((((DWORD_PTR)(l)) >> 16) & 0xffff))
124 typedef unsigned long DWORD;
126 typedef unsigned char BYTE;
127 typedef unsigned short WORD;
133 uint32_t chip_serial;
137 uint32_t ver_sec_unlock;
138 uint16_t customer_id;
140 enum switchtec_debug_mode {
141 SWITCHTEC_DEBUG_MODE_ENABLED,
142 SWITCHTEC_DEBUG_MODE_DISABLED_BUT_ENABLE_ALLOWED,
143 SWITCHTEC_DEBUG_MODE_DISABLED,
144 SWITCHTEC_DEBUG_MODE_DISABLED_EXT
147 enum switchtec_secure_state {
148 SWITCHTEC_UNINITIALIZED_UNSECURED,
149 SWITCHTEC_INITIALIZED_UNSECURED,
150 SWITCHTEC_INITIALIZED_SECURED,
151 SWITCHTEC_SECURE_STATE_UNKNOWN = 0xff,
157 enum switchtec_otp_program_status {
158 SWITCHTEC_OTP_PROGRAMMABLE = 0,
159 SWITCHTEC_OTP_UNPROGRAMMABLE = 1,
164 bool mixed_ver_valid;
165 bool main_fw_ver_valid;
166 bool sec_unlock_ver_valid;
168 enum switchtec_otp_program_status basic;
169 enum switchtec_otp_program_status mixed_ver;
170 enum switchtec_otp_program_status main_fw_ver;
171 enum switchtec_otp_program_status sec_unlock_ver;
172 enum switchtec_otp_program_status kmsk[4];
176 uint8_t basic_setting_valid;
177 uint8_t public_key_num_valid;
178 uint8_t public_key_ver_valid;
181 enum switchtec_secure_state secure_state;
184 uint32_t i2c_recovery_tmo;
187 uint32_t i2c_cmd_map;
188 uint32_t public_key_exponent;
189 uint32_t public_key_num;
190 uint32_t public_key_ver;
192 uint8_t public_key[SWITCHTEC_KMSK_NUM][SWITCHTEC_KMSK_LEN];
200 uint32_t i2c_recovery_tmo;
203 uint32_t i2c_cmd_map;
204 uint32_t public_key_exponent;
207 enum switchtec_active_index_id {
208 SWITCHTEC_ACTIVE_INDEX_0 = 0,
209 SWITCHTEC_ACTIVE_INDEX_1 = 1,
210 SWITCHTEC_ACTIVE_INDEX_NOT_SET = 0xfe
214 enum switchtec_active_index_id bl2;
215 enum switchtec_active_index_id firmware;
216 enum switchtec_active_index_id config;
217 enum switchtec_active_index_id keyman;
220 enum switchtec_bl2_recovery_mode {
221 SWITCHTEC_BL2_RECOVERY_I2C = 1,
222 SWITCHTEC_BL2_RECOVERY_XMODEM = 2,
223 SWITCHTEC_BL2_RECOVERY_I2C_AND_XMODEM = 3
227 uint8_t kmsk[SWITCHTEC_KMSK_LEN];
231 uint8_t pubkey[SWITCHTEC_PUB_KEY_LEN];
241 uint8_t sku_info[SKU_NO_OF_BLOCKS];
242 uint8_t write_protected:1;
243 uint8_t valid_flags:SKU_NO_OF_BLOCKS;
248 uint8_t idcode[SJTAG_IDCODE_LEN];
256 uint8_t uuid[SJTAG_UUID_LEN];
260 uint8_t nonce[SJTAG_NONCE_LEN];
264 uint8_t debug_token[SJTAG_DEBUG_TOKEN_LEN];
268 uint8_t uuid_data[OTP_SJTAG_UUID_LENGTH];
272 uint8_t sjtag_key[OTP_SJTAG_KEY_LENGTH];
276 uint8_t config_data[OTP_CONFIG_DATA_MAX_LEN];
284 uint8_t die_trace[OTP_DIE_TRACE_LENGTH];
290 uint32_t bit_byte_mode:1;
291 uint32_t smart_prog_mode:1;
298 uint8_t signature[SWITCHTEC_SIG_LEN];
303 float rates[SWITCHTEC_SECURITY_SPI_RATE_MAX_NUM];
319 enum switchtec_bl2_recovery_mode recovery_mode);
326 enum switchtec_secure_state state);
328 uint32_t ver_sec_unlock,
333 uint32_t ver_sec_unlock,
339 int switchtec_read_pubk_file(FILE *pubk_file,
struct switchtec_pubkey *pubk);
358 bool sku_info,
bool otp_config);
360 uint32_t chip_serial_num);
371 uint8_t *sjtag_key, uint8_t *is_verified);
381 uint8_t *config_data,
382 bool is_firmware_halt);
384 uint16_t config_start_address,
385 int32_t config_length,
389 unsigned short config_len);
394 uint8_t *sjtag_uuid_ptr,
395 uint8_t *sjtag_idcode);
406 void sjtag_hr_compute(uint8_t *
sjtag_uuid, uint8_t *sjtag_suv, uint8_t *
sjtag_nonce, uint8_t *sjtag_hr);
410 #endif // LIBSWITCHTEC_MFG_H
int switchtec_read_signature_file(FILE *sig_file, struct switchtec_signature *sigature)
Read signature data from signature file.
int switchtec_sjtag_get_nonce(struct switchtec_dev *dev, struct sjtag_nonce *sjtag_nonce_ptr)
Retrieve the SJTAG nonce from the device.
int switchtec_otp_config_read(struct switchtec_dev *dev, uint16_t config_start_address, int32_t config_length, int out_fd)
Reads OTP configuration data from the device.
int switchtec_read_sec_cfg_file(struct switchtec_dev *dev, FILE *setting_file, struct switchtec_security_cfg_set *set)
Read security settings from config file.
int switchtec_boot_resume(struct switchtec_dev *dev)
Resume device boot. Note that after calling this function, the current 'dev' pointer is no longer val...
int switchtec_otp_sjtag_key_verify(struct switchtec_dev *dev, uint8_t *sjtag_key, uint8_t *is_verified)
Verify the SJTAG key in the OTP memory.
int switchtec_otp_die_trace_prog(struct switchtec_dev *dev, uint8_t *die_trace)
Progrom Die Trace into OTP.
int switchtec_sjtag_status_get(struct switchtec_dev *dev, struct sjtag_status_get *sjtag_sts_get)
Get the SJTAG status from the switchtec device.
int switchtec_otp_sku_info_set(struct switchtec_dev *dev, struct otp_sku_info_set *sku_info_set_str)
Set the SKU information in the OTP memory of the Switchtec device.
int switchtec_secure_state_set(struct switchtec_dev *dev, enum switchtec_secure_state state)
Set device secure state.
int switchtec_custid_prog(struct switchtec_dev *dev, uint16_t cust_id)
Program given customer id into OTP.
int switchtec_sjtag_hr_send(struct switchtec_dev *dev, uint8_t *sjtag_hr)
Send SJTAG host response to the device.
int switchtec_otp_bit_byte_prog_mode_set(struct switchtec_dev *dev, bool bit_byte_mode)
Set Bit or Byte Mode for OTP.
int switchtec_security_state_has_kmsk(struct switchtec_security_cfg_state *state, struct switchtec_kmsk *kmsk)
Check if secure config already has a KMSK entry KMSK stands for Key Manifest Secure Key....
int switchtec_active_image_index_get(struct switchtec_dev *dev, struct switchtec_active_index *index)
Get active image index.
int switchtec_otp_smart_prog_mode_set(struct switchtec_dev *dev, bool smart_prog_mode)
Set Smart Programming mode for OTP.
int switchtec_otp_sjtag_uuid_set(struct switchtec_dev *dev, uint8_t *sjtag_uuid)
Set the SJTAG UUID for a Switchtec device.
int switchtec_mailbox_to_file(struct switchtec_dev *dev, int fd)
Retrieve mailbox entries.
int switchtec_sn_ver_get(struct switchtec_dev *dev, struct switchtec_sn_ver_info *info)
Get serial number and security version.
int switchtec_read_sjtag_debug_token_file(FILE *debug_token_file, struct sjtag_debug_token *debug_token)
This function fetches the Debug Token from a bin file.
int switchtec_dbg_unlock_version_update(struct switchtec_dev *dev, uint32_t serial, uint32_t ver_sec_unlock, struct switchtec_pubkey *public_key, struct switchtec_signature *signature)
Update firmware debug secure unlock version number.
int sjtag_debug_token_gen(uint8_t *idcode_ptr, uint8_t *uuid_ptr, uint8_t *suv_ptr, uint8_t *sjtag_debug_token, bool verbose)
This Generates the Debug Token.
int switchtec_read_sjtag_key_file(FILE *sjtag_file, struct otp_sjtag_key *sjtag_key)
Read SJTAG key data from SJTAG file.
int switchtec_otp_config_prog(struct switchtec_dev *dev, uint16_t config_len, uint8_t *config_data, bool is_firmware_halt)
Programs the OTP configuration on the Switchtec device.
int switchtec_otp_sjtag_key_lock(struct switchtec_dev *dev)
Locks the SJTAG key on the specified Switchtec device.
int switchtec_chip_serial_num_prog(struct switchtec_dev *dev, uint32_t chip_serial_num)
Program the chip serial number for a Switchtec device.
int switchtec_security_config_set(struct switchtec_dev *dev, struct switchtec_security_cfg_set *setting)
Set secure settings.
int switchtec_otp_self_test_policy_set(struct switchtec_dev *dev, uint8_t *self_test_policy)
Program Self Test Policy into OTP.
int switchtec_security_spi_avail_rate_get(struct switchtec_dev *dev, struct switchtec_security_spi_avail_rate *rates)
Get the available SPI rates for the Switchtec device.
int switchtec_dbg_unlock(struct switchtec_dev *dev, uint32_t serial, uint32_t ver_sec_unlock, struct switchtec_pubkey *public_key, struct switchtec_signature *signature)
Unlock firmware debug features.
int switchtec_otp_sjtag_mode_set(struct switchtec_dev *dev, uint8_t sjtag_mode)
Set the SJTAG mode for the Switchtec device.
int switchtec_otp_sku_info_get(struct switchtec_dev *dev, struct otp_sku_info_get *sku_info_get_str)
Get SKU Information and Write Protected Status.
int switchtec_read_kmsk_file(FILE *kmsk_file, struct switchtec_kmsk *kmsk)
Read KMSK data from KMSK file.
int switchtec_otp_sjtag_key_set(struct switchtec_dev *dev, uint8_t *sjtag_key)
Set the SJTAG key in the OTP memory of the Switchtec device.
int switchtec_sjtag_get_uuid_idcode(struct switchtec_dev *dev, uint8_t *sjtag_uuid_ptr, uint8_t *sjtag_idcode)
Retrieve the UUID and ID code from the switchtec device.
int switchtec_otp_regs_write_protect(struct switchtec_dev *dev, bool sku_info, bool otp_config)
Write Protect given choice of OTP Regions.
int switchtec_read_otp_config_data_file(FILE *config_file, struct otp_config_data *config_data, unsigned short config_len)
Read OTP Config data from bin file.
int switchtec_read_uuid_file(FILE *uuid_file, struct switchtec_uuid *uuid_data)
Read UUID data from UUID file.
int switchtec_active_image_index_set(struct switchtec_dev *dev, struct switchtec_active_index *index)
Set active image index.
int switchtec_security_config_get(struct switchtec_dev *dev, struct switchtec_security_cfg_state *state)
Get secure boot configurations.
int switchtec_fw_exec(struct switchtec_dev *dev, enum switchtec_bl2_recovery_mode recovery_mode)
Execute the transferred firmware.
int switchtec_read_self_test_policy_file(FILE *self_test_file, struct otp_self_test_policy *otp_self_test_policy)
Read Self Test Policy from bin file.
int switchtec_kmsk_set(struct switchtec_dev *dev, struct switchtec_pubkey *public_key, struct switchtec_signature *signature, struct switchtec_kmsk *kmsk)
Set KMSK entry KMSK stands for Key Manifest Secure Key. It is a key used to verify Key Manifest parti...
int switchtec_read_die_trace_file(FILE *die_trace_file, struct otp_die_trace *otp_die_trace_ptr)
Read Die Trace from die trace bin file.
int switchtec_otp_mode_status_get(struct switchtec_dev *dev, struct otp_mode_status *otp_mode_status_str)
Get Status of Programming Modes in OTP.