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);
{"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'},
{}
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;
" 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);
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, };
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)