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