From e8362f58cb49df9b8392eb21624f51794384330c Mon Sep 17 00:00:00 2001 From: Mateusz Moscicki Date: Fri, 28 Jun 2024 12:28:35 +0200 Subject: [PATCH] osu: Add ability to set update type To perform an offline update use: osu --offline-update To perform an online update use: osu --online-update Option --update will perform an offline update. Change-Id: I16232e5025094db0484ad53dc022ab2b93d89319 Signed-off-by: Mateusz Moscicki Signed-off-by: SangYoun Kwak --- tools/osu/CMakeLists.txt | 11 +++++++++++ tools/osu/osu.c | 22 +++++++++++++++++----- tools/osu/update.c | 24 +++++++++++++++++++++++- tools/osu/update.h | 3 ++- 4 files changed, 53 insertions(+), 7 deletions(-) diff --git a/tools/osu/CMakeLists.txt b/tools/osu/CMakeLists.txt index 42f2cf2..da2727c 100644 --- a/tools/osu/CMakeLists.txt +++ b/tools/osu/CMakeLists.txt @@ -2,6 +2,17 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6) SET(OUTPUT_BIN_NAME osu) PROJECT(update-control-tools-${OUTPUT_BIN_NAME} C) +SET(PKG_MODULES + hal-api-device +) + +INCLUDE(FindPkgConfig) +pkg_check_modules(REQUIRED_PKGS REQUIRED ${PKG_MODULES}) + +FOREACH(flag ${REQUIRED_PKGS_CFLAGS}) + SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") +ENDFOREACH(flag) + INCLUDE_DIRECTORIES(. ${CMAKE_SOURCE_DIR}/include) FILE(GLOB_RECURSE SRCS osu.c resize.c update.c) diff --git a/tools/osu/osu.c b/tools/osu/osu.c index 2f35d72..524dbc3 100644 --- a/tools/osu/osu.c +++ b/tools/osu/osu.c @@ -30,6 +30,7 @@ struct arguments { bool resize; bool update; + bool online; }; static void print_help(char*); @@ -41,10 +42,13 @@ static int parse_args(int argc, char **argv, struct arguments *args) args->resize = false; args->update = false; + args->online = false; struct option long_options[] = { {"resize", no_argument, NULL, 'r'}, {"update", no_argument, NULL, 'u'}, + {"offline-update", no_argument, NULL, 'f'}, + {"online-update", no_argument, NULL, 'n'}, {"help", no_argument, NULL, 'h'}, {} }; @@ -56,10 +60,16 @@ static int parse_args(int argc, char **argv, struct arguments *args) args->resize = true; return 0; } - case 'u': { + case 'u': + case 'f': { args->update = true; return 0; } + case 'n': { + args->update = true; + args->online = true; + return 0; + } case 'h': { print_help(argv[0]); return 0; @@ -83,9 +93,11 @@ static void print_help(char *my_name) printf("Usage:\n" " %s [--help|--resize|--update]\n\n" "Possible arguments:\n" - " --help Print this help\n" - " --update Trigger the OS Upgrade\n" - " --resize Run resize2fs on the rootfs partition.\n" + " --help Print this help\n" + " --update Trigger the OS Upgrade (Offline Upgrade)\n" + " --offline-update Trigger the OS Offline Upgrade\n" + " --online-update Trigger the OS Online Upgrade\n" + " --resize Run resize2fs on the rootfs partition.\n" " After that, performing the OS Upgrade will be impossible.\n\n" ,my_name); } @@ -101,7 +113,7 @@ int main(int argc, char **argv) return do_resize(); if (args.update) - return do_update(); + return do_update(args.online); print_help(argv[0]); diff --git a/tools/osu/update.c b/tools/osu/update.c index 3df4c15..13bd7bd 100644 --- a/tools/osu/update.c +++ b/tools/osu/update.c @@ -2,12 +2,34 @@ #include "update_control.h" #include "update.h" +#include -int do_update(void) + +#define UPDATE_TYPE_ONLINE "online" +#define UPDATE_TYPE_OFFLINE "offline" + +int set_update_type(bool online) +{ + char *type; + if (online) { + type = UPDATE_TYPE_ONLINE; + } else { + type = UPDATE_TYPE_OFFLINE; + } + return hal_device_board_set_upgrade_type(type); +} + +int do_update(bool online) { int ret = 0; int ret_deinit = 0; + ret = set_update_type(online); + if (ret != 0) { + printf("Failed to set update type\n"); + return ret; + } + ret = update_control_initialize(); if (ret != UPDATE_CONTROL_ERROR_NONE) { printf("Failed to initialize: %d\n", ret); diff --git a/tools/osu/update.h b/tools/osu/update.h index 5c64bbc..df95c45 100644 --- a/tools/osu/update.h +++ b/tools/osu/update.h @@ -15,5 +15,6 @@ */ #pragma once +#include -int do_update(void); +int do_update(bool online); -- 2.34.1