From e021542a3270c05d42d1c9b0bca2f0f183344003 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 8 Mar 2022 11:44:56 +0900 Subject: [PATCH 01/16] battery: suppress config parse error Do not consider encounter of a section that we are not intersted in as an error, because several new sections have been added recently. Change-Id: I9d3f3d6a5dd6e14ca0478ed6f661e39a7519cd46 Signed-off-by: Youngjae Cho --- src/battery/config.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/battery/config.c b/src/battery/config.c index 7c5ca10..1595040 100644 --- a/src/battery/config.c +++ b/src/battery/config.c @@ -40,13 +40,13 @@ static int load_config(struct parse_result *result, void *user_data) char *name; char *value; - _D("Load config. section=%s name=%s value=%s", result->section, result->name, result->value); - if (!info) return -EINVAL; if (!MATCH(result->section, "BatteryLevelThreshold")) - return -EINVAL; + return 0; + + _D("Load config. section=%s name=%s value=%s", result->section, result->name, result->value); name = result->name; value = result->value; -- 2.7.4 From 0bd46b2a3a4b46dcf25d9eeca6d190c346ea76c7 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 14 Mar 2022 11:01:37 +0900 Subject: [PATCH 02/16] battery: fix name of battery charging state Change-Id: Ide4c233bf2c69ffdec270622a5d23736cfb661e4 Signed-off-by: Youngjae Cho --- src/battery/lowbat-handler.c | 6 ++--- src/battery/power-supply.c | 50 +++++++++++++++++------------------ src/battery/power-supply.h | 14 +++++----- tests/auto-test/battery.c | 62 ++++++++++++++++++++++---------------------- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/src/battery/lowbat-handler.c b/src/battery/lowbat-handler.c index 56a4959..7358f40 100644 --- a/src/battery/lowbat-handler.c +++ b/src/battery/lowbat-handler.c @@ -737,7 +737,7 @@ static void lowbat_exit(void *data) } } -static gboolean low_battery_charge_status(void *data) +static gboolean low_battery_charging_status(void *data) { low_batt_sig_timer = 0; battery->charging_level = lowbat_monitor(data); @@ -768,9 +768,9 @@ static int lowbat_execute(void *data) * This prevents poweroff from being delayed infinitely when the uevent continues * to occur shorter than 1.5 seconds on realoff capacity */ if (capacity <= battery_info.realoff || !uevent_buffering) - low_battery_charge_status(data); + low_battery_charging_status(data); else - low_batt_sig_timer = g_timeout_add(1500, low_battery_charge_status, data); + low_batt_sig_timer = g_timeout_add(1500, low_battery_charging_status, data); return 0; } diff --git a/src/battery/power-supply.c b/src/battery/power-supply.c index 08f00cd..ace82a3 100644 --- a/src/battery/power-supply.c +++ b/src/battery/power-supply.c @@ -400,14 +400,14 @@ static void charger_state_send_system_event(int state) const char *str; switch (state) { - case CHARGE_STATUS_CHARGING: + case CHARGING_STATUS_CHARGING: str = EVT_VAL_BATTERY_CHARGER_CHARGING; break; - case CHARGE_STATUS_FULL: + case CHARGING_STATUS_FULL: str = EVT_VAL_BATTERY_CHARGER_DISCHARGING; CRITICAL_LOG("Battery charger: %s", str); break; - case CHARGE_STATUS_DISCHARGING: + case CHARGING_STATUS_DISCHARGING: str = EVT_VAL_BATTERY_CHARGER_DISCHARGING; CRITICAL_LOG("Battery charger: %s", str); break; @@ -546,7 +546,7 @@ static void check_abnormal_status(void) } } -static void check_charge_status(const char *env_value) +static void check_charging_status(const char *env_value) { int len; @@ -555,26 +555,26 @@ static void check_charge_status(const char *env_value) len = strlen(env_value); if (strncmp(env_value, CHARGEFULL_NAME, len) == 0) - battery.charge_status = CHARGE_STATUS_FULL; + battery.charging_status = CHARGING_STATUS_FULL; else if (strncmp(env_value, CHARGENOW_NAME, len) == 0) - battery.charge_status = CHARGE_STATUS_CHARGING; + battery.charging_status = CHARGING_STATUS_CHARGING; else if (strncmp(env_value, DISCHARGE_NAME, len) == 0) - battery.charge_status = CHARGE_STATUS_DISCHARGING; + battery.charging_status = CHARGING_STATUS_DISCHARGING; else if (strncmp(env_value, NOTCHARGE_NAME, len) == 0) - battery.charge_status = CHARGE_STATUS_NOT_CHARGING; + battery.charging_status = CHARGING_STATUS_NOT_CHARGING; else - battery.charge_status = CHARGE_STATUS_UNKNOWN; + battery.charging_status = CHARGING_STATUS_UNKNOWN; - if (battery.charge_status == CHARGE_STATUS_FULL) { + if (battery.charging_status == CHARGING_STATUS_FULL) { battery.charge_full = CHARGING_FULL; battery.charge_now = CHARGER_DISCHARGING; - } else if (battery.charge_status == CHARGE_STATUS_CHARGING) { + } else if (battery.charging_status == CHARGING_STATUS_CHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_CHARGING; - } else if (battery.charge_status == CHARGE_STATUS_DISCHARGING) { + } else if (battery.charging_status == CHARGING_STATUS_DISCHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_DISCHARGING; - } else if (battery.charge_status == CHARGE_STATUS_NOT_CHARGING) { + } else if (battery.charging_status == CHARGING_STATUS_NOT_CHARGING) { battery.charge_full = CHARGING_NOT_FULL; battery.charge_now = CHARGER_ABNORMAL; } else { @@ -769,8 +769,8 @@ static void process_power_supply(void *data) } } - if (old_battery.charge_status != battery.charge_status) - charger_state_send_system_event(battery.charge_status); + if (old_battery.charging_status != battery.charging_status) + charger_state_send_system_event(battery.charging_status); if (old_battery.online_type != battery.online_type) { ret_val = vconf_set_int(VCONFKEY_SYSMAN_CHARGER_TYPE, battery.online_type); @@ -815,7 +815,7 @@ static void process_power_supply(void *data) old_battery.charging_level = battery.charging_level; old_battery.charger_connected = battery.charger_connected; old_battery.online_type = battery.online_type; - old_battery.charge_status = battery.charge_status; + old_battery.charging_status = battery.charging_status; old_battery.charge_full = battery.charge_full; old_battery.misc = battery.misc; @@ -869,7 +869,7 @@ static void uevent_power_handler(struct udev_device *dev) return; env_value = udev_device_get_property_value(dev, CHARGE_STATUS); - check_charge_status(env_value); + check_charging_status(env_value); env_value = udev_device_get_property_value(dev, CHARGE_ONLINE); check_online_type(env_value); env_value = udev_device_get_property_value(dev, CHARGE_HEALTH); @@ -913,7 +913,7 @@ static int battery_state(struct battery_info *info) } if (battery.capacity != 0 && prev_status.capacity == battery.capacity && - prev_status.charge_status == battery.charge_status && + prev_status.charging_status == battery.charging_status && prev_status.online_type == battery.online_type && prev_status.charge_full == battery.charge_full && prev_status.charge_now == battery.charge_now && @@ -924,7 +924,7 @@ static int battery_state(struct battery_info *info) return 0; prev_status.capacity = battery.capacity; - prev_status.charge_status = battery.charge_status; + prev_status.charging_status = battery.charging_status; prev_status.charge_full = battery.charge_full; prev_status.charge_now = battery.charge_now; prev_status.health = battery.health; @@ -987,7 +987,7 @@ static void battery_changed(struct battery_info *info, void *data) if (info->status) { snprintf(battery.status_s, sizeof(battery.status_s), "%s", info->status); - check_charge_status(info->status); + check_charging_status(info->status); } else battery.status_s[0] = '\0'; @@ -1022,11 +1022,11 @@ static void battery_changed(struct battery_info *info, void *data) ret_val = delayed_init_done(NULL); if (ret_val) { /* If the same notification is requested repeatedly, it is ignored by power_supply_noti(). - * A notification will be triggered only when charge_status changes between - * CHARGE_STATUS_CHARGING/FULL <-> CHARGE_STATUS_DISCHARGING. */ - if (battery.charge_status == CHARGE_STATUS_CHARGING || battery.charge_status == CHARGE_STATUS_FULL) + * A notification will be triggered only when charging_status changes between + * CHARGING_STATUS_CHARGING/FULL <-> CHARGING_STATUS_DISCHARGING. */ + if (battery.charging_status == CHARGING_STATUS_CHARGING || battery.charging_status == CHARGING_STATUS_FULL) power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_ON); - else if (battery.charge_status == CHARGE_STATUS_DISCHARGING) + else if (battery.charging_status == CHARGING_STATUS_DISCHARGING) power_supply_noti(DEVICE_NOTI_BATT_CHARGE, DEVICE_NOTI_OFF); } @@ -1257,7 +1257,7 @@ static GVariant *dbus_get_power_supply_handler(GDBusConnection *conn, return g_variant_new("(iiiiiiiisiiiii)", 0, battery.capacity, - battery.charge_status, + battery.charging_status, battery.health, battery.charger_connected, battery.present, diff --git a/src/battery/power-supply.h b/src/battery/power-supply.h index 547a2d2..1350299 100644 --- a/src/battery/power-supply.h +++ b/src/battery/power-supply.h @@ -30,12 +30,12 @@ enum device_change_type { DEVICE_CHANGE_NORMAL, }; -enum charge_status_type { - CHARGE_STATUS_UNKNOWN, - CHARGE_STATUS_CHARGING, - CHARGE_STATUS_DISCHARGING, - CHARGE_STATUS_NOT_CHARGING, - CHARGE_STATUS_FULL, +enum charging_status_type { + CHARGING_STATUS_UNKNOWN, + CHARGING_STATUS_CHARGING, + CHARGING_STATUS_DISCHARGING, + CHARGING_STATUS_NOT_CHARGING, + CHARGING_STATUS_FULL, }; enum charge_full_type { @@ -94,7 +94,7 @@ enum charger_type { struct battery_status { int capacity; - int charge_status; + int charging_status; int charge_full; int charge_now; int health; diff --git a/tests/auto-test/battery.c b/tests/auto-test/battery.c index 14b3964..e245b64 100644 --- a/tests/auto-test/battery.c +++ b/tests/auto-test/battery.c @@ -101,12 +101,12 @@ #define S_ENTER 1 #define S_LEAVE 0 -enum charge_status_type { - CHARGE_STATUS_UNKNOWN, - CHARGE_STATUS_CHARGING, - CHARGE_STATUS_DISCHARGING, - CHARGE_STATUS_NOT_CHARGING, - CHARGE_STATUS_FULL, +enum charging_status_type { + CHARGING_STATUS_UNKNOWN, + CHARGING_STATUS_CHARGING, + CHARGING_STATUS_DISCHARGING, + CHARGING_STATUS_NOT_CHARGING, + CHARGING_STATUS_FULL, }; enum charge_now_type { @@ -135,7 +135,7 @@ static struct power_supply_type { const char *scenario; const int status; const char *capacity; - const char *charge_status; + const char *charging_status; const char *health; const int online; const char *present; @@ -445,7 +445,7 @@ static bool get_battery_info_direct(struct device_battery_info *info) return capi_result(METHOD_BATTERY_GETINFO_DIRECT, ret); } -static int change_charge_status_to_enum(const char *env_value) +static int change_charging_status_to_enum(const char *env_value) { int len, ret; @@ -454,15 +454,15 @@ static int change_charge_status_to_enum(const char *env_value) len = strlen(env_value); if (strncmp(env_value, CHARGEFULL, len) == 0) - ret = CHARGE_STATUS_FULL; + ret = CHARGING_STATUS_FULL; else if (strncmp(env_value, CHARGENOW, len) == 0) - ret = CHARGE_STATUS_CHARGING; + ret = CHARGING_STATUS_CHARGING; else if (strncmp(env_value, DISCHARGE, len) == 0) - ret = CHARGE_STATUS_DISCHARGING; + ret = CHARGING_STATUS_DISCHARGING; else if (strncmp(env_value, NOTCHARGE, len) == 0) - ret = CHARGE_STATUS_NOT_CHARGING; + ret = CHARGING_STATUS_NOT_CHARGING; else - ret = CHARGE_STATUS_UNKNOWN; + ret = CHARGING_STATUS_UNKNOWN; return ret; } @@ -492,7 +492,7 @@ static int change_health_status_to_enum(const char *env_value) static bool compare_vconf(struct power_supply_type list) { int value, ret, temp; - int capacity, online, charge_status; + int capacity, online, charging_status; int invalid; invalid = (strcmp(list.present, PRESENT_ABNORMAL) == 0); @@ -504,22 +504,22 @@ static bool compare_vconf(struct power_supply_type list) } if (invalid) { - charge_status = CHARGE_STATUS_NOT_CHARGING; + charging_status = CHARGING_STATUS_NOT_CHARGING; temp = -ENODEV; - } else if (!strcmp(list.charge_status, CHARGEFULL)) { - charge_status = CHARGE_STATUS_FULL; + } else if (!strcmp(list.charging_status, CHARGEFULL)) { + charging_status = CHARGING_STATUS_FULL; temp = CHARGER_DISCHARGING; - } else if (!strcmp(list.charge_status, CHARGENOW)) { - charge_status = CHARGE_STATUS_CHARGING; + } else if (!strcmp(list.charging_status, CHARGENOW)) { + charging_status = CHARGING_STATUS_CHARGING; temp = CHARGER_CHARGING; - } else if (!strcmp(list.charge_status, DISCHARGE)) { - charge_status = CHARGE_STATUS_DISCHARGING; + } else if (!strcmp(list.charging_status, DISCHARGE)) { + charging_status = CHARGING_STATUS_DISCHARGING; temp = CHARGER_DISCHARGING; - } else if (!strcmp(list.charge_status, NOTCHARGE)) { - charge_status = CHARGE_STATUS_NOT_CHARGING; + } else if (!strcmp(list.charging_status, NOTCHARGE)) { + charging_status = CHARGING_STATUS_NOT_CHARGING; temp = CHARGER_ABNORMAL; } else { - charge_status = CHARGE_STATUS_UNKNOWN; + charging_status = CHARGING_STATUS_UNKNOWN; temp = CHARGER_DISCHARGING; } @@ -538,7 +538,7 @@ static bool compare_vconf(struct power_supply_type list) if (invalid) { temp = -ENODEV; } else if (capacity <= DEFAULT_REALOFF) { - if (charge_status == CHARGE_STATUS_CHARGING) + if (charging_status == CHARGING_STATUS_CHARGING) temp = VCONFKEY_SYSMAN_BAT_POWER_OFF; else temp = VCONFKEY_SYSMAN_BAT_REAL_POWER_OFF; @@ -549,7 +549,7 @@ static bool compare_vconf(struct power_supply_type list) } else if (capacity <= DEFAULT_WARNING) { temp = VCONFKEY_SYSMAN_BAT_WARNING_LOW; } else if (capacity >= DEFAULT_NORMAL && - charge_status == CHARGE_STATUS_FULL) { + charging_status == CHARGING_STATUS_FULL) { temp = VCONFKEY_SYSMAN_BAT_FULL; } else { temp = VCONFKEY_SYSMAN_BAT_NORMAL; @@ -629,8 +629,8 @@ static bool compare_power_supply(struct power_supply_type list, int value[], con return false; } - if (change_charge_status_to_enum(list.charge_status) != value[1]) { - _E("Different charge_status : %d %d", change_charge_status_to_enum(list.charge_status), value[1]); + if (change_charging_status_to_enum(list.charging_status) != value[1]) { + _E("Different charging_status : %d %d", change_charging_status_to_enum(list.charging_status), value[1]); return false; } @@ -696,7 +696,7 @@ static bool set_battery_power_supply(int index) var = g_variant_new("(sisssisssssssss)", POWER_SUBSYSTEM, 13, power_supply_types[index].capacity, - power_supply_types[index].charge_status, + power_supply_types[index].charging_status, power_supply_types[index].health, power_supply_types[index].online, power_supply_types[index].present, @@ -711,7 +711,7 @@ static bool set_battery_power_supply(int index) _I("C(%s) S(%s) H(%s) O(%d) P(%s) M(%s) F(%s) SRC(%s) Vol(%s %s) Cur(%s %s) T(%s)", power_supply_types[index].capacity, - power_supply_types[index].charge_status, + power_supply_types[index].charging_status, power_supply_types[index].health, power_supply_types[index].online, power_supply_types[index].present, @@ -767,7 +767,7 @@ static bool get_battery_power_supply(int out_rsp[], char **out_power_source) if (!g_variant_get_safe(reply, "(iiiiiiiisiiiii)", &reply_val, //return value &out_rsp[0], //capacity - &out_rsp[1], //charge_status + &out_rsp[1], //charging_status &out_rsp[2], //health &out_rsp[3], //online &out_rsp[4], //present -- 2.7.4 From 501f642b1f0517310744f24998fecf4416559db5 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Mon, 14 Mar 2022 14:32:36 +0900 Subject: [PATCH 03/16] Support silent boot via cmdline bootmode The /proc/cmdline has changed to have bootmode=silent parameter on silent booting. Change-Id: I15ebb44bdd86155fc1a65489e23ec527fd9cbf86 Signed-off-by: Youngjae Cho --- src/core/main.c | 8 ++++++-- tests/auto-test/boot.c | 32 +++++++++++++++++++++++++------- tests/auto-test/test.c | 15 --------------- tests/auto-test/test.h | 3 +-- 4 files changed, 32 insertions(+), 26 deletions(-) diff --git a/src/core/main.c b/src/core/main.c index fa1e4a1..ecbf942 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include #include "display/core.h" @@ -99,6 +99,8 @@ static int deviced_main(int argc, char **argv) int ret; dbus_handle_h handle = NULL; guint timer; + char bootmode[32] = "normal"; + int retval; CRITICAL_LOG("Initializing deviced."); mainloop = g_main_loop_new(NULL, FALSE); @@ -118,7 +120,9 @@ static int deviced_main(int argc, char **argv) load_plugins(); - silent_boot = device_get_reboot_mode(); + retval = device_board_get_boot_mode(bootmode, sizeof(bootmode)); + silent_boot = (retval == 0 && strncmp(bootmode, "silent", sizeof("silent")) == 0); + CRITICAL_LOG("bootmode=%s", bootmode); devices_init(NULL); diff --git a/tests/auto-test/boot.c b/tests/auto-test/boot.c index d589f8c..26f7193 100644 --- a/tests/auto-test/boot.c +++ b/tests/auto-test/boot.c @@ -16,17 +16,35 @@ * limitations under the License. */ #include "test.h" -#include +#include #define METHOD_GET_REBOOT_MODE "GetRebootMode" -static bool get_reboot_mode(void) +static bool get_boot_mode(void) { - int ret; + int retval; + char bootmode[32] = {0, }; - ret = device_get_reboot_mode(); + retval = device_board_get_boot_mode(bootmode, sizeof(bootmode)); + if (retval != 0) { + _E("bootmode not supported."); + return 1; + } + + if (strncmp(bootmode, "normal", sizeof("normal")) == 0) + return 1; + if (strncmp(bootmode, "silent", sizeof("silent")) == 0) + return 1; + if (strncmp(bootmode, "fota", sizeof("fota")) == 0) + return 1; + if (strncmp(bootmode, "recovery", sizeof("recovery")) == 0) + return 1; + if (strncmp(bootmode, "download", sizeof("download")) == 0) + return 1; - return capi_reboot_result(METHOD_GET_REBOOT_MODE, ret); + _E("Invalid bootmode=%s", bootmode); + + return 0; } static void booting_test_all(int *success, int *fail) @@ -34,7 +52,7 @@ static void booting_test_all(int *success, int *fail) int s = 0; int f = 0; - (get_reboot_mode()) ? s++ : f++; + (get_boot_mode()) ? s++ : f++; if (NULL != success) *success = s; if (NULL != fail) *fail = f; @@ -67,7 +85,7 @@ static int booting_unit(int argc, char **argv) booting_test_all(&success, &fail); _I("Total: %d, Success: %d, Fail: %d", success+fail, success, fail); } else if (0 == strcasecmp(argv[3], METHOD_GET_REBOOT_MODE)) { - get_reboot_mode(); + get_boot_mode(); } else { _E("Unknown test case!!!"); } diff --git a/tests/auto-test/test.c b/tests/auto-test/test.c index f50faf1..142310a 100644 --- a/tests/auto-test/test.c +++ b/tests/auto-test/test.c @@ -146,18 +146,3 @@ bool capi_result(const char *method, int val) return ret; } - -bool capi_reboot_result(const char *method, int val) -{ - bool ret = FALSE; - - if (val == NORMAL_BOOT || val == SILENT_BOOT) { - _I("success (%s): %d", method, val); - ret = TRUE; - } else { - _E("fail (%s): returned fail (%d)", method, val); - ret = FALSE; - } - - return ret; -} diff --git a/tests/auto-test/test.h b/tests/auto-test/test.h index 0ba59c6..ef10f18 100644 --- a/tests/auto-test/test.h +++ b/tests/auto-test/test.h @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include "shared/common.h" #include "core/udev.h" @@ -107,6 +107,5 @@ const struct test_ops *find_test(const char *name); void _R(const char *format, ...); void __cb(GVariant *result, void *data, GError *err); bool capi_result(const char *method, int val); -bool capi_reboot_result(const char *method, int val); int feature_supported(const char *feature); #endif -- 2.7.4 From f596affda397bc4f21d05eeb32d2b294227fe39a Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Wed, 16 Mar 2022 17:25:33 +0900 Subject: [PATCH 04/16] usb-gadget: introduce configurable usb-gadget Change-Id: Iaf2adf68666b1def8dcf6b04707d0f5a3f5fc3e0 Signed-off-by: Youngjae Cho --- src/usb/usb-state.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++-- src/usb/usb.c | 1 + src/usb/usb.h | 2 + 3 files changed, 183 insertions(+), 4 deletions(-) diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c index 17df193..77375c6 100644 --- a/src/usb/usb-state.c +++ b/src/usb/usb-state.c @@ -17,10 +17,12 @@ */ +#include #include #include #include #include +#include #include "core/log.h" #include "apps/apps.h" @@ -29,6 +31,8 @@ #include "usb.h" #include "usb-debug.h" +#define PATH_USB_GADGET_CONF "/hal/etc/deviced/usb_gadget.conf" + static int noti_id = -1; static unsigned int usb_current_mode = USB_FUNCTION_NONE; @@ -49,6 +53,7 @@ static extcon_usb_state_e usb_connection = USB_DISCONNECTED; static const struct _usb_mode_mapping_table { int mode_v; /* Integer defined by vconf */ unsigned int mode; /* Bitmap of usb function combination */ + struct usb_gadget_attrs attrs; } usb_mode_mapping_table[] = { /* Hack for performance. In most cases this is the value. */ {SET_USB_DEFAULT, USB_FUNCTION_MTP | USB_FUNCTION_ACM}, @@ -68,12 +73,43 @@ static const struct _usb_mode_mapping_table { {SET_USB_RNDIS_SDB_ACM, USB_FUNCTION_ACM | USB_FUNCTION_SDB | USB_FUNCTION_RNDIS}, }; +static const int mapping_table_len = sizeof(usb_mode_mapping_table) / sizeof(usb_mode_mapping_table[0]); + +/* + * Private, custom defined mode mapping. + * You can define custom mode_v with mode from /hal/etc/deviced/usb_gadget.conf + * A custom mapping precedes the above default mapping if the custom mode_v overlaps + * default mode_v. + * + * Do not declare it with static storage class as it will be exported as dynamic symbol + * so that dlopen-ed device-common can refer it. + */ +GList *usb_mode_mapping_table_custom; + +/* + * Do not declare it with static storage class as it will be exported as dynamic symbol + * so that dlopen-ed device-common can refer it. + */ +struct service_config { + char name[128]; + int remain_after_disable; /* do not stop the service on disabling usb-gadget function */ +}; +GList *service_config_list; + unsigned int get_mode_bitmap_from_vconf(int mode_v) { int i; - int array_len = sizeof(usb_mode_mapping_table)/sizeof(usb_mode_mapping_table[0]); + GList *elem; + struct _usb_mode_mapping_table *table; + + /* lookup from custom mapping table first */ + SYS_G_LIST_FOREACH(usb_mode_mapping_table_custom, elem, table) { + if (table->mode_v == mode_v) + return table->mode; + } - for (i = 0; i < array_len; i++) { + /* and then lookup the default mapping table */ + for (i = 0; i < mapping_table_len; i++) { if (usb_mode_mapping_table[i].mode_v == mode_v) return usb_mode_mapping_table[i].mode; } @@ -84,10 +120,17 @@ unsigned int get_mode_bitmap_from_vconf(int mode_v) static int get_mode_vconf_from_bitmap(unsigned int mode) { int i; - int array_len = sizeof(usb_mode_mapping_table)/sizeof(usb_mode_mapping_table[0]); + GList *elem; + struct _usb_mode_mapping_table *table; + + /* lookup from custom mapping table first */ + SYS_G_LIST_FOREACH(usb_mode_mapping_table_custom, elem, table) { + if (table->mode == mode) + return table->mode_v; + } /* Caution: The order to search the usb_mode_mapping_table must start with a low index. */ - for (i = 0; i < array_len; i++) { + for (i = 0; i < mapping_table_len; i++) { if (usb_mode_mapping_table[i].mode == mode) return usb_mode_mapping_table[i].mode_v; } @@ -125,6 +168,139 @@ static void usb_state_send_system_event(int status) bundle_free(b); } +static void parse_property_systemd_unit(gpointer data, gpointer udata) +{ + struct section_property *prop = (struct section_property *) data; + struct service_config *svc = (struct service_config *) udata; + + if (MATCH(prop->key, "Service")) { + strncpy(svc->name, prop->value, sizeof(svc->name)); + } else if (MATCH(prop->key, "RemainAfterDisable")) { + svc->remain_after_disable = MATCH(prop->value, "yes"); + } +} + +static unsigned int parse_usb_function(char *fstr) +{ + // Parse Function=, e.g., "Function=diag,acm" + unsigned int ret = USB_FUNCTION_NONE; + char *p, *saveptr; + + if (!fstr) + return ret; + + p = strtok_r(fstr, ",", &saveptr); + if (!p) + return ret; + + do { + if (strncasecmp(p, "mtp", sizeof("mtp")) == 0) { + ret |= USB_FUNCTION_MTP; + } else if (strncasecmp(p, "acm", sizeof("acm")) == 0) { + ret |= USB_FUNCTION_ACM; + } else if(strncasecmp(p, "sdb", sizeof("sdb")) == 0) { + ret |= USB_FUNCTION_SDB; + } else if (strncasecmp(p, "rndis", sizeof("rndis")) == 0) { + ret |= USB_FUNCTION_RNDIS; + } else if (strncasecmp(p, "diag", sizeof("diag")) == 0) { + ret |= USB_FUNCTION_DIAG; + } else if (strncasecmp(p, "conngadget", sizeof("conngadget")) == 0) { + ret |= USB_FUNCTION_CONN_GADGET; + } else if (strncasecmp(p, "dm", sizeof("dm")) == 0) { + ret |= USB_FUNCTION_DM; + } else if (strncasecmp(p, "rmnet", sizeof("rmnet")) == 0) { + ret |= USB_FUNCTION_RMNET; + } + } while ((p = strtok_r(NULL, ",", &saveptr))); + + return ret; +} + +static void parse_property_attribute(gpointer data, gpointer udata) +{ + struct section_property *prop = (struct section_property *) data; + struct _usb_mode_mapping_table *table = (struct _usb_mode_mapping_table *) udata; + unsigned int value; + + if (MATCH(prop->key, "Mode")) { + sscanf(prop->value, "%d", &table->mode_v); + } else if (MATCH(prop->key, "Function")) { + table->mode = parse_usb_function(prop->value); + } else if (MATCH(prop->key, "bDeviceClass")) { + sscanf(prop->value, "%x", &value); + table->attrs.bDeviceClass = (uint8_t) value; + } else if (MATCH(prop->key, "bDeviceSubClass")) { + sscanf(prop->value, "%x", &value); + table->attrs.bDeviceSubClass = (uint8_t) value; + } else if (MATCH(prop->key, "bDeviceProtocol")) { + sscanf(prop->value, "%x", &value); + table->attrs.bDeviceProtocol = (uint8_t) value; + } else if (MATCH(prop->key, "idVendor")) { + sscanf(prop->value, "%x", &value); + table->attrs.idVendor = (uint16_t) value; + } else if (MATCH(prop->key, "idProduct")) { + sscanf(prop->value, "%x", &value); + table->attrs.idProduct = (uint16_t) value; + } else if (MATCH(prop->key, "bcdDevice")) { + sscanf(prop->value, "%x", &value); + table->attrs.bcdDevice = (uint16_t) value; + } +} + +static int load_usb_gadget_config(const struct parse_result *result, void *data) +{ + if (MATCH(result->section, "SystemdUnit")) { + struct service_config svc = { 0, }; + void *entry = NULL; + + g_list_foreach(result->props, parse_property_systemd_unit, &svc); + + entry = malloc(sizeof(struct service_config)); + if (!entry) { + _E("Failed to alloc service config"); + return 0; + } + + _I("usb-gadget service config: name=%s, remain_after_disable=%d", + svc.name, svc.remain_after_disable); + service_config_list = g_list_prepend(service_config_list, memcpy(entry, &svc, sizeof(svc))); + + } else if (MATCH(result->section, "Attribute")) { + struct _usb_mode_mapping_table table = { 0, }; + void *entry = NULL; + + g_list_foreach(result->props, parse_property_attribute, &table); + + // if it hasn't defined mode, use default or pre-defined one + if (table.mode == USB_FUNCTION_NONE) + table.mode = get_mode_bitmap_from_vconf(table.mode_v); + + if (table.mode == USB_FUNCTION_INVALID) + return 0; + + if (table.mode_v >= SET_USB_NONE && table.mode_v <= SET_USB_RNDIS_SDB_ACM) + _W("The custom mode=%d replaces the predefined usb-gadget configuration", table.mode_v); + + entry = malloc(sizeof(struct _usb_mode_mapping_table)); + if (!entry) { + _E("Failed to alloc mapping table"); + return 0; + } + + _I("Custom usb-gadget: mode=%d, function=%#x, idVendor=%#x, idProduct=%#x", + table.mode_v, table.mode, table.attrs.idVendor, table.attrs.idProduct); + + usb_mode_mapping_table_custom = g_list_prepend(usb_mode_mapping_table_custom, memcpy(entry, &table, sizeof(table))); + } + + return 0; +} + +void usb_state_load_custom_mode(void) +{ + libsys_config_parse_by_section(PATH_USB_GADGET_CONF, load_usb_gadget_config, NULL); +} + void usb_state_retrieve_selected_mode(void) { int mode_v; diff --git a/src/usb/usb.c b/src/usb/usb.c index d1f9198..6792310 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -283,6 +283,7 @@ static void usb_init(void *data) { int ret; + usb_state_load_custom_mode(); usb_state_retrieve_selected_mode(); ret = hal_device_usb_gadget_get_backend(); diff --git a/src/usb/usb.h b/src/usb/usb.h index 204cadb..0e30b2e 100644 --- a/src/usb/usb.h +++ b/src/usb/usb.h @@ -28,6 +28,8 @@ int usb_dbus_init(void); +void usb_state_load_custom_mode(void); + int usb_change_mode(unsigned int mode, bool change_debug_mode); void usb_state_retrieve_selected_mode(void); unsigned int get_mode_bitmap_from_vconf(int mode_v); -- 2.7.4 From 33add101f3345ed53faeaaae5f4cf3d296fe3fe3 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Tue, 15 Mar 2022 16:23:25 +0900 Subject: [PATCH 05/16] Add new command to manipulate the "cloned" flag Change-Id: I6dc81870f7769869f02b0dfaa6e2418179288ee2 Signed-off-by: SangYoun Kwak --- packaging/deviced.spec | 5 ++++- tools/board/CMakeLists.txt | 6 +++++- tools/board/clear-partition-ab-cloned.c | 25 +++++++++++++++++++++++++ tools/board/get-partition-ab-cloned.c | 33 +++++++++++++++++++++++++++++++++ tools/board/set-partition-ab-cloned.c | 25 +++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 tools/board/clear-partition-ab-cloned.c create mode 100644 tools/board/get-partition-ab-cloned.c create mode 100644 tools/board/set-partition-ab-cloned.c diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 9a31220..595f28f 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -316,10 +316,13 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so #if #{?usb_module} == on ==> always on %{_bindir}/direct_set_debug.sh %{TZ_SYS_DUMPGEN}/dump_pmstate_log.sh -%attr(2551,root,root) %{_bindir}/device_board_switch_partition %attr(2551,root,root) %{_bindir}/device_board_set_boot_success %attr(2551,root,root) %{_bindir}/device_board_clear_boot_mode %attr(2551,root,root) %{_bindir}/device_board_get_boot_mode +%attr(2551,root,root) %{_bindir}/device_board_switch_partition +%attr(2551,root,root) %{_bindir}/device_board_set_partition_ab_cloned +%attr(2551,root,root) %{_bindir}/device_board_clear_partition_ab_cloned +%attr(2551,root,root) %{_bindir}/device_board_get_partition_ab_cloned #endif %files auto-test diff --git a/tools/board/CMakeLists.txt b/tools/board/CMakeLists.txt index 2ac7eab..1ebb56e 100644 --- a/tools/board/CMakeLists.txt +++ b/tools/board/CMakeLists.txt @@ -15,7 +15,11 @@ MACRO(ADD_BOOT_EXECUTABLE BINARY_NAME SRCS) INSTALL(TARGETS ${BINARY_NAME} DESTINATION bin) ENDMACRO() -ADD_BOOT_EXECUTABLE(device_board_switch_partition switch-partition.c) ADD_BOOT_EXECUTABLE(device_board_set_boot_success set-boot-success.c) ADD_BOOT_EXECUTABLE(device_board_clear_boot_mode clear-boot-mode.c) ADD_BOOT_EXECUTABLE(device_board_get_boot_mode get-boot-mode.c) + +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) diff --git a/tools/board/clear-partition-ab-cloned.c b/tools/board/clear-partition-ab-cloned.c new file mode 100644 index 0000000..36425fa --- /dev/null +++ b/tools/board/clear-partition-ab-cloned.c @@ -0,0 +1,25 @@ +/* + * 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 + +int main(int argc, char *argv[]) +{ + return hal_device_board_clear_partition_ab_cloned(); +} diff --git a/tools/board/get-partition-ab-cloned.c b/tools/board/get-partition-ab-cloned.c new file mode 100644 index 0000000..fb55772 --- /dev/null +++ b/tools/board/get-partition-ab-cloned.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 cloned; + int ret; + + ret = hal_device_board_get_partition_ab_cloned(&cloned); + if (ret == 0) + printf("%d", cloned); + + return ret; +} diff --git a/tools/board/set-partition-ab-cloned.c b/tools/board/set-partition-ab-cloned.c new file mode 100644 index 0000000..7bbc906 --- /dev/null +++ b/tools/board/set-partition-ab-cloned.c @@ -0,0 +1,25 @@ +/* + * 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 + +int main(int argc, char *argv[]) +{ + return hal_device_board_set_partition_ab_cloned(); +} -- 2.7.4 From be1df8683e1726a2d60bda896ea488d8583dec5c Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 24 Mar 2022 15:45:47 +0900 Subject: [PATCH 06/16] power: change configuration section of TimeoutSleepSupport Change-Id: I9e534b858d7994182d994d9649d4f1e2375c32e9 Signed-off-by: Youngjae Cho --- conf/power.conf | 4 +--- src/power/power-control.c | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/conf/power.conf b/conf/power.conf index 60a66cc..57a49fa 100644 --- a/conf/power.conf +++ b/conf/power.conf @@ -5,8 +5,6 @@ Option=wdownload Option=debug Option=silent -[Sleep] -TimeoutSleepSupport=yes - [PowerState] +TimeoutSleepSupport=yes ChangeStateMaxWaitSecond=10 diff --git a/src/power/power-control.c b/src/power/power-control.c index c44d2de..91d07b9 100644 --- a/src/power/power-control.c +++ b/src/power/power-control.c @@ -332,7 +332,7 @@ static int __pm_power_unlock(void *data) static int load_sleep_config(struct parse_result *result, void *user_data) { - if (!MATCH(result->section, "Sleep")) + if (!MATCH(result->section, "PowerState")) return 0; if (MATCH(result->name, "TimeoutSleepSupport") && MATCH(result->value, "yes")) { -- 2.7.4 From 2a8ce43a4b7ff301378443f0de05c4e3d05d96b8 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Thu, 24 Mar 2022 13:56:26 +0900 Subject: [PATCH 07/16] power: add configuration for poweroff delay time Change-Id: I29fe716445cb197b66338d973c6acd1fc40890a8 Signed-off-by: Youngjae Cho --- conf/power.conf | 1 + src/power/power-handler.c | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/conf/power.conf b/conf/power.conf index 57a49fa..437c672 100644 --- a/conf/power.conf +++ b/conf/power.conf @@ -8,3 +8,4 @@ Option=silent [PowerState] TimeoutSleepSupport=yes ChangeStateMaxWaitSecond=10 +PowerOffDelaySecond=4 diff --git a/src/power/power-handler.c b/src/power/power-handler.c index b52bb6d..9e09401 100644 --- a/src/power/power-handler.c +++ b/src/power/power-handler.c @@ -51,7 +51,6 @@ #include "boot.h" #include "shared/plugin.h" -#define POWEROFF_DURATION 4 #define POWEROFF_WAIT_RESOURCED (0.5*1000) /* 0.5 seconds */ #define POWEROFF_WAIT_MAX 10 /* 10 seconds */ #define POWEROFF_WAIT_SYSTEMD_MS (30 * 1000/*ms*/) /* 30 seconds */ @@ -83,6 +82,7 @@ enum poweroff_stage { POWEROFF_WAIT_OTHERS, /* Wait for other processes to clean up their resources */ }; +static int poweroff_delay_second = 0; static enum poweroff_stage poweroff_stage; static const char *poweroff_type_to_name(enum poweroff_type type) @@ -202,21 +202,23 @@ void poweroff_request_shutdown(void) raise(SIGUSR1); } -static void poweroff_wait_for_seconds(void) +static void poweroff_delay_for_seconds(void) { static int wait; struct timeval now; - int poweroff_duration = POWEROFF_DURATION; int check_duration = 0; + if (poweroff_delay_second == 0) + return; + watchdog_notify(); gettimeofday(&now, NULL); check_duration = now.tv_sec - tv_start_poweroff.tv_sec; - while (check_duration < poweroff_duration) { + while (check_duration < poweroff_delay_second) { if (wait == 0) { - _I("Wait poweroff %d %d.", check_duration, poweroff_duration); + _I("Wait poweroff %d %d.", check_duration, poweroff_delay_second); wait = 1; } usleep(100000); @@ -244,7 +246,7 @@ void poweroff_prepare(void) disable_systemd_journald(); disable_coredump_handler(); - poweroff_wait_for_seconds(); + poweroff_delay_for_seconds(); disable_display(); @@ -728,22 +730,15 @@ static int add_poweroff_option(enum poweroff_type type, const char *option) static int load_config(struct parse_result *result, void *user_data) { enum poweroff_type type; - int ret_val; - if (MATCH(result->section, "PowerOff")) + if (MATCH(result->section, "PowerOff") && MATCH(result->name, "Option")) { type = POWEROFF_TYPE_DIRECT; - else if (MATCH(result->section, "Reboot")) + add_poweroff_option(type, result->value); + } else if (MATCH(result->section, "Reboot") && MATCH(result->name, "Option")) { type = POWEROFF_TYPE_RESTART; - else - return 0; - - if (!MATCH(result->name, "Option")) - return 0; - - ret_val = add_poweroff_option(type, result->value); - if (ret_val < 0) { - _E("Failed to add %s option=%s", result->section, result->value); - return ret_val; + add_poweroff_option(type, result->value); + } else if (MATCH(result->section, "PowerState") && MATCH(result->name, "PowerOffDelaySecond")) { + sscanf(result->value, "%d", &poweroff_delay_second); } return 0; -- 2.7.4 From 4ac5e7ffe949d231581c89febe86bbc9309716c7 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 30 Mar 2022 14:33:26 +0900 Subject: [PATCH 08/16] Fix DAC performance for device_board tools Change-Id: I5c4cff6cef406aa4dcc798743bb8c3d3fd5a67f1 Signed-off-by: Hyotaek Shim --- packaging/deviced.spec | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 595f28f..22f93f2 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -316,13 +316,13 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so #if #{?usb_module} == on ==> always on %{_bindir}/direct_set_debug.sh %{TZ_SYS_DUMPGEN}/dump_pmstate_log.sh -%attr(2551,root,root) %{_bindir}/device_board_set_boot_success -%attr(2551,root,root) %{_bindir}/device_board_clear_boot_mode -%attr(2551,root,root) %{_bindir}/device_board_get_boot_mode -%attr(2551,root,root) %{_bindir}/device_board_switch_partition -%attr(2551,root,root) %{_bindir}/device_board_set_partition_ab_cloned -%attr(2551,root,root) %{_bindir}/device_board_clear_partition_ab_cloned -%attr(2551,root,root) %{_bindir}/device_board_get_partition_ab_cloned +%attr(2550,root,root) %{_bindir}/device_board_set_boot_success +%attr(2550,root,root) %{_bindir}/device_board_clear_boot_mode +%attr(2555,root,root) %{_bindir}/device_board_get_boot_mode +%attr(2550,root,root) %{_bindir}/device_board_switch_partition +%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 #endif %files auto-test -- 2.7.4 From b8fd400089dbad1e1c06a9e62ee49142cc69a97b Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Wed, 30 Mar 2022 18:20:59 +0900 Subject: [PATCH 09/16] 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 From af0a7f6275f7513bebc5c8470f4e35284fe63de8 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 31 Mar 2022 14:05:03 +0900 Subject: [PATCH 10/16] Fix include and parameter Change-Id: I9ced21c55ce596087418a9f5f3867e42411e16c7 Signed-off-by: SangYoun Kwak --- tools/board/set-upgrade-status.c | 2 +- tools/board/switch-partition.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/board/set-upgrade-status.c b/tools/board/set-upgrade-status.c index 22876d7..e863d0a 100644 --- a/tools/board/set-upgrade-status.c +++ b/tools/board/set-upgrade-status.c @@ -60,5 +60,5 @@ int main(int argc, char *argv[]) return -EINVAL; } - return hal_device_board_set_upgrade_status(argc, argv); + return hal_device_board_set_upgrade_status(status); } diff --git a/tools/board/switch-partition.c b/tools/board/switch-partition.c index bfdd5af..69bf28a 100644 --- a/tools/board/switch-partition.c +++ b/tools/board/switch-partition.c @@ -17,6 +17,7 @@ * */ +#include #include int main(int argc, char *argv[]) -- 2.7.4 From 9b8cbc8167937d244e0f5529bcf00febe8ddc341 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 29 Mar 2022 18:28:05 -0700 Subject: [PATCH 11/16] hdmi: remove display control Controlling display from hdmi will be more discussed as multi-display concept would be introduced. Therefore, remove old fashioned display control policy. Change-Id: Iecd28b73491d6fcb565183196d2c9291720db23a Signed-off-by: Youngjae Cho --- src/extcon/hdmi.c | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/src/extcon/hdmi.c b/src/extcon/hdmi.c index 943f767..56ffea6 100644 --- a/src/extcon/hdmi.c +++ b/src/extcon/hdmi.c @@ -34,7 +34,6 @@ #define HDMI_NUMBER_MAX (64) // max number of supported hdmi static struct dd_bitmap *bm_hdmi; -static struct display_plugin *disp_plgn; static struct extcon_ops hdmi_extcon_ops; static void hdmi_send_broadcast(int status) @@ -110,8 +109,6 @@ static int hdmi_update(const char *index, int status) } _I("Hdmi changed"); - if (disp_plgn->pm_change_internal) - disp_plgn->pm_change_internal(INTERNAL_LOCK_HDMI, LCD_NORMAL); if (!index) update_all_hdmi_bitmap(status); @@ -132,35 +129,6 @@ static int hdmi_update(const char *index, int status) hdmi_extcon_ops.status = hdmi_status; hdmi_send_broadcast(hdmi_status); - if (hdmi_status == HDMI_CONNECTED) { - if (disp_plgn->pm_lock_internal) - disp_plgn->pm_lock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, STAY_CUR_STATE, 0); - } else { - if (disp_plgn->pm_unlock_internal) - disp_plgn->pm_unlock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, PM_SLEEP_MARGIN); - } - - return 0; -} - -static int display_changed(void *data) -{ - enum state_t state; - int hdmi; - - if (!data) - return 0; - - state = *(int *)data; - if (state != S_NORMAL) - return 0; - - hdmi = hdmi_extcon_ops.status; - if (hdmi == 0) { - if (disp_plgn->pm_lock_internal) - disp_plgn->pm_lock_internal(INTERNAL_LOCK_HDMI, LCD_DIM, STAY_CUR_STATE, 0); - _I("Hdmi is connected. Dim lock is on."); - } return 0; } @@ -187,8 +155,6 @@ static void hdmi_init(void *data) { int ret; - register_notifier(DEVICE_NOTIFIER_LCD, display_changed); - ret = gdbus_add_object(NULL, DEVICED_PATH_SYSNOTI, &dbus_interface); if (ret < 0) _E("Failed to init dbus method: %d", ret); @@ -198,8 +164,6 @@ static void hdmi_init(void *data) static void hdmi_exit(void *data) { - unregister_notifier(DEVICE_NOTIFIER_LCD, display_changed); - deinit_bitmap(bm_hdmi); } @@ -211,10 +175,3 @@ static struct extcon_ops hdmi_extcon_ops = { }; EXTCON_OPS_REGISTER(hdmi_extcon_ops) - -static void __CONSTRUCTOR__ initialize(void) -{ - disp_plgn = get_var_display_plugin(); - if (!disp_plgn) - _E("Failed to get display plugin variable."); -} -- 2.7.4 From 189ec95d3161aabdff5a7b9cd0851e3b80a6e640 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Fri, 1 Apr 2022 16:07:13 +0900 Subject: [PATCH 12/16] Fix to initialize the char pointer to NULL Change-Id: I7144bf7646e813a905c3eae7fd209d342cabb450 Signed-off-by: SangYoun Kwak --- tools/board/set-upgrade-status.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/board/set-upgrade-status.c b/tools/board/set-upgrade-status.c index e863d0a..d1a9fe1 100644 --- a/tools/board/set-upgrade-status.c +++ b/tools/board/set-upgrade-status.c @@ -25,7 +25,7 @@ static int parse_integer(const char *str, int *val) { - char *endptr = str; + char *endptr = NULL; long longval = 0; errno = 0; -- 2.7.4 From 943e2f348215f1c60136909ecb640598c289c5d5 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 1 Apr 2022 15:30:23 +0900 Subject: [PATCH 13/16] power: separate power configuration for each profile Change-Id: Id24e09c02a3e4e706cbe95eeee351eb23c250273 Signed-off-by: Youngjae Cho --- CMakeLists.txt | 6 +++++- conf/power-profile-iot-headed.conf | 11 +++++++++++ conf/power-profile-iot-headless.conf | 11 +++++++++++ conf/{power.conf => power-profile-mobile.conf} | 0 conf/power-profile-tv.conf | 11 +++++++++++ conf/power-profile-wearable.conf | 11 +++++++++++ packaging/deviced.spec | 11 ++++++++++- 7 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 conf/power-profile-iot-headed.conf create mode 100644 conf/power-profile-iot-headless.conf rename conf/{power.conf => power-profile-mobile.conf} (100%) create mode 100644 conf/power-profile-tv.conf create mode 100644 conf/power-profile-wearable.conf diff --git a/CMakeLists.txt b/CMakeLists.txt index 49efd97..287aac9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,7 +278,11 @@ ENDIF() IF(POWER_MODULE STREQUAL on) INSTALL_CONF(conf init) - INSTALL_CONF(conf power) + INSTALL_CONF(conf power-profile-mobile) + INSTALL_CONF(conf power-profile-wearable) + INSTALL_CONF(conf power-profile-tv) + INSTALL_CONF(conf power-profile-iot-headed) + INSTALL_CONF(conf power-profile-iot-headless) ENDIF() # USB connection diff --git a/conf/power-profile-iot-headed.conf b/conf/power-profile-iot-headed.conf new file mode 100644 index 0000000..ce213be --- /dev/null +++ b/conf/power-profile-iot-headed.conf @@ -0,0 +1,11 @@ +[Reboot] +Option=recovery +Option=download +Option=wdownload +Option=debug +Option=silent + +[PowerState] +TimeoutSleepSupport=no +ChangeStateMaxWaitSecond=10 +PowerOffDelaySecond=4 diff --git a/conf/power-profile-iot-headless.conf b/conf/power-profile-iot-headless.conf new file mode 100644 index 0000000..27c6908 --- /dev/null +++ b/conf/power-profile-iot-headless.conf @@ -0,0 +1,11 @@ +[Reboot] +Option=recovery +Option=download +Option=wdownload +Option=debug +Option=silent + +[PowerState] +TimeoutSleepSupport=yes +ChangeStateMaxWaitSecond=10 +PowerOffDelaySecond=0 diff --git a/conf/power.conf b/conf/power-profile-mobile.conf similarity index 100% rename from conf/power.conf rename to conf/power-profile-mobile.conf diff --git a/conf/power-profile-tv.conf b/conf/power-profile-tv.conf new file mode 100644 index 0000000..437c672 --- /dev/null +++ b/conf/power-profile-tv.conf @@ -0,0 +1,11 @@ +[Reboot] +Option=recovery +Option=download +Option=wdownload +Option=debug +Option=silent + +[PowerState] +TimeoutSleepSupport=yes +ChangeStateMaxWaitSecond=10 +PowerOffDelaySecond=4 diff --git a/conf/power-profile-wearable.conf b/conf/power-profile-wearable.conf new file mode 100644 index 0000000..437c672 --- /dev/null +++ b/conf/power-profile-wearable.conf @@ -0,0 +1,11 @@ +[Reboot] +Option=recovery +Option=download +Option=wdownload +Option=debug +Option=silent + +[PowerState] +TimeoutSleepSupport=yes +ChangeStateMaxWaitSecond=10 +PowerOffDelaySecond=4 diff --git a/packaging/deviced.spec b/packaging/deviced.spec index 1331169..97860ae 100644 --- a/packaging/deviced.spec +++ b/packaging/deviced.spec @@ -223,6 +223,7 @@ update-alternatives --remove shutdown %{_sbindir}/deviced-power-command || : %post plugin-profile-mobile mv %{_sysconfdir}/deviced/display-profile-mobile.conf %{_sysconfdir}/deviced/display.conf +mv %{_sysconfdir}/deviced/power-profile-mobile.conf %{_sysconfdir}/deviced/power.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/mobile-display.so %{_libdir}/deviced/display.so %if %{?battery_module} == on @@ -231,6 +232,7 @@ mv %{_libdir}/mobile-battery.so %{_libdir}/deviced/battery.so %post plugin-profile-wearable mv %{_sysconfdir}/deviced/display-profile-wearable.conf %{_sysconfdir}/deviced/display.conf +mv %{_sysconfdir}/deviced/power-profile-wearable.conf %{_sysconfdir}/deviced/power.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/wearable-display.so %{_libdir}/deviced/display.so %if %{?battery_module} == on @@ -239,16 +241,19 @@ mv %{_libdir}/wearable-battery.so %{_libdir}/deviced/battery.so %post plugin-profile-tv mv %{_sysconfdir}/deviced/display-profile-tv.conf %{_sysconfdir}/deviced/display.conf +mv %{_sysconfdir}/deviced/power-profile-tv.conf %{_sysconfdir}/deviced/power.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/tv-display.so %{_libdir}/deviced/display.so %post plugin-profile-iot-headed mv %{_sysconfdir}/deviced/display-profile-iot-headed.conf %{_sysconfdir}/deviced/display.conf +mv %{_sysconfdir}/deviced/power-profile-iot-headed.conf %{_sysconfdir}/deviced/power.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so %post plugin-profile-iot-headless mv %{_sysconfdir}/deviced/input-profile-iot-headless.conf %{_sysconfdir}/deviced/input.conf +mv %{_sysconfdir}/deviced/power-profile-iot-headless.conf %{_sysconfdir}/deviced/power.conf mkdir -p %{_libdir}/deviced mv %{_libdir}/iot-headless-input-handler.so %{_libdir}/deviced/input-handler.so mv %{_libdir}/iot-headless-power.so %{_libdir}/deviced/power.so @@ -267,7 +272,6 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %{_unitdir}/basic.target.wants/sdb-prestart.service %endif %config %{_sysconfdir}/dbus-1/system.d/org.tizen.system.deviced.conf -%config %{_sysconfdir}/deviced/power.conf %config %{_sysconfdir}/deviced/init.conf %if %{?battery_module} == on %config %{_sysconfdir}/deviced/battery.conf @@ -337,6 +341,7 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/display-profile-mobile.conf +%config %{_sysconfdir}/deviced/power-profile-mobile.conf %{_libdir}/mobile-display.so %if %{?battery_module} == on %{_libdir}/mobile-battery.so @@ -349,6 +354,7 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/display-profile-wearable.conf +%config %{_sysconfdir}/deviced/power-profile-wearable.conf %{_libdir}/wearable-display.so %if %{?battery_module} == on %{_libdir}/wearable-battery.so @@ -361,6 +367,7 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/display-profile-tv.conf +%config %{_sysconfdir}/deviced/power-profile-tv.conf %{_libdir}/tv-display.so %{_unitdir}/rndis.service %{_bindir}/rndis.sh @@ -370,6 +377,7 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/display-profile-iot-headed.conf +%config %{_sysconfdir}/deviced/power-profile-iot-headed.conf %{_libdir}/iot-headed-display.so %{_unitdir}/rndis.service %{_bindir}/rndis.sh @@ -379,6 +387,7 @@ mv %{_libdir}/iot-headless-battery.so %{_libdir}/deviced/battery.so %license LICENSE.Apache-2.0 %defattr(-,root,root,-) %config %{_sysconfdir}/deviced/input-profile-iot-headless.conf +%config %{_sysconfdir}/deviced/power-profile-iot-headless.conf %{_libdir}/iot-headless-input-handler.so %{_libdir}/iot-headless-power.so %{_libdir}/iot-headless-battery.so -- 2.7.4 From c29ab86fae1e3e6e08b5ae76a9c51f35581e9e9e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 5 Apr 2022 17:29:24 -0700 Subject: [PATCH 14/16] usb: prevent not null-terminated string Change-Id: I17b1d4c7753120dd09192523f75c8939ba96e184 Signed-off-by: Youngjae Cho --- src/usb/usb-state.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/usb/usb-state.c b/src/usb/usb-state.c index 77375c6..51fa4cb 100644 --- a/src/usb/usb-state.c +++ b/src/usb/usb-state.c @@ -174,7 +174,8 @@ static void parse_property_systemd_unit(gpointer data, gpointer udata) struct service_config *svc = (struct service_config *) udata; if (MATCH(prop->key, "Service")) { - strncpy(svc->name, prop->value, sizeof(svc->name)); + strncpy(svc->name, prop->value, sizeof(svc->name) - 1); + svc->name[sizeof(svc->name) - 1] = '\0'; } else if (MATCH(prop->key, "RemainAfterDisable")) { svc->remain_after_disable = MATCH(prop->value, "yes"); } -- 2.7.4 From 43658e8acdef4676c65bc1462f1306f5d3950587 Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Thu, 7 Apr 2022 16:32:35 +0900 Subject: [PATCH 15/16] Modify the return value and the output of deviced-tools Change-Id: Ic9070e2062f17b109a09791d38948e0aa7c20da9 Signed-off-by: SangYoun Kwak --- tools/board/clear-boot-mode.c | 11 ++++++++++- tools/board/clear-partition-ab-cloned.c | 11 ++++++++++- tools/board/get-boot-mode.c | 10 +++++++--- tools/board/get-partition-ab-cloned.c | 10 +++++++--- tools/board/get-upgrade-status.c | 10 +++++++--- tools/board/set-boot-success.c | 11 ++++++++++- tools/board/set-partition-ab-cloned.c | 11 ++++++++++- tools/board/set-upgrade-status.c | 21 ++++++++++++++++----- tools/board/switch-partition.c | 19 ++++++++++++++++--- 9 files changed, 93 insertions(+), 21 deletions(-) diff --git a/tools/board/clear-boot-mode.c b/tools/board/clear-boot-mode.c index 38075f9..7ae0704 100644 --- a/tools/board/clear-boot-mode.c +++ b/tools/board/clear-boot-mode.c @@ -17,9 +17,18 @@ * */ +#include #include int main(int argc, char *argv[]) { - return hal_device_board_clear_boot_mode(); + int ret = hal_device_board_clear_boot_mode(); + + if(ret < 0) { + printf("FAILURE\n"); + return 1; + } + + printf("SUCCESS\n"); + return 0; } diff --git a/tools/board/clear-partition-ab-cloned.c b/tools/board/clear-partition-ab-cloned.c index 36425fa..6c4437d 100644 --- a/tools/board/clear-partition-ab-cloned.c +++ b/tools/board/clear-partition-ab-cloned.c @@ -17,9 +17,18 @@ * */ +#include #include int main(int argc, char *argv[]) { - return hal_device_board_clear_partition_ab_cloned(); + int ret = hal_device_board_clear_partition_ab_cloned(); + + if(ret < 0) { + printf("FAILURE\n"); + return 1; + } + + printf("SUCCESS\n"); + return 0; } diff --git a/tools/board/get-boot-mode.c b/tools/board/get-boot-mode.c index 29ddde5..f72172c 100644 --- a/tools/board/get-boot-mode.c +++ b/tools/board/get-boot-mode.c @@ -26,8 +26,12 @@ int main(int argc, char *argv[]) int ret; ret = hal_device_board_get_boot_mode(buffer, sizeof(buffer)); - if (ret == 0) - printf("%s", buffer); - return ret; + if(ret < 0) { + printf("FAILURE\n"); + return 1; + } + + printf("%s\n", buffer); + return 0; } diff --git a/tools/board/get-partition-ab-cloned.c b/tools/board/get-partition-ab-cloned.c index fb55772..d843930 100644 --- a/tools/board/get-partition-ab-cloned.c +++ b/tools/board/get-partition-ab-cloned.c @@ -26,8 +26,12 @@ int main(int argc, char *argv[]) int ret; ret = hal_device_board_get_partition_ab_cloned(&cloned); - if (ret == 0) - printf("%d", cloned); - return ret; + if (ret < 0) { + printf("FAILURE\n"); + return 1; + } + + printf("%d\n", cloned); + return 0; } diff --git a/tools/board/get-upgrade-status.c b/tools/board/get-upgrade-status.c index bf3da64..f66ad36 100644 --- a/tools/board/get-upgrade-status.c +++ b/tools/board/get-upgrade-status.c @@ -26,8 +26,12 @@ int main(int argc, char *argv[]) int ret; ret = hal_device_board_get_upgrade_status(&status); - if (ret == 0) - printf("%d", status); - return ret; + if(ret < 0) { + printf("FAILURE\n"); + return 1; + } + + printf("%d\n", status); + return 0; } diff --git a/tools/board/set-boot-success.c b/tools/board/set-boot-success.c index 16ec3a5..5146149 100644 --- a/tools/board/set-boot-success.c +++ b/tools/board/set-boot-success.c @@ -17,9 +17,18 @@ * */ +#include #include int main(int argc, char *argv[]) { - return hal_device_board_set_boot_success(); + int ret = hal_device_board_set_boot_success(); + + if(ret < 0) { + printf("FAILURE\n"); + return 1; + } + + printf("SUCCESS\n"); + return 0; } diff --git a/tools/board/set-partition-ab-cloned.c b/tools/board/set-partition-ab-cloned.c index 7bbc906..941fe0d 100644 --- a/tools/board/set-partition-ab-cloned.c +++ b/tools/board/set-partition-ab-cloned.c @@ -17,9 +17,18 @@ * */ +#include #include int main(int argc, char *argv[]) { - return hal_device_board_set_partition_ab_cloned(); + int ret = hal_device_board_set_partition_ab_cloned(); + + if(ret < 0) { + printf("FAILURE\n"); + return 1; + } + + printf("SUCCESS\n"); + return 0; } diff --git a/tools/board/set-upgrade-status.c b/tools/board/set-upgrade-status.c index d1a9fe1..5bd1fb1 100644 --- a/tools/board/set-upgrade-status.c +++ b/tools/board/set-upgrade-status.c @@ -48,17 +48,28 @@ static int parse_integer(const char *str, int *val) int main(int argc, char *argv[]) { int status; - int parse_ret; + int parse_ret, ret; if(argc < 2) { - return -EINVAL; + goto err; } parse_ret = parse_integer(argv[1], &status); - if(parse_ret != 0) { - return -EINVAL; + if(parse_ret < 0) { + goto err; } - return hal_device_board_set_upgrade_status(status); + ret = hal_device_board_set_upgrade_status(status); + + if(ret < 0) { + goto err; + } + + printf("SUCCESS\n"); + return 0; + +err: + printf("FAILURE\n"); + return 1; } diff --git a/tools/board/switch-partition.c b/tools/board/switch-partition.c index 69bf28a..973e4ac 100644 --- a/tools/board/switch-partition.c +++ b/tools/board/switch-partition.c @@ -17,21 +17,34 @@ * */ +#include #include #include int main(int argc, char *argv[]) { char partition_ab; + int ret; if(argc < 2) { - return -EINVAL; + goto err; } partition_ab = argv[1][0]; if(partition_ab != 'a' && partition_ab != 'b') { - return -EINVAL; + goto err; } - return hal_device_board_switch_partition(partition_ab); + ret = hal_device_board_switch_partition(partition_ab); + + if(ret < 0) { + goto err; + } + + printf("SUCCESS\n"); + return 0; + +err: + printf("FAILURE\n"); + return 1; } -- 2.7.4 From fa58aae05a2915990380cdbd6cee7d557552282b Mon Sep 17 00:00:00 2001 From: SangYoun Kwak Date: Fri, 8 Apr 2022 17:29:15 +0900 Subject: [PATCH 16/16] Fix implicit declaration warning Change-Id: I9abfa31c34e01ed1796655cd86705430ab279d2f Signed-off-by: SangYoun Kwak --- tools/board/set-upgrade-status.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/board/set-upgrade-status.c b/tools/board/set-upgrade-status.c index 5bd1fb1..6080d63 100644 --- a/tools/board/set-upgrade-status.c +++ b/tools/board/set-upgrade-status.c @@ -17,6 +17,7 @@ * */ +#include #include #include #include -- 2.7.4