configs: meson64_android: define BOOT_CMD macro
[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 #define CONFIG_SYS_MALLOC_LEN          SZ_128M
15
16 #ifndef BOOT_PARTITION
17 #define BOOT_PARTITION "boot"
18 #endif
19
20 #ifndef LOGO_PARTITION
21 #define LOGO_PARTITION "logo"
22 #endif
23
24 #ifndef CONTROL_PARTITION
25 #define CONTROL_PARTITION "misc"
26 #endif
27
28 #if defined(CONFIG_CMD_AVB)
29 #define AVB_VERIFY_CHECK \
30         "if test \"${force_avb}\" -eq 1; then " \
31                 "if run avb_verify; then " \
32                         "echo AVB verification OK.;" \
33                         "setenv bootargs \"$bootargs $avb_bootargs\";" \
34                 "else " \
35                         "echo AVB verification failed.;" \
36                 "exit; fi;" \
37         "else " \
38                 "setenv bootargs \"$bootargs androidboot.verifiedbootstate=orange\";" \
39                 "echo Running without AVB...; "\
40         "fi;"
41
42 #define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0"
43 #else
44 #define AVB_VERIFY_CHECK ""
45 #define AVB_VERIFY_CMD ""
46 #endif
47
48 #if defined(CONFIG_CMD_AB_SELECT)
49 #define ANDROIDBOOT_GET_CURRENT_SLOT_CMD "get_current_slot=" \
50         "if part number mmc ${mmcdev} " CONTROL_PARTITION " control_part_number; " \
51         "then " \
52                 "echo " CONTROL_PARTITION \
53                         " partition number:${control_part_number};" \
54                 "ab_select current_slot mmc ${mmcdev}:${control_part_number};" \
55         "else " \
56                 "echo " CONTROL_PARTITION " partition not found;" \
57         "fi;\0"
58
59 #define AB_SELECT_SLOT \
60         "run get_current_slot; " \
61         "if test -e \"${current_slot}\"; " \
62         "then " \
63                 "setenv slot_suffix _${current_slot}; " \
64         "else " \
65                 "echo current_slot not found;" \
66                 "exit;" \
67         "fi;"
68
69 #define AB_SELECT_ARGS \
70         "setenv bootargs_ab androidboot.slot_suffix=${slot_suffix}; " \
71         "echo A/B cmdline addition: ${bootargs_ab};" \
72         "setenv bootargs ${bootargs} ${bootargs_ab};"
73
74 #define AB_BOOTARGS " androidboot.force_normal_boot=1"
75 #define RECOVERY_PARTITION "boot"
76 #else
77 #define AB_SELECT_SLOT ""
78 #define AB_SELECT_ARGS " "
79 #define ANDROIDBOOT_GET_CURRENT_SLOT_CMD ""
80 #define AB_BOOTARGS " "
81 #define RECOVERY_PARTITION "recovery"
82 #endif
83
84 #define BOOT_CMD "bootm ${loadaddr};"
85
86 #define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \
87         "bootcmd_fastboot=" \
88                 "setenv run_fastboot 0;" \
89                 "if test \"${boot_source}\" = \"usb\"; then " \
90                         "echo Fastboot forced by usb rom boot;" \
91                         "setenv run_fastboot 1;" \
92                 "fi;" \
93                 "if gpt verify mmc ${mmcdev} ${partitions}; then; " \
94                 "else " \
95                         "echo Broken MMC partition scheme;" \
96                         "setenv run_fastboot 1;" \
97                 "fi;" \
98                 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
99                 CONTROL_PARTITION "; then " \
100                         "if bcb test command = bootonce-bootloader; then " \
101                                 "echo BCB: Bootloader boot...; " \
102                                 "bcb clear command; bcb store; " \
103                                 "setenv run_fastboot 1;" \
104                         "fi; " \
105                         "if bcb test command = boot-fastboot; then " \
106                                 "echo BCB: fastboot userspace boot...; " \
107                                 "setenv force_recovery 1;" \
108                         "fi; " \
109                 "else " \
110                         "echo Warning: BCB is corrupted or does not exist; " \
111                 "fi;" \
112                 "if test \"${run_fastboot}\" -eq 1; then " \
113                         "echo Running Fastboot...;" \
114                         "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
115                 "fi\0"
116
117 #define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \
118                 "fastboot "
119
120 #define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \
121         "bootcmd_recovery=" \
122                 "pinmux dev pinctrl@14;" \
123                 "pinmux dev pinctrl@40;" \
124                 "setenv run_recovery 0;" \
125                 "if run check_button; then " \
126                         "echo Recovery button is pressed;" \
127                         "setenv run_recovery 1;" \
128                 "fi; " \
129                 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
130                 CONTROL_PARTITION "; then " \
131                         "if bcb test command = boot-recovery; then " \
132                                 "echo BCB: Recovery boot...; " \
133                                 "setenv run_recovery 1;" \
134                         "fi;" \
135                 "else " \
136                         "echo Warning: BCB is corrupted or does not exist; " \
137                 "fi;" \
138                 "if test \"${skip_recovery}\" -eq 1; then " \
139                         "echo Recovery skipped by environment;" \
140                         "setenv run_recovery 0;" \
141                 "fi;" \
142                 "if test \"${force_recovery}\" -eq 1; then " \
143                         "echo Recovery forced by environment;" \
144                         "setenv run_recovery 1;" \
145                 "fi;" \
146                 "if test \"${run_recovery}\" -eq 1; then " \
147                         "echo Running Recovery...;" \
148                         "mmc dev ${mmcdev};" \
149                         "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \
150                         AB_SELECT_SLOT \
151                         AB_SELECT_ARGS \
152                         AVB_VERIFY_CHECK \
153                         "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \
154                         "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \
155                         "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
156                                 "echo Running Android Recovery...;" \
157                                 BOOT_CMD \
158                         "fi;" \
159                         "echo Failed to boot Android...;" \
160                         "reset;" \
161                 "fi\0"
162
163 #define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \
164                 "recovery "
165
166 #define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \
167         "bootcmd_system=" \
168                 "echo Loading Android " BOOT_PARTITION " partition...;" \
169                 "mmc dev ${mmcdev};" \
170                 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \
171                 AB_SELECT_SLOT \
172                 AB_SELECT_ARGS \
173                 AVB_VERIFY_CHECK \
174                 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \
175                 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \
176                 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
177                         "setenv bootargs \"${bootargs} " AB_BOOTARGS "\"  ; " \
178                         "echo Running Android...;" \
179                         BOOT_CMD \
180                 "fi;" \
181                 "echo Failed to boot Android...;" \
182                 "reset\0"
183
184 #define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance)   \
185                 "system "
186
187 #define BOOT_TARGET_DEVICES(func) \
188         func(FASTBOOT, fastboot, na) \
189         func(RECOVERY, recovery, na) \
190         func(SYSTEM, system, na) \
191
192 #define PREBOOT_LOAD_LOGO \
193         "if test \"${boot_source}\" != \"usb\" && " \
194                 "gpt verify mmc ${mmcdev} ${partitions}; then; " \
195                 "mmc dev ${mmcdev};" \
196                 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \
197                 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \
198                 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
199                         "bmp display ${loadaddr} m m;" \
200                 "fi;" \
201         "fi;"
202
203 #define CONFIG_EXTRA_ENV_SETTINGS                                     \
204         "partitions=" PARTS_DEFAULT "\0"                              \
205         "mmcdev=2\0"                                                  \
206         ANDROIDBOOT_GET_CURRENT_SLOT_CMD                              \
207         AVB_VERIFY_CMD                                                \
208         "force_avb=0\0"                                               \
209         "gpio_recovery=88\0"                                          \
210         "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0"   \
211         "load_logo=" PREBOOT_LOAD_LOGO "\0"                           \
212         "stdin=" STDIN_CFG "\0"                                       \
213         "stdout=" STDOUT_CFG "\0"                                     \
214         "stderr=" STDOUT_CFG "\0"                                     \
215         "loadaddr=0x01000000\0"                                       \
216         "fdt_addr_r=0x01000000\0"                                     \
217         "scriptaddr=0x08000000\0"                                     \
218         "kernel_addr_r=0x01080000\0"                                  \
219         "pxefile_addr_r=0x01080000\0"                                 \
220         "ramdisk_addr_r=0x13000000\0"                                 \
221         "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0"        \
222         BOOTENV
223
224 #include <configs/meson64.h>
225
226 #endif /* __MESON64_ANDROID_CONFIG_H */