• 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 __TRANSFER_H__
17 #define __TRANSFER_H__
18 
19 #include <ymodem.h>
20 #include <hi_boot_rom.h>
21 #include <efuse_opt.h>
22 #include <load.h>
23 
24 #define MODEM_SOH                   0x01 /* Start character of data block */
25 #define MODEM_STX                   0x02 /* The start byte of 1024 bytes */
26 #define MODEM_EOT                   0x04 /* File transfer finish */
27 #define MODEM_ACK                   0x06 /* ACK message */
28 #define MODEM_NAK                   0x15 /* Error occurred */
29 #define MODEM_CAN                   0x18 /* Cancel transmission */
30 #define MODEM_EOF                   0x1A /* Data blank filler */
31 #define MODEM_C                     0x43 /* Capital letter C */
32 
33 #define FLASH_ADDR_OFFSET           0x400000
34 
35 #define UPLOAD_WAIT_START_C_TIME    10000000 /* 10s */
36 #define UPLOAD_WAIT_DEFAULT_TIME    2000000  /* 2s */
37 
38 #define UPLOAD_DATA_SIZE            1024
39 #define UPLOAD_BUFF_LEN             1029
40 
41 #define RETRY_COUNT                 0
42 #define CAN_COUNT                   3
43 #define MSG_START_LEN               3
44 #define SOH_MSG_LEN                 128
45 #define SOH_MSG_TOTAL_LEN           133
46 #define WAIT_ZERO_ACK_DELAY         100
47 #define UPLOAD_FILE_NAME            "upload.bin"
48 #define UPLOAD_FILE_NAME_LEN        11
49 
50 enum {
51     UPLOAD_NONE,
52     UPLOAD_WAIT_START_C,
53     UPLOAD_WAIT_INIT_ACK,
54     UPLOAD_WAIT_TRANS_C,
55     UPLOAD_WAIT_INTER_ACK,
56     UPLOAD_WAIT_FINAL_ACK,
57     UPLOAD_WAIT_EOT_C,
58     UPLOAD_WAIT_ZERO_ACK,
59 };
60 
61 typedef struct {
62     uintptr_t file_addr;
63     hi_u32 file_length;
64     hi_char *file_name;
65     hi_u32 offset;
66     hi_u8 status;
67     hi_u8 seq;
68     hi_u8 retry : 4;
69     hi_u8 can_cnt : 4;
70     hi_u8 buffer[UPLOAD_BUFF_LEN];
71 } upload_context;
72 
73 hi_u32 download_image(hi_u32 addr, hi_u32 erase_size, hi_u32 flash_size, hi_u8 burn_efuse);
74 hi_u32 download_factory_image(hi_u32 addr, hi_u32 erase_size, hi_u32 flash_size, hi_u8 burn_efuse);
75 hi_u32 loady_file(uintptr_t ram_addr);
76 hi_u32 loady_version_file(uintptr_t ram_addr);
77 hi_u32 upload_data(hi_u32 addr, hi_u32 length);
78 
79 #endif
80