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