tizen: add recovery boot mode
[profile/mobile/platform/kernel/u-boot-tm1.git] / property / normal_emc_mode.c
1 #include <config.h>
2 #include "normal_mode.h"
3 #include "../disk/part_uefi.h"
4 #include "../disk/part_efi.h"
5 #include "../drivers/mmc/card_sdio.h"
6 #include "asm/arch/sci_types.h"
7 #include <ext_common.h>
8 #include <ext4fs.h>
9 #ifdef CONFIG_SECURE_BOOT
10 #include <asm/arch/secure_boot.h>
11 #include "secure_verify.h"
12 #endif
13 #include <asm/arch/sprd_reg.h>
14 #ifdef CONFIG_ARCH_SCX35L       //only for sharkL branch modem boot process
15 #include <asm/arch/cp_boot.h>
16 #endif
17
18 #include "dev_tree.h"
19
20 #define KERNL_PAGE_SIZE 2048
21
22 long long load_image_time = 0;
23
24 #ifdef CONFIG_SUPPORT_TDLTE
25 static boot_image_required_t const s_boot_image_tl_table[] = {
26         {L"tl_fixnv1", L"tl_fixnv2", LTE_FIXNV_SIZE, LTE_FIXNV_ADDR},
27         {L"tl_runtimenv1", L"tl_runtimenv2", LTE_RUNNV_SIZE, LTE_RUNNV_ADDR},
28         {L"tl_modem", NULL, LTE_MODEM_SIZE, LTE_MODEM_ADDR},
29         {L"tl_ldsp", NULL, LTE_LDSP_SIZE, LTE_LDSP_ADDR},       //ltedsp
30         {L"tl_tgdsp", NULL, LTE_GDSP_SIZE, LTE_GDSP_ADDR},
31         {NULL, NULL, 0, 0}
32 };
33 #endif
34
35 #ifdef CONFIG_SUPPORT_WLTE
36 static boot_image_required_t const s_boot_image_wl_table[] = {
37         {L"wl_fixnv1", L"wl_fixnv2", LTE_FIXNV_SIZE, LTE_FIXNV_ADDR},
38         {L"wl_runtimenv1", L"wl_runtimenv2", LTE_RUNNV_SIZE, LTE_RUNNV_ADDR},
39         {L"wl_modem", NULL, LTE_MODEM_SIZE, LTE_MODEM_ADDR},
40         {L"wl_ldsp", NULL, LTE_LDSP_SIZE, LTE_LDSP_ADDR},
41         {L"wl_gdsp", NULL, LTE_GDSP_SIZE, LTE_GDSP_ADDR},
42         {L"wl_warm", NULL, WL_WARM_SIZE, WL_WARM_ADDR},
43         {NULL, NULL, 0, 0}
44 };
45 #endif
46
47 #ifdef CONFIG_SUPPORT_LTE
48 static boot_image_required_t const s_boot_image_lte_table[] = {
49         {L"l_fixnv1", L"l_fixnv2", LTE_FIXNV_SIZE, LTE_FIXNV_ADDR},
50         {L"l_runtimenv1", L"l_runtimenv2", LTE_RUNNV_SIZE, LTE_RUNNV_ADDR},
51         {L"l_modem", NULL, LTE_MODEM_SIZE, LTE_MODEM_ADDR},
52         {L"l_ldsp", NULL, LTE_LDSP_SIZE, LTE_LDSP_ADDR},
53         {L"l_gdsp", NULL, LTE_GDSP_SIZE, LTE_GDSP_ADDR},
54         {L"l_warm", NULL, WL_WARM_SIZE, WL_WARM_ADDR},
55         {NULL, NULL, 0, 0}
56 };
57 #endif
58
59 #ifdef CONFIG_SUPPORT_TD
60 static boot_image_required_t const s_boot_image_TD_table[] = {
61         {L"tdfixnv1", L"tdfixnv2", FIXNV_SIZE, TDFIXNV_ADR},
62         {L"tdruntimenv1", L"tdruntimenv2", RUNTIMENV_SIZE, TDRUNTIMENV_ADR},
63         {L"tdmodem", NULL, TDMODEM_SIZE, TDMODEM_ADR},
64         {L"tddsp", NULL, TDDSP_SIZE, TDDSP_ADR},
65         {NULL, NULL, 0, 0}
66 };
67 #endif
68
69 #ifdef CONFIG_SUPPORT_GSM
70 static boot_image_required_t const s_boot_image_gsm_table[] = {
71         {L"g_fixnv1", L"g_fixnv2", GSM_FIXNV_SIZE, GSM_FIXNV_ADDR},
72         {L"g_runtimenv1", L"g_runtimenv2", GSM_RUNNV_SIZE, GSM_RUNNV_ADDR},
73         {L"g_modem", NULL, GSM_MODEM_SIZE, GSM_MODEM_ADDR},
74         {L"g_dsp", NULL, GSM_DSP_SIZE, GSM_DSP_ADDR},
75         {NULL, NULL, 0, 0}
76 };
77 #endif
78
79 #ifdef CONFIG_SUPPORT_W
80 static boot_image_required_t const s_boot_image_W_table[] = {
81         {L"wfixnv1", L"wfixnv2", FIXNV_SIZE, WFIXNV_ADR},
82         {L"wruntimenv1", L"wruntimenv2", RUNTIMENV_SIZE, WRUNTIMENV_ADR},
83         {L"wmodem", NULL, WMODEM_SIZE, WMODEM_ADR},
84         {L"wdsp", NULL, WDSP_SIZE, WDSP_ADR},
85         {NULL, NULL, 0, 0}
86 };
87 #endif
88
89 #ifdef CONFIG_SUPPORT_WIFI
90 static boot_image_required_t const s_boot_image_WIFI_table[] = {
91         {L"wcnfixnv1", L"wcnfixnv2", FIXNV_SIZE, WCNFIXNV_ADR},
92         {L"wcnruntimenv1", L"wcnruntimenv2", RUNTIMENV_SIZE, WCNRUNTIMENV_ADR},
93         {L"wcnmodem", NULL, WCNMODEM_SIZE, WCNMODEM_ADR},
94         {NULL, NULL, 0, 0}
95 };
96 #endif
97
98 static boot_image_required_t const s_boot_image_COMMON_table[] = {
99 #if !BOOT_NATIVE_LINUX
100         {L"vm", NULL, VMJALUNA_SIZE, VMJALUNA_ADR},
101 #endif
102 #ifdef CONFIG_SIMLOCK_ENABLE
103         {L"simlock", NULL, SIMLOCK_SIZE, SIMLOCK_ADR},
104 #endif
105 #ifdef CONFIG_DFS_ENABLE
106         {L"pm_sys", NULL, DFS_SIZE, DFS_ADDR},
107 #endif
108         {NULL, NULL, 0, 0}
109
110 };
111
112 static boot_image_required_t *const s_boot_image_table[] = {
113 #ifdef CONFIG_SUPPORT_TDLTE
114         s_boot_image_tl_table,
115 #endif
116
117 #ifdef CONFIG_SUPPORT_WLTE
118         s_boot_image_wl_table,
119 #endif
120
121 #ifdef CONFIG_SUPPORT_LTE
122         s_boot_image_lte_table,
123 #endif
124
125 #ifdef CONFIG_SUPPORT_GSM
126         s_boot_image_gsm_table,
127 #endif
128
129 #ifdef CONFIG_SUPPORT_TD
130         s_boot_image_TD_table,
131 #endif
132
133 #ifndef CONFIG_TIZEN
134 #ifdef CONFIG_SUPPORT_W
135         s_boot_image_W_table,
136 #endif
137 #endif
138
139 #ifndef CONFIG_TIZEN
140 #ifdef CONFIG_SUPPORT_WIFI
141         s_boot_image_WIFI_table,
142 #endif
143 #endif
144         s_boot_image_COMMON_table,
145
146         0
147 };
148
149 #ifdef CONFIG_SECURE_BOOT
150 uint8 header_buf[SEC_HEADER_MAX_SIZE];
151 #endif
152
153 int read_logoimg(char *bmp_img, size_t size)
154 {
155         block_dev_desc_t *p_block_dev = NULL;
156         disk_partition_t info;
157
158         p_block_dev = get_dev("mmc", 1);
159         if (NULL == p_block_dev) {
160                 return -1;
161         }
162         if (!get_partition_info_by_name(p_block_dev, L"logo", &info)) {
163                 if (TRUE != Emmc_Read(PARTITION_USER, info.start, size / EMMC_SECTOR_SIZE, bmp_img)) {
164                         debugf("function: %s nand read error\n", __FUNCTION__);
165                         return -1;
166                 }
167         }
168         return 0;
169 }
170
171 int read_spldata()
172 {
173 #if 0
174         int size = CONFIG_SPL_LOAD_LEN;
175         if (TRUE != Emmc_Read(PARTITION_BOOT1, 0, size / EMMC_SECTOR_SIZE, (uint8 *) spl_data)) {
176                 debugf("vmjaluna nand read error \n");
177                 return -1;
178         }
179 #endif
180         return 0;
181 }
182
183 #ifdef CONFIG_SECURE_BOOT
184
185 int get_spl_hash(void *hash_data)
186 {
187         NBLHeader *header;
188         int len;
189         uint8 *spl_data;
190         int ret = 0;
191         //int size = CONFIG_SPL_LOAD_LEN;
192         int size = CONFIG_SPL_HASH_LEN;
193
194         spl_data = malloc(size);
195         if (!spl_data) {
196                 return ret;
197         }
198
199         if (TRUE != Emmc_Read(PARTITION_BOOT1, 0, size / EMMC_SECTOR_SIZE, (uint8 *) spl_data)) {
200                 debugf("PARTITION_BOOT1 read error \n");
201                 return ret;
202         }
203
204         header = (NBLHeader *) ((unsigned char *)spl_data + BOOTLOADER_HEADER_OFFSET);
205         len = header->mHashLen;
206         /*clear header */
207         memset(header, 0, sizeof(NBLHeader));
208         header->mHashLen = len;
209         debugf("cal spl hash len=%d\n", header->mHashLen * 4);
210
211         ret = cal_sha1(spl_data, (header->mHashLen) << 2, hash_data);
212
213         if (spl_data)
214                 free(spl_data);
215
216         return ret;
217 }
218 #endif
219
220 /**
221         just convert partition name wchar to char with violent.
222 */
223 LOCAL __inline char *w2c(wchar_t * wchar)
224 {
225         static char buf[72] = { 0 };
226         unsigned int i = 0;
227         while ((NULL != wchar[i]) && (i < 72)) {
228                 buf[i] = wchar[i] & 0xFF;
229                 i++;
230         }
231         buf[i] = 0;
232
233         return buf;
234 }
235
236 LOCAL void _boot_secure_check(void)
237 {
238 #ifdef CONFIG_SECURE_BOOT
239         int puk_adr;
240         vlr_info_t *vlr_info;
241
242 #ifdef CONFIG_SUPPORT_W
243         puk_adr = CONFIG_SYS_NAND_U_BOOT_DST + CONFIG_SYS_NAND_U_BOOT_SIZE - KEY_INFO_SIZ - VLR_INFO_SIZ;
244         vlr_info = (vlr_info_t *) (WDSP_ADR + WDSP_SIZE - VLR_INFO_SIZ);
245         secure_check(WDSP_ADR, vlr_info->length, vlr_info, puk_adr);
246
247         puk_adr = CONFIG_SYS_NAND_U_BOOT_DST + CONFIG_SYS_NAND_U_BOOT_SIZE - KEY_INFO_SIZ - VLR_INFO_SIZ;
248         vlr_info = (vlr_info_t *) (WMODEM_ADR + WMODEM_SIZE - VLR_INFO_SIZ);
249         secure_check(WMODEM_ADR, vlr_info->length, vlr_info, puk_adr);
250 #endif
251
252 #ifdef CONFIG_SUPPORT_WIFI
253         puk_adr = CONFIG_SYS_NAND_U_BOOT_DST + CONFIG_SYS_NAND_U_BOOT_SIZE - KEY_INFO_SIZ - VLR_INFO_SIZ;
254         vlr_info = (vlr_info_t *) (WCNMODEM_ADR + WCNMODEM_SIZE - VLR_INFO_SIZ);
255         secure_check(WCNMODEM_ADR, vlr_info->length, vlr_info, puk_adr);
256 #endif
257
258 #if !BOOT_NATIVE_LINUX
259         secure_check(VMJALUNA_ADR, 0, VMJALUNA_ADR + VMJALUNA_SIZE - VLR_INFO_OFF,
260                      CONFIG_SYS_NAND_U_BOOT_DST + CONFIG_SYS_NAND_U_BOOT_SIZE - KEY_INFO_SIZ - VLR_INFO_OFF);
261 #endif
262
263 #ifdef CONFIG_SIMLOCK
264         secure_check(SIMLOCK_ADR, 0, SIMLOCK_ADR + SIMLOCK_SIZE - VLR_INFO_OFF,
265                      CONFIG_SYS_NAND_U_BOOT_DST + CONFIG_SYS_NAND_U_BOOT_SIZE - KEY_INFO_SIZ - VLR_INFO_OFF);
266 #endif
267 #endif
268         return;
269 }
270
271 /**
272         Function for reading user partition.
273 */
274 PUBLIC int _boot_partition_read(block_dev_desc_t * dev, wchar_t * partition_name, u32 offsetsector, u32 size, u8 * buf)
275 {
276         int ret = 0;
277         u32 left;
278         u32 nsct;
279         char *sctbuf = NULL;
280         disk_partition_t info;
281
282         if (NULL == buf) {
283                 debugf("%s:buf is NULL!\n", __func__);
284                 goto end;
285         }
286         nsct = size / EMMC_SECTOR_SIZE;
287         left = size % EMMC_SECTOR_SIZE;
288
289         if (get_partition_info_by_name(dev, partition_name, &info)) {
290                 debugf("get partition %s info failed!\n", w2c(partition_name));
291                 goto end;
292         }
293
294         if (TRUE != Emmc_Read(PARTITION_USER, info.start + offsetsector, nsct, buf))
295                 goto end;
296
297         if (left) {
298                 sctbuf = malloc(EMMC_SECTOR_SIZE);
299                 if (NULL != sctbuf) {
300                         if (TRUE == Emmc_Read(PARTITION_USER, info.start + offsetsector + nsct, 1, sctbuf)) {
301                                 memcpy(buf + (nsct * EMMC_SECTOR_SIZE), sctbuf, left);
302                                 ret = 1;
303                         }
304                         free(sctbuf);
305                 }
306         } else {
307                 ret = 1;
308         }
309
310 end:
311         debugf("%s: partition %s read %s!\n", __func__, w2c(partition_name), ret ? "success" : "failed");
312         return ret;
313 }
314
315 PUBLIC int blk_data_read(u32 offset, u32 size, u8 *buf)
316 {
317         int ret = 0;
318         char *sctbuf = NULL;
319         u32 start_sec, nsct, left;
320
321         if (!buf) {
322                 debugf("NULL BUF\n");
323                 goto end;
324         }
325
326         start_sec = offset / EMMC_SECTOR_SIZE;
327         nsct = size / EMMC_SECTOR_SIZE;
328         left = size % EMMC_SECTOR_SIZE;
329
330         if (nsct && !Emmc_Read(PARTITION_USER, start_sec, nsct, buf)) {
331                 debugf("Failed to read mmc\n");
332                 goto end;
333         }
334
335         if (left) {
336                 sctbuf = malloc(EMMC_SECTOR_SIZE);
337                 if (sctbuf) {
338                         if (!Emmc_Read(PARTITION_USER, start_sec + nsct, 1, sctbuf)) {
339                                 debugf("Failed to read mmc\n");
340                                 goto end;
341                         }
342
343                         memcpy(buf + (nsct * EMMC_SECTOR_SIZE), sctbuf, left);
344                         ret = 1;
345                         free(sctbuf);
346                 }
347         } else {
348                 ret = 1;
349         }
350
351 end:
352         return ret;
353 }
354
355 /**
356         Function for writing user partition.
357 */
358 PUBLIC int _boot_partition_write(block_dev_desc_t * dev, wchar_t * partition_name, u32 size, u8 * buf)
359 {
360         disk_partition_t info;
361
362         if (NULL == buf) {
363                 debugf("%s:buf is NULL!\n", __FUNCTION__);
364                 return 0;
365         }
366         size = (size + (EMMC_SECTOR_SIZE - 1)) & (~(EMMC_SECTOR_SIZE - 1));
367         size = size / EMMC_SECTOR_SIZE;
368         if (0 == get_partition_info_by_name(dev, partition_name, &info)) {
369                 if (TRUE != Emmc_Write(PARTITION_USER, info.start, size, buf)) {
370                         debugf("%s: partition:%s read error!\n", __FUNCTION__, w2c(partition_name));
371                         return 0;
372                 }
373         } else {
374                 debugf("%s: partition:%s >>>get partition info failed!\n", __FUNCTION__, w2c(partition_name));
375                 return 0;
376         }
377         debugf("%s: partition:%s write success!\n", __FUNCTION__, w2c(partition_name));
378         return 1;
379 }
380
381 /**
382         Function for displaying logo.
383 */
384 LOCAL __inline void _boot_display_logo(block_dev_desc_t * dev, int backlight_set)
385 {
386         size_t size;
387
388 #if defined(CONFIG_LCD_720P) || defined(CONFIG_LCD_HD) || CONFIG_LCD_PAD_WXGA   //LiWei add CONFIG_LCD_HD
389         size = 1 << 20;
390 #else
391         size = 1 << 19;
392 #endif
393         uint8 *bmp_img = malloc(size);
394         if (!bmp_img) {
395                 debugf("%s: malloc for splash image failed!\n", __FUNCTION__);
396                 return;
397         }
398         if (!_boot_partition_read(dev, L"logo", 0, size, bmp_img)) {
399                 debugf("%s: read logo partition failed!\n", __FUNCTION__);
400                 goto end;
401         }
402         lcd_display_logo(backlight_set, (ulong) bmp_img, size);
403 end:
404         free(bmp_img);
405         return;
406 }
407
408 /**
409         we assume partition with backup must check ecc.
410 */
411 LOCAL __inline int _boot_read_partition_with_backup(block_dev_desc_t * dev, boot_image_required_t info)
412 {
413         uint8 *bakbuf = NULL;
414         uint8 *oribuf = NULL;
415         u8 status = 0;
416         uint8 header[EMMC_SECTOR_SIZE];
417         uint32 checksum = 0;
418         nv_header_t *header_p = NULL;
419         uint32 bufsize = info.size + EMMC_SECTOR_SIZE;
420
421         header_p = header;
422         bakbuf = malloc(bufsize);
423         if (NULL == bakbuf)
424                 return 0;
425         memset(bakbuf, 0xff, bufsize);
426         oribuf = malloc(bufsize);
427         if (NULL == oribuf) {
428                 free(bakbuf);
429                 return 0;
430         }
431         memset(oribuf, 0xff, bufsize);
432
433         if (_boot_partition_read(dev, info.partition, 0, info.size + EMMC_SECTOR_SIZE, oribuf)) {
434                 memset(header, 0, EMMC_SECTOR_SIZE);
435                 memcpy(header, oribuf, EMMC_SECTOR_SIZE);
436                 checksum = header_p->checksum;
437                 debugf("_boot_read_partition_with_backup origin checksum 0x%x\n", checksum);
438                 if (_chkNVEcc(oribuf + EMMC_SECTOR_SIZE, info.size, checksum)) {
439                         memcpy(info.mem_addr, oribuf + EMMC_SECTOR_SIZE, info.size);
440                         status += 1;
441                 }
442         }
443         if (_boot_partition_read(dev, info.bak_partition, 0, info.size + EMMC_SECTOR_SIZE, bakbuf)) {
444                 memset(header, 0, EMMC_SECTOR_SIZE);
445                 memcpy(header, bakbuf, EMMC_SECTOR_SIZE);
446                 checksum = header_p->checksum;
447                 debugf("_boot_read_partition_with_backup backup checksum 0x%x\n", checksum);
448                 if (_chkNVEcc(bakbuf + EMMC_SECTOR_SIZE, info.size, checksum))
449                         status += 1 << 1;
450         }
451
452         switch (status) {
453         case 0:
454                 debugf("%s:(%s)both org and bak partition are damaged!\n", __FUNCTION__, w2c(info.partition));
455         memset(info.mem_addr, 0, info.size);
456                 free(bakbuf);
457                 free(oribuf);
458                 return 0;
459         case 1:
460                 debugf("%s:(%s)bak partition is damaged!\n", __FUNCTION__, w2c(info.bak_partition));
461                 _boot_partition_write(dev, info.bak_partition, info.size + EMMC_SECTOR_SIZE, oribuf);
462                 break;
463         case 2:
464                 debugf("%s:(%s)org partition is damaged!\n!", __FUNCTION__, w2c(info.partition));
465                 memcpy(info.mem_addr, bakbuf + EMMC_SECTOR_SIZE, info.size);
466                 _boot_partition_write(dev, info.partition, info.size + EMMC_SECTOR_SIZE, bakbuf);
467                 break;
468         case 3:
469                 debugf("%s:(%s)both org and bak partition are ok!\n", __FUNCTION__, w2c(info.partition));
470                 break;
471         default:
472                 debugf("%s: status error!\n", __FUNCTION__);
473                 free(bakbuf);
474                 free(oribuf);
475                 return 0;
476         }
477         free(bakbuf);
478         free(oribuf);
479         return 1;
480 }
481
482 /**
483         Function for reading image which is needed when power on.
484 */
485 //LOCAL __inline
486 int _boot_load_required_image(block_dev_desc_t * dev, boot_image_required_t img_info)
487 {
488         uint32 secure_boot_offset = 0;
489
490         debugf("%s: load %s to addr 0x%08x\n", __FUNCTION__, w2c(img_info.partition), img_info.mem_addr);
491
492         if (NULL != img_info.bak_partition) {
493                 _boot_read_partition_with_backup(dev, img_info);
494         } else {
495 #ifdef CONFIG_SECURE_BOOT
496                 if (!_boot_partition_read(dev, img_info.partition, 0, SEC_HEADER_MAX_SIZE, header_buf)) {
497                         debugf("%s:%s read error!\n", __FUNCTION__, w2c(img_info.partition));
498                         return 0;
499                 }
500                 //if(header_parser(header_buf) )
501                 secure_boot_offset = get_code_offset(header_buf);
502                 _boot_partition_read(dev, img_info.partition, 0 + secure_boot_offset, img_info.size, (u8 *) img_info.mem_addr);
503
504                 secure_verify(L"uboot", header_buf, img_info.mem_addr);
505 #else
506                 _boot_partition_read(dev, img_info.partition, 0, img_info.size, (u8 *) img_info.mem_addr);
507 #endif
508         }
509
510         return 1;
511 }
512
513 /**
514         Function for checking and loading kernel/ramdisk image.
515 */
516 LOCAL int _boot_load_kernel_ramdisk_image(block_dev_desc_t * dev, char *bootmode, boot_img_hdr * hdr)
517 {
518         wchar_t *partition = NULL;
519         uint32 size, offset;
520         uint32 dt_img_adr;
521         uint32 secure_boot_offset = 0;
522         disk_partition_t info;
523
524         if (0 == memcmp(bootmode, RECOVERY_PART, strlen(RECOVERY_PART))) {
525                 partition = L"recovery";
526                 debugf("enter recovery mode!\n");
527                 set_recovery_mode(1);
528         } else {
529                 partition = L""BOOT_PART;
530                 debugf("Enter boot mode (partition name: %s)\n", w2c(partition));
531         }
532
533         if (get_partition_info_by_name(dev, partition, &info)) {
534                 debugf("get partition %s info failed!\n", w2c(partition));
535                 return 0;
536         }
537
538         offset = info.start * info.blksz;
539
540         if (!blk_data_read(offset, sizeof(*hdr), hdr)) {
541                 debugf("%s:%s read error!\n", __FUNCTION__, w2c(partition));
542                 return 0;
543         }
544
545         //image header check
546         if (hdr->magic_num != MAGIC_NUM) {
547                 debugf("BAD BOOT IMAGE HEADER: %x\n", hdr->magic_num);
548                 return 0;
549         }
550         debugf("BOOT IMAGE HEADER: %x\n", hdr->magic_num);
551
552         //read kernel image
553         size = roundup(sizeof(*hdr), ALIGN_SIZE) +
554                 roundup(hdr->kernel_size, ALIGN_SIZE) +
555                 roundup(hdr->dt_size, ALIGN_SIZE);
556
557         debugf("bzImage size: %x\n", size);
558
559         if (!blk_data_read(offset, size, KERNEL_ADR - roundup(sizeof(*hdr), ALIGN_SIZE))) {
560                 debugf("%s:%s kernel read error!\n", __FUNCTION__, w2c(partition));
561                 return 0;
562         }
563
564         //read dt image
565         dt_img_adr = KERNEL_ADR + roundup(hdr->kernel_size, ALIGN_SIZE);
566         debugf("dt_img_adr: %u\n", dt_img_adr);
567         debugf("dt_img_adr: %x\n", dt_img_adr);
568         if (load_dtb((int)DT_ADR, (void *)dt_img_adr)) {
569                 debugf("%s:dt load error!\n", __FUNCTION__);
570                 return 0;
571         }
572
573
574 #ifdef CONFIG_TIZEN
575 #ifdef CONFIG_RAMDISK_BOOT
576         {
577                 char *ramdisk_part;
578                 if (0 == memcmp(bootmode, RECOVERY_PART, strlen(RECOVERY_PART)))
579                         ramdisk_part = PARTS_RAMDISK2;
580                 else
581                         ramdisk_part = PARTS_RAMDISK;
582                 load_ramdisk(ramdisk_part, RAMDISK_ADR, RAMDISK_SIZE_MB * 1024 * 1024);
583         }
584 #endif /* CONFIG_RAMDISK_BOOT */
585 #else /* CONFIG_TIZEN */
586 #ifdef CONFIG_SDRAMDISK
587         {
588                 int sd_ramdisk_size = 0;
589 #ifdef WDSP_ADR
590                 size = WDSP_ADR - RAMDISK_ADR;
591 #else
592                 size = TDDSP_ADR - RAMDISK_ADR;
593 #endif
594                 if (size > 0)
595                         sd_ramdisk_size = load_sd_ramdisk((uint8 *) RAMDISK_ADR, size);
596                 if (sd_ramdisk_size > 0)
597                         hdr->ramdisk_size = sd_ramdisk_size;
598         }
599 #endif
600 #endif /* CONFIG_TIZEN */
601         return 1;
602 }
603
604 #ifdef CONFIG_SECURE_BOOT
605 PUBLIC int secure_verify_partition(block_dev_desc_t * dev, wchar_t * partition_name, int ram_addr)
606 {
607         int ret = 0;
608         int size;
609         disk_partition_t info;
610
611         if (get_partition_info_by_name(dev, partition_name, &info)) {
612                 debugf("verify get partition %s info failed!\n", w2c(partition_name));
613                 ret = 1;
614         }
615         size = info.size * GPT_BLOCK_SIZE;
616         debugf("%s=%x  =%x\n", w2c(partition_name), info.size, size);
617
618         _boot_partition_read(dev, partition_name, 0, size, (u8 *) ram_addr);
619         secure_verify(L"uboot", ram_addr, 0);
620         return ret;
621 }
622 #endif
623
624 void vlx_nand_boot(char *kernel_pname, char *cmdline, int backlight_set)
625 {
626         boot_img_hdr *hdr = (void *)raw_header;
627         block_dev_desc_t *dev = NULL;
628         wchar_t *partition = NULL;
629         int i, j;
630         long long start = get_ticks();
631
632         dev = get_dev("mmc", 1);
633         if (NULL == dev) {
634                 debugf("Fatal Error,get_dev mmc failed!\n");
635                 return;
636         }
637 #ifdef CONFIG_SC9630
638         pmic_arm7_RAM_active();
639 #endif
640
641 #ifndef CONFIG_TIZEN
642 #ifdef CONFIG_SPLASH_SCREEN
643         _boot_display_logo(dev, backlight_set);
644         performance_debug("7:");
645 #endif
646 #endif
647         set_vibrator(FALSE);
648
649 #if ((!BOOT_NATIVE_LINUX)||(BOOT_NATIVE_LINUX_MODEM))
650         //load required image which config in table
651         i = 0;
652         while (s_boot_image_table[i]) {
653                 j = 0;
654                 while (s_boot_image_table[i][j].partition) {
655                         _boot_load_required_image(dev, s_boot_image_table[i][j]);
656                         j++;
657                 }
658                 i++;
659         }
660         performance_debug("8:");
661 #endif
662
663 #ifdef CONFIG_SECURE_BOOT
664         if (0 == memcmp(kernel_pname, RECOVERY_PART, strlen(RECOVERY_PART))) {
665                 partition = L"recovery";
666         } else {
667                 partition = L"boot";
668         }
669         secure_verify_partition(dev, partition, KERNEL_ADR);
670 #endif
671         //loader kernel and ramdisk
672         if (!_boot_load_kernel_ramdisk_image(dev, kernel_pname, hdr))
673                 return;
674         performance_debug("9:");
675         load_image_time = get_ticks() - start;
676         //secure check for secure boot
677         //_boot_secure_check();
678
679         if (creat_cmdline(cmdline, hdr)) {
680                 debugf("creat_cmdline failed\n");
681                 return;
682         }
683 #if BOOT_NATIVE_LINUX_MODEM
684         //sipc addr clear
685         sipc_addr_reset();
686 #endif
687 #if defined CONFIG_SC9630
688 //      Emmc_DisSdClk();
689 #endif
690         vlx_entry();
691 }