blob: c0e977abb01fb9efb7a462906a0073c84c800897 [file] [log] [blame]
Guillaume La Roque95b488a2019-10-11 17:33:57 +02001/* 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
Mattijs Korpershoeka3ad03f2021-08-05 17:17:21 +020012#include <linux/sizes.h>
13
Mattijs Korpershoek5a4a7102021-07-29 09:21:11 +020014#ifndef BOOT_PARTITION
15#define BOOT_PARTITION "boot"
16#endif
Guillaume La Roque95b488a2019-10-11 17:33:57 +020017
Mattijs Korpershoek4a3ede92021-07-29 09:21:12 +020018#ifndef LOGO_PARTITION
19#define LOGO_PARTITION "logo"
20#endif
21
Mattijs Korpershoekb09908c2021-07-30 14:28:08 +020022#ifndef CONTROL_PARTITION
23#define CONTROL_PARTITION "misc"
24#endif
25
Mattijs Korpershoeka65f8352021-11-22 16:22:04 +010026#ifndef EXTRA_ANDROID_ENV_SETTINGS
27#define EXTRA_ANDROID_ENV_SETTINGS ""
28#endif
29
Mattijs Korpershoek94c09882021-08-05 17:17:22 +020030#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
Mattijs Korpershoek8c357212021-08-05 17:17:23 +020044#define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0"
Mattijs Korpershoek94c09882021-08-05 17:17:22 +020045#else
46#define AVB_VERIFY_CHECK ""
47#define AVB_VERIFY_CMD ""
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +020048#endif
49
Mattijs Korpershoek8c357212021-08-05 17:17:23 +020050#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
Guillaume La Roqueb8ec7622021-08-05 17:17:25 +020086#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;" \
Mattijs Korpershoek7f834cb2021-11-22 16:22:05 +0100107 "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;" \
Guillaume La Roqueb8ec7622021-08-05 17:17:25 +0200113 "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;" \
Mattijs Korpershoek7f834cb2021-11-22 16:22:05 +0100126 "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;" \
Guillaume La Roqueb8ec7622021-08-05 17:17:25 +0200132 "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 " "
Mattijs Korpershoek6b414b52021-08-05 17:17:24 +0200149#define BOOT_CMD "bootm ${loadaddr};"
Guillaume La Roqueb8ec7622021-08-05 17:17:25 +0200150#endif
Mattijs Korpershoek6b414b52021-08-05 17:17:24 +0200151
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200152#define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \
153 "bootcmd_fastboot=" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200154 "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;" \
Neil Armstrong6cb37a22021-11-17 12:04:10 +0100159 "if test \"${run_fastboot}\" -eq 0; then " \
160 "if gpt verify mmc ${mmcdev} ${partitions}; then; " \
161 "else " \
162 "echo Broken MMC partition scheme;" \
Mattijs Korpershoekb09908c2021-07-30 14:28:08 +0200163 "setenv run_fastboot 1;" \
164 "fi; " \
Neil Armstrong6cb37a22021-11-17 12:04:10 +0100165 "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;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200180 "fi;" \
181 "if test \"${run_fastboot}\" -eq 1; then " \
182 "echo Running Fastboot...;" \
Mattijs Korpershoekb0a88af2021-07-29 09:21:10 +0200183 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200184 "fi\0"
185
186#define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \
187 "fastboot "
188
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200189#define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \
190 "bootcmd_recovery=" \
191 "pinmux dev pinctrl@14;" \
192 "pinmux dev pinctrl@40;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200193 "setenv run_recovery 0;" \
194 "if run check_button; then " \
195 "echo Recovery button is pressed;" \
196 "setenv run_recovery 1;" \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200197 "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; " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200206 "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...;" \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200217 "mmc dev ${mmcdev};" \
218 "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200219 AB_SELECT_SLOT \
220 AB_SELECT_ARGS \
Mattijs Korpershoek94c09882021-08-05 17:17:22 +0200221 AVB_VERIFY_CHECK \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200222 "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \
223 "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200224 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Guillaume La Roqueb8ec7622021-08-05 17:17:25 +0200225 PREPARE_FDT \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200226 "echo Running Android Recovery...;" \
Mattijs Korpershoek6b414b52021-08-05 17:17:24 +0200227 BOOT_CMD \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200228 "fi;" \
229 "echo Failed to boot Android...;" \
230 "reset;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200231 "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=" \
Mattijs Korpershoek5a4a7102021-07-29 09:21:11 +0200238 "echo Loading Android " BOOT_PARTITION " partition...;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200239 "mmc dev ${mmcdev};" \
Mattijs Korpershoek6f51aa22021-07-29 09:21:13 +0200240 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200241 AB_SELECT_SLOT \
242 AB_SELECT_ARGS \
Mattijs Korpershoek94c09882021-08-05 17:17:22 +0200243 AVB_VERIFY_CHECK \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200244 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \
245 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200246 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Guillaume La Roqueb8ec7622021-08-05 17:17:25 +0200247 PREPARE_FDT \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200248 "setenv bootargs \"${bootargs} " AB_BOOTARGS "\" ; " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200249 "echo Running Android...;" \
Mattijs Korpershoek6b414b52021-08-05 17:17:24 +0200250 BOOT_CMD \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200251 "fi;" \
Neil Armstrongd2608892021-11-17 12:04:11 +0100252 "echo Failed to boot Android...;\0"
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200253
254#define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance) \
255 "system "
256
Neil Armstrongd2608892021-11-17 12:04:11 +0100257#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
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200265#define BOOT_TARGET_DEVICES(func) \
266 func(FASTBOOT, fastboot, na) \
267 func(RECOVERY, recovery, na) \
268 func(SYSTEM, system, na) \
Neil Armstrongd2608892021-11-17 12:04:11 +0100269 func(PANIC, panic, na) \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200270
271#define PREBOOT_LOAD_LOGO \
Guillaume La Roqueb7162fa2020-10-30 16:03:44 +0100272 "if test \"${boot_source}\" != \"usb\" && " \
273 "gpt verify mmc ${mmcdev} ${partitions}; then; " \
274 "mmc dev ${mmcdev};" \
Mattijs Korpershoek4a3ede92021-07-29 09:21:12 +0200275 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \
276 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \
Guillaume La Roqueb7162fa2020-10-30 16:03:44 +0100277 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200278 "bmp display ${loadaddr} m m;" \
Guillaume La Roqueb7162fa2020-10-30 16:03:44 +0100279 "fi;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200280 "fi;"
281
Tom Rinic9edebe2022-12-04 10:03:50 -0500282#define CFG_EXTRA_ENV_SETTINGS \
Mattijs Korpershoeka65f8352021-11-22 16:22:04 +0100283 EXTRA_ANDROID_ENV_SETTINGS \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200284 "partitions=" PARTS_DEFAULT "\0" \
285 "mmcdev=2\0" \
Mattijs Korpershoek500373b2022-01-07 17:39:13 +0100286 "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0" \
287 "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0" \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200288 ANDROIDBOOT_GET_CURRENT_SLOT_CMD \
Mattijs Korpershoek94c09882021-08-05 17:17:22 +0200289 AVB_VERIFY_CMD \
290 "force_avb=0\0" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200291 "gpio_recovery=88\0" \
292 "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0" \
293 "load_logo=" PREBOOT_LOAD_LOGO "\0" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200294 "stdin=" STDIN_CFG "\0" \
295 "stdout=" STDOUT_CFG "\0" \
296 "stderr=" STDOUT_CFG "\0" \
Guillaume La Roqueb8ec7622021-08-05 17:17:25 +0200297 "dtboaddr=0x08200000\0" \
298 "loadaddr=0x01080000\0" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200299 "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" \
Mattijs Korpershoek4d73d352021-07-29 09:21:09 +0200304 "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
305 BOOTENV
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200306
307#include <configs/meson64.h>
308
309#endif /* __MESON64_ANDROID_CONFIG_H */