1 /*
2 * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
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 #include "duet_cm4.h"
17 #include "duet_flash.h"
18 #include "duet_flash_alg.h"
19
20 /* Logic partition on flash devices */
21 const duet_logic_partition_t duet_partitions[] = {
22 [PARTITION_BOOTLOADER] =
23 {
24 .partition_owner = FLASH_EMBEDDED,
25 .partition_description = "Bootloader",
26 .partition_start_addr = BOOTLOADER_FLASH_START_ADDR,
27 .partition_length = BOOTLOADER_MAX_SIZE, // 64k bytes
28 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_DIS,
29 },
30 [PARTITION_PARAMETER_1] =
31 {
32 .partition_owner = FLASH_EMBEDDED,
33 .partition_description = "Info",
34 .partition_start_addr = INFO_FLASH_START_ADDR,
35 .partition_length = INFO_MAX_SIZE, // 4k bytes
36 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
37 },
38 [PARTITION_PARAMETER_2] =
39 {
40 .partition_owner = FLASH_EMBEDDED,
41 .partition_description = "KV",
42 .partition_start_addr = KV_FLASH_START_ADDR,
43 .partition_length = KV_MAX_SIZE, // 12k bytes
44 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
45 },
46 [PARTITION_PARAMETER_3] =
47 {
48 .partition_owner = FLASH_EMBEDDED,
49 .partition_description = "MIDEA_INFO",
50 .partition_start_addr = MIDEA_INFO_START_ADDR,
51 .partition_length = MIDEA_INFO_MAX_SIZE, // 4k bytes
52 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
53 },
54 [PARTITION_PARAMETER_4] =
55 {
56 .partition_owner = FLASH_EMBEDDED,
57 .partition_description = "MIDEA_INFO_BKUP",
58 .partition_start_addr = MIDEA_INFO_BKUP_START_ADDR,
59 .partition_length = MIDEA_INFO_BKUP_MAX_SIZE, // 4k bytes
60 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
61 },
62 [PARTITION_APPLICATION] =
63 {
64 .partition_owner = FLASH_EMBEDDED,
65 .partition_description = "Application",
66 .partition_start_addr = APP_FLASH_START_ADDR,
67 .partition_length = APP_MAX_SIZE, // 768k bytes
68 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
69 },
70 [PARTITION_OTA_TEMP] =
71 {
72 .partition_owner = FLASH_EMBEDDED,
73 .partition_description = "OTA Storage",
74 .partition_start_addr = OTA_FLASH_START_ADDR,
75 .partition_length = OTA_MAX_SIZE, // 768k bytes
76 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
77 },
78 [PARTITION_CUSTOM_1] =
79 {
80 .partition_owner = FLASH_EMBEDDED,
81 .partition_description = "FLASH Customer1",
82 .partition_start_addr = CUST1_FLASH_START_ADDR,
83 .partition_length = CUST1_MAX_SIZE, // 12k bytes
84 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
85 },
86 #ifdef MS_CONFIG_OTA_SUPPORT
87 [PARTITION_OTA_MCU] =
88 {
89 .partition_owner = FLASH_EMBEDDED,
90 .partition_description = "OTA MCU",
91 .partition_start_addr = OTA_MCU_FLASH_START_ADDR,
92 .partition_length = OTA_MCU_MAX_SIZE, // 192k bytes
93 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
94 },
95 [PARTITION_OTA_PARA] =
96 {
97 .partition_owner = FLASH_EMBEDDED,
98 .partition_description = "OTA PARA",
99 .partition_start_addr = OTA_PARA_START_ADDR,
100 .partition_length = OTA_PARA_MAX_SIZE, // 4k bytes
101 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
102 },
103 [PARTITION_OTA_HEAD_PARA] =
104 {
105 .partition_owner = FLASH_EMBEDDED,
106 .partition_description = "OTA HEAD PARA",
107 .partition_start_addr = OTA_HEAD_PARA_START_ADDR,
108 .partition_length = OTA_HEAD_PARA_MAX_SIZE, // 4k bytes
109 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
110 },
111 #endif
112 [PARTITION_PARAMETER_5] =
113 {
114 .partition_owner = FLASH_EMBEDDED,
115 .partition_description = "NVDS", // offline log
116 .partition_start_addr = NVDS_FLASH_START_ADDR,
117 .partition_length = NVDS_MAX_SIZE, // 8k bytes
118 .partition_options = PAR_OPT_READ_EN | PAR_OPT_WRITE_EN,
119 },
120 };
121 #ifdef LOW_LEVEL_FLASH_RW_SUPPORT
duet_flash_get_wifi_mac(flash_mac_addr_t * addr)122 int32_t duet_flash_get_wifi_mac(flash_mac_addr_t *addr)
123 {
124 int32_t inBufLen = sizeof(flash_mac_addr_t);
125 duet_flash_kv_get(FLASH_MAC_ADDR_TOKEN_NAME, addr, &inBufLen);
126 // printf("%s:%d addr=%02x %02x %02x %02x %02x %02x token=0x%x\n",__FUNCTION__,__LINE__,addr->mac[0],addr->mac[1],addr->mac[2],addr->mac[3],addr->mac[4],addr->mac[5],addr->token);
127 return 0;
128 }
duet_flash_set_wifi_mac(flash_mac_addr_t * addr)129 int32_t duet_flash_set_wifi_mac(flash_mac_addr_t *addr)
130 {
131 // printf("%s:%d addr=%02x %02x %02x %02x %02x %02x token=0x%x\n",__FUNCTION__,__LINE__,addr->mac[0],addr->mac[1],addr->mac[2],addr->mac[3],addr->mac[4],addr->mac[5],addr->mac,addr->token);
132 return duet_flash_kv_set(FLASH_MAC_ADDR_TOKEN_NAME, addr, sizeof(flash_mac_addr_t), 0);
133 }
134 #endif