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