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 int do_fs_file_read(char *mpart, char *filenm, void *buf, int len);
20 extern unsigned int get_alarm_lead_set(void);
21 extern void sprd_rtc_init(void);
22 extern void sprd_rtc_set_alarm_sec(unsigned long secs);
23 extern unsigned long sprd_rtc_get_alarm_sec(void);
24 extern unsigned long sprd_rtc_get_sec(void);
25 extern int sprd_is_poweroff_alarm(void);
27 int alarm_file_check(char *time_buf)
29 if(!do_fs_file_read(PROD_PART, "/alarm_flag", time_buf,200)){
36 int poweron_file_check(char *time_buf)
38 if(!do_fs_file_read(PROD_PART, "/poweron_timeinmillis", time_buf,200)){
47 printf("%s\n", __func__);
50 vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=alarm", BACKLIGHT_OFF);
52 vlx_nand_boot(BOOT_PART, "androidboot.mode=alarm", BACKLIGHT_OFF);
57 static void uboot_rtc_set_alarm_sec(unsigned long secs)
60 unsigned long read_secs;
61 sprd_rtc_set_alarm_sec(secs);
65 sprd_rtc_set_alarm_sec(secs);
68 read_secs = sprd_rtc_get_alarm_sec();
71 }while(read_secs != secs && i < 100);
75 int alarm_flag_check(void)
77 if (sprd_is_poweroff_alarm())
84 int alarm_flag_check(void)
86 int ret = -1,ret1 = -1;
89 unsigned long time_rtc= 0;
90 unsigned long time_rtc1= 0;
91 unsigned long now_rtc = 0;
93 char time_buf[200]={0};
94 char time_buf1[200]={0};
96 memset(time_buf,0x0,200);
97 memset(time_buf1,0x0,200);
99 ret = alarm_file_check(time_buf);
101 printf("file: alarm_flag exist\n");
102 printf("time get %s", time_buf);
103 time = simple_strtol(time_buf, NULL, 10);
106 ret1 = poweron_file_check(time_buf1);
108 printf("file: poweron_timeinmillis exist\n");
109 printf("time get %s", time_buf1);
110 time1 = simple_strtol(time_buf1, NULL, 10);
114 now_rtc = sprd_rtc_get_sec();
115 printf("now rtc %lu\n", now_rtc);
116 time_lead = get_alarm_lead_set();
117 time = time - now_rtc;
118 time1 = time1 - now_rtc;
119 if((time < time_lead +180) && (time > time_lead -10))
121 if((time1 < time_lead +180) && (time1 > time_lead -10)&& (time -time1>50))
126 else if((time1 < time_lead +180) && (time1 > time_lead -10))
129 if (ret == -1&& ret1== -1) {
130 printf("file: all not found\n");
132 uboot_rtc_set_alarm_sec(time_rtc);
134 uboot_rtc_set_alarm_sec(time_rtc1);
136 if(time_rtc1 > time_rtc){
137 uboot_rtc_set_alarm_sec(time_rtc);
139 uboot_rtc_set_alarm_sec(time_rtc1);