⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash.c

📁 AT91RM9200的完整启动代码:包括loader, boot及U-boot三部分均已编译通过!欢迎下载使用!
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * (C) Copyright 2002, 2003 * Daniel Engstr鰉, Omicron Ceti AB, daniel@omicron.se *  * (C) Copyright 2002 * Sysgo Real-Time Solutions, GmbH <www.elinos.com> * Alex Zuepke <azu@sysgo.de> * * See file CREDITS for list of people who contributed to this * project. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, * MA 02111-1307 USA */#include <common.h>#include <asm/io.h>#include <pci.h>#include <asm/ic/sc520.h>#define PROBE_BUFFER_SIZE 1024static unsigned char buffer[PROBE_BUFFER_SIZE];#define SC520_MAX_FLASH_BANKS  1#define SC520_FLASH_BANK0_BASE 0x38000000  /* BOOTCS */#define SC520_FLASH_BANKSIZE   0x8000000#define A29LV641DH_SIZE        0x800000#define A29LV641DH_SECTORS     128#define A29LV641MH_SIZE        0x800000#define A29LV641MH_SECTORS     128#define I28F320J3A_SIZE        0x400000#define I28F320J3A_SECTORS     32#define I28F640J3A_SIZE        0x800000#define I28F640J3A_SECTORS     64#define I28F128J3A_SIZE        0x1000000#define I28F128J3A_SECTORS     128flash_info_t    flash_info[SC520_MAX_FLASH_BANKS];#define READY 1#define ERR   2#define TMO   4/*----------------------------------------------------------------------- */static u32 _probe_flash(u32 addr, u32 bw, int il){	u32 result=0;		/* First do an unlock cycle for the benefit of	 * devices that need it */		switch (bw) {			case 1:		*(volatile u8*)(addr+0x5555) = 0xaa;		*(volatile u8*)(addr+0x2aaa) = 0x55;		*(volatile u8*)(addr+0x5555) = 0x90;				/* Read vendor */		result = *(volatile u8*)addr;		result <<= 16;				/* Read device */		result |= *(volatile u8*)(addr+2);				/* Return device to data mode */		*(volatile u8*)addr = 0xff;		*(volatile u8*)(addr+0x5555), 0xf0;  		break;			case 2:		*(volatile u16*)(addr+0xaaaa) = 0xaaaa;		*(volatile u16*)(addr+0x5554) = 0x5555;				/* Issue identification command */		if (il == 2) {			*(volatile u16*)(addr+0xaaaa) = 0x9090;						/* Read vendor */			result = *(volatile u8*)addr;			result <<= 16;						/* Read device */			result |= *(volatile u8*)(addr+2);						/* Return device to data mode */			*(volatile u16*)addr =  0xffff;			*(volatile u16*)(addr+0xaaaa), 0xf0f0;  					} else {			*(volatile u8*)(addr+0xaaaa) = 0x90;			/* Read vendor */			result = *(volatile u16*)addr;			result <<= 16;						/* Read device */			result |= *(volatile u16*)(addr+2);						/* Return device to data mode */			*(volatile u8*)addr = 0xff;			*(volatile u8*)(addr+0xaaaa), 0xf0;  					}				break;			 case 4:		*(volatile u32*)(addr+0x5554) = 0xaaaaaaaa;		*(volatile u32*)(addr+0xaaa8) = 0x55555555;				switch (il) {		case 1:			/* Issue identification command */			*(volatile u8*)(addr+0x5554) = 0x90;						/* Read vendor */			result = *(volatile u16*)addr;			result <<= 16;					/* Read device */			result |= *(volatile u16*)(addr+4);						/* Return device to data mode */			*(volatile u8*)addr =  0xff;			*(volatile u8*)(addr+0x5554), 0xf0;  			break;					case 2:			/* Issue identification command */			*(volatile u32*)(addr + 0x5554) = 0x00900090;						/* Read vendor */			result = *(volatile u16*)addr;			result <<= 16;						/* Read device */			result |= *(volatile u16*)(addr+4);						/* Return device to data mode */			*(volatile u32*)addr =  0x00ff00ff;			*(volatile u32*)(addr+0x5554), 0x00f000f0;  			break;					case 4:			/* Issue identification command */			*(volatile u32*)(addr+0x5554) = 0x90909090;						/* Read vendor */			result = *(volatile u8*)addr;			result <<= 16;						/* Read device */			result |= *(volatile u8*)(addr+4);						/* Return device to data mode */			*(volatile u32*)addr =  0xffffffff;			*(volatile u32*)(addr+0x5554), 0xf0f0f0f0; 			break;		}		break;	}				return result;}extern int _probe_flash_end;asm ("_probe_flash_end:\n"     ".long 0\n");static int identify_flash(unsigned address, int width){	int is;		int device;	int vendor;		int size;	unsigned res;		u32 (*_probe_flash_ptr)(u32 a, u32 bw, int il);		size = (unsigned)&_probe_flash_end - (unsigned)_probe_flash; 		if (size > PROBE_BUFFER_SIZE) {		printf("_probe_flash() routine too large (%d) %p - %p\n",		       size, &_probe_flash_end, _probe_flash);		return 0;	}		memcpy(buffer, _probe_flash, size);	_probe_flash_ptr = (void*)buffer;		is = disable_interrupts();	res = _probe_flash_ptr(address, width, 1);	if (is) {		enable_interrupts();	}		        vendor = res >> 16;	device = res & 0xffff;				return res;}ulong flash_init(void){	int i, j;	ulong size = 0;		for (i = 0; i < SC520_MAX_FLASH_BANKS; i++) {		unsigned id;		ulong flashbase = 0;		int sectsize = 0; 				memset(flash_info[i].protect, 0, CFG_MAX_FLASH_SECT);		switch (i) {		case 0:			flashbase = SC520_FLASH_BANK0_BASE;			break;		default:			panic("configured to many flash banks!\n");		}				id = identify_flash(flashbase, 2);		switch (id) {		case 0x000122d7:			/* 29LV641DH */			flash_info[i].flash_id =				(AMD_MANUFACT & FLASH_VENDMASK) |				(AMD_ID_LV640U & FLASH_TYPEMASK);						flash_info[i].size = A29LV641DH_SIZE;			flash_info[i].sector_count = A29LV641DH_SECTORS;			sectsize = A29LV641DH_SIZE/A29LV641DH_SECTORS;			printf("Bank %d: AMD 29LV641DH\n", i);			break;					case 0x0001227E:			/* 29LV641MH */			flash_info[i].flash_id =				(AMD_MANUFACT & FLASH_VENDMASK) |				(AMD_ID_DL640 & FLASH_TYPEMASK);						flash_info[i].size = A29LV641MH_SIZE;			flash_info[i].sector_count = A29LV641MH_SECTORS;			sectsize = A29LV641MH_SIZE/A29LV641MH_SECTORS;			printf("Bank %d: AMD 29LV641MH\n", i);			break;					case 0x00890016:			/* 28F320J3A */			flash_info[i].flash_id =				(INTEL_MANUFACT & FLASH_VENDMASK) |				(INTEL_ID_28F320J3A & FLASH_TYPEMASK);						flash_info[i].size = I28F320J3A_SIZE;			flash_info[i].sector_count = I28F320J3A_SECTORS;			sectsize = I28F320J3A_SIZE/I28F320J3A_SECTORS;			printf("Bank %d: Intel 28F320J3A\n", i);			break;					case 0x00890017:			/* 28F640J3A */			flash_info[i].flash_id =				(INTEL_MANUFACT & FLASH_VENDMASK) |				(INTEL_ID_28F640J3A & FLASH_TYPEMASK);						flash_info[i].size = I28F640J3A_SIZE;			flash_info[i].sector_count = I28F640J3A_SECTORS;			sectsize = I28F640J3A_SIZE/I28F640J3A_SECTORS;			printf("Bank %d: Intel 28F640J3A\n", i);			break;					case 0x00890018:			/* 28F128J3A */			flash_info[i].flash_id =				(INTEL_MANUFACT & FLASH_VENDMASK) |				(INTEL_ID_28F128J3A & FLASH_TYPEMASK);						flash_info[i].size = I28F128J3A_SIZE;			flash_info[i].sector_count = I28F128J3A_SECTORS;			sectsize = I28F128J3A_SIZE/I28F128J3A_SECTORS;			printf("Bank %d: Intel 28F128J3A\n", i);			break;					default:			printf("Bank %d have unknown flash %08x\n", i, id);			flash_info[i].flash_id = FLASH_UNKNOWN;			continue;		}				for (j = 0; j < flash_info[i].sector_count; j++) {			flash_info[i].start[j] = flashbase + j * sectsize;		}		size += flash_info[i].size;				flash_protect(FLAG_PROTECT_CLEAR,			      flash_info[i].start[0],			       flash_info[i].start[0] + flash_info[i].size - 1,			      &flash_info[i]);	}		/*	 * Protect monitor and environment sectors	 */	flash_protect(FLAG_PROTECT_SET,		      i386boot_start,		      i386boot_end,		      &flash_info[0]);#ifdef CFG_ENV_ADDR	flash_protect(FLAG_PROTECT_SET,		      CFG_ENV_ADDR,		      CFG_ENV_ADDR + CFG_ENV_SIZE - 1,		      &flash_info[0]);#endif		return size;}/*----------------------------------------------------------------------- */void flash_print_info(flash_info_t *info){	int i;		switch (info->flash_id & FLASH_VENDMASK) {	case (INTEL_MANUFACT & FLASH_VENDMASK):		printf("INTEL: ");		switch (info->flash_id & FLASH_TYPEMASK) {		case (INTEL_ID_28F320J3A & FLASH_TYPEMASK):			printf("1x I28F320J3A (32Mbit)\n");			break;		case (INTEL_ID_28F640J3A & FLASH_TYPEMASK):			printf("1x I28F640J3A (64Mbit)\n");			break;		case (INTEL_ID_28F128J3A & FLASH_TYPEMASK):			printf("1x I28F128J3A (128Mbit)\n");			break;		default:			printf("Unknown Chip Type\n");			goto done;			break;		}				break;			case (AMD_MANUFACT & FLASH_VENDMASK):		printf("AMD:   ");		switch (info->flash_id & FLASH_TYPEMASK) {		case (AMD_ID_LV640U & FLASH_TYPEMASK):			printf("1x AMD29LV641DH (64Mbit)\n");			break;		case (AMD_ID_DL640 & FLASH_TYPEMASK):			printf("1x AMD29LV641MH (64Mbit)\n");			break;		default:			printf("Unknown Chip Type\n");			goto done;			break;		}				break;	default:		printf("Unknown Vendor ");		break;	}			printf("  Size: %ld MB in %d Sectors\n",	       info->size >> 20, info->sector_count);		printf("  Sector Start Addresses:");	for (i = 0; i < info->sector_count; i++) {		if ((i % 5) == 0) {			printf ("\n   ");		}		printf (" %08lX%s", info->start[i],			info->protect[i] ? " (RO)" : "     ");	}	printf ("\n");		done:}/*----------------------------------------------------------------------- */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -