4 * Copyright (c) 2005-2007 Analog Devices Inc.
6 * (C) Copyright 2000-2004
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
31 #include <asm/blackfin.h>
33 #include "ether_bf537.h"
35 DECLARE_GLOBAL_DATA_PTR;
37 #define POST_WORD_ADDR 0xFF903FFC
40 * the bootldr command loads an address, checks to see if there
41 * is a Boot stream that the on-chip BOOTROM can understand,
42 * and loads it via the BOOTROM Callback. It is possible
43 * to also add booting from SPI, or TWI, but this function does
44 * not currently support that.
46 int do_bootldr(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
55 addr = simple_strtoul(argv[1], NULL, 16);
58 /* Check if it is a LDR file */
59 data = (ulong *) addr;
60 if (*data == 0xFF800060 || *data == 0xFF800040 || *data == 0xFF800020) {
61 /* We want to boot from FLASH or SDRAM */
62 entry = _BOOTROM_BOOT_DXE_FLASH;
63 printf("## Booting ldr image at 0x%08lx ...\n", addr);
69 __asm__("R7=%[a];\n" "P0=%[b];\n" "JUMP (P0);\n":
70 :[a] "d"(addr),[b] "a"(entry)
74 printf("## No ldr image at address 0x%08lx\n", addr);
80 U_BOOT_CMD(bootldr, 2, 0, do_bootldr,
81 "bootldr - boot ldr image from memory\n",
82 "[addr]\n - boot ldr image stored in memory\n");
86 #if (BFIN_CPU == ADSP_BF534)
87 printf("CPU: ADSP BF534 Rev.: 0.%d\n", *pCHIPID >> 28);
88 #elif (BFIN_CPU == ADSP_BF536)
89 printf("CPU: ADSP BF536 Rev.: 0.%d\n", *pCHIPID >> 28);
91 printf("CPU: ADSP BF537 Rev.: 0.%d\n", *pCHIPID >> 28);
93 printf("Board: ADI BF537 stamp board\n");
94 printf(" Support: http://blackfin.uclinux.org/\n");
98 #if defined(CONFIG_BFIN_IDE)
100 void cf_outb(unsigned char val, volatile unsigned char *addr)
106 unsigned char cf_inb(volatile unsigned char *addr)
108 volatile unsigned char c;
116 void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
120 for (i = 0; i < words; i++)
121 *(sect_buf + i) = *(addr);
125 void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
129 for (i = 0; i < words; i++)
130 *(addr) = *(sect_buf + i);
133 #endif /* CONFIG_BFIN_IDE */
135 long int initdram(int board_type)
139 char *tmp = getenv("baudrate");
140 brate = simple_strtoul(tmp, NULL, 16);
141 printf("Serial Port initialized with Baud rate = %x\n", brate);
142 printf("SDRAM attributes:\n");
143 printf("tRCD %d SCLK Cycles,tRP %d SCLK Cycles,tRAS %d SCLK Cycles"
144 "tWR %d SCLK Cycles,CAS Latency %d SCLK cycles \n",
146 printf("SDRAM Begin: 0x%x\n", CFG_SDRAM_BASE);
147 printf("Bank size = %d MB\n", CFG_MAX_RAM_SIZE >> 20);
149 gd->bd->bi_memstart = CFG_SDRAM_BASE;
150 gd->bd->bi_memsize = CFG_MAX_RAM_SIZE;
151 return CFG_MAX_RAM_SIZE;
154 #if defined(CONFIG_MISC_INIT_R)
155 /* miscellaneous platform dependent initialisations */
156 int misc_init_r(void)
158 #if (BFIN_BOOT_MODE == BF537_BYPASS_BOOT)
160 unsigned char *pMACaddr = (unsigned char *)0x203F0000;
161 u8 SrcAddr[6] = { 0x02, 0x80, 0xAD, 0x20, 0x31, 0xB8 };
163 #if defined(CONFIG_CMD_NET)
164 /* The 0xFF check here is to make sure we don't use the address
165 * in flash if it's simply been erased (aka all 0xFF values) */
166 if (getenv("ethaddr") == NULL && is_valid_ether_addr(pMACaddr)) {
167 sprintf(nid, "%02x:%02x:%02x:%02x:%02x:%02x",
168 pMACaddr[0], pMACaddr[1],
169 pMACaddr[2], pMACaddr[3], pMACaddr[4], pMACaddr[5]);
170 setenv("ethaddr", nid);
172 if (getenv("ethaddr")) {
173 SetupMacAddr(SrcAddr);
176 #endif /* BFIN_BOOT_MODE == BF537_BYPASS_BOOT */
178 #if defined(CONFIG_BFIN_IDE)
179 #if defined(CONFIG_BFIN_TRUE_IDE)
180 /* Enable ATASEL when in True IDE mode */
181 printf("Using CF True IDE Mode\n");
182 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_ENA);
184 #elif defined(CONFIG_BFIN_CF_IDE)
185 /* Disable ATASEL when we're in Common Memory Mode */
186 printf("Using CF Common Memory Mode\n");
187 cf_outb(0, (unsigned char *)CONFIG_CF_ATASEL_DIS);
189 #elif defined(CONFIG_BFIN_HDD_IDE)
190 printf("Using HDD IDE Mode\n");
193 #endif /* CONFIG_BFIN_IDE */
196 #endif /* CONFIG_MISC_INIT_R */
199 #if (BFIN_BOOT_MODE != BF537_BYPASS_BOOT)
200 /* Using sw10-PF5 as the hotkey */
201 int post_hotkeys_pressed(void)
206 /* Using sw10-PF5 as the hotkey */
207 int post_hotkeys_pressed(void)
211 unsigned short value;
214 *pPORTFIO_DIR &= ~PF5;
215 *pPORTFIO_INEN |= PF5;
217 printf("########Press SW10 to enter Memory POST########: %2d ", delay);
219 for (i = 0; i < 100; i++) {
220 value = *pPORTFIO & PF5;
226 printf("\b\b\b%2d ", delay);
233 printf("Hotkey has been pressed, Enter POST . . . . . .\n");
240 #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
241 void post_word_store(ulong a)
243 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
247 ulong post_word_load(void)
249 volatile ulong *save_addr = (volatile ulong *)POST_WORD_ADDR;
255 int uart_post_test(int flags)
260 #define BLOCK_SIZE 0x10000
261 #define VERIFY_ADDR 0x2000000
262 extern int erase_block_flash(int);
263 extern int write_data(long lStart, long lCount, uchar * pnData);
264 int flash_post_test(int flags)
266 unsigned short *pbuf, *temp;
271 pbuf = (unsigned short *)VERIFY_ADDR;
273 for (n = FLASH_START_POST_BLOCK; n < FLASH_END_POST_BLOCK; n++) {
274 offset = (n - 7) * BLOCK_SIZE;
275 printf("--------Erase block:%2d..", n);
276 erase_block_flash(n);
278 printf("--------Program block:%2d...", n);
279 write_data(CFG_FLASH_BASE + offset, BLOCK_SIZE, pbuf);
281 printf("--------Verify block:%2d...", n);
282 for (i = 0; i < BLOCK_SIZE; i += 2) {
283 if (*(unsigned short *)(CFG_FLASH_BASE + offset + i) !=
295 FLASH_START_POST_BLOCK) *
296 100 / (FLASH_END_POST_BLOCK -
297 FLASH_START_POST_BLOCK)));
309 /****************************************************
310 * LED1 ---- PF6 LED2 ---- PF7 *
311 * LED3 ---- PF8 LED4 ---- PF9 *
312 * LED5 ---- PF10 LED6 ---- PF11 *
313 ****************************************************/
314 int led_post_test(int flags)
316 *pPORTF_FER &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
317 *pPORTFIO_DIR |= PF6 | PF7 | PF8 | PF9 | PF10 | PF11;
318 *pPORTFIO_INEN &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
319 *pPORTFIO &= ~(PF6 | PF7 | PF8 | PF9 | PF10 | PF11);
324 printf("\b\b\b\b\b\b\b");
328 printf("\b\b\b\b\b\b\b");
332 printf("\b\b\b\b\b\b\b");
336 printf("\b\b\b\b\b\b\b");
340 printf("\b\b\b\b\b\b\b");
343 printf("\b\b\b\b\b\b\b ");
347 /************************************************
348 * SW10 ---- PF5 SW11 ---- PF4 *
349 * SW12 ---- PF3 SW13 ---- PF2 *
350 ************************************************/
351 int button_post_test(int flags)
354 unsigned short value = 0;
357 *pPORTF_FER &= ~(PF5 | PF4 | PF3 | PF2);
358 *pPORTFIO_DIR &= ~(PF5 | PF4 | PF3 | PF2);
359 *pPORTFIO_INEN |= (PF5 | PF4 | PF3 | PF2);
361 printf("\n--------Press SW10: %2d ", delay);
363 for (i = 0; i < 100; i++) {
364 value = *pPORTFIO & PF5;
370 printf("\b\b\b%2d ", delay);
376 printf("\b\bfailed");
380 printf("\n--------Press SW11: %2d ", delay);
382 for (i = 0; i < 100; i++) {
383 value = *pPORTFIO & PF4;
389 printf("\b\b\b%2d ", delay);
395 printf("\b\bfailed");
399 printf("\n--------Press SW12: %2d ", delay);
401 for (i = 0; i < 100; i++) {
402 value = *pPORTFIO & PF3;
408 printf("\b\b\b%2d ", delay);
414 printf("\b\bfailed");
418 printf("\n--------Press SW13: %2d ", delay);
420 for (i = 0; i < 100; i++) {
421 value = *pPORTFIO & PF2;
427 printf("\b\b\b%2d ", delay);
433 printf("\b\bfailed");