b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <unistd.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <errno.h> |
| 5 | #include <string.h> |
| 6 | #include <sys/types.h> |
| 7 | #include <sys/stat.h> |
| 8 | #include <fcntl.h> |
| 9 | |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame] | 10 | #include "mbtk_type.h" |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 11 | |
| 12 | #ifdef MBTK_DEV_INFO_VERSION_2 |
| 13 | #include "mbtk_device_v2.h" |
| 14 | #else |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 15 | #include "mbtk_device.h" |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 16 | #endif |
| 17 | |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 18 | |
| 19 | static mbtk_device_info_header_t info_header = { |
| 20 | .tag = MBTK_DEVICE_INFO_PARTITION_TAG, |
| 21 | .version = MBTK_DEVICE_INFO_CURR_VERSION, |
| 22 | .item_count = MBTK_DEVICE_INFO_ITEM_NUM, |
| 23 | .item_header = { |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 24 | #ifdef MBTK_DEV_INFO_VERSION_2 |
| 25 | {MBTK_DEVICE_INFO_ITEM_BASIC, MBTK_DEVICE_INFO_ITEM_ADDR_BASIC}, |
| 26 | {MBTK_DEVICE_INFO_ITEM_FOTA, MBTK_DEVICE_INFO_ITEM_ADDR_FOTA}, |
| 27 | {MBTK_DEVICE_INFO_ITEM_MODEM, MBTK_DEVICE_INFO_ITEM_ADDR_MODEM}, |
| 28 | {MBTK_DEVICE_INFO_ITEM_LOG, MBTK_DEVICE_INFO_ITEM_ADDR_LOG}, |
| 29 | #else |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 30 | {MBTK_DEVICE_INFO_ITEM_BASIC, 0}, |
| 31 | {MBTK_DEVICE_INFO_ITEM_FOTA, 0}, |
| 32 | {MBTK_DEVICE_INFO_ITEM_MODEM, 0}, |
| 33 | {MBTK_DEVICE_INFO_ITEM_LOG, 0}, |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 34 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 35 | } |
| 36 | }; |
| 37 | |
| 38 | static mbtk_device_info_basic_t item_basic = { |
| 39 | .name = MBTK_DEVICE_INFO_ITEM_STR_BASIC, |
| 40 | .version = MBTK_DEVICE_INFO_CURR_VERSION, |
| 41 | .project = {0}, |
| 42 | .project_cust = {0}, |
| 43 | .ab_support = 1, // Default for ab system. |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame] | 44 | .reboot_flag = MBTK_REBOOT_FLAG_NORMAL, |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 45 | .revision_out = {0}, |
b.liu | 8e0743a | 2024-08-29 16:53:16 +0800 | [diff] [blame] | 46 | .revision_in = {0}, |
| 47 | .build_time = {0} |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | static mbtk_device_info_fota_t item_fota = { |
| 51 | .name = MBTK_DEVICE_INFO_ITEM_STR_FOTA, |
| 52 | .version = MBTK_DEVICE_INFO_CURR_VERSION, |
| 53 | .state = 0 |
| 54 | }; |
| 55 | |
| 56 | static mbtk_device_info_modem_t item_modem = { |
| 57 | .name = MBTK_DEVICE_INFO_ITEM_STR_MODEM, |
| 58 | .version = MBTK_DEVICE_INFO_CURR_VERSION, |
| 59 | .band_area = MBTK_MODEM_BAND_AREA_ALL, // Default for all bands. |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 60 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 61 | .net_pref = 15, // Default *band is 15 |
| 62 | .net_support = MBTK_NET_SUPPORT_2G | MBTK_NET_SUPPORT_3G | MBTK_NET_SUPPORT_4G, // Default support 2G/3G/4G |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 63 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 64 | .band_gsm = MBTK_BAND_ALL_GSM_DEFAULT, |
| 65 | .band_wcdma = MBTK_BAND_ALL_WCDMA_DEFAULT, |
| 66 | .band_tdlte = MBTK_BAND_ALL_TDLTE_DEFAULT, |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame] | 67 | .band_fddlte = MBTK_BAND_ALL_FDDLTE_DEFAULT, |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 68 | .band_lte_ext = MBTK_BAND_ALL_EXT_LTE_DEFAULT, |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 69 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 70 | .band_nr_3 = MBTK_BAND_ALL_NR_3_DEFAULT, |
| 71 | .band_nr_2 = MBTK_BAND_ALL_NR_2_DEFAULT, |
| 72 | .band_nr_1 = MBTK_BAND_ALL_NR_1_DEFAULT, |
| 73 | .band_nr_0 = MBTK_BAND_ALL_NR_0_DEFAULT |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 74 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | static mbtk_device_info_log_t item_log = { |
| 78 | .name = MBTK_DEVICE_INFO_ITEM_STR_LOG, |
| 79 | .version = MBTK_DEVICE_INFO_CURR_VERSION, |
| 80 | .state = 0 |
| 81 | }; |
| 82 | |
| 83 | static void help() |
| 84 | { |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 85 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 86 | printf("device_info_generate -a [a/ab] -b [revision_out] -c [revision_in] -d [project] -e [project_cust] -f [cn/eu/all] -g [build_time] -h [net_pref] -i [net_support] -o [out_bin]\n"); |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 87 | #else |
b.liu | 8e0743a | 2024-08-29 16:53:16 +0800 | [diff] [blame] | 88 | printf("device_info_generate -a [a/ab] -b [revision_out] -c [revision_in] -d [project] -e [project_cust] -f [cn/eu/all] -g [build_time] -o [out_bin]\n"); |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 89 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static int update_and_write_header(int fd, mbtk_device_info_header_t *header) |
| 93 | { |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 94 | #ifdef MBTK_DEV_INFO_VERSION_2 |
| 95 | |
| 96 | #else |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 97 | header->item_header[MBTK_DEVICE_INFO_ITEM_BASIC].addr = sizeof(mbtk_device_info_header_t); |
| 98 | header->item_header[MBTK_DEVICE_INFO_ITEM_FOTA].addr = header->item_header[MBTK_DEVICE_INFO_ITEM_BASIC].addr + sizeof(mbtk_device_info_basic_t); |
| 99 | header->item_header[MBTK_DEVICE_INFO_ITEM_MODEM].addr = header->item_header[MBTK_DEVICE_INFO_ITEM_FOTA].addr + sizeof(mbtk_device_info_fota_t); |
| 100 | header->item_header[MBTK_DEVICE_INFO_ITEM_LOG].addr = header->item_header[MBTK_DEVICE_INFO_ITEM_MODEM].addr + sizeof(mbtk_device_info_modem_t); |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 101 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 102 | |
| 103 | if(sizeof(mbtk_device_info_header_t) != write(fd, header, sizeof(mbtk_device_info_header_t))) { |
| 104 | printf("Write header fail:%d\n", errno); |
| 105 | return -1; |
| 106 | } |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 111 | static int write_item_basic(int fd, uint32 addr, mbtk_device_info_basic_t *item_basic) |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 112 | { |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 113 | if(-1 == lseek(fd, addr, SEEK_SET)) { |
| 114 | printf("lseek() fail:%d\n", errno); |
| 115 | return -1; |
| 116 | } |
| 117 | |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 118 | if(sizeof(mbtk_device_info_basic_t) != write(fd, item_basic, sizeof(mbtk_device_info_basic_t))) { |
| 119 | printf("Write item basic fail:%d\n", errno); |
| 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 126 | static int write_item_fota(int fd, uint32 addr, mbtk_device_info_fota_t *item_fota) |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 127 | { |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 128 | if(-1 == lseek(fd, addr, SEEK_SET)) { |
| 129 | printf("lseek() fail:%d\n", errno); |
| 130 | return -1; |
| 131 | } |
| 132 | |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 133 | if(sizeof(mbtk_device_info_fota_t) != write(fd, item_fota, sizeof(mbtk_device_info_fota_t))) { |
| 134 | printf("Write item fota fail:%d\n", errno); |
| 135 | return -1; |
| 136 | } |
| 137 | |
| 138 | return 0; |
| 139 | } |
| 140 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 141 | static int write_item_modem(int fd, uint32 addr, mbtk_device_info_modem_t *item_modem) |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 142 | { |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 143 | if(-1 == lseek(fd, addr, SEEK_SET)) { |
| 144 | printf("lseek() fail:%d\n", errno); |
| 145 | return -1; |
| 146 | } |
| 147 | |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 148 | if(sizeof(mbtk_device_info_modem_t) != write(fd, item_modem, sizeof(mbtk_device_info_modem_t))) { |
| 149 | printf("Write item modem fail:%d\n", errno); |
| 150 | return -1; |
| 151 | } |
| 152 | |
| 153 | return 0; |
| 154 | } |
| 155 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 156 | static int write_item_log(int fd, uint32 addr, mbtk_device_info_log_t *item_log) |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 157 | { |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 158 | if(-1 == lseek(fd, addr, SEEK_SET)) { |
| 159 | printf("lseek() fail:%d\n", errno); |
| 160 | return -1; |
| 161 | } |
| 162 | |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 163 | if(sizeof(mbtk_device_info_log_t) != write(fd, item_log, sizeof(mbtk_device_info_log_t))) { |
| 164 | printf("Write item log fail:%d\n", errno); |
| 165 | return -1; |
| 166 | } |
| 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 171 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 172 | static char* net_support_str_get(uint32 net_support) |
| 173 | { |
| 174 | static char net_str[100] = {0}; |
| 175 | |
| 176 | if(net_support & 0x01) { // GSM |
| 177 | if(strlen(net_str) > 0) { |
| 178 | strcat(net_str, "/2G"); |
| 179 | } else { |
| 180 | strcat(net_str, "2G"); |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | if(net_support & 0x02) { // WCDMA |
| 185 | if(strlen(net_str) > 0) { |
| 186 | strcat(net_str, "/3G"); |
| 187 | } else { |
| 188 | strcat(net_str, "3G"); |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | if(net_support & 0x04) { // LTE |
| 193 | if(strlen(net_str) > 0) { |
| 194 | strcat(net_str, "/4G"); |
| 195 | } else { |
| 196 | strcat(net_str, "4G"); |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | if(net_support & 0x08) { // NR |
| 201 | if(strlen(net_str) > 0) { |
| 202 | strcat(net_str, "/5G"); |
| 203 | } else { |
| 204 | strcat(net_str, "5G"); |
| 205 | } |
| 206 | } |
| 207 | return net_str; |
| 208 | } |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 209 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 210 | /* |
| 211 | * |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame] | 212 | * device_info_generate -a [a/ab] -b [revision_out] -c [revision_in] -d [project] -e [project_cust] -f [cn/eu/sa/all] -o [out_bin] |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 213 | * |
| 214 | */ |
| 215 | int main(int argc, char *argv[]) |
| 216 | { |
| 217 | int ch; |
| 218 | char out_bin[128] = {0}; |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 219 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 220 | while((ch = getopt(argc, argv, "a:b:c:d:e:f:g:h:i:o:"))!= -1){ |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 221 | #else |
b.liu | 8e0743a | 2024-08-29 16:53:16 +0800 | [diff] [blame] | 222 | while((ch = getopt(argc, argv, "a:b:c:d:e:f:g:o:"))!= -1){ |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 223 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 224 | switch(ch) |
| 225 | { |
| 226 | case 'a': |
| 227 | if(strcmp(optarg, "ab") == 0) { |
| 228 | item_basic.ab_support = 1; |
| 229 | } else if(strcmp(optarg, "a") == 0) { |
| 230 | item_basic.ab_support = 0; |
| 231 | } else { |
| 232 | printf("Must be a/ab.\n"); |
| 233 | return -1; |
| 234 | } |
| 235 | break; |
| 236 | case 'b': |
| 237 | if(strlen(optarg) > 0) |
| 238 | memcpy(item_basic.revision_out, optarg, strlen(optarg)); |
| 239 | break; |
| 240 | case 'c': |
| 241 | if(strlen(optarg) > 0) |
| 242 | memcpy(item_basic.revision_in, optarg, strlen(optarg)); |
| 243 | break; |
| 244 | case 'd': |
| 245 | if(strlen(optarg) > 0) |
| 246 | memcpy(item_basic.project, optarg, strlen(optarg)); |
| 247 | break; |
| 248 | case 'e': |
| 249 | if(strlen(optarg) > 0) |
| 250 | memcpy(item_basic.project_cust, optarg, strlen(optarg)); |
| 251 | break; |
| 252 | case 'f': |
| 253 | if(strcmp(optarg, "cn") == 0) { |
| 254 | item_modem.band_area = MBTK_MODEM_BAND_AREA_CN; |
| 255 | item_modem.band_gsm = MBTK_BAND_CN_GSM_DEFAULT; |
| 256 | item_modem.band_wcdma = MBTK_BAND_CN_WCDMA_DEFAULT; |
| 257 | item_modem.band_tdlte = MBTK_BAND_CN_TDLTE_DEFAULT; |
| 258 | item_modem.band_fddlte = MBTK_BAND_CN_FDDLTE_DEFAULT; |
b.liu | 288093c | 2024-05-09 17:02:57 +0800 | [diff] [blame] | 259 | item_modem.band_lte_ext = MBTK_BAND_CN_EXT_LTE_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 260 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 261 | item_modem.band_nr_3 = MBTK_BAND_CN_NR_3_DEFAULT; |
| 262 | item_modem.band_nr_2 = MBTK_BAND_CN_NR_2_DEFAULT; |
| 263 | item_modem.band_nr_1 = MBTK_BAND_CN_NR_1_DEFAULT; |
| 264 | item_modem.band_nr_0 = MBTK_BAND_CN_NR_0_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 265 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 266 | } else if(strcmp(optarg, "eu") == 0) { |
| 267 | item_modem.band_area = MBTK_MODEM_BAND_AREA_EU; |
| 268 | item_modem.band_gsm = MBTK_BAND_EU_GSM_DEFAULT; |
| 269 | item_modem.band_wcdma = MBTK_BAND_EU_WCDMA_DEFAULT; |
| 270 | item_modem.band_tdlte = MBTK_BAND_EU_TDLTE_DEFAULT; |
| 271 | item_modem.band_fddlte = MBTK_BAND_EU_FDDLTE_DEFAULT; |
b.liu | 288093c | 2024-05-09 17:02:57 +0800 | [diff] [blame] | 272 | item_modem.band_lte_ext = MBTK_BAND_EU_EXT_LTE_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 273 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 274 | item_modem.band_nr_3 = MBTK_BAND_EU_NR_3_DEFAULT; |
| 275 | item_modem.band_nr_2 = MBTK_BAND_EU_NR_2_DEFAULT; |
| 276 | item_modem.band_nr_1 = MBTK_BAND_EU_NR_1_DEFAULT; |
| 277 | item_modem.band_nr_0 = MBTK_BAND_EU_NR_0_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 278 | #endif |
b.liu | f678f99 | 2024-05-08 15:23:10 +0800 | [diff] [blame] | 279 | } else if(strcmp(optarg, "sa") == 0) { |
| 280 | item_modem.band_area = MBTK_MODEM_BAND_AREA_SA; |
| 281 | item_modem.band_gsm = MBTK_BAND_SA_GSM_DEFAULT; |
| 282 | item_modem.band_wcdma = MBTK_BAND_SA_WCDMA_DEFAULT; |
| 283 | item_modem.band_tdlte = MBTK_BAND_SA_TDLTE_DEFAULT; |
| 284 | item_modem.band_fddlte = MBTK_BAND_SA_FDDLTE_DEFAULT; |
b.liu | 288093c | 2024-05-09 17:02:57 +0800 | [diff] [blame] | 285 | item_modem.band_lte_ext = MBTK_BAND_SA_EXT_LTE_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 286 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 287 | item_modem.band_nr_3 = MBTK_BAND_SA_NR_3_DEFAULT; |
| 288 | item_modem.band_nr_2 = MBTK_BAND_SA_NR_2_DEFAULT; |
| 289 | item_modem.band_nr_1 = MBTK_BAND_SA_NR_1_DEFAULT; |
| 290 | item_modem.band_nr_0 = MBTK_BAND_SA_NR_0_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 291 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 292 | } else { |
| 293 | item_modem.band_area = MBTK_MODEM_BAND_AREA_ALL; |
| 294 | item_modem.band_gsm = MBTK_BAND_ALL_GSM_DEFAULT; |
| 295 | item_modem.band_wcdma = MBTK_BAND_ALL_WCDMA_DEFAULT; |
| 296 | item_modem.band_tdlte = MBTK_BAND_ALL_TDLTE_DEFAULT; |
| 297 | item_modem.band_fddlte = MBTK_BAND_ALL_FDDLTE_DEFAULT; |
b.liu | 288093c | 2024-05-09 17:02:57 +0800 | [diff] [blame] | 298 | item_modem.band_lte_ext = MBTK_BAND_ALL_EXT_LTE_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 299 | #ifdef MBTK_DEV_INFO_VERSION_2 |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 300 | item_modem.band_nr_3 = MBTK_BAND_ALL_NR_3_DEFAULT; |
| 301 | item_modem.band_nr_2 = MBTK_BAND_ALL_NR_2_DEFAULT; |
| 302 | item_modem.band_nr_1 = MBTK_BAND_ALL_NR_1_DEFAULT; |
| 303 | item_modem.band_nr_0 = MBTK_BAND_ALL_NR_0_DEFAULT; |
b.liu | f2ea8bf | 2025-01-09 15:07:34 +0800 | [diff] [blame^] | 304 | #endif |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 305 | printf("Set to default band.\n"); |
| 306 | } |
| 307 | break; |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 308 | #ifdef MBTK_DEV_INFO_VERSION_2 |
| 309 | case 'h': |
| 310 | item_modem.net_pref = (uint32)atoi(optarg); |
| 311 | printf("Set net_pref to %d success.\n", item_modem.net_pref); |
| 312 | break; |
b.liu | 61ad917 | 2025-01-09 14:33:55 +0800 | [diff] [blame] | 313 | case 'i': |
| 314 | item_modem.net_support = (uint32)atoi(optarg); |
| 315 | printf("Set net_support to %d(%s) success.\n", item_modem.net_support, |
| 316 | net_support_str_get(item_modem.net_support)); |
| 317 | break; |
b.liu | 472cfaf | 2024-12-19 19:08:19 +0800 | [diff] [blame] | 318 | #endif |
b.liu | 8e0743a | 2024-08-29 16:53:16 +0800 | [diff] [blame] | 319 | case 'g': |
| 320 | if(strlen(optarg) > 0) |
| 321 | memcpy(item_basic.build_time, optarg, strlen(optarg)); |
| 322 | break; |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 323 | case 'o': |
| 324 | if(strlen(optarg) > 0) |
| 325 | memcpy(out_bin, optarg, strlen(optarg)); |
| 326 | break; |
| 327 | default: |
| 328 | help(); |
| 329 | return -1; |
| 330 | } |
| 331 | } |
| 332 | if(strlen(item_basic.revision_out) == 0 || strlen(out_bin) == 0) { |
| 333 | help(); |
| 334 | return -1; |
| 335 | } |
| 336 | |
| 337 | printf("Version:%s, Bin:%s\n", item_basic.revision_out, out_bin); |
| 338 | |
| 339 | int fd = open(out_bin, O_WRONLY | O_TRUNC | O_CREAT, 0644); |
| 340 | if(fd < 0) { |
| 341 | printf("Open(%s) fail:%d\n", out_bin, errno); |
| 342 | return -1; |
| 343 | } |
| 344 | |
| 345 | if(update_and_write_header(fd, &info_header)) { |
| 346 | printf("update_and_write_header() fail."); |
| 347 | goto fail; |
| 348 | } |
| 349 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 350 | if(write_item_basic(fd, info_header.item_header[MBTK_DEVICE_INFO_ITEM_BASIC].addr, &item_basic)) { |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 351 | printf("update_and_write_item_basic() fail."); |
| 352 | goto fail; |
| 353 | } |
| 354 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 355 | if(write_item_fota(fd, info_header.item_header[MBTK_DEVICE_INFO_ITEM_FOTA].addr, &item_fota)) { |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 356 | printf("update_and_write_item_fota() fail."); |
| 357 | goto fail; |
| 358 | } |
| 359 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 360 | if(write_item_modem(fd, info_header.item_header[MBTK_DEVICE_INFO_ITEM_MODEM].addr, &item_modem)) { |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 361 | printf("update_and_write_item_modem() fail."); |
| 362 | goto fail; |
| 363 | } |
| 364 | |
b.liu | ec4485e | 2024-12-20 10:28:40 +0800 | [diff] [blame] | 365 | if(write_item_log(fd, info_header.item_header[MBTK_DEVICE_INFO_ITEM_LOG].addr, &item_log)) { |
b.liu | 3a41a31 | 2024-02-28 09:57:39 +0800 | [diff] [blame] | 366 | printf("update_and_write_item_log() fail."); |
| 367 | goto fail; |
| 368 | } |
| 369 | |
| 370 | printf("Success generate device_info bin:%s\n", out_bin); |
| 371 | close(fd); |
| 372 | return 0; |
| 373 | fail: |
| 374 | close(fd); |
| 375 | return -1; |
| 376 | } |
| 377 | |