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_UART_AUTH_H 20 #define BOOT_UART_AUTH_H 21 22 #include <stdint.h> 23 #include "boot_serial.h" 24 25 #define UART_FIRST_CHAR_TIMEOUT 1000 26 #define UART_PACKET_START_FLAG 0xDEADBEEF 27 #define UART_PACKET_PAYLOAD_MAX 1024 28 29 extern uart_param_stru g_uart_param; 30 31 enum { 32 UART_TYPE_ROMBOOT_HANDSHAKE = 0xF0, 33 UART_TYPE_ACK = 0xE1, 34 UART_TYPE_FILE_START = 0xD2, 35 UART_TYPE_FILE_END = 0xC3, 36 UART_TYPE_CMD = 0xB4, 37 UART_TYPE_DATA = 0xA5, 38 UART_TYPE_FLASHBOOT_HANDSHAKE = 0x0F, 39 }; 40 41 typedef struct { 42 uint32_t start_flag; /* 起始标识: 0xDEADBEEF */ 43 uint16_t packet_size; /* 报文长度:真实传输数据长度,要求不超过1024 */ 44 uint8_t type; /* 报文类型 */ 45 uint8_t pad; 46 } packet_data_head; 47 48 typedef struct { 49 packet_data_head head; 50 uint8_t payload[UART_PACKET_PAYLOAD_MAX]; /**< 报文数据 */ 51 uint16_t check_sum; /* 校验和 */ 52 uint8_t rev[2]; /* 2: rev */ 53 } packet_data_info; 54 55 /* UART AUTH context */ 56 typedef struct { 57 uint8_t status; 58 uint8_t pad; 59 uint16_t received; 60 packet_data_info packet; 61 } uart_ctx; 62 63 uint32_t uart_process(uint32_t interrupt_timeout_ms); 64 65 #ifdef CONFIG_LOADERBOOT_SUPPORT_SET_BUADRATE 66 uart_param_stru* uart_baudrate_rcv(const uart_ctx *ctx); 67 uint32_t serial_port_set_baudrate(uart_param_stru *uart); 68 #endif 69 70 #endif