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

📄 tgt_flash.c

📁 MIPS处理器的bootloader,龙芯就是用的修改过的PMON2
💻 C
字号:
/*	$Id: tgt_flash.c,v 1.1 2002/05/08 19:23:00 patrik Exp $ *//* * Copyright (c) 2002 Patrik Lindergren (www.lindergren.com) *  * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by Patrik Lindergren. * 4. The name of the author may not be used to endorse or promote products *    derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * */#include <sys/types.h>#include <stdio.h>#include <setjmp.h>#include <termio.h>#include <string.h>#include <machine/cpu.h>#include <machine/pio.h>#include <pflash.h>#include <dev/pflash_tgt.h>#include <pmon/dev/mpc107reg.h>#include <dev/pci/pcivar.h>#include <pmon.h>/* *  Flash programming support code. *//* *  Table of flash devices on target. See pflash_tgt.h. */struct fl_map tgt_fl_map[] = {	{ USERFLASH_BASE,  USERFLASH_SIZE,  1, 1, FL_BUS_8, 0},	{ BOOTFLASH1_BASE, BOOTFLASH1_SIZE, 1, 1, FL_BUS_8, 0},		{ BOOTFLASH2_BASE, BOOTFLASH2_SIZE, 1, 1, FL_BUS_8, 0},		{ 0x00000000, 0x00000000 }};voidtgt_flashinit(){#if 0   	unsigned int cfg;	cfg = inl(CONFIG_REGISTER) & CFG_REG_MASK;	switch(CFG_REG_FLASHSIZE(cfg)) {		case 0: /* 32 MB UserFlash */			tgt_fl_map[0].fl_map_size = 0x02000000;			tgt_fl_map[0].fl_map_width = 4;			tgt_fl_map[0].fl_map_chips = 2;			break;		case 1: /* 64 MB UserFlash */			tgt_fl_map[0].fl_map_size = 0x04000000;			tgt_fl_map[0].fl_map_width = 8;			tgt_fl_map[0].fl_map_chips = 4;			break;	}#endif}struct fl_map *tgt_flashmap(){	return(tgt_fl_map);}voidtgt_flashwrite_disable(){	pcitag_t tag;	pcireg_t reg;		tag = _pci_make_tag(0, 0, 0);	reg = _pci_conf_read(tag, MPC107_CFG_PICR1);	reg &= MPC107_PICR1_FLASH_WR_EN;	_pci_conf_write(tag, MPC107_CFG_PICR1, reg);}inttgt_flashwrite_enable(){	pcitag_t tag;	pcireg_t reg;	tag = _pci_make_tag(0, 0, 0);	reg = _pci_conf_read(tag, MPC107_CFG_PICR1);	reg |= MPC107_PICR1_FLASH_WR_EN;	_pci_conf_write(tag, MPC107_CFG_PICR1, reg);	return(1);}voidtgt_flashinfo(void *p, size_t *t){	struct fl_map *map;		map = fl_find_map(p);	if(map) {		*t = map->fl_map_size - NVRAM_MAXSIZE;	}	else {		*t = 0;	}}voidtgt_flashprogram(void *p, int size, void *s, int endian){	printf("Programming flash %p:%p into %p\n", s, size, p);	if(fl_erase_device(p, size, TRUE)) {		printf("Erase failed!\n");		return;	}	if(fl_program_device(p, s, size, TRUE)) {		printf("Programming failed!\n");	}}

⌨️ 快捷键说明

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