📄 nand_write_yaffs.patch
字号:
diff -uNr u-boot-1.2.0/board/smdk2410/config.mk bootloader/u-boot-1.2.0/board/smdk2410/config.mk--- u-boot-1.2.0/board/smdk2410/config.mk 2007-01-07 07:13:11.000000000 +0800+++ bootloader/u-boot-1.2.0/board/smdk2410/config.mk 2007-04-24 15:08:47.000000000 +0800@@ -22,4 +22,4 @@ # -TEXT_BASE = 0x33F80000+TEXT_BASE = 0x31F80000diff -uNr u-boot-1.2.0/board/smdk2410/flash.c bootloader/u-boot-1.2.0/board/smdk2410/flash.c--- u-boot-1.2.0/board/smdk2410/flash.c 2007-01-07 07:13:11.000000000 +0800+++ bootloader/u-boot-1.2.0/board/smdk2410/flash.c 2007-04-24 15:04:23.000000000 +0800@@ -1,7 +1,12 @@ /*- * (C) Copyright 2002- * Sysgo Real-Time Solutions, GmbH <www.elinos.com>- * Alex Zuepke <azu@sysgo.de>+ * (C) Copyright 2005+ * Greg Ungerer, OpenGear Inc, greg.ungerer@opengear.com+ *+ * (C) Copyright 2001+ * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net+ *+ * (C) Copyright 2001+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de. * * See file CREDITS for list of people who contributed to this * project.@@ -23,114 +28,89 @@ */ #include <common.h>+#include <linux/byteorder/swab.h> -ulong myflush (void);---#define FLASH_BANK_SIZE PHYS_FLASH_SIZE-#define MAIN_SECT_SIZE 0x10000 /* 64 KB */--flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; +flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */ -#define CMD_READ_ARRAY 0x000000F0-#define CMD_UNLOCK1 0x000000AA-#define CMD_UNLOCK2 0x00000055-#define CMD_ERASE_SETUP 0x00000080-#define CMD_ERASE_CONFIRM 0x00000030-#define CMD_PROGRAM 0x000000A0-#define CMD_UNLOCK_BYPASS 0x00000020+#define mb() __asm__ __volatile__ ("" : : : "memory") -#define MEM_FLASH_ADDR1 (*(volatile u16 *)(CFG_FLASH_BASE + (0x00000555 << 1)))-#define MEM_FLASH_ADDR2 (*(volatile u16 *)(CFG_FLASH_BASE + (0x000002AA << 1)))--#define BIT_ERASE_DONE 0x00000080-#define BIT_RDY_MASK 0x00000080-#define BIT_PROGRAM_ERROR 0x00000020-#define BIT_TIMEOUT 0x80000000 /* our flag */--#define READY 1-#define ERR 2-#define TMO 4+/*-----------------------------------------------------------------------+ * Functions+ */+static ulong flash_get_size (unsigned char * addr, flash_info_t * info);+static int write_data (flash_info_t * info, ulong dest, unsigned char data);+//static int write_word (flash_info_t * info, ulong dest, ushort data)+static void flash_get_offsets (ulong base, flash_info_t * info);+void inline spin_wheel (void); /*----------------------------------------------------------------------- */ -ulong flash_init (void)+unsigned long flash_init (void) {- int i, j;+ int i; ulong size = 0; for (i = 0; i < CFG_MAX_FLASH_BANKS; i++) {- ulong flashbase = 0;-- flash_info[i].flash_id =-#if defined(CONFIG_AMD_LV400)- (AMD_MANUFACT & FLASH_VENDMASK) |- (AMD_ID_LV400B & FLASH_TYPEMASK);-#elif defined(CONFIG_AMD_LV800)- (AMD_MANUFACT & FLASH_VENDMASK) |- (AMD_ID_LV800B & FLASH_TYPEMASK);-#else-#error "Unknown flash configured"-#endif- flash_info[i].size = FLASH_BANK_SIZE;- flash_info[i].sector_count = CFG_MAX_FLASH_SECT;- memset (flash_info[i].protect, 0, CFG_MAX_FLASH_SECT);- if (i == 0)- flashbase = PHYS_FLASH_1;- else+ switch (i) {+ case 0:+ flash_info[i].flash_id = (INTEL_MANUFACT & FLASH_VENDMASK) | (INTEL_ID_28F128J3A & FLASH_TYPEMASK);+ flash_get_size ((unsigned char *) PHYS_FLASH_1, &flash_info[i]);+ flash_get_offsets (PHYS_FLASH_1, &flash_info[i]);+ break;+ case 1:+ /* ignore for now */+ flash_info[i].flash_id = FLASH_UNKNOWN;+ break;+ default: panic ("configured too many flash banks!\n");- for (j = 0; j < flash_info[i].sector_count; j++) {- if (j <= 3) {- /* 1st one is 16 KB */- if (j == 0) {- flash_info[i].start[j] =- flashbase + 0;- }-- /* 2nd and 3rd are both 8 KB */- if ((j == 1) || (j == 2)) {- flash_info[i].start[j] =- flashbase + 0x4000 + (j -- 1) *- 0x2000;- }-- /* 4th 32 KB */- if (j == 3) {- flash_info[i].start[j] =- flashbase + 0x8000;- }- } else {- flash_info[i].start[j] =- flashbase + (j - 3) * MAIN_SECT_SIZE;- }+ break; } size += flash_info[i].size; } + /* Protect monitor and environment sectors+ */ flash_protect (FLAG_PROTECT_SET, CFG_FLASH_BASE,- CFG_FLASH_BASE + monitor_flash_len - 1,+ CFG_FLASH_BASE + _bss_start - _armboot_start, &flash_info[0]); - flash_protect (FLAG_PROTECT_SET,- CFG_ENV_ADDR,- CFG_ENV_ADDR + CFG_ENV_SIZE - 1, &flash_info[0]);- return size; } /*----------------------------------------------------------------------- */+static void flash_get_offsets (ulong base, flash_info_t * info)+{+ int i;++ if (info->flash_id == FLASH_UNKNOWN)+ return;++ if ((info->flash_id & FLASH_VENDMASK) == FLASH_MAN_INTEL) {+ for (i = 0; i < info->sector_count; i++) {+ info->start[i] = base + (i * PHYS_FLASH_SECT_SIZE);+ info->protect[i] = 0;+ }+ }+}++/*-----------------------------------------------------------------------+ */ void flash_print_info (flash_info_t * info) { int i; + if (info->flash_id == FLASH_UNKNOWN) {+ printf ("missing or unknown FLASH type\n");+ return;+ }+ switch (info->flash_id & FLASH_VENDMASK) {- case (AMD_MANUFACT & FLASH_VENDMASK):- printf ("AMD: ");+ case FLASH_MAN_INTEL:+ printf ("INTEL "); break; default: printf ("Unknown Vendor ");@@ -138,15 +118,11 @@ } switch (info->flash_id & FLASH_TYPEMASK) {- case (AMD_ID_LV400B & FLASH_TYPEMASK):- printf ("1x Amd29LV400BB (4Mbit)\n");- break;- case (AMD_ID_LV800B & FLASH_TYPEMASK):- printf ("1x Amd29LV800BB (8Mbit)\n");+ case FLASH_28F128J3A:+ printf ("28F128J3\n"); break; default: printf ("Unknown Chip Type\n");- goto Done; break; } @@ -154,40 +130,104 @@ info->size >> 20, info->sector_count); printf (" Sector Start Addresses:");- for (i = 0; i < info->sector_count; i++) {- if ((i % 5) == 0) {+ 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 (" %08lX%s",+ info->start[i], info->protect[i] ? " (RO)" : " "); } printf ("\n");+ return;+}++/*+ * The following code cannot be run from FLASH!+ */+static ulong flash_get_size (unsigned char * addr, flash_info_t * info)+{+ volatile unsigned char value;++ /* Write auto select command: read Manufacturer ID */+ addr[0x5555] = 0xAA;+ addr[0x2AAA] = 0x55;+ addr[0x5555] = 0x90;++ mb ();+ //value = addr[0];+ value = (unsigned char)INTEL_MANUFACT;++ switch (value) {++ case (unsigned char)INTEL_MANUFACT:+ info->flash_id = FLASH_MAN_INTEL;+ break;++ default:+ info->flash_id = FLASH_UNKNOWN;+ info->sector_count = 0;+ info->size = 0;+ addr[0] = 0xFF; /* restore read mode */+ return (0); /* no or unknown flash */+ }++ mb ();+ //value = addr[2]; /* device ID */+ value = (unsigned char)INTEL_ID_28F128J3A; /* device ID */++ switch (value) {++ case (unsigned char)INTEL_ID_28F640J3A:+ info->flash_id += FLASH_28F640J3A;+ info->sector_count = 64;+ info->size = 0x00800000;+ break; /* => 8 MB */++ case (unsigned char)INTEL_ID_28F128J3A:+ info->flash_id += FLASH_28F128J3A;+ info->sector_count = 128;+ info->size = 0x01000000;+ break; /* => 16 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] = 0xFF; /* restore read mode */ - Done:;+ return (info->size); } + /*----------------------------------------------------------------------- */ int flash_erase (flash_info_t * info, int s_first, int s_last) {- ushort result;- int iflag, cflag, prot, sect;- int rc = ERR_OK;- int chip;-- /* first look for protection bits */-- if (info->flash_id == FLASH_UNKNOWN)- return ERR_UNKNOWN_FLASH_TYPE;+ int flag, prot, sect;+ ulong type;+ 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) !=- (AMD_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;@@ -196,116 +236,194 @@ prot++; } }+ if (prot)- return ERR_PROTECTED;+ printf ("- Warning: %d protected sectors will not be erased!\n", prot);+ else+ printf ("\n"); - /*- * 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 ();+ /* Disable interrupts which might cause a timeout here */+ flag = disable_interrupts (); /* Start erase on unprotected sectors */- for (sect = s_first; sect <= s_last && !ctrlc (); sect++) {- printf ("Erasing sector %2d ... ", sect);-- /* arm simple, non interrupt dependent timer */- reset_timer_masked ();-+ for (sect = s_first; sect <= s_last; sect++) { if (info->protect[sect] == 0) { /* not protected */- vu_short *addr = (vu_short *) (info->start[sect]);+ volatile unsigned char *addr;+ unsigned char 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 */- chip = 0;+ addr = (volatile unsigned char *) (info->start[sect]);+ *addr = 0x50; /* clear status register */+ *addr = 0x20; /* erase setup */+ *addr = 0xD0; /* erase confirm */ - do {- result = *addr;-- /* check timeout */+ while (((status = *addr) & 0x80) != 0x80) { if (get_timer_masked () > CFG_FLASH_ERASE_TOUT) {- MEM_FLASH_ADDR1 = CMD_READ_ARRAY;- chip = TMO;+ printf ("Timeout\n");+ *addr = 0xB0; /* suspend erase */+ *addr = 0xFF; /* reset to read mode */+ rcode = 1; break; }+ } - if (!chip- && (result & 0xFFFF) & BIT_ERASE_DONE)- chip = READY;+ *addr = 0x50; /* clear status register cmd */+ *addr = 0xFF; /* resest to read mode */ - if (!chip- && (result & 0xFFFF) & BIT_PROGRAM_ERROR)- chip = ERR;+ printf (" done\n");+ }+ }+ return rcode;+} - } while (!chip);+/*-----------------------------------------------------------------------+ * Copy memory to flash, returns:+ * 0 - OK+ * 1 - write timeout+ * 2 - Flash not erased+ * 4 - Flash not identified+ */ - MEM_FLASH_ADDR1 = CMD_READ_ARRAY;+#if 0 +int write_buff (flash_info_t * info, uchar * src, ulong addr, ulong cnt)+{+ ulong cp, wp;+ unsigned char data;+ int count, i, l, rc, port_width; - if (chip == ERR) {- rc = ERR_PROG_ERROR;- goto outahere;- }- if (chip == TMO) {- rc = ERR_TIMOUT;- goto outahere;- }+ if (info->flash_id == FLASH_UNKNOWN)+ return 4; - printf ("ok.\n");- } else { /* it was protected */+ wp = addr;+ port_width = 1; - printf ("protected!\n");+ /*+ * handle unaligned start bytes+ */+ if ((l = addr - wp) != 0) {+ data = 0;+ for (i = 0, cp = wp; i < l; ++i, ++cp) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -