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

📄 flash.c

📁 Boot code for ADM5120 with serial console for Edimax router.
💻 C
字号:
/*****************************************************************************;;    Project : Common Platform;    Creator : Dan Everett;    File    : flash.c;    Abstract:;;;*****************************************************************************/#include <flash.h>#include <test_def.h>#if PRESERVE_FLASH == 1 || TEST_BOOTLOADER == 1#include <buart.h>#endifvoid mx29lv320_enter_ss();void mx29lv320_exit_ss();void mx29lv320_erase_ss(struct FLASH_DESC_S *);void mx29lv320_whack_ss(struct FLASH_DESC_S *, char *, char *, int);/**************************  declare global variables **************************/static  FLASH_DESC *chips = 0;int ssopen;/*----------------------------------------------------------------------* ROUTINE NAME - flash_init*-----------------------------------------------------------------------* DESCRIPTION:*	Intialize the flash driver*   *----------------------------------------------------------------------*/int flash_init(){	/* THE "#if 0" WAS ALREADY IN HERE - DE */	/* There IS NO flash_sem ANYWHERE! - DE */#if 0    if (flash_sem.lock == 0)    {        strcpy(flash_sem.name, "Flah Drv");        flash_sem.sem_count = 1;    }#endif    return 0;}/*----------------------------------------------------------------------* ROUTINE NAME - flash_add*-----------------------------------------------------------------------* DESCRIPTION:*	Intialize the flash driver*   *----------------------------------------------------------------------*/int flash_add(FLASH_DESC *dev){	register FLASH_DESC *cp = chips;	dev->next = 0;	while (cp) {		/* Already installed? */		if (cp == dev)			return 0;		if (cp->next == 0)			break;		else			cp = cp->next;	}	if (cp == 0)		chips = dev;	else		cp->next = dev;	return 0;}/*----------------------------------------------------------------------* ROUTINE NAME - flash_fit*-----------------------------------------------------------------------* DESCRIPTION:*	Check the range of the input data*   * INPUT:*   cp      -- flash control block*	flash   -- Address of the block to read.*   cells   -- cell number to check.*----------------------------------------------------------------------*/static int flash_fit (struct FLASH_DESC_S *cp, unsigned long addr, int *size){#if PRESERVE_FLASH == 1	buart_print("\n\rOOPS!  Tried to run 'flash_fit()' in test mode!\n\r");#else	register int len;	register unsigned long start = (unsigned long)cp->start;	register unsigned long end = (unsigned long)cp->start + cp->flash_size;	/* check range */	if (addr < start || addr >= end)		return FLASH_NOT_FIT_IN;        /* out of range */	/* Get the size to write */	len = (end - addr) / cp->addr_inc;	if (*size > len) {		*size = len;		return FLASH_PARTIAL_DONE;      /* partial written */	} else {		switch (cp->byte_width) {			case 16:				*size = ((*size + 1)/2)*2;				break;			case 32:				*size = ((*size + 3)/4)*4;			default:				break;		}	}#endif	return FLASH_OK;}/*----------------------------------------------------------------------* ROUTINE NAME - flash_read*-----------------------------------------------------------------------* DESCRIPTION:*	Called by NV RAM driver to read NV data.** INPUT:*	flash   -- Address of the block to read.*   dst 	-- address of this data buffer.*   size    -- data size to read from the flash.*----------------------------------------------------------------------*/int flash_read(char *dst, char *flash, int cells){	register int rc = 0;#if PRESERVE_FLASH == 1	buart_print("\n\rOOPS!  Tried to run 'flash_read()' in test mode!\n\r");#else	int size = cells;	register FLASH_DESC *cp = chips;    	while (cp && cells > 0) {		if (flash_fit(cp, (unsigned long)flash, &size) != FLASH_NOT_FIT_IN) {			rc = (*cp->read)(cp, flash, dst, size);			if (rc == FLASH_ERROR)				break;			flash += size * cp->addr_inc;			dst   += size;			cells -= size;		}		size = cells;		cp = cp->next;	}#endif	return rc;}/*----------------------------------------------------------------------* ROUTINE NAME - flash_write*-----------------------------------------------------------------------* DESCRIPTION:*	Called by NV RAM driver or the image updating module *   to update the date content.** INPUT:*	flash   -- Address of the block to wirte.*   src	    -- Source address of this image.*   size    -- image size to write to the flash.*----------------------------------------------------------------------*/int flash_write(char *flash, char *src, int cells){	register int rc = FLASH_OK;#if PRESERVE_FLASH == 1	buart_print("\n\rOOPS!  Tried to run 'flash_write()' in test mode!\n\r");#else	int size = cells;	register FLASH_DESC *cp = chips;    	while (cp && cells > 0) {		if (flash_fit(cp, (unsigned long)flash, &size) != FLASH_NOT_FIT_IN) {//			buart_print("\n\rflash_write(): rc not FLASH_NOT_FIT_IN\n\r");			rc = (*cp->write)(cp, flash, src, size);			if (rc == FLASH_ERROR)				break;			flash += size * cp->addr_inc;			src   += size;			cells -= size;		} else {			buart_print("\n\rflash_write(): rc is FLASH_NOT_FIT_IN\n\r");		}		size = cells;		cp = cp->next;	}#endif	return rc;}/*----------------------------------------------------------------------* ROUTINE NAME - flash_erase*-----------------------------------------------------------------------* DESCRIPTION:*	Called by NV RAM driver or the image updating module *   to erase the blocks, whereafter this block can accept new data*   written.** INPUT:*	flash   -- Address of the flash start address to be erased*   size    -- size of the flash portion to be erased*----------------------------------------------------------------------*/int flash_erase(char *flash, int cells){	register int rc = FLASH_OK;#if PRESERVE_FLASH == 1	buart_print("\n\rOOPS!  Tried to run 'flash_erase()' in test mode!\n\r");#else	int size = cells;	register FLASH_DESC *cp = chips;    	while (cp && cells > 0) {		if (flash_fit(cp, (unsigned long)flash, &size) != FLASH_NOT_FIT_IN) {			rc = (*cp->erase)(cp, flash, size);			if (rc == FLASH_ERROR) {				buart_print("\n\rflash_erase(): FLASH_ERROR from *cp->erase()");				break;			}			flash += size * cp->addr_inc;			cells -= size;		} else {			buart_print("\n\rflash_erase(): FLASH_NOT_FIT_IN from flash_fit()");		}		size = cells;		cp = cp->next;	}#endif	return rc;}/*----------------------------------------------------------------------* ROUTINE NAME - flash_info*-----------------------------------------------------------------------* DESCRIPTION:*	Called by NV RAM driver or the image updating module *   to retrieve information about the flash protection setuo.** INPUT:*	flash   --*   size    --*----------------------------------------------------------------------*/int flash_info(){	register int rc = 0;	register FLASH_DESC *cp = chips;	/* Real simple.  Assume one NOR flash device. */	if (cp) {		rc = (*cp->protectinfo)(cp);	}	return rc;}void flash_toggle_ss(){	FLASH_DESC *cp = chips;	if (cp) {		if (ssopen == 0) {			mx29lv320_enter_ss(cp);			buart_print("\r\nSecurity Sector is now OPEN");		} else {			mx29lv320_exit_ss(cp);			buart_print("\r\nSecurity Sector is now CLOSED");		}	}}void flash_erase_ss(){	FLASH_DESC *cp = chips;	if (cp) {		mx29lv320_erase_ss(cp);	}}void flash_whack_ss(){	FLASH_DESC *cp = chips;	unsigned long copyme = 0x401a6000;	if (cp) {		mx29lv320_whack_ss(cp, (char *) 0xbfc00000, (char *) &copyme, 4);	}}void flash_exit_ss(){	mx29lv320_exit_ss();}FLASH_DESC *flash_get_head_chip(){	return chips;}

⌨️ 快捷键说明

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