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