Guillaume La Roque | 880c0aa | 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 | 285a83b | 2021-08-05 17:17:21 +0200 | [diff] [blame] | 12 | #include <linux/sizes.h> |
| 13 | |
Mattijs Korpershoek | f2cd648 | 2021-07-29 09:21:11 +0200 | [diff] [blame] | 14 | #ifndef BOOT_PARTITION |
| 15 | #define BOOT_PARTITION "boot" |
| 16 | #endif |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 17 | |
Mattijs Korpershoek | 211f1d9 | 2021-07-29 09:21:12 +0200 | [diff] [blame] | 18 | #ifndef LOGO_PARTITION |
| 19 | #define LOGO_PARTITION "logo" |
| 20 | #endif |
| 21 | |
Mattijs Korpershoek | 9d0ac61 | 2021-07-30 14:28:08 +0200 | [diff] [blame] | 22 | #ifndef CONTROL_PARTITION |
| 23 | #define CONTROL_PARTITION "misc" |
| 24 | #endif |
| 25 | |
Mattijs Korpershoek | 4eff742 | 2021-11-22 16:22:04 +0100 | [diff] [blame] | 26 | #ifndef EXTRA_ANDROID_ENV_SETTINGS |
| 27 | #define EXTRA_ANDROID_ENV_SETTINGS "" |
| 28 | #endif |
| 29 | |
Mattijs Korpershoek | e6c782b | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 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\";" \ |
| 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 Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 44 | #define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0" |
Mattijs Korpershoek | e6c782b | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 45 | #else |
| 46 | #define AVB_VERIFY_CHECK "" |
| 47 | #define AVB_VERIFY_CMD "" |
Mattijs Korpershoek | 72d7c03 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 48 | #endif |
| 49 | |
Mattijs Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 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; " \ |
| 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 Roque | 72cefba | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 86 | #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 Korpershoek | f89b90d | 2021-11-22 16:22:05 +0100 | [diff] [blame] | 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;" \ |
Guillaume La Roque | 72cefba | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 113 | "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 Korpershoek | 0b063d6 | 2024-10-11 17:51:03 +0200 | [diff] [blame^] | 119 | "fdt addr $fdt_addr_r 0x80000; " |
Guillaume La Roque | 72cefba | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 120 | |
| 121 | #define BOOT_CMD "bootm ${loadaddr} ${loadaddr} ${fdt_addr_r};" |
| 122 | |
| 123 | #else |
| 124 | #define PREPARE_FDT " " |
Mattijs Korpershoek | 7039cbd | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 125 | #define BOOT_CMD "bootm ${loadaddr};" |
Guillaume La Roque | 72cefba | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 126 | #endif |
Mattijs Korpershoek | 7039cbd | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 127 | |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 128 | #define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \ |
| 129 | "bootcmd_fastboot=" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 130 | "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 Armstrong | bdc68df | 2021-11-17 12:04:10 +0100 | [diff] [blame] | 135 | "if test \"${run_fastboot}\" -eq 0; then " \ |
| 136 | "if gpt verify mmc ${mmcdev} ${partitions}; then; " \ |
| 137 | "else " \ |
| 138 | "echo Broken MMC partition scheme;" \ |
Mattijs Korpershoek | 9d0ac61 | 2021-07-30 14:28:08 +0200 | [diff] [blame] | 139 | "setenv run_fastboot 1;" \ |
| 140 | "fi; " \ |
Neil Armstrong | bdc68df | 2021-11-17 12:04:10 +0100 | [diff] [blame] | 141 | "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 Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 156 | "fi;" \ |
| 157 | "if test \"${run_fastboot}\" -eq 1; then " \ |
| 158 | "echo Running Fastboot...;" \ |
Mattijs Korpershoek | 75be1eb | 2021-07-29 09:21:10 +0200 | [diff] [blame] | 159 | "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 160 | "fi\0" |
| 161 | |
| 162 | #define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \ |
| 163 | "fastboot " |
| 164 | |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 165 | #define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \ |
| 166 | "bootcmd_recovery=" \ |
| 167 | "pinmux dev pinctrl@14;" \ |
| 168 | "pinmux dev pinctrl@40;" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 169 | "setenv run_recovery 0;" \ |
| 170 | "if run check_button; then " \ |
| 171 | "echo Recovery button is pressed;" \ |
| 172 | "setenv run_recovery 1;" \ |
Mattijs Korpershoek | 72d7c03 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 173 | "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 Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 182 | "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 Korpershoek | 72d7c03 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 193 | "mmc dev ${mmcdev};" \ |
| 194 | "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \ |
Mattijs Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 195 | AB_SELECT_SLOT \ |
| 196 | AB_SELECT_ARGS \ |
Mattijs Korpershoek | e6c782b | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 197 | AVB_VERIFY_CHECK \ |
Mattijs Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 198 | "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \ |
| 199 | "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \ |
Mattijs Korpershoek | 72d7c03 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 200 | "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ |
Guillaume La Roque | 72cefba | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 201 | PREPARE_FDT \ |
Mattijs Korpershoek | 72d7c03 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 202 | "echo Running Android Recovery...;" \ |
Mattijs Korpershoek | 7039cbd | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 203 | BOOT_CMD \ |
Mattijs Korpershoek | 72d7c03 | 2021-07-30 14:28:09 +0200 | [diff] [blame] | 204 | "fi;" \ |
| 205 | "echo Failed to boot Android...;" \ |
| 206 | "reset;" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 207 | "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 Korpershoek | f2cd648 | 2021-07-29 09:21:11 +0200 | [diff] [blame] | 214 | "echo Loading Android " BOOT_PARTITION " partition...;" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 215 | "mmc dev ${mmcdev};" \ |
Mattijs Korpershoek | 143e153 | 2021-07-29 09:21:13 +0200 | [diff] [blame] | 216 | "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \ |
Mattijs Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 217 | AB_SELECT_SLOT \ |
| 218 | AB_SELECT_ARGS \ |
Mattijs Korpershoek | e6c782b | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 219 | AVB_VERIFY_CHECK \ |
Mattijs Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 220 | "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \ |
| 221 | "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 222 | "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ |
Guillaume La Roque | 72cefba | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 223 | PREPARE_FDT \ |
Mattijs Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 224 | "setenv bootargs \"${bootargs} " AB_BOOTARGS "\" ; " \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 225 | "echo Running Android...;" \ |
Mattijs Korpershoek | 7039cbd | 2021-08-05 17:17:24 +0200 | [diff] [blame] | 226 | BOOT_CMD \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 227 | "fi;" \ |
Neil Armstrong | 28f70cf | 2021-11-17 12:04:11 +0100 | [diff] [blame] | 228 | "echo Failed to boot Android...;\0" |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 229 | |
| 230 | #define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance) \ |
| 231 | "system " |
| 232 | |
Neil Armstrong | 28f70cf | 2021-11-17 12:04:11 +0100 | [diff] [blame] | 233 | #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 Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 241 | #define BOOT_TARGET_DEVICES(func) \ |
| 242 | func(FASTBOOT, fastboot, na) \ |
| 243 | func(RECOVERY, recovery, na) \ |
| 244 | func(SYSTEM, system, na) \ |
Neil Armstrong | 28f70cf | 2021-11-17 12:04:11 +0100 | [diff] [blame] | 245 | func(PANIC, panic, na) \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 246 | |
| 247 | #define PREBOOT_LOAD_LOGO \ |
Guillaume La Roque | 82f6508 | 2020-10-30 16:03:44 +0100 | [diff] [blame] | 248 | "if test \"${boot_source}\" != \"usb\" && " \ |
| 249 | "gpt verify mmc ${mmcdev} ${partitions}; then; " \ |
| 250 | "mmc dev ${mmcdev};" \ |
Mattijs Korpershoek | 211f1d9 | 2021-07-29 09:21:12 +0200 | [diff] [blame] | 251 | "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \ |
| 252 | "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \ |
Guillaume La Roque | 82f6508 | 2020-10-30 16:03:44 +0100 | [diff] [blame] | 253 | "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 254 | "bmp display ${loadaddr} m m;" \ |
Guillaume La Roque | 82f6508 | 2020-10-30 16:03:44 +0100 | [diff] [blame] | 255 | "fi;" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 256 | "fi;" |
| 257 | |
Tom Rini | 0613c36 | 2022-12-04 10:03:50 -0500 | [diff] [blame] | 258 | #define CFG_EXTRA_ENV_SETTINGS \ |
Mattijs Korpershoek | 4eff742 | 2021-11-22 16:22:04 +0100 | [diff] [blame] | 259 | EXTRA_ANDROID_ENV_SETTINGS \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 260 | "partitions=" PARTS_DEFAULT "\0" \ |
| 261 | "mmcdev=2\0" \ |
Mattijs Korpershoek | b749d5e | 2022-01-07 17:39:13 +0100 | [diff] [blame] | 262 | "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0" \ |
| 263 | "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0" \ |
Mattijs Korpershoek | efc28f6 | 2021-08-05 17:17:23 +0200 | [diff] [blame] | 264 | ANDROIDBOOT_GET_CURRENT_SLOT_CMD \ |
Mattijs Korpershoek | e6c782b | 2021-08-05 17:17:22 +0200 | [diff] [blame] | 265 | AVB_VERIFY_CMD \ |
| 266 | "force_avb=0\0" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 267 | "gpio_recovery=88\0" \ |
| 268 | "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0" \ |
| 269 | "load_logo=" PREBOOT_LOAD_LOGO "\0" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 270 | "stdin=" STDIN_CFG "\0" \ |
| 271 | "stdout=" STDOUT_CFG "\0" \ |
| 272 | "stderr=" STDOUT_CFG "\0" \ |
Guillaume La Roque | 72cefba | 2021-08-05 17:17:25 +0200 | [diff] [blame] | 273 | "dtboaddr=0x08200000\0" \ |
| 274 | "loadaddr=0x01080000\0" \ |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 275 | "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 Korpershoek | d1af9aa | 2021-07-29 09:21:09 +0200 | [diff] [blame] | 280 | "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \ |
| 281 | BOOTENV |
Guillaume La Roque | 880c0aa | 2019-10-11 17:33:57 +0200 | [diff] [blame] | 282 | |
| 283 | #include <configs/meson64.h> |
| 284 | |
| 285 | #endif /* __MESON64_ANDROID_CONFIG_H */ |