Merge tag 'xilinx-for-v2022.04-rc3' of https://gitlab.denx.de/u-boot/custodians/u...
[platform/kernel/u-boot.git] / include / configs / meson64_android.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Configuration for Android Amlogic Meson 64bits SoCs
4  *
5  * Copyright (C) 2019 Baylibre, SAS
6  * Author: Jerome Brunet <jbrunet@baylibre.com>
7  */
8
9 #ifndef __MESON64_ANDROID_CONFIG_H
10 #define __MESON64_ANDROID_CONFIG_H
11
12 #include <linux/sizes.h>
13
14 #ifndef BOOT_PARTITION
15 #define BOOT_PARTITION "boot"
16 #endif
17
18 #ifndef LOGO_PARTITION
19 #define LOGO_PARTITION "logo"
20 #endif
21
22 #ifndef CONTROL_PARTITION
23 #define CONTROL_PARTITION "misc"
24 #endif
25
26 #ifndef EXTRA_ANDROID_ENV_SETTINGS
27 #define EXTRA_ANDROID_ENV_SETTINGS ""
28 #endif
29
30 #if defined(CONFIG_CMD_AVB)
31 #define AVB_VERIFY_CHECK \
32         "if test \"${force_avb}\" -eq 1; then " \
33                 "if run avb_verify; then " \
34                         "echo AVB verification OK.;" \
35                         "setenv bootargs \"$bootargs $avb_bootargs\";" \
36                 "else " \
37                         "echo AVB verification failed.;" \
38                 "exit; fi;" \
39         "else " \
40                 "setenv bootargs \"$bootargs androidboot.verifiedbootstate=orange\";" \
41                 "echo Running without AVB...; "\
42         "fi;"
43
44 #define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0"
45 #else
46 #define AVB_VERIFY_CHECK ""
47 #define AVB_VERIFY_CMD ""
48 #endif
49
50 #if defined(CONFIG_CMD_AB_SELECT)
51 #define ANDROIDBOOT_GET_CURRENT_SLOT_CMD "get_current_slot=" \
52         "if part number mmc ${mmcdev} " CONTROL_PARTITION " control_part_number; " \
53         "then " \
54                 "echo " CONTROL_PARTITION \
55                         " partition number:${control_part_number};" \
56                 "ab_select current_slot mmc ${mmcdev}:${control_part_number};" \
57         "else " \
58                 "echo " CONTROL_PARTITION " partition not found;" \
59         "fi;\0"
60
61 #define AB_SELECT_SLOT \
62         "run get_current_slot; " \
63         "if test -e \"${current_slot}\"; " \
64         "then " \
65                 "setenv slot_suffix _${current_slot}; " \
66         "else " \
67                 "echo current_slot not found;" \
68                 "exit;" \
69         "fi;"
70
71 #define AB_SELECT_ARGS \
72         "setenv bootargs_ab androidboot.slot_suffix=${slot_suffix}; " \
73         "echo A/B cmdline addition: ${bootargs_ab};" \
74         "setenv bootargs ${bootargs} ${bootargs_ab};"
75
76 #define AB_BOOTARGS " androidboot.force_normal_boot=1"
77 #define RECOVERY_PARTITION "boot"
78 #else
79 #define AB_SELECT_SLOT ""
80 #define AB_SELECT_ARGS " "
81 #define ANDROIDBOOT_GET_CURRENT_SLOT_CMD ""
82 #define AB_BOOTARGS " "
83 #define RECOVERY_PARTITION "recovery"
84 #endif
85
86 #if defined(CONFIG_CMD_ABOOTIMG)
87 /*
88  * Prepares complete device tree blob for current board (for Android boot).
89  *
90  * Boot image or recovery image should be loaded into $loadaddr prior to running
91  * these commands. The logic of these commnads is next:
92  *
93  *   1. Read correct DTB for current SoC/board from boot image in $loadaddr
94  *      to $fdtaddr
95  *   2. Merge all needed DTBO for current board from 'dtbo' partition into read
96  *      DTB
97  *   3. User should provide $fdtaddr as 3rd argument to 'bootm'
98  */
99 #define PREPARE_FDT \
100         "echo Preparing FDT...; " \
101         "if test $board_name = sei510; then " \
102                 "echo \"  Reading DTB for sei510...\"; " \
103                 "setenv dtb_index 0;" \
104         "elif test $board_name = sei610; then " \
105                 "echo \"  Reading DTB for sei610...\"; " \
106                 "setenv dtb_index 1;" \
107         "elif test $board_name = vim3l; then " \
108                 "echo \"  Reading DTB for vim3l...\"; " \
109                 "setenv dtb_index 2;" \
110         "elif test $board_name = vim3; then " \
111                 "echo \"  Reading DTB for vim3...\"; " \
112                 "setenv dtb_index 3;" \
113         "else " \
114                 "echo Error: Android boot is not supported for $board_name; " \
115                 "exit; " \
116         "fi; " \
117         "abootimg get dtb --index=$dtb_index dtb_start dtb_size; " \
118         "cp.b $dtb_start $fdt_addr_r $dtb_size; " \
119         "fdt addr $fdt_addr_r  0x80000; " \
120         "if test $board_name = sei510; then " \
121                 "echo \"  Reading DTBO for sei510...\"; " \
122                 "setenv dtbo_index 0;" \
123         "elif test $board_name = sei610; then " \
124                 "echo \"  Reading DTBO for sei610...\"; " \
125                 "setenv dtbo_index 1;" \
126         "elif test $board_name = vim3l; then " \
127                 "echo \"  Reading DTBO for vim3l...\"; " \
128                 "setenv dtbo_index 2;" \
129         "elif test $board_name = vim3; then " \
130                 "echo \"  Reading DTBO for vim3...\"; " \
131                 "setenv dtbo_index 3;" \
132         "else " \
133                 "echo Error: Android boot is not supported for $board_name; " \
134                 "exit; " \
135         "fi; " \
136         "part start mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_start; " \
137         "part size mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_size; " \
138         "mmc read ${dtboaddr} ${p_dtbo_start} ${p_dtbo_size}; " \
139         "echo \"  Applying DTBOs...\"; " \
140         "adtimg addr $dtboaddr; " \
141         "adtimg get dt --index=$dtbo_index dtbo0_addr; " \
142         "fdt apply $dtbo0_addr;" \
143         "setenv bootargs \"$bootargs androidboot.dtbo_idx=$dtbo_index \";"\
144
145 #define BOOT_CMD "bootm ${loadaddr} ${loadaddr} ${fdt_addr_r};"
146
147 #else
148 #define PREPARE_FDT " "
149 #define BOOT_CMD "bootm ${loadaddr};"
150 #endif
151
152 #define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \
153         "bootcmd_fastboot=" \
154                 "setenv run_fastboot 0;" \
155                 "if test \"${boot_source}\" = \"usb\"; then " \
156                         "echo Fastboot forced by usb rom boot;" \
157                         "setenv run_fastboot 1;" \
158                 "fi;" \
159                 "if test \"${run_fastboot}\" -eq 0; then " \
160                         "if gpt verify mmc ${mmcdev} ${partitions}; then; " \
161                         "else " \
162                                 "echo Broken MMC partition scheme;" \
163                                 "setenv run_fastboot 1;" \
164                         "fi; " \
165                 "fi;" \
166                 "if test \"${run_fastboot}\" -eq 0; then " \
167                         "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
168                         CONTROL_PARTITION "; then " \
169                                 "if bcb test command = bootonce-bootloader; then " \
170                                         "echo BCB: Bootloader boot...; " \
171                                         "bcb clear command; bcb store; " \
172                                         "setenv run_fastboot 1;" \
173                                 "elif bcb test command = boot-fastboot; then " \
174                                         "echo BCB: fastboot userspace boot...; " \
175                                         "setenv force_recovery 1;" \
176                                 "fi; " \
177                         "else " \
178                                 "echo Warning: BCB is corrupted or does not exist; " \
179                         "fi;" \
180                 "fi;" \
181                 "if test \"${run_fastboot}\" -eq 1; then " \
182                         "echo Running Fastboot...;" \
183                         "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
184                 "fi\0"
185
186 #define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \
187                 "fastboot "
188
189 #define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \
190         "bootcmd_recovery=" \
191                 "pinmux dev pinctrl@14;" \
192                 "pinmux dev pinctrl@40;" \
193                 "setenv run_recovery 0;" \
194                 "if run check_button; then " \
195                         "echo Recovery button is pressed;" \
196                         "setenv run_recovery 1;" \
197                 "fi; " \
198                 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
199                 CONTROL_PARTITION "; then " \
200                         "if bcb test command = boot-recovery; then " \
201                                 "echo BCB: Recovery boot...; " \
202                                 "setenv run_recovery 1;" \
203                         "fi;" \
204                 "else " \
205                         "echo Warning: BCB is corrupted or does not exist; " \
206                 "fi;" \
207                 "if test \"${skip_recovery}\" -eq 1; then " \
208                         "echo Recovery skipped by environment;" \
209                         "setenv run_recovery 0;" \
210                 "fi;" \
211                 "if test \"${force_recovery}\" -eq 1; then " \
212                         "echo Recovery forced by environment;" \
213                         "setenv run_recovery 1;" \
214                 "fi;" \
215                 "if test \"${run_recovery}\" -eq 1; then " \
216                         "echo Running Recovery...;" \
217                         "mmc dev ${mmcdev};" \
218                         "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \
219                         AB_SELECT_SLOT \
220                         AB_SELECT_ARGS \
221                         AVB_VERIFY_CHECK \
222                         "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \
223                         "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \
224                         "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
225                                 PREPARE_FDT \
226                                 "echo Running Android Recovery...;" \
227                                 BOOT_CMD \
228                         "fi;" \
229                         "echo Failed to boot Android...;" \
230                         "reset;" \
231                 "fi\0"
232
233 #define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \
234                 "recovery "
235
236 #define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \
237         "bootcmd_system=" \
238                 "echo Loading Android " BOOT_PARTITION " partition...;" \
239                 "mmc dev ${mmcdev};" \
240                 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \
241                 AB_SELECT_SLOT \
242                 AB_SELECT_ARGS \
243                 AVB_VERIFY_CHECK \
244                 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \
245                 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \
246                 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
247                         PREPARE_FDT \
248                         "setenv bootargs \"${bootargs} " AB_BOOTARGS "\"  ; " \
249                         "echo Running Android...;" \
250                         BOOT_CMD \
251                 "fi;" \
252                 "echo Failed to boot Android...;\0"
253
254 #define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance)   \
255                 "system "
256
257 #define BOOTENV_DEV_PANIC(devtypeu, devtypel, instance) \
258         "bootcmd_panic=" \
259                 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
260                 "reset\0"
261
262 #define BOOTENV_DEV_NAME_PANIC(devtypeu, devtypel, instance)    \
263                 "panic "
264
265 #define BOOT_TARGET_DEVICES(func) \
266         func(FASTBOOT, fastboot, na) \
267         func(RECOVERY, recovery, na) \
268         func(SYSTEM, system, na) \
269         func(PANIC, panic, na) \
270
271 #define PREBOOT_LOAD_LOGO \
272         "if test \"${boot_source}\" != \"usb\" && " \
273                 "gpt verify mmc ${mmcdev} ${partitions}; then; " \
274                 "mmc dev ${mmcdev};" \
275                 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \
276                 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \
277                 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
278                         "bmp display ${loadaddr} m m;" \
279                 "fi;" \
280         "fi;"
281
282 #define CONFIG_EXTRA_ENV_SETTINGS                                     \
283         EXTRA_ANDROID_ENV_SETTINGS                                    \
284         "partitions=" PARTS_DEFAULT "\0"                              \
285         "mmcdev=2\0"                                                  \
286         "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0"     \
287         "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0"        \
288         ANDROIDBOOT_GET_CURRENT_SLOT_CMD                              \
289         AVB_VERIFY_CMD                                                \
290         "force_avb=0\0"                                               \
291         "gpio_recovery=88\0"                                          \
292         "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0"   \
293         "load_logo=" PREBOOT_LOAD_LOGO "\0"                           \
294         "stdin=" STDIN_CFG "\0"                                       \
295         "stdout=" STDOUT_CFG "\0"                                     \
296         "stderr=" STDOUT_CFG "\0"                                     \
297         "dtboaddr=0x08200000\0"                                       \
298         "loadaddr=0x01080000\0"                                       \
299         "fdt_addr_r=0x01000000\0"                                     \
300         "scriptaddr=0x08000000\0"                                     \
301         "kernel_addr_r=0x01080000\0"                                  \
302         "pxefile_addr_r=0x01080000\0"                                 \
303         "ramdisk_addr_r=0x13000000\0"                                 \
304         "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0"        \
305         BOOTENV
306
307 #include <configs/meson64.h>
308
309 #endif /* __MESON64_ANDROID_CONFIG_H */