1 /* 2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 * Description: Common Boot for Standard Application Core 15 * 16 * Create: 2023-01-09 17 */ 18 19 #ifndef BOOT_SERIAL_H 20 #define BOOT_SERIAL_H 21 22 #include "boot_init.h" 23 #include "uart.h" 24 25 extern uart_bus_t g_hiburn_uart; 26 27 /** 28 * @ingroup hct_boot_api 29 * 串口参数结构体 30 */ 31 typedef struct { 32 uint32_t baudrate; /* 波特率,比如:115200 */ 33 uint8_t databit; /* 5; 6; 7; 8 */ 34 uint8_t stopbit; /* 1:stop_bit 1; 2: stop_bit 2. */ 35 uint8_t parity; /* 0: None; 1:Odd; 2:Even */ 36 uint8_t flow_ctrl; /* 0: None; 1:rts&&cts. 2:only rts; 3:only cts */ 37 uint8_t fifoline_tx_int; /* 0:tx FIFO≤1/8full; 1:tx FIFO≤1/4full; 2:tx FIFO≤1/2full; 38 3:tx FIFO≤3/4full; 4:tx FIFO≤7/8full */ 39 uint8_t fifoline_rx_int; /* 0:rx FIFO≥1/8full; 1:rx FIFO≥1/4full; 2:rx FIFO≥1/2full; 40 3:rx FIFO≥3/4full; 4:rx FIFO≥7/8full */ 41 uint8_t fifoline_rts; /* 0:rx FIFO≥1/8full; 1:rx FIFO≥1/4full; 2:rx FIFO≥1/2full; 42 3:rx FIFO≥3/4full; 4:rx FIFO≥7/8full */ 43 uint8_t pad; 44 } uart_param_stru; 45 46 #define DEFAULT_FIFOLINE_TX_INT 3 47 #define DEFAULT_FIFOLINE_RX_INT 1 48 #define DEFAULT_FIFOLINE_RTS 4 49 50 /** 51 * @ingroup boot_error_status 52 * 打印错误码类型 53 */ 54 typedef enum { 55 ERRCODE_UART_INIT = 0x3600, /* UART认证初始化失败 */ 56 ERRCODE_LOADER_ERR = 0x3601, /* 加载loaderboot失败 */ 57 ERRCODE_BOOT_DECRYPT_ERR = 0x3602, /* boot解密失败 */ 58 ERRCODE_BOOT_LEN_ERR = 0x3603, /* boot长度检验失败 */ 59 ERRCODE_BOOT_HEAD_ERR = 0x3604, /* boot头校验失败 */ 60 ERRCODE_BOOT_SECURE_BOOT_ERR = 0x3605, /* SECURE BOOT读取失败 */ 61 ERRCODE_BOOT_ROOT_KEY_LEN_ERR = 0x3606, /* rootkye长度不正确 */ 62 ERRCODE_BOOT_ROOT_KEY_ERR = 0x3607, /* rootkey证失败 */ 63 ERRCODE_BOOT_READ_ENCPT_ERR = 0x3608, /* SECURE FLAG读取失败 */ 64 ERRCODE_BOOT_SUB_KEY_LEN_ERR = 0x3609, /* subkey长度不正确 */ 65 ERRCODE_BOOT_SUB_KEY_CAT_ERR = 0x360A, /* subkey Category不正确 */ 66 ERRCODE_BOOT_SUB_KEY_RSIM_ERR = 0x360B, /* subkey RSIM校验失败 */ 67 ERRCODE_BOOT_SUB_KEY_ERR = 0x360C, /* subkey认证失败 */ 68 ERRCODE_BOOT_CODE_VERIFY_ERR = 0x360D, /* code校验失败 */ 69 ERRCODE_BOOT_DIE_ID_ERR = 0x360E, /* DIE ID校验失败 */ 70 ERRCODE_BOOT_VER_ERR = 0x360F, /* flashboot版本号校验失败 */ 71 ERRCODE_BOOT_GET_TAIL_ERR = 0x3610, /* 获取flash尾地址失败 */ 72 ERRCODE_BOOT_BACKUP_TAIL_ERR = 0x3611, /* 备份flashboot魔术字和长度校验失败 */ 73 ERRCODE_BOOT_MAIN_CHECK_ERR = 0x3612, /* 非安全启动主flashboot完整性校验失败 */ 74 ERRCODE_BOOT_BACKUP_CHECK_ERR = 0x3613, /* 非安全启动备份flashboot完整性校验失败 */ 75 ERRCODE_MALLOC_EXAUST_ERR = 0x3614, /* 堆内存不足 */ 76 ERRCODE_MALLOC_STRUCT_ERR = 0x3615, /* 堆内存管理结构体被破坏 */ 77 ERRCODE_NO_ENCPT_CNT_LEFT_ERR = 0x3616, /* flash加密烧写次数已用完 */ 78 ERRCODE_CRYPTO_PREPARE_ERR = 0x3617, /* flash加解密准备失败 */ 79 ERRCODE_CRYPTO_KEY_EMPTY_ERR = 0x3618, /* flash加解密工作密钥为空 */ 80 ERRCODE_CRYPTO_KEY_INVALID_ERR = 0x3619, /* flash加解密工作密钥无效 */ 81 ERRCODE_CRYPTO_KEY_SAVE_ERR = 0x361A, /* flash加解密工作密钥保存失败 */ 82 ERRCODE_CRYPTO_KEY_DECRYPT_ERR = 0x361B, /* flash加解密工作密钥解密失败 */ 83 ERRCODE_CRYPTO_FW_DECRYPT_ERR = 0x361C, /* flash加解密固件加密失败 */ 84 ERRCODE_CRYPTO_FW_ENCRYPT_ERR = 0x361D, /* flash加解密固件解密失败 */ 85 ERRCODE_CRYPTO_NV_ENCRYPT_ERR = 0x361E, /* flash加解密NV区加密失败 */ 86 ERRCODE_BOOT_MAIN_HASH_ERR = 0x361F, /* 非安全启动主flashboot hash校验失败 */ 87 ERRCODE_BOOT_BACKUP_HASH_ERR = 0x3620, /* 非安全启动备份flashboot hash校验失败 */ 88 ERRCODE_BOOT_LOAD_HASH_ERR = 0x3621, /* 非安全启动loaderboot hash校验失败 */ 89 ERRCODE_BOOT_FLASH_ERASE_ERR = 0x3622, /* flash 擦除失败 */ 90 ERRCODE_BOOT_FLASH_RESUME_ERR = 0x3623, /* flash 备份恢复 */ 91 ERRCODE_IDX_MAX, /* 错误码类型最大值 */ 92 } hi_print_errno; 93 94 void hiburn_uart_init(uart_param_stru uart_param, uart_bus_t uart_bus); 95 void hiburn_uart_deinit(void); 96 #ifndef ATE_CLOSE_DEBUG 97 void boot_put_errno(uint32_t print_errno); 98 void boot_puthex(uint32_t h, bool print0); 99 void boot_msg0(const char *s); 100 void boot_msg1(const char *s, uint32_t h); 101 void boot_msg2(const char *s, uint32_t h1, uint32_t h2); 102 void boot_msg4(const char *s, uint32_t h1, uint32_t h2, uint32_t h3, uint32_t h4); 103 #else 104 #define boot_put_errno(print_errno) 105 #define boot_puthex(h, rint0) 106 #define boot_msg0(s) 107 #define boot_msg1(s, h) 108 #define boot_msg2(s, h1, h2) 109 #define boot_msg4(s, h1, h2, h3, h4) 110 #endif 111 void serial_set_mute(void); 112 void serial_cancel_mute(void); 113 void serial_putc(const char c); 114 void serial_puts(const char *s); 115 void serial_put_buf(const char *buffer, int32_t length); 116 uint8_t serial_getc(void); 117 int32_t serial_tstc(void); 118 void serial_puthex(uint32_t h, bool print_all); 119 uint32_t serial_getc_timeout(uint32_t timeout_us, uint8_t *ch); 120 121 #endif 122