-
Notifications
You must be signed in to change notification settings - Fork 58
/
dvrmain.c
3463 lines (3152 loc) · 131 KB
/
dvrmain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifdef FPGA
#include <stdio.h>
#include <stdlib.h>
#endif
#include "project_config_f.h"
#include "extern_param.h"
#include "shell_golinux.h"
#include "platform_iso.h"
#include "flashdev_n.h"
#include "flashdev_e.h"
#include "flashdev_s.h"
#include "otp.h"
#include "dvrboot_inc/mis_reg.h"
#include "dvrboot_inc/sys_reg.h"
#include "dvrboot_inc/util.h"
#include "dvrboot_inc/mcp.h"
#include "dvrboot_inc/string.h"
#include "uart.h"
#include "BootPartition_wrapper.h"
//#define SPI_ENV_PARAM_ADDR 0x18200000
//#define SPI_ENV_PARAM_SIZE 0x00010000
#define FLASH_MAGICNO_NOR_PARALLEL 0xBE
#define FLASH_MAGICNO_NAND 0xCE
#define FLASH_MAGICNO_NOR_SERIAL 0xDE
#define FLASH_MAGICNO_EMMC 0xEE
#define EXT_PARA_DDR_BASE (0xA0A00000 - UBOOT_DDR_OFFSET) // t_extern_param + logo + rescue base address on DDR
#define NAND_ENV_DDR_BASE (0xA0040000 - UBOOT_DDR_OFFSET) // modify by angus, original value is 0xa0010000
#define BOOTCODE_SIZE_ADDR 0XB801A60C
#define SIMULATION_DUMP_ADDR (0xA3000000 - UBOOT_DDR_OFFSET) // dump hwsetting/bootcode related to DDR
#define NAND_BOOT_BACKUP_COUNT 3 // number of backup bootcode in NAND flash
#define HWSETTING_INFO_LEN 96 //not use anymore, for Romcode read size
extern unsigned char resetrom[]; //rom data : 0x1FC0_0000 ~ 0x1FC0_1FFF
extern unsigned char resetrom_end;
extern unsigned char mips_resetrom[];
extern unsigned char mips_resetrom_end;
extern unsigned char hwsetting[];
extern unsigned char hwsetting_end;
extern unsigned char hasharray[];
extern unsigned char hasharray_end;
extern unsigned char hasharray64[];
extern unsigned char hasharray64_end;
extern unsigned char signature[];
extern unsigned char signature_end;
extern unsigned char fsbl[];
extern unsigned char fsbl_end;
extern unsigned char fsbl_signature[];
extern unsigned char fsbl_signature_end;
extern unsigned char fsbl_os[];
extern unsigned char fsbl_os_end;
extern unsigned char fsbl_os_signature[];
extern unsigned char fsbl_os_signature_end;
extern unsigned char bl31[];
extern unsigned char bl31_end;
extern unsigned char bl31_signature[];
extern unsigned char bl31_signature_end;
extern unsigned char rsa_pub[];
extern unsigned char rsa_pub_end;
#if defined(Config_Secure_Improve_TRUE)
extern unsigned char Kpublic_fw[];
extern unsigned char Kpublic_fw_end;
extern unsigned char Kpublic_fw_signature[];
extern unsigned char Kpublic_fw_signature_end;
extern unsigned char Kpublic_tee[];
extern unsigned char Kpublic_tee_end;
extern unsigned char Kpublic_tee_signature[];
extern unsigned char Kpublic_tee_signature_end;
#endif
extern unsigned char bootcode2_boot_hasharray[];
extern unsigned char bootcode2_boot_hasharray_end;
extern unsigned char bootcode2_boot_signature[];
extern unsigned char bootcode2_boot_signature_end;
#ifdef MAGALLAN_PRJ
extern unsigned char bootcode3_boot_hasharray[];
extern unsigned char bootcode3_boot_hasharray_end;
extern unsigned char bootcode3_boot_signature[];
extern unsigned char bootcode3_boot_signature_end;
#endif
extern unsigned char ecbarray[];
extern unsigned char ecbarray_end;
extern unsigned char linux_rescue_hasharray[];
extern unsigned char linux_rescue_hasharray_end;
extern unsigned char linux_rescue_signature[];
extern unsigned char linux_rescue_signature_end;
extern unsigned char cbc_linux[];
extern unsigned char cbc_linux_end;
extern unsigned char hwsetting_sig_image[];
extern unsigned char hwsetting_sig_image_end;
extern unsigned char dcas_key_sig_image[];
extern unsigned char dcas_key_sig_image_end;
extern unsigned char logo[];
extern unsigned char logo_end;
extern unsigned char logo2[];
extern unsigned char logo2_end;
extern unsigned char logo3[];
extern unsigned char logo3_end;
extern unsigned char logo4[];
extern unsigned char logo4_end;
extern unsigned char logo5[];
extern unsigned char logo5_end;
extern unsigned char logo6[];
extern unsigned char logo6_end;
extern unsigned char logo7[];
extern unsigned char logo7_end;
extern unsigned char logo8[];
extern unsigned char logo8_end;
extern unsigned int pages_per_block;
extern unsigned int blocks_per_flash;
extern unsigned int mcp_dscpt_addr;
unsigned char verify_after_write;
unsigned char force_secure;
unsigned char test_secure;
unsigned char noreset;
PrintFuncPtr_t rtprintf=NULL;
Flush_Dcache_AllPtr_t rtflush_dcache_all=NULL;
Flush_CachePtr_t rtflush_cache=NULL;
/************************************************************************
*
************************************************************************/
unsigned int align_to_boundary(unsigned int size, unsigned int block_size)
{
return (size % block_size ? size / block_size + 1 : size / block_size);
}
unsigned int align_to_boundary_length(unsigned int size, unsigned int block_size)
{
return (size % block_size ? (size / block_size + 1)*block_size : (size / block_size)*block_size );
}
void set_spi_pin_mux(void)
{
#ifndef FPGA //wilma+ 0802
//1295
//set sf_en=1
REG32(SYS_muxpad5) |= 0x01;
#endif
}
void set_nand_pin_mux(void)
{
//1295
//set default i/f to nand
REG32(SYS_muxpad0) = 0x55555555;
}
void set_emmc_freq()
{
//1295
REG32(SYS_PLL_EMMC2) = 0x031C0001;
REG32(SYS_PLL_EMMC3) = 0x00AF0000;
REG32(SYS_PLL_EMMC4) = 0x00000007;
REG32(EMMC_CKGEN_CTL) = 0x2102;
REG32(SYS_NF_CKSEL) = 0x5;
sync();
}
void set_emmc_pin_mux(void)
{
//1295 muxpad0 is in card reader
//set default i/f to emmc
unsigned int reg_val=0;
reg_val = REG32(SYS_muxpad0);
reg_val &= ~0xFFFF0C3C;
reg_val |= 0xaaaa0828;
REG32(SYS_muxpad0) = reg_val;
//emmc:pfunc_nf1
REG32(CR_EMMC_PFUC_NF1) = 0x33333333;
}
/************************************************************************
* get uboot domain function pointer to dvrmain domain function pointer
************************************************************************/
void rebuild_function_pointer_from_uboot_to_dvrmain( void )
{
// get fun ptr of printf(...) from specified address
#define DUMMY (*((unsigned int *)0x00020060))
#define DUMMY2 (*((unsigned int *)0x00020064))
#define UBOOT_PRINTF_ADDRESS_TAG (*((unsigned int *)0x00020068))
#define UBOOT_PRINTF_ADDRESS (*((unsigned int *)0x0002006C))
#define UBOOT_FLUSH_DCACHE_ALL_ADDRESS_TAG (*((unsigned int *)0x00020070))
#define UBOOT_FLUSH_DCACHE_ALL_ADDRESS (*((unsigned int *)0x00020074))
#define UBOOT_FLUSH_CACHE_ADDRESS_TAG (*((unsigned int *)0x00020078))
#define UBOOT_FLUSH_CACHE_ADDRESS (*((unsigned int *)0x0002007C))
if( UBOOT_PRINTF_ADDRESS_TAG == CODE_VAILD_MAGIC_NUMBER ) {
rtprintf = (PrintFuncPtr_t) (UBOOT_PRINTF_ADDRESS);
rtprintf("\n\nHello World(%s %s), get printf ptr=%p\n\n", __DATE__, __TIME__, rtprintf);
}
else {
rtprintf = NULL;
}
if( UBOOT_FLUSH_DCACHE_ALL_ADDRESS_TAG == CODE_VAILD_MAGIC_NUMBER ) {
rtflush_dcache_all = (Flush_Dcache_AllPtr_t) (UBOOT_FLUSH_DCACHE_ALL_ADDRESS);
}
else {
rtflush_dcache_all = NULL;
}
if( UBOOT_FLUSH_CACHE_ADDRESS_TAG == CODE_VAILD_MAGIC_NUMBER ) {
if (UBOOT_FLUSH_CACHE_ADDRESS != UBOOT_PRINTF_ADDRESS) // prevent side effect
{
rtflush_cache = (Flush_CachePtr_t) (UBOOT_FLUSH_CACHE_ADDRESS);
}
else
{
rtflush_cache = NULL;
}
}
else {
rtflush_cache = NULL;
}
}
/************************************************************************
*
* dvrmain
* Description :
* -------------
* main function of flash writer
* attention:
* 1. since 0xbfc0_0000 ~ 0xbfc0_1fff occupied by ROM code,
* space from 0xbfc0_0000 ~ 0xbfc0_1fff in NOR flash can not be utilized.
* In order to write data to the space, we shift writing address space from
* 0xbed0_0000 ~ 0xbfcf_ffff to 0xbdd0_0000 ~ 0xbecf_ffff. So that we can
* access to space 0xbfc0_0000 ~ 0xbfc0_1fff in NOR flash.
* 2. we left 0xbecf_f000 ~ 0xbecf_ffff for ext_param.
* 3. ext_param is located from 0xbecf_f800.
*
* Parameters :
* Return values :
*
************************************************************************/
int dvrmain ( int argc, char * const argv[] )
{
// spi used
unsigned char * spi_resetrom_addr;
unsigned char * spi_mips_resetrom_addr;
unsigned char * spi_hwsetting_addr;
unsigned char * spi_param_addr;
unsigned char * spi_param_addr2;
unsigned char * spi_bootcode_addr;
unsigned char * spi_rescue_addr;
unsigned char * spi_rescue_sig_addr;
unsigned char * spi_fsbl_addr;
unsigned char * spi_fsbl_sig_addr;
unsigned char * spi_fsbl_os_addr;
unsigned char * spi_fsbl_os_sig_addr;
// spi bl31
unsigned char * spi_bl31_addr;
unsigned char * spi_bl31_sig_addr;
#if defined(Config_Secure_Improve_TRUE)
unsigned char * spi_Kpublic_fw_addr;
unsigned char * spi_Kpublic_fw_sig_addr;
unsigned char * spi_Kpublic_tee_addr;
unsigned char * spi_Kpublic_tee_sig_addr;
#endif
unsigned char * spi_rsa_pub_addr;
unsigned char * spi_bootcode_sig_addr;
unsigned char * spi_bootcode_addr2;
unsigned char * spi_bootcode_addr3;
unsigned char * spi_key_sig_addr;
unsigned char * spi_key_sig_addr2;
unsigned char * spi_key_sig_addr3;
// for nand
// for emmc
// common
unsigned char * logo_addr;
unsigned char * logo2_addr;
unsigned char * logo3_addr;
unsigned char * logo4_addr;
unsigned char * logo5_addr;
unsigned char * logo6_addr;
unsigned char * logo7_addr;
unsigned char * logo8_addr;
unsigned int resetrom_size;
unsigned int mips_resetrom_size;
unsigned int hwsetting_size;
unsigned int hasharray_size;
unsigned int hasharray64_size;
unsigned int signature_size;
unsigned int bootcode2_boot_hasharray_size;
unsigned int bootcode2_boot_signature_size;
unsigned int bootcode3_boot_hasharray_size;
unsigned int bootcode3_boot_signature_size;
unsigned int linux_rescue_hasharray_size;
unsigned int linux_rescue_signature_size;
unsigned int hwsetting_sig_size;
unsigned int dcas_key_sig_size;
unsigned int logo_size;
unsigned int logo2_size;
unsigned int logo3_size;
unsigned int logo4_size;
unsigned int logo5_size;
unsigned int logo6_size;
unsigned int logo7_size;
unsigned int logo8_size;
unsigned char * env_param_addr;
unsigned char * linux_sec1_addr;
unsigned char * linux_sec2_addr;
unsigned int linux_sec1_size;
unsigned int linux_sec2_size;
unsigned char * programmed_img_base;
unsigned char * programmed_img64_base;
unsigned int programmed_img_size;
unsigned int programmed_img64_size;
unsigned char * programmed_img_sig_base;
unsigned int programmed_img_sig_size;
unsigned char * programmed_linux_rescue_sig_base;
unsigned int programmed_linux_rescue_sig_size;
unsigned char * programmed_fsbl_base;
unsigned int programmed_fsbl_size;
unsigned char * programmed_fsbl_sig_base;
unsigned int programmed_fsbl_sig_size;
unsigned char * programmed_fsbl_os_base;
unsigned int programmed_fsbl_os_size;
unsigned char * programmed_fsbl_os_sig_base;
unsigned int programmed_fsbl_os_sig_size;
unsigned char * programmed_bl31_base;
unsigned int programmed_bl31_size;
unsigned char * programmed_bl31_sig_base;
unsigned int programmed_bl31_sig_size;
#if defined(Config_Secure_Improve_TRUE)
unsigned char * programmed_Kpublic_fw_base;
unsigned int programmed_Kpublic_fw_size;
unsigned char * programmed_Kpublic_fw_sig_base;
unsigned int programmed_Kpublic_fw_sig_size;
unsigned char * programmed_Kpublic_tee_base;
unsigned int programmed_Kpublic_tee_size;
unsigned char * programmed_Kpublic_tee_sig_base;
unsigned int programmed_Kpublic_tee_sig_size;
#endif
unsigned char * programmed_rsa_pub_base;
unsigned int programmed_rsa_pub_size;
unsigned char * bootcode2_boot_programmed_img_base;
unsigned int bootcode2_boot_programmed_img_size;
unsigned char * bootcode3_boot_programmed_img_base;
unsigned int bootcode3_boot_programmed_img_size;
unsigned char * programmed_linux_rescue_img_base;
unsigned int programmed_linux_rescue_img_size;
unsigned char flash_type;
unsigned char flash_magicno;
unsigned int idx, i, j;
unsigned int temp, reg_addr;
unsigned char * temp_ptr;
unsigned int * temp_ptr32;
void * device;
int res;
int save_nand_env;
unsigned int block_size;
unsigned int total_block_cnt;
t_extern_param param;
t_extern_param *orignal_param;
#ifdef CR_MEMORY_DUMP
UINT32 emmc_dump_addr = 0x03000000;
UINT32 emmc_dump_ptr=0;
#endif
// -------------------------------------------------------------------------
// function declaration
// -------------------------------------------------------------------------
int (*do_erase)(void *, unsigned int * , unsigned int);
int (*do_write)(void *, unsigned char *, unsigned int *, unsigned int, unsigned int, const unsigned int);
int (*do_identify)(void **);
int (*do_init)(void *);
int (*do_read)(void *, unsigned int *, unsigned char *, unsigned int, INT32);
int (*do_hide_hwsetting)(void *, unsigned char *, unsigned int *, unsigned int, unsigned int, const unsigned int);
void (*do_exit)(void *dev);
// -------------------------------------------------------------------------
// copy uboot domain fun pointer to dvrmoan domain
// -------------------------------------------------------------------------
#ifndef FOR_ICE_LOAD
rebuild_function_pointer_from_uboot_to_dvrmain();
#else
// make a copy here to avoid flush function pointer being invalid.
rebuild_function_pointer_from_uboot_to_dvrmain();
init_uart();
set_focus_uart(0); //default : uart0
#endif
// -------------------------------------------------------------------------
// initial global variable
// -------------------------------------------------------------------------
block_size = 0x00001000; // block size == 4096 bytes
total_block_cnt = 0x00100000 / block_size; // 256 blocks for 1MB ( 0xbec0_0000~0xbecf_ffff )
mcp_dscpt_addr = 0;
// -------------------------------------------------------------------------
// initial local variable
// -------------------------------------------------------------------------
// sort by address value
resetrom_size = (unsigned int )(&resetrom_end - resetrom);
mips_resetrom_size = (unsigned int )(&mips_resetrom_end - mips_resetrom);
hwsetting_size = (unsigned int )(&hwsetting_end - hwsetting); //hwsetting + signature for both secure/non-secure
hasharray_size = (unsigned int )(&hasharray_end - hasharray); //bootcode for secure/non-secure
hasharray64_size = (unsigned int )(&hasharray64_end - hasharray64); //bootcode for secure/non-secure
signature_size = (unsigned int )(&signature_end - signature); //bootcode signature for secure/non-secure
bootcode2_boot_hasharray_size = (unsigned int )(&bootcode2_boot_hasharray_end - bootcode2_boot_hasharray);
bootcode2_boot_signature_size = (unsigned int )(&bootcode2_boot_signature_end - bootcode2_boot_signature);
#ifdef MAGALLAN_PRJ
bootcode3_boot_hasharray_size = (unsigned int )(&bootcode3_boot_hasharray_end - bootcode3_boot_hasharray);
bootcode3_boot_signature_size = (unsigned int )(&bootcode3_boot_signature_end - bootcode3_boot_signature);
#endif
linux_rescue_hasharray_size = (unsigned int )(&linux_rescue_hasharray_end - linux_rescue_hasharray);
linux_rescue_signature_size = (unsigned int )(&linux_rescue_signature_end - linux_rescue_signature);
hwsetting_sig_size = (unsigned int )(&hwsetting_sig_image_end - hwsetting_sig_image);
dcas_key_sig_size = (unsigned int )(&dcas_key_sig_image_end - dcas_key_sig_image);
logo_size = (unsigned int )(&logo_end - logo);
logo2_size = (unsigned int )(&logo2_end - logo2);
logo3_size = (unsigned int )(&logo3_end - logo3);
logo4_size = (unsigned int )(&logo4_end - logo4);
logo5_size = (unsigned int )(&logo5_end - logo5);
logo6_size = (unsigned int )(&logo6_end - logo6);
logo7_size = (unsigned int )(&logo7_end - logo7);
logo8_size = (unsigned int )(&logo8_end - logo8);
programmed_img_size = hasharray_size;
programmed_img_base = hasharray; //without signature
programmed_img64_size = hasharray64_size;
programmed_img64_base = hasharray64; //without signature
programmed_img_sig_base = signature;
// fsbl
programmed_fsbl_size = (unsigned int )(&fsbl_end - fsbl);
programmed_fsbl_base = fsbl;
programmed_fsbl_sig_size = (unsigned int )(&fsbl_signature_end - fsbl_signature);
programmed_fsbl_sig_base = fsbl_signature;
// tee os
programmed_fsbl_os_size = (unsigned int )(&fsbl_os_end - fsbl_os);
programmed_fsbl_os_base = fsbl_os;
programmed_fsbl_os_sig_size = (unsigned int )(&fsbl_os_signature_end - fsbl_os_signature);
programmed_fsbl_os_sig_base = fsbl_os_signature;
// bl31
programmed_bl31_size = (unsigned int )(&bl31_end - bl31);
programmed_bl31_base = bl31;
programmed_bl31_sig_size = (unsigned int )(&bl31_signature_end - bl31_signature);
programmed_bl31_sig_base = bl31_signature;
programmed_rsa_pub_size = (unsigned int )(&rsa_pub_end - rsa_pub);
programmed_rsa_pub_base = rsa_pub;
#if defined(Config_Secure_Improve_TRUE)
programmed_Kpublic_fw_size = (unsigned int )(&Kpublic_fw_end - Kpublic_fw);
programmed_Kpublic_fw_base = Kpublic_fw;
programmed_Kpublic_fw_sig_size = (unsigned int )(&Kpublic_fw_signature_end - Kpublic_fw_signature);
programmed_Kpublic_fw_sig_base = Kpublic_fw_signature;
programmed_Kpublic_tee_size = (unsigned int )(&Kpublic_tee_end - Kpublic_tee);
programmed_Kpublic_tee_base = Kpublic_tee;
programmed_Kpublic_tee_sig_size = (unsigned int )(&Kpublic_tee_signature_end - Kpublic_tee_signature);
programmed_Kpublic_tee_sig_base = Kpublic_tee_signature;
#endif
if (signature_size>=sizeof(unsigned int))
programmed_img_sig_size = signature_size;
else
programmed_img_sig_size = 0;
bootcode2_boot_programmed_img_size = bootcode2_boot_hasharray_size;
bootcode2_boot_programmed_img_base = bootcode2_boot_hasharray;
#ifdef MAGALLAN_PRJ
bootcode3_boot_programmed_img_size = bootcode3_boot_hasharray_size;
bootcode3_boot_programmed_img_base = bootcode3_boot_hasharray;
#endif
programmed_linux_rescue_img_size = linux_rescue_hasharray_size;
programmed_linux_rescue_img_base = linux_rescue_hasharray;
programmed_linux_rescue_sig_size = linux_rescue_signature_size;
programmed_linux_rescue_sig_base = linux_rescue_signature;
#ifdef ROMCODE_ON_SPI
spi_resetrom_addr = (unsigned char *)SPI_CODE_PART1; //assign arm romcode start address
spi_mips_resetrom_addr = (unsigned char *)SPI_CODE_PART11; //assign lexra romcode start address
spi_param_addr = (unsigned char *)(SPI_CODE_PART1 + SPI_RESETROM_SIZE + SPI_MIPS_RESETROM_SIZE);
spi_hwsetting_addr = (unsigned char *)(SPI_CODE_PART1 + SPI_RESETROM_SIZE + SPI_MIPS_RESETROM_SIZE + SPI_MAX_PARAM_SIZE); //assign hw setting start address, moidfy by angus, original value is 0xb8108000
#else
spi_resetrom_addr = NULL;
spi_mips_resetrom_addr = NULL;
spi_param_addr = (unsigned char *)(SPI_CODE_PART1 + SPI_RESETROM_SIZE + SPI_MIPS_RESETROM_SIZE);
spi_hwsetting_addr = (unsigned char *)(SPI_CODE_PART1 + SPI_RESETROM_SIZE + SPI_MIPS_RESETROM_SIZE + SPI_MAX_PARAM_SIZE); //assign hw setting start address, moidfy by angus, original value is 0xb8108000
#endif
spi_bootcode_addr = spi_hwsetting_addr + hwsetting_size;
spi_bootcode_sig_addr = spi_bootcode_addr + hasharray_size;
// spi fsbl
spi_fsbl_addr = spi_bootcode_sig_addr + signature_size;
spi_fsbl_sig_addr = spi_fsbl_addr + programmed_fsbl_size;
// spi tee os
spi_fsbl_os_addr = spi_fsbl_sig_addr + programmed_fsbl_sig_size;
spi_fsbl_os_sig_addr = spi_fsbl_os_addr + programmed_fsbl_os_size;
// spi bl31
spi_bl31_addr = spi_fsbl_os_sig_addr + programmed_fsbl_os_sig_size;
spi_bl31_sig_addr = spi_bl31_addr + programmed_bl31_size;
#if defined(Config_Secure_Improve_TRUE)
spi_Kpublic_fw_addr = spi_fsbl_os_sig_addr + programmed_fsbl_os_sig_size;
spi_Kpublic_fw_sig_addr = spi_Kpublic_fw_addr + programmed_Kpublic_fw_size;
spi_Kpublic_tee_addr = spi_Kpublic_fw_sig_addr + programmed_Kpublic_fw_sig_size;
spi_Kpublic_tee_sig_addr = spi_Kpublic_tee_addr + programmed_Kpublic_tee_size;
spi_rescue_addr = spi_Kpublic_tee_sig_addr + programmed_Kpublic_tee_sig_size;
#else
spi_rescue_addr = spi_fsbl_os_sig_addr + programmed_fsbl_os_sig_size;
#endif
spi_rescue_sig_addr = spi_rescue_addr + linux_rescue_hasharray_size;
spi_rsa_pub_addr = SPI_CODE_PART1+0x80000;
spi_bootcode_addr2 = SPI_CODE_PART2;
spi_bootcode_addr3 = SPI_CODE_PART3;
rtprintf("*** %s %d : resetrom_size = 0x%08x\n", __FUNCTION__, __LINE__, resetrom_size);
rtprintf("*** %s %d : mips_resetrom_size = 0x%08x\n", __FUNCTION__, __LINE__, mips_resetrom_size);
rtprintf("*** %s %d : hwsetting_size = 0x%08x\n", __FUNCTION__, __LINE__, hwsetting_size);
rtprintf("*** %s %d : hwsetting_sig_size = 0x%08x\n", __FUNCTION__, __LINE__, hwsetting_sig_size);
rtprintf("*** %s %d : hasharray_size = 0x%08x\n", __FUNCTION__, __LINE__, hasharray_size);
rtprintf("*** %s %d : signature_size = 0x%08x\n", __FUNCTION__, __LINE__, signature_size);
rtprintf("*** %s %d : bootcode2_boot_hasharray_size = 0x%08x\n", __FUNCTION__, __LINE__, bootcode2_boot_hasharray_size);
rtprintf("*** %s %d : bootcode2_boot_signature_size = 0x%08x\n", __FUNCTION__, __LINE__, bootcode2_boot_signature_size);
rtprintf("*** %s %d : bootcode3_boot_hasharray_size = 0x%08x\n", __FUNCTION__, __LINE__, bootcode3_boot_hasharray_size);
rtprintf("*** %s %d : bootcode3_boot_signature_size = 0x%08x\n", __FUNCTION__, __LINE__, bootcode3_boot_signature_size);
rtprintf("*** %s %d : programmed_img_base = 0x%08x\n", __FUNCTION__, __LINE__, (unsigned int)programmed_img_base);
rtprintf("*** %s %d : programmed_img_size = 0x%08x\n", __FUNCTION__, __LINE__, programmed_img_size);
rtprintf("*** %s %d : bootcode2_boot_programmed_img_base = 0x%08x\n", __FUNCTION__, __LINE__, (unsigned int)bootcode2_boot_programmed_img_base);
rtprintf("*** %s %d : bootcode2_boot_programmed_img_size = 0x%08x\n", __FUNCTION__, __LINE__, bootcode2_boot_programmed_img_size);
rtprintf("*** %s %d : bootcode3_boot_programmed_img_base = 0x%08x\n", __FUNCTION__, __LINE__, (unsigned int)bootcode3_boot_programmed_img_base);
rtprintf("*** %s %d : bootcode3_boot_programmed_img_size = 0x%08x\n", __FUNCTION__, __LINE__, bootcode3_boot_programmed_img_size);
rtprintf("*** %s %d : linux_rescue_hasharray = 0x%08x\n", __FUNCTION__, __LINE__, (unsigned int)linux_rescue_hasharray);
rtprintf("*** %s %d : linux_rescue_hasharray_size = 0x%08x\n", __FUNCTION__, __LINE__, linux_rescue_hasharray_size);
rtprintf("*** %s %d : linux_rescue_signature = 0x%08x\n", __FUNCTION__, __LINE__, (unsigned int)linux_rescue_signature);
rtprintf("*** %s %d : linux_rescue_signature_size = 0x%08x\n", __FUNCTION__, __LINE__, linux_rescue_signature_size);
rtprintf("*** %s %d : dcas_key_sig_size = 0x%08x\n", __FUNCTION__, __LINE__, dcas_key_sig_size);
/* reserve one block in 0xbecf_f000 ~ 0xbecf_ffff for ext_param */
total_block_cnt = total_block_cnt - 1;
/***********************************************************************
* determine flash type and program flow
* 0 for nand flash FLASH_TYPE_NAND
* 1 for spi nor FLASH_TYPE_SPI
* 2 for eMMC FLASH_TYPE_EMMC
***********************************************************************/
verify_after_write = 0;
force_secure = 0;
test_secure = 0;
noreset = 0;
#if defined(FPGA_BOOT_NAND) || defined(RTK_FLASH_NAND)
flash_type = FLASH_TYPE_NAND;
verify_after_write = 1;
#elif defined(FPGA_BOOT_EMMC) || defined(RTK_FLASH_EMMC)
flash_type = FLASH_TYPE_EMMC;
verify_after_write = 1;
#else
flash_type = FLASH_TYPE_SPI;
#endif
rtprintf("flash_type: ");
#ifdef FOR_ICE_LOAD
prints("flash_type: ");
#endif
switch( flash_type )
{
case FLASH_TYPE_SPI:
#ifdef FOR_ICE_LOAD
prints("SPI\n");
#endif
rtprintf("SPI\n");
flash_magicno = FLASH_MAGICNO_NOR_SERIAL;
do_erase = do_erase_s;
do_write = do_write_s;
do_identify = do_identify_s;
do_init = do_init_s;
do_exit = do_exit_s;
do_read = NULL;
do_hide_hwsetting = NULL;
env_param_addr = (unsigned char *)SPI_ENV_PARAM_ADDR;
break;
case FLASH_TYPE_EMMC:
#ifdef FOR_ICE_LOAD
prints("eMMC\n");
#endif
rtprintf("eMMC\n");
flash_magicno = FLASH_MAGICNO_EMMC;
do_erase = do_erase_e;
do_write = do_write_e;
do_identify = do_identify_e;
do_init = do_init_e;
do_exit = do_exit_e;
do_read = do_read_e;
do_hide_hwsetting = do_hide_hwsetting_e;
env_param_addr = (unsigned char *)NAND_ENV_DDR_BASE;
break;
case FLASH_TYPE_NAND:
#ifdef FOR_ICE_LOAD
prints("nand\n");
#endif
rtprintf("nand\n");
flash_magicno = FLASH_MAGICNO_NAND;
do_erase = do_erase_n;
do_write = do_write_n;
do_identify = do_identify_n;
do_init = do_init_n;
do_exit = do_exit_n;
do_read = NULL;
do_hide_hwsetting = NULL;
env_param_addr = (unsigned char *)NAND_ENV_DDR_BASE;
break;
default:
#ifdef FOR_ICE_LOAD
prints("unknown!\n");
#endif
rtprintf("unknown!\n");
return -1;
break;
}
/***********************************************************************
* update bootcode size of the HW setting table
***********************************************************************/
#ifdef MAGALLAN_PRJ
if( check_secure_boot() != NDS_SECURE_BOOT ) {
// find bootcode size field in HW setting table
temp_ptr32 = (unsigned int *)hwsetting;
res = 0;
for( idx = 0; idx < ( hwsetting_size >> 2); idx += temp )
{
reg_addr = swap_endian( temp_ptr32[idx] );
switch( reg_addr & 0x3 )
{
case 1: // poll operation: 3 word
case 2: // mask operation: 3 word
temp = 3;
break;
default: // write/nop operation: 2 word
temp = 2;
break;
}
if( reg_addr == BOOTCODE_SIZE_ADDR ) {
// change to real bootcode size
rtprintf("update hwsetting reg(0x%08x) with 0x%08x\n", reg_addr, *((unsigned int *)programmed_img_base));
temp_ptr32[idx + 1] = *((unsigned int *)programmed_img_base);
res = 1;
break;
}
}
}
#endif
/***********************************************************************
* calculate images start address
***********************************************************************/
logo_addr = 0x0;
logo2_addr = 0x0;
logo3_addr = 0x0;
logo4_addr = 0x0;
logo5_addr = 0x0;
logo6_addr = 0x0;
logo7_addr = 0x0;
logo8_addr = 0x0;
linux_sec1_addr = 0;
linux_sec1_size = 0;
linux_sec2_addr = 0;
linux_sec2_size = 0;
if( (flash_magicno == FLASH_MAGICNO_NAND) || (flash_magicno == FLASH_MAGICNO_EMMC) )
{
// data will be copied to DDR when NAND oreMMC,
// so we need to fill with corresponding DRAM address
temp = EXT_PARA_DDR_BASE + sizeof(param);
rtprintf(" EXT_PARA_DDR_BASE = 0x%08x\n", EXT_PARA_DDR_BASE);
rtprintf(" sizeof(param) = 0x%08x\n", sizeof(param));
rtprintf(" temp = 0x%08x\n", temp);
logo_addr = (unsigned char *)temp; temp += logo_size;
logo2_addr = (unsigned char *)temp; temp += logo2_size;
logo3_addr = (unsigned char *)temp; temp += logo3_size;
logo4_addr = (unsigned char *)temp; temp += logo4_size;
logo5_addr = (unsigned char *)temp; temp += logo5_size;
logo6_addr = (unsigned char *)temp; temp += logo6_size;
logo7_addr = (unsigned char *)temp; temp += logo7_size;
logo8_addr = (unsigned char *)temp; temp += logo8_size;
linux_sec1_addr = (unsigned char *)temp;
linux_sec1_size = programmed_linux_rescue_img_size;
linux_sec2_addr = 0;
linux_sec2_size = 0;
rtprintf(" logo_addr = 0x%08x\n", logo_addr);
rtprintf(" logo2_addr = 0x%08x\n", logo2_addr);
rtprintf(" logo3_addr = 0x%08x\n", logo3_addr);
rtprintf(" logo4_addr = 0x%08x\n", logo4_addr);
rtprintf(" logo5_addr = 0x%08x\n", logo5_addr);
rtprintf(" logo6_addr = 0x%08x\n", logo6_addr);
rtprintf(" logo7_addr = 0x%08x\n", logo7_addr);
rtprintf(" logo8_addr = 0x%08x\n", logo8_addr);
rtprintf(" linux_sec1_addr = 0x%08x\n", linux_sec1_addr);
rtprintf(" linux_sec1_size = 0x%08x\n", linux_sec1_size);
}
else if (flash_magicno == FLASH_MAGICNO_NOR_SERIAL) // NOR flash case
{
res = check_secure_boot();
if( res == DCAS_SECURE_BOOT ) {
temp = ((programmed_img_size + hwsetting_size + dcas_key_sig_size ) / block_size )+ 1;
}
else {
temp = ((programmed_img_size + hwsetting_size) / block_size )+ 1;
}
total_block_cnt -= temp;
temp_ptr = (unsigned char *)(spi_hwsetting_addr + (temp * block_size));
rtprintf(" spi_resetrom_addr = 0x%08x\n", spi_resetrom_addr);
rtprintf(" spi_mips_resetrom_addr = 0x%08x\n", spi_mips_resetrom_addr);
rtprintf(" spi_param_addr = 0x%08x\n", spi_param_addr);
rtprintf(" spi_hwsetting_addr = 0x%08x\n", spi_hwsetting_addr);
rtprintf(" spi_bootcode_addr = 0x%08x\n", spi_bootcode_addr);
rtprintf(" spi_key_sig_addr = 0x%08x\n", spi_key_sig_addr);
rtprintf(" logo_addr = 0x%08x\n", logo_addr);
rtprintf(" logo2_addr = 0x%08x\n", logo2_addr);
rtprintf(" logo3_addr = 0x%08x\n", logo3_addr);
rtprintf(" logo4_addr = 0x%08x\n", logo4_addr);
rtprintf(" logo5_addr = 0x%08x\n", logo5_addr);
rtprintf(" logo6_addr = 0x%08x\n", logo6_addr);
rtprintf(" logo7_addr = 0x%08x\n", logo7_addr);
rtprintf(" logo8_addr = 0x%08x\n", logo8_addr);
rtprintf(" linux_sec1_addr = 0x%08x\n", linux_sec1_addr);
rtprintf(" linux_sec1_size = 0x%08x\n", linux_sec1_size);
}
else
{
rtprintf("unknown flash_magicno\n");
return -66;
}
/***********************************************************************
* assign value to param object
***********************************************************************/
param.secure_mode = check_secure_boot();
param.flash_type = flash_magicno;
param.region = 0;
param.mac_hi = Param_MAC_hi;
param.mac_lo = Param_MAC_lo;
param.array_img_saddr = 0;
param.array_img_size = 0;
param.secure_mode = check_secure_boot();
param.rescue_img_size = programmed_linux_rescue_img_size;
param.rescue_img_addr = 0;
param.rescue_img_part0_saddr = linux_sec1_addr;
param.rescue_img_part0_len = linux_sec1_size;
param.rescue_img_part1_saddr = linux_sec2_addr;
param.rescue_img_part1_len = linux_sec2_size;
//clear logo value if logo2, logo3 ,logo4 was not used
param.logo_img_saddr = 0;
param.logo2_img_saddr = 0;
param.logo3_img_saddr = 0;
param.logo4_img_saddr = 0;
param.logo5_img_saddr = 0;
param.logo6_img_saddr = 0;
param.logo7_img_saddr = 0;
param.logo8_img_saddr = 0;
param.logo_img_len = 0;
param.logo2_img_len = 0;
param.logo3_img_len = 0;
param.logo4_img_len = 0;
param.logo5_img_len = 0;
param.logo6_img_len = 0;
param.logo7_img_len = 0;
param.logo8_img_len = 0;
param.logo_type = 0;
param.logo2_type = 0;
param.logo3_type = 0;
param.logo4_type = 0;
param.logo5_type = 0;
param.logo6_type = 0;
param.logo7_type = 0;
param.logo8_type = 0;
param.logo_offset = 0;
param.logo2_offset = 0;
param.logo3_offset = 0;
param.logo4_offset = 0;
param.logo5_offset = 0;
param.logo6_offset = 0;
param.logo7_offset = 0;
param.logo8_offset = 0;
param.logo_reg_5370 = 0;
param.logo2_reg_5370 = 0;
param.logo3_reg_5370 = 0;
param.logo4_reg_5370 = 0;
param.logo5_reg_5370 = 0;
param.logo6_reg_5370 = 0;
param.logo7_reg_5370 = 0;
param.logo8_reg_5370 = 0;
param.logo_reg_5374 = 0;
param.logo2_reg_5374 = 0;
param.logo3_reg_5374 = 0;
param.logo4_reg_5374 = 0;
param.logo5_reg_5374 = 0;
param.logo6_reg_5374 = 0;
param.logo7_reg_5374 = 0;
param.logo8_reg_5374 = 0;
param.logo_reg_5378 = 0;
param.logo2_reg_5378 = 0;
param.logo3_reg_5378 = 0;
param.logo4_reg_5378 = 0;
param.logo5_reg_5378 = 0;
param.logo6_reg_5378 = 0;
param.logo7_reg_5378 = 0;
param.logo8_reg_5378 = 0;
param.logo_reg_537c = 0;
param.logo2_reg_537c = 0;
param.logo3_reg_537c = 0;
param.logo4_reg_537c = 0;
param.logo5_reg_537c = 0;
param.logo6_reg_537c = 0;
param.logo7_reg_537c = 0;
param.logo8_reg_537c = 0;
// clear hdmi key
for (i = 0; i < sizeof(param.hdmi_key1); i++)
param.hdmi_key1[i] = 0;
for (i = 0; i < sizeof(param.hdmi_key2); i++)
param.hdmi_key2[i] = 0;
for (i = 0; i < sizeof(param.hdmi_key3); i++)
param.hdmi_key3[i] = 0;
for (i = 0; i < sizeof(param.hdmi_key4); i++)
param.hdmi_key4[i] = 0;
for (i = 0; i < sizeof(param.hdmi_key5); i++)
param.hdmi_key5[i] = 0;
for (i = 0; i < sizeof(param.hdmi_key6); i++)
param.hdmi_key6[i] = 0;
set_memory(param.custom_field, 0, sizeof(param.custom_field));
#if defined(Logo_Source_FLASH)
param.logo_img_saddr = logo_addr;
param.logo_img_len = logo_size;
#if defined(Logo_Type_NTSC)
param.logo_type = 0;
#elif defined(Logo_Type_PAL)
param.logo_type = 1;
#elif defined(Logo_Type_1080p50)
param.logo_type = 2;
#elif defined(Logo_Type_1080p60)
param.logo_type = 3;
#endif
param.logo_offset = Logo_Offset;
param.logo_reg_5370 = Logo_Reg5370;
param.logo_reg_5374 = Logo_Reg5374;
param.logo_reg_5378 = Logo_Reg5378;
param.logo_reg_537c = Logo_Reg537c;
#endif
#if defined(Logo2_Source_FLASH)
param.logo2_img_saddr = logo2_addr;
param.logo2_img_len = logo2_size;
#if defined(Logo2_Type_NTSC)
param.logo2_type = 0;
#elif defined(Logo2_Type_PAL)
param.logo2_type = 1;
#elif defined(Logo2_Type_1080p50)
param.logo2_type = 2;
#elif defined(Logo2_Type_1080p60)
param.logo2_type = 3;
#endif
param.logo2_offset = Logo2_Offset;
param.logo2_reg_5370 = Logo2_Reg5370;
param.logo2_reg_5374 = Logo2_Reg5374;
param.logo2_reg_5378 = Logo2_Reg5378;
param.logo2_reg_537c = Logo2_Reg537c;
#endif
#if defined(Logo3_Source_FLASH)
param.logo3_img_saddr = logo3_addr;
param.logo3_img_len = logo3_size ;
#if defined(Logo3_Type_NTSC)
param.logo3_type = 0 ;
#elif defined(Logo3_Type_PAL)
param.logo3_type = 1 ;
#elif defined(Logo3_Type_1080p50)
param.logo3_type = 2;
#elif defined(Logo3_Type_1080p60)
param.logo3_type = 3;
#endif
param.logo3_offset = Logo3_Offset;
param.logo3_reg_5370 = Logo3_Reg5370;
param.logo3_reg_5374 = Logo3_Reg5374;
param.logo3_reg_5378 = Logo3_Reg5378;
param.logo3_reg_537c = Logo3_Reg537c;
#endif
#if defined(Logo4_Source_FLASH)
param.logo4_img_saddr = logo4_addr;
param.logo4_img_len = logo4_size ;
#if defined(Logo4_Type_NTSC)
param.logo4_type = 0 ;
#elif defined(Logo4_Type_PAL)
param.logo4_type = 1 ;
#elif defined(Logo4_Type_1080p50)
param.logo4_type = 2;
#elif defined(Logo4_Type_1080p60)
param.logo4_type = 3;
#endif
param.logo4_offset = Logo4_Offset;
param.logo4_reg_5370 = Logo4_Reg5370;
param.logo4_reg_5374 = Logo4_Reg5374;
param.logo4_reg_5378 = Logo4_Reg5378;
param.logo4_reg_537c = Logo4_Reg537c;
#endif
#if defined(Logo5_Source_FLASH)
param.logo5_img_saddr = logo5_addr;
param.logo5_img_len = logo5_size ;
#if defined(Logo5_Type_NTSC)
param.logo5_type = 0 ;
#elif defined(Logo5_Type_PAL)
param.logo5_type = 1 ;
#elif defined(Logo5_Type_1080p50)
param.logo5_type = 2;
#elif defined(Logo5_Type_1080p60)
param.logo5_type = 3;
#endif
param.logo5_offset = Logo5_Offset;
param.logo5_reg_5370 = Logo5_Reg5370;
param.logo5_reg_5374 = Logo5_Reg5374;
param.logo5_reg_5378 = Logo5_Reg5378;
param.logo5_reg_537c = Logo5_Reg537c;
#endif
#if defined(Logo6_Source_FLASH)
param.logo6_img_saddr = logo6_addr;
param.logo6_img_len = logo6_size ;
#if defined(Logo6_Type_NTSC)
param.logo6_type = 0 ;
#elif defined(Logo6_Type_PAL)
param.logo6_type = 1 ;
#elif defined(Logo6_Type_1080p50)
param.logo6_type = 2;
#elif defined(Logo6_Type_1080p60)
param.logo6_type = 3;
#endif
param.logo6_offset = Logo6_Offset;
param.logo6_reg_5370 = Logo6_Reg5370;
param.logo6_reg_5374 = Logo6_Reg5374;
param.logo6_reg_5378 = Logo6_Reg5378;
param.logo6_reg_537c = Logo6_Reg537c;
#endif
#if defined(Logo7_Source_FLASH)
param.logo7_img_saddr = logo7_addr;
param.logo7_img_len = logo7_size ;
#if defined(Logo7_Type_NTSC)
param.logo7_type = 0 ;
#elif defined(Logo7_Type_PAL)
param.logo7_type = 1 ;
#elif defined(Logo7_Type_1080p50)
param.logo7_type = 2;
#elif defined(Logo7_Type_1080p60)
param.logo7_type = 3;
#endif
param.logo7_offset = Logo7_Offset;
param.logo7_reg_5370 = Logo7_Reg5370;
param.logo7_reg_5374 = Logo7_Reg5374;
param.logo7_reg_5378 = Logo7_Reg5378;
param.logo7_reg_537c = Logo7_Reg537c;
#endif