summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util/ec_sb_firmware_update.c22
-rw-r--r--util/powerd_lock.c30
-rw-r--r--util/powerd_lock.h8
3 files changed, 29 insertions, 31 deletions
diff --git a/util/ec_sb_firmware_update.c b/util/ec_sb_firmware_update.c
index 3e1d51a205..2b392fd679 100644
--- a/util/ec_sb_firmware_update.c
+++ b/util/ec_sb_firmware_update.c
@@ -68,7 +68,8 @@ enum {
F_VERSION_CHECK = 0x2, /* do firmware version check */
F_UPDATE = 0x4, /* do firmware update */
F_NEED_UPDATE = 0x8, /* need firmware update */
- F_POWERD_DISABLED = 0x10 /* powerd is disabled */
+ F_POWERD_DISABLED = 0x10, /* powerd is disabled */
+ F_LFCC_ZERO = 0x20 /* last full charge is zero */
};
struct fw_update_ctrl {
@@ -487,13 +488,9 @@ static enum fw_update_state s2_write_prepare(struct fw_update_ctrl *fw_update)
{
int rv;
rv = disable_power_management();
- if (rv) {
- fw_update->rv = -1;
- log_msg(fw_update, S2_WRITE_PREPARE,
- "disable power management error");
- return S10_TERMINAL;
- }
- fw_update->flags |= F_POWERD_DISABLED;
+ if (0 == rv)
+ fw_update->flags |= F_POWERD_DISABLED;
+
rv = send_subcmd(EC_SB_FW_UPDATE_PREPARE);
if (rv) {
fw_update->rv = -1;
@@ -770,6 +767,13 @@ int main(int argc, char *argv[])
fw_update.flags |= F_AC_PRESENT;
printf("AC_PRESENT\n");
}
+ rv = ec_readmem(EC_MEMMAP_BATT_LFCC, sizeof(val), &val);
+ if (rv <= 0) {
+ printf("EC Memmap read error:%d\n", rv);
+ goto out;
+ }
+ if (val == 0)
+ fw_update.flags |= F_LFCC_ZERO;
if (op == OP_UPDATE)
fw_update.flags |= F_UPDATE;
@@ -799,5 +803,5 @@ out:
if (rv)
return -1;
else
- return fw_update.flags & F_NEED_UPDATE;
+ return fw_update.flags & (F_LFCC_ZERO | F_NEED_UPDATE);
}
diff --git a/util/powerd_lock.c b/util/powerd_lock.c
index 632bae069a..94fa999e30 100644
--- a/util/powerd_lock.c
+++ b/util/powerd_lock.c
@@ -40,37 +40,23 @@ int disable_power_management()
{
FILE *lock_file;
int rc = 0;
-
lock_file = fopen(lock_file_path, "w");
- if (!lock_file) {
- printf("%s: Failed to open %s for writing: %s\n",
- __func__, lock_file_path, strerror(errno));
- return 1;
- }
+ if (!lock_file)
+ return POWERD_CREATE_LOCK_FILE_ERROR;
- if (fprintf(lock_file, "%ld", (long)getpid()) < 0) {
- printf("%s: Failed to write PID to %s: %s\n",
- __func__, lock_file_path, strerror(errno));
- rc = 1;
- }
+ if (fprintf(lock_file, "%ld", (long)getpid()) < 0)
+ rc = POWERD_WRITE_LOCK_FILE_ERROR;
- if (fclose(lock_file) != 0) {
- printf("%s: Failed to close %s: %s\n",
- __func__, lock_file_path, strerror(errno));
- }
+ if (fclose(lock_file) != 0)
+ rc |= POWERD_CLOSE_LOCK_FILE_ERROR;
return rc;
-
}
int restore_power_management()
{
int result = 0;
-
result = unlink(lock_file_path);
- if (result != 0 && errno != ENOENT) {
- printf("%s: Failed to unlink %s: %s\n",
- __func__, lock_file_path, strerror(errno));
- return 1;
- }
+ if (result != 0 && errno != ENOENT)
+ return POWERD_DELETE_LOCK_FILE_ERROR;
return 0;
}
diff --git a/util/powerd_lock.h b/util/powerd_lock.h
index c486047035..ddcd5f0553 100644
--- a/util/powerd_lock.h
+++ b/util/powerd_lock.h
@@ -24,6 +24,14 @@
#ifndef __POWER_H__
#define __POWER_H__ 1
+enum POWERD_ERROR_CODE {
+ POWERD_OK = 0,
+ POWERD_CREATE_LOCK_FILE_ERROR = 0x1,
+ POWERD_WRITE_LOCK_FILE_ERROR = 0x2,
+ POWERD_CLOSE_LOCK_FILE_ERROR = 0x4,
+ POWERD_DELETE_LOCK_FILE_ERROR = 0x8
+};
+
/* Disable power management. */
int disable_power_management(void);