• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file hi_nvm.h
3  *
4  * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __HI_NVM_H__
19 #define __HI_NVM_H__
20 
21 #include <hi_types.h>
22 
23 #define hi_make_identifier(a, b, c, d)      hi_makeu32(hi_makeu16(a, b), hi_makeu16(c, d))
24 #define HNV_FILE_SIGNATURE               hi_make_identifier('H', 'N', 'V', '$')
25 #define FNV_FILE_SIGNATURE               hi_make_identifier('F', 'N', 'V', '#')
26 
27 #define FACTORY_NV_SIZE   0x2000
28 #define FLASH_BLOCK_SIZE  0x1000
29 #define HNV_NCRC_SIZE  8                      /* no crc length */
30 #define NV_TOTAL_MAX_NUM  255                 /* Maximum number of NVs that can be set */
31 #define HNV_FAULT_TOLERANT_TIMES  3           /* Error tolerance times */
32 
33 #define HNV_MANAGE_FIXED_LEN  24
34 
35 /*
36  * The NV structure in the factory area must be the same as that in the kernel and
37  * cannot be modified after being fixed.
38  */
39 typedef struct _hi_nvm_manage_s_ {
40     hi_u32  magic;
41     hi_u32  crc;
42     hi_u8   ver;
43     hi_u8   head_len;
44     hi_u16  total_num;
45     hi_u32  seq;
46     hi_u32  ver_magic;
47     hi_u32  flash_size;
48     hi_u8   keep_id_range[2]; /* Reserved upg id, size:2 bytes, byte0:upper boundary, byte1:lower boundary */
49     hi_u8   reserve[2];       /* Reserved 2 bytes */
50     hi_u8   nv_item_data[0];
51 } hi_nv_manage;
52 
53 typedef struct hi_nv_item_index_s_ {
54     hi_u8 nv_id;
55     hi_u8 nv_len;
56     hi_u16 nv_offset;
57 } hi_nv_item_index;
58 
59 typedef struct _hi_nv_ctrl_s_ {
60     hi_u32 base_addr;
61     hi_u32 block_size;
62     hi_u32 total_block_size;
63     hi_u32 current_addr;
64     hi_u32 seq;
65     hi_u32 sem_handle;
66 
67     hi_u8 init_flag;
68     hi_u8 reserve;
69     hi_u16 total_num;
70     hi_u32 ver_magic;
71     hi_nv_item_index* index;
72 } hi_nv_ctrl;
73 
74 typedef enum _hi_nv_type_e_ {
75     HI_TYPE_NV = 0,
76     HI_TYPE_FACTORY_NV,
77     HI_TYPE_TEMP,
78     HI_TYPE_NV_MAX,
79 } hi_nv_type;
80 
81 hi_u32 hi_nv_flush_keep_ids(hi_u8* addr, hi_u32 len);
82 hi_u32 hi_nv_block_write(hi_u8* nv_file, hi_u32 len, hi_u32 flag);
83 
84 #endif   /* __HI_NVM_H__ */
85 
86