Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 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 | |
Mattijs Korpershoek | a3ad03f | 2021-08-05 17:17:21 +0200 | [diff] [blame] | 12 | #include <linux/sizes.h> |
| 13 | |
| 14 | #define CONFIG_SYS_MALLOC_LEN SZ_128M |
| 15 | |
Mattijs Korpershoek | 5a4a710 | 2021-07-29 09:21:11 +0200 | [diff] [blame] | 16 | #ifndef BOOT_PARTITION |
| 17 | #define BOOT_PARTITION "boot" |
| 18 | #endif |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 19 | |
Mattijs Korpershoek | 4a3ede9 | 2021-07-29 09:21:12 +0200 | [diff] [blame] | 20 | #ifndef LOGO_PARTITION |
| 21 | #define LOGO_PARTITION "logo" |
| 22 | #endif |
| 23 | |
Mattijs Korpershoek | b09908c | 2021-07-30 14:28:08 +0200 | [diff] [blame] | 24 | #ifndef CONTROL_PARTITION |
| 25 | #define CONTROL_PARTITION "misc" |
| 26 | #endif |
| 27 | |
Mattijs Korpershoek | 94c0988 | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 28 | #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 Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 42 | #define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0" |
Mattijs Korpershoek | 94c0988 | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 43 | #else |
| 44 | #define AVB_VERIFY_CHECK "" |
| 45 | #define AVB_VERIFY_CMD "" |
Mattijs Korpershoek | dfe1208 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 46 | #endif |
| 47 | |
Mattijs Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 48 | #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 Roque | b8ec762 | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 84 | #if defined(CONFIG_CMD_ABOOTIMG) |
| 85 | /* |
| 86 | * Prepares complete device tree blob for current board (for Android boot). |
| 87 | * |
| 88 | * Boot image or recovery image should be loaded into $loadaddr prior to running |
| 89 | * these commands. The logic of these commnads is next: |
| 90 | * |
| 91 | * 1. Read correct DTB for current SoC/board from boot image in $loadaddr |
| 92 | * to $fdtaddr |
| 93 | * 2. Merge all needed DTBO for current board from 'dtbo' partition into read |
| 94 | * DTB |
| 95 | * 3. User should provide $fdtaddr as 3rd argument to 'bootm' |
| 96 | */ |
| 97 | #define PREPARE_FDT \ |
| 98 | "echo Preparing FDT...; " \ |
| 99 | "if test $board_name = sei510; then " \ |
| 100 | "echo \" Reading DTB for sei510...\"; " \ |
| 101 | "setenv dtb_index 0;" \ |
| 102 | "elif test $board_name = sei610; then " \ |
| 103 | "echo \" Reading DTB for sei610...\"; " \ |
| 104 | "setenv dtb_index 1;" \ |
| 105 | "else " \ |
| 106 | "echo Error: Android boot is not supported for $board_name; " \ |
| 107 | "exit; " \ |
| 108 | "fi; " \ |
| 109 | "abootimg get dtb --index=$dtb_index dtb_start dtb_size; " \ |
| 110 | "cp.b $dtb_start $fdt_addr_r $dtb_size; " \ |
| 111 | "fdt addr $fdt_addr_r 0x80000; " \ |
| 112 | "if test $board_name = sei510; then " \ |
| 113 | "echo \" Reading DTBO for sei510...\"; " \ |
| 114 | "setenv dtbo_index 0;" \ |
| 115 | "elif test $board_name = sei610; then " \ |
| 116 | "echo \" Reading DTBO for sei610...\"; " \ |
| 117 | "setenv dtbo_index 1;" \ |
| 118 | "else " \ |
| 119 | "echo Error: Android boot is not supported for $board_name; " \ |
| 120 | "exit; " \ |
| 121 | "fi; " \ |
| 122 | "part start mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_start; " \ |
| 123 | "part size mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_size; " \ |
| 124 | "mmc read ${dtboaddr} ${p_dtbo_start} ${p_dtbo_size}; " \ |
| 125 | "echo \" Applying DTBOs...\"; " \ |
| 126 | "adtimg addr $dtboaddr; " \ |
| 127 | "adtimg get dt --index=$dtbo_index dtbo0_addr; " \ |
| 128 | "fdt apply $dtbo0_addr;" \ |
| 129 | "setenv bootargs \"$bootargs androidboot.dtbo_idx=$dtbo_index \";"\ |
| 130 | |
| 131 | #define BOOT_CMD "bootm ${loadaddr} ${loadaddr} ${fdt_addr_r};" |
| 132 | |
| 133 | #else |
| 134 | #define PREPARE_FDT " " |
Mattijs Korpershoek | 6b414b5 | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 135 | #define BOOT_CMD "bootm ${loadaddr};" |
Guillaume La Roque | b8ec762 | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 136 | #endif |
Mattijs Korpershoek | 6b414b5 | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 137 | |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 138 | #define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \ |
| 139 | "bootcmd_fastboot=" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 140 | "setenv run_fastboot 0;" \ |
| 141 | "if test \"${boot_source}\" = \"usb\"; then " \ |
| 142 | "echo Fastboot forced by usb rom boot;" \ |
| 143 | "setenv run_fastboot 1;" \ |
| 144 | "fi;" \ |
| 145 | "if gpt verify mmc ${mmcdev} ${partitions}; then; " \ |
| 146 | "else " \ |
| 147 | "echo Broken MMC partition scheme;" \ |
| 148 | "setenv run_fastboot 1;" \ |
| 149 | "fi;" \ |
Mattijs Korpershoek | b09908c | 2021-07-30 14:28:08 +0200 | [diff] [blame] | 150 | "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \ |
| 151 | CONTROL_PARTITION "; then " \ |
| 152 | "if bcb test command = bootonce-bootloader; then " \ |
| 153 | "echo BCB: Bootloader boot...; " \ |
| 154 | "bcb clear command; bcb store; " \ |
| 155 | "setenv run_fastboot 1;" \ |
| 156 | "fi; " \ |
Mattijs Korpershoek | 527ee43 | 2021-07-30 14:28:10 +0200 | [diff] [blame] | 157 | "if bcb test command = boot-fastboot; then " \ |
| 158 | "echo BCB: fastboot userspace boot...; " \ |
| 159 | "setenv force_recovery 1;" \ |
| 160 | "fi; " \ |
Mattijs Korpershoek | b09908c | 2021-07-30 14:28:08 +0200 | [diff] [blame] | 161 | "else " \ |
| 162 | "echo Warning: BCB is corrupted or does not exist; " \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 163 | "fi;" \ |
| 164 | "if test \"${run_fastboot}\" -eq 1; then " \ |
| 165 | "echo Running Fastboot...;" \ |
Mattijs Korpershoek | b0a88af | 2021-07-29 09:21:10 +0200 | [diff] [blame] | 166 | "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 167 | "fi\0" |
| 168 | |
| 169 | #define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \ |
| 170 | "fastboot " |
| 171 | |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 172 | #define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \ |
| 173 | "bootcmd_recovery=" \ |
| 174 | "pinmux dev pinctrl@14;" \ |
| 175 | "pinmux dev pinctrl@40;" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 176 | "setenv run_recovery 0;" \ |
| 177 | "if run check_button; then " \ |
| 178 | "echo Recovery button is pressed;" \ |
| 179 | "setenv run_recovery 1;" \ |
Mattijs Korpershoek | dfe1208 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 180 | "fi; " \ |
| 181 | "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \ |
| 182 | CONTROL_PARTITION "; then " \ |
| 183 | "if bcb test command = boot-recovery; then " \ |
| 184 | "echo BCB: Recovery boot...; " \ |
| 185 | "setenv run_recovery 1;" \ |
| 186 | "fi;" \ |
| 187 | "else " \ |
| 188 | "echo Warning: BCB is corrupted or does not exist; " \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 189 | "fi;" \ |
| 190 | "if test \"${skip_recovery}\" -eq 1; then " \ |
| 191 | "echo Recovery skipped by environment;" \ |
| 192 | "setenv run_recovery 0;" \ |
| 193 | "fi;" \ |
| 194 | "if test \"${force_recovery}\" -eq 1; then " \ |
| 195 | "echo Recovery forced by environment;" \ |
| 196 | "setenv run_recovery 1;" \ |
| 197 | "fi;" \ |
| 198 | "if test \"${run_recovery}\" -eq 1; then " \ |
| 199 | "echo Running Recovery...;" \ |
Mattijs Korpershoek | dfe1208 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 200 | "mmc dev ${mmcdev};" \ |
| 201 | "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \ |
Mattijs Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 202 | AB_SELECT_SLOT \ |
| 203 | AB_SELECT_ARGS \ |
Mattijs Korpershoek | 94c0988 | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 204 | AVB_VERIFY_CHECK \ |
Mattijs Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 205 | "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \ |
| 206 | "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \ |
Mattijs Korpershoek | dfe1208 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 207 | "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ |
Guillaume La Roque | b8ec762 | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 208 | PREPARE_FDT \ |
Mattijs Korpershoek | dfe1208 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 209 | "echo Running Android Recovery...;" \ |
Mattijs Korpershoek | 6b414b5 | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 210 | BOOT_CMD \ |
Mattijs Korpershoek | dfe1208 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 211 | "fi;" \ |
| 212 | "echo Failed to boot Android...;" \ |
| 213 | "reset;" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 214 | "fi\0" |
| 215 | |
| 216 | #define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \ |
| 217 | "recovery " |
| 218 | |
| 219 | #define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \ |
| 220 | "bootcmd_system=" \ |
Mattijs Korpershoek | 5a4a710 | 2021-07-29 09:21:11 +0200 | [diff] [blame] | 221 | "echo Loading Android " BOOT_PARTITION " partition...;" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 222 | "mmc dev ${mmcdev};" \ |
Mattijs Korpershoek | 6f51aa2 | 2021-07-29 09:21:13 +0200 | [diff] [blame] | 223 | "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \ |
Mattijs Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 224 | AB_SELECT_SLOT \ |
| 225 | AB_SELECT_ARGS \ |
Mattijs Korpershoek | 94c0988 | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 226 | AVB_VERIFY_CHECK \ |
Mattijs Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 227 | "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \ |
| 228 | "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 229 | "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ |
Guillaume La Roque | b8ec762 | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 230 | PREPARE_FDT \ |
Mattijs Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 231 | "setenv bootargs \"${bootargs} " AB_BOOTARGS "\" ; " \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 232 | "echo Running Android...;" \ |
Mattijs Korpershoek | 6b414b5 | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 233 | BOOT_CMD \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 234 | "fi;" \ |
| 235 | "echo Failed to boot Android...;" \ |
| 236 | "reset\0" |
| 237 | |
| 238 | #define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance) \ |
| 239 | "system " |
| 240 | |
| 241 | #define BOOT_TARGET_DEVICES(func) \ |
| 242 | func(FASTBOOT, fastboot, na) \ |
| 243 | func(RECOVERY, recovery, na) \ |
| 244 | func(SYSTEM, system, na) \ |
| 245 | |
| 246 | #define PREBOOT_LOAD_LOGO \ |
Guillaume La Roque | b7162fa | 2020-10-30 16:03:44 +0100 | [diff] [blame] | 247 | "if test \"${boot_source}\" != \"usb\" && " \ |
| 248 | "gpt verify mmc ${mmcdev} ${partitions}; then; " \ |
| 249 | "mmc dev ${mmcdev};" \ |
Mattijs Korpershoek | 4a3ede9 | 2021-07-29 09:21:12 +0200 | [diff] [blame] | 250 | "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \ |
| 251 | "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \ |
Guillaume La Roque | b7162fa | 2020-10-30 16:03:44 +0100 | [diff] [blame] | 252 | "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 253 | "bmp display ${loadaddr} m m;" \ |
Guillaume La Roque | b7162fa | 2020-10-30 16:03:44 +0100 | [diff] [blame] | 254 | "fi;" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 255 | "fi;" |
| 256 | |
| 257 | #define CONFIG_EXTRA_ENV_SETTINGS \ |
| 258 | "partitions=" PARTS_DEFAULT "\0" \ |
| 259 | "mmcdev=2\0" \ |
Mattijs Korpershoek | 8c35721 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 260 | ANDROIDBOOT_GET_CURRENT_SLOT_CMD \ |
Mattijs Korpershoek | 94c0988 | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 261 | AVB_VERIFY_CMD \ |
| 262 | "force_avb=0\0" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 263 | "gpio_recovery=88\0" \ |
| 264 | "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0" \ |
| 265 | "load_logo=" PREBOOT_LOAD_LOGO "\0" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 266 | "stdin=" STDIN_CFG "\0" \ |
| 267 | "stdout=" STDOUT_CFG "\0" \ |
| 268 | "stderr=" STDOUT_CFG "\0" \ |
Guillaume La Roque | b8ec762 | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 269 | "dtboaddr=0x08200000\0" \ |
| 270 | "loadaddr=0x01080000\0" \ |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 271 | "fdt_addr_r=0x01000000\0" \ |
| 272 | "scriptaddr=0x08000000\0" \ |
| 273 | "kernel_addr_r=0x01080000\0" \ |
| 274 | "pxefile_addr_r=0x01080000\0" \ |
| 275 | "ramdisk_addr_r=0x13000000\0" \ |
Mattijs Korpershoek | 4d73d35 | 2021-07-29 09:21:09 +0200 | [diff] [blame] | 276 | "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \ |
| 277 | BOOTENV |
Guillaume La Roque | 95b488a | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 278 | |
| 279 | #include <configs/meson64.h> |
| 280 | |
| 281 | #endif /* __MESON64_ANDROID_CONFIG_H */ |