Move print function of board parameters from board-params-getter and board-params-setter files to osu file.
Previously, it was responsible for the function of printing the board parameters
after the getting and setting them in board-params-getter/setter files.
In order to print the board parameter in osu file,
add get_param_name() and get_description() functions in board-params-getter/setter files
to get parameter name and description.
Additionally, in the process of moving the print function to the osu file,
the board-params.c file has been added for commonly used as getter/setter.
Change-Id: Idc66100b2b52af89ff92b8b43c0f3ce13c589e7d
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
board-params-getter.c
board-params-setter.c
board-params-util.c
+ board-params.c
)
ADD_EXECUTABLE(${OUTPUT_BIN_NAME} ${SRCS})
SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
return -1;
}
-static void print_board_param_getters(void)
+int board_params_getter_get_param_name(board_params_e board_params,
+ char *name, size_t name_size)
{
- printf("Available getter board params:\n");
- for (int i = 0; g_getters[i].param_name != NULL; ++i) {
- if (g_getters[i].getter == NULL)
- continue;
- printf(" %s: %s\n", g_getters[i].param_name, g_getters[i].description);
+ size_t board_param_name_size;
+
+ if (!board_params_is_valid_board_params(board_params)) {
+ printf("Failed to verify board param: enum board_params (%d)\n", board_params);
+ return -EINVAL;
+ }
+
+ if (g_getters[board_params].param_name == NULL) {
+ printf("Board parameter name is null\n");
+ return -EINVAL;
}
- printf("\n"
- " * Parameters should be provided separated with ','.\n"
- " * e.g. \"partition-status,a\"\n");
+ board_param_name_size = strlen (g_getters[board_params].param_name) + 1;
+ if (name_size < board_param_name_size) {
+ printf("Buffer is not enough to copy param name: src(%lu), dst(%lu)\n",
+ (unsigned long)board_param_name_size, (unsigned long)name_size);
+ return -EINVAL;
+ }
+
+ strncpy(name, g_getters[board_params].param_name, name_size - 1);
+
+ return 0;
}
-int board_params_getter_get_board_param(const char *params_str)
+int board_params_getter_get_description(board_params_e board_params,
+ char *description, size_t description_size)
+{
+ size_t board_param_description_size;
+
+ if (!board_params_is_valid_board_params(board_params)) {
+ printf("Failed to verify board param: enum board_params (%d)\n", board_params);
+ return -EINVAL;
+ }
+
+ if (g_getters[board_params].description == NULL) {
+ printf("Board parameter description is null\n");
+ return -EINVAL;
+ }
+
+ board_param_description_size = strlen (g_getters[board_params].description) + 1;
+ if (description_size < board_param_description_size) {
+ printf("Buffer is not enough to copy param description: src(%lu), dst(%lu)\n",
+ (unsigned long)board_param_description_size, (unsigned long)description_size);
+ return -EINVAL;
+ }
+
+ strncpy(description, g_getters[board_params].description, description_size - 1);
+
+ return 0;
+}
+
+int board_params_getter_get_board_param(const char *params_str,
+ char *result_buffer, size_t buffer_size)
{
int ret = 0;
char *params_str_dup = NULL;
struct board_param_getter *board_param_getter = NULL;
- char result_buffer[1024] = { 0, };
char *params[BOARD_PARAM_PARAMS_LEN] = { NULL, };
size_t params_len = BOARD_PARAM_PARAMS_LEN;
param_name = params[0];
if (strncmp(param_name, "help", sizeof("help")) == 0) {
- print_board_param_getters();
- ret = 0;
+ ret = -EAGAIN;
goto release_and_exit;
}
ret = get_board_param_getter(param_name, &board_param_getter);
if (ret != 0) {
printf("Invalid board param: %s\n", params_str);
- print_board_param_getters();
+ ret = -EAGAIN;
goto release_and_exit;
}
- ret = (board_param_getter->getter)(params + 1, params_len - 1, result_buffer, sizeof(result_buffer));
+ ret = (board_param_getter->getter)(params + 1, params_len - 1, result_buffer, buffer_size);
if (ret != 0) {
printf("Failed to get board param %s: %d\n", param_name, ret);
printf("%s: %s\n", param_name, board_param_getter->description);
goto release_and_exit;
}
- ret = 0;
- printf("%s\n", result_buffer);
-
release_and_exit:
free(params_str_dup);
#pragma once
-int board_params_getter_get_board_param(const char *param_name);
+#include "board-params.h"
+
+int board_params_getter_get_param_name(board_params_e board_params,
+ char *name, size_t name_size);
+int board_params_getter_get_description(board_params_e board_params,
+ char *description, size_t description_size);
+int board_params_getter_get_board_param(const char *params_str,
+ char *result_buffer, size_t buffer_size);
return -1;
}
-static void print_board_param_setters(void)
+int board_params_setter_get_param_name(board_params_e board_params,
+ char *name, size_t name_size)
{
- printf("Available board params:\n");
- for (int i = 0; g_setters[i].param_name != NULL; ++i) {
- if (g_setters[i].setter == NULL)
- continue;
- printf(" %s: %s\n", g_setters[i].param_name, g_setters[i].description);
+ size_t board_param_name_size;
+
+ if (!board_params_is_valid_board_params(board_params)) {
+ printf("Failed to verify board param: enum board_params (%d)\n", board_params);
+ return -EINVAL;
+ }
+
+ if (g_setters[board_params].param_name == NULL) {
+ printf("Board parameter name is null\n");
+ return -EINVAL;
+ }
+
+ board_param_name_size = strlen (g_setters[board_params].param_name) + 1;
+ if (name_size < board_param_name_size) {
+ printf("Buffer is not enough to copy param name: src(%lu), dst(%lu)\n",
+ (unsigned long)board_param_name_size, (unsigned long)name_size);
+ return -EINVAL;
}
- printf("\n"
- " * Parameters should be provided separated with ','.\n"
- " * e.g. \"upgrade_progress_status,100\"\n");
+ strncpy(name, g_setters[board_params].param_name, name_size - 1);
+
+ return 0;
+}
+
+int board_params_setter_get_description(board_params_e board_params,
+ char *description, size_t description_size)
+{
+ size_t board_param_description_size;
+
+ if (!board_params_is_valid_board_params(board_params)) {
+ printf("Failed to verify board param: enum board_params (%d)\n", board_params);
+ return -EINVAL;
+ }
+
+ if (g_setters[board_params].description == NULL) {
+ printf("Board parameter description is null\n");
+ return -EINVAL;
+ }
+
+ board_param_description_size = strlen (g_setters[board_params].description) + 1;
+ if (description_size < board_param_description_size) {
+ printf("Buffer is not enough to copy param description: src(%lu), dst(%lu)\n",
+ (unsigned long)board_param_description_size, (unsigned long)description_size);
+ return -EINVAL;
+ }
+
+ strncpy(description, g_setters[board_params].description, description_size - 1);
+
+ return 0;
}
int board_params_setter_set_board_param(const char *params_str)
param_name = params[0];
if (strncmp(param_name, "help", sizeof("help")) == 0) {
- print_board_param_setters();
- ret = 0;
+ ret = -EAGAIN;
goto release_and_exit;
}
ret = get_board_param_setter(param_name, &board_param_setter);
if (ret != 0) {
printf("Invalid parameter(s): %s\n", param_name);
- print_board_param_setters();
+ ret = -EAGAIN;
goto release_and_exit;
}
goto release_and_exit;
}
- printf("Success\n");
-
release_and_exit:
free(params_str_dup);
#pragma once
+#include "board-params.h"
+
+int board_params_setter_get_param_name(board_params_e board_params,
+ char *name, size_t name_size);
+int board_params_setter_get_description(board_params_e board_params,
+ char *description, size_t description_size);
int board_params_setter_set_board_param(const char *param_name);
--- /dev/null
+/*
+ * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ *
+ * OSU is a tool to support Tizen OS Upgrade testing and development
+ *
+ */
+
+#include <stdbool.h>
+
+#include "board-params.h"
+
+bool board_params_is_valid_board_params(board_params_e board_params)
+{
+ 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_PARTITION_STATUS:
+ case BOARD_PARAMS_UPGRADE_PROGRESS_STATUS:
+ case BOARD_PARAMS_UPGRADE_STATE:
+ case BOARD_PARAMS_UPGRADE_TYPE:
+ return true;
+ default:
+ return false;
+ }
+}
#pragma once
-#include "board-params-getter.h"
-#include "board-params-setter.h"
+#include <stdbool.h>
typedef enum {
BOARD_PARAMS_BOOT_NONE = -1,
BOARD_PARAMS_UPGRADE_TYPE,
BOARD_PARAMS_MAX,
} board_params_e;
+
+bool board_params_is_valid_board_params(board_params_e board_params);
#include <stdbool.h>
#include <getopt.h>
#include <assert.h>
+#include <string.h>
+#include <errno.h>
#include "resize.h"
#include "update.h"
#include "board-params.h"
-
+#include "board-params-getter.h"
+#include "board-params-setter.h"
struct arguments {
bool help;
"\n" ,my_name);
}
+static int print_board_param_getters(void)
+{
+ char param_name[1024] = { 0, };
+ char description[1024] = { 0, };
+ int ret;
+
+ printf("Available getter board params:\n");
+ 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;
+
+ printf(" %s: %s\n", param_name, description);
+ }
+
+ printf("\n"
+ " * Parameters should be provided separated with ','.\n"
+ " * e.g. \"partition-status,a\"\n\n");
+
+ return 0;
+}
+
+static int print_board_param_setters(void)
+{
+ char param_name[1024] = { 0, };
+ char description[1024] = { 0, };
+ int ret;
+
+ printf("Available setter board params:\n");
+ for (board_params_e board_params = BOARD_PARAMS_BOOT_MODE;
+ board_params < BOARD_PARAMS_MAX; board_params++) {
+ ret = board_params_setter_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_setter_get_description(board_params,
+ description, sizeof(description));
+ if (ret != 0)
+ return ret;
+
+ if (strncmp(description, "None", strlen("None") + 1) == 0)
+ continue;
+
+ printf(" %s: %s\n", param_name, description);
+ }
+
+ printf("\n"
+ " * Parameters should be provided separated with ','.\n"
+ " * e.g. \"upgrade_progress_status,100\"\n\n");
+
+ return 0;
+}
+
+static int print_argument(struct arguments *args)
+{
+ if (args == NULL)
+ return -EINVAL;
+
+ if (args->get_board_param) {
+ print_board_param_getters();
+ }
+
+ if (args->set_board_param) {
+ print_board_param_setters();
+ }
+
+ return 0;
+}
+
int main(int argc, char **argv)
{
+ char result_buffer[1024] = { 0, };
struct arguments args;
+ int ret = 0;
if (parse_args(argc, argv, &args) != 0) {
return 1;
if (args.update)
return update_do_update(args.online);
- if (args.get_board_param)
- return board_params_getter_get_board_param(args.board_param);
+ if (args.get_board_param) {
+ ret = board_params_getter_get_board_param(args.board_param,
+ result_buffer, sizeof(result_buffer));
+ if (ret == -EAGAIN)
+ return print_argument(&args);
- if (args.set_board_param)
- return board_params_setter_set_board_param(args.board_param);
+ if (ret != 0)
+ return ret;
+
+ printf("%s\n", result_buffer);
+
+ return 0;
+ }
+
+ if (args.set_board_param) {
+ ret = board_params_setter_set_board_param(args.board_param);
+ if (ret == -EAGAIN)
+ return print_argument(&args);
+
+ if (ret != 0)
+ return ret;
+
+ printf("Success\n");
+
+ return 0;
+ }
print_help(argv[0]);