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

📄 autoboot-1.3.0.patch

📁 针对AT91RM9200的U-BOOT1.30制作的官方AT91RM9200DK的补丁
💻 PATCH
📖 第 1 页 / 共 3 页
字号:
  */--int flash_erase (flash_info_t * info, int s_first, int s_last)+static ulong flash_get_size (FPW *addr, flash_info_t *info) {-	ulong result;-	int iflag, cflag, prot, sect;-	int rc = ERR_OK;-	int chip1;+	volatile FPW value;++	/* Write auto select command: read Manufacturer ID */+	addr[0x5555] = (FPW) 0x00AA00AA;+	addr[0x2AAA] = (FPW) 0x00550055;+	addr[0x5555] = (FPW) 0x00900090;++	mb ();+	value = addr[0];++	switch (value) {++	case (FPW) INTEL_MANUFACT:+		info->flash_id = FLASH_MAN_INTEL;+		break;++	default:+		info->flash_id = FLASH_UNKNOWN;+		info->sector_count = 0;+		info->size = 0;+		addr[0] = (FPW) 0x00FF00FF;	/* restore read mode */+		return (0);			/* no or unknown flash  */+	}++	mb ();+	value = addr[1];			/* device ID        */++	switch (value) {++	case (FPW) INTEL_ID_28F128J3A:+		info->flash_id += FLASH_28F128J3A;+		info->sector_count = 128;+		info->size = 0x01000000;+		break;				/* => 16 MB     */++	case (FPW) INTEL_ID_28F640J3A:+		info->flash_id += FLASH_28F640J3A;+		info->sector_count = 64;+		info->size = 0x00800000;+		break;				/* => 8 MB     */++	default:+		info->flash_id = FLASH_UNKNOWN;+		break;+	}++	if (info->sector_count > CFG_MAX_FLASH_SECT) {+		printf ("** ERROR: sector count %d > max (%d) **\n",+			info->sector_count, CFG_MAX_FLASH_SECT);+		info->sector_count = CFG_MAX_FLASH_SECT;+	}++	addr[0] = (FPW) 0x00FF00FF;		/* restore read mode */ -	/* first look for protection bits */+	return (info->size);+}+++/*-----------------------------------------------------------------------+ */ -	if (info->flash_id == FLASH_UNKNOWN)-		return ERR_UNKNOWN_FLASH_TYPE;+int flash_erase (flash_info_t *info, int s_first, int s_last)+{+	int flag, prot, sect;+	ulong type, start, last;+	int rcode = 0;  	if ((s_first < 0) || (s_first > s_last)) {-		return ERR_INVAL;+		if (info->flash_id == FLASH_UNKNOWN) {+			printf ("- missing\n");+		} else {+			printf ("- no sectors to erase\n");+		}+		return 1; 	} -	if ((info->flash_id & FLASH_VENDMASK) !=-		(ATM_MANUFACT & FLASH_VENDMASK)) {-		return ERR_UNKNOWN_FLASH_VENDOR;+	type = (info->flash_id & FLASH_VENDMASK);+	if ((type != FLASH_MAN_INTEL)) {+		printf ("Can't erase unknown flash type %08lx - aborted\n",+			info->flash_id);+		return 1; 	}  	prot = 0;@@ -306,197 +275,262 @@ 			prot++; 		} 	}-	if (prot)-		return ERR_PROTECTED; -	/*-	 * Disable interrupts which might cause a timeout-	 * here. Remember that our exception vectors are-	 * at address 0 in the flash, and we don't want a-	 * (ticker) exception to happen while the flash-	 * chip is in programming mode.-	 */-	cflag = icache_status ();-	icache_disable ();-	iflag = disable_interrupts ();+	if (prot) {+		printf ("- Warning: %d protected sectors will not be erased!\n",+			prot);+	} else {+		printf ("\n");+	} -	/* Start erase on unprotected sectors */-	for (sect = s_first; sect <= s_last && !ctrlc (); sect++) {-		printf ("Erasing sector %2d ... ", sect);+	start = get_timer (0);+	last = start; -		/* arm simple, non interrupt dependent timer */-		reset_timer_masked ();+	/* Disable interrupts which might cause a timeout here */+	flag = disable_interrupts (); +	/* Start erase on unprotected sectors */+	for (sect = s_first; sect <= s_last; sect++) { 		if (info->protect[sect] == 0) {	/* not protected */-			volatile u16 *addr = (volatile u16 *) (info->start[sect]);+			FPWV *addr = (FPWV *) (info->start[sect]);+			FPW status; -			MEM_FLASH_ADDR1 = CMD_UNLOCK1;-			MEM_FLASH_ADDR2 = CMD_UNLOCK2;-			MEM_FLASH_ADDR1 = CMD_ERASE_SETUP;+			printf ("Erasing sector %2d ... ", sect); -			MEM_FLASH_ADDR1 = CMD_UNLOCK1;-			MEM_FLASH_ADDR2 = CMD_UNLOCK2;-			*addr = CMD_ERASE_CONFIRM;+			/* arm simple, non interrupt dependent timer */+			reset_timer_masked (); -			/* wait until flash is ready */-			chip1 = 0;+			*addr = (FPW) 0x00500050;	/* clear status register */+			*addr = (FPW) 0x00200020;	/* erase setup */+			*addr = (FPW) 0x00D000D0;	/* erase confirm */ -			do {-				result = *addr;--				/* check timeout */+			while (((status = *addr) & (FPW) 0x00800080) != (FPW) 0x00800080) { 				if (get_timer_masked () > CFG_FLASH_ERASE_TOUT) {-					MEM_FLASH_ADDR1 = CMD_READ_ARRAY;-					chip1 = TMO;+					printf ("Timeout\n");+					*addr = (FPW) 0x00B000B0;	/* suspend erase     */+					*addr = (FPW) 0x00FF00FF;	/* reset to read mode */+					rcode = 1; 					break; 				}+			} -				if (!chip1 && (result & 0xFFFF) & BIT_ERASE_DONE)-					chip1 = READY;+			*addr = (FPW) 0x00500050;	/* clear status register cmd.   */+			*addr = (FPW) 0x00FF00FF;	/* resest to read mode          */++			printf (" done\n");+		}+	}+	return rcode;+} -			} while (!chip1);+/*-----------------------------------------------------------------------+ * Copy memory to flash, returns:+ * 0 - OK+ * 1 - write timeout+ * 2 - Flash not erased+ * 4 - Flash not identified+ */ -			MEM_FLASH_ADDR1 = CMD_READ_ARRAY;+int write_buff (flash_info_t *info, uchar *src, ulong addr, ulong cnt)+{+	ulong cp, wp;+	FPW data;+	int count, i, l, rc, port_width;++	if (info->flash_id == FLASH_UNKNOWN) {+		return 4;+	}+/* get lower word aligned address */+#ifdef FLASH_PORT_WIDTH16+	wp = (addr & ~1);+	port_width = 2;+#else+	wp = (addr & ~3);+	port_width = 4;+#endif -			if (chip1 == ERR) {-				rc = ERR_PROG_ERROR;-				goto outahere;-			}-			if (chip1 == TMO) {-				rc = ERR_TIMOUT;-				goto outahere;-			}+	/*+	 * handle unaligned start bytes+	 */+	if ((l = addr - wp) != 0) {+		data = 0;+		for (i = 0, cp = wp; i < l; ++i, ++cp) {+			data = (data << 8) | (*(uchar *) cp);+		}+		for (; i < port_width && cnt > 0; ++i) {+			data = (data << 8) | *src++;+			--cnt;+			++cp;+		}+		for (; cnt == 0 && i < port_width; ++i, ++cp) {+			data = (data << 8) | (*(uchar *) cp);+		} -			printf ("ok.\n");-		} else {			/* it was protected */-			printf ("protected!\n");+		if ((rc = write_data (info, wp, SWAP (data))) != 0) {+			return (rc); 		}+		wp += port_width; 	} -	if (ctrlc ())-		printf ("User Interrupt!\n");--outahere:-	/* allow flash to settle - wait 10 ms */-	udelay_masked (10000);+	/*+	 * handle word aligned part+	 */+	count = 0;+	while (cnt >= port_width) {+		data = 0;+		for (i = 0; i < port_width; ++i) {+			data = (data << 8) | *src++;+		}+		if ((rc = write_data (info, wp, SWAP (data))) != 0) {+			return (rc);+		}+		wp += port_width;+		cnt -= port_width;+		if (count++ > 0x800) {+			spin_wheel ();+			count = 0;+		}+	} -	if (iflag)-		enable_interrupts ();+	if (cnt == 0) {+		return (0);+	} -	if (cflag)-		icache_enable ();+	/*+	 * handle unaligned tail bytes+	 */+	data = 0;+	for (i = 0, cp = wp; i < port_width && cnt > 0; ++i, ++cp) {+		data = (data << 8) | *src++;+		--cnt;+	}+	for (; i < port_width; ++i, ++cp) {+		data = (data << 8) | (*(uchar *) cp);+	} -	return rc;+	return (write_data (info, wp, SWAP (data))); }  /*------------------------------------------------------------------------ * Copy memory to flash+ * Write a word or halfword to Flash, returns:+ * 0 - OK+ * 1 - write timeout+ * 2 - Flash not erased  */--static int write_word (flash_info_t * info, ulong dest, ulong data)+static int write_data (flash_info_t *info, ulong dest, FPW data) {-	volatile u16 *addr = (volatile u16 *) dest;-	ulong result;-	int rc = ERR_OK;-	int cflag, iflag;-	int chip1;+	FPWV *addr = (FPWV *) dest;+	ulong status;+	int flag; -	/*-	 * Check if Flash is (sufficiently) erased-	 */-	result = *addr;-	if ((result & data) != data)-		return ERR_NOT_ERASED;+	/* Check if Flash is (sufficiently) erased */+	if ((*addr & data) != data) {+		printf ("not erased at %08lx (%lx)\n", (ulong) addr, *addr);+		return (2);+	}+	/* Disable interrupts which might cause a timeout here */+	flag = disable_interrupts (); -	/*-	 * Disable interrupts which might cause a timeout-	 * here. Remember that our exception vectors are-	 * at address 0 in the flash, and we don't want a-	 * (ticker) exception to happen while the flash-	 * chip is in programming mode.-	 */-	cflag = icache_status ();-	icache_disable ();-	iflag = disable_interrupts ();--	MEM_FLASH_ADDR1 = CMD_UNLOCK1;-	MEM_FLASH_ADDR2 = CMD_UNLOCK2;-	MEM_FLASH_ADDR1 = CMD_PROGRAM;+	*addr = (FPW) 0x00400040;	/* write setup */ 	*addr = data;  	/* arm simple, non interrupt dependent timer */ 	reset_timer_masked (); -	/* wait until flash is ready */-	chip1 = 0;-	do {-		result = *addr;--		/* check timeout */-		if (get_timer_masked () > CFG_FLASH_ERASE_TOUT) {-			chip1 = ERR | TMO;-			break;+	/* wait while polling the status register */+	while (((status = *addr) & (FPW) 0x00800080) != (FPW) 0x00800080) {+		if (get_timer_masked () > CFG_FLASH_WRITE_TOUT) {+			*addr = (FPW) 0x00FF00FF;	/* restore read mode */+			return (1); 		}-		if (!chip1 && ((result & 0x80) == (data & 0x80)))-			chip1 = READY;--	} while (!chip1);--	*addr = CMD_READ_ARRAY;+	} -	if (chip1 == ERR || *addr != data)-		rc = ERR_PROG_ERROR;+	*addr = (FPW) 0x00FF00FF;	/* restore read mode */ -	if (iflag)-		enable_interrupts ();+	return (0);+} -	if (cflag)-		icache_enable ();+void inline spin_wheel (void)+{+	static int p = 0;+	static char w[] = "\\/-"; -	return rc;+	printf ("\010%c", w[p]);+	(++p == 3) ? (p = 0) : 0; }  /*------------------------------------------------------------------------ * Copy memory to flash.+ * Set/Clear sector's lock bit, returns:+ * 0 - OK+ * 1 - Error (timeout, voltage problems, etc.)  */--int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)+int flash_real_protect(flash_info_t *info, long sector, int prot) {-	ulong wp, data;-	int rc;+	int i;+	int rc = 0;+	vu_long *addr = (vu_long *)(info->start[sector]);+	int flag = disable_interrupts();++	*addr = INTEL_CLEAR;	/* Clear status register */+	if (prot) {			/* Set sector lock bit */+		*addr = INTEL_LOCKBIT;	/* Sector lock bit */+		*addr = INTEL_PROTECT;	/* set */+	}+	else {				/* Clear sector lock bit */+		*addr = INTEL_LOCKBIT;	/* All sectors lock bits */

⌨️ 快捷键说明

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