blob: 83fa25bfb1f0cedd0fda7762f7beb01699857aef [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
14#define CONFIG_SYS_MALLOC_LEN SZ_128M
15
Mattijs Korpershoek5a4a7102021-07-29 09:21:11 +020016#ifndef BOOT_PARTITION
17#define BOOT_PARTITION "boot"
18#endif
Guillaume La Roque95b488a2019-10-11 17:33:57 +020019
Mattijs Korpershoek4a3ede92021-07-29 09:21:12 +020020#ifndef LOGO_PARTITION
21#define LOGO_PARTITION "logo"
22#endif
23
Mattijs Korpershoekb09908c2021-07-30 14:28:08 +020024#ifndef CONTROL_PARTITION
25#define CONTROL_PARTITION "misc"
26#endif
27
Mattijs Korpershoek94c09882021-08-05 17:17:22 +020028#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
Mattijs Korpershoek8c357212021-08-05 17:17:23 +020042#define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0"
Mattijs Korpershoek94c09882021-08-05 17:17:22 +020043#else
44#define AVB_VERIFY_CHECK ""
45#define AVB_VERIFY_CMD ""
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +020046#endif
47
Mattijs Korpershoek8c357212021-08-05 17:17:23 +020048#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
Guillaume La Roque95b488a2019-10-11 17:33:57 +020084#define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \
85 "bootcmd_fastboot=" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +020086 "setenv run_fastboot 0;" \
87 "if test \"${boot_source}\" = \"usb\"; then " \
88 "echo Fastboot forced by usb rom boot;" \
89 "setenv run_fastboot 1;" \
90 "fi;" \
91 "if gpt verify mmc ${mmcdev} ${partitions}; then; " \
92 "else " \
93 "echo Broken MMC partition scheme;" \
94 "setenv run_fastboot 1;" \
95 "fi;" \
Mattijs Korpershoekb09908c2021-07-30 14:28:08 +020096 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
97 CONTROL_PARTITION "; then " \
98 "if bcb test command = bootonce-bootloader; then " \
99 "echo BCB: Bootloader boot...; " \
100 "bcb clear command; bcb store; " \
101 "setenv run_fastboot 1;" \
102 "fi; " \
Mattijs Korpershoek527ee432021-07-30 14:28:10 +0200103 "if bcb test command = boot-fastboot; then " \
104 "echo BCB: fastboot userspace boot...; " \
105 "setenv force_recovery 1;" \
106 "fi; " \
Mattijs Korpershoekb09908c2021-07-30 14:28:08 +0200107 "else " \
108 "echo Warning: BCB is corrupted or does not exist; " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200109 "fi;" \
110 "if test \"${run_fastboot}\" -eq 1; then " \
111 "echo Running Fastboot...;" \
Mattijs Korpershoekb0a88af2021-07-29 09:21:10 +0200112 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200113 "fi\0"
114
115#define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \
116 "fastboot "
117
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200118#define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \
119 "bootcmd_recovery=" \
120 "pinmux dev pinctrl@14;" \
121 "pinmux dev pinctrl@40;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200122 "setenv run_recovery 0;" \
123 "if run check_button; then " \
124 "echo Recovery button is pressed;" \
125 "setenv run_recovery 1;" \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200126 "fi; " \
127 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
128 CONTROL_PARTITION "; then " \
129 "if bcb test command = boot-recovery; then " \
130 "echo BCB: Recovery boot...; " \
131 "setenv run_recovery 1;" \
132 "fi;" \
133 "else " \
134 "echo Warning: BCB is corrupted or does not exist; " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200135 "fi;" \
136 "if test \"${skip_recovery}\" -eq 1; then " \
137 "echo Recovery skipped by environment;" \
138 "setenv run_recovery 0;" \
139 "fi;" \
140 "if test \"${force_recovery}\" -eq 1; then " \
141 "echo Recovery forced by environment;" \
142 "setenv run_recovery 1;" \
143 "fi;" \
144 "if test \"${run_recovery}\" -eq 1; then " \
145 "echo Running Recovery...;" \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200146 "mmc dev ${mmcdev};" \
147 "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200148 AB_SELECT_SLOT \
149 AB_SELECT_ARGS \
Mattijs Korpershoek94c09882021-08-05 17:17:22 +0200150 AVB_VERIFY_CHECK \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200151 "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \
152 "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \
Mattijs Korpershoekdfe12082021-07-30 14:28:09 +0200153 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
154 "echo Running Android Recovery...;" \
155 "bootm ${loadaddr};" \
156 "fi;" \
157 "echo Failed to boot Android...;" \
158 "reset;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200159 "fi\0"
160
161#define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \
162 "recovery "
163
164#define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \
165 "bootcmd_system=" \
Mattijs Korpershoek5a4a7102021-07-29 09:21:11 +0200166 "echo Loading Android " BOOT_PARTITION " partition...;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200167 "mmc dev ${mmcdev};" \
Mattijs Korpershoek6f51aa22021-07-29 09:21:13 +0200168 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200169 AB_SELECT_SLOT \
170 AB_SELECT_ARGS \
Mattijs Korpershoek94c09882021-08-05 17:17:22 +0200171 AVB_VERIFY_CHECK \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200172 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \
173 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200174 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200175 "setenv bootargs \"${bootargs} " AB_BOOTARGS "\" ; " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200176 "echo Running Android...;" \
177 "bootm ${loadaddr};" \
178 "fi;" \
179 "echo Failed to boot Android...;" \
180 "reset\0"
181
182#define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance) \
183 "system "
184
185#define BOOT_TARGET_DEVICES(func) \
186 func(FASTBOOT, fastboot, na) \
187 func(RECOVERY, recovery, na) \
188 func(SYSTEM, system, na) \
189
190#define PREBOOT_LOAD_LOGO \
Guillaume La Roqueb7162fa2020-10-30 16:03:44 +0100191 "if test \"${boot_source}\" != \"usb\" && " \
192 "gpt verify mmc ${mmcdev} ${partitions}; then; " \
193 "mmc dev ${mmcdev};" \
Mattijs Korpershoek4a3ede92021-07-29 09:21:12 +0200194 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \
195 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \
Guillaume La Roqueb7162fa2020-10-30 16:03:44 +0100196 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200197 "bmp display ${loadaddr} m m;" \
Guillaume La Roqueb7162fa2020-10-30 16:03:44 +0100198 "fi;" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200199 "fi;"
200
201#define CONFIG_EXTRA_ENV_SETTINGS \
202 "partitions=" PARTS_DEFAULT "\0" \
203 "mmcdev=2\0" \
Mattijs Korpershoek8c357212021-08-05 17:17:23 +0200204 ANDROIDBOOT_GET_CURRENT_SLOT_CMD \
Mattijs Korpershoek94c09882021-08-05 17:17:22 +0200205 AVB_VERIFY_CMD \
206 "force_avb=0\0" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200207 "gpio_recovery=88\0" \
208 "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0" \
209 "load_logo=" PREBOOT_LOAD_LOGO "\0" \
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200210 "stdin=" STDIN_CFG "\0" \
211 "stdout=" STDOUT_CFG "\0" \
212 "stderr=" STDOUT_CFG "\0" \
213 "loadaddr=0x01000000\0" \
214 "fdt_addr_r=0x01000000\0" \
215 "scriptaddr=0x08000000\0" \
216 "kernel_addr_r=0x01080000\0" \
217 "pxefile_addr_r=0x01080000\0" \
218 "ramdisk_addr_r=0x13000000\0" \
Mattijs Korpershoek4d73d352021-07-29 09:21:09 +0200219 "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \
220 BOOTENV
Guillaume La Roque95b488a2019-10-11 17:33:57 +0200221
222#include <configs/meson64.h>
223
224#endif /* __MESON64_ANDROID_CONFIG_H */