-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathdev_tree.c
More file actions
2533 lines (2260 loc) · 83.4 KB
/
Copy pathdev_tree.c
File metadata and controls
2533 lines (2260 loc) · 83.4 KB
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
/* Copyright (c) 2012-2015,2017-2021 The Linux Foundation. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of The Linux Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <libfdt.h>
#include <dev_tree.h>
#include <lib/ptable.h>
#include <malloc.h>
#include <qpic_nand.h>
#include <stdlib.h>
#include <string.h>
#include <platform.h>
#include <board.h>
#include <list.h>
#include <kernel/thread.h>
#include <kernel/event.h>
#include <target.h>
#include <partial_goods.h>
#include <boot_device.h>
#include <platform.h>
#include <scm.h>
#include <partition_parser.h>
#if WITH_LIB_LIBUFDT
#include <libufdt_sysdeps.h>
#include <ufdt_overlay.h>
#endif
#include <boot_stats.h>
#include <verifiedboot.h>
#if WITH_LK2ND_DEVICE
#include <lk2nd/device.h>
#endif
#define NODE_PROPERTY_MAX_LEN 64
#define ADD_OF(a, b) (UINT_MAX - b > a) ? (a + b) : UINT_MAX
#define ADDR_ALIGNMENT 16
/** 512KB stack **/
#define DTBO_STACK_SIZE (524288)
#define MAX_DTBO_SZ 2097152
static bool dtbo_needed = true;
static void *board_dtb = NULL;
static void *soc_dtb = NULL;
static void *final_dtb_hdr = NULL;
static event_t dtbo_event;
dtbo_error ret = DTBO_SUCCESS;
struct dt_entry_v1
{
uint32_t platform_id;
uint32_t variant_id;
uint32_t soc_rev;
uint32_t offset;
uint32_t size;
};
#if ENABLE_BOOTDEVICE_MOUNT || DYNAMIC_PARTITION_SUPPORT
/* Look up table for fstab node */
struct fstab_node
{
const char *parent_node;
const char *node_prop;
const char *device_path_id;
};
static struct fstab_node dynamic_fstab_table =
{
"/firmware/android/fstab", "status", ""
};
static struct fstab_node fstab_table =
{
"/firmware/android/fstab", "dev", "/soc/"
};
#endif
static struct dt_mem_node_info mem_node;
static int platform_dt_absolute_match(struct dt_entry *cur_dt_entry, struct dt_entry_node *dt_list);
static struct dt_entry *platform_dt_match_best(struct dt_entry_node *dt_list);
static int update_dtb_entry_node(struct dt_entry_node *dt_list, uint32_t dtb_info);
extern int target_is_emmc_boot(void);
extern uint32_t target_dev_tree_mem(void *fdt, uint32_t memory_node_offset);
static int update_fstab_node(void *fdt);
/* TODO: This function needs to be moved to target layer to check violations
* against all the other regions as well.
*/
extern int check_aboot_addr_range_overlap(uintptr_t start, uint32_t size);
#if WITH_LK2ND_DEVICE
static struct dt_entry lk2nd_dt_override;
#endif
static int dtbo_idx = INVALID_PTN;
int get_dtbo_idx (void)
{
return dtbo_idx;
}
static int dtb_idx = INVALID_PTN;
int get_dtb_idx (void)
{
return dtb_idx;
}
int fdt_check_header_ext(const void *fdt)
{
uintptr_t fdt_start, fdt_end;
fdt_start = (uintptr_t)fdt;
if(fdt_start + fdt_totalsize(fdt) < fdt_start)
{
dprintf(CRITICAL,"Integer over in fdt header %s\t%d",__func__,__LINE__);
return FDT_ERR_BADOFFSET;
}
fdt_end = fdt_start + fdt_totalsize(fdt);
if (((uint64_t)fdt_start + (uint64_t)fdt_off_dt_struct(fdt) + (uint64_t)fdt_size_dt_struct(fdt)) > UINT_MAX)
return FDT_ERR_BADOFFSET;
if ((fdt_start + fdt_off_dt_struct(fdt) + fdt_size_dt_struct(fdt)) > fdt_end)
return FDT_ERR_BADOFFSET;
if (((uint64_t)fdt_start + (uint64_t)fdt_off_dt_strings(fdt) + (uint64_t)fdt_size_dt_strings(fdt)) > UINT_MAX)
return FDT_ERR_BADOFFSET;
if ((fdt_start + fdt_off_dt_strings(fdt) + fdt_size_dt_strings(fdt)) > fdt_end)
return FDT_ERR_BADOFFSET;
return 0;
}
/* Returns soc version if platform id and hardware id matches
otherwise return 0xFFFFFFFF */
#define INVALID_SOC_REV_ID 0XFFFFFFFF
/* Add function to allocate dt entry list, used for recording
* the entry which conform to platform_dt_absolute_match()
*/
static struct dt_entry_node *dt_entry_list_init(void)
{
struct dt_entry_node *dt_node_member = NULL;
dt_node_member = (struct dt_entry_node *)
malloc(sizeof(struct dt_entry_node));
ASSERT(dt_node_member);
list_clear_node(&dt_node_member->node);
dt_node_member->dt_entry_m = (struct dt_entry *)
malloc(sizeof(struct dt_entry));
ASSERT(dt_node_member->dt_entry_m);
memset(dt_node_member->dt_entry_m ,0 ,sizeof(struct dt_entry));
return dt_node_member;
}
/*
* Function to validate dtbo image.
* return: TRUE or FALSE.
*/
dtbo_error load_validate_dtbo_image(void **dtbo_buf, uint32_t *dtbo_image_sz)
{
uint64_t dtbo_total_size = 0;
static void *dtbo_image_buf = NULL;
unsigned int dtbo_image_buf_size;
unsigned int dtbo_partition_size;
unsigned long long ptn, boot_img_sz;
int index = INVALID_PTN;
int page_size = mmc_page_size();
struct dtbo_table_hdr *dtbo_table_header = NULL;
dtbo_error ret = DTBO_SUCCESS;
static bool dtbo_loaded = false;
static unsigned long long ptn_size = 0;
uint32_t recovery_dtbo_size = 0;
void *recovery_appended_dtbo = NULL;
/* If dtbo loaded skip loading */
if (dtbo_loaded)
goto out;
get_recovery_dtbo_info(&recovery_dtbo_size, &recovery_appended_dtbo);
/* Intialize dtbo for recovery header v1 */
if (recovery_dtbo_size && recovery_appended_dtbo) {
dtbo_image_buf = recovery_appended_dtbo;
dtbo_partition_size = recovery_dtbo_size;
ptn_size = recovery_dtbo_size;
} else {
index = partition_get_index("dtbo");
/* Immediately return if dtbo is not supported */
if (index == INVALID_PTN)
{
ret = DTBO_NOT_SUPPORTED;
goto out;
}
ptn = partition_get_offset(index);
if(!ptn)
{
dprintf(CRITICAL, "ERROR: dtbo parition failed to get offset. \n");
ret = DTBO_ERROR;
goto out;
}
ptn_size = partition_get_size(index);
if (ptn_size > MAX_SUPPORTED_DTBO_IMG_BUF)
{
dprintf(CRITICAL, "ERROR: dtbo parition size is greater than supported.\n");
ret = DTBO_ERROR;
goto out;
}
/*
Read dtbo image into scratch region after kernel image.
dtbo_image_buf_size = total_scratch_region_size - boot_img_sz
*/
boot_img_sz = partition_get_size(partition_get_index("boot"));
if (!boot_img_sz)
{
dprintf(CRITICAL, "ERROR: Unable to get boot partition size\n");
ret = DTBO_NOT_SUPPORTED;
goto out;
}
dtbo_image_buf_size = target_get_max_flash_size() - boot_img_sz;
dtbo_partition_size = ptn_size + ADDR_ALIGNMENT;
dtbo_partition_size = ROUND_TO_PAGE(dtbo_partition_size, (page_size - 1)); /* Maximum dtbo size possible */
if (dtbo_partition_size == UINT_MAX ||
dtbo_image_buf_size < dtbo_partition_size)
{
dprintf(CRITICAL, "ERROR: Invalid DTBO partition size\n");
ret = DTBO_NOT_SUPPORTED;
goto out;
}
mmc_set_lun(partition_get_lun(index));
/* read dtbo at last 10MB of scratch */
dtbo_image_buf = target_get_scratch_address() +
(target_get_max_flash_size() - DTBO_IMG_BUF);
dtbo_image_buf =
(void *)ROUND_TO_PAGE((addr_t)dtbo_image_buf, (ADDR_ALIGNMENT-1));
if(dtbo_image_buf == (void *)UINT_MAX)
{
dprintf(CRITICAL, "ERROR: Invalid DTBO image buf addr\n");
ret = DTBO_NOT_SUPPORTED;
goto out;
}
/* Add offset for salt buffer for verification */
dtbo_image_buf += SALT_BUFF_OFFSET;
/* Read dtbo partition with header */
if (mmc_read(ptn, (uint32_t *)(dtbo_image_buf), dtbo_partition_size))
{
dprintf(CRITICAL, "ERROR: dtbo partition mmc read failure \n");
ret = DTBO_ERROR;
goto out;
}
}
/* validate the dtbo image, before reading complete image */
dtbo_table_header = (struct dtbo_table_hdr *)dtbo_image_buf;
/*Check for dtbo magic*/
if (fdt32_to_cpu(dtbo_table_header->magic) != DTBO_TABLE_MAGIC)
{
dprintf(CRITICAL, "dtbo header magic mismatch %x, with %x\n",
fdt32_to_cpu(dtbo_table_header->magic), DTBO_TABLE_MAGIC);
ret = DTBO_ERROR;
goto out;
}
/*Check for dtbo image table size*/
if (fdt32_to_cpu(dtbo_table_header->hdr_size) != sizeof(struct dtbo_table_hdr))
{
dprintf(CRITICAL, "dtbo table header size got corrupted\n");
ret = DTBO_ERROR;
goto out;
}
/*Check for dt entry size of dtbo image*/
if (fdt32_to_cpu(dtbo_table_header->dt_entry_size) != sizeof(struct dtbo_table_entry))
{
dprintf(CRITICAL, "dtbo table dt entry size got corrupted\n");
ret = DTBO_ERROR;
goto out;
}
/*Total size of dtbo */
dtbo_total_size = fdt32_to_cpu(dtbo_table_header->total_size);
if (dtbo_total_size > dtbo_partition_size || dtbo_total_size == 0)
{
dprintf(CRITICAL, "dtbo table total size exceeded the dtbo buffer allocated\n");
ret = DTBO_ERROR;
goto out;
}
/* Total size of dtbo entries */
dtbo_total_size = fdt32_to_cpu(dtbo_table_header->dt_entry_count) *
fdt32_to_cpu(dtbo_table_header->dt_entry_size);
if (dtbo_total_size > dtbo_partition_size || dtbo_total_size == 0)
{
dprintf(CRITICAL, "dtbo table total size exceeded the dtbo buffer allocated\n");
ret = DTBO_ERROR;
goto out;
}
/* Offset should be less than image size */
if (fdt32_to_cpu(dtbo_table_header->dt_entry_offset) > dtbo_partition_size)
{
dprintf(CRITICAL, "dtbo offset exceeds the dtbo buffer allocated\n");
ret = DTBO_ERROR;
goto out;
}
/* Offset + total size is less than image size */
if (dtbo_total_size + fdt32_to_cpu(dtbo_table_header->dt_entry_offset) > dtbo_partition_size)
{
dprintf(CRITICAL, "dtbo size exceeded the dtbo buffer allocated\n");
ret = DTBO_ERROR;
}
out:
if (ret == DTBO_SUCCESS)
{
*dtbo_buf = dtbo_image_buf;
*dtbo_image_sz = (uint32_t)ptn_size;
dtbo_loaded = true;
}
else
{
*dtbo_buf = NULL;
*dtbo_image_sz = 0;
}
return ret;
}
static bool check_all_bits_set(uint32_t matchdt_value)
{
return (matchdt_value & ALL_BITS_SET) == (ALL_BITS_SET);
}
/* Dt selection table for quick reference
| SNO | Dt Property | CDT Property | Exact | Best | Default |
|-----+---------------+-----------------+-------+------+---------+
| | qcom, msm-id | | | | |
| | | PlatformId | Y | N | N |
| | | SocRev | N | Y | N |
| | | FoundryId | Y | N | 0 |
| | qcom,board-id | | | | |
| | | VariantId | Y | N | N |
| | | VariantMajor | N | Y | N |
| | | VariantMinor | N | Y | N |
| | | PlatformSubtype | Y | N | 0 |
| | qcom,pmic-id | | | | |
| | | PmicModelId | Y | N | 0 |
| | | PmicMetalRev | N | Y | N |
| | | PmicLayerRev | N | Y | N |
| | | PmicVariantRev | N | Y | N |
*/
static boolean dtb_read_find_match(dt_info *current_dtb_info, dt_info *best_dtb_info, uint32_t exact_match)
{
int board_id_len;
int platform_id_len = 0;
int pmic_id_len;
int root_offset = 0;
void *dtb = current_dtb_info->aligned_dtb;
uint32_t idx;
const char *platform_prop = NULL;
const char *board_prop = NULL;
const char *pmic_prop = NULL;
boolean find_best_match = false;
current_dtb_info->dt_match_val = 0;
root_offset = fdt_path_offset(dtb, "/");
if (root_offset < 0) {
dprintf(CRITICAL, "ERROR: Unable to locate root node\n");
return false;
}
#if WITH_LK2ND_DEVICE
if (fdt_node_check_compatible(dtb, root_offset, lk2nd_device_get_dtb_compatible()) == 0) {
dprintf(INFO, "Compatible %s matches, mark as best dtb node\n", lk2nd_device_get_dtb_compatible());
current_dtb_info->dt_match_val = UINT_MAX;
current_dtb_info->dt_match_val &= ~exact_match;
goto cleanup;
}
#endif
/* Get the msm-id prop from DTB and find best match */
platform_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,msm-id", &platform_id_len);
if (platform_prop && (platform_id_len > 0) && (!(platform_id_len % PLAT_ID_SIZE))) {
/*Compare msm-id of the dtb vs board*/
current_dtb_info->dt_platform_id = fdt32_to_cpu(((struct plat_id *)platform_prop)->platform_id);
dprintf(SPEW, "Board SOC ID = %x | DT SOC ID = %x\n", (board_platform_id() & SOC_MASK),
(current_dtb_info->dt_platform_id & SOC_MASK));
if ((board_platform_id() & SOC_MASK) == (current_dtb_info->dt_platform_id & SOC_MASK)) {
current_dtb_info->dt_match_val |= BIT(SOC_MATCH);
} else {
dprintf(SPEW, "qcom,msm-id does not match\n");
/* If soc doesn't match, don't select dtb */
current_dtb_info->dt_match_val = BIT(NONE_MATCH);
goto cleanup;
}
/*Compare soc rev of the dtb vs board*/
current_dtb_info->dt_soc_rev = fdt32_to_cpu(((struct plat_id *)platform_prop)->soc_rev);
dprintf(SPEW, "Board SOC Rev = %x | DT SOC Rev =%x\n", board_soc_version(),
current_dtb_info->dt_soc_rev);
if (current_dtb_info->dt_soc_rev == board_soc_version()) {
current_dtb_info->dt_match_val |= BIT(VERSION_EXACT_MATCH);
} else if (current_dtb_info->dt_soc_rev < board_soc_version()) {
current_dtb_info->dt_match_val |= BIT(VERSION_BEST_MATCH);
} else if (current_dtb_info->dt_soc_rev) {
dprintf(SPEW, "SOC version does not match\n");
}
/*Compare Foundry Id of the dtb vs Board*/
current_dtb_info->dt_foundry_id = fdt32_to_cpu(((struct plat_id *)platform_prop)->platform_id) & FOUNDRY_ID_MASK;
dprintf (SPEW, "Board Foundry id = %x | DT Foundry id = %x\n", (board_foundry_id() << PLATFORM_FOUNDRY_SHIFT), current_dtb_info->dt_foundry_id);
if (current_dtb_info->dt_foundry_id == (board_foundry_id() << PLATFORM_FOUNDRY_SHIFT)) {
current_dtb_info->dt_match_val |= BIT (FOUNDRYID_EXACT_MATCH);
} else if (current_dtb_info->dt_foundry_id == 0 ){
current_dtb_info->dt_match_val |= BIT (FOUNDRYID_DEFAULT_MATCH);
} else {
dprintf(SPEW, "soc foundry does not match\n");
/* If soc doesn't match, don't select dtb */
current_dtb_info->dt_match_val = BIT(NONE_MATCH);
goto cleanup;
}
} else {
dprintf(SPEW, "qcom,msm-id does not exist (or) is (%d) not a multiple of (%d)\n", platform_id_len, PLAT_ID_SIZE);
}
/* Get the properties like variant id, subtype from DTB and compare the DTB vs Board */
board_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,board-id", &board_id_len);
if (board_prop && (board_id_len > 0) && (!(board_id_len % BOARD_ID_SIZE))) {
current_dtb_info->dt_variant_id = fdt32_to_cpu(((struct board_id *)board_prop)->variant_id);
current_dtb_info->dt_platform_subtype = fdt32_to_cpu(((struct board_id *)board_prop)->platform_subtype);
if (current_dtb_info->dt_platform_subtype == 0)
current_dtb_info->dt_platform_subtype = fdt32_to_cpu(((struct board_id *)board_prop)->variant_id) >> PLATFORM_SUBTYPE_SHIFT_ID;
dprintf(SPEW, "Board variant id = %x | DT variant id = %x\n",board_hardware_id(), current_dtb_info->dt_variant_id);
current_dtb_info->dt_variant_major = current_dtb_info->dt_variant_id & VARIANT_MAJOR_MASK;
current_dtb_info->dt_variant_minor = current_dtb_info->dt_variant_id & VARIANT_MINOR_MASK;
current_dtb_info->dt_variant_id = current_dtb_info->dt_variant_id & VARIANT_MASK;
if (current_dtb_info->dt_variant_id == board_hardware_id()) {
current_dtb_info->dt_match_val |= BIT(VARIANT_MATCH);
} else if (current_dtb_info->dt_variant_id) {
dprintf(SPEW, "qcom,board-id doesnot match\n");
/* If board variant doesn't match, don't select dtb */
current_dtb_info->dt_match_val = BIT(NONE_MATCH);
goto cleanup;
}
if (current_dtb_info->dt_variant_major == (board_target_id() & VARIANT_MAJOR_MASK)) {
current_dtb_info->dt_match_val |= BIT(VARIANT_MAJOR_EXACT_MATCH);
} else if (current_dtb_info->dt_variant_major < (board_target_id() & VARIANT_MAJOR_MASK)) {
current_dtb_info->dt_match_val |= BIT(VARIANT_MAJOR_BEST_MATCH);
} else if (current_dtb_info->dt_variant_major) {
dprintf(SPEW, "qcom,board-id major version doesnot match\n");
}
if (current_dtb_info->dt_variant_minor == (board_target_id() & VARIANT_MINOR_MASK)) {
current_dtb_info->dt_match_val |= BIT(VARIANT_MINOR_EXACT_MATCH);
} else if (current_dtb_info->dt_variant_minor < (board_target_id() & VARIANT_MINOR_MASK)) {
current_dtb_info->dt_match_val |= BIT(VARIANT_MINOR_BEST_MATCH);
} else if (current_dtb_info->dt_variant_minor) {
dprintf(SPEW, "qcom,board-id minor version doesnot match\n");
}
dprintf(SPEW, "Board platform subtype = %x | DT platform subtype = %x\n",
board_hardware_subtype(), current_dtb_info->dt_platform_subtype);
if (current_dtb_info->dt_platform_subtype == board_hardware_subtype()) {
current_dtb_info->dt_match_val |= BIT(SUBTYPE_EXACT_MATCH);
} else if (current_dtb_info->dt_platform_subtype == 0) {
current_dtb_info->dt_match_val |= BIT(SUBTYPE_DEFAULT_MATCH);
} else if (current_dtb_info->dt_platform_subtype) {
dprintf(SPEW, "subtype id doesnot match\n");
/* If board platform doesn't match, don't select dtb */
current_dtb_info->dt_match_val = BIT(NONE_MATCH);
goto cleanup;
}
} else {
dprintf(SPEW, "qcom,board-id does not exist (or)(%d) is not a multiple of (%d)\n",
board_id_len, BOARD_ID_SIZE);
}
/* Get the pmic property from DTB then compare the DTB vs Board */
pmic_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,pmic-id", &pmic_id_len);
if (pmic_prop && (pmic_id_len > 0) && (!(pmic_id_len % sizeof(struct pmic_id))))
{
pmic_info curr_pmic_info;
pmic_info best_pmic_info;
unsigned int pmic_entry_indx;
unsigned int pmic_entries_count;
/* Find all pmic entries count */
pmic_entries_count = pmic_id_len/sizeof(struct pmic_id);
memset(&best_pmic_info, 0, sizeof(pmic_info));
for (pmic_entry_indx = 0; pmic_entry_indx < pmic_entries_count; pmic_entry_indx++)
{
memset(&curr_pmic_info, 0, sizeof(pmic_info));
/* Read all pmic info */
/* Compare with board pmic */
for (idx = 0; idx < MAX_PMIC_IDX; idx++)
{
curr_pmic_info.dt_pmic_model[idx] =
fdt32_to_cpu (((struct pmic_id *)pmic_prop)->pmic_version[idx]);
dprintf(SPEW, "pmic_data[%u]:%x\n", idx, curr_pmic_info.dt_pmic_model[idx]);
curr_pmic_info.dt_pmic_rev[idx] =
curr_pmic_info.dt_pmic_model[idx] & PMIC_REV_MASK;
curr_pmic_info.dt_pmic_model[idx] =
curr_pmic_info.dt_pmic_model[idx] & PMIC_MODEL_MASK;
/* Compare with board pmic information & Update bit mask */
if (curr_pmic_info.dt_pmic_model[idx] == (board_pmic_target(idx) & PMIC_MODEL_MASK))
curr_pmic_info.dt_match_val |= BIT (PMIC_MATCH_EXACT_MODEL_IDX0 + idx * PMIC_SHIFT_IDX);
else if (curr_pmic_info.dt_pmic_model[idx] == 0)
curr_pmic_info.dt_match_val |= BIT (PMIC_MATCH_DEFAULT_MODEL_IDX0 + idx * PMIC_SHIFT_IDX);
else
{
curr_pmic_info.dt_match_val |= BIT (NONE_MATCH);
dprintf(SPEW, "PMIC Model doesn't match\n");
break; /* go to next pmic entry */
}
if (curr_pmic_info.dt_pmic_rev[idx] == (board_pmic_target(idx) & PMIC_REV_MASK))
curr_pmic_info.dt_match_val |= BIT(PMIC_MATCH_EXACT_REV_IDX0 + idx * PMIC_SHIFT_IDX);
else if (curr_pmic_info.dt_pmic_rev[idx] < (board_pmic_target(idx) & PMIC_REV_MASK))
curr_pmic_info.dt_match_val |= BIT(PMIC_MATCH_BEST_REV_IDX0 + idx * PMIC_SHIFT_IDX);
else {
dprintf(SPEW, "PMIC revision doesn't match\n");
break; /* go to next pmic entry */
}
}
dprintf(SPEW, "Bestpmicinfo.dtmatchval : %x | cur_pmic_info.dtmatchval: %x\n",
best_pmic_info.dt_match_val, curr_pmic_info.dt_match_val);
/* Update best pmic info, if required */
if(best_pmic_info.dt_match_val < curr_pmic_info.dt_match_val)
memscpy(&best_pmic_info, sizeof(pmic_info), &curr_pmic_info, sizeof(pmic_info));
else if (best_pmic_info.dt_match_val == curr_pmic_info.dt_match_val)
{
if (best_pmic_info.dt_pmic_rev[PMIC_IDX0] < curr_pmic_info.dt_pmic_rev[PMIC_IDX0])
memscpy(&best_pmic_info, sizeof(pmic_info), &curr_pmic_info, sizeof(pmic_info));
else if (best_pmic_info.dt_pmic_rev[PMIC_IDX1] < curr_pmic_info.dt_pmic_rev[PMIC_IDX1])
memscpy(&best_pmic_info, sizeof(pmic_info), &curr_pmic_info, sizeof(pmic_info));
else if (best_pmic_info.dt_pmic_rev[PMIC_IDX2] < curr_pmic_info.dt_pmic_rev[PMIC_IDX2])
memscpy(&best_pmic_info, sizeof(pmic_info), &curr_pmic_info, sizeof(pmic_info));
else if (best_pmic_info.dt_pmic_rev[PMIC_IDX3] < curr_pmic_info.dt_pmic_rev[PMIC_IDX3])
memscpy(&best_pmic_info, sizeof(pmic_info), &curr_pmic_info, sizeof(pmic_info));
}
/* Increment to next pmic entry */
pmic_prop += sizeof (struct pmic_id);
}
dprintf(SPEW, "Best pmic info 0x%0x/0x%x/0x%x/0x%0x for current dt\n",
best_pmic_info.dt_pmic_model[PMIC_IDX0],
best_pmic_info.dt_pmic_model[PMIC_IDX1],
best_pmic_info.dt_pmic_model[PMIC_IDX2],
best_pmic_info.dt_pmic_model[PMIC_IDX3]);
current_dtb_info->dt_match_val |= best_pmic_info.dt_match_val;
current_dtb_info->dt_pmic_rev[PMIC_IDX0] = best_pmic_info.dt_pmic_rev[PMIC_IDX0];
current_dtb_info->dt_pmic_model[PMIC_IDX0] = best_pmic_info.dt_pmic_model[PMIC_IDX0];
current_dtb_info->dt_pmic_rev[PMIC_IDX1] = best_pmic_info.dt_pmic_rev[PMIC_IDX1];
current_dtb_info->dt_pmic_model[PMIC_IDX1] = best_pmic_info.dt_pmic_model[PMIC_IDX1];
current_dtb_info->dt_pmic_rev[PMIC_IDX2] = best_pmic_info.dt_pmic_rev[PMIC_IDX2];
current_dtb_info->dt_pmic_model[PMIC_IDX2] = best_pmic_info.dt_pmic_model[PMIC_IDX2];
current_dtb_info->dt_pmic_rev[PMIC_IDX3] = best_pmic_info.dt_pmic_rev[PMIC_IDX3];
current_dtb_info->dt_pmic_model[PMIC_IDX3] = best_pmic_info.dt_pmic_model[PMIC_IDX3];
}
else
{
dprintf(SPEW, "qcom,pmic-id does not exit (or) is (%d) not a multiple of (%d)\n",
pmic_id_len, PMIC_ID_SIZE);
}
cleanup:
if (current_dtb_info->dt_match_val & BIT(exact_match)) {
if (best_dtb_info->dt_match_val < current_dtb_info->dt_match_val) {
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
find_best_match = true;
} else if (best_dtb_info->dt_match_val == current_dtb_info->dt_match_val) {
find_best_match = true;
if (best_dtb_info->dt_soc_rev < current_dtb_info->dt_soc_rev)
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
else if (best_dtb_info->dt_variant_major < current_dtb_info->dt_variant_major)
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
else if (best_dtb_info->dt_variant_minor < current_dtb_info->dt_variant_minor)
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
else if (best_dtb_info->dt_pmic_rev[0] < current_dtb_info->dt_pmic_rev[0])
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
else if (best_dtb_info->dt_pmic_rev[1] < current_dtb_info->dt_pmic_rev[1])
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
else if (best_dtb_info->dt_pmic_rev[2] < current_dtb_info->dt_pmic_rev[2])
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
else if (best_dtb_info->dt_pmic_rev[3] < current_dtb_info->dt_pmic_rev[3])
memscpy(best_dtb_info, sizeof(dt_info), current_dtb_info, sizeof(dt_info));
else
find_best_match = false;
}
}
return find_best_match;
}
void *get_soc_dtb(void *kernel, void *tags, uint32_t kernel_size, uint32_t dtb_offset)
{
uintptr_t kernel_end_offset = (uintptr_t)kernel + kernel_size;
void *dtb = NULL;
struct fdt_header dtb_header __ALIGNED(8);
uint32_t dtb_size = 0;
dt_info cur_dtb_info = {0};
dt_info best_dtb_info = {0};
uint32_t dtb_cnt = 0;
boolean find_best_dtb = false;
if (!dtb_offset){
dprintf(CRITICAL, "DTB offset is NULL\n");
return NULL;
}
if (((uintptr_t)kernel + (uintptr_t)dtb_offset) < (uintptr_t)kernel) {
return NULL;
}
dtb = kernel + dtb_offset;
while (((uintptr_t)dtb + sizeof(struct fdt_header)) < (uintptr_t)kernel_end_offset) {
/* the DTB could be unaligned, so extract the header,
* and operate on it separately */
memscpy(&dtb_header, sizeof(struct fdt_header), dtb, sizeof(struct fdt_header));
dtb_size = fdt_totalsize((const void *)&dtb_header);
if (fdt_check_header((const void *)&dtb_header) != 0 ||
fdt_check_header_ext((void *)&dtb_header) != 0 ||
((uintptr_t)dtb + dtb_size < (uintptr_t)dtb) ||
((uintptr_t)dtb + dtb_size > (uintptr_t)kernel_end_offset))
break;
cur_dtb_info.dtb = dtb;
cur_dtb_info.aligned_dtb = dtb;
cur_dtb_info.dtb_size = dtb_size;
/* Need to copy DTB if not aligned properly :/ */
if ((uintptr_t)dtb & 7) {
if (dtb_size > MAX_DTBO_SZ) {
dprintf(CRITICAL, "SoC DTB too large: %d\n", dtb_size);
return NULL;
}
if (best_dtb_info.aligned_dtb == tags)
best_dtb_info.aligned_dtb = NULL;
memcpy(tags, dtb, dtb_size);
cur_dtb_info.aligned_dtb = tags;
}
find_best_dtb = dtb_read_find_match(&cur_dtb_info, &best_dtb_info, SOC_MATCH);
if (cur_dtb_info.dt_match_val) {
if (cur_dtb_info.dt_match_val & BIT(SOC_MATCH)) {
if (check_all_bits_set(cur_dtb_info.dt_match_val)) {
dprintf(CRITICAL, "Exact DTB match found. dtbo search is not required\n");
dtbo_needed = false;
}
}
}
dprintf(SPEW, "dtb count = %u local_soc_dt_match val = %x\n", dtb_cnt, best_dtb_info.dt_match_val);
dtb += dtb_size;
if (find_best_dtb) {
dtb_idx = dtb_cnt;
}
dtb_cnt++;
}
if (!best_dtb_info.dtb) {
dprintf(CRITICAL, "No match found for soc dtb type\n");
return NULL;
}
/* Need to copy DTB if not aligned properly :/ */
dtb = best_dtb_info.aligned_dtb;
if (!dtb) {
memcpy(tags, best_dtb_info.dtb, best_dtb_info.dtb_size);
dtb = tags;
}
return dtb;
}
void *get_board_dtb(void *dtbo_image_buf, uint32_t dtbo_image_sz)
{
struct dtbo_table_hdr *dtbo_table_header = dtbo_image_buf;
struct dtbo_table_entry *dtb_table_entry = NULL;
uint32_t dtbo_count = 0;
void *board_dtb = NULL;
uint32_t dtbo_table_entries_count = 0;
uint32_t first_dtbo_table_entry_offset = 0;
struct fdt_header dtb_header __ALIGNED(8);
uint32_t dtb_size = 0;
dt_info cur_dtb_info = {0};
dt_info best_dtb_info = {0};
boolean find_best_dtb = false;
void *tmp; uint32_t max_tmp_size;
if (!dtbo_image_buf) {
dprintf(CRITICAL, "dtbo image buffer is NULL\n");
return NULL;
}
/* Temporary copy DTB after DTBO for alignment */
tmp = (void*)ROUND_TO_PAGE((addr_t)dtbo_image_buf + dtbo_image_sz, (ADDR_ALIGNMENT-1));
max_tmp_size = target_get_scratch_address() + target_get_max_flash_size() - tmp;
first_dtbo_table_entry_offset = fdt32_to_cpu(dtbo_table_header->dt_entry_offset);
if ((uintptr_t)dtbo_image_buf > ((uintptr_t)dtbo_image_buf + (uintptr_t)first_dtbo_table_entry_offset))
{
dprintf(CRITICAL, "dtbo table entry offset is invalid\n");
return NULL;
}
dtb_table_entry = (struct dtbo_table_entry *)(dtbo_image_buf + first_dtbo_table_entry_offset);
dtbo_table_entries_count = fdt32_to_cpu(dtbo_table_header->dt_entry_count);
for (dtbo_count = 0; dtbo_count < dtbo_table_entries_count; dtbo_count++) {
board_dtb = dtbo_image_buf + fdt32_to_cpu(dtb_table_entry->dt_offset);
/* The DTB could be unaligned, so extract the header,
* and operate on it separately */
memscpy(&dtb_header, sizeof(struct fdt_header), board_dtb, sizeof(struct fdt_header));
dtb_size = fdt_totalsize((const void *)&dtb_header);
if (fdt_check_header((const void *)&dtb_header) != 0 ||
fdt_check_header_ext((void *)&dtb_header) != 0 ||
((uintptr_t)board_dtb + dtb_size < (uintptr_t)board_dtb)) {
dprintf(CRITICAL, "No valid board dtb found\n");
break;
}
dprintf(SPEW, "Valid board dtb is found\n");
cur_dtb_info.dtb = board_dtb;
cur_dtb_info.aligned_dtb = board_dtb;
cur_dtb_info.dtb_size = dtb_size;
/* Need to copy DTB if not aligned properly :/ */
if ((uintptr_t)board_dtb & 7) {
if (dtb_size > max_tmp_size) {
dprintf(CRITICAL, "Board DTB too large: %d\n", dtb_size);
return NULL;
}
if (best_dtb_info.aligned_dtb == tmp)
best_dtb_info.aligned_dtb = NULL;
memcpy(tmp, board_dtb, dtb_size);
cur_dtb_info.aligned_dtb = tmp;
}
find_best_dtb = dtb_read_find_match(&cur_dtb_info, &best_dtb_info, VARIANT_MATCH);
dprintf(SPEW, "dtbo count = %u local_board_dt_match =%x\n",dtbo_count, cur_dtb_info.dt_match_val);
dtb_table_entry++;
if (find_best_dtb) {
dtbo_idx = dtbo_count;
}
}
if (!best_dtb_info.dtb) {
dprintf(CRITICAL, "Unable to find the board dtb\n");
return NULL;
}
/* Need to copy DTB if not aligned properly :/ */
board_dtb = best_dtb_info.aligned_dtb;
if (!board_dtb) {
memcpy(tmp, best_dtb_info.dtb, best_dtb_info.dtb_size);
board_dtb = tmp;
}
return board_dtb;
}
static void insert_dt_entry_in_queue(struct dt_entry_node *dt_list, struct dt_entry_node *dt_node_member)
{
list_add_tail(&dt_list->node, &dt_node_member->node);
}
static void dt_entry_list_delete(struct dt_entry_node *dt_node_member)
{
if (list_in_list(&dt_node_member->node)) {
list_delete(&dt_node_member->node);
free(dt_node_member->dt_entry_m);
free(dt_node_member);
}
}
static int dev_tree_compatible(const void *dtb, const void *real_dtb, uint32_t dtb_size,
int root_offset, struct dt_entry_node *dtb_list)
{
const void *prop = NULL;
const char *plat_prop = NULL;
const char *board_prop = NULL;
const char *pmic_prop = NULL;
char *model = NULL;
struct dt_entry *cur_dt_entry;
struct dt_entry *dt_entry_array = NULL;
struct board_id *board_data = NULL;
struct plat_id *platform_data = NULL;
struct pmic_id *pmic_data = NULL;
int len;
int len_board_id;
int len_plat_id;
int min_plat_id_len = 0;
int len_pmic_id;
uint32_t dtb_ver;
uint32_t num_entries = 0;
uint32_t i, j, k, n;
uint32_t msm_data_count;
uint32_t board_data_count;
uint32_t pmic_data_count;
uint32_t dtb_count = 0;;
bool set_dt_entry_is_best = false;
if (!root_offset)
root_offset = fdt_path_offset(dtb, "/");
if (root_offset < 0)
return false;
if (DEBUGLEVEL >= SPEW) {
prop = fdt_getprop(dtb, root_offset, "model", &len);
if (prop && len > 0) {
model = (char *) malloc(sizeof(char) * len);
ASSERT(model);
strlcpy(model, prop, len);
} else {
dprintf(INFO, "model does not exist in device tree\n");
}
}
#if WITH_LK2ND_DEVICE
if (fdt_node_check_compatible(dtb, root_offset, lk2nd_device_get_dtb_compatible()) == 0) {
dprintf(INFO, "Compatible %s matches, mark as best dtb node\n", lk2nd_device_get_dtb_compatible());
set_dt_entry_is_best = true;
}
#endif
/* Find the pmic-id prop from DTB , if pmic-id is present then
* the DTB is version 3, otherwise find the board-id prop from DTB ,
* if board-id is present then the DTB is version 2 */
pmic_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,pmic-id", &len_pmic_id);
board_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,board-id", &len_board_id);
if (pmic_prop && (len_pmic_id > 0) && board_prop && (len_board_id > 0)) {
if ((len_pmic_id % PMIC_ID_SIZE) || (len_board_id % BOARD_ID_SIZE))
{
dprintf(CRITICAL, "qcom,pmic-id(%d) or qcom,board-id(%d) in device tree is not a multiple of (%d %d)\n",
len_pmic_id, len_board_id, PMIC_ID_SIZE, BOARD_ID_SIZE);
return false;
}
dtb_ver = DEV_TREE_VERSION_V3;
min_plat_id_len = PLAT_ID_SIZE;
} else if (board_prop && len_board_id > 0) {
if (len_board_id % BOARD_ID_SIZE)
{
dprintf(CRITICAL, "qcom,board-id in device tree is (%d) not a multiple of (%d)\n",
len_board_id, BOARD_ID_SIZE);
return false;
}
dtb_ver = DEV_TREE_VERSION_V2;
min_plat_id_len = PLAT_ID_SIZE;
} else {
dtb_ver = DEV_TREE_VERSION_V1;
min_plat_id_len = DT_ENTRY_V1_SIZE;
}
/* Get the msm-id prop from DTB */
plat_prop = (const char *)fdt_getprop(dtb, root_offset, "qcom,msm-id", &len_plat_id);
if (!plat_prop || len_plat_id <= 0) {
#if WITH_LK2ND_DEVICE
if (!dtb_list->dt_entry_m) /* Do not log for lk2nd device DTB */
#endif
dprintf(INFO, "qcom,msm-id entry not found\n");
return false;
} else if (len_plat_id % min_plat_id_len) {
dprintf(INFO, "qcom,msm-id in device tree is (%d) not a multiple of (%d)\n",
len_plat_id, min_plat_id_len);
if (dtb_ver == DEV_TREE_VERSION_V1 && len_plat_id == DT_ENTRY_LGE8974_SIZE)
min_plat_id_len = DT_ENTRY_LGE8974_SIZE;
else
return false;
}
/*
* If DTB version is '1' look for <x y z> pair in the DTB
* x: platform_id
* y: variant_id
* z: SOC rev
*/
if (dtb_ver == DEV_TREE_VERSION_V1) {
#if WITH_LK2ND_DEVICE
/* Cannot override with more than one entry */
if (dtb_list->dt_entry_m && len_plat_id != min_plat_id_len) {
if (model)
free(model);
return false;
}
#endif
cur_dt_entry = (struct dt_entry *)
malloc(sizeof(struct dt_entry));
if (!cur_dt_entry) {
dprintf(CRITICAL, "Out of memory\n");
return false;
}
memset(cur_dt_entry, 0, sizeof(struct dt_entry));
while (len_plat_id) {
cur_dt_entry->platform_id = fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->platform_id);
cur_dt_entry->variant_id = fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->variant_id);
cur_dt_entry->soc_rev = fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->soc_rev);
cur_dt_entry->board_hw_subtype =
fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->variant_id) >> 0x18;
cur_dt_entry->pmic_rev[0] = board_pmic_target(0);
cur_dt_entry->pmic_rev[1] = board_pmic_target(1);
cur_dt_entry->pmic_rev[2] = board_pmic_target(2);
cur_dt_entry->pmic_rev[3] = board_pmic_target(3);
cur_dt_entry->offset = (uint32_t)real_dtb;
cur_dt_entry->size = dtb_size;
cur_dt_entry->is_best = set_dt_entry_is_best;
if (min_plat_id_len == DT_ENTRY_LGE8974_SIZE)
cur_dt_entry->board_hw_subtype = fdt32_to_cpu(((const struct dt_entry_v1 *)plat_prop)->offset);
dprintf(SPEW, "Found an appended flattened device tree (%s - %u %u 0x%x)\n",
model ? model : "unknown",
cur_dt_entry->platform_id, cur_dt_entry->variant_id, cur_dt_entry->soc_rev);
if (platform_dt_absolute_match(cur_dt_entry, dtb_list)) {
dprintf(SPEW, "Device tree exact match the board: <%u %u 0x%x> != <%u %u 0x%x>\n",
cur_dt_entry->platform_id,
cur_dt_entry->variant_id,
cur_dt_entry->soc_rev,
board_platform_id(),
board_hardware_id(),
board_soc_version());
} else {
dprintf(SPEW, "Device tree's msm_id doesn't match the board: <%u %u 0x%x> != <%u %u 0x%x>\n",
cur_dt_entry->platform_id,
cur_dt_entry->variant_id,
cur_dt_entry->soc_rev,
board_platform_id(),
board_hardware_id(),
board_soc_version());
}
plat_prop += min_plat_id_len;
len_plat_id -= min_plat_id_len;
}
free(cur_dt_entry);
}
/*
* If DTB Version is '3' then we have split DTB with board & msm data & pmic
* populated saperately in board-id & msm-id & pmic-id prop respectively.
* Extract the data & prepare a look up table
*/
else if (dtb_ver == DEV_TREE_VERSION_V2 || dtb_ver == DEV_TREE_VERSION_V3) {
board_data_count = (len_board_id / BOARD_ID_SIZE);
msm_data_count = (len_plat_id / PLAT_ID_SIZE);
/* If dtb version is v2.0, the pmic_data_count will be <= 0 */
pmic_data_count = (len_pmic_id / PMIC_ID_SIZE);
#if WITH_LK2ND_DEVICE
/* Cannot override with more than one entry */
if (dtb_list->dt_entry_m && (board_data_count > 1 || msm_data_count > 1 || pmic_data_count > 1)) {
if (model)
free(model);
return false;
}
#endif
/* If we are using dtb v3.0, then we have split board, msm & pmic data in the DTB
* If we are using dtb v2.0, then we have split board & msmdata in the DTB
*/