meson64_android.h 9.2 KB

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