1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Configuration for Android Amlogic Meson 64bits SoCs
5 * Copyright (C) 2019 Baylibre, SAS
6 * Author: Jerome Brunet <jbrunet@baylibre.com>
9 #ifndef __MESON64_ANDROID_CONFIG_H
10 #define __MESON64_ANDROID_CONFIG_H
12 #include <linux/sizes.h>
14 #ifndef BOOT_PARTITION
15 #define BOOT_PARTITION "boot"
18 #ifndef LOGO_PARTITION
19 #define LOGO_PARTITION "logo"
22 #ifndef CONTROL_PARTITION
23 #define CONTROL_PARTITION "misc"
26 #ifndef EXTRA_ANDROID_ENV_SETTINGS
27 #define EXTRA_ANDROID_ENV_SETTINGS ""
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\";" \
37 "echo AVB verification failed.;" \
40 "setenv bootargs \"$bootargs androidboot.verifiedbootstate=orange\";" \
41 "echo Running without AVB...; "\
44 #define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0"
46 #define AVB_VERIFY_CHECK ""
47 #define AVB_VERIFY_CMD ""
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; " \
54 "echo " CONTROL_PARTITION \
55 " partition number:${control_part_number};" \
56 "ab_select current_slot mmc ${mmcdev}:${control_part_number};" \
58 "echo " CONTROL_PARTITION " partition not found;" \
61 #define AB_SELECT_SLOT \
62 "run get_current_slot; " \
63 "if test -e \"${current_slot}\"; " \
65 "setenv slot_suffix _${current_slot}; " \
67 "echo current_slot not found;" \
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};"
76 #define AB_BOOTARGS " androidboot.force_normal_boot=1"
77 #define RECOVERY_PARTITION "boot"
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"
86 #if defined(CONFIG_CMD_ABOOTIMG)
88 * Prepares complete device tree blob for current board (for Android boot).
90 * Boot image or recovery image should be loaded into $loadaddr prior to running
91 * these commands. The logic of these commnads is next:
93 * 1. Read correct DTB for current SoC/board from boot image in $loadaddr
95 * 2. Merge all needed DTBO for current board from 'dtbo' partition into read
97 * 3. User should provide $fdtaddr as 3rd argument to 'bootm'
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 "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;" \
114 "echo Error: Android boot is not supported for $board_name; " \
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;" \
126 "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;" \
133 "echo Error: Android boot is not supported for $board_name; " \
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 \";"\
145 #define BOOT_CMD "bootm ${loadaddr} ${loadaddr} ${fdt_addr_r};"
148 #define PREPARE_FDT " "
149 #define BOOT_CMD "bootm ${loadaddr};"
152 #define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \
153 "bootcmd_fastboot=" \
154 "setenv run_fastboot 0;" \
155 "if test \"${boot_source}\" = \"usb\"; then " \
156 "echo Fastboot forced by usb rom boot;" \
157 "setenv run_fastboot 1;" \
159 "if test \"${run_fastboot}\" -eq 0; then " \
160 "if gpt verify mmc ${mmcdev} ${partitions}; then; " \
162 "echo Broken MMC partition scheme;" \
163 "setenv run_fastboot 1;" \
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;" \
178 "echo Warning: BCB is corrupted or does not exist; " \
181 "if test \"${run_fastboot}\" -eq 1; then " \
182 "echo Running Fastboot...;" \
183 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
186 #define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \
189 #define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \
190 "bootcmd_recovery=" \
191 "pinmux dev pinctrl@14;" \
192 "pinmux dev pinctrl@40;" \
193 "setenv run_recovery 0;" \
194 "if run check_button; then " \
195 "echo Recovery button is pressed;" \
196 "setenv run_recovery 1;" \
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;" \
205 "echo Warning: BCB is corrupted or does not exist; " \
207 "if test \"${skip_recovery}\" -eq 1; then " \
208 "echo Recovery skipped by environment;" \
209 "setenv run_recovery 0;" \
211 "if test \"${force_recovery}\" -eq 1; then " \
212 "echo Recovery forced by environment;" \
213 "setenv run_recovery 1;" \
215 "if test \"${run_recovery}\" -eq 1; then " \
216 "echo Running Recovery...;" \
217 "mmc dev ${mmcdev};" \
218 "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \
222 "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \
223 "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \
224 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
226 "echo Running Android Recovery...;" \
229 "echo Failed to boot Android...;" \
233 #define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \
236 #define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \
238 "echo Loading Android " BOOT_PARTITION " partition...;" \
239 "mmc dev ${mmcdev};" \
240 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \
244 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \
245 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \
246 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
248 "setenv bootargs \"${bootargs} " AB_BOOTARGS "\" ; " \
249 "echo Running Android...;" \
252 "echo Failed to boot Android...;\0"
254 #define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance) \
257 #define BOOTENV_DEV_PANIC(devtypeu, devtypel, instance) \
259 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
262 #define BOOTENV_DEV_NAME_PANIC(devtypeu, devtypel, instance) \
265 #define BOOT_TARGET_DEVICES(func) \
266 func(FASTBOOT, fastboot, na) \
267 func(RECOVERY, recovery, na) \
268 func(SYSTEM, system, na) \
269 func(PANIC, panic, na) \
271 #define PREBOOT_LOAD_LOGO \
272 "if test \"${boot_source}\" != \"usb\" && " \
273 "gpt verify mmc ${mmcdev} ${partitions}; then; " \
274 "mmc dev ${mmcdev};" \
275 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \
276 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \
277 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
278 "bmp display ${loadaddr} m m;" \
282 #define CONFIG_EXTRA_ENV_SETTINGS \
283 EXTRA_ANDROID_ENV_SETTINGS \
284 "partitions=" PARTS_DEFAULT "\0" \
286 "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0" \
287 "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0" \
288 ANDROIDBOOT_GET_CURRENT_SLOT_CMD \
291 "gpio_recovery=88\0" \
292 "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0" \
293 "load_logo=" PREBOOT_LOAD_LOGO "\0" \
294 "stdin=" STDIN_CFG "\0" \
295 "stdout=" STDOUT_CFG "\0" \
296 "stderr=" STDOUT_CFG "\0" \
297 "dtboaddr=0x08200000\0" \
298 "loadaddr=0x01080000\0" \
299 "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" \
304 "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
307 #include <configs/meson64.h>
309 #endif /* __MESON64_ANDROID_CONFIG_H */