• 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  * Description: UPG ab mode config file for product.
15  */
16 #ifndef FACTORY_H
17 #define FACTORY_H
18 
19 #include <stdbool.h>
20 #include "partition.h"
21 #include "errcode.h"
22 
23 #ifdef __cplusplus
24 #if __cplusplus
25 extern "C" {
26 #endif
27 #endif
28 
29 #define FLASH_PAGE_SIZE_BIT_LENGTH 12
30 #define MFG_FACTORY_DEFAULT_MODE 1
31 #define MFG_DEFAULT_REGION 0
32 #define FACTORY_INFO_OFFSET 2
33 #define BYTE_4K 0x1000
34 #define BYTE_4K_MASK 0xFFF
35 #define MFG_FACTORY_REGION_CONFIG_SIZE 0x1000
36 #define MFG_FACTORY_CONFIG_CHECK 0x8F45BA2F
37 #define FLASH_MAPPED_END 0x400000
38 #define FACTORYBOOT_KEY_AREA_IMAGE_ID 0x4B7CF333
39 #define MFG_FACTORY_VALID 0x0
40 #define MFG_FACTORY_INVALID 0x1
41 #define FLASH_PRIVATE_CUSTOM_CONFIG_TIMES 4
42 #define FLASH_PRIVATE_CUSTOM_CONFIG_OFFSET 0x200
43 #define IMAGE_HEADER_LEN ((KEY_AREA_STRUCTURE_LENGTH) + (CODE_INFO_STRUCTURE_LENGTH))
44 
45 typedef enum  {
46     FTM_REGION_SERVICE,
47     FTM_REGION_FACTORY,
48     FTM_REGION_COUNT
49 } mfg_region_index;
50 
51 typedef struct {
52     uint32_t factory_mode;          /* 0:normal_mode;1:factory_mode */
53     uint32_t factory_addr_start;    /* factory bin start address */
54     uint32_t factory_addr_switch;   /* factory bin switch address */
55     uint32_t factory_size;          /* factory bin size */
56     uint32_t factory_switch_size;   /* factory bin size */
57     uint32_t factory_valid;         /* 0:erase 1:invalid;2:valid */
58     uint32_t check_num;             /* check number */
59 } mfg_factory_config_t;
60 
61 typedef struct {
62     partition_information_t  app_info;
63     partition_information_t  mfg_info;
64 } mfg_region_config_t;
65 
66 uint32_t global_interrupt_lock(void);
67 void global_interrupt_restore(uint32_t);
68 #ifdef WS63_PRODUCT_NONE
69 uint32_t mfg_get_ftm_run_region(mfg_factory_config_t *mfg_factory_cfg);
70 #endif
71 uint32_t mfg_get_region_config(mfg_region_config_t *region_cfg);
72 errcode_t mfg_flash_erase(void);
73 errcode_t mfg_flash_read(uint8_t *ram_data, const uint32_t size);
74 errcode_t mfg_flash_write(const uint8_t *ram_data, uint32_t size);
75 errcode_t mfg_factory_mode_switch(mfg_region_config_t img_info, uint32_t switch_mode, mfg_factory_config_t *config);
76 uint32_t mfg_set_factory_invalid(mfg_factory_config_t *config);
77 errcode_t mfg_flash_write_info(const uint8_t *ram_data, uint32_t flash_offset, uint32_t size, bool do_erase);
78 #ifdef _PRE_WLAN_FEATURE_MFG_TEST
79 errcode_t plt_flash_read_data(uint32_t addr, uint32_t size, uint8_t *data);
80 errcode_t plt_flash_write_data(uint32_t addr, uint32_t size, uint8_t *data, uint32_t *left);
81 #endif
82 #ifdef __cplusplus
83 #if __cplusplus
84 }
85 #endif
86 #endif
87 
88 #endif /* FACTORY_H */