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 __HI_NVM_H__ 17 #define __HI_NVM_H__ 18 19 #include <hi_types.h> 20 21 #define HNV_FILE_SIGNATURE hi_make_identifier('H', 'N', 'V', '$') 22 #define FNV_FILE_SIGNATURE hi_make_identifier('F', 'N', 'V', '#') 23 24 #define FLASH_BLOCK_SIZE 0x1000 25 #define HNV_NCRC_SIZE 8 26 #define NV_TOTAL_MAX_NUM 255 27 #define HNV_FAULT_TOLERANT_TIMES 3 28 29 #define HNV_MANAGE_FIXED_LEN 24 30 31 typedef struct _hi_nvm_manage_s_ { 32 hi_u32 magic; 33 hi_u32 crc; 34 hi_u8 ver; 35 hi_u8 head_len; 36 hi_u16 total_num; 37 hi_u32 seq; 38 hi_u32 ver_magic; 39 hi_u32 flash_size; 40 hi_u8 keep_id_range[2]; /* Reserved upg id, size:2 bytes, byte0:upper boundary, byte1:lower boundary */ 41 hi_u8 reserve[2]; /* Reserved 2 bytes */ 42 hi_u8 nv_item_data[0]; 43 } hi_nv_manage; 44 45 typedef struct hi_nv_item_index_s_ { 46 hi_u8 nv_id; 47 hi_u8 nv_len; 48 hi_u16 nv_offset; 49 } hi_nv_item_index; 50 51 typedef struct _hi_nv_ctrl_s_ { 52 hi_u32 base_addr; 53 hi_u32 block_size; 54 hi_u32 total_block_size; 55 hi_u32 current_addr; 56 hi_u32 seq; 57 hi_u32 sem_handle; 58 59 hi_u8 init_flag; 60 hi_u8 reserve; 61 hi_u16 total_num; 62 hi_u32 ver_magic; 63 hi_nv_item_index* index; 64 } hi_nv_ctrl; 65 66 typedef enum _hi_nv_type_e_ { 67 HI_TYPE_NV = 0, 68 HI_TYPE_FACTORY_NV, 69 HI_TYPE_TEMP, 70 HI_TYPE_NV_MAX, 71 } hi_nv_type; 72 73 hi_u32 hi_nv_flush_keep_ids(hi_u8* addr, hi_u32 len); 74 hi_u32 hi_nv_block_write(hi_u8* nv_file, hi_u32 len, hi_u32 flag); 75 76 #endif /* __HI_NVM_H__ */