summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-07-23 11:50:59 +0800
committerChromeBot <chrome-bot@google.com>2013-07-23 16:06:24 -0700
commitb702babbb7ae1c9c225e9937f4a7656d36151310 (patch)
tree224e24cf13975f52c0faa0623cc6b364cdf8e44c /chip
parentf98def750d61d48e654f02e2384c517e0d698a99 (diff)
downloadchrome-ec-b702babbb7ae1c9c225e9937f4a7656d36151310.tar.gz
Fix reset flags and sysjump time for emulator
Reset flags should be set properly according to reset type. Also, on system jump, current time should be preserved. BUG=chrome-os-partner:19235 TEST='sysjump rw' and check time is the same. TEST='reboot hard' and see '[Reset cause: hard]' BRANCH=None Change-Id: I00fd2c652d10c237f23cc6a33e0b667422bc625d Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/62958 Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/host/system.c83
1 files changed, 70 insertions, 13 deletions
diff --git a/chip/host/system.c b/chip/host/system.c
index e1bd2cc898..3a0be45a20 100644
--- a/chip/host/system.c
+++ b/chip/host/system.c
@@ -9,9 +9,10 @@
#include "common.h"
#include "host_test.h"
-#include "system.h"
#include "panic.h"
#include "persistence.h"
+#include "system.h"
+#include "timer.h"
#include "util.h"
#define SHARED_MEM_SIZE 512 /* bytes */
@@ -73,7 +74,7 @@ static uint32_t get_image_copy(void)
uint32_t ret;
if (f == NULL)
- return SYSTEM_IMAGE_RO;
+ return SYSTEM_IMAGE_UNKNOWN;
fread(&ret, sizeof(ret), 1, f);
release_persistent_storage(f);
remove_persistent_storage("image_copy");
@@ -81,6 +82,53 @@ static uint32_t get_image_copy(void)
return ret;
}
+static void save_reset_flags(uint32_t flags)
+{
+ FILE *f = get_persistent_storage("reset_flags", "wb");
+
+ ASSERT(f != NULL);
+ ASSERT(fwrite(&flags, sizeof(flags), 1, f) == 1);
+
+ release_persistent_storage(f);
+}
+
+static uint32_t load_reset_flags(void)
+{
+ FILE *f = get_persistent_storage("reset_flags", "rb");
+ uint32_t ret;
+
+ if (f == NULL)
+ return RESET_FLAG_POWER_ON;
+ fread(&ret, sizeof(ret), 1, f);
+ release_persistent_storage(f);
+ remove_persistent_storage("reset_flags");
+
+ return ret;
+}
+
+static void save_time(timestamp_t t)
+{
+ FILE *f = get_persistent_storage("time", "wb");
+
+ ASSERT(f != NULL);
+ ASSERT(fwrite(&t, sizeof(t), 1, f) == 1);
+
+ release_persistent_storage(f);
+}
+
+static int load_time(timestamp_t *t)
+{
+ FILE *f = get_persistent_storage("time", "rb");
+
+ if (f == NULL)
+ return 0;
+ fread(t, sizeof(*t), 1, f);
+ release_persistent_storage(f);
+ remove_persistent_storage("time");
+
+ return 1;
+}
+
test_mockable struct panic_data *panic_get_data(void)
{
return (struct panic_data *)
@@ -89,7 +137,16 @@ test_mockable struct panic_data *panic_get_data(void)
test_mockable void system_reset(int flags)
{
- exit(EXIT_CODE_RESET | flags);
+ uint32_t save_flags = 0;
+ if (flags & SYSTEM_RESET_PRESERVE_FLAGS)
+ save_flags = system_get_reset_flags() | RESET_FLAG_PRESERVED;
+ if (flags & SYSTEM_RESET_LEAVE_AP_OFF)
+ save_flags |= RESET_FLAG_AP_OFF;
+ if (flags & SYSTEM_RESET_HARD)
+ save_flags |= RESET_FLAG_HARD;
+ if (save_flags)
+ save_reset_flags(save_flags);
+ exit(EXIT_CODE_RESET);
}
test_mockable void system_hibernate(uint32_t seconds, uint32_t microseconds)
@@ -102,16 +159,6 @@ test_mockable int system_is_locked(void)
return 0;
}
-test_mockable int system_jumped_to_this_image(void)
-{
- return 0;
-}
-
-test_mockable uint32_t system_get_reset_flags(void)
-{
- return RESET_FLAG_POWER_ON;
-}
-
const char *system_get_chip_vendor(void)
{
return "chromeos";
@@ -177,6 +224,7 @@ uintptr_t system_usable_ram_end(void)
static void __jump_resetvec(void)
{
+ save_time(get_time());
ramdata_set_persistent();
exit(EXIT_CODE_RESET);
}
@@ -195,8 +243,17 @@ static void __rw_jump_resetvec(void)
void system_pre_init(void)
{
+ timestamp_t t;
+
+ if (load_time(&t))
+ force_time(t);
+
ramdata_get_persistent();
__running_copy = get_image_copy();
+ if (__running_copy == SYSTEM_IMAGE_UNKNOWN) {
+ __running_copy = SYSTEM_IMAGE_RO;
+ system_set_reset_flags(load_reset_flags());
+ }
*(uintptr_t *)(__host_flash + CONFIG_FW_RO_OFF + 4) =
(uintptr_t)__ro_jump_resetvec;