1 /*
2  * Copyright (C) 2015 Marek Vasut <marex@denx.de>
3  *
4  * SPDX-License-Identifier:	GPL-2.0+
5  */
6 #ifndef __CONFIG_SAMTEC_VINING_FPGA_H__
7 #define __CONFIG_SAMTEC_VINING_FPGA_H__
8 
9 #include <asm/arch/base_addr_ac5.h>
10 
11 /* U-Boot Commands */
12 #define CONFIG_FAT_WRITE
13 #define CONFIG_HW_WATCHDOG
14 
15 /* Memory configurations */
16 #define PHYS_SDRAM_1_SIZE		0x40000000	/* 1GiB on VINING_FPGA */
17 
18 /* Booting Linux */
19 #define CONFIG_BOOTFILE		"openwrt-socfpga-socfpga_cyclone5_vining_fpga-fit-uImage.itb"
20 #define CONFIG_BOOTARGS		"console=ttyS0," __stringify(CONFIG_BAUDRATE)
21 #define CONFIG_BOOTCOMMAND	"run selboot"
22 #define CONFIG_LOADADDR		0x01000000
23 #define CONFIG_SYS_LOAD_ADDR	CONFIG_LOADADDR
24 
25 /* I2C EEPROM */
26 #ifdef CONFIG_CMD_EEPROM
27 #define CONFIG_SYS_I2C_EEPROM_ADDR		0x50
28 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN		1
29 #define CONFIG_SYS_I2C_EEPROM_BUS		0
30 #define CONFIG_SYS_EEPROM_PAGE_WRITE_BITS	3
31 #define CONFIG_SYS_EEPROM_PAGE_WRITE_DELAY_MS	70
32 #endif
33 
34 /*
35  * Status LEDs:
36  *   0 ... Top Green
37  *   1 ... Top Red
38  *   2 ... Bottom Green
39  *   3 ... Bottom Red
40  */
41 
42 /* Ethernet on SoC (EMAC) */
43 #if defined(CONFIG_CMD_NET)
44 #define CONFIG_BOOTP_SEND_HOSTNAME
45 /* PHY */
46 #define CONFIG_PHY_MICREL
47 #define CONFIG_PHY_MICREL_KSZ9021
48 #endif
49 
50 /* Extra Environment */
51 #define CONFIG_HOSTNAME			socfpga_vining_fpga
52 
53 /*
54  * Active LOW GPIO buttons:
55  * A: GPIO 77 ... the button between USB B and ethernet
56  * B: GPIO 78 ... the button between USB A ports
57  *
58  * The logic:
59  *  if button B is not pressed, boot normal Linux system immediatelly
60  *  if button B is pressed, wait $bootdelay and boot recovery system
61  */
62 #define CONFIG_PREBOOT						\
63 	"setenv hostname vining-${unit_serial} ; "		\
64 	"setenv PS1 \"${unit_ident} (${unit_serial}) => \" ; "	\
65 	"if gpio input 78 ; then "			\
66 		"setenv bootdelay 10 ; "		\
67 		"setenv boottype rcvr ; "		\
68 	"else "						\
69 		"setenv bootdelay 5 ; "			\
70 		"setenv boottype norm ; "		\
71 	"fi"
72 
73 #define CONFIG_EXTRA_ENV_SETTINGS \
74 	"verify=n\0" \
75 	"consdev=ttyS0\0"						\
76 	"baudrate=115200\0"						\
77 	"bootscript=boot.scr\0"						\
78 	"ubimtdnr=5\0"							\
79 	"ubimtd=rootfs\0"						\
80 	"ubipart=ubi0:rootfs\0"						\
81 	"ubisfcs=1\0"		/* Default is flash at CS#1 */		\
82 	"netdev=eth0\0"							\
83 	"hostname=vining_fpga\0"						\
84 	"kernel_addr_r=0x10000000\0"					\
85 	"mtdparts_0=ff705000.spi.0:"					\
86 		"1m(u-boot),"						\
87 		"64k(env1),"						\
88 		"64k(env2),"						\
89 		"256k(samtec1),"					\
90 		"256k(samtec2),"					\
91 		"-(rcvrfs)\0"	/* Recovery */				\
92 	"mtdparts_1=ff705000.spi.1:"					\
93 		"32m(rootfs),"						\
94 		"-(userfs)\0"						\
95 	"update_filename=u-boot-with-spl-dtb.sfp\0"			\
96 	"update_qspi_offset=0x0\0"					\
97 	"update_qspi="		/* Update the QSPI firmware */		\
98 		"if sf probe ; then "					\
99 		"if tftp ${update_filename} ; then "			\
100 		"sf update ${loadaddr} ${update_qspi_offset} ${filesize} ; " \
101 		"fi ; "							\
102 		"fi\0"							\
103 	"fpga_filename=output_file.rbf\0"				\
104 	"load_fpga="		/* Load FPGA bitstream */		\
105 		"if tftp ${fpga_filename} ; then "			\
106 		"fpga load 0 $loadaddr $filesize ; "			\
107 		"bridge enable ; "					\
108 		"fi\0"							\
109 	"addcons="							\
110 		"setenv bootargs ${bootargs} "				\
111 		"console=${consdev},${baudrate}\0"			\
112 	"addip="							\
113 		"setenv bootargs ${bootargs} "				\
114 		"ip=${ipaddr}:${serverip}:${gatewayip}:"		\
115 			"${netmask}:${hostname}:${netdev}:off\0"	\
116 	"addmisc="							\
117 		"setenv bootargs ${bootargs} ${miscargs}\0"		\
118 	"addmtd="							\
119 		"setenv mtdparts \"${mtdparts_0};${mtdparts_1}\" ; "	\
120 		"setenv bootargs ${bootargs} mtdparts=${mtdparts}\0"	\
121 	"addargs=run addcons addmtd addmisc\0"				\
122 	"ubiload="							\
123 		"ubi part ${ubimtd} ; ubifsmount ${ubipart} ; "		\
124 		"ubifsload ${kernel_addr_r} /boot/${bootfile}\0"	\
125 	"netload="							\
126 		"tftp ${kernel_addr_r} ${hostname}/${bootfile}\0"	\
127 	"miscargs=nohlt panic=1\0"					\
128 	"ubiargs="							\
129 		"setenv bootargs ubi.mtd=${ubimtdnr} "			\
130 		"root=${ubipart} rootfstype=ubifs\0"			\
131 	"nfsargs="							\
132 		"setenv bootargs root=/dev/nfs rw "			\
133 			"nfsroot=${serverip}:${rootpath},v3,tcp\0"	\
134 	"ubi_sfsel="							\
135 		"if test \"${boottype}\" = \"rcvr\" ; then "		\
136 			"setenv ubisfcs 0 ; "				\
137 			"setenv ubimtd rcvrfs ; "			\
138 			"setenv ubimtdnr 5 ; "				\
139 			"setenv mtdparts mtdparts=${mtdparts_0} ; "	\
140 			"setenv mtdids nor0=ff705000.spi.0 ; "		\
141 			"setenv ubipart ubi0:rootfs ; "			\
142 		"else "							\
143 			"setenv ubisfcs 1 ; "				\
144 			"setenv ubimtd rootfs ; "			\
145 			"setenv ubimtdnr 6 ; "				\
146 			"setenv mtdparts mtdparts=${mtdparts_1} ; "	\
147 			"setenv mtdids nor0=ff705000.spi.1 ; "		\
148 			"setenv ubipart ubi0:rootfs ; "			\
149 		"fi ; "							\
150 		"sf probe 0:${ubisfcs}\0"				\
151 	"ubi_ubi="							\
152 		"run ubi_sfsel ubiload ubiargs addargs ; "		\
153 		"bootm ${kernel_addr_r}\0"				\
154 	"ubi_nfs="							\
155 		"run ubiload nfsargs addip addargs ; "			\
156 		"bootm ${kernel_addr_r}\0"				\
157 	"net_ubi="							\
158 		"run netload ubiargs addargs ; "			\
159 		"bootm ${kernel_addr_r}\0"				\
160 	"net_nfs="							\
161 		"run netload nfsargs addip addargs ; "			\
162 		"bootm ${kernel_addr_r}\0"				\
163 	"selboot="	/* Select from where to boot. */		\
164 		"if test \"${bootmode}\" = \"qspi\" ; then "		\
165 			"led all off ; "				\
166 			"if test \"${boottype}\" = \"rcvr\" ; then "	\
167 				"echo \"Booting recovery system\" ; "	\
168 				"led 3 on ; "	/* Bottom RED */	\
169 			"fi ; "						\
170 			"led 1 on ; "		/* Top RED */		\
171 			"run ubi_ubi ; "				\
172 		"else echo \"Unsupported boot mode: \"${bootmode} ; "	\
173 		"fi\0"							\
174 
175 #define CONFIG_CMD_UBIFS
176 #define CONFIG_RBTREE
177 #define CONFIG_LZO
178 #define MTDPARTS_DEFAULT			\
179 	"mtdparts=ff705000.spi.0:"		\
180 		"1m(u-boot),"			\
181 		"64k(env1),"			\
182 		"64k(env2),"			\
183 		"256k(samtec1),"		\
184 		"256k(samtec2),"		\
185 		"-(rcvrfs);"	/* Recovery */	\
186 
187 #define CONFIG_ENV_IS_IN_SPI_FLASH
188 #define CONFIG_SYS_REDUNDAND_ENVIRONMENT
189 #define CONFIG_ENV_SIZE_REDUND		CONFIG_ENV_SIZE
190 #define CONFIG_ENV_SECT_SIZE		(64 * 1024)
191 #define CONFIG_ENV_OFFSET		0x100000
192 #define CONFIG_ENV_OFFSET_REDUND	\
193 	(CONFIG_ENV_OFFSET + CONFIG_ENV_SECT_SIZE)
194 
195 #define CONFIG_MISC_INIT_R
196 
197 /* Support changing the prompt string */
198 #define CONFIG_CMDLINE_PS_SUPPORT
199 
200 /* The rest of the configuration is shared */
201 #include <configs/socfpga_common.h>
202 
203 #endif	/* __CONFIG_SAMTEC_VINING_FPGA_H__ */
204