3 #include <linux/types.h>
4 #include <asm/arch/bits.h>
5 #include <linux/string.h>
6 #include <android_bootimg.h>
7 #include <linux/mtd/mtd.h>
8 #include <linux/mtd/nand.h>
10 #include <android_boot.h>
11 #include <environment.h>
12 #include <jffs2/jffs2.h>
13 #include <boot_mode.h>
16 #define msleep(a) udelay(a * 1000)
17 #define PROD_PART "prodnv"
19 extern void sprd_rtc_init(void);
20 extern void sprd_rtc_set_alarm_sec(unsigned long secs);
21 extern unsigned long sprd_rtc_get_alarm_sec(void);
22 extern unsigned long sprd_rtc_get_sec(void);
23 extern int sprd_is_poweroff_alarm(void);
25 int alarm_file_check(char *time_buf)
27 if(!do_fs_file_read(PROD_PART, "/alarm_flag", time_buf,200)){
34 int poweron_file_check(char *time_buf)
36 if(!do_fs_file_read(PROD_PART, "/poweron_timeinmillis", time_buf,200)){
45 printf("%s\n", __func__);
48 vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=alarm", BACKLIGHT_OFF);
50 vlx_nand_boot(BOOT_PART, "androidboot.mode=alarm", BACKLIGHT_OFF);
55 static void uboot_rtc_set_alarm_sec(unsigned long secs)
58 unsigned long read_secs;
59 sprd_rtc_set_alarm_sec(secs);
63 sprd_rtc_set_alarm_sec(secs);
66 read_secs = sprd_rtc_get_alarm_sec();
69 }while(read_secs != secs && i < 100);
73 int alarm_flag_check(void)
75 if (sprd_is_poweroff_alarm())
82 int alarm_flag_check(void)
84 int ret = -1,ret1 = -1;
87 unsigned long time_rtc= 0;
88 unsigned long time_rtc1= 0;
89 unsigned long now_rtc = 0;
91 char time_buf[200]={0};
92 char time_buf1[200]={0};
94 memset(time_buf,0x0,200);
95 memset(time_buf1,0x0,200);
97 ret = alarm_file_check(time_buf);
99 printf("file: alarm_flag exist\n");
100 printf("time get %s", time_buf);
101 time = simple_strtol(time_buf, NULL, 10);
104 ret1 = poweron_file_check(time_buf1);
106 printf("file: poweron_timeinmillis exist\n");
107 printf("time get %s", time_buf1);
108 time1 = simple_strtol(time_buf1, NULL, 10);
112 now_rtc = sprd_rtc_get_sec();
113 printf("now rtc %lu\n", now_rtc);
114 time_lead = get_alarm_lead_set();
115 time = time - now_rtc;
116 time1 = time1 - now_rtc;
117 if((time < time_lead +180) && (time > time_lead -10))
119 if((time1 < time_lead +180) && (time1 > time_lead -10)&& (time -time1>50))
124 else if((time1 < time_lead +180) && (time1 > time_lead -10))
127 if (ret == -1&& ret1== -1) {
128 printf("file: all not found\n");
130 uboot_rtc_set_alarm_sec(time_rtc);
132 uboot_rtc_set_alarm_sec(time_rtc1);
134 if(time_rtc1 > time_rtc){
135 uboot_rtc_set_alarm_sec(time_rtc);
137 uboot_rtc_set_alarm_sec(time_rtc1);