From b8fd400089dbad1e1c06a9e62ee49142cc69a97b Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Wed, 30 Mar 2022 18:20:59 +0900 Subject: [PATCH] Add new commands for upgrade status and change params in switch command Change-Id: Ib9de10fd0609cfa1eaa631e01f2a5eff756ff933 Signed-off-by: SangYoun Kwak --- packaging/deviced.spec | 2 ++ tools/board/CMakeLists.txt | 3 ++ tools/board/get-upgrade-status.c | 33 +++++++++++++++++++++ tools/board/set-upgrade-status.c | 64 ++++++++++++++++++++++++++++++++++++++++ tools/board/switch-partition.c | 13 +++++++- 5 files changed, 114 insertions(+), 1 deletion(-) create mode 100644 tools/board/get-upgrade-status.c create mode 100644 tools/board/set-upgrade-status.c diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 22f93f2..1331169 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -323,6 +323,8 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %attr(2550,root,root) %{_bindir}/device_board_set_partition_ab_cloned %attr(2550,root,root) %{_bindir}/device_board_clear_partition_ab_cloned %attr(2555,root,root) %{_bindir}/device_board_get_partition_ab_cloned +%attr(2550,root,root) %{_bindir}/device_board_set_upgrade_status +%attr(2555,root,root) %{_bindir}/device_board_get_upgrade_status #endif %files auto-test diff --git a/tools/board/CMakeLists.txt b/tools/board/CMakeLists.txt index 1ebb56e..533901d 100644 --- a/tools/board/CMakeLists.txt +++ b/tools/board/CMakeLists.txt @@ -23,3 +23,6 @@ ADD_BOOT_EXECUTABLE(device_board_switch_partition switch-partition.c) ADD_BOOT_EXECUTABLE(device_board_clear_partition_ab_cloned clear-partition-ab-cloned.c) ADD_BOOT_EXECUTABLE(device_board_get_partition_ab_cloned get-partition-ab-cloned.c) ADD_BOOT_EXECUTABLE(device_board_set_partition_ab_cloned set-partition-ab-cloned.c) + +ADD_BOOT_EXECUTABLE(device_board_set_upgrade_status set-upgrade-status.c) +ADD_BOOT_EXECUTABLE(device_board_get_upgrade_status get-upgrade-status.c) diff --git a/tools/board/get-upgrade-status.c b/tools/board/get-upgrade-status.c new file mode 100644 index 0000000..bf3da64 --- /dev/null +++ b/tools/board/get-upgrade-status.c @@ -0,0 +1,33 @@ +/* + * device-board-get-boot-mode + * + * Copyright (c) 2022 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. + * + */ + +#include +#include + +int main(int argc, char *argv[]) +{ + int status; + int ret; + + ret = hal_device_board_get_upgrade_status(&status); + if (ret == 0) + printf("%d", status); + + return ret; +} diff --git a/tools/board/set-upgrade-status.c b/tools/board/set-upgrade-status.c new file mode 100644 index 0000000..22876d7 --- /dev/null +++ b/tools/board/set-upgrade-status.c @@ -0,0 +1,64 @@ +/* + * device-board-switch-partition + * + * Copyright (c) 2022 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. + * + */ + +#include +#include +#include + +#include + +static int parse_integer(const char *str, int *val) +{ + char *endptr = str; + long longval = 0; + + errno = 0; + longval = strtol(str, &endptr, 10); + + if(errno || *endptr) { + errno = 0; + return -EINVAL; + } + + if(longval > INT_MAX || longval < INT_MIN) { + return -EINVAL; + } + + *val = (int)longval; + + return 0; +} + +int main(int argc, char *argv[]) +{ + int status; + int parse_ret; + + if(argc < 2) { + return -EINVAL; + } + + parse_ret = parse_integer(argv[1], &status); + + if(parse_ret != 0) { + return -EINVAL; + } + + return hal_device_board_set_upgrade_status(argc, argv); +} diff --git a/tools/board/switch-partition.c b/tools/board/switch-partition.c index 6c8c580..bfdd5af 100644 --- a/tools/board/switch-partition.c +++ b/tools/board/switch-partition.c @@ -21,5 +21,16 @@ int main(int argc, char *argv[]) { - return hal_device_board_switch_partition(argc, argv); + char partition_ab; + + if(argc < 2) { + return -EINVAL; + } + + partition_ab = argv[1][0]; + if(partition_ab != 'a' && partition_ab != 'b') { + return -EINVAL; + } + + return hal_device_board_switch_partition(partition_ab); } -- 2.7.4