1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * (C) Copyright 2013
4  * Texas Instruments Incorporated.
5  * Sricharan R	  <r.sricharan@ti.com>
6  *
7  * Derived from OMAP4 done by:
8  *	Aneesh V <aneesh@ti.com>
9  *
10  * TI OMAP5 AND DRA7XX common configuration settings
11  *
12  * For more details, please see the technical documents listed at
13  * https://www.ti.com/product/omap5432
14  */
15 
16 #ifndef __CONFIG_TI_OMAP5_COMMON_H
17 #define __CONFIG_TI_OMAP5_COMMON_H
18 
19 /* Use General purpose timer 1 */
20 #define CFG_SYS_TIMERBASE		GPT2_BASE
21 
22 #include <linux/stringify.h>
23 
24 #include <asm/arch/cpu.h>
25 #include <asm/arch/omap.h>
26 
27 #include <configs/ti_armv7_omap.h>
28 
29 /*
30  * Hardware drivers
31  */
32 #define CFG_SYS_NS16550_CLK		48000000
33 
34 /*
35  * Environment setup
36  */
37 
38 #ifndef DFUARGS
39 #define DFUARGS
40 #endif
41 
42 #include <env/ti/mmc.h>
43 #include <env/ti/nand.h>
44 
45 #ifndef CONSOLEDEV
46 #define CONSOLEDEV "ttyS2"
47 #endif
48 
49 #ifndef PARTS_DEFAULT
50 /*
51  * Default GPT tables for eMMC (Linux and Android). Notes:
52  *   1. Keep partitions aligned to erase group size (512 KiB) when possible
53  *   2. Keep partitions in sync with DFU_ALT_INFO_EMMC (see dfu.h)
54  *   3. Keep 'bootloader' partition (U-Boot proper) start address in sync with
55  *      CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR (see common/spl/Kconfig)
56  */
57 #define PARTS_DEFAULT \
58 	/* Linux partitions */ \
59 	"uuid_disk=${uuid_gpt_disk};" \
60 	"name=bootloader,start=384K,size=1792K,uuid=${uuid_gpt_bootloader};" \
61 	"name=rootfs,start=2688K,size=-,uuid=${uuid_gpt_rootfs}\0" \
62 	/* Android partitions */ \
63 	"partitions_android=" \
64 	"uuid_disk=${uuid_gpt_disk};" \
65 	"name=xloader,start=128K,size=256K,uuid=${uuid_gpt_xloader};" \
66 	"name=bootloader,size=2048K,uuid=${uuid_gpt_bootloader};" \
67 	"name=uboot-env,start=2432K,size=256K,uuid=${uuid_gpt_reserved};" \
68 	"name=misc,size=128K,uuid=${uuid_gpt_misc};" \
69 	"name=boot_a,size=20M,uuid=${uuid_gpt_boot_a};" \
70 	"name=boot_b,size=20M,uuid=${uuid_gpt_boot_b};" \
71 	"name=dtbo_a,size=8M,uuid=${uuid_gpt_dtbo_a};" \
72 	"name=dtbo_b,size=8M,uuid=${uuid_gpt_dtbo_b};" \
73 	"name=vbmeta_a,size=64K,uuid=${uuid_gpt_vbmeta_a};" \
74 	"name=vbmeta_b,size=64K,uuid=${uuid_gpt_vbmeta_b};" \
75 	"name=recovery,size=64M,uuid=${uuid_gpt_recovery};" \
76 	"name=super,size=2560M,uuid=${uuid_gpt_super};" \
77 	"name=metadata,size=16M,uuid=${uuid_gpt_metadata};" \
78 	"name=userdata,size=-,uuid=${uuid_gpt_userdata}"
79 #endif /* PARTS_DEFAULT */
80 
81 #if defined(CONFIG_CMD_AVB)
82 #define AVB_VERIFY_CHECK "if run avb_verify; then " \
83 				"echo AVB verification OK.;" \
84 				"set bootargs $bootargs $avb_bootargs;" \
85 			"else " \
86 				"echo AVB verification failed.;" \
87 			"exit; fi;"
88 #define AVB_VERIFY_CMD "avb_verify=avb init 1; avb verify $slot_suffix;\0"
89 #else
90 #define AVB_VERIFY_CHECK ""
91 #define AVB_VERIFY_CMD ""
92 #endif
93 
94 #define CONTROL_PARTITION "misc"
95 
96 #if defined(CONFIG_CMD_BCB) && defined(CONFIG_ANDROID_AB)
97 #define AB_SELECT_SLOT \
98 	"if part number mmc 1 " CONTROL_PARTITION " control_part_number; " \
99 	"then " \
100 		"echo " CONTROL_PARTITION \
101 			" partition number:${control_part_number};" \
102 		"bcb ab_select slot_name mmc ${mmcdev}:${control_part_number};" \
103 	"else " \
104 		"echo " CONTROL_PARTITION " partition not found;" \
105 		"exit;" \
106 	"fi;" \
107 	"setenv slot_suffix _${slot_name};"
108 #define AB_SELECT_ARGS \
109 	"setenv bootargs_ab androidboot.slot_suffix=${slot_suffix}; " \
110 	"echo A/B cmdline addition: ${bootargs_ab};" \
111 	"setenv bootargs ${bootargs} ${bootargs_ab};"
112 #else
113 #define AB_SELECT_SLOT ""
114 #define AB_SELECT_ARGS ""
115 #endif
116 
117 /*
118  * Prepares complete device tree blob for current board (for Android boot).
119  *
120  * Boot image or recovery image should be loaded into $loadaddr prior to running
121  * these commands. The logic of these commnads is next:
122  *
123  *   1. Read correct DTB for current SoC/board from boot image in $loadaddr
124  *      to $fdtaddr
125  *   2. Merge all needed DTBO for current board from 'dtbo' partition into read
126  *      DTB
127  *   3. User should provide $fdtaddr as 3rd argument to 'bootm'
128  */
129 #define PREPARE_FDT \
130 	"echo Preparing FDT...; " \
131 	"if test $board_name = am57xx_evm_reva3; then " \
132 		"echo \"  Reading DTBO partition...\"; " \
133 		"part start mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_start; " \
134 		"part size mmc ${mmcdev} dtbo${slot_suffix} p_dtbo_size; " \
135 		"mmc read ${dtboaddr} ${p_dtbo_start} ${p_dtbo_size}; " \
136 		"echo \"  Reading DTB for AM57x EVM RevA3...\"; " \
137 		"abootimg get dtb --index=0 dtb_start dtb_size; " \
138 		"cp.b $dtb_start $fdtaddr $dtb_size; " \
139 		"fdt addr $fdtaddr 0x80000; " \
140 		"echo \"  Applying DTBOs for AM57x EVM RevA3...\"; " \
141 		"adtimg addr $dtboaddr; " \
142 		"adtimg get dt --index=0 dtbo0_addr dtbo0_size; " \
143 		"fdt apply $dtbo0_addr; " \
144 		"adtimg get dt --index=1 dtbo1_addr dtbo1_size; " \
145 		"fdt apply $dtbo1_addr; " \
146 	"elif test $board_name = beagle_x15_revc; then " \
147 		"echo \"  Reading DTB for Beagle X15 RevC...\"; " \
148 		"abootimg get dtb --index=0 dtb_start dtb_size; " \
149 		"cp.b $dtb_start $fdtaddr $dtb_size; " \
150 		"fdt addr $fdtaddr 0x80000; " \
151 	"else " \
152 		"echo Error: Android boot is not supported for $board_name; " \
153 		"exit; " \
154 	"fi; " \
155 
156 #define DEFAULT_COMMON_BOOT_TI_ARGS \
157 	"console=" CONSOLEDEV ",115200n8\0" \
158 	"fdtfile=undefined\0" \
159 	"finduuid=part uuid mmc 0:2 uuid\0" \
160 	"usbtty=cdc_acm\0" \
161 	"vram=16M\0" \
162 	AVB_VERIFY_CMD \
163 	"partitions=" PARTS_DEFAULT "\0" \
164 	"optargs=\0" \
165 	"dofastboot=0\0" \
166 	"emmc_android_boot=" \
167 		"setenv mmcdev 1; " \
168 		"mmc dev $mmcdev; " \
169 		"mmc rescan; " \
170 		AB_SELECT_SLOT \
171 		"if bcb load " __stringify(CONFIG_FASTBOOT_FLASH_MMC_DEV) " " \
172 		CONTROL_PARTITION "; then " \
173 			"setenv ardaddr -; " \
174 			"if bcb test command = bootonce-bootloader; then " \
175 				"echo Android: Bootloader boot...; " \
176 				"bcb clear command; bcb store; " \
177 				"fastboot 1; " \
178 				"exit; " \
179 			"elif bcb test command = boot-recovery; then " \
180 				"echo Android: Recovery boot...; " \
181 				"setenv ardaddr $loadaddr;" \
182 				"setenv apart recovery; " \
183 			"else " \
184 				"echo Android: Normal boot...; " \
185 				"setenv ardaddr $loadaddr; " \
186 				"setenv apart boot${slot_suffix}; " \
187 			"fi; " \
188 		"else " \
189 			"echo Warning: BCB is corrupted or does not exist; " \
190 			"echo Android: Normal boot...; " \
191 		"fi; " \
192 		"setenv eval_bootargs setenv bootargs $bootargs; " \
193 		"run eval_bootargs; " \
194 		"setenv machid fe6; " \
195 		AVB_VERIFY_CHECK \
196 		AB_SELECT_ARGS \
197 		"if part start mmc $mmcdev $apart boot_start; then " \
198 			"part size mmc $mmcdev $apart boot_size; " \
199 			"mmc read $loadaddr $boot_start $boot_size; " \
200 			PREPARE_FDT \
201 			"bootm $loadaddr $ardaddr $fdtaddr; " \
202 		"else " \
203 			"echo $apart partition not found; " \
204 			"exit; " \
205 		"fi;\0"
206 
207 #define DEFAULT_FDT_TI_ARGS \
208 	"findfdt="\
209 		"if test $board_name = omap5_uevm; then " \
210 			"setenv fdtfile omap5-uevm.dtb; fi; " \
211 		"if test $board_name = dra7xx; then " \
212 			"setenv fdtfile dra7-evm.dtb; fi;" \
213 		"if test $board_name = dra72x-revc; then " \
214 			"setenv fdtfile dra72-evm-revc.dtb; fi;" \
215 		"if test $board_name = dra72x; then " \
216 			"setenv fdtfile dra72-evm.dtb; fi;" \
217 		"if test $board_name = dra71x; then " \
218 			"setenv fdtfile dra71-evm.dtb; fi;" \
219 		"if test $board_name = dra76x_acd; then " \
220 			"setenv fdtfile dra76-evm.dtb; fi;" \
221 		"if test $board_name = beagle_x15; then " \
222 			"setenv fdtfile am57xx-beagle-x15.dtb; fi;" \
223 		"if test $board_name = beagle_x15_revb1; then " \
224 			"setenv fdtfile am57xx-beagle-x15-revb1.dtb; fi;" \
225 		"if test $board_name = beagle_x15_revc; then " \
226 			"setenv fdtfile am57xx-beagle-x15-revc.dtb; fi;" \
227 		"if test $board_name = am5729_beagleboneai; then " \
228 			"setenv fdtfile am5729-beagleboneai.dtb; fi;" \
229 		"if test $board_name = am572x_idk; then " \
230 			"setenv fdtfile am572x-idk.dtb; fi;" \
231 		"if test $board_name = am574x_idk; then " \
232 			"setenv fdtfile am574x-idk.dtb; fi;" \
233 		"if test $board_name = am57xx_evm; then " \
234 			"setenv fdtfile am57xx-beagle-x15.dtb; fi;" \
235 		"if test $board_name = am57xx_evm_reva3; then " \
236 			"setenv fdtfile am57xx-beagle-x15.dtb; fi;" \
237 		"if test $board_name = am571x_idk; then " \
238 			"setenv fdtfile am571x-idk.dtb; fi;" \
239 		"if test $fdtfile = undefined; then " \
240 			"echo WARNING: Could not determine device tree to use; fi; \0"
241 
242 #define GET_OVERLAY_MMC_TI_ARGS \
243 	"get_overlay_mmc=" \
244 		"fdt address ${fdtaddr};" \
245 		"fdt resize 0x100000;" \
246 		"for overlay in $name_overlays;" \
247 		"do;" \
248 			"load mmc ${bootpart} ${dtboaddr} ${bootdir}/dtb/${overlay} &&" \
249 			"fdt apply ${dtboaddr};" \
250 		"done;\0" \
251 
252 #define BOOT_TARGET_DEVICES(func) \
253 	func(TI_MMC, ti_mmc, na) \
254 	func(MMC, mmc, 0) \
255 	func(MMC, mmc, 1) \
256 	func(PXE, pxe, na) \
257 	func(DHCP, dhcp, na)
258 
259 #define BOOTENV_DEV_TI_MMC(devtypeu, devtypel, instance)	\
260 	"bootcmd_ti_mmc= run get_name_kern; run mmcboot\0"
261 
262 #define BOOTENV_DEV_NAME_TI_MMC(devtyeu, devtypel, instance)            \
263 	"ti_mmc "
264 
265 #include <config_distro_bootcmd.h>
266 
267 #define CFG_EXTRA_ENV_SETTINGS \
268 	DEFAULT_LINUX_BOOT_ENV \
269 	DEFAULT_MMC_TI_ARGS \
270 	"bootpart=0:2\0" \
271 	"bootdir=/boot\0" \
272 	"get_name_kern=" \
273 	"if test $boot_fit -eq 1; then " \
274 		"setenv bootfile fitImage; " \
275 	"else " \
276 		"setenv bootfile zImage; " \
277 	"fi\0" \
278 	DEFAULT_FIT_TI_ARGS \
279 	"get_fit_config=setenv name_fit_config ${fdtfile}\0" \
280 	DEFAULT_COMMON_BOOT_TI_ARGS \
281 	DEFAULT_FDT_TI_ARGS \
282 	GET_OVERLAY_MMC_TI_ARGS \
283 	DFUARGS \
284 	NETARGS \
285 	NANDARGS \
286 	BOOTENV
287 
288 /*
289  * SPL related defines.  The Public RAM memory map the ROM defines the
290  * area between 0x40300000 and 0x4031E000 as a download area for OMAP5.
291  * On DRA7xx/AM57XX the download area is between 0x40300000 and 0x4037E000.
292  * We set CONFIG_SPL_DISPLAY_PRINT to have omap_rev_string() called and
293  * print some information.
294  */
295 #ifdef CONFIG_TI_SECURE_DEVICE
296 /*
297  * For memory booting on HS parts, the first 4KB of the internal RAM is
298  * reserved for secure world use and the flash loader image is
299  * preceded by a secure certificate. The SPL will therefore run in internal
300  * RAM from address 0x40301350 (0x40300000+0x1000(reserved)+0x350(cert)).
301  */
302 #define TI_OMAP5_SECURE_BOOT_RESV_SRAM_SZ	0x1000
303 /* If no specific start address is specified then the secure EMIF
304  * region will be placed at the end of the DDR space. In order to prevent
305  * the main u-boot relocation from clobbering that memory and causing a
306  * firewall violation, we tell u-boot that memory is protected RAM (PRAM)
307  */
308 #if (CONFIG_TI_SECURE_EMIF_REGION_START == 0)
309 #define CFG_PRAM (CONFIG_TI_SECURE_EMIF_TOTAL_REGION_SIZE) >> 10
310 #endif
311 #else
312 /*
313  * For all booting on GP parts, the flash loader image is
314  * downloaded into internal RAM at address 0x40300000.
315  */
316 #endif
317 
318 #endif /* __CONFIG_TI_OMAP5_COMMON_H */
319