blob: 9ef27ddf86105b6fb7949216ff44577d70e7eeeb [file] [log] [blame]
Sam Wu083c4852023-04-25 19:37:54 +08001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2019 Amlogic, Inc. All rights reserved.
4*/
5/*
6* uboot text based env
7* more details: https://u-boot.readthedocs.io/en/latest/usage/environment.html
8* or: v2023 doc/usage/environment.rst
9*/
Tao Zeng4dd2adf2024-02-21 15:26:04 +080010#ifdef CONFIG_NOVERBOSE_BUILD
11silent=1
12#else
13silent=0
14#endif
Sam Wu083c4852023-04-25 19:37:54 +080015firstboot=0
16lock=10101000
Sam Wu083c4852023-04-25 19:37:54 +080017upgrade_step=0
18jtag=disable
Sam Wuc7da1752023-07-28 12:05:06 +080019loadaddr=0x001080000
20dtb_mem_addr=0x001000000
Sam Wu083c4852023-04-25 19:37:54 +080021os_ident_addr=0x00500000
benlong.zhou7940f772023-07-21 09:21:09 +080022loadaddr_rtos=0x00080000
Bo Lv76f5c7d2023-07-27 15:16:40 +080023dtb_mem_addr=0x1000000
Sam Wu083c4852023-04-25 19:37:54 +080024loadaddr_kernel=0x03080000
Bo Lvda8d5b72023-07-31 14:58:21 +080025decaddr_kernel=0x01800000
Sam Wu083c4852023-04-25 19:37:54 +080026dv_fw_addr=0xa00000
27otg_device=1
28fdt_high=0x20000000
29EnableSelinux=enforcing
30recovery_offset=0
31osd_reverse=0
32video_reverse=0
33active_slot=normal
Sam Wu083c4852023-04-25 19:37:54 +080034boot_flag=0
35write_boot=0
Bo Lv119f5f32023-06-27 16:32:31 +080036fb_addr=0x00300000
Xindong Xu22e8daf2024-03-12 18:08:41 +080037fastboot_step=0
Bo Lv119f5f32023-06-27 16:32:31 +080038
Tao Zeng4dd2adf2024-02-21 15:26:04 +080039#ifdef CONFIG_NOVERBOSE_BUILD
40loglevel=2
41#else
Sam Wu083c4852023-04-25 19:37:54 +080042#ifdef CONFIG_KNL_LOG_LEVEL
43loglevel=CONFIG_KNL_LOG_LEVEL
44#else
45loglevel=8
46#endif//ifdef CONFIG_KNL_LOG_LEVEL
Tao Zeng4dd2adf2024-02-21 15:26:04 +080047#endif
Sam Wu083c4852023-04-25 19:37:54 +080048
49#ifdef CONFIG_DTB_BIND_KERNEL //load dtb from kernel, such as boot partition
50common_dtb_load=imgread dtb ${boot_part} ${dtb_mem_addr}
51#else
52common_dtb_load=imgread dtb _aml_dtb ${dtb_mem_addr}
53#endif//#ifdef CONFIG_DTB_BIND_KERNEL //load dtb from kernel, such as boot partition
54
Mingyen Hung96effce2023-09-01 00:39:46 -070055get_os_type=if imgread part ${boot_part} ${os_ident_addr} 0 0x1000; then os_ident ${os_ident_addr}; fi
Sam Wu083c4852023-04-25 19:37:54 +080056fatload_dev=usb
57fs_type=rootfstype=ramfs
58upgrade_check=
59 echo recovery_status=${recovery_status};
60 if itest.s "${recovery_status}" == "in_progress"; then
61 run storeargs; run recovery_from_flash;
62 else fi;
63 echo upgrade_step=${upgrade_step};
64 if itest ${upgrade_step} == 3; then run storeargs; run update; fi;
65
66initargs=init=/init ramoops.pstore_en=1 ramoops.record_size=0x8000 ramoops.console_size=0x4000 loop.max_part=4
67
68storeargs=
69 get_bootloaderversion;
70 setenv bootargs ${initargs}
yao zhang15ef11eb2023-11-21 14:46:44 +080071 loglevel=${loglevel} async_long_initcall=1 console=ttyS0,${baudrate} no_console_suspend earlycon=aml_uart,${uart_base}
Sam Wu083c4852023-04-25 19:37:54 +080072 ${fs_type} otg_device=${otg_device}
lizhi.hu77c2a882024-03-21 16:28:16 +080073 logo=${display_layer},loaded,${fb_addr} vout=${outputmode},enable
74 panel_type=${panel_type} lcd_ctrl=${lcd_ctrl} lcd_debug=${lcd_debug}
Sam Wu083c4852023-04-25 19:37:54 +080075 hdmitx=${cecconfig},${colorattribute} hdmimode=${hdmimode}
76 hdmichecksum=${hdmichecksum} dolby_vision_on=${dolby_vision_on}
77 hdr_policy=${hdr_policy} hdr_priority=${hdr_priority}
78 frac_rate_policy=${frac_rate_policy} hdmi_read_edid=${hdmi_read_edid} cvbsmode=${cvbsmode}
79 osd_reverse=${osd_reverse} video_reverse=${video_reverse} irq_check_en=${Irq_check_en}
ruofei.zhaoab821032024-05-07 14:43:58 +080080 jtag=${jtag} config_csc_en=${config_csc_en};
Sam Wuefee52f2024-04-29 12:03:12 +080081 setenv bootargs ${bootargs} production_mode=${production_mode};
Sam Wu083c4852023-04-25 19:37:54 +080082 run cmdline_keys;
83
84switch_bootmode=
85 get_rebootmode;
86 if test ${reboot_mode} = factory_reset; then run recovery_from_flash;
87 else if test ${reboot_mode} = update; then run update;
88 else if test ${reboot_mode} = quiescent; then
89 setenv bootargs ${bootargs} androidboot.quiescent=1;
90 else if test ${reboot_mode} = recovery_quiescent; then
91 setenv bootargs ${bootargs} androidboot.quiescent=1;
92 run recovery_from_flash;
93 else if test ${reboot_mode} = cold_boot; then
94 else if test ${reboot_mode} = fastboot; then fastboot 0; fi;
95 fi;fi;fi;fi;fi;
96
97storeboot=
98 run get_os_type;
99 run storage_param;
100 if test ${os_type} = rtos; then
101 setenv loadaddr ${loadaddr_rtos};
102 store read ${loadaddr} ${boot_part} 0 0x400000;
103 bootm ${loadaddr};
104 else if test ${os_type} = kernel; then
105 get_avb_mode;
106 if fdt addr ${dtb_mem_addr}; then else echo retry common dtb; run common_dtb_load; fi;
107 setenv loadaddr ${loadaddr_kernel};
Mingyen Hung96effce2023-09-01 00:39:46 -0700108 if imgread kernel ${boot_part} ${loadaddr}; then
109#if CONFIG_PARTITION_ENCRYPTION
110 partition_enc apply;
111#endif
112 bootm ${loadaddr};
113 fi;
Sam Wu083c4852023-04-25 19:37:54 +0800114 else echo wrong OS format ${os_type}; fi;fi;
115 echo try upgrade as booting failure; run update;
116
117update=
118 /*first usb burning, second sdc_burn, third ext-sd autoscr/recovery, last udisk autoscr/recovery*/\
119 run usb_burning;
120 run recovery_from_sdcard;
121 run recovery_from_udisk;
122 run recovery_from_flash;
123
124recovery_from_fat_dev=
125 setenv loadaddr ${loadaddr_kernel};
126 if fatload ${fatload_dev} 0 ${loadaddr} aml_autoscript; then autoscr ${loadaddr}; fi;
127 if fatload ${fatload_dev} 0 ${loadaddr} recovery.img; then
128 if fatload ${fatload_dev} 0 ${dtb_mem_addr} dtb.img; then echo ${fatload_dev} dtb.img loaded; fi;
129 setenv bootargs ${bootargs} ${fs_type};
130 bootm ${loadaddr};
131 fi;
132recovery_from_udisk=
133 setenv fatload_dev usb;
134 if usb start 0; then run recovery_from_fat_dev; fi;
135recovery_from_sdcard=
136 setenv fatload_dev mmc;
137 if mmcinfo; then run recovery_from_fat_dev; fi;
138
139recovery_from_flash=
140 echo active_slot: ${active_slot};
Bing Jiangee808882023-09-15 15:29:24 +0800141 run storage_param;
Sam Wu083c4852023-04-25 19:37:54 +0800142 setenv loadaddr ${loadaddr_kernel};
143 if test ${active_slot} = normal; then
144 setenv bootargs ${bootargs} ${fs_type} aml_dt=${aml_dt}
145 recovery_part=${recovery_part} recovery_offset=${recovery_offset};
146 if test ${upgrade_step} = 3; then
147 if ext4load mmc 1:2 ${dtb_mem_addr} /recovery/dtb.img; then echo cache dtb.img loaded; fi;
148 if test ${vendor_boot_mode} = true; then
149 if imgread kernel ${recovery_part} ${loadaddr} ${recovery_offset}; then bootm ${loadaddr}; fi;
150 else
151 if ext4load mmc 1:2 ${loadaddr} /recovery/recovery.img; then
152 echo cache recovery.img loaded; bootm ${loadaddr};
153 fi;
154 fi;
155 else
156 if imgread dtb recovery ${dtb_mem_addr}; then
157 else echo restore dtb; run common_dtb_load;
158 fi;
159 fi;
Mingyen Hung96effce2023-09-01 00:39:46 -0700160 if imgread kernel ${recovery_part} ${loadaddr} ${recovery_offset}; then
161#if CONFIG_PARTITION_ENCRYPTION
162 partition_enc apply;
163#endif
164 bootm ${loadaddr};
165 fi;
Sam Wu083c4852023-04-25 19:37:54 +0800166 else
Sam Wu9db1ccc2023-05-09 18:31:35 +0800167 echo "active_slot ${active_slot} not supported";
Sam Wu083c4852023-04-25 19:37:54 +0800168 fi;
169
170bcb_cmd=
171 get_avb_mode;
172 get_valid_slot;
173 if test ${vendor_boot_mode} = true; then
Bo Lv119f5f32023-06-27 16:32:31 +0800174 setenv loadaddr_kernel 0x3000000;
Sam Wu083c4852023-04-25 19:37:54 +0800175 setenv dtb_mem_addr 0x1000000;
176 fi;
Bo Lv119f5f32023-06-27 16:32:31 +0800177 if test ${active_slot} != "normal"; then
Sam Wu083c4852023-04-25 19:37:54 +0800178 echo ab mode, read dtb from kernel;
179 setenv common_dtb_load imgread dtb ${boot_part} ${dtb_mem_addr};
180 fi;
181
182load_bmp_logo=
183 if imgread pic logo bootup $loadaddr; then bmp display $bootup_offset; fi;
184
185init_display=
186 get_rebootmode;
187 echo reboot_mode:::: ${reboot_mode};
188 if test ${reboot_mode} = quiescent; then
189 setenv reboot_mode_android "quiescent";
190 setenv dolby_status 0;
191 setenv dolby_vision_on 0;
Wenjie Qiao52d73732023-09-11 17:08:11 +0800192 run storeargs;
Sam Wu083c4852023-04-25 19:37:54 +0800193 setenv bootargs ${bootargs} androidboot.quiescent=1;
194 osd open;osd clear;
195 else if test ${reboot_mode} = recovery_quiescent; then
196 setenv reboot_mode_android "quiescent";
197 setenv dolby_status 0;
198 setenv dolby_vision_on 0;
Wenjie Qiao52d73732023-09-11 17:08:11 +0800199 run storeargs;
Sam Wu083c4852023-04-25 19:37:54 +0800200 setenv bootargs ${bootargs} androidboot.quiescent=1;
201 osd open;osd clear;
202 else
203 setenv reboot_mode_android "normal";
ruofei.zhao4a2ec0c2023-10-31 19:24:41 +0800204 hdmitx hpd;hdmitx get_parse_edid;
Bo Lvcb044df2023-08-07 10:55:30 +0800205 dovi process;watermark_init;osd open;osd clear;run load_bmp_logo;
206 bmp scale;vout output ${outputmode};dovi set;dovi pkg;vpp hdrpkt;
Wenjie Qiao52d73732023-09-11 17:08:11 +0800207 run storeargs;
Sam Wu083c4852023-04-25 19:37:54 +0800208 fi;fi;
209
210storage_param=
211 setenv bootargs ${bootargs} ${emmc_quirks};
212 store param;
213 setenv bootargs ${bootargs} ${mtdbootparts};
214
215cmdline_keys=
216 setenv region_code US;
217 if keyman init 0x1234; then
218 if keyman read usid ${loadaddr} str; then
219 setenv bootargs ${bootargs} androidboot.serialno=${usid};
220 setenv serial ${usid}; setenv serial# ${usid};
221 else
222 setenv bootargs ${bootargs} androidboot.serialno=ap222${cpu_id};
223 setenv serial ap222${cpu_id}; setenv serial# ap222${cpu_id};
224 fi;
225 if keyman read region_code ${loadaddr} str; then fi;
226 if keyman read mac ${loadaddr} str; then
227 setenv bootargs ${bootargs} mac=${mac} androidboot.mac=${mac};
228 fi;
229 if keyman read deviceid ${loadaddr} str; then
230 setenv bootargs ${bootargs} androidboot.deviceid=${deviceid};
231 fi;
232 fi;
233 setenv bootargs ${bootargs} androidboot.wificountrycode=${region_code};
234 factory_provision init;
235
236upgrade_key=
237 if gpio input GPIOD_2; then
238 echo detect upgrade key; run update;
239 fi;
240