configs: meson64_android: add board specific env settings
[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         "else " \
108                 "echo Error: Android boot is not supported for $board_name; " \
109                 "exit; " \
110         "fi; " \
111         "abootimg get dtb --index=$dtb_index dtb_start dtb_size; " \
112         "cp.b $dtb_start $fdt_addr_r $dtb_size; " \
113         "fdt addr $fdt_addr_r  0x80000; " \
114         "if test $board_name = sei510; then " \
115                 "echo \"  Reading DTBO for sei510...\"; " \
116                 "setenv dtbo_index 0;" \
117         "elif test $board_name = sei610; then " \
118                 "echo \"  Reading DTBO for sei610...\"; " \
119                 "setenv dtbo_index 1;" \
120         "else " \
121                 "echo Error: Android boot is not supported for $board_name; " \
122                 "exit; " \
123         "fi; " \
124         "part start mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_start; " \
125         "part size mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_size; " \
126         "mmc read ${dtboaddr} ${p_dtbo_start} ${p_dtbo_size}; " \
127         "echo \"  Applying DTBOs...\"; " \
128         "adtimg addr $dtboaddr; " \
129         "adtimg get dt --index=$dtbo_index dtbo0_addr; " \
130         "fdt apply $dtbo0_addr;" \
131         "setenv bootargs \"$bootargs androidboot.dtbo_idx=$dtbo_index \";"\
132
133 #define BOOT_CMD "bootm ${loadaddr} ${loadaddr} ${fdt_addr_r};"
134
135 #else
136 #define PREPARE_FDT " "
137 #define BOOT_CMD "bootm ${loadaddr};"
138 #endif
139
140 #define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \
141         "bootcmd_fastboot=" \
142                 "setenv run_fastboot 0;" \
143                 "if test \"${boot_source}\" = \"usb\"; then " \
144                         "echo Fastboot forced by usb rom boot;" \
145                         "setenv run_fastboot 1;" \
146                 "fi;" \
147                 "if test \"${run_fastboot}\" -eq 0; then " \
148                         "if gpt verify mmc ${mmcdev} ${partitions}; then; " \
149                         "else " \
150                                 "echo Broken MMC partition scheme;" \
151                                 "setenv run_fastboot 1;" \
152                         "fi; " \
153                 "fi;" \
154                 "if test \"${run_fastboot}\" -eq 0; then " \
155                         "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
156                         CONTROL_PARTITION "; then " \
157                                 "if bcb test command = bootonce-bootloader; then " \
158                                         "echo BCB: Bootloader boot...; " \
159                                         "bcb clear command; bcb store; " \
160                                         "setenv run_fastboot 1;" \
161                                 "elif bcb test command = boot-fastboot; then " \
162                                         "echo BCB: fastboot userspace boot...; " \
163                                         "setenv force_recovery 1;" \
164                                 "fi; " \
165                         "else " \
166                                 "echo Warning: BCB is corrupted or does not exist; " \
167                         "fi;" \
168                 "fi;" \
169                 "if test \"${run_fastboot}\" -eq 1; then " \
170                         "echo Running Fastboot...;" \
171                         "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
172                 "fi\0"
173
174 #define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \
175                 "fastboot "
176
177 #define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \
178         "bootcmd_recovery=" \
179                 "pinmux dev pinctrl@14;" \
180                 "pinmux dev pinctrl@40;" \
181                 "setenv run_recovery 0;" \
182                 "if run check_button; then " \
183                         "echo Recovery button is pressed;" \
184                         "setenv run_recovery 1;" \
185                 "fi; " \
186                 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
187                 CONTROL_PARTITION "; then " \
188                         "if bcb test command = boot-recovery; then " \
189                                 "echo BCB: Recovery boot...; " \
190                                 "setenv run_recovery 1;" \
191                         "fi;" \
192                 "else " \
193                         "echo Warning: BCB is corrupted or does not exist; " \
194                 "fi;" \
195                 "if test \"${skip_recovery}\" -eq 1; then " \
196                         "echo Recovery skipped by environment;" \
197                         "setenv run_recovery 0;" \
198                 "fi;" \
199                 "if test \"${force_recovery}\" -eq 1; then " \
200                         "echo Recovery forced by environment;" \
201                         "setenv run_recovery 1;" \
202                 "fi;" \
203                 "if test \"${run_recovery}\" -eq 1; then " \
204                         "echo Running Recovery...;" \
205                         "mmc dev ${mmcdev};" \
206                         "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \
207                         AB_SELECT_SLOT \
208                         AB_SELECT_ARGS \
209                         AVB_VERIFY_CHECK \
210                         "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \
211                         "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \
212                         "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
213                                 PREPARE_FDT \
214                                 "echo Running Android Recovery...;" \
215                                 BOOT_CMD \
216                         "fi;" \
217                         "echo Failed to boot Android...;" \
218                         "reset;" \
219                 "fi\0"
220
221 #define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \
222                 "recovery "
223
224 #define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \
225         "bootcmd_system=" \
226                 "echo Loading Android " BOOT_PARTITION " partition...;" \
227                 "mmc dev ${mmcdev};" \
228                 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \
229                 AB_SELECT_SLOT \
230                 AB_SELECT_ARGS \
231                 AVB_VERIFY_CHECK \
232                 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \
233                 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \
234                 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
235                         PREPARE_FDT \
236                         "setenv bootargs \"${bootargs} " AB_BOOTARGS "\"  ; " \
237                         "echo Running Android...;" \
238                         BOOT_CMD \
239                 "fi;" \
240                 "echo Failed to boot Android...;\0"
241
242 #define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance)   \
243                 "system "
244
245 #define BOOTENV_DEV_PANIC(devtypeu, devtypel, instance) \
246         "bootcmd_panic=" \
247                 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
248                 "reset\0"
249
250 #define BOOTENV_DEV_NAME_PANIC(devtypeu, devtypel, instance)    \
251                 "panic "
252
253 #define BOOT_TARGET_DEVICES(func) \
254         func(FASTBOOT, fastboot, na) \
255         func(RECOVERY, recovery, na) \
256         func(SYSTEM, system, na) \
257         func(PANIC, panic, na) \
258
259 #define PREBOOT_LOAD_LOGO \
260         "if test \"${boot_source}\" != \"usb\" && " \
261                 "gpt verify mmc ${mmcdev} ${partitions}; then; " \
262                 "mmc dev ${mmcdev};" \
263                 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \
264                 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \
265                 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
266                         "bmp display ${loadaddr} m m;" \
267                 "fi;" \
268         "fi;"
269
270 #define CONFIG_EXTRA_ENV_SETTINGS                                     \
271         EXTRA_ANDROID_ENV_SETTINGS                                    \
272         "partitions=" PARTS_DEFAULT "\0"                              \
273         "mmcdev=2\0"                                                  \
274         ANDROIDBOOT_GET_CURRENT_SLOT_CMD                              \
275         AVB_VERIFY_CMD                                                \
276         "force_avb=0\0"                                               \
277         "gpio_recovery=88\0"                                          \
278         "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0"   \
279         "load_logo=" PREBOOT_LOAD_LOGO "\0"                           \
280         "stdin=" STDIN_CFG "\0"                                       \
281         "stdout=" STDOUT_CFG "\0"                                     \
282         "stderr=" STDOUT_CFG "\0"                                     \
283         "dtboaddr=0x08200000\0"                                       \
284         "loadaddr=0x01080000\0"                                       \
285         "fdt_addr_r=0x01000000\0"                                     \
286         "scriptaddr=0x08000000\0"                                     \
287         "kernel_addr_r=0x01080000\0"                                  \
288         "pxefile_addr_r=0x01080000\0"                                 \
289         "ramdisk_addr_r=0x13000000\0"                                 \
290         "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0"        \
291         BOOTENV
292
293 #include <configs/meson64.h>
294
295 #endif /* __MESON64_ANDROID_CONFIG_H */