From 1646a7e44668b5a08a3f51cf0c97d77c2719a014 Mon Sep 17 00:00:00 2001 From: Unsung Lee Date: Thu, 19 Dec 2024 16:57:01 +0900 Subject: [PATCH] osu: Add an option to print all board params 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 --- packaging/update-control.spec | 2 +- tools/osu/osu.c | 140 ++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+), 1 deletion(-) diff --git a/packaging/update-control.spec b/packaging/update-control.spec index 42fc70b..f481805 100644 --- a/packaging/update-control.spec +++ b/packaging/update-control.spec @@ -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 diff --git a/tools/osu/osu.c b/tools/osu/osu.c index f9945af..7ebc3b0 100644 --- a/tools/osu/osu.c +++ b/tools/osu/osu.c @@ -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 [,...] Print value of a board param\n" " Use as 'help' for details.\n" + " --get-all-board-param Print value of all board params.\n" " --set-board-param [,...] Set value of a board param\n" " Use 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) -- 2.34.1