xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @file main.c |
| 3 | * @brief flags·ÖÇø¹¤¾ß |
| 4 | * |
| 5 | * Copyright (C) 2023 Sanechips Technology Co., Ltd. |
| 6 | * @author |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£© |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | |
| 15 | /******************************************************************************* |
| 16 | * Include header files * |
| 17 | ******************************************************************************/ |
| 18 | #include <stdio.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <string.h> |
| 21 | #include <sys/types.h> |
| 22 | #include <errno.h> |
| 23 | #include <sys/stat.h> |
| 24 | #include <fcntl.h> |
| 25 | #include <sys/ioctl.h> |
| 26 | #include <dirent.h> |
| 27 | #include <getopt.h> |
| 28 | #include <unistd.h> |
| 29 | |
| 30 | #include "pub_flags.h" |
| 31 | #include "flags_api.h" |
| 32 | |
| 33 | |
| 34 | /******************************************************************************* |
| 35 | * Macro definitions * |
| 36 | ******************************************************************************/ |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 37 | #define FLAGS_UTILS_GET _IOWR('b', 1, T_FLAGS_INFO) |
| 38 | #define FLAGS_UTILS_SET _IOWR('b', 2, T_FLAGS_INFO) |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 39 | |
| 40 | |
| 41 | /******************************************************************************* |
| 42 | * Type definitions * |
| 43 | ******************************************************************************/ |
| 44 | typedef struct |
| 45 | { |
| 46 | int option_value; |
| 47 | int (*func)(char *); |
| 48 | } option_handle_t; |
| 49 | |
| 50 | |
| 51 | |
| 52 | /******************************************************************************* |
| 53 | * Static function declarations * |
| 54 | ******************************************************************************/ |
| 55 | static int excute_command_help(char *option_para); |
| 56 | static int excute_command_init(char *option_para); |
| 57 | static int excute_command_get(char *option_para); |
| 58 | static int excute_command_set(char *option_para); |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 59 | static int excute_command_switch(char *option_para); |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 60 | static int excute_command_get_ubifs_status(char *option_para); |
| 61 | static int excute_command_set_ubifs_status(char *option_para); |
| 62 | |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 63 | static int excute_command_kernel_get(char *option_para); |
| 64 | static int excute_command_kernel_set(char *option_para); |
| 65 | |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 66 | static int excute_command_get_nocrc(char *option_para); |
| 67 | static int excute_command_set_nocrc(char *option_para); |
| 68 | |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 69 | |
| 70 | /******************************************************************************* |
| 71 | * Global variable declarations * |
| 72 | ******************************************************************************/ |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 73 | static char * g_short_string = "higswubtqac:"; |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 74 | |
| 75 | static struct option g_long_options[] = |
| 76 | { |
| 77 | {"help", no_argument, NULL, 'h'}, |
| 78 | {"init", no_argument, NULL, 'i'}, |
| 79 | {"get", no_argument, NULL, 'g'}, |
| 80 | {"set", no_argument, NULL, 's'}, |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 81 | {"switch", no_argument, NULL, 'w'}, |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 82 | {"get-ubifs-status", no_argument, NULL, 'u'}, |
| 83 | {"set-ubifs-status", no_argument, NULL, 'b'}, |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 84 | {"kernel-get", no_argument, NULL, 't'}, |
| 85 | {"kernel-set", no_argument, NULL, 'q'}, |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 86 | {"get-nocrc", no_argument, NULL, 'a'}, |
| 87 | {"set-nocrc", required_argument, NULL, 'c'}, |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 88 | {0, 0, 0, 0} |
| 89 | }; |
| 90 | |
| 91 | static option_handle_t g_option_handle[] = |
| 92 | { |
| 93 | {'h', excute_command_help}, |
| 94 | {'i', excute_command_init}, |
| 95 | {'g', excute_command_get}, |
| 96 | {'s', excute_command_set}, |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 97 | {'w', excute_command_switch}, |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 98 | {'u', excute_command_get_ubifs_status}, |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 99 | {'b', excute_command_set_ubifs_status}, |
| 100 | {'t', excute_command_kernel_get}, |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 101 | {'q', excute_command_kernel_set}, |
| 102 | {'a', excute_command_get_nocrc}, |
| 103 | {'c', excute_command_set_nocrc} |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | |
| 107 | /******************************************************************************* |
| 108 | * Static function define * |
| 109 | ******************************************************************************/ |
| 110 | static void usage(void) |
| 111 | { |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 112 | printf("flags_tool [-higswub] \n " |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 113 | " -h, --help show usage \n" |
| 114 | " -i, --init init flags \n" |
| 115 | " -g, --get get flags data \n" |
| 116 | " -s, --set set flags data \n" |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 117 | " -w, --switch system A/B switch \n" |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 118 | " -u, --get-ubifs-status get ubifs status \n" |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 119 | " -b, --set-ubifs-status set ubifs status \n" |
| 120 | " -t, --kernel-get kernel-get flags data \n" |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 121 | " -q, --kernel-set kernel-set flags data \n" |
| 122 | " -a, --get-nocrc get-nocrc flags data \n" |
| 123 | " -c, --set-nocrc set-nocrc flags data \n"); |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 124 | |
| 125 | return; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | static int excute_command_help(char *option_para) |
| 130 | { |
| 131 | usage(); |
| 132 | |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | |
| 137 | static int excute_command_init(char *option_para) |
| 138 | { |
| 139 | if (flags_init() != 0) |
| 140 | { |
| 141 | printf("Err: flags init fail \n"); |
| 142 | |
| 143 | return -1; |
| 144 | } |
| 145 | else |
| 146 | { |
| 147 | printf("Log: flags init success \n"); |
| 148 | |
| 149 | return 0; |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | |
| 154 | static int excute_command_get(char *option_para) |
| 155 | { |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 156 | int i = 0; |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 157 | T_FLAGS_INFO flags_info = {0}; |
| 158 | |
| 159 | if (flags_get(&flags_info) != 0) |
| 160 | { |
| 161 | printf("Err: flags get fail \n"); |
| 162 | |
| 163 | return -1; |
| 164 | } |
| 165 | else |
| 166 | { |
| 167 | printf("magic_start = 0x%x \n", flags_info.magic_start); |
| 168 | |
| 169 | printf("boot_fota_flag.boot_to = 0x%x \n", flags_info.boot_fota_flag.boot_to); |
| 170 | printf("boot_fota_flag.fota_status = %u \n", flags_info.boot_fota_flag.fota_status); |
| 171 | printf("boot_fota_flag.system.status = 0x%x \n", flags_info.boot_fota_flag.system.status); |
| 172 | printf("boot_fota_flag.system.try_cnt = %d \n", flags_info.boot_fota_flag.system.try_cnt); |
| 173 | printf("boot_fota_flag.system2.status = 0x%x \n", flags_info.boot_fota_flag.system2.status); |
| 174 | printf("boot_fota_flag.system2.try_cnt = %d \n", flags_info.boot_fota_flag.system2.try_cnt); |
| 175 | |
| 176 | printf("boot_env.dualsys_type = 0x%x \n", flags_info.boot_env.dualsys_type); |
| 177 | printf("boot_env.system_boot_env = %s \n", flags_info.boot_env.system_boot_env); |
| 178 | printf("boot_env.system2_boot_env = %s \n", flags_info.boot_env.system2_boot_env); |
| 179 | |
| 180 | printf("ubifs_status.fs_status = %d \n", flags_info.ubifs_status.fs_status); |
| 181 | printf("ubifs_status.fs_mtd_name = %s \n", flags_info.ubifs_status.fs_mtd_name); |
| 182 | printf("ubifs_status.fs_ubi_vol_name = %s \n", flags_info.ubifs_status.fs_ubi_vol_name); |
| 183 | |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 184 | printf("nvro_flag = %u \n", flags_info.nvro_flag); |
| 185 | |
| 186 | printf("ota_system = %d \n", flags_info.ota_system); |
| 187 | |
| 188 | for (i = 0; i < OTA_PARTITION_NUM_MAX; i++) |
| 189 | { |
| 190 | printf("index=%d, mtdnum=%d, len=%u \n", i, flags_info.ota_partiton_info[i].mtdnum, flags_info.ota_partiton_info[i].len); |
| 191 | } |
| 192 | |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 193 | printf("magic_end = 0x%x \n", flags_info.magic_end); |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | |
| 200 | static int excute_command_set(char *option_para) |
| 201 | { |
| 202 | T_FLAGS_INFO flags_info = {0}; |
| 203 | |
| 204 | char system_boot_env[128] = "bootEnv1"; |
| 205 | char system2_boot_env[128] = "2bootEnv"; |
| 206 | |
| 207 | char fs_mtd_name[16] = "nameMTD"; |
| 208 | char fs_ubi_vol_name[16] = "nameVOL"; |
| 209 | |
| 210 | flags_info.magic_start = FLAGS_MAGIC; |
| 211 | |
| 212 | flags_info.boot_fota_flag.boot_to = DUAL_SYSTEM; |
| 213 | flags_info.boot_fota_flag.fota_status = 0; |
| 214 | flags_info.boot_fota_flag.system.status = DUALSYSTEM_STATUS_BOOTABLE; |
| 215 | flags_info.boot_fota_flag.system.try_cnt = 5; |
| 216 | flags_info.boot_fota_flag.system2.status = DUALSYSTEM_STATUS_BOOTABLE; |
| 217 | flags_info.boot_fota_flag.system2.try_cnt = 13; |
| 218 | |
| 219 | flags_info.boot_env.dualsys_type = DUALSYSTEM_AB; |
| 220 | strncpy(flags_info.boot_env.system_boot_env, system_boot_env, sizeof(flags_info.boot_env.system_boot_env)); |
| 221 | strncpy(flags_info.boot_env.system2_boot_env, system2_boot_env, sizeof(flags_info.boot_env.system2_boot_env)); |
| 222 | |
| 223 | flags_info.ubifs_status.fs_status = 0; |
| 224 | strncpy(flags_info.ubifs_status.fs_mtd_name, fs_mtd_name, sizeof(flags_info.ubifs_status.fs_mtd_name)); |
| 225 | strncpy(flags_info.ubifs_status.fs_ubi_vol_name, fs_ubi_vol_name, sizeof(flags_info.ubifs_status.fs_ubi_vol_name)); |
| 226 | |
| 227 | flags_info.magic_end = FLAGS_MAGIC; |
| 228 | |
| 229 | if (flags_set(&flags_info) != 0) |
| 230 | { |
| 231 | printf("Err: set flags fail \n"); |
| 232 | |
| 233 | return -1; |
| 234 | } |
| 235 | else |
| 236 | { |
| 237 | printf("Log: set flags success \n"); |
| 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | } |
| 242 | |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 243 | static int excute_command_switch(char *option_para) |
| 244 | { |
| 245 | T_FLAGS_INFO flags_info = {0}; |
| 246 | int ret = -1; |
| 247 | |
| 248 | ret = flags_get(&flags_info); |
| 249 | if (ret < 0) |
| 250 | { |
| 251 | printf("flags switch flags_get fail\n"); |
| 252 | return ret; |
| 253 | } |
| 254 | if (flags_info.boot_fota_flag.boot_to == DUAL_SYSTEM) |
| 255 | { |
| 256 | flags_info.boot_fota_flag.boot_to = DUAL_SYSTEM2; //A->B |
| 257 | printf("flags switch system A to system B\n"); |
| 258 | } |
| 259 | else |
| 260 | { |
| 261 | flags_info.boot_fota_flag.boot_to = DUAL_SYSTEM; //B->A |
| 262 | printf("flags switch system B to system A\n"); |
| 263 | } |
| 264 | ret = flags_set(&flags_info); |
| 265 | if (ret < 0) |
| 266 | { |
| 267 | printf("flags switch flags_set fail\n"); |
| 268 | return ret; |
| 269 | } |
| 270 | printf("flags AB system switch sucess\n"); |
| 271 | |
| 272 | return 0; |
| 273 | } |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 274 | |
| 275 | static int excute_command_get_ubifs_status(char *option_para) |
| 276 | { |
| 277 | T_UBIFS_STATUS ubifs_status = {0}; |
| 278 | |
| 279 | if (flags_get_ubifs_status(&ubifs_status) != 0) |
| 280 | { |
| 281 | printf("Err: get ubifs status fail \n"); |
| 282 | |
| 283 | return -1; |
| 284 | } |
| 285 | else |
| 286 | { |
| 287 | printf("ubifs_status.fs_status = %d \n", ubifs_status.fs_status); |
| 288 | printf("ubifs_status.fs_mtd_name = %s \n", ubifs_status.fs_mtd_name); |
| 289 | printf("ubifs_status.fs_ubi_vol_name = %s \n", ubifs_status.fs_ubi_vol_name); |
| 290 | |
| 291 | return 0; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | |
| 296 | static int excute_command_set_ubifs_status(char *option_para) |
| 297 | { |
| 298 | T_UBIFS_STATUS ubifs_status = {0}; |
| 299 | |
| 300 | char fs_mtd_name[16] = "mtdName"; |
| 301 | char fs_ubi_vol_name[16] = "volName"; |
| 302 | |
| 303 | ubifs_status.fs_status = 2; |
| 304 | strncpy(ubifs_status.fs_mtd_name, fs_mtd_name, sizeof(ubifs_status.fs_mtd_name)); |
| 305 | strncpy(ubifs_status.fs_ubi_vol_name, fs_ubi_vol_name, sizeof(ubifs_status.fs_ubi_vol_name)); |
| 306 | |
| 307 | if (flags_set_ubifs_status(&ubifs_status) != 0) |
| 308 | { |
| 309 | printf("Err: set ubifs status fail \n"); |
| 310 | |
| 311 | return -1; |
| 312 | } |
| 313 | else |
| 314 | { |
| 315 | printf("Log: set ubifs status success \n"); |
| 316 | |
| 317 | return 0; |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 322 | static int excute_command_kernel_get(char *option_para) |
| 323 | { |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 324 | int i = 0; |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 325 | int fd = -1; |
| 326 | T_FLAGS_INFO flags_info = {0}; |
| 327 | |
| 328 | fd = open("/dev/chardevnode0", O_RDWR); |
| 329 | if (-1 == open) |
| 330 | { |
| 331 | printf("kernel get open chardevnode fail, errno=%d \n", errno); |
| 332 | return -1; |
| 333 | } |
| 334 | |
| 335 | if (ioctl(fd, FLAGS_UTILS_GET, &flags_info) < 0) |
| 336 | { |
| 337 | printf("Err: ioctl cmd(0x%x) fail, errno=%d \n", FLAGS_UTILS_GET, errno); |
| 338 | |
| 339 | close(fd); |
| 340 | return -1; |
| 341 | } |
| 342 | |
| 343 | printf("magic_start = 0x%x \n", flags_info.magic_start); |
| 344 | |
| 345 | printf("boot_fota_flag.boot_to = 0x%x \n", flags_info.boot_fota_flag.boot_to); |
| 346 | printf("boot_fota_flag.fota_status = %u \n", flags_info.boot_fota_flag.fota_status); |
| 347 | printf("boot_fota_flag.system.status = 0x%x \n", flags_info.boot_fota_flag.system.status); |
| 348 | printf("boot_fota_flag.system.try_cnt = %d \n", flags_info.boot_fota_flag.system.try_cnt); |
| 349 | printf("boot_fota_flag.system2.status = 0x%x \n", flags_info.boot_fota_flag.system2.status); |
| 350 | printf("boot_fota_flag.system2.try_cnt = %d \n", flags_info.boot_fota_flag.system2.try_cnt); |
| 351 | |
| 352 | printf("boot_env.dualsys_type = 0x%x \n", flags_info.boot_env.dualsys_type); |
| 353 | printf("boot_env.system_boot_env = %s \n", flags_info.boot_env.system_boot_env); |
| 354 | printf("boot_env.system2_boot_env = %s \n", flags_info.boot_env.system2_boot_env); |
| 355 | |
| 356 | printf("ubifs_status.fs_status = %d \n", flags_info.ubifs_status.fs_status); |
| 357 | printf("ubifs_status.fs_mtd_name = %s \n", flags_info.ubifs_status.fs_mtd_name); |
| 358 | printf("ubifs_status.fs_ubi_vol_name = %s \n", flags_info.ubifs_status.fs_ubi_vol_name); |
| 359 | |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 360 | printf("nvro_flag = %u \n", flags_info.nvro_flag); |
| 361 | |
| 362 | printf("ota_system = %d \n", flags_info.ota_system); |
| 363 | |
| 364 | for (i = 0; i < OTA_PARTITION_NUM_MAX; i++) |
| 365 | { |
| 366 | printf("index=%d, mtdnum=%d, len=%u \n", i, flags_info.ota_partiton_info[i].mtdnum, flags_info.ota_partiton_info[i].len); |
| 367 | } |
| 368 | |
xf.li | aa4d92f | 2023-09-13 00:18:58 -0700 | [diff] [blame] | 369 | printf("magic_end = 0x%x \n", flags_info.magic_end); |
| 370 | |
| 371 | close(fd); |
| 372 | return 0; |
| 373 | } |
| 374 | |
| 375 | |
| 376 | static int excute_command_kernel_set(char *option_para) |
| 377 | { |
| 378 | int fd = -1; |
| 379 | T_FLAGS_INFO flags_info = {0}; |
| 380 | |
| 381 | char system_boot_env[128] = "bootEnv1"; |
| 382 | char system2_boot_env[128] = "2bootEnv"; |
| 383 | |
| 384 | char fs_mtd_name[16] = "nameMTD"; |
| 385 | char fs_ubi_vol_name[16] = "nameVOL"; |
| 386 | |
| 387 | fd = open("/dev/chardevnode0", O_RDWR); |
| 388 | if (-1 == open) |
| 389 | { |
| 390 | printf("kernel set open chardevnode fail, errno=%d \n", errno); |
| 391 | return -1; |
| 392 | } |
| 393 | |
| 394 | flags_info.magic_start = FLAGS_MAGIC; |
| 395 | |
| 396 | flags_info.boot_fota_flag.boot_to = DUAL_SYSTEM; |
| 397 | flags_info.boot_fota_flag.fota_status = 0; |
| 398 | flags_info.boot_fota_flag.system.status = DUALSYSTEM_STATUS_BOOTABLE; |
| 399 | flags_info.boot_fota_flag.system.try_cnt = 5; |
| 400 | flags_info.boot_fota_flag.system2.status = DUALSYSTEM_STATUS_BOOTABLE; |
| 401 | flags_info.boot_fota_flag.system2.try_cnt = 13; |
| 402 | |
| 403 | flags_info.boot_env.dualsys_type = DUALSYSTEM_AB; |
| 404 | strncpy(flags_info.boot_env.system_boot_env, system_boot_env, sizeof(flags_info.boot_env.system_boot_env)); |
| 405 | strncpy(flags_info.boot_env.system2_boot_env, system2_boot_env, sizeof(flags_info.boot_env.system2_boot_env)); |
| 406 | |
| 407 | flags_info.ubifs_status.fs_status = 0; |
| 408 | strncpy(flags_info.ubifs_status.fs_mtd_name, fs_mtd_name, sizeof(flags_info.ubifs_status.fs_mtd_name)); |
| 409 | strncpy(flags_info.ubifs_status.fs_ubi_vol_name, fs_ubi_vol_name, sizeof(flags_info.ubifs_status.fs_ubi_vol_name)); |
| 410 | |
| 411 | flags_info.magic_end = FLAGS_MAGIC; |
| 412 | |
| 413 | if (ioctl(fd, FLAGS_UTILS_SET, &flags_info) < 0) |
| 414 | { |
| 415 | printf("Err: ioctl cmd(0x%x) fail, errno=%d \n", FLAGS_UTILS_SET, errno); |
| 416 | |
| 417 | close(fd); |
| 418 | return -1; |
| 419 | } |
| 420 | |
| 421 | printf("Log: kernel set flags success \n"); |
| 422 | |
| 423 | close(fd); |
| 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | |
xf.li | ce87319 | 2023-11-08 17:10:35 -0800 | [diff] [blame] | 428 | static int excute_command_get_nocrc(char *option_para) |
| 429 | { |
| 430 | int i = 0; |
| 431 | T_FLAGS_INFO flags_info = {0}; |
| 432 | |
| 433 | if (flags_get_nocrc(&flags_info) != 0) |
| 434 | { |
| 435 | printf("Err: flags get fail \n"); |
| 436 | return -1; |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | printf("magic_start = 0x%x \n", flags_info.magic_start); |
| 441 | |
| 442 | printf("boot_fota_flag.boot_to = 0x%x \n", flags_info.boot_fota_flag.boot_to); |
| 443 | printf("boot_fota_flag.fota_status = %u \n", flags_info.boot_fota_flag.fota_status); |
| 444 | printf("boot_fota_flag.system.status = 0x%x \n", flags_info.boot_fota_flag.system.status); |
| 445 | printf("boot_fota_flag.system.try_cnt = %d \n", flags_info.boot_fota_flag.system.try_cnt); |
| 446 | printf("boot_fota_flag.system2.status = 0x%x \n", flags_info.boot_fota_flag.system2.status); |
| 447 | printf("boot_fota_flag.system2.try_cnt = %d \n", flags_info.boot_fota_flag.system2.try_cnt); |
| 448 | |
| 449 | printf("boot_env.dualsys_type = 0x%x \n", flags_info.boot_env.dualsys_type); |
| 450 | printf("boot_env.system_boot_env = %s \n", flags_info.boot_env.system_boot_env); |
| 451 | printf("boot_env.system2_boot_env = %s \n", flags_info.boot_env.system2_boot_env); |
| 452 | |
| 453 | printf("ubifs_status.fs_status = %d \n", flags_info.ubifs_status.fs_status); |
| 454 | printf("ubifs_status.fs_mtd_name = %s \n", flags_info.ubifs_status.fs_mtd_name); |
| 455 | printf("ubifs_status.fs_ubi_vol_name = %s \n", flags_info.ubifs_status.fs_ubi_vol_name); |
| 456 | |
| 457 | printf("nvro_flag = %u \n", flags_info.nvro_flag); |
| 458 | printf("crc32 = %u \n", flags_info.crc32); |
| 459 | |
| 460 | printf("ota_system = %d \n", flags_info.ota_system); |
| 461 | |
| 462 | for (i = 0; i < OTA_PARTITION_NUM_MAX; i++) |
| 463 | { |
| 464 | printf("index=%d, mtdnum=%d, len=%u \n", i, flags_info.ota_partiton_info[i].mtdnum, flags_info.ota_partiton_info[i].len); |
| 465 | } |
| 466 | |
| 467 | printf("magic_end = 0x%x \n", flags_info.magic_end); |
| 468 | |
| 469 | return 0; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | |
| 474 | static int excute_command_set_nocrc(char *option_para) |
| 475 | { |
| 476 | T_FLAGS_INFO flags_info = {0}; |
| 477 | |
| 478 | const char delim[2] = ","; |
| 479 | char *token_1 = NULL; |
| 480 | char *token_2 = NULL; |
| 481 | char *token_3 = NULL; |
| 482 | char *token_4 = NULL; |
| 483 | char *token_5 = NULL; |
| 484 | char *token_6 = NULL; |
| 485 | |
| 486 | if (NULL == option_para) |
| 487 | { |
| 488 | usage(); |
| 489 | printf("Command input invalid value! null option parameters! \n"); |
| 490 | return -1; |
| 491 | } |
| 492 | |
| 493 | if (flags_get_nocrc(&flags_info) != 0) |
| 494 | { |
| 495 | printf("Err: flags get fail \n"); |
| 496 | return -1; |
| 497 | } |
| 498 | |
| 499 | token_1 = strtok(option_para, delim); |
| 500 | if (NULL == token_1) |
| 501 | { |
| 502 | printf("token_1 delim fail: NULL \n"); |
| 503 | return -1; |
| 504 | } |
| 505 | |
| 506 | token_2 = strtok(NULL, delim); |
| 507 | if (NULL == token_2) |
| 508 | { |
| 509 | printf("token_2 delim fail: NULL \n"); |
| 510 | return -1; |
| 511 | } |
| 512 | |
| 513 | token_3 = strtok(NULL, delim); |
| 514 | if (NULL == token_3) |
| 515 | { |
| 516 | printf("token_3 delim fail: NULL \n"); |
| 517 | return -1; |
| 518 | } |
| 519 | |
| 520 | token_4 = strtok(NULL, delim); |
| 521 | if (NULL == token_4) |
| 522 | { |
| 523 | printf("token_4 delim fail: NULL \n"); |
| 524 | return -1; |
| 525 | } |
| 526 | |
| 527 | token_5 = strtok(NULL, delim); |
| 528 | if (NULL == token_5) |
| 529 | { |
| 530 | printf("token_5 delim fail: NULL \n"); |
| 531 | return -1; |
| 532 | } |
| 533 | |
| 534 | token_6 = strtok(NULL, delim); |
| 535 | if (NULL != token_6) |
| 536 | { |
| 537 | printf("too many command input, fail \n"); |
| 538 | return -1; |
| 539 | } |
| 540 | |
| 541 | flags_info.boot_fota_flag.system2.try_cnt = atoi(token_1); |
| 542 | |
| 543 | strncpy(flags_info.boot_env.system_boot_env, token_2, sizeof(flags_info.boot_env.system_boot_env)); |
| 544 | |
| 545 | flags_info.ubifs_status.fs_status = atoi(token_3); |
| 546 | strncpy(flags_info.ubifs_status.fs_mtd_name, token_4, sizeof(flags_info.ubifs_status.fs_mtd_name)); |
| 547 | |
| 548 | flags_info.magic_end = atoi(token_5); |
| 549 | |
| 550 | if (flags_set_nocrc(&flags_info) != 0) |
| 551 | { |
| 552 | printf("Err: set flags fail \n"); |
| 553 | return -1; |
| 554 | } |
| 555 | else |
| 556 | { |
| 557 | printf("Log: set flags success \n"); |
| 558 | return 0; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | |
xf.li | 6c8fc1e | 2023-08-12 00:11:09 -0700 | [diff] [blame] | 563 | /******************************************************************************* |
| 564 | * Global function declarations * |
| 565 | ******************************************************************************/ |
| 566 | int main(int argc, char *argv[]) |
| 567 | { |
| 568 | int i = 0; |
| 569 | int option_index = 0; |
| 570 | int cmd_num = 0; |
| 571 | |
| 572 | int ret = -1; |
| 573 | int ch = -1; |
| 574 | |
| 575 | printf("Log: build date: %s %s \n", __DATE__, __TIME__); |
| 576 | |
| 577 | while ((ch = getopt_long(argc, argv, g_short_string, g_long_options, &option_index)) != -1) |
| 578 | { |
| 579 | for (i = 0; i < sizeof(g_option_handle) / sizeof(option_handle_t); i++) |
| 580 | { |
| 581 | if (ch != g_option_handle[i].option_value) |
| 582 | { |
| 583 | continue; |
| 584 | } |
| 585 | |
| 586 | cmd_num++; |
| 587 | |
| 588 | if (NULL == g_option_handle[i].func) |
| 589 | { |
| 590 | printf("Err: command short string is: %c, but option handle func is NULL \n", ch); |
| 591 | break; |
| 592 | } |
| 593 | |
| 594 | ret = g_option_handle[i].func(optarg); |
| 595 | if (ret < 0) |
| 596 | { |
| 597 | ret = -1; |
| 598 | goto end; |
| 599 | } |
| 600 | } |
| 601 | } |
| 602 | |
| 603 | if (0 == cmd_num) |
| 604 | { |
| 605 | printf("Err: can not find valid command \n"); |
| 606 | usage(); |
| 607 | ret = -1; |
| 608 | goto end; |
| 609 | } |
| 610 | |
| 611 | ret = 0; |
| 612 | |
| 613 | end: |
| 614 | return ret ; |
| 615 | } |
| 616 | |