Add new command to set/get partition status 07/274607/2
authorSangYoun Kwak <sy.kwak@samsung.com>
Tue, 3 May 2022 09:03:15 +0000 (18:03 +0900)
committerSangYoun Kwak <sy.kwak@samsung.com>
Wed, 4 May 2022 00:42:54 +0000 (09:42 +0900)
Change-Id: Idbbed070614b0d4438ad71a34f50c406e86f9c16
Signed-off-by: SangYoun Kwak <sy.kwak@samsung.com>
packaging/deviced.spec
tools/board/CMakeLists.txt
tools/board/get-partition-status.c [new file with mode: 0644]
tools/board/set-partition-status.c [new file with mode: 0644]
tools/board/switch-partition.c

index 4fdeb7a..378d02d 100644 (file)
@@ -330,6 +330,8 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so
 %attr(0554,system_fw,system_fw) %{_bindir}/device_board_set_partition_ab_cloned
 %attr(0554,system_fw,system_fw) %{_bindir}/device_board_clear_partition_ab_cloned
 %attr(0555,system_fw,system_fw) %{_bindir}/device_board_get_partition_ab_cloned
+%attr(0555,system_fw,system_fw) %{_bindir}/device_board_set_partition_status
+%attr(0555,system_fw,system_fw) %{_bindir}/device_board_get_partition_status
 %attr(0554,system_fw,system_fw) %{_bindir}/device_board_set_upgrade_status
 %attr(0555,system_fw,system_fw) %{_bindir}/device_board_get_upgrade_status
 
index 83c1d31..a87ccc0 100644 (file)
@@ -24,6 +24,8 @@ 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_get_partition_status get-partition-status.c)
+ADD_BOOT_EXECUTABLE(device_board_set_partition_status set-partition-status.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-partition-status.c b/tools/board/get-partition-status.c
new file mode 100644 (file)
index 0000000..20b6938
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * device-board-get-partition-status
+ *
+ * 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 <stdio.h>
+#include <hal/device/hal-board.h>
+
+int main(int argc, char *argv[])
+{
+       char buffer[1024] = { 0, };
+       char partition_ab;
+       int ret;
+
+       if (argc < 2) {
+               partition_ab = '\0';
+       } else {
+               partition_ab = argv[1][0];
+
+               if (partition_ab != 'a' && partition_ab != 'b') {
+                       goto err;
+               }
+       }
+
+       ret = hal_device_board_get_partition_status(partition_ab, buffer, sizeof(buffer));
+
+       if (ret < 0) {
+               goto err;
+       }
+
+       printf("%s\n", buffer);
+       return 0;
+
+err:
+       printf("FAILURE\n");
+       return 1;
+}
diff --git a/tools/board/set-partition-status.c b/tools/board/set-partition-status.c
new file mode 100644 (file)
index 0000000..467bae6
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * device-board-set-partition-status
+ *
+ * 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 <stdio.h>
+#include <string.h>
+#include <hal/device/hal-board.h>
+
+#define AVAILABLE_STATUS_NUM 3
+
+int main(int argc, char *argv[])
+{
+       const char *available_status[AVAILABLE_STATUS_NUM] = { "ok", "failed", "corrupted" };
+       const char *status;
+       int is_status_available;
+       char partition_ab;
+       int ret;
+
+       if (argc < 2) {
+               goto err;
+       } else if (argc == 2) {
+               partition_ab = '\0';
+               status = argv[1];
+       } else {
+               partition_ab = argv[1][0];
+               status = argv[2];
+
+               if (partition_ab != 'a' && partition_ab != 'b') {
+                       goto err;
+               }
+       }
+
+       is_status_available = 0;
+       for (int i = 0; i < AVAILABLE_STATUS_NUM; ++i) {
+               if (!strncmp(status, available_status[i], strlen(available_status[i]))) {
+                       is_status_available = 1;
+                       break;
+               }
+       }
+
+       if (!is_status_available) {
+               goto err;
+       }
+
+       ret = hal_device_board_set_partition_status(partition_ab, status);
+
+       if(ret < 0) {
+               goto err;
+       }
+
+       printf("SUCCESS\n");
+       return 0;
+
+err:
+       printf("FAILURE\n");
+       return 1;
+}
index 639a29f..0c7fa6f 100644 (file)
@@ -18,7 +18,6 @@
  */
 
 #include <stdio.h>
-#include <errno.h>
 #include <hal/device/hal-board.h>
 
 int main(int argc, char *argv[])