恢复出厂设置后, 时间没有恢复

原文:http://blog.csdn.net/mm167891/article/details/8618884

步骤:先设置日期或时间,恢复出厂设置,日期或时间没有恢复成默认

现象:如:先设置日期为2017-1-1,恢复出厂设置之后,日期仍为2017-1-1;

         (注:系统默认的时间为2013-1-1)

原因:

     恢复出厂设置主要功能为清除/data, /cache分区信息,系统时间涉及到板级rtc信息而没有进行清除。

实现:

    通过在recovery wipe过程中增加设置rtc时间过程实现在恢复出厂设置时复位系统默认时间。
    系统默认初始时间设置为:2013-01-01 00:00:00(+08:00),对应UTC为:2012-12-31 16:00:00

注:这里设置使用的时间值是作为UTC时间(通用协调时)来的,即对应0时区(格林尼治标准时间-伦敦)当地时间,而中国位于东8时区,所以对于当前时区的中国当地时间为上午8时,手动选择时区调整为GMT+0:00则当前系统时间也会变为0时,即存在8小时偏移。

1、recovery.c(bootable\recovery)

增加一下内容:

#include <linux/rtc.h>
#include <sys/ioctl.h>
static void set_rtc(void) {
    struct tm tm;
    int fd;

    tm.tm_sec = 0;
    tm.tm_min = 0;
    tm.tm_hour = 16;
    tm.tm_mday = 31;
    tm.tm_mon = 11;
    tm.tm_year = 2012-1900;
              
    fd = open("/dev/rtc0", O_WRONLY);
    if (fd != -1) {
        ioctl(fd, RTC_SET_TIME, &tm);
        close(fd);
    }
}

在int
main(int argc, char **argv)下

else if (wipe_data) {

        //在此增加set_rtc();
        set_rtc();

        if (device_wipe_data()) status = INSTALL_ERROR;
        if (erase_volume("/data")) status = INSTALL_ERROR;
        if (wipe_cache && erase_volume("/cache")) status = INSTALL_ERROR;
        if (status != INSTALL_SUCCESS) ui_print("Data wipe failed.\n");
    }
发布了6 篇原创文章 · 获赞 2 · 访问量 1074

猜你喜欢

转载自blog.csdn.net/thonmin/article/details/43525705