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