tizen: add ramdisk bootmode with ramdisk config option
[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 #ifdef CONFIG_RAMDISK_BOOT
176         ptr += sprintf(ptr, " root=/dev/ram0 rw initrd=0x%x,%dM",
177                                 RAMDISK_ADR, RAMDISK_SIZE_MB);
178 #else
179         val = tizen_get_part_num(PARTS_ROOTFS);
180         ptr += sprintf(ptr, " root=/dev/mmcblk0p%d ro rootfstype=ext4 rootwait", val);
181         ptr += sprintf(ptr, " initrd=0x%x,0x%x", RAMDISK_ADR, 0);
182 #endif
183
184         ptr += sprintf(ptr, " lcd_id=ID%06x", load_lcd_id_to_kernel());
185         ptr += sprintf(ptr, " lcd_base=%x", CONFIG_FB_RAM_BASE);
186
187         ptr += sprintf(ptr, " mtp_offset=%s", load_mtp_offset_to_kernel());
188         ptr += sprintf(ptr, " elvss_offset=0x%x", load_elvss_offset_to_kernel());
189         ptr += sprintf(ptr, " hbm_offset=%s", load_hbm_offset_to_kernel());
190
191         ptr += sprintf(ptr, " wfixnv=0x%x,0x%x", WFIXNV_ADR, FIXNV_SIZE);
192         ptr += sprintf(ptr, " wruntimenv=0x%x,0x%x", WRUNTIMENV_ADR, RUNTIMENV_SIZE);
193
194         switch (check_pm_status()) {
195         case PM_STATE_LPM:
196                 ptr += sprintf(ptr, " systemd.unit=charging-mode.target");
197                 /* Write Charger state */
198                 *(volatile unsigned int *)0xFC8 = 0x03;
199                 sprdchg_start_charge();
200                 break;
201         case PM_STATE_NORMAL:
202         default:
203 #ifdef CONFIG_RAMDISK_BOOT
204                 ptr += sprintf(ptr, " bootmode=ramdisk");
205 #else
206                 ptr += sprintf(ptr, " bootmode=normal");
207 #endif
208         }
209         thor_save_env("normal");
210
211         s = getenv("hw_revision");
212         if (s != NULL)
213                 val = (u32) simple_strtoul(s, NULL, 10);
214         else
215                 val = 0;
216         ptr += sprintf(ptr, " hw_revision=%d", val);
217
218         s = getenv("muic_rustproof");
219         if (s != NULL)
220                 val = (u32) simple_strtoul(s, NULL, 10);
221         else
222                 val = 0;
223         ptr += sprintf(ptr, " muic_rustproof=%d", val);
224
225         s = getenv("dbg_level");
226         if (s && (*s == 'a')) {
227                 ptr += sprintf(ptr, " sec_debug.enable=1");
228                 ptr += sprintf(ptr, " sec_debug.enable_user=0");
229         } else if (s && (*s == 'h')) {
230                 ptr += sprintf(ptr, " sec_debug.enable=1");
231                 ptr += sprintf(ptr, " sec_debug.enable_user=1");
232         } else if (s && (*s == 'm')) {
233                 ptr += sprintf(ptr, " sec_debug.enable=1");
234                 ptr += sprintf(ptr, " sec_debug.enable_user=0");
235         } else {
236                 ptr += sprintf(ptr, " sec_debug.enable=0");
237                 ptr += sprintf(ptr, " sec_debug.enable_user=0");
238         }
239
240         if (tizen_get_jig_state() == 2) {
241                 s = getenv("console");
242                 if (s && (*s == 'o'))
243                         ptr += sprintf(ptr, " console=ttyS1,115200n8 loglevel=7");
244                 else
245                         ptr += sprintf(ptr, " console=ram loglevel=0");
246         } else {
247                         ptr += sprintf(ptr, " console=ram loglevel=0");
248         }
249
250         s = getenv("sec_log");
251         if (s && (*s == 'o')) {
252                 if (s = getenv("sec_log_addr")) {
253                         val = (u32) simple_strtoul(s, NULL, 16);
254                         ptr += sprintf(ptr, " sec_log=0x%x@0x%x", SEC_LOG_LENGTH, val);
255                 }
256         }
257
258         ptr += sprintf(ptr, " bootloader.ver=%s", CONFIG_BOOTLOADER_VER);
259
260         s = getenv("emmc_checksum");
261         if (s != NULL)
262                 val = (u32) simple_strtoul(s, NULL, 10);
263         else
264                 val = 0;
265
266         ptr += sprintf(ptr, " tizenboot.emmc_checksum=%d", val);
267
268         ptr += sprintf(ptr, " mem_cs=%d, mem_cs0_sz=%08x",get_dram_cs_number(), get_dram_cs0_size());
269
270         /* TODO: connie, cordon */
271         /* connie, cordon */
272         /* toss ddi value for sysscope */
273         //      set_system_info(CONFIG_MODEL_NAME, CONFIG_OPERATOR, CONFIG_REGION, VT_SPRD, 16);
274         //      ptr += sprintf(ptr, " connie=%s", get_conniecmdline_value());
275         //      ptr += sprintf(ptr, " cordon=%s", get_ddicmdline_value());
276
277         tizen_get_emmc_serial_number((unsigned int *)uid);
278         ptr += sprintf(ptr, " tizenboot.serialno=%x%08x",
279                         *(unsigned int *)(uid + 8), *(unsigned int *)(uid + 12));
280
281         /* if is uart calibraton, remove ttys1 console */
282         if (is_calibration_by_uart())
283                 val = 1;
284         else
285                 val = 0;
286
287         ptr += sprintf(ptr, " calmode=%d", is_calibration_by_uart());
288         ptr += sprintf(ptr, " fgu_init=%d,%d", get_fgu_vol(), get_fgu_cur());
289
290         str_len = strlen(buf);
291         buf[str_len] = '\0';
292
293         nodeoffset = fdt_path_offset (fdt, "/chosen");
294         ret = fdt_setprop_string(fdt, nodeoffset, "bootargs", buf);
295         return ret;
296 }
297 #endif
298
299 /*FDT_ADD_SIZE used to describe the size of the new bootargs items*/
300 /*include lcd id, lcd base, etc*/
301 #define FDT_ADD_SIZE (1024)
302 static int start_linux()
303 {
304         void (*theKernel) (int zero, int arch, u32 params);
305         u32 exec_at = (u32) - 1;
306         u32 parm_at = (u32) - 1;
307         u32 machine_type;
308         u8 *fdt_blob;
309         u32 fdt_size;
310         boot_img_hdr *hdr = raw_header;
311         int err;
312
313         machine_type = machine_arch_type;       /* get machine type */
314         machine_type = 2014;    /* get machine type */
315         theKernel = (void (*)(int, int, u32))KERNEL_ADR;        /* set the kernel address */
316 #if !(defined(CONFIG_SC8830) || defined(CONFIG_SC9630))
317         *(volatile u32 *)0x84001000 = 'j';
318         *(volatile u32 *)0x84001000 = 'm';
319         *(volatile u32 *)0x84001000 = 'p';
320 #endif
321
322 #ifdef CONFIG_OF_LIBFDT
323         fdt_blob = (u8 *) DT_ADR;
324         if (fdt_check_header(fdt_blob) != 0) {
325                 printk("image is not a fdt\n");
326         }
327         fdt_size = fdt_totalsize(fdt_blob);
328
329         err = fdt_open_into(fdt_blob, fdt_blob, fdt_size + FDT_ADD_SIZE);
330         if (err != 0) {
331                 printf("libfdt fdt_open_into(): %s\n", fdt_strerror(err));
332         }
333
334 #ifdef CONFIG_TIZEN
335         load_nvitem();
336         load_modem_data();
337         load_dsp_data();
338
339         sipc_addr_reset();
340         modem_entry();
341
342         fdt_fixup_for_tizen(fdt_blob);
343 #ifdef CONFIG_EMMC_BOOT
344         Emmc_DisSdClk();
345 #endif
346
347         theKernel(0, machine_type, (unsigned long)fdt_blob);
348         while (1);
349 #endif  /* CONFIG_TIZEN */
350
351 //#else
352 //      fdt_initrd_norsvmem(fdt_blob, RAMDISK_ADR, RAMDISK_ADR + hdr->ramdisk_size, 1);
353         fdt_fixup_lcdid(fdt_blob);
354         fdt_fixup_lcdbase(fdt_blob);
355         fdt_fixup_calibration_parameter(fdt_blob);
356         fdt_fixup_serialno(fdt_blob);
357         fdt_fixup_adc_calibration_data(fdt_blob);
358         fdt_fixup_dram_training(fdt_blob);
359         fdt_fixup_ddr_size(fdt_blob);
360 #ifdef CONFIG_SECURE_BOOT
361         fdt_secureboot_param(fdt_blob);
362 #endif
363 #ifndef CONFIG_EMMC_BOOT
364         fdt_fixup_mtd(fdt_blob);
365 #endif
366         debugf("start_linux boot_cmd: %s\n", boot_cmd);
367         fdt_fixup_boot_mode(fdt_blob, boot_cmd);
368         fdt_fixup_boot_ram_log(fdt_blob);
369         fdt_fixup_chosen_bootargs_board_private(fdt_blob, boot_cmd);
370 #ifdef SPRD_BM_UBOOT_SET
371         sprd_bm_set_uboot_reg();
372 #endif
373         // start modem CP
374         modem_entry();
375 #ifdef CONFIG_EMMC_BOOT
376         Emmc_DisSdClk();
377 #endif
378         theKernel(0, machine_type, (unsigned long)fdt_blob);
379 #else   /* CONFIG_OF_LIBFDT */
380         // start modem CP
381         modem_entry();
382 #ifdef CONFIG_EMMC_BOOT
383         Emmc_DisSdClk();
384 #endif
385         theKernel(0, machine_type, DT_ADR);     /* jump to kernel with register set */
386 #endif
387
388         while (1);
389         return 0;
390 }
391
392 void lcd_display_logo(int backlight_set, ulong bmp_img, size_t size)
393 {
394 #define mdelay(t)     ({unsigned long msec=(t); while (msec--) { udelay(1000);}})       //LiWei add
395 #ifdef CONFIG_SPLASH_SCREEN
396         extern int lcd_display_bitmap(ulong bmp_image, int x, int y);
397         extern void lcd_display(void);
398         extern void *lcd_base;
399         extern void Dcache_CleanRegion(unsigned int addr, unsigned int length);
400         extern void set_backlight(uint32_t value);
401         if (backlight_set == BACKLIGHT_ON) {
402                 lcd_display_bitmap((ulong) bmp_img, 0, 0);
403 #if defined(CONFIG_SC8810) || defined(CONFIG_SC8825) || defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
404                 Dcache_CleanRegion((unsigned int)(lcd_base), size << 1);        //Size is to large.
405 #endif
406                 lcd_display();
407 #ifdef CONFIG_SC8830_LVDS
408                 mdelay(50);     //LiWei add
409 #endif
410                 mdelay(50);
411                 set_backlight(255);
412         } else {
413                 memset((unsigned int)lcd_base, 0, size);
414 #if defined(CONFIG_SC8810) || defined(CONFIG_SC8825) || defined(CONFIG_SC8830) || defined(CONFIG_SC9630)
415                 Dcache_CleanRegion((unsigned int)(lcd_base), size << 1);        //Size is to large.
416 #endif
417                 lcd_display();
418         }
419 #endif
420 }
421
422 int is_factorymode()
423 {
424         char factorymode_falg[8] = { 0 };
425         int ret = 0;
426
427         if (do_fs_file_read(FACTORY_PART, "/factorymode.file", factorymode_falg, 8))
428                 return 0;
429         debugf("Checking factorymode :  factorymode_falg = %s \n", factorymode_falg);
430         if (!strcmp(factorymode_falg, "1"))
431                 ret = 1;
432         else
433                 ret = 0;
434         debugf("Checking factorymode :  ret = %d \n", ret);
435         return ret;
436 }
437
438 char *get_product_sn(void)
439 {
440         SP09_PHASE_CHECK_T phase_check;
441
442         memset(serial_number_to_transfer, 0x0, SP09_MAX_SN_LEN);
443
444         strcpy(serial_number_to_transfer, "0123456789ABCDEF");
445         if (do_raw_data_read(PRODUCTINFO_FILE_PATITION, sizeof(phase_check), 0, (char *)&phase_check)) {
446                 debugf("%s: read miscdata error.\n", __func__);
447                 return serial_number_to_transfer;
448         }
449
450         if ((phase_check.Magic == SP09_SPPH_MAGIC_NUMBER) && strlen(phase_check.SN1)) {
451                 memcpy(serial_number_to_transfer, phase_check.SN1, SP09_MAX_SN_LEN);
452         }
453
454         return serial_number_to_transfer;
455 }
456
457 #ifdef CONFIG_OF_LIBFDT
458 static char *set_boot_mode(char *cmdline)
459 {
460         char *boot_mode_p = NULL;
461
462         memset(boot_cmd, 0, 64);
463         boot_mode_p = strstr(cmdline, "androidboot");
464         if (boot_mode_p) {
465                 if (strlen(boot_mode_p) > 64) {
466                         debugf("boot mode too long\n");
467                         return NULL;
468                 }
469                 strcpy(boot_cmd, boot_mode_p);
470         }
471         debugf("CONFIG_OF_LIBFDT cmdline %s boot_cmd %s\n", cmdline, boot_cmd);
472         return boot_cmd;
473 }
474
475 int cmdline_lte_mode(char *buf, int str_len)
476 {
477         int offset = str_len;
478 #ifdef CONFIG_SUPPORT_TDLTE
479         offset += sprintf(buf + offset, " ltemode=tcsfb");
480 #elif defined CONFIG_SUPPORT_WLTE
481         offset += sprintf(buf + offset, " ltemode=fcsfb");
482 #elif defined CONFIG_SUPPORT_LTE
483         offset += sprintf(buf + offset, " ltemode=lcsfb");
484 #endif
485         return offset;
486 }
487
488 #else
489
490 #ifndef CONFIG_FPGA
491 int cmdline_fixup_lcd(char *buf, int str_len)
492 {
493         extern uint32_t load_lcd_id_to_kernel();
494         uint32_t lcd_id;
495         int offset;
496
497         offset = str_len;
498         lcd_id = load_lcd_id_to_kernel();
499         //add lcd id
500         if (lcd_id) {
501                 offset += sprintf(buf + offset, " lcd_id=ID");
502                 offset += sprintf(buf + offset, "%x", lcd_id);
503         }
504         if (lcd_base != NULL) {
505                 //add lcd frame buffer base, length should be lcd w*h*2(RGB565)
506                 offset += sprintf(buf + offset, " lcd_base=");
507                 offset += sprintf(buf + offset, "%x", lcd_base);
508         }
509
510         return offset;
511 }
512 #endif
513
514 #ifdef USB_PHY_TUNE_VALUE
515 int cmdline_fixup_usb_phy_tune(char *buf, int str_len)
516 {
517         /*transfer this value to kernel usb_hw.c */
518         int offset = str_len;
519
520         offset += sprintf(buf + offset, " usb_phy_tune=");
521         offset += sprintf(buf + offset, "%x", USB_PHY_TUNE_VALUE);
522         //buf[offset] = '\0';
523
524         return offset;
525 }
526 #endif
527 int cmdline_fixup_factorymode(char *buf, int str_len)
528 {
529         int offset = str_len;
530
531         if (1 == is_factorymode()) {
532                 offset += sprintf(buf + offset, " factory=1");
533         }
534
535         return offset;
536 }
537
538 #if defined( CONFIG_AP_ADC_CALIBRATION)||defined(CONFIG_SC8830)||defined(CONFIG_SC9630)||(defined(CONFIG_SC8825) && (!(BOOT_NATIVE_LINUX)))
539 int cmdline_fixup_adc_data(char *buf, int str_len)
540 {
541         extern int read_adc_calibration_data(char *buffer, int size);
542         extern void CHG_SetADCCalTbl(unsigned int *adc_data);
543         int offset = str_len;
544         unsigned int *adc_data;
545
546         adc_data = malloc(64);
547         if (adc_data) {
548                 memset(adc_data, 0, 64);
549                 if (0 < read_adc_calibration_data(adc_data, 48)) {
550                         if (((adc_data[2] & 0xffff) < 4500) && ((adc_data[2] & 0xffff) > 3000) &&
551                             ((adc_data[3] & 0xffff) < 4500) && ((adc_data[3] & 0xffff) > 3000)) {
552                                 offset += sprintf(buf + offset, " adc_cal=%d,%d", adc_data[2], adc_data[3]);
553                         }
554                         /*just after fgu adc calibration,and no aux adc calibration,need save fgu adc parameters */
555                         if ((0x00000002 == adc_data[10]) && (0x00000002 & adc_data[11])) {
556                                 offset += sprintf(buf + offset, " fgu_cal=%d,%d,%d", adc_data[4], adc_data[5], adc_data[6]);
557                         }
558 #if (defined(CONFIG_SC8825) && (!(BOOT_NATIVE_LINUX)))
559                         CHG_SetADCCalTbl(adc_data);
560                         DCDC_Cal_ArmCore();
561 #endif
562                 }
563                 free(adc_data);
564         }
565
566         return offset;
567 }
568 #endif
569
570 int cmdline_fixup_harsh_data(char *buf, int str_len)
571 {
572         int offset = str_len;
573
574         if (0 != read_spldata()) {
575                 debugf("read_spldata failed\n");
576                 free(buf);
577                 return 0;
578         }
579         if (harsh_data == NULL) {
580                 debugf("harsh_data malloc failed\n");
581                 free(buf);
582                 return 0;
583         }
584         debugf("spl_data adr 0x%x harsh_data adr 0x%x\n", spl_data, harsh_data);
585         if (cal_md5(spl_data, CONFIG_SPL_LOAD_LEN, harsh_data)) {
586                 offset += sprintf(buf + offset, " securemd5=%08x%08x%08x%08x", *(uint32_t *) harsh_data, *(uint32_t *) (harsh_data + 4),
587                                   *(uint32_t *) (harsh_data + 8), *(uint32_t *) (harsh_data + 12));
588         }
589         return offset;
590 }
591
592 int cmdline_fixup_serialno(char *buf, int str_len)
593 {
594         int offset;
595         char *sn = get_product_sn();
596
597         offset = str_len;
598         offset += sprintf(buf + offset, " androidboot.serialno=%s", sn ? sn : "0123456789ABCDEF");
599
600         return offset;
601 }
602
603 #if defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
604 int cmdline_fixup_fgu(char *buf, int str_len)
605 {
606         extern unsigned int fgu_cur;
607         extern unsigned int fgu_vol;
608         int offset;
609
610         offset = str_len;
611         offset += sprintf(buf + offset, " fgu_init=%d,%d", fgu_vol, fgu_cur);
612
613         return offset;
614 }
615 #endif
616
617 int cmdline_fixup_apct_param(char *buf, int str_len)
618 {
619         extern long long lcd_init_time;
620         extern long long load_image_time;
621         int offset;
622
623         offset = str_len;
624         offset += sprintf(buf + offset, " lcd_init=%lld", lcd_init_time);
625         offset += sprintf(buf + offset, " load_image=%lld", load_image_time);
626         offset += sprintf(buf + offset, " pl_t=%lld", get_ticks());
627
628         return offset;
629 }
630 #endif
631
632 void cmdline_set_cp_cmdline(char *buf, int str_len)
633 {
634         char *nv_info;
635 #ifdef CONFIG_SUPPORT_TD
636         nv_info = (char *)(((volatile u32 *)CALIBRATION_FLAG));
637         sprintf(nv_info, buf);
638         nv_info[str_len] = '\0';
639         debugf("nv_info:[%08x]%s \n", nv_info, nv_info);
640 #endif
641 #ifdef CONFIG_SUPPORT_W
642         nv_info = (char *)((volatile u32 *)CALIBRATION_FLAG_WCDMA);
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 #ifdef CONFIG_SC9630
648 #ifdef  CONFIG_CP0_ARM0_BOOT
649         nv_info = (char *)(((volatile u32 *)CALIBRATION_FLAG_CP0));
650         sprintf(nv_info, buf);
651         nv_info[str_len] = '\0';
652         debugf("nv_info:[%08x]%s \n", nv_info, nv_info);
653 #endif
654         nv_info = (char *)(((volatile u32 *)CALIBRATION_FLAG_CP1));
655         sprintf(nv_info, buf);
656         nv_info[str_len] = '\0';
657         debugf("nv_info:[%08x]%s \n", nv_info, nv_info);
658 #endif
659 }
660
661 int creat_cmdline(char *cmdline, boot_img_hdr * hdr)
662 {
663         char *buf;
664         int offset = 0;
665         int ret = 0;
666
667         if (cmdline == NULL) {
668                 return -1;
669         }
670         buf = malloc(CMDLINE_BUF_SIZE);
671         memset(buf, 0, CMDLINE_BUF_SIZE);
672
673 #ifdef CONFIG_OF_LIBFDT
674         if (set_boot_mode(cmdline)) {
675                 if (cmdline && cmdline[0]) {
676                         offset += sprintf(buf, " %s", cmdline);
677                 }
678 #ifdef CONFIG_AP_VERSION
679                 offset += sprintf(buf + offset, " apv=\"%s\"", CONFIG_AP_VERSION);
680 #endif
681                 offset = cmdline_lte_mode(buf, offset);
682                 cmdline_set_cp_cmdline(buf, offset);
683                 if (buf != NULL) {
684                         free(buf);
685                 }
686                 return 0;
687         } else {
688                 if (buf != NULL) {
689                         free(buf);
690                 }
691                 return -1;
692         }
693 #else
694
695 //      if (hdr) {
696 //              offset += sprintf(buf, "initrd=0x%x,0x%x", RAMDISK_ADR, hdr->ramdisk_size);
697 //      }
698 /* preset loop_per_jiffy */
699 #ifdef CONFIG_LOOP_PER_JIFFY
700         offset += sprintf(buf + offset, " lpj=%d", CONFIG_LOOP_PER_JIFFY);
701 #endif
702 #ifdef CONFIG_AP_VERSION
703         offset += sprintf(buf + offset, " apv=\"%s\"", CONFIG_AP_VERSION);
704 #endif
705         if (cmdline && cmdline[0]) {
706                 offset += sprintf(buf + offset, " %s", cmdline);
707         }
708 #ifndef CONFIG_FPGA
709         offset = cmdline_fixup_lcd(buf, offset);
710 #endif
711 #ifdef USB_PHY_TUNE_VALUE
712         offset = cmdline_fixup_usb_phy_tune(buf, offset);
713 #endif
714         offset = cmdline_fixup_factorymode(buf, offset);
715         offset += sprintf(buf + offset, " no_console_suspend");
716 #ifdef CONFIG_RAM_CONSOLE
717 /* Fill ram log base address and size to cmdline.
718 It will be used when assigning reserve memory in kernel and dump ram log*/
719         offset += sprintf(buf + offset, " boot_ram_log=%#010x,%#x", CONFIG_RAM_CONSOLE_START, CONFIG_RAM_CONSOLE_SIZE);
720 #endif
721         offset = cmdline_fixup_serialno(buf, offset);
722         ret = cmdline_fixup_harsh_data(buf, offset);
723         if (ret) {
724                 offset = ret;
725         } else {
726                 return -1;
727         }
728 #if defined(CONFIG_AP_ADC_CALIBRATION)||defined(CONFIG_SC8830) || defined(CONFIG_SC9630) || (defined(CONFIG_SC8825) && (!(BOOT_NATIVE_LINUX)))
729         offset = cmdline_fixup_adc_data(buf, offset);
730 #if defined(CONFIG_SC8830)
731         offset = cmdline_fixup_fgu(buf, offset);
732 #endif
733         offset = cmdline_fixup_apct_param(buf, offset);
734 #endif
735         cmdline_set_cp_cmdline(buf, offset);
736
737         debugf("cmdline_len = %d \n pass cmdline: %s \n", strlen(buf), buf);
738         creat_atags(VLX_TAG_ADDR, buf, NULL, 0);
739
740         if (buf != NULL) {
741                 free(buf);
742         }
743         return 0;
744 #endif
745 }
746
747 void vlx_entry()
748 {
749         /*down the device if charger disconnect during calibration detect. */
750         if (g_charger_mode && !charger_connected()) {
751                 g_charger_mode = 0;
752                 power_down_devices();
753                 while (1) ;
754         }
755 #if !(defined CONFIG_SC8810 || defined CONFIG_TIGER || defined CONFIG_SC8830) || (defined CONFIG_SC9630)
756         MMU_InvalideICACHEALL();
757 #endif
758
759 #if (defined CONFIG_SC8810) || (defined CONFIG_SC8825) || (defined CONFIG_SC8830) || (defined CONFIG_SC9630)
760         MMU_DisableIDCM();
761 #endif
762
763 #ifdef REBOOT_FUNCTION_INUBOOT
764         reboot_func();
765 #endif
766
767 #if BOOT_NATIVE_LINUX
768         start_linux();
769 #else
770         void (*entry) (void) = (void *)VMJALUNA_ADR;
771         entry();
772 #endif
773 }
774
775 void normal_mode(void)
776 {
777 #if defined (CONFIG_SC8810) || defined (CONFIG_SC8825) || defined (CONFIG_SC8830) || (defined CONFIG_SC9630)
778         //MMU_Init(CONFIG_MMU_TABLE_ADDR);
779         vibrator_hw_init();
780 #endif
781         set_vibrator(1);
782
783 #ifndef UART_CONSOLE_SUPPORT
784 #ifdef CONFIG_SC7710G2
785         extern int serial1_SwitchToModem(void);
786         serial1_SwitchToModem();
787 #endif
788 #endif
789
790 #if BOOT_NATIVE_LINUX
791         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS, BACKLIGHT_ON);
792 #else
793         vlx_nand_boot(BOOT_PART, NULL, BACKLIGHT_ON);
794 #endif
795
796 }
797 void calibration_mode(void)
798 {
799         debugf("calibration_mode\n");
800 #if defined(BOOT_NATIVE_LINUX_MODEM)
801         vlx_nand_boot(RECOVERY_PART,calibration_cmd_buf, BACKLIGHT_OFF);
802 #else
803         vlx_nand_boot(BOOT_PART, calibration_cmd_buf, BACKLIGHT_OFF);
804 #endif
805 }
806 void autotest_mode(void)
807 {
808         debugf("autotest_mode\n");
809         vlx_nand_boot(BOOT_PART, calibration_cmd_buf, BACKLIGHT_OFF);
810 }
811
812 void special_mode(void)
813 {
814         debugf("special_mode\n");
815 #if BOOT_NATIVE_LINUX
816         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=special", BACKLIGHT_OFF);
817 #else
818         vlx_nand_boot(BOOT_PART, "androidboot.mode=special", BACKLIGHT_OFF);
819 #endif
820
821 }
822
823 void iq_mode(void)
824 {
825         debugf("iq_mode\n");
826 #if BOOT_NATIVE_LINUX
827         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=iq", BACKLIGHT_OFF);
828 #else
829         vlx_nand_boot(BOOT_PART, " androidboot.mode=iq", BACKLIGHT_OFF);
830 #endif
831
832 }
833
834 #ifdef CONFIG_GENERIC_MMC
835 #define MODEM_MEMORY_NAME "modem_memory.log"
836 #define MODEM_MEMORY_SIZE  (22 * 1024 * 1024)
837 #ifdef CONFIG_SC8810
838 #define MODEM_MEMORY_ADDR 0
839 #elif defined (CONFIG_SC8825) || defined (CONFIG_TIGER) || defined(CONFIG_SC8830) || (defined CONFIG_SC9630)
840 #define MODEM_MEMORY_ADDR 0x80000000
841 #endif
842 #endif
843 void watchdog_mode(void)
844 {
845         debugf("watchdog_mode\n");
846 #if BOOT_NATIVE_LINUX
847         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=wdgreboot", BACKLIGHT_OFF);
848 #else
849         vlx_nand_boot(BOOT_PART, "androidboot.mode=wdgreboot", BACKLIGHT_OFF);
850 #endif
851 }
852
853 void unknow_reboot_mode(void)
854 {
855         debugf("unknow_reboot_mode\n");
856 #if BOOT_NATIVE_LINUX
857         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=unknowreboot", BACKLIGHT_OFF);
858 #else
859         vlx_nand_boot(BOOT_PART, "androidboot.mode=unknowreboot", BACKLIGHT_OFF);
860 #endif
861 }
862
863 void panic_reboot_mode(void)
864 {
865         debugf("%s\n", __func__);
866 #if BOOT_NATIVE_LINUX
867         vlx_nand_boot(BOOT_PART, CONFIG_BOOTARGS " androidboot.mode=panic", BACKLIGHT_OFF);
868 #else
869         vlx_nand_boot(BOOT_PART, "androidboot.mode=panic", BACKLIGHT_OFF);
870 #endif
871 }
872
873 #if BOOT_NATIVE_LINUX_MODEM
874
875 void sipc_addr_reset()
876 {
877 #ifdef CONFIG_SC8825
878         memset((void *)SIPC_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
879 #elif defined (CONFIG_SC8830)
880 #if defined(CONFIG_SUPPORT_TD) || defined(CONFIG_SC9620OPENPHONE) || defined(CONFIG_SC9620FPGA)
881         memset((void *)SIPC_TD_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
882
883 #elif defined(CONFIG_SUPPORT_W)
884
885         memset((void *)SIPC_WCDMA_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
886 #else
887 #ifndef CONFIG_NOT_BOOT_TD_MODEM
888         memset((void *)SIPC_TD_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
889 #endif
890 #ifndef CONFIG_NOT_BOOT_W_MODEM
891         memset((void *)SIPC_WCDMA_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
892 #endif
893 #endif
894 #ifdef CONFIG_SP8830WCN
895         memset((void *)SIPC_WCN_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
896 #endif
897 #endif
898
899 #ifdef CONFIG_SC9630
900 #ifdef CONFIG_CP0_ARM0_BOOT
901         memset((void *)SIPC_GGE_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
902 #endif
903         memset((void *)SIPC_LTE_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
904         memset((void *)SIPC_PMIC_APCP_START_ADDR, 0x0, SIPC_APCP_RESET_ADDR_SIZE);
905 #endif
906
907 }
908
909 #endif