osu: Add an option to print all board params 10/317710/1 accepted/tizen_9.0_unified tizen_9.0 accepted/tizen/9.0/unified/20250109.040122
authorUnsung Lee <unsung.lee@samsung.com>
Thu, 19 Dec 2024 07:57:01 +0000 (16:57 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Tue, 7 Jan 2025 02:40:11 +0000 (11:40 +0900)
Add an option called --get-all-board-param to print all board parameters.
It will show all board parameter with instruction 'osu --get-all-board-param'.
It is the option for users who want to know all board parameters at once.
If the user want to know just one board parameter, then use 'osu --get-board-param'.
If the user want to know all board parameters, then use 'osu --get-all-board-param'

Example of the result of 'osu --get-all-board-param':
boot-mode: normal
current-partition: a
partition-ab-cloned: 1
partition-status: a: ok
partition-status: b: ok
upgrade-progress-status: 0
upgrade-state: standby
upgrade-type: offline

Change-Id: I41361b473a24f855af27a04560d74d74824562e3
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
packaging/update-control.spec
tools/osu/osu.c

index 42fc70be8cbae6f8bc71cf7c8561ba8dedfb8fc2..f481805d0adcae775dde489d2c8612ac9555224e 100644 (file)
@@ -4,7 +4,7 @@
 %define service_file update-manager.service
 
 Name:           update-control
-Version:        1.0.5
+Version:        1.0.6
 Release:        0
 License:        Apache-2.0
 Summary:        Update Control API
index f9945af1346c688cfc3be9efcb4968ff6a130e6b..7ebc3b0fa6a1468918e72d1fe24d939826b7c0f9 100644 (file)
@@ -43,6 +43,9 @@ struct arguments {
 
 static void print_help(char*);
 
+#define BOARD_AB_PARTITION_NUM                 2
+#define BOARD_PARAMS_GETTER_ALL_BOARD_PARAM    "all-board-params"
+
 static int parse_args(int argc, char **argv, struct arguments *args)
 {
        assert(argv);
@@ -62,6 +65,7 @@ static int parse_args(int argc, char **argv, struct arguments *args)
                {"offline-update", no_argument, NULL, 'f'},
                {"online-update", no_argument, NULL, 'n'},
                {"get-board-param", required_argument, NULL, 'g'},
+               {"get-all-board-param", no_argument, NULL, 'a'},
                {"set-board-param", required_argument, NULL, 's'},
                {"help", no_argument, NULL, 'h'},
                {}
@@ -89,6 +93,11 @@ static int parse_args(int argc, char **argv, struct arguments *args)
                                args->board_param = optarg;
                                return 0;
                        }
+                       case 'a': {
+                               args->get_board_param = true;
+                               args->board_param = BOARD_PARAMS_GETTER_ALL_BOARD_PARAM;
+                               return 0;
+                       }
                        case 's': {
                                args->set_board_param = true;
                                args->board_param = optarg;
@@ -125,6 +134,7 @@ static void print_help(char *my_name)
                "                                               After that, performing the OS Upgrade will be impossible.\n"
                "  --get-board-param <param name>[,<param>...]  Print value of a board param\n"
                "                                               Use <param name> as 'help' for details.\n"
+               "  --get-all-board-param                        Print value of all board params.\n"
                "  --set-board-param <param name>[,<param>...]  Set value of a board param\n"
                "                                               Use <param name> as 'help' for details.\n"
                "\n" ,my_name);
@@ -216,6 +226,132 @@ static int print_argument(struct arguments *args)
        return 0;
 }
 
+static int print_all_partition_status(const char *param_name, const char *description)
+{
+       char result_buffer[1024] = { 0, };
+       char input_buffer[1024] = { 0, };
+       char *partition[] = { "a", "b"};
+       int ret;
+
+       if (!param_name) {
+               ret = -EINVAL;
+               goto print_error;
+       }
+
+       if (!description) {
+               ret = -EINVAL;
+               goto print_error;
+       }
+
+       for (int i = 0; i < BOARD_AB_PARTITION_NUM; i++) {
+               ret = snprintf(input_buffer, sizeof(input_buffer), "%s,%s", param_name, partition[i]);
+               if (ret < 0) {
+                       goto print_error;
+               }
+
+               ret = board_params_getter_get_board_param(input_buffer,
+                               result_buffer, sizeof(result_buffer));
+               if (ret != 0) {
+                       goto print_error;
+               }
+
+               printf("%s: %s: %s\n", param_name, partition[i], result_buffer);
+
+               if (i != BOARD_AB_PARTITION_NUM - 1) {
+                       memset(input_buffer, 0, sizeof(input_buffer));
+                       memset(result_buffer, 0, sizeof(result_buffer));
+               }
+       }
+
+       return 0;
+
+print_error:
+       printf("Failed to get board param (%s): ret (%d)\n", param_name, ret);
+       printf("%s: %s\n", param_name, description);
+
+       return ret;
+}
+
+static int print_single_param(const char *param_name, const char *description)
+{
+       char result_buffer[1024] = { 0, };
+       int ret;
+
+       if (!param_name) {
+               ret = -EINVAL;
+               goto print_error;
+       }
+
+       if (!description) {
+               ret = -EINVAL;
+               goto print_error;
+       }
+
+       ret = board_params_getter_get_board_param(param_name,
+                       result_buffer, sizeof(result_buffer));
+       if (ret != 0) {
+               goto print_error;
+       }
+
+       printf("%s: %s\n", param_name, result_buffer);
+
+       return 0;
+
+print_error:
+       printf("Failed to get board param (%s): ret (%d)\n", param_name, ret);
+       printf("%s: %s\n", param_name, description);
+
+       return ret;
+}
+
+static int print_all_board_params(void)
+{
+       char param_name[1024] = { 0, };
+       char description[1024] = { 0, };
+       int ret;
+
+       for (board_params_e board_params = BOARD_PARAMS_BOOT_MODE;
+                       board_params < BOARD_PARAMS_MAX; board_params++) {
+               ret = board_params_getter_get_param_name(board_params,
+                               param_name, sizeof(param_name));
+               if (ret != 0)
+                       return ret;
+
+               if (strncmp(param_name, "none", strlen("none") + 1) == 0)
+                       continue;
+
+               ret = board_params_getter_get_description(board_params,
+                               description, sizeof(description));
+               if (ret != 0)
+                       return ret;
+
+               if (strncmp(description, "None", strlen("None") + 1) == 0)
+                       continue;
+
+               switch (board_params) {
+               case BOARD_PARAMS_BOOT_MODE:
+               case BOARD_PARAMS_CURRENT_PARTITION:
+               case BOARD_PARAMS_PARTITION_AB:
+               case BOARD_PARAMS_PARTITION_AB_CLONED:
+               case BOARD_PARAMS_UPGRADE_PROGRESS_STATUS:
+               case BOARD_PARAMS_UPGRADE_STATE:
+               case BOARD_PARAMS_UPGRADE_TYPE:
+                       ret = print_single_param(param_name, description);
+                       break;
+               case BOARD_PARAMS_PARTITION_STATUS:
+                       ret = print_all_partition_status(param_name, description);
+                       break;
+               default:
+                       assert(0);
+               }
+
+               if (ret != 0)
+                       return ret;
+       }
+
+       return 0;
+}
+
 int main(int argc, char **argv)
 {
        char result_buffer[1024] = { 0, };
@@ -241,6 +377,10 @@ int main(int argc, char **argv)
                return update_do_update(args.online);
 
        if (args.get_board_param) {
+               if (strncmp(args.board_param, BOARD_PARAMS_GETTER_ALL_BOARD_PARAM,
+                                       strlen(BOARD_PARAMS_GETTER_ALL_BOARD_PARAM) + 1) == 0)
+                       return print_all_board_params();
+
                ret = board_params_getter_get_board_param(args.board_param,
                                result_buffer, sizeof(result_buffer));
                if (ret == -EAGAIN)