[Feature][ZXW-88]merge P50 version
Only Configure: No
Affected branch: master
Affected module: unknown
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No
Change-Id: I34667719d9e0e7e29e8e4368848601cde0a48408
diff --git a/ap/app/flags_tool/src/main.c b/ap/app/flags_tool/src/main.c
new file mode 100755
index 0000000..403349e
--- /dev/null
+++ b/ap/app/flags_tool/src/main.c
@@ -0,0 +1,310 @@
+/**
+* @file main.c
+* @brief flags·ÖÇø¹¤¾ß
+*
+* Copyright (C) 2023 Sanechips Technology Co., Ltd.
+* @author
+*
+* This program is free software; you can redistribute it and/or modify
+* it under the terms of the GNU General Public License version 2 as
+* published by the Free Software Foundation. £¨±ØÑ¡£ºGPLv2 Licence£©
+*
+*/
+
+
+/*******************************************************************************
+ * Include header files *
+ ******************************************************************************/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <dirent.h>
+#include <getopt.h>
+#include <unistd.h>
+
+#include "pub_flags.h"
+#include "flags_api.h"
+
+
+/*******************************************************************************
+ * Macro definitions *
+ ******************************************************************************/
+
+
+/*******************************************************************************
+ * Type definitions *
+ ******************************************************************************/
+typedef struct
+{
+ int option_value;
+ int (*func)(char *);
+} option_handle_t;
+
+
+
+/*******************************************************************************
+ * Static function declarations *
+ ******************************************************************************/
+static int excute_command_help(char *option_para);
+static int excute_command_init(char *option_para);
+static int excute_command_get(char *option_para);
+static int excute_command_set(char *option_para);
+static int excute_command_get_ubifs_status(char *option_para);
+static int excute_command_set_ubifs_status(char *option_para);
+
+
+/*******************************************************************************
+ * Global variable declarations *
+ ******************************************************************************/
+static char * g_short_string = "higsub";
+
+static struct option g_long_options[] =
+{
+ {"help", no_argument, NULL, 'h'},
+ {"init", no_argument, NULL, 'i'},
+ {"get", no_argument, NULL, 'g'},
+ {"set", no_argument, NULL, 's'},
+ {"get-ubifs-status", no_argument, NULL, 'u'},
+ {"set-ubifs-status", no_argument, NULL, 'b'},
+ {0, 0, 0, 0}
+};
+
+static option_handle_t g_option_handle[] =
+{
+ {'h', excute_command_help},
+ {'i', excute_command_init},
+ {'g', excute_command_get},
+ {'s', excute_command_set},
+ {'u', excute_command_get_ubifs_status},
+ {'b', excute_command_set_ubifs_status}
+};
+
+
+/*******************************************************************************
+ * Static function define *
+ ******************************************************************************/
+static void usage(void)
+{
+ printf("flags_tool [-higsub] \n "
+ " -h, --help show usage \n"
+ " -i, --init init flags \n"
+ " -g, --get get flags data \n"
+ " -s, --set set flags data \n"
+ " -u, --get-ubifs-status get ubifs status \n"
+ " -b, --set-ubifs-status set ubifs status \n");
+
+ return;
+}
+
+
+static int excute_command_help(char *option_para)
+{
+ usage();
+
+ return 0;
+}
+
+
+static int excute_command_init(char *option_para)
+{
+ if (flags_init() != 0)
+ {
+ printf("Err: flags init fail \n");
+
+ return -1;
+ }
+ else
+ {
+ printf("Log: flags init success \n");
+
+ return 0;
+ }
+}
+
+
+static int excute_command_get(char *option_para)
+{
+ T_FLAGS_INFO flags_info = {0};
+
+ if (flags_get(&flags_info) != 0)
+ {
+ printf("Err: flags get fail \n");
+
+ return -1;
+ }
+ else
+ {
+ printf("magic_start = 0x%x \n", flags_info.magic_start);
+
+ printf("boot_fota_flag.boot_to = 0x%x \n", flags_info.boot_fota_flag.boot_to);
+ printf("boot_fota_flag.fota_status = %u \n", flags_info.boot_fota_flag.fota_status);
+ printf("boot_fota_flag.system.status = 0x%x \n", flags_info.boot_fota_flag.system.status);
+ printf("boot_fota_flag.system.try_cnt = %d \n", flags_info.boot_fota_flag.system.try_cnt);
+ printf("boot_fota_flag.system2.status = 0x%x \n", flags_info.boot_fota_flag.system2.status);
+ printf("boot_fota_flag.system2.try_cnt = %d \n", flags_info.boot_fota_flag.system2.try_cnt);
+
+ printf("boot_env.dualsys_type = 0x%x \n", flags_info.boot_env.dualsys_type);
+ printf("boot_env.system_boot_env = %s \n", flags_info.boot_env.system_boot_env);
+ printf("boot_env.system2_boot_env = %s \n", flags_info.boot_env.system2_boot_env);
+
+ printf("ubifs_status.fs_status = %d \n", flags_info.ubifs_status.fs_status);
+ printf("ubifs_status.fs_mtd_name = %s \n", flags_info.ubifs_status.fs_mtd_name);
+ printf("ubifs_status.fs_ubi_vol_name = %s \n", flags_info.ubifs_status.fs_ubi_vol_name);
+
+ printf("magic_end = 0x%x \n", flags_info.magic_end);
+
+ return 0;
+ }
+}
+
+
+static int excute_command_set(char *option_para)
+{
+ T_FLAGS_INFO flags_info = {0};
+
+ char system_boot_env[128] = "bootEnv1";
+ char system2_boot_env[128] = "2bootEnv";
+
+ char fs_mtd_name[16] = "nameMTD";
+ char fs_ubi_vol_name[16] = "nameVOL";
+
+ flags_info.magic_start = FLAGS_MAGIC;
+
+ flags_info.boot_fota_flag.boot_to = DUAL_SYSTEM;
+ flags_info.boot_fota_flag.fota_status = 0;
+ flags_info.boot_fota_flag.system.status = DUALSYSTEM_STATUS_BOOTABLE;
+ flags_info.boot_fota_flag.system.try_cnt = 5;
+ flags_info.boot_fota_flag.system2.status = DUALSYSTEM_STATUS_BOOTABLE;
+ flags_info.boot_fota_flag.system2.try_cnt = 13;
+
+ flags_info.boot_env.dualsys_type = DUALSYSTEM_AB;
+ strncpy(flags_info.boot_env.system_boot_env, system_boot_env, sizeof(flags_info.boot_env.system_boot_env));
+ strncpy(flags_info.boot_env.system2_boot_env, system2_boot_env, sizeof(flags_info.boot_env.system2_boot_env));
+
+ flags_info.ubifs_status.fs_status = 0;
+ strncpy(flags_info.ubifs_status.fs_mtd_name, fs_mtd_name, sizeof(flags_info.ubifs_status.fs_mtd_name));
+ strncpy(flags_info.ubifs_status.fs_ubi_vol_name, fs_ubi_vol_name, sizeof(flags_info.ubifs_status.fs_ubi_vol_name));
+
+ flags_info.magic_end = FLAGS_MAGIC;
+
+ if (flags_set(&flags_info) != 0)
+ {
+ printf("Err: set flags fail \n");
+
+ return -1;
+ }
+ else
+ {
+ printf("Log: set flags success \n");
+
+ return 0;
+ }
+}
+
+
+static int excute_command_get_ubifs_status(char *option_para)
+{
+ T_UBIFS_STATUS ubifs_status = {0};
+
+ if (flags_get_ubifs_status(&ubifs_status) != 0)
+ {
+ printf("Err: get ubifs status fail \n");
+
+ return -1;
+ }
+ else
+ {
+ printf("ubifs_status.fs_status = %d \n", ubifs_status.fs_status);
+ printf("ubifs_status.fs_mtd_name = %s \n", ubifs_status.fs_mtd_name);
+ printf("ubifs_status.fs_ubi_vol_name = %s \n", ubifs_status.fs_ubi_vol_name);
+
+ return 0;
+ }
+}
+
+
+static int excute_command_set_ubifs_status(char *option_para)
+{
+ T_UBIFS_STATUS ubifs_status = {0};
+
+ char fs_mtd_name[16] = "mtdName";
+ char fs_ubi_vol_name[16] = "volName";
+
+ ubifs_status.fs_status = 2;
+ strncpy(ubifs_status.fs_mtd_name, fs_mtd_name, sizeof(ubifs_status.fs_mtd_name));
+ strncpy(ubifs_status.fs_ubi_vol_name, fs_ubi_vol_name, sizeof(ubifs_status.fs_ubi_vol_name));
+
+ if (flags_set_ubifs_status(&ubifs_status) != 0)
+ {
+ printf("Err: set ubifs status fail \n");
+
+ return -1;
+ }
+ else
+ {
+ printf("Log: set ubifs status success \n");
+
+ return 0;
+ }
+}
+
+
+/*******************************************************************************
+ * Global function declarations *
+ ******************************************************************************/
+int main(int argc, char *argv[])
+{
+ int i = 0;
+ int option_index = 0;
+ int cmd_num = 0;
+
+ int ret = -1;
+ int ch = -1;
+
+ printf("Log: build date: %s %s \n", __DATE__, __TIME__);
+
+ while ((ch = getopt_long(argc, argv, g_short_string, g_long_options, &option_index)) != -1)
+ {
+ for (i = 0; i < sizeof(g_option_handle) / sizeof(option_handle_t); i++)
+ {
+ if (ch != g_option_handle[i].option_value)
+ {
+ continue;
+ }
+
+ cmd_num++;
+
+ if (NULL == g_option_handle[i].func)
+ {
+ printf("Err: command short string is: %c, but option handle func is NULL \n", ch);
+ break;
+ }
+
+ ret = g_option_handle[i].func(optarg);
+ if (ret < 0)
+ {
+ ret = -1;
+ goto end;
+ }
+ }
+ }
+
+ if (0 == cmd_num)
+ {
+ printf("Err: can not find valid command \n");
+ usage();
+ ret = -1;
+ goto end;
+ }
+
+ ret = 0;
+
+end:
+ return ret ;
+}
+