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 12 #include <linux/sizes.h> 13 14 #ifndef BOOT_PARTITION 15 #define BOOT_PARTITION "boot" 16 #endif 17 18 #ifndef LOGO_PARTITION 19 #define LOGO_PARTITION "logo" 20 #endif 21 22 #ifndef CONTROL_PARTITION 23 #define CONTROL_PARTITION "misc" 24 #endif 25 26 #ifndef EXTRA_ANDROID_ENV_SETTINGS 27 #define EXTRA_ANDROID_ENV_SETTINGS "" 28 #endif 29 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 44 #define AVB_VERIFY_CMD "avb_verify=avb init ${mmcdev}; avb verify $slot_suffix;\0" 45 #else 46 #define AVB_VERIFY_CHECK "" 47 #define AVB_VERIFY_CMD "" 48 #endif 49 50 #if defined(CONFIG_CMD_BCB) && defined(CONFIG_ANDROID_AB) 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 "bcb 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 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;" \ 107 "else " \ 108 "echo Error: Android boot is not supported for $board_name; " \ 109 "exit; " \ 110 "fi; " \ 111 "abootimg get dtb --index=$dtb_index dtb_start dtb_size; " \ 112 "cp.b $dtb_start $fdt_addr_r $dtb_size; " \ 113 "fdt addr $fdt_addr_r 0x80000; " 114 115 #define BOOT_CMD "bootm ${loadaddr} ${loadaddr} ${fdt_addr_r};" 116 117 #else 118 #define PREPARE_FDT " " 119 #define BOOT_CMD "bootm ${loadaddr};" 120 #endif 121 122 #define BOOTENV_DEV_FASTBOOT(devtypeu, devtypel, instance) \ 123 "bootcmd_fastboot=" \ 124 "setenv run_fastboot 0;" \ 125 "if test \"${boot_source}\" = \"usb\"; then " \ 126 "echo Fastboot forced by usb rom boot;" \ 127 "setenv run_fastboot 1;" \ 128 "fi;" \ 129 "if test \"${run_fastboot}\" -eq 0; then " \ 130 "if gpt verify mmc ${mmcdev} ${partitions}; then; " \ 131 "else " \ 132 "echo Broken MMC partition scheme;" \ 133 "setenv run_fastboot 1;" \ 134 "fi; " \ 135 "fi;" \ 136 "if test \"${run_fastboot}\" -eq 0; then " \ 137 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \ 138 CONTROL_PARTITION "; then " \ 139 "if bcb test command = bootonce-bootloader; then " \ 140 "echo BCB: Bootloader boot...; " \ 141 "bcb clear command; bcb store; " \ 142 "setenv run_fastboot 1;" \ 143 "elif bcb test command = boot-fastboot; then " \ 144 "echo BCB: fastboot userspace boot...; " \ 145 "setenv force_recovery 1;" \ 146 "fi; " \ 147 "else " \ 148 "echo Warning: BCB is corrupted or does not exist; " \ 149 "fi;" \ 150 "fi;" \ 151 "if test \"${run_fastboot}\" -eq 1; then " \ 152 "echo Running Fastboot...;" \ 153 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \ 154 "fi\0" 155 156 #define BOOTENV_DEV_NAME_FASTBOOT(devtypeu, devtypel, instance) \ 157 "fastboot " 158 159 #define BOOTENV_DEV_RECOVERY(devtypeu, devtypel, instance) \ 160 "bootcmd_recovery=" \ 161 "pinmux dev pinctrl@14;" \ 162 "pinmux dev pinctrl@40;" \ 163 "setenv run_recovery 0;" \ 164 "if run check_button; then " \ 165 "echo Recovery button is pressed;" \ 166 "setenv run_recovery 1;" \ 167 "fi; " \ 168 "if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \ 169 CONTROL_PARTITION "; then " \ 170 "if bcb test command = boot-recovery; then " \ 171 "echo BCB: Recovery boot...; " \ 172 "setenv run_recovery 1;" \ 173 "fi;" \ 174 "else " \ 175 "echo Warning: BCB is corrupted or does not exist; " \ 176 "fi;" \ 177 "if test \"${skip_recovery}\" -eq 1; then " \ 178 "echo Recovery skipped by environment;" \ 179 "setenv run_recovery 0;" \ 180 "fi;" \ 181 "if test \"${force_recovery}\" -eq 1; then " \ 182 "echo Recovery forced by environment;" \ 183 "setenv run_recovery 1;" \ 184 "fi;" \ 185 "if test \"${run_recovery}\" -eq 1; then " \ 186 "echo Running Recovery...;" \ 187 "mmc dev ${mmcdev};" \ 188 "setenv bootargs \"${bootargs} androidboot.serialno=${serial#}\";" \ 189 AB_SELECT_SLOT \ 190 AB_SELECT_ARGS \ 191 AVB_VERIFY_CHECK \ 192 "part start mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_start;" \ 193 "part size mmc ${mmcdev} " RECOVERY_PARTITION "${slot_suffix} boot_size;" \ 194 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ 195 PREPARE_FDT \ 196 "echo Running Android Recovery...;" \ 197 BOOT_CMD \ 198 "fi;" \ 199 "echo Failed to boot Android...;" \ 200 "reset;" \ 201 "fi\0" 202 203 #define BOOTENV_DEV_NAME_RECOVERY(devtypeu, devtypel, instance) \ 204 "recovery " 205 206 #define BOOTENV_DEV_SYSTEM(devtypeu, devtypel, instance) \ 207 "bootcmd_system=" \ 208 "echo Loading Android " BOOT_PARTITION " partition...;" \ 209 "mmc dev ${mmcdev};" \ 210 "setenv bootargs ${bootargs} androidboot.serialno=${serial#};" \ 211 AB_SELECT_SLOT \ 212 AB_SELECT_ARGS \ 213 AVB_VERIFY_CHECK \ 214 "part start mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_start;" \ 215 "part size mmc ${mmcdev} " BOOT_PARTITION "${slot_suffix} boot_size;" \ 216 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ 217 PREPARE_FDT \ 218 "setenv bootargs \"${bootargs} " AB_BOOTARGS "\" ; " \ 219 "echo Running Android...;" \ 220 BOOT_CMD \ 221 "fi;" \ 222 "echo Failed to boot Android...;\0" 223 224 #define BOOTENV_DEV_NAME_SYSTEM(devtypeu, devtypel, instance) \ 225 "system " 226 227 #define BOOTENV_DEV_PANIC(devtypeu, devtypel, instance) \ 228 "bootcmd_panic=" \ 229 "fastboot " __stringify(CONFIG_FASTBOOT_USB_DEV) "; " \ 230 "reset\0" 231 232 #define BOOTENV_DEV_NAME_PANIC(devtypeu, devtypel, instance) \ 233 "panic " 234 235 #define BOOT_TARGET_DEVICES(func) \ 236 func(FASTBOOT, fastboot, na) \ 237 func(RECOVERY, recovery, na) \ 238 func(SYSTEM, system, na) \ 239 func(PANIC, panic, na) \ 240 241 #define PREBOOT_LOAD_LOGO \ 242 "if test \"${boot_source}\" != \"usb\" && " \ 243 "gpt verify mmc ${mmcdev} ${partitions}; then; " \ 244 "mmc dev ${mmcdev};" \ 245 "part start mmc ${mmcdev} " LOGO_PARTITION " boot_start;" \ 246 "part size mmc ${mmcdev} " LOGO_PARTITION " boot_size;" \ 247 "if mmc read ${loadaddr} ${boot_start} ${boot_size}; then " \ 248 "bmp display ${loadaddr} m m;" \ 249 "fi;" \ 250 "fi;" 251 252 #define CFG_EXTRA_ENV_SETTINGS \ 253 EXTRA_ANDROID_ENV_SETTINGS \ 254 "partitions=" PARTS_DEFAULT "\0" \ 255 "mmcdev=2\0" \ 256 "fastboot_raw_partition_bootloader=0x1 0xfff mmcpart 1\0" \ 257 "fastboot_raw_partition_bootenv=0x0 0xfff mmcpart 2\0" \ 258 ANDROIDBOOT_GET_CURRENT_SLOT_CMD \ 259 AVB_VERIFY_CMD \ 260 "force_avb=0\0" \ 261 "gpio_recovery=88\0" \ 262 "check_button=gpio input ${gpio_recovery};test $? -eq 0;\0" \ 263 "load_logo=" PREBOOT_LOAD_LOGO "\0" \ 264 "stdin=" STDIN_CFG "\0" \ 265 "stdout=" STDOUT_CFG "\0" \ 266 "stderr=" STDOUT_CFG "\0" \ 267 "dtboaddr=0x08200000\0" \ 268 "loadaddr=0x01080000\0" \ 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" \ 274 "fdtfile=amlogic/" CONFIG_DEFAULT_DEVICE_TREE ".dtb\0" \ 275 BOOTENV 276 277 #include <configs/meson64.h> 278 279 #endif /* __MESON64_ANDROID_CONFIG_H */ 280