tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / property / normal_mode.c
1 #include "normal_mode.h"
2 #include "calibration_detect.h"
3 #include <mmc.h>
4 #include <fat.h>
5 #include <asm/arch/sprd_reg.h>
6 #ifdef CONFIG_ARCH_SCX35L       //only for sharkL branch modem boot process
7 #include <asm/arch/cp_boot.h>
8 #endif
9 #if defined(CONFIG_OF_LIBFDT)
10 #include <libfdt.h>
11 #include <fdt_support.h>
12 #endif
13
14 #ifdef CONFIG_TIZEN
15 #include "tizen_misc.h"
16 #endif
17
18 #include <common.h>
19 DECLARE_GLOBAL_DATA_PTR;
20
21 //#define SPRD_BM_UBOOT_SET
22 #define FACTORY_PART "prodnv"
23 #define CMDLINE_BUF_SIZE        (1024)
24
25 unsigned spl_data_buf[0x2000] __attribute__ ((align(4))) = {
26 0};
27
28 unsigned harsh_data_buf[8] __attribute__ ((align(4))) = {
29 0};
30
31 void *spl_data = spl_data_buf;
32 void *harsh_data = harsh_data_buf;
33 unsigned char raw_header[8192];
34 const int SP09_MAX_PHASE_BUFF_SIZE = sizeof(SP09_PHASE_CHECK_T);
35 unsigned int g_charger_mode = 0;
36 char serial_number_to_transfer[SP09_MAX_SN_LEN];
37
38 extern int charger_connected(void);
39
40 extern void *lcd_base;
41 #ifdef CONFIG_OF_LIBFDT
42 static char boot_cmd[64];
43 #endif
44
45 #ifdef SPRD_BM_UBOOT_SET
46 /**
47  *      sprd_bm_set_uboot_reg - set uboot bus monitor reg
48  *      How to use this interface.:
49  *      1. set the channel config you want to monitor the mem, e.g, channel 0-9, bm_cnt=0, bm_cnt<10.
50  *      2. set the addr range, e.g 80000000-90000000,
51  *              0x30040008 + bm_cnt * 0x10000) = 0x80000000;
52  *              0x3004000C + bm_cnt * 0x10000) = 0x90000000;
53  *      3. if you want mask the addr, just like the following code.
54  *      4. please do not change others reg.
55  *      5. if you make this config active, you must disable the bus monitor in kernel side.
56  */
57 static void sprd_bm_set_uboot_reg(void)
58 {
59         u8 bm_cnt;
60         for (bm_cnt = 0; bm_cnt < 10; bm_cnt++) {
61                 //if((bm_cnt == 5)||(bm_cnt == 6))//||(bm_cnt == 0)||(bm_cnt == 1)||(bm_cnt == 3))
62                 //      continue;
63                 *(volatile u32 *)(0x30040000 + bm_cnt * 0x10000) = 0x20000001;
64                 *(volatile u32 *)(0x30040000 + bm_cnt * 0x10000) = 0x10000001;
65                 *(volatile u32 *)(0x30040004 + bm_cnt * 0x10000) = 0x00000003;
66                 *(volatile u32 *)(0x30040008 + bm_cnt * 0x10000) = 0x00620000;
67                 *(volatile u32 *)(0x3004000c + bm_cnt * 0x10000) = 0x077ffffc;
68                 *(volatile u32 *)(0x30040010 + bm_cnt * 0x10000) = 0xC0000000;
69                 *(volatile u32 *)(0x30040014 + bm_cnt * 0x10000) = 0x0FFFFFFF;
70                 *(volatile u32 *)(0x30040018 + bm_cnt * 0x10000) = 0x0FFFFFFF;
71                 *(volatile u32 *)(0x3004001c + bm_cnt * 0x10000) = 0x00000000;
72                 *(volatile u32 *)(0x30040020 + bm_cnt * 0x10000) = 0x00000000;
73                 *(volatile u32 *)(0x30040024 + bm_cnt * 0x10000) = 0x00000000;
74                 *(volatile u32 *)(0x30040028 + bm_cnt * 0x10000) = 0x00000000;
75                 *(volatile u32 *)(0x3004002c + bm_cnt * 0x10000) = 0x00000000;
76                 *(volatile u32 *)(0x30040030 + bm_cnt * 0x10000) = 0x00000000;
77                 *(volatile u32 *)(0x30040034 + bm_cnt * 0x10000) = 0x00000000;
78                 *(volatile u32 *)(0x30040038 + bm_cnt * 0x10000) = 0x00000000;
79                 *(volatile u32 *)(0x3004003c + bm_cnt * 0x10000) = 0x00000000;
80                 *(volatile u32 *)(0x30040040 + bm_cnt * 0x10000) = 0x00000000;
81         }
82 }
83 #endif
84
85 unsigned short calc_checksum(unsigned char *dat, unsigned long len)
86 {
87         unsigned short num = 0;
88         unsigned long chkSum = 0;
89         while (len > 1) {
90                 num = (unsigned short)(*dat);
91                 dat++;
92                 num |= (((unsigned short)(*dat)) << 8);
93                 dat++;
94                 chkSum += (unsigned long)num;
95                 len -= 2;
96         }
97         if (len) {
98                 chkSum += *dat;
99         }
100         chkSum = (chkSum >> 16) + (chkSum & 0xffff);
101         chkSum += (chkSum >> 16);
102         return (~chkSum);
103 }
104
105 unsigned char _chkNVEcc(uint8_t * buf, uint32_t size, uint32_t checksum)
106 {
107         uint16_t crc;
108
109         crc = calc_checksum(buf, size);
110         debugf("_chkNVEcc calcout 0x%lx, org 0x%llx\n", crc, checksum);
111         return (crc == (uint16_t) checksum);
112 }
113
114 #ifdef CONFIG_SECURE_BOOT
115 //#define PRIMPUKPATH "/dev/block/mmcblk0boot0"
116 //#define PRIMPUKSTART 512
117 //#define PRIMPUKLEN 260
118 void fdt_secureboot_param(fdt_blob)
119 {
120
121         char *buf = NULL;
122         int str_len = 0;
123         buf = malloc(CMDLINE_BUF_SIZE);
124         memset(buf, 0, CMDLINE_BUF_SIZE);
125
126 #ifdef PRIMPUKPATH
127         str_len = strlen(buf);
128         sprintf(&buf[str_len], " primpukpath=%s", PRIMPUKPATH); //"/dev/block/mmcblk0boot0");
129         str_len = strlen(buf);
130         buf[str_len] = '\0';
131 #endif
132 #ifdef PRIMPUKSTART
133         str_len = strlen(buf);
134         sprintf(&buf[str_len], " primpukstart=%d", PRIMPUKSTART);       //512);
135         str_len = strlen(buf);
136         buf[str_len] = '\0';
137 #endif
138 #ifdef PRIMPUKLEN
139         str_len = strlen(buf);
140         sprintf(&buf[str_len], " primpuklen=%d", PRIMPUKLEN);   //260);
141         str_len = strlen(buf);
142         buf[str_len] = '\0';
143 #endif
144         /*hash write by pc tool,but the hash value calculated by u-boot */
145         /*if rom secure enable,do not need cal spl hash and pass to kernel */
146         if (!secureboot_enabled()) {
147
148         int ret = get_spl_hash(harsh_data);
149         if (ret) {
150                 str_len = strlen(buf);
151                 sprintf(&buf[str_len], " securesha1=%08x%08x%08x%08x%08x", *(uint32_t *) harsh_data, *(uint32_t *) (harsh_data + 4),
152                         *(uint32_t *) (harsh_data + 8), *(uint32_t *) (harsh_data + 12), *(uint32_t *) (harsh_data + 16));
153                 str_len = strlen(buf);
154                 buf[str_len] = '\0';
155         }
156 }
157         fdt_chosen_bootargs_append(fdt_blob, buf, 1);
158 }
159 #endif
160
161 #ifdef CONFIG_TIZEN
162 int fdt_fixup_for_tizen(void *fdt)
163 {
164         char buf[1024];
165         unsigned char uid[16];
166         int ret, nodeoffset, str_len;
167         char *ptr = buf;
168         char *s;
169         unsigned int val;
170         struct mmc *mmc;
171
172         /* Tizen default cmdline: mem */
173         ptr += sprintf(ptr, CMDLINE_DEFAULT_TIZEN);
174
175         val = tizen_get_part_num(PARTS_ROOTFS);
176         ptr += sprintf(ptr, " root=/dev/mmcblk0p%d ro rootfstype=ext4 rootwait", val);
177
178         ptr += sprintf(ptr, " lcd_id=ID%06x", load_lcd_id_to_kernel());
179         ptr += sprintf(ptr, " lcd_base=%x", CONFIG_FB_RAM_BASE);
180
181         /* check ramdisk_size */
182         ptr += sprintf(ptr, " initrd=0x%x,0x%x", RAMDISK_ADR, 0);
183
184         ptr += sprintf(ptr, " mtp_offset=%s", load_mtp_offset_to_kernel());
185         ptr += sprintf(ptr, " elvss_offset=0x%x", load_elvss_offset_to_kernel());
186         ptr += sprintf(ptr, " hbm_offset=%s", load_hbm_offset_to_kernel());
187
188         ptr += sprintf(ptr, " wfixnv=0x%x,0x%x", WFIXNV_ADR, FIXNV_SIZE);
189         ptr += sprintf(ptr, " wruntimenv=0x%x,0x%x", WRUNTIMENV_ADR, RUNTIMENV_SIZE);
190
191         switch (check_pm_status()) {
192         case PM_STATE_LPM:
193                 ptr += sprintf(ptr, " systemd.unit=charging-mode.target");
194                 /* Write Charger state */
195                 *(volatile unsigned int *)0xFC8 = 0x03;
196                 sprdchg_start_charge();
197                 break;
198         case PM_STATE_NORMAL:
199         default:
200                 ptr += sprintf(ptr, " bootmode=normal");
201         }
202         thor_save_env("normal");
203
204         s = getenv("hw_revision");
205         if (s != NULL)
206                 val = (u32) simple_strtoul(s, NULL, 10);
207         else
208                 val = 0;
209         ptr += sprintf(ptr, " hw_revision=%d", val);
210
211         s = getenv("muic_rustproof");
212         if (s != NULL)
213                 val = (u32) simple_strtoul(s, NULL, 10);
214         else
215                 val = 0;
216         ptr += sprintf(ptr, " muic_rustproof=%d", val);
217
218         s = getenv("dbg_level");
219         if (s && (*s == 'a')) {
220                 ptr += sprintf(ptr, " sec_debug.enable=1");
221                 ptr += sprintf(ptr, " sec_debug.enable_user=0");
222         } else if (s && (*s == 'h')) {
223                 ptr += sprintf(ptr, " sec_debug.enable=1");
224                 ptr += sprintf(ptr, " sec_debug.enable_user=1");
225         } else if (s && (*s == 'm')) {
226                 ptr += sprintf(ptr, " sec_debug.enable=1");
227                 ptr += sprintf(ptr, " sec_debug.enable_user=0");
228         } else {
229                 ptr += sprintf(ptr, " sec_debug.enable=0");
230                 ptr += sprintf(ptr, " sec_debug.enable_user=0");
231         }
232
233         if (tizen_get_jig_state() == 2) {
234                 s = getenv("console");
235                 if (s && (*s == 'o'))
236                         ptr += sprintf(ptr, " console=ttyS1,115200n8 loglevel=7");
237                 else
238                         ptr += sprintf(ptr, " console=ram loglevel=0");
239         } else {
240                         ptr += sprintf(ptr, " console=ram loglevel=0");
241         }
242
243         s = getenv("sec_log");
244         if (s && (*s == 'o')) {
245                 if (s = getenv("sec_log_addr")) {
246                         val = (u32) simple_strtoul(s, NULL, 16);
247                         ptr += sprintf(ptr, " sec_log=0x%x@0x%x", SEC_LOG_LENGTH, val);
248                 }
249         }
250
251         ptr += sprintf(ptr, " bootloader.ver=%s", CONFIG_BOOTLOADER_VER);
252
253         s = getenv("emmc_checksum");
254         if (s != NULL)
255                 val = (u32) simple_strtoul(s, NULL, 10);
256         else
257                 val = 0;
258
259         ptr += sprintf(ptr, " tizenboot.emmc_checksum=%d", val);
260
261         ptr += sprintf(ptr, " mem_cs=%d, mem_cs0_sz=%08x",get_dram_cs_number(), get_dram_cs0_size());
262
263         /* TODO: connie, cordon */
264         /* connie, cordon */
265         /* toss ddi value for sysscope */
266         //      set_system_info(CONFIG_MODEL_NAME, CONFIG_OPERATOR, CONFIG_REGION, VT_SPRD, 16);
267         //      ptr += sprintf(ptr, " connie=%s", get_conniecmdline_value());
268         //      ptr += sprintf(ptr, " cordon=%s", get_ddicmdline_value());
269
270         tizen_get_emmc_serial_number((unsigned int *)uid);
271         ptr += sprintf(ptr, " tizenboot.serialno=%x%08x",
272                         *(unsigned int *)(uid + 8), *(unsigned int *)(uid + 12));
273
274         /* if is uart calibraton, remove ttys1 console */
275         if (is_calibration_by_uart())
276                 val = 1;
277         else
278                 val = 0;
279
280         ptr += sprintf(ptr, " calmode=%d", is_calibration_by_uart());
281         ptr += sprintf(ptr, " fgu_init=%d,%d", get_fgu_vol(), get_fgu_cur());
282
283         str_len = strlen(buf);
284         buf[str_len] = '\0';
285
286         nodeoffset = fdt_path_offset (fdt, "/chosen");
287         ret = fdt_setprop_string(fdt, nodeoffset, "bootargs", buf);
288         return ret;
289 }
290 #endif
291
292 /*FDT_ADD_SIZE used to describe the size of the new bootargs items*/
293 /*include lcd id, lcd base, etc*/
294 #define FDT_ADD_SIZE (1024)
295 static int start_linux()
296 {
297         void (*theKernel) (int zero, int arch, u32 params);
298         u32 exec_at = (u32) - 1;
299         u32 parm_at = (u32) - 1;
300         u32 machine_type;
301         u8 *fdt_blob;
302         u32 fdt_size;
303         boot_img_hdr *hdr = raw_header;
304         int err;
305
306         machine_type = machine_arch_type;       /* get machine type */
307         machine_type = 2014;    /* get machine type */
308         theKernel = (void (*)(int, int, u32))KERNEL_ADR;        /* set the kernel address */
309 #if !(defined(CONFIG_SC8830) || defined(CONFIG_SC9630))
310         *(volatile u32 *)0x84001000 = 'j';
311         *(volatile u32 *)0x84001000 = 'm';
312         *(volatile u32 *)0x84001000 = 'p';
313 #endif
314
315 #ifdef CONFIG_OF_LIBFDT
316         fdt_blob = (u8 *) DT_ADR;
317         if (fdt_check_header(fdt_blob) != 0) {
318                 printk("image is not a fdt\n");
319         }
320         fdt_size = fdt_totalsize(fdt_blob);
321
322         err = fdt_open_into(fdt_blob, fdt_blob, fdt_size + FDT_ADD_SIZE);
323         if (err != 0) {
324                 printf("libfdt fdt_open_into(): %s\n", fdt_strerror(err));
325         }
326
327 #ifdef CONFIG_TIZEN
328         load_nvitem();
329         load_modem_data();
330         load_dsp_data();
331
332         sipc_addr_reset();
333         modem_entry();
334
335         fdt_fixup_for_tizen(fdt_blob);
336 #ifdef CONFIG_EMMC_BOOT
337         Emmc_DisSdClk();
338 #endif
339
340         theKernel(0, machine_type, (unsigned long)fdt_blob);
341         while (1);
342 #endif  /* CONFIG_TIZEN */
343
344 //#else
345 //      fdt_initrd_norsvmem(fdt_blob, RAMDISK_ADR, RAMDISK_ADR + hdr->ramdisk_size, 1);
346         fdt_fixup_lcdid(fdt_blob);
347         fdt_fixup_lcdbase(fdt_blob);
348         fdt_fixup_calibration_parameter(fdt_blob);
349         fdt_fixup_serialno(fdt_blob);
350         fdt_fixup_adc_calibration_data(fdt_blob);
351         fdt_fixup_dram_training(fdt_blob);
352         fdt_fixup_ddr_size(fdt_blob);
353 #ifdef CONFIG_SECURE_BOOT
354         fdt_secureboot_param(fdt_blob);
355 #endif
356 #ifndef CONFIG_EMMC_BOOT
357         fdt_fixup_mtd(fdt_blob);
358 #endif
359         debugf("start_linux boot_cmd: %s\n", boot_cmd);
360         fdt_fixup_boot_mode(fdt_blob, boot_cmd);
361         fdt_fixup_boot_ram_log(fdt_blob);
362         fdt_fixup_chosen_bootargs_board_private(fdt_blob, boot_cmd);
363 #ifdef SPRD_BM_UBOOT_SET
364         sprd_bm_set_uboot_reg();
365 #endif
366         // start modem CP
367         modem_entry();
368 #ifdef CONFIG_EMMC_BOOT
369         Emmc_DisSdClk();
370 #endif
371         theKernel(0, machine_type, (unsigned long)fdt_blob);
372 #else   /* CONFIG_OF_LIBFDT */
373         // start modem CP
374         modem_entry();
375 #ifdef CONFIG_EMMC_BOOT
376         Emmc_DisSdClk();
377 #endif
378         theKernel(0, machine_type, DT_ADR);     /* jump to kernel with register set */
379 #endif
380
381         while (1);
382         return 0;
383 }
384
385 void lcd_display_logo(int backlight_set, ulong bmp_img, size_t size)
386 {
387 #define mdelay(t)     ({unsigned long msec=(t); while (msec--) { udelay(1000);}})       //LiWei add
388 #ifdef CONFIG_SPLASH_SCREEN
389         extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
390         extern void lcd_display(void);
391         extern void *lcd_base;
392         extern void Dcache_CleanRegion(unsigned int addr, unsigned int length);
393         extern void set_backlight(uint32_t value);
394         if (backlight_set == BACKLIGHT_ON) {
395                 lcd_display_bitmap((ulong) bmp_img, 0, 0);
396 #if defined(CONFIG_SC8810) || defined(CONFIG_SC8825) || defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
397                 Dcache_CleanRegion((unsigned int)(lcd_base), size << 1);        //Size is to large.
398 #endif
399                 lcd_display();
400 #ifdef CONFIG_SC8830_LVDS
401                 mdelay(50);     //LiWei add
402 #endif
403                 mdelay(50);
404                 set_backlight(255);
405         } else {
406                 memset((unsigned int)lcd_base, 0, size);
407 #if defined(CONFIG_SC8810) || defined(CONFIG_SC8825) || defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
408                 Dcache_CleanRegion((unsigned int)(lcd_base), size << 1);        //Size is to large.
409 #endif
410                 lcd_display();
411         }
412 #endif
413 }
414
415 int is_factorymode()
416 {
417         char factorymode_falg[8] = { 0 };
418         int ret = 0;
419
420         if (do_fs_file_read(FACTORY_PART, "/factorymode.file", factorymode_falg, 8))
421                 return 0;
422         debugf("Checking factorymode :  factorymode_falg = %s \n", factorymode_falg);
423         if (!strcmp(factorymode_falg, "1"))
424                 ret = 1;
425         else
426                 ret = 0;
427         debugf("Checking factorymode :  ret = %d \n", ret);
428         return ret;
429 }
430
431 char *get_product_sn(void)
432 {
433         SP09_PHASE_CHECK_T phase_check;
434
435         memset(serial_number_to_transfer, 0x0, SP09_MAX_SN_LEN);
436
437         strcpy(serial_number_to_transfer, "0123456789ABCDEF");
438         if (do_raw_data_read(PRODUCTINFO_FILE_PATITION, sizeof(phase_check), 0, (char *)&phase_check)) {
439                 debugf("%s: read miscdata error.\n", __func__);
440                 return serial_number_to_transfer;
441         }
442
443         if ((phase_check.Magic == SP09_SPPH_MAGIC_NUMBER) && strlen(phase_check.SN1)) {
444                 memcpy(serial_number_to_transfer, phase_check.SN1, SP09_MAX_SN_LEN);
445         }
446
447         return serial_number_to_transfer;
448 }
449
450 #ifdef CONFIG_OF_LIBFDT
451 static char *set_boot_mode(char *cmdline)
452 {
453         char *boot_mode_p = NULL;
454
455         memset(boot_cmd, 0, 64);
456         boot_mode_p = strstr(cmdline, "androidboot");
457         if (boot_mode_p) {
458                 if (strlen(boot_mode_p) > 64) {
459                         debugf("boot mode too long\n");
460                         return NULL;
461                 }
462                 strcpy(boot_cmd, boot_mode_p);
463         }
464         debugf("CONFIG_OF_LIBFDT cmdline %s boot_cmd %s\n", cmdline, boot_cmd);
465         return boot_cmd;
466 }
467
468 int cmdline_lte_mode(char *buf, int str_len)
469 {
470         int offset = str_len;
471 #ifdef CONFIG_SUPPORT_TDLTE
472         offset += sprintf(buf + offset, " ltemode=tcsfb");
473 #elif defined CONFIG_SUPPORT_WLTE
474         offset += sprintf(buf + offset, " ltemode=fcsfb");
475 #elif defined CONFIG_SUPPORT_LTE
476         offset += sprintf(buf + offset, " ltemode=lcsfb");
477 #endif
478         return offset;
479 }
480
481 #else
482
483 #ifndef CONFIG_FPGA
484 int cmdline_fixup_lcd(char *buf, int str_len)
485 {
486         extern uint32_t load_lcd_id_to_kernel();
487         uint32_t lcd_id;
488         int offset;
489
490         offset = str_len;
491         lcd_id = load_lcd_id_to_kernel();
492         //add lcd id
493         if (lcd_id) {
494                 offset += sprintf(buf + offset, " lcd_id=ID");
495                 offset += sprintf(buf + offset, "%x", lcd_id);
496         }
497         if (lcd_base != NULL) {
498                 //add lcd frame buffer base, length should be lcd w*h*2(RGB565)
499                 offset += sprintf(buf + offset, " lcd_base=");
500                 offset += sprintf(buf + offset, "%x", lcd_base);
501         }
502
503         return offset;
504 }
505 #endif
506
507 #ifdef USB_PHY_TUNE_VALUE
508 int cmdline_fixup_usb_phy_tune(char *buf, int str_len)
509 {
510         /*transfer this value to kernel usb_hw.c */
511         int offset = str_len;
512
513         offset += sprintf(buf + offset, " usb_phy_tune=");
514         offset += sprintf(buf + offset, "%x", USB_PHY_TUNE_VALUE);
515         //buf[offset] = '\0';
516
517         return offset;
518 }
519 #endif
520 int cmdline_fixup_factorymode(char *buf, int str_len)
521 {
522         int offset = str_len;
523
524         if (1 == is_factorymode()) {
525                 offset += sprintf(buf + offset, " factory=1");
526         }
527
528         return offset;
529 }
530
531 #if defined( CONFIG_AP_ADC_CALIBRATION)||defined(CONFIG_SC8830)||defined(CONFIG_SC9630)||(defined(CONFIG_SC8825) && (!(BOOT_NATIVE_LINUX)))
532 int cmdline_fixup_adc_data(char *buf, int str_len)
533 {
534         extern int read_adc_calibration_data(char *buffer, int size);
535         extern void CHG_SetADCCalTbl(unsigned int *adc_data);
536         int offset = str_len;
537         unsigned int *adc_data;
538
539         adc_data = malloc(64);
540         if (adc_data) {
541                 memset(adc_data, 0, 64);
542                 if (0 < read_adc_calibration_data(adc_data, 48)) {
543                         if (((adc_data[2] & 0xffff) < 4500) && ((adc_data[2] & 0xffff) > 3000) &&
544                             ((adc_data[3] & 0xffff) < 4500) && ((adc_data[3] & 0xffff) > 3000)) {
545                                 offset += sprintf(buf + offset, " adc_cal=%d,%d", adc_data[2], adc_data[3]);
546                         }
547                         /*just after fgu adc calibration,and no aux adc calibration,need save fgu adc parameters */
548                         if ((0x00000002 == adc_data[10]) && (0x00000002 & adc_data[11])) {
549                                 offset += sprintf(buf + offset, " fgu_cal=%d,%d,%d", adc_data[4], adc_data[5], adc_data[6]);
550                         }
551 #if (defined(CONFIG_SC8825) && (!(BOOT_NATIVE_LINUX)))
552                         CHG_SetADCCalTbl(adc_data);
553                         DCDC_Cal_ArmCore();
554 #endif
555                 }
556                 free(adc_data);
557         }
558
559         return offset;
560 }
561 #endif
562
563 int cmdline_fixup_harsh_data(char *buf, int str_len)
564 {
565         int offset = str_len;
566
567         if (0 != read_spldata()) {
568                 debugf("read_spldata failed\n");
569                 free(buf);
570                 return 0;
571         }
572         if (harsh_data == NULL) {
573                 debugf("harsh_data malloc failed\n");
574                 free(buf);
575                 return 0;
576         }
577         debugf("spl_data adr 0x%x harsh_data adr 0x%x\n", spl_data, harsh_data);
578         if (cal_md5(spl_data, CONFIG_SPL_LOAD_LEN, harsh_data)) {
579                 offset += sprintf(buf + offset, " securemd5=%08x%08x%08x%08x", *(uint32_t *) harsh_data, *(uint32_t *) (harsh_data + 4),
580                                   *(uint32_t *) (harsh_data + 8), *(uint32_t *) (harsh_data + 12));
581         }
582         return offset;
583 }
584
585 int cmdline_fixup_serialno(char *buf, int str_len)
586 {
587         int offset;
588         char *sn = get_product_sn();
589
590         offset = str_len;
591         offset += sprintf(buf + offset, " androidboot.serialno=%s", sn ? sn : "0123456789ABCDEF");
592
593         return offset;
594 }
595
596 #if defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
597 int cmdline_fixup_fgu(char *buf, int str_len)
598 {
599         extern unsigned int fgu_cur;
600         extern unsigned int fgu_vol;
601         int offset;
602
603         offset = str_len;
604         offset += sprintf(buf + offset, " fgu_init=%d,%d", fgu_vol, fgu_cur);
605
606         return offset;
607 }
608 #endif
609
610 int cmdline_fixup_apct_param(char *buf, int str_len)
611 {
612         extern long long lcd_init_time;
613         extern long long load_image_time;
614         int offset;
615
616         offset = str_len;
617         offset += sprintf(buf + offset, " lcd_init=%lld", lcd_init_time);
618         offset += sprintf(buf + offset, " load_image=%lld", load_image_time);
619         offset += sprintf(buf + offset, " pl_t=%lld", get_ticks());
620
621         return offset;
622 }
623 #endif
624
625 void cmdline_set_cp_cmdline(char *buf, int str_len)
626 {
627         char *nv_info;
628 #ifdef CONFIG_SUPPORT_TD
629         nv_info = (char *)(((volatile u32 *)CALIBRATION_FLAG));
630         sprintf(nv_info, buf);
631         nv_info[str_len] = '\0';
632         debugf("nv_info:[%08x]%s \n", nv_info, nv_info);
633 #endif
634 #ifdef CONFIG_SUPPORT_W
635         nv_info = (char *)((volatile u32 *)CALIBRATION_FLAG_WCDMA);
636         sprintf(nv_info, buf);
637         nv_info[str_len] = '\0';
638         debugf("nv_info:[%08x]%s \n", nv_info, nv_info);
639 #endif
640 #ifdef CONFIG_SC9630
641 #ifdef  CONFIG_CP0_ARM0_BOOT
642         nv_info = (char *)(((volatile u32 *)CALIBRATION_FLAG_CP0));
643         sprintf(nv_info, buf);
644         nv_info[str_len] = '\0';
645         debugf("nv_info:[%08x]%s \n", nv_info, nv_info);
646 #endif
647         nv_info = (char *)(((volatile u32 *)CALIBRATION_FLAG_CP1));
648         sprintf(nv_info, buf);
649         nv_info[str_len] = '\0';
650         debugf("nv_info:[%08x]%s \n", nv_info, nv_info);
651 #endif
652 }
653
654 int creat_cmdline(char *cmdline, boot_img_hdr * hdr)
655 {
656         char *buf;
657         int offset = 0;
658         int ret = 0;
659
660         if (cmdline == NULL) {
661                 return -1;
662         }
663         buf = malloc(CMDLINE_BUF_SIZE);
664         memset(buf, 0, CMDLINE_BUF_SIZE);
665
666 #ifdef CONFIG_OF_LIBFDT
667         if (set_boot_mode(cmdline)) {
668                 if (cmdline && cmdline[0]) {
669                         offset += sprintf(buf, " %s", cmdline);
670                 }
671 #ifdef CONFIG_AP_VERSION
672                 offset += sprintf(buf + offset, " apv=\"%s\"", CONFIG_AP_VERSION);
673 #endif
674                 offset = cmdline_lte_mode(buf, offset);
675                 cmdline_set_cp_cmdline(buf, offset);
676                 if (buf != NULL) {
677                         free(buf);
678                 }
679                 return 0;
680         } else {
681                 if (buf != NULL) {
682                         free(buf);
683                 }
684                 return -1;
685         }
686 #else
687
688 //      if (hdr) {
689 //              offset += sprintf(buf, "initrd=0x%x,0x%x", RAMDISK_ADR, hdr->ramdisk_size);
690 //      }
691 /* preset loop_per_jiffy */
692 #ifdef CONFIG_LOOP_PER_JIFFY
693         offset += sprintf(buf + offset, " lpj=%d", CONFIG_LOOP_PER_JIFFY);
694 #endif
695 #ifdef CONFIG_AP_VERSION
696         offset += sprintf(buf + offset, " apv=\"%s\"", CONFIG_AP_VERSION);
697 #endif
698         if (cmdline && cmdline[0]) {
699                 offset += sprintf(buf + offset, " %s", cmdline);
700         }
701 #ifndef CONFIG_FPGA
702         offset = cmdline_fixup_lcd(buf, offset);
703 #endif
704 #ifdef USB_PHY_TUNE_VALUE
705         offset = cmdline_fixup_usb_phy_tune(buf, offset);
706 #endif
707         offset = cmdline_fixup_factorymode(buf, offset);
708         offset += sprintf(buf + offset, " no_console_suspend");
709 #ifdef CONFIG_RAM_CONSOLE
710 /* Fill ram log base address and size to cmdline.
711 It will be used when assigning reserve memory in kernel and dump ram log*/
712         offset += sprintf(buf + offset, " boot_ram_log=%#010x,%#x", CONFIG_RAM_CONSOLE_START, CONFIG_RAM_CONSOLE_SIZE);
713 #endif
714         offset = cmdline_fixup_serialno(buf, offset);
715         ret = cmdline_fixup_harsh_data(buf, offset);
716         if (ret) {
717                 offset = ret;
718         } else {
719                 return -1;
720         }
721 #if defined(CONFIG_AP_ADC_CALIBRATION)||defined(CONFIG_SC8830) || defined(CONFIG_SC9630) || (defined(CONFIG_SC8825) && (!(BOOT_NATIVE_LINUX)))
722         offset = cmdline_fixup_adc_data(buf, offset);
723 #if defined(CONFIG_SC8830)
724         offset = cmdline_fixup_fgu(buf, offset);
725 #endif
726         offset = cmdline_fixup_apct_param(buf, offset);
727 #endif
728         cmdline_set_cp_cmdline(buf, offset);
729
730         debugf("cmdline_len = %d \n pass cmdline: %s \n", strlen(buf), buf);
731         creat_atags(VLX_TAG_ADDR, buf, NULL, 0);
732
733         if (buf != NULL) {
734                 free(buf);
735         }
736         return 0;
737 #endif
738 }
739
740 void vlx_entry()
741 {
742         /*down the device if charger disconnect during calibration detect. */
743         if (g_charger_mode && !charger_connected()) {
744                 g_charger_mode = 0;
745                 power_down_devices();
746                 while (1) ;
747         }
748 #if !(defined CONFIG_SC8810 || defined CONFIG_TIGER || defined CONFIG_SC8830) || (defined CONFIG_SC9630)
749         MMU_InvalideICACHEALL();
750 #endif
751
752 #if (defined CONFIG_SC8810) || (defined CONFIG_SC8825) || (defined CONFIG_SC8830) || (defined CONFIG_SC9630)
753         MMU_DisableIDCM();
754 #endif
755
756 #ifdef REBOOT_FUNCTION_INUBOOT
757         reboot_func();
758 #endif
759
760 #if BOOT_NATIVE_LINUX
761         start_linux();
762 #else
763         void (*entry) (void) = (void *)VMJALUNA_ADR;
764         entry();
765 #endif
766 }
767
768 void normal_mode(void)
769 {
770 #if defined (CONFIG_SC8810) || defined (CONFIG_SC8825) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
771         //MMU_Init(CONFIG_MMU_TABLE_ADDR);
772         vibrator_hw_init();
773 #endif
774         set_vibrator(1);
775
776 #ifndef UART_CONSOLE_SUPPORT
777 #ifdef CONFIG_SC7710G2
778         extern int serial1_SwitchToModem(void);
779         serial1_SwitchToModem();
780 #endif
781 #endif
782
783 #if BOOT_NATIVE_LINUX
784         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS, BACKLIGHT_ON);
785 #else
786         vlx_nand_boot(BOOT_PART, NULL, BACKLIGHT_ON);
787 #endif
788
789 }
790 void calibration_mode(void)
791 {
792         debugf("calibration_mode\n");
793 #if defined(BOOT_NATIVE_LINUX_MODEM)
794         vlx_nand_boot(RECOVERY_PART,calibration_cmd_buf, BACKLIGHT_OFF);
795 #else
796         vlx_nand_boot(BOOT_PART, calibration_cmd_buf, BACKLIGHT_OFF);
797 #endif
798 }
799 void autotest_mode(void)
800 {
801         debugf("autotest_mode\n");
802         vlx_nand_boot(BOOT_PART, calibration_cmd_buf, BACKLIGHT_OFF);
803 }
804
805 void special_mode(void)
806 {
807         debugf("special_mode\n");
808 #if BOOT_NATIVE_LINUX
809         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=special", BACKLIGHT_OFF);
810 #else
811         vlx_nand_boot(BOOT_PART, "androidboot.mode=special", BACKLIGHT_OFF);
812 #endif
813
814 }
815
816 void iq_mode(void)
817 {
818         debugf("iq_mode\n");
819 #if BOOT_NATIVE_LINUX
820         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=iq", BACKLIGHT_OFF);
821 #else
822         vlx_nand_boot(BOOT_PART, " androidboot.mode=iq", BACKLIGHT_OFF);
823 #endif
824
825 }
826
827 #ifdef CONFIG_GENERIC_MMC
828 #define MODEM_MEMORY_NAME "modem_memory.log"
829 #define MODEM_MEMORY_SIZE  (22 * 1024 * 1024)
830 #ifdef CONFIG_SC8810
831 #define MODEM_MEMORY_ADDR 0
832 #elif defined (CONFIG_SC8825) || defined (CONFIG_TIGER) || defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
833 #define MODEM_MEMORY_ADDR 0x80000000
834 #endif
835 #endif
836 void watchdog_mode(void)
837 {
838         debugf("watchdog_mode\n");
839 #if BOOT_NATIVE_LINUX
840         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=wdgreboot", BACKLIGHT_OFF);
841 #else
842         vlx_nand_boot(BOOT_PART, "androidboot.mode=wdgreboot", BACKLIGHT_OFF);
843 #endif
844 }
845
846 void unknow_reboot_mode(void)
847 {
848         debugf("unknow_reboot_mode\n");
849 #if BOOT_NATIVE_LINUX
850         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=unknowreboot", BACKLIGHT_OFF);
851 #else
852         vlx_nand_boot(BOOT_PART, "androidboot.mode=unknowreboot", BACKLIGHT_OFF);
853 #endif
854 }
855
856 void panic_reboot_mode(void)
857 {
858         debugf("%s\n", __func__);
859 #if BOOT_NATIVE_LINUX
860         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=panic", BACKLIGHT_OFF);
861 #else
862         vlx_nand_boot(BOOT_PART, "androidboot.mode=panic", BACKLIGHT_OFF);
863 #endif
864 }
865
866 #if BOOT_NATIVE_LINUX_MODEM
867
868 void sipc_addr_reset()
869 {
870 #ifdef CONFIG_SC8825
871         memset((void *)SIPC_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
872 #elif defined (CONFIG_SC8830)
873 #if defined(CONFIG_SUPPORT_TD) || defined(CONFIG_SC9620OPENPHONE) || defined(CONFIG_SC9620FPGA)
874         memset((void *)SIPC_TD_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
875
876 #elif defined(CONFIG_SUPPORT_W)
877
878         memset((void *)SIPC_WCDMA_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
879 #else
880 #ifndef CONFIG_NOT_BOOT_TD_MODEM
881         memset((void *)SIPC_TD_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
882 #endif
883 #ifndef CONFIG_NOT_BOOT_W_MODEM
884         memset((void *)SIPC_WCDMA_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
885 #endif
886 #endif
887 #ifdef CONFIG_SP8830WCN
888         memset((void *)SIPC_WCN_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
889 #endif
890 #endif
891
892 #ifdef CONFIG_SC9630
893 #ifdef CONFIG_CP0_ARM0_BOOT
894         memset((void *)SIPC_GGE_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
895 #endif
896         memset((void *)SIPC_LTE_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
897         memset((void *)SIPC_PMIC_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
898 #endif
899
900 }
901
902 #endif