power: consider bootmode as well as bootreason 59/279159/5
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 3 Aug 2022 02:33:50 +0000 (11:33 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Tue, 16 Aug 2022 01:44:36 +0000 (10:44 +0900)
Take consideration of bootmode as well as bootreason for the initial
state transition.

Change-Id: I2ba378cbf146215f315b4d413ec4fd4e470cafe1
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
conf/init.conf
src/power/power-boot.c
src/power/power-boot.h
src/power/power.c

index ee77c26..504fec7 100644 (file)
@@ -1,3 +1,6 @@
+# BootMode= is optional. If it isn't specified then
+# it is regarded as BootMode=normal
+
 [EventAction]
 #INITIAL_STATE_BY_POWERKEY_BOOTING
 Enum=3000
@@ -11,7 +14,14 @@ BootReason=charger
 ActionChangeState=start,sleep
 
 [EventAction]
-#INITIAL_STATE_BY_REBOOT
+#INITIAL_STATE_BY_REBOOT_NORMAL
 Enum=3002
 BootReason=reboot
 ActionChangeState=start,normal
+
+[EventAction]
+#INITIAL_STATE_BY_REBOOT_SILENT
+Enum=3003
+BootReason=reboot
+BootMode=silent
+ActionChangeState=start,sleep
index ff6ba8a..75ed8db 100644 (file)
@@ -47,6 +47,11 @@ static struct trans_info init_ti = {
        .next = 0,
 };
 
+static struct boot_condition {
+       char reason[64];
+       char mode[64];
+} bc = { "unknown", "normal" };
+
 static guint sig_id[2] = {0, 0};
 
 void remove_delayed_init_done_handler(void *data)
@@ -143,37 +148,45 @@ static void parse_init_ti(const struct parse_result *result)
        }
 }
 
-static int parse_matching_bootreason(const struct parse_result *result, void *data)
+static int parse_matching_boot_condition(const struct parse_result *result, void *data)
 {
        GList *elem;
        struct section_property *prop;
-       char *bootreason = (char *) data;
+       struct boot_condition config_bc = { "", "normal" };
 
        if (!MATCH(result->section, "EventAction"))
                return 0;
 
        SYS_G_LIST_FOREACH(result->props, elem, prop) {
-               if (MATCH(prop->key, "BootReason") && MATCH(prop->value, bootreason))
-                       parse_init_ti(result);
+               if (MATCH(prop->key, "BootReason"))
+                       sscanf(prop->value, "%s", config_bc.reason);
+               else if (MATCH(prop->key, "BootMode"))
+                       sscanf(prop->value, "%s", config_bc.mode);
        }
 
+       if (MATCH(bc.reason, config_bc.reason) && MATCH(bc.mode, config_bc.mode))
+               parse_init_ti(result);
+
        return 0;
 }
 
-void initial_transition_by_bootreason(void)
+void initial_transition_by_boot_condition(void)
 {
        int retval;
-       char bootreason[64] = "Unknown";
 
-       retval = hal_device_board_get_boot_reason(bootreason, sizeof(bootreason));
+       retval = hal_device_board_get_boot_reason(bc.reason, sizeof(bc.reason));
        if (retval != 0) {
                _I("Failed to get BootReason, %d. Default change state to normal.", retval);
                power_request_change_state_strict(POWER_STATE_START, POWER_STATE_NORMAL, 1, NULL);
                return;
        }
 
-       CRITICAL_LOG("BootReason=%s", bootreason);
-       libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_bootreason, bootreason);
+       retval = hal_device_board_get_boot_mode(bc.mode, sizeof(bc.mode));
+       if (retval != 0)
+               _I("Failed to get BootMode, %d", retval);
+
+       CRITICAL_LOG("BootReason=%s, BootMode=%s", bc.reason, bc.mode);
+       libsys_config_parse_by_section(INIT_CONF_PATH, parse_matching_boot_condition, NULL);
 
        power_request_change_state_strict(init_ti.curr, init_ti.next, init_ti.reason, NULL);
 }
index cdabd28..d3057ef 100644 (file)
@@ -21,7 +21,7 @@
 
 void add_delayed_init_done_handler(void *data);
 void remove_delayed_init_done_handler(void *data);
-void initial_transition_by_bootreason(void);
+void initial_transition_by_boot_condition(void);
 
 extern int silent_boot;
 
index 01ee2df..519a126 100644 (file)
@@ -314,10 +314,11 @@ void power_state_init(void *data)
 
        /* Take the first transition.
         *
-        * It is determined by bootreason to which state to transition, POWER_STATE_NORMAL or POWER_STATE_SLEEP.
-        * Or it may stay in POWER_STATE_START if there is no defined action for the matching bootreason.
+        * It is determined by bootreason and bootmode to which state to transition, POWER_STATE_NORMAL
+        * or POWER_STATE_SLEEP. it may stay in POWER_STATE_START if there is no defined action for the
+        * matching bootreason and bootmode.
         */
-       initial_transition_by_bootreason();
+       initial_transition_by_boot_condition();
 }
 
 static const struct device_ops power_state_device_ops = {