blob: fa520265800ccf081862bc97643b6a8e28b13327 [file] [log] [blame]
Guillaume La Roque880c0aa2019-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 Korpershoek285a83b2021-08-05 17:17:21 +020012#include <linux/sizes.h>
13
Mattijs Korpershoekf2cd6482021-07-29 09:21:11 +020014#ifndef BOOT_PARTITION
15#define BOOT_PARTITION "boot"
16#endif
Guillaume La Roque880c0aa2019-10-11 17:33:57 +020017
Mattijs Korpershoek211f1d92021-07-29 09:21:12 +020018#ifndef LOGO_PARTITION
19#define LOGO_PARTITION "logo"
20#endif
21
Mattijs Korpershoek9d0ac612021-07-30 14:28:08 +020022#ifndef CONTROL_PARTITION
23#define CONTROL_PARTITION "misc"
24#endif
25
Mattijs Korpershoek4eff7422021-11-22 16:22:04 +010026#ifndef EXTRA_ANDROID_ENV_SETTINGS
27#define EXTRA_ANDROID_ENV_SETTINGS ""
28#endif
29
Mattijs Korpershoeke6c782b2021-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 Korpershoekefc28f62021-08-05 17:17:23 +020044#define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0"
Mattijs Korpershoeke6c782b2021-08-05 17:17:22 +020045#else
46#define AVB_VERIFY_CHECK ""
47#define AVB_VERIFY_CMD ""
Mattijs Korpershoek72d7c032021-07-30 14:28:09 +020048#endif
49
Mattijs Korpershoekefc28f62021-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 Roque72cefba2021-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 Korpershoekf89b90d2021-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 Roque72cefba2021-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; " \
Mattijs Korpershoek0b063d62024-10-11 17:51:03 +0200119 "fdt addr $fdt_addr_r 0x80000; "
Guillaume La Roque72cefba2021-08-05 17:17:25 +0200120
121#define BOOT_CMD "bootm ${loadaddr} ${loadaddr} ${fdt_addr_r};"
122
123#else
124#define PREPARE_FDT " "
Mattijs Korpershoek7039cbd2021-08-05 17:17:24 +0200125#define BOOT_CMD "bootm ${loadaddr};"
Guillaume La Roque72cefba2021-08-05 17:17:25 +0200126#endif
Mattijs Korpershoek7039cbd2021-08-05 17:17:24 +0200127
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200128#define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \
129 "bootcmd_fastboot=" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200130 "setenv run_fastboot 0;" \
131 "if test \"${boot_source}\" = \"usb\"; then " \
132 "echo Fastboot forced by usb rom boot;" \
133 "setenv run_fastboot 1;" \
134 "fi;" \
Neil Armstrongbdc68df2021-11-17 12:04:10 +0100135 "if test \"${run_fastboot}\" -eq 0; then " \
136 "if gpt verify mmc ${mmcdev} ${partitions}; then; " \
137 "else " \
138 "echo Broken MMC partition scheme;" \
Mattijs Korpershoek9d0ac612021-07-30 14:28:08 +0200139 "setenv run_fastboot 1;" \
140 "fi; " \
Neil Armstrongbdc68df2021-11-17 12:04:10 +0100141 "fi;" \
142 "if test \"${run_fastboot}\" -eq 0; then " \
143 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
144 CONTROL_PARTITION "; then " \
145 "if bcb test command = bootonce-bootloader; then " \
146 "echo BCB: Bootloader boot...; " \
147 "bcb clear command; bcb store; " \
148 "setenv run_fastboot 1;" \
149 "elif bcb test command = boot-fastboot; then " \
150 "echo BCB: fastboot userspace boot...; " \
151 "setenv force_recovery 1;" \
152 "fi; " \
153 "else " \
154 "echo Warning: BCB is corrupted or does not exist; " \
155 "fi;" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200156 "fi;" \
157 "if test \"${run_fastboot}\" -eq 1; then " \
158 "echo Running Fastboot...;" \
Mattijs Korpershoek75be1eb2021-07-29 09:21:10 +0200159 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200160 "fi\0"
161
162#define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \
163 "fastboot "
164
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200165#define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \
166 "bootcmd_recovery=" \
167 "pinmux dev pinctrl@14;" \
168 "pinmux dev pinctrl@40;" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200169 "setenv run_recovery 0;" \
170 "if run check_button; then " \
171 "echo Recovery button is pressed;" \
172 "setenv run_recovery 1;" \
Mattijs Korpershoek72d7c032021-07-30 14:28:09 +0200173 "fi; " \
174 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
175 CONTROL_PARTITION "; then " \
176 "if bcb test command = boot-recovery; then " \
177 "echo BCB: Recovery boot...; " \
178 "setenv run_recovery 1;" \
179 "fi;" \
180 "else " \
181 "echo Warning: BCB is corrupted or does not exist; " \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200182 "fi;" \
183 "if test \"${skip_recovery}\" -eq 1; then " \
184 "echo Recovery skipped by environment;" \
185 "setenv run_recovery 0;" \
186 "fi;" \
187 "if test \"${force_recovery}\" -eq 1; then " \
188 "echo Recovery forced by environment;" \
189 "setenv run_recovery 1;" \
190 "fi;" \
191 "if test \"${run_recovery}\" -eq 1; then " \
192 "echo Running Recovery...;" \
Mattijs Korpershoek72d7c032021-07-30 14:28:09 +0200193 "mmc dev ${mmcdev};" \
194 "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \
Mattijs Korpershoekefc28f62021-08-05 17:17:23 +0200195 AB_SELECT_SLOT \
196 AB_SELECT_ARGS \
Mattijs Korpershoeke6c782b2021-08-05 17:17:22 +0200197 AVB_VERIFY_CHECK \
Mattijs Korpershoekefc28f62021-08-05 17:17:23 +0200198 "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \
199 "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \
Mattijs Korpershoek72d7c032021-07-30 14:28:09 +0200200 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Guillaume La Roque72cefba2021-08-05 17:17:25 +0200201 PREPARE_FDT \
Mattijs Korpershoek72d7c032021-07-30 14:28:09 +0200202 "echo Running Android Recovery...;" \
Mattijs Korpershoek7039cbd2021-08-05 17:17:24 +0200203 BOOT_CMD \
Mattijs Korpershoek72d7c032021-07-30 14:28:09 +0200204 "fi;" \
205 "echo Failed to boot Android...;" \
206 "reset;" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200207 "fi\0"
208
209#define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \
210 "recovery "
211
212#define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \
213 "bootcmd_system=" \
Mattijs Korpershoekf2cd6482021-07-29 09:21:11 +0200214 "echo Loading Android " BOOT_PARTITION " partition...;" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200215 "mmc dev ${mmcdev};" \
Mattijs Korpershoek143e1532021-07-29 09:21:13 +0200216 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \
Mattijs Korpershoekefc28f62021-08-05 17:17:23 +0200217 AB_SELECT_SLOT \
218 AB_SELECT_ARGS \
Mattijs Korpershoeke6c782b2021-08-05 17:17:22 +0200219 AVB_VERIFY_CHECK \
Mattijs Korpershoekefc28f62021-08-05 17:17:23 +0200220 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \
221 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200222 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Guillaume La Roque72cefba2021-08-05 17:17:25 +0200223 PREPARE_FDT \
Mattijs Korpershoekefc28f62021-08-05 17:17:23 +0200224 "setenv bootargs \"${bootargs} " AB_BOOTARGS "\" ; " \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200225 "echo Running Android...;" \
Mattijs Korpershoek7039cbd2021-08-05 17:17:24 +0200226 BOOT_CMD \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200227 "fi;" \
Neil Armstrong28f70cf2021-11-17 12:04:11 +0100228 "echo Failed to boot Android...;\0"
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200229
230#define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance) \
231 "system "
232
Neil Armstrong28f70cf2021-11-17 12:04:11 +0100233#define BOOTENV_DEV_PANIC(devtypeu, devtypel, instance) \
234 "bootcmd_panic=" \
235 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
236 "reset\0"
237
238#define BOOTENV_DEV_NAME_PANIC(devtypeu, devtypel, instance) \
239 "panic "
240
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200241#define BOOT_TARGET_DEVICES(func) \
242 func(FASTBOOT, fastboot, na) \
243 func(RECOVERY, recovery, na) \
244 func(SYSTEM, system, na) \
Neil Armstrong28f70cf2021-11-17 12:04:11 +0100245 func(PANIC, panic, na) \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200246
247#define PREBOOT_LOAD_LOGO \
Guillaume La Roque82f65082020-10-30 16:03:44 +0100248 "if test \"${boot_source}\" != \"usb\" && " \
249 "gpt verify mmc ${mmcdev} ${partitions}; then; " \
250 "mmc dev ${mmcdev};" \
Mattijs Korpershoek211f1d92021-07-29 09:21:12 +0200251 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \
252 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \
Guillaume La Roque82f65082020-10-30 16:03:44 +0100253 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200254 "bmp display ${loadaddr} m m;" \
Guillaume La Roque82f65082020-10-30 16:03:44 +0100255 "fi;" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200256 "fi;"
257
Tom Rini0613c362022-12-04 10:03:50 -0500258#define CFG_EXTRA_ENV_SETTINGS \
Mattijs Korpershoek4eff7422021-11-22 16:22:04 +0100259 EXTRA_ANDROID_ENV_SETTINGS \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200260 "partitions=" PARTS_DEFAULT "\0" \
261 "mmcdev=2\0" \
Mattijs Korpershoekb749d5e2022-01-07 17:39:13 +0100262 "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0" \
263 "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0" \
Mattijs Korpershoekefc28f62021-08-05 17:17:23 +0200264 ANDROIDBOOT_GET_CURRENT_SLOT_CMD \
Mattijs Korpershoeke6c782b2021-08-05 17:17:22 +0200265 AVB_VERIFY_CMD \
266 "force_avb=0\0" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200267 "gpio_recovery=88\0" \
268 "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0" \
269 "load_logo=" PREBOOT_LOAD_LOGO "\0" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200270 "stdin=" STDIN_CFG "\0" \
271 "stdout=" STDOUT_CFG "\0" \
272 "stderr=" STDOUT_CFG "\0" \
Guillaume La Roque72cefba2021-08-05 17:17:25 +0200273 "dtboaddr=0x08200000\0" \
274 "loadaddr=0x01080000\0" \
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200275 "fdt_addr_r=0x01000000\0" \
276 "scriptaddr=0x08000000\0" \
277 "kernel_addr_r=0x01080000\0" \
278 "pxefile_addr_r=0x01080000\0" \
279 "ramdisk_addr_r=0x13000000\0" \
Mattijs Korpershoekd1af9aa2021-07-29 09:21:09 +0200280 "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
281 BOOTENV
Guillaume La Roque880c0aa2019-10-11 17:33:57 +0200282
283#include <configs/meson64.h>
284
285#endif /* __MESON64_ANDROID_CONFIG_H */