-
Notifications
You must be signed in to change notification settings - Fork 490
Expand file tree
/
Copy pathaboot.c
More file actions
5787 lines (5076 loc) · 154 KB
/
Copy pathaboot.c
File metadata and controls
5787 lines (5076 loc) · 154 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) 2009, Google Inc.
* All rights reserved.
*
* Copyright (c) 2009-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 BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 <app.h>
#include <debug.h>
#include <arch/arm.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <kernel/thread.h>
#include <arch/ops.h>
#include <dev/flash.h>
#include <dev/flash-ubi.h>
#include <lib/ptable.h>
#include <dev/keys.h>
#include <dev/fbcon.h>
#include <baseband.h>
#include <target.h>
#include <mmc.h>
#include <partition_parser.h>
#include <ab_partition_parser.h>
#include <verifiedboot.h>
#include <platform.h>
#include <crypto_hash.h>
#include <malloc.h>
#include <boot_stats.h>
#include <platform/iomap.h>
#include <boot_device.h>
#include <boot_verifier.h>
#include <image_verify.h>
#include <decompress.h>
#include <platform/timer.h>
#include <sys/types.h>
#if USE_RPMB_FOR_DEVINFO
#include <rpmb.h>
#endif
#if ENABLE_WBC
#include <pm_smbchg_common.h>
#endif
#if DEVICE_TREE
#include <libfdt.h>
#include <dev_tree.h>
#endif
#if WDOG_SUPPORT
#include <wdog.h>
#endif
#include <reboot.h>
#include "image_verify.h"
#include "recovery.h"
#include "boot.h"
#include "bootimg.h"
#include "fastboot.h"
#include "sparse_format.h"
#include "meta_format.h"
#include "mmc.h"
#include "devinfo.h"
#include "board.h"
#include "scm.h"
#include "mdtp.h"
#include "secapp_loader.h"
#include <menu_keys_detect.h>
#include <display_menu.h>
#include "fastboot_test.h"
#if WITH_LK2ND
#include <lk2nd/init.h>
#endif
#if WITH_LK2ND_DEVICE
#include <lk2nd/device.h>
#endif
#if WITH_LK2ND_BOOT
#include <lk2nd/boot.h>
#endif
extern bool target_use_signed_kernel(void);
extern void platform_uninit(void);
extern void target_uninit(void);
extern int get_target_boot_params(const char *cmdline, const char *part,
char **buf);
void *info_buf;
#if !ABOOT_STANDALONE
void write_device_info_mmc(device_info *dev);
void write_device_info_flash(device_info *dev);
#endif
static int aboot_save_boot_hash_mmc(uint32_t image_addr, uint32_t image_size);
static int aboot_frp_unlock(char *pname, void *data, unsigned sz);
static inline uint64_t validate_partition_size(struct ptentry *ptn);
bool pwr_key_is_pressed = false;
unsigned boot_into_recovery = 0;
static bool is_systemd_present=false;
static void publish_getvar_multislot_vars(void);
/* fastboot command function pointer */
typedef void (*fastboot_cmd_fn) (const char *, void *, unsigned);
bool get_perm_attr_status(void);
struct fastboot_cmd_desc {
char * name;
fastboot_cmd_fn cb;
};
#define EXPAND(NAME) #NAME
#define TARGET(NAME) EXPAND(NAME)
#define DISPLAY_PANEL_HDMI "hdmi"
#ifdef MEMBASE
#define EMMC_BOOT_IMG_HEADER_ADDR (0xFF000+(MEMBASE))
#else
#define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000
#endif
#ifndef MEMSIZE
#define MEMSIZE 1024*1024
#endif
#define MAX_TAGS_SIZE 1024
#define PLL_CODES_OFFSET 4096
/* make 4096 as default size to ensure EFS,EXT4's erasing */
#define DEFAULT_ERASE_SIZE 4096
#define MAX_PANEL_BUF_SIZE 196
#define FOOTER_SIZE 16384
#define DISPLAY_DEFAULT_PREFIX "mdss_mdp"
#define BOOT_DEV_MAX_LEN 64
#define IS_ARM64(ptr) (ptr->magic_64 == KERNEL64_HDR_MAGIC) ? true : false
#define ADD_OF(a, b) (UINT_MAX - b > a) ? (a + b) : UINT_MAX
//Size of the header that is used in case the boot image has
//a uncompressed kernel + appended dtb
#define PATCHED_KERNEL_HEADER_SIZE 20
//String used to determine if the boot image has
//a uncompressed kernel + appended dtb
#define PATCHED_KERNEL_MAGIC "UNCOMPRESSED_IMG"
#if USE_BOOTDEV_CMDLINE
static const char *emmc_cmdline = " androidboot.bootdevice=";
#else
static const char *emmc_cmdline = " androidboot.emmc=true";
#endif
static const char *dynamic_bootdev_cmdline =
" androidboot.boot_devices=soc/";
static const char *usb_sn_cmdline = " androidboot.serialno=";
static const char *androidboot_mode = " androidboot.mode=";
static const char *systemd_ffbm_mode = " systemd.unit=ffbm.target";
static const char *alarmboot_cmdline = " androidboot.alarmboot=true";
static const char *loglevel = " quiet";
static const char *battchg_pause = " androidboot.mode=charger";
static const char *auth_kernel = " androidboot.authorized_kernel=true";
static const char *secondary_gpt_enable = " gpt";
#ifdef MDTP_SUPPORT
static const char *mdtp_activated_flag = " mdtp";
#endif
static const char *baseband_apq = " androidboot.baseband=apq";
static const char *baseband_msm = " androidboot.baseband=msm";
static const char *baseband_csfb = " androidboot.baseband=csfb";
static const char *baseband_svlte2a = " androidboot.baseband=svlte2a";
static const char *baseband_mdm = " androidboot.baseband=mdm";
static const char *baseband_mdm2 = " androidboot.baseband=mdm2";
static const char *baseband_sglte = " androidboot.baseband=sglte";
static const char *baseband_dsda = " androidboot.baseband=dsda";
static const char *baseband_dsda2 = " androidboot.baseband=dsda2";
static const char *baseband_sglte2 = " androidboot.baseband=sglte2";
static const char *warmboot_cmdline = " qpnp-power-on.warm_boot=1";
static const char *baseband_apq_nowgr = " androidboot.baseband=baseband_apq_nowgr";
static const char *androidboot_slot_suffix = " androidboot.slot_suffix=";
static const char *skip_ramfs = " skip_initramfs";
#if HIBERNATION_SUPPORT
static const char *resume = " resume=/dev/mmcblk0p";
#endif
#ifdef INIT_BIN_LE
static const char *sys_path_cmdline = " rootwait ro init="INIT_BIN_LE;
#else
static const char *sys_path_cmdline = " rootwait ro init=/init";
#endif
#if VERITY_LE
static const char *verity_dev = " root=/dev/dm-0";
static const char *verity_system_part = " dm=\"system";
static const char *verity_params = " none ro,0 1 android-verity /dev/mmcblk0p";
#else
static const char *sys_path = " root=/dev/mmcblk0p";
#if DEVICE_TREE
#define MAX_DTBO_IDX_STR 64
static const char *android_boot_dtbo_idx = " androidboot.dtbo_idx=";
#define MAX_DTB_IDX_STR MAX_DTBO_IDX_STR
static const char *android_boot_dtb_idx = " androidboot.dtb_idx=";
#endif
#endif
#if VERIFIED_BOOT
static const char *verity_mode = " androidboot.veritymode=";
static const char *verified_state= " androidboot.verifiedbootstate=";
static const char *keymaster_v1= " androidboot.keymaster=1";
//indexed based on enum values, green is 0 by default
struct verified_boot_verity_mode vbvm[] =
{
#if ENABLE_VB_ATTEST
{false, "eio"},
#else
{false, "logging"},
#endif
{true, "enforcing"},
};
struct verified_boot_state_name vbsn[] =
{
{GREEN, "green"},
{ORANGE, "orange"},
{YELLOW,"yellow"},
{RED,"red" },
};
#endif
/*As per spec delay wait time before shutdown in Red state*/
#define DELAY_WAIT 30000
static unsigned page_size = BOARD_KERNEL_PAGESIZE;
uint32_t kernel_hdr_page_size(void)
{
return page_size;
}
static unsigned page_mask = 0;
static unsigned mmc_blocksize = 0;
static unsigned mmc_blocksize_mask = 0;
static char ffbm_mode_string[FFBM_MODE_BUF_SIZE];
static bool boot_into_ffbm;
static char *target_boot_params = NULL;
static bool boot_reason_alarm;
bool boot_into_fastboot = false;
#if DEVICE_TREE
static uint32_t dt_size = 0;
#endif
static char *vbcmdline;
static bootinfo info = {0};
static void *recovery_dtbo_buf = NULL;
static uint32_t recovery_dtbo_size = 0;
/* Assuming unauthorized kernel image by default */
static int auth_kernel_img = 0;
#if ABOOT_STANDALONE
static device_info device; /* Keep uninitialized to save some space */
#else
static device_info device = {DEVICE_MAGIC,0,0,0,0,{0},{0},{0},1,{0},0,{0}};
static bool devinfo_present = true;
static bool is_allow_unlock = 0;
static char frp_ptns[2][8] = {"config","frp"};
static const char *critical_flash_allowed_ptn[] = {
"aboot",
"rpm",
"tz",
"sbl",
"sdi",
"sbl1",
"xbl",
"hyp",
"pmic",
"bootloader",
"devinfo",
"partition"};
#endif
static const char *VirtualAbCriticalPartitions[] = {
"misc",
"metadata",
"userdata"};
static bool CheckVirtualAbCriticalPartition (const char *PartitionName);
static const char *VabSnapshotMergeStatus[] = {
"none",
"unknown",
"snapshotted",
"merging",
"cancelled"};
struct atag_ptbl_entry
{
char name[16];
unsigned offset;
unsigned size;
unsigned flags;
};
/*
* Partition info, required to be published
* for fastboot
*/
struct getvar_partition_info {
char part_name[MAX_GPT_NAME_SIZE]; /* Partition name */
char getvar_size[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for size */
char getvar_type[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for type */
char size_response[MAX_RSP_SIZE]; /* fastboot response for size */
char type_response[MAX_RSP_SIZE]; /* fastboot response for type */
};
/*
* Update the part_type_known for known paritions types.
*/
#define RAW_STR "raw"
#define EXT_STR "ext4"
#define F2FS_STR "f2fs"
#define FS_SUPERBLOCK_OFFSET 0x400
#define EXT_MAGIC 0xEF53
#define EXT_MAGIC_OFFSET_SB 0x38
#define F2FS_MAGIC 0xF2F52010 // F2FS Magic Number
#define F2FS_MAGIC_OFFSET_SB 0x0
typedef enum fs_signature_type {
EXT_FS_SIGNATURE = 1,
EXT_F2FS_SIGNATURE = 2,
NO_FS = -1
} fs_signature_type;
struct getvar_partition_info part_info[NUM_PARTITIONS];
struct getvar_partition_info part_type_known[] =
{
{ "system" , "partition-size:", "partition-type:", "", "ext4" },
{ "userdata" , "partition-size:", "partition-type:", "", "ext4" },
{ "cache" , "partition-size:", "partition-type:", "", "ext4" },
{ "recoveryfs" , "partition-size:", "partition-type:", "", "ext4" },
};
char max_download_size[MAX_RSP_SIZE];
char charger_screen_enabled[MAX_RSP_SIZE];
char sn_buf[13];
char display_panel_buf[MAX_PANEL_BUF_SIZE];
char panel_display_mode[MAX_RSP_SIZE];
char soc_version_str[MAX_RSP_SIZE];
char block_size_string[MAX_RSP_SIZE];
static char SnapshotMergeState[MAX_RSP_SIZE];
#if PRODUCT_IOT
/* For IOT we are using custom version */
#define PRODUCT_IOT_VERSION "IOT001"
char bootloader_version_string[MAX_RSP_SIZE];
#endif
#if CHECK_BAT_VOLTAGE
char battery_voltage[MAX_RSP_SIZE];
char battery_soc_ok [MAX_RSP_SIZE];
#endif
char get_variant[MAX_RSP_SIZE];
extern int emmc_recovery_init(void);
#if NO_KEYPAD_DRIVER
extern int fastboot_trigger(void);
#endif
static void update_ker_tags_rdisk_addr(boot_img_hdr *hdr, struct kernel64_hdr *kptr)
{
/* overwrite the destination of specified for the project */
#ifdef ABOOT_IGNORE_BOOT_HEADER_ADDRS
if (kptr && IS_ARM64(kptr))
hdr->kernel_addr = ABOOT_FORCE_KERNEL64_ADDR;
else
hdr->kernel_addr = ABOOT_FORCE_KERNEL_ADDR;
hdr->ramdisk_addr = ABOOT_FORCE_RAMDISK_ADDR;
hdr->tags_addr = ABOOT_FORCE_TAGS_ADDR;
/*
* ARM64 kernels specify the expected text offset in kptr->text_offset.
* However, this is not reliable until Linux 3.17.
* Check if image_size != 0 to detect newer kernels and use their
* expected offset in that case to avoid:
*
* [Firmware Bug]: Kernel image misaligned at boot, please fix your bootloader!
*
* See Linux commit a2c1d73b94ed49f5fac12e95052d7b140783f800.
*/
if (kptr && IS_ARM64(kptr) && kptr->image_size) {
/* text_offset bytes from a 2MB aligned base address */
hdr->kernel_addr &= ~0x1fffff;
hdr->kernel_addr += kptr->text_offset;
}
#endif
}
static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn)
{
struct atag_ptbl_entry atag_ptn;
memcpy(atag_ptn.name, ptn->name, 16);
atag_ptn.name[15] = '\0';
atag_ptn.offset = ptn->start;
atag_ptn.size = ptn->length;
atag_ptn.flags = ptn->flags;
memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry));
*ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned);
}
#ifdef VERIFIED_BOOT_2
void load_vbmeta_image(void **vbmeta_image_buf, uint32_t *vbmeta_image_sz)
{
int index = 0;
char *vbm_img_buf = NULL;
unsigned long long ptn = 0;
unsigned long long ptn_size = 0;
/* Immediately return if dtbo is not supported */
index = partition_get_index("vbmeta");
ptn = partition_get_offset(index);
if(!ptn)
{
dprintf(CRITICAL, "ERROR: vbmeta partition not found.\n");
return;
}
ptn_size = partition_get_size(index);
if (ptn_size > MAX_SUPPORTED_VBMETA_IMG_BUF)
{
dprintf(CRITICAL, "ERROR: vbmeta parition size is greater than supported.\n");
return;
}
vbm_img_buf = (char *)memalign(CACHE_LINE, ROUNDUP((uint32_t)ptn_size, CACHE_LINE));
if (!vbm_img_buf)
{
dprintf(CRITICAL, "ERROR: vbmeta unable to locate buffer\n");
return;
}
mmc_set_lun(partition_get_lun(index));
if (mmc_read(ptn, (uint32_t *)vbm_img_buf, (uint32_t)ptn_size))
{
dprintf(CRITICAL, "ERROR: vbmeta read failure\n");
free(vbm_img_buf);
return;
}
*vbmeta_image_buf = vbm_img_buf;
*vbmeta_image_sz = (uint32_t)ptn_size;
return;
}
#endif
#if CHECK_BAT_VOLTAGE
void update_battery_status(void)
{
snprintf(battery_voltage,MAX_RSP_SIZE, "%d",target_get_battery_voltage());
snprintf(battery_soc_ok ,MAX_RSP_SIZE, "%s",target_battery_soc_ok()? "yes":"no");
}
#endif
unsigned char *update_cmdline(const char * cmdline)
{
int cmdline_len = 0;
int have_cmdline = 0;
unsigned char *cmdline_final = NULL;
int pause_at_bootup = 0;
bool warm_boot = false;
bool gpt_exists = target_is_emmc_boot() && partition_gpt_exists();
int have_target_boot_params = 0;
char *boot_dev_buf = NULL;
#ifdef MDTP_SUPPORT
bool is_mdtp_activated = 0;
#endif
int current_active_slot = INVALID;
int system_ptn_index = -1;
unsigned int lun = 0;
char lun_char_base = 'a';
#if VERITY_LE
int syspath_buflen = strlen(verity_dev)
+ strlen(verity_system_part) + (sizeof(char) * 2) + 2
+ strlen(verity_params) + sizeof(int) + 2;
#else
int syspath_buflen = strlen(sys_path) + sizeof(int) + 2; /*allocate buflen for largest possible string*/
#if DEVICE_TREE
char dtbo_idx_str[MAX_DTBO_IDX_STR] = "\0";
int dtbo_idx = INVALID_PTN;
char dtb_idx_str[MAX_DTB_IDX_STR] = "\0";
int dtb_idx = INVALID_PTN;
#endif
#endif
char syspath_buf[syspath_buflen];
#if HIBERNATION_SUPPORT
int resume_buflen = strlen(resume) + sizeof(int) + 2;
char resume_buf[resume_buflen];
int swap_ptn_index = INVALID_PTN;
#endif
#if VERIFIED_BOOT
uint32_t boot_state = RED;
#endif
#if USE_LE_SYSTEMD
is_systemd_present=true;
#endif
#if VERIFIED_BOOT
if (VB_M <= target_get_vb_version())
{
boot_state = boot_verify_get_state();
}
#endif
#ifdef MDTP_SUPPORT
mdtp_activated(&is_mdtp_activated);
#endif /* MDTP_SUPPORT */
if (cmdline && cmdline[0]) {
cmdline_len = strlen(cmdline);
have_cmdline = 1;
}
if (target_is_emmc_boot()) {
cmdline_len += strlen(emmc_cmdline);
boot_dev_buf = (char *) malloc(sizeof(char) * BOOT_DEV_MAX_LEN);
if (!boot_dev_buf) {
dprintf(CRITICAL, "ERROR: Failed to allocate boot_dev_buf\n");
} else {
platform_boot_dev_cmdline(boot_dev_buf, sizeof(char) * BOOT_DEV_MAX_LEN);
#if USE_BOOTDEV_CMDLINE
cmdline_len += strlen(boot_dev_buf);
#endif
if (target_dynamic_partition_supported()) {
cmdline_len += strlen(dynamic_bootdev_cmdline);
cmdline_len += strlen(boot_dev_buf);
}
}
}
cmdline_len += strlen(usb_sn_cmdline);
cmdline_len += strlen(sn_buf);
#if VERIFIED_BOOT
if (VB_M <= target_get_vb_version())
{
cmdline_len += strlen(verified_state) + strlen(vbsn[boot_state].name);
if ((device.verity_mode != 0 ) && (device.verity_mode != 1))
{
dprintf(CRITICAL, "Devinfo paritition possibly corrupted!!!. Please erase devinfo partition to continue booting\n");
ASSERT(0);
}
cmdline_len += strlen(verity_mode) + strlen(vbvm[device.verity_mode].name);
cmdline_len += strlen(keymaster_v1);
}
#endif
if (vbcmdline != NULL) {
dprintf(DEBUG, "UpdateCmdLine vbcmdline present len %d\n",
strlen(vbcmdline));
cmdline_len += strlen(vbcmdline);
}
if (boot_into_recovery && gpt_exists)
cmdline_len += strlen(secondary_gpt_enable);
#ifdef MDTP_SUPPORT
if(is_mdtp_activated)
cmdline_len += strlen(mdtp_activated_flag);
#endif
if (boot_into_ffbm) {
cmdline_len += strlen(androidboot_mode);
if(is_systemd_present)
cmdline_len += strlen(systemd_ffbm_mode);
cmdline_len += strlen(ffbm_mode_string);
/* reduce kernel console messages to speed-up boot */
cmdline_len += strlen(loglevel);
} else if (boot_reason_alarm) {
cmdline_len += strlen(alarmboot_cmdline);
} else if ((target_build_variant_user() || device.charger_screen_enabled)
&& target_pause_for_battery_charge() && !boot_into_recovery) {
pause_at_bootup = 1;
cmdline_len += strlen(battchg_pause);
}
if(target_use_signed_kernel() && auth_kernel_img) {
cmdline_len += strlen(auth_kernel);
}
if (get_target_boot_params(cmdline, boot_into_recovery ? "recoveryfs" :
"system",
&target_boot_params) == 0) {
have_target_boot_params = 1;
cmdline_len += strlen(target_boot_params);
}
/* Determine correct androidboot.baseband to use */
switch(target_baseband())
{
case BASEBAND_APQ:
cmdline_len += strlen(baseband_apq);
break;
case BASEBAND_MSM:
cmdline_len += strlen(baseband_msm);
break;
case BASEBAND_CSFB:
cmdline_len += strlen(baseband_csfb);
break;
case BASEBAND_SVLTE2A:
cmdline_len += strlen(baseband_svlte2a);
break;
case BASEBAND_MDM:
cmdline_len += strlen(baseband_mdm);
break;
case BASEBAND_MDM2:
cmdline_len += strlen(baseband_mdm2);
break;
case BASEBAND_SGLTE:
cmdline_len += strlen(baseband_sglte);
break;
case BASEBAND_SGLTE2:
cmdline_len += strlen(baseband_sglte2);
break;
case BASEBAND_DSDA:
cmdline_len += strlen(baseband_dsda);
break;
case BASEBAND_DSDA2:
cmdline_len += strlen(baseband_dsda2);
break;
case BASEBAND_APQ_NOWGR:
cmdline_len += strlen(baseband_apq_nowgr);
break;
}
#if DISPLAY_SPLASH_SCREEN
if (cmdline) {
if ((strstr(cmdline, DISPLAY_DEFAULT_PREFIX) == NULL) &&
target_display_panel_node(display_panel_buf,
MAX_PANEL_BUF_SIZE) &&
strlen(display_panel_buf)) {
cmdline_len += strlen(display_panel_buf);
}
}
#endif
if (target_warm_boot()) {
warm_boot = true;
cmdline_len += strlen(warmboot_cmdline);
}
if (target_uses_system_as_root() ||
partition_multislot_is_supported())
{
current_active_slot = partition_find_active_slot();
cmdline_len += (strlen(androidboot_slot_suffix)+
strlen(SUFFIX_SLOT(current_active_slot)));
system_ptn_index = partition_get_index("system");
if (platform_boot_dev_isemmc())
{
#if VERITY_LE
/*
Condition 4: Verity and A/B both enabled
Eventual command line looks like:
... androidboot.slot_suffix=<slot_suffix> ... rootfstype=ext4 ...
... root=/dev/dm-0 dm="system_<slot_suffix> none ro,0 1 android-verity /dev/mmcblk0p<NN>"
*/
snprintf(syspath_buf, syspath_buflen, " %s %s%s %s%d\"",
verity_dev,
verity_system_part, suffix_slot[current_active_slot],
verity_params, system_ptn_index + 1);
#else
/*
Condition 5: A/B enabled, but verity disabled
Eventual command line looks like:
... androidboot.slot_suffix=<slot_suffix> ... rootfstype=ext4 ...
... root=/dev/mmcblk0p<NN> ...
*/
snprintf(syspath_buf, syspath_buflen, " %s%d",
sys_path, system_ptn_index + 1);
#endif
}
else
{
lun = partition_get_lun(system_ptn_index);
snprintf(syspath_buf, syspath_buflen, " root=/dev/sd%c%d",
lun_char_base + lun,
partition_get_index_in_lun("system", lun));
}
#ifndef VERIFIED_BOOT_2
cmdline_len += strlen(syspath_buf);
#endif
}
if (target_uses_system_as_root() ||
partition_multislot_is_supported())
{
cmdline_len += strlen(sys_path_cmdline);
/* For dynamic partition, support skip skip_initramfs */
if (!target_dynamic_partition_supported() &&
!boot_into_recovery)
cmdline_len += strlen(skip_ramfs);
}
#if HIBERNATION_SUPPORT
if (platform_boot_dev_isemmc())
{
swap_ptn_index = partition_get_index("swap");
if (swap_ptn_index != INVALID_PTN)
{
snprintf(resume_buf, resume_buflen,
" %s%d", resume,
(swap_ptn_index + 1));
cmdline_len += strlen(resume_buf);
}
else
{
dprintf(INFO, "WARNING: swap partition not found\n");
}
}
#endif
#if TARGET_CMDLINE_SUPPORT
char *target_cmdline_buf = malloc(TARGET_MAX_CMDLNBUF);
int target_cmd_line_len;
ASSERT(target_cmdline_buf);
target_cmd_line_len = target_update_cmdline(target_cmdline_buf);
cmdline_len += target_cmd_line_len;
#endif
#if !VERITY_LE && DEVICE_TREE
dtbo_idx = get_dtbo_idx ();
if (dtbo_idx != INVALID_PTN) {
snprintf(dtbo_idx_str, sizeof(dtbo_idx_str), "%s%d",
android_boot_dtbo_idx, dtbo_idx);
cmdline_len += strlen (dtbo_idx_str);
}
dtb_idx = get_dtb_idx ();
if (dtb_idx != INVALID_PTN) {
snprintf(dtb_idx_str, sizeof(dtb_idx_str), "%s%d",
android_boot_dtb_idx, dtb_idx);
cmdline_len += strlen (dtb_idx_str);
}
#endif
if (cmdline_len > 0) {
const char *src;
unsigned char *dst;
cmdline_final = (unsigned char*) malloc((cmdline_len + 4) & (~3));
ASSERT(cmdline_final != NULL);
memset((void *)cmdline_final, 0, sizeof(*cmdline_final));
dst = cmdline_final;
/* Save start ptr for debug print */
if (have_cmdline) {
src = cmdline;
while ((*dst++ = *src++));
}
if (target_is_emmc_boot()) {
src = emmc_cmdline;
if (have_cmdline) --dst;
have_cmdline = 1;
while ((*dst++ = *src++));
#if USE_BOOTDEV_CMDLINE
src = boot_dev_buf;
if (have_cmdline &&
boot_dev_buf) {
--dst;
while ((*dst++ = *src++));
}
#endif
/* Dynamic partition append boot_devices */
if (target_dynamic_partition_supported() &&
boot_dev_buf) {
src = dynamic_bootdev_cmdline;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
src = boot_dev_buf;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
}
#if VERIFIED_BOOT
if (VB_M <= target_get_vb_version())
{
src = verified_state;
if(have_cmdline) --dst;
have_cmdline = 1;
while ((*dst++ = *src++));
src = vbsn[boot_state].name;
if(have_cmdline) --dst;
while ((*dst++ = *src++));
if ((device.verity_mode != 0 ) && (device.verity_mode != 1))
{
dprintf(CRITICAL, "Devinfo paritition possibly corrupted!!!. Please erase devinfo partition to continue booting\n");
ASSERT(0);
}
src = verity_mode;
if(have_cmdline) --dst;
while ((*dst++ = *src++));
src = vbvm[device.verity_mode].name;
if(have_cmdline) -- dst;
while ((*dst++ = *src++));
src = keymaster_v1;
if(have_cmdline) --dst;
while ((*dst++ = *src++));
}
#endif
if (vbcmdline != NULL) {
src = vbcmdline;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
src = usb_sn_cmdline;
if (have_cmdline) --dst;
have_cmdline = 1;
while ((*dst++ = *src++));
src = sn_buf;
if (have_cmdline) --dst;
have_cmdline = 1;
while ((*dst++ = *src++));
if (warm_boot) {
if (have_cmdline) --dst;
src = warmboot_cmdline;
while ((*dst++ = *src++));
}
if (boot_into_recovery && gpt_exists) {
src = secondary_gpt_enable;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
#ifdef MDTP_SUPPORT
if (is_mdtp_activated) {
src = mdtp_activated_flag;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
#endif
if (boot_into_ffbm) {
src = androidboot_mode;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
src = ffbm_mode_string;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
if(is_systemd_present) {
src = systemd_ffbm_mode;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
src = loglevel;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
} else if (boot_reason_alarm) {
src = alarmboot_cmdline;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
} else if (pause_at_bootup) {
src = battchg_pause;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
if(target_use_signed_kernel() && auth_kernel_img) {
src = auth_kernel;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
switch(target_baseband())
{
case BASEBAND_APQ:
src = baseband_apq;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_MSM:
src = baseband_msm;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_CSFB:
src = baseband_csfb;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_SVLTE2A:
src = baseband_svlte2a;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_MDM:
src = baseband_mdm;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_MDM2:
src = baseband_mdm2;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_SGLTE:
src = baseband_sglte;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_SGLTE2:
src = baseband_sglte2;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_DSDA:
src = baseband_dsda;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_DSDA2:
src = baseband_dsda2;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
case BASEBAND_APQ_NOWGR:
src = baseband_apq_nowgr;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
break;
}
if (strlen(display_panel_buf)) {
src = display_panel_buf;
if (have_cmdline) --dst;
while ((*dst++ = *src++));
}
if (have_target_boot_params) {
if (have_cmdline) --dst;
src = target_boot_params;
while ((*dst++ = *src++));
free(target_boot_params);