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

📄 nand_write_yaffs.patch

📁 uboot nandflash 启动补丁文件
💻 PATCH
📖 第 1 页 / 共 5 页
字号:
+			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); 		}-	} -	if (ctrlc ())-		printf ("User Interrupt!\n");+		if ((rc = write_data (info, wp, data)) != 0) {+			return (rc);+		}+		wp += port_width;+	} -      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, 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, 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_data (flash_info_t * info, ulong dest, unsigned char data)+{+	volatile unsigned char *addr = (volatile unsigned char *) dest;+	ulong status;+	int flag;++	/* Check if Flash is (sufficiently) erased */+	if ((*addr & data) != data) {+		printf ("not erased at %08lx (%lx)\n", (ulong) addr,+			(ulong) * addr);+		return (2);+	}+	/* Disable interrupts which might cause a timeout here */+	flag = disable_interrupts (); -volatile static int write_hword (flash_info_t * info, ulong dest, ushort data)+	*addr = 0x40;	/* write setup */+	*addr = data;++	/* arm simple, non interrupt dependent timer */+	reset_timer_masked ();++	/* wait while polling the status register */+	while (((status = *addr) & 0x80) != 0x80) {+		if (get_timer_masked () > CFG_FLASH_WRITE_TOUT) {+			*addr = 0xFF;	/* restore read mode */+			return (1);+		}+	}++	*addr = 0xFF;	/* restore read mode */++	return (0);+}++void inline spin_wheel (void) {-	vu_short *addr = (vu_short *) dest;-	ushort result;+	static int p = 0;+	static char w[] = "\\/-";++	printf ("\010%c", w[p]);+	(++p == 3) ? (p = 0) : 0;+}+#endif //if 0+static int write_word (flash_info_t * info, ulong dest, ushort data)+{+	vu_short *addr = (vu_short *) dest, val; 	int rc = ERR_OK;-	int cflag, iflag;-	int chip;+	int flag; -	/*-	 * Check if Flash is (sufficiently) erased+	/* Check if Flash is (sufficiently) erased 	 */-	result = *addr;-	if ((result & data) != data)+	if ((*addr & data) != data) 		return ERR_NOT_ERASED; - 	/* 	 * Disable interrupts which might cause a timeout 	 * here. Remember that our exception vectors are@@ -313,53 +431,58 @@ 	 * (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_UNLOCK_BYPASS;-	*addr = CMD_PROGRAM;+	flag = disable_interrupts ();++	/* clear status register command */+	*addr = 0x50;++	/* program set-up command */+	*addr = 0x40;++	/* latch address/data */ 	*addr = data;  	/* arm simple, non interrupt dependent timer */ 	reset_timer_masked (); -	/* wait until flash is ready */-	chip = 0;-	do {-		result = *addr;--		/* check timeout */-		if (get_timer_masked () > CFG_FLASH_ERASE_TOUT) {-			chip = ERR | TMO;-			break;+	/* wait while polling the status register */+	while (((val = *addr) & 0x80) != 0x80) {+		if (get_timer_masked () > CFG_FLASH_WRITE_TOUT) {+			rc = ERR_TIMOUT;+			/* suspend program command */+			*addr = 0xB0;+			goto outahere; 		}-		if (!chip && ((result & 0x80) == (data & 0x80)))-			chip = READY;--		if (!chip && ((result & 0xFFFF) & BIT_PROGRAM_ERROR)) {-			result = *addr;+	} -			if ((result & 0x80) == (data & 0x80))-				chip = READY;-			else-				chip = ERR;+	if (val & 0x1A) {	/* check for error */+		printf ("\nFlash write error %02x at address %08lx\n",+			(int) val, (unsigned long) dest);+		if (val & (1 << 3)) {+			printf ("Voltage range error.\n");+			rc = ERR_PROG_ERROR;+			goto outahere;+		}+		if (val & (1 << 1)) {+			printf ("Device protect error.\n");+			rc = ERR_PROTECTED;+			goto outahere;+		}+		if (val & (1 << 4)) {+			printf ("Programming error.\n");+			rc = ERR_PROG_ERROR;+			goto outahere; 		}--	} while (!chip);--	*addr = CMD_READ_ARRAY;--	if (chip == ERR || *addr != data) 		rc = ERR_PROG_ERROR;+		goto outahere;+	} -	if (iflag)-		enable_interrupts ();+outahere:+	/* read array command */+	*addr = 0xFF; -	if (cflag)-		icache_enable ();+	if (flag)+		enable_interrupts ();  	return rc; }@@ -371,9 +494,9 @@ int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt) { 	ulong cp, wp;+	ushort data; 	int l; 	int i, rc;-	ushort data;  	wp = (addr & ~1);	/* get lower word aligned address */ @@ -394,7 +517,7 @@ 			data = (data >> 8) | (*(uchar *) cp << 8); 		} -		if ((rc = write_hword (info, wp, data)) != 0) {+		if ((rc = write_word (info, wp, data)) != 0) { 			return (rc); 		} 		wp += 2;@@ -405,7 +528,7 @@ 	 */ 	while (cnt >= 2) { 		data = *((vu_short *) src);-		if ((rc = write_hword (info, wp, data)) != 0) {+		if ((rc = write_word (info, wp, data)) != 0) { 			return (rc); 		} 		src += 2;@@ -429,5 +552,5 @@ 		data = (data >> 8) | (*(uchar *) cp << 8); 	} -	return write_hword (info, wp, data);+	return write_word (info, wp, data); }diff -uNr u-boot-1.2.0/board/smdk2410/lowlevel_init.S bootloader/u-boot-1.2.0/board/smdk2410/lowlevel_init.S--- u-boot-1.2.0/board/smdk2410/lowlevel_init.S	2007-01-07 07:13:11.000000000 +0800+++ bootloader/u-boot-1.2.0/board/smdk2410/lowlevel_init.S	2007-04-24 15:09:06.000000000 +0800@@ -56,7 +56,7 @@ #define B3_BWSCON	  	(DW16 + WAIT + UBLB) #define B4_BWSCON	  	(DW16) #define B5_BWSCON	  	(DW16)-#define B6_BWSCON	  	(DW32)+#define B6_BWSCON	  	(DW16) #define B7_BWSCON	  	(DW32)  /* BANK0CON */diff -uNr u-boot-1.2.0/board/smdk2410/Makefile bootloader/u-boot-1.2.0/board/smdk2410/Makefile--- u-boot-1.2.0/board/smdk2410/Makefile	2007-01-07 07:13:11.000000000 +0800+++ bootloader/u-boot-1.2.0/board/smdk2410/Makefile	2007-04-24 15:04:23.000000000 +0800@@ -25,7 +25,7 @@  LIB	= $(obj)lib$(BOARD).a -COBJS	:= smdk2410.o flash.o+COBJS	:= smdk2410.o flash.o nand_read.o SOBJS	:= lowlevel_init.o  SRCS	:= $(SOBJS:.o=.S) $(COBJS:.o=.c)diff -uNr u-boot-1.2.0/board/smdk2410/smdk2410.c bootloader/u-boot-1.2.0/board/smdk2410/smdk2410.c--- u-boot-1.2.0/board/smdk2410/smdk2410.c	2007-01-07 07:13:11.000000000 +0800+++ bootloader/u-boot-1.2.0/board/smdk2410/smdk2410.c	2007-04-25 11:35:54.000000000 +0800@@ -121,3 +121,131 @@  	return 0; }+/*+   * NAND flash initialization.+   */+/*                                                                                +#if (CONFIG_COMMANDS & CFG_CMD_NAND)+typedef enum {+        NFCE_LOW,+        NFCE_HIGH+} NFCE_STATE;+                                                                                +extern unsigned long nand_probe(unsigned long physadr);+                                                                                +static inline void NF_Reset(void)+{+        int i;+                                                                                +        NF_SetCE(NFCE_LOW);+        NF_Cmd(0xFF); // reset command+        for(i = 0; i < 10; i++); // tWB = 100ns.+        NF_WaitRB(); // wait 200~500us;+        NF_SetCE(NFCE_HIGH);+}+static inline void NF_Init(void)+{+#if 0 // a little bit too optimistic+#define TACLS 0+#define TWRPH0 3+#define TWRPH1 0+#else+#define TACLS 0+#define TWRPH0 4+#define TWRPH1 2+#endif+                                                                                +        NF_Conf((1<<15)|(0<<14)|(0<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));+//      NF_Conf((1<<15)|(1<<14)|(1<<13)|(1<<12)|(1<<11)|(TACLS<<8)|(TWRPH0<<4)|(TWRPH1<<0));+        // 1  1    1     1,   1      xxx,  r xxx, r xxx+        // En 512B 4step ECCR nFCE=H tACLS   tWRPH0 tWRPH1+                                                                                +        NF_Reset();+}+void nand_init(void)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+        NF_Init();+        printf ("%4lu MB\n", nand_probe((ulong)nand) >> 20);+}+                                                                                +static  void NF_Conf(u16 conf)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        nand->NFCONF = conf;+}+                                                                                +static  void NF_Cmd(u8 cmd)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        nand->NFCMD = cmd;+}+                                                                                +static void NF_CmdW(u8 cmd)+{+        NF_Cmd(cmd);+        udelay(1);+}+                                                                                +static  void NF_Addr(u8 addr)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        nand->NFADDR = addr;+}+                                                                                +                                                                                +static  void NF_SetCE(NFCE_STATE s)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        switch (s) {+                case NFCE_LOW:+                        nand->NFCONF &= ~(1<<11);+                        break;+                                                                                +                case NFCE_HIGH:+                        nand->NFCONF |= (1<<11);+                        break;+        }+}+                                                                                +static void NF_WaitRB(void)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        while (!(nand->NFSTAT & (1<<0)));+}+                                                                                +static  void NF_Write(u8 data)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        nand->NFDATA = data;+}+                                                                                +static  u8 NF_Read(void)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        return(nand->NFDATA);+}+                                                                                +static  void NF_Init_ECC(void)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        nand->NFCONF |= (1<<12);+}+                                                                                +static  u32 NF_Read_ECC(void)+{+        S3C2410_NAND * const nand = S3C2410_GetBase_NAND();+                                                                                +        return(nand->NFECC);+}+                                                                                +#endif+*/diff -uNr u-boot-1.2.0/common/cmd_boot.c bootloader/u-boot-1.2.0/common/cmd_boot.c--- u-boot-1.2.0/common/cmd_boot.c	2007-01-07 07:13:11.000000000 +0800+++ bootloader/u-boot-1.2.0/common/cmd_boot.c	2007-04-24 15:04:23.000000000 +0800@@ -28,14 +28,15 @@ #include <command.h> #include <net.h> -#if defined(CONFIG_I386)+//#if defined(CONFIG_I386)	//HHTECH wk DECLARE_GLOBAL_DATA_PTR;-#endif+//#endif			//HHTECH wk  int do_go (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) { 	ulong	addr, rc; 	int     rcode = 0;+	struct param_struct *params = gd->bd->bi_boot_params;  	if (argc < 2) { 		printf ("Usage:\n%s\n", cmdtp->usage);@@ -56,9 +57,16 @@ 	 * to the global_data 	 */ 	argv[0] = (char *)gd;+ #endif #if !defined(CONFIG_NIOS)-	rc = ((ulong (*)(int, char *[]))addr) (--argc, &argv[1]);+/////////////////////////////////////HHTECH wk/////////////////////////+//	setup_linux_param(/*boot_mem_base*/0x30000000 + 0x100);+	params->u1.s.page_size = 4096;+	memcpy(params->commandline, CONFIG_BOOTARGS, strlen(CONFIG_BOOTARGS) + 1);

⌨️ 快捷键说明

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