• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
15 
16 #ifndef __UART_AUTH_H__
17 #define __UART_AUTH_H__
18 
19 #include <secure.h>
20 #include "hi_boot_rom.h"
21 #include <hi_types.h>
22 
23 #define UART_PACKET_START_FLAG 0xDEADBEEF
24 
25 #define UART_PACKET_PAYLOAD_MAX 1024
26 
27 HI_EXTERN uart_param_stru g_uart_param;
28 HI_EXTERN hi_u32 g_uart_int_type;
29 
30 enum {
31     UART_TYPE_ROMBOOT_HANDSHAKE = 0xF0,
32     UART_TYPE_ACK = 0xE1,
33     UART_TYPE_FILE_START = 0xD2,
34     UART_TYPE_FILE_END = 0xC3,
35     UART_TYPE_CMD = 0xB4,
36     UART_TYPE_DATA = 0xA5,
37     UART_TYPE_FLASHBOOT_HANDSHAKE = 0x0F,
38 };
39 
40 typedef struct {
41     hi_u32 start_flag;  /* start flag: 0xDEADBEEF */
42     hi_u16 packet_size; /* Packet length: actual length of data to be transmitted.
43                            The length cannot exceed 1024 bytes.
44                            CNcomment:报文长度:真实传输数据长度,要求不超过1024 */
45     hi_u8 type;         /* Packet Type。CNcomment:报文类型 */
46     hi_u8 pad;
47 } packet_data_head;
48 
49 typedef struct {
50     packet_data_head head;
51     hi_u8 payload[UART_PACKET_PAYLOAD_MAX]; /**< Packet data */
52     hi_u16 check_sum;   /* Checksum */
53     hi_u8 rev[2];       /* 2: rev */
54 } packet_data_info;
55 
56 /* UART AUTH context */
57 typedef struct {
58     hi_u8 status;
59     hi_u8 pad;
60     hi_u16 received;
61     packet_data_info packet;
62 } uart_ctx;
63 
64 hi_u32 uart_process(hi_uart uart, hi_u32 interrupt_timeout_ms);
65 
66 #endif /* __UART_AUTH_H__ */
67