📄 blkmem.c
字号:
printk(".");#ifdef CONFIG_LEDMAN if (i & 1) { ledman_cmd(LEDMAN_CMD_OFF, LEDMAN_NVRAM_1); ledman_cmd(LEDMAN_CMD_ON, LEDMAN_NVRAM_2); } else { ledman_cmd(LEDMAN_CMD_ON, LEDMAN_NVRAM_1); ledman_cmd(LEDMAN_CMD_OFF, LEDMAN_NVRAM_2); }#endif#if 0 printk("%s(%d): PROGRAM BLOCK min=%x max=%x\n", __FILE__, __LINE__, (int) min, (int) max);#endif for (ptr = min; (ptr < max); ptr += 2, w++) { offset = (ptr - a->address) % a->unitsize; base = ptr - offset;#if 0 printk("%s(%d): PROGRAM base=%x offset=%x ptr=%x value=%x\n", __FILE__, __LINE__, (int) base, (int) offset, (int) ptr, (int) *w);#endif *((volatile unsigned short *) (base | (0x555 << 1))) = 0xaaaa; *((volatile unsigned short *) (base | (0x2aa << 1))) = 0x5555; *((volatile unsigned short *) (base | (0x555 << 1))) = 0xa0a0; *((volatile unsigned short *) ptr) = *w; for (j = 0; (j < FTIMEOUT); j++) { status = *((volatile unsigned short *) ptr); if (status == *w) { /* Program complete */ break; } } status = *((volatile unsigned short *) ptr); if (status != *w) { printk("FLASH: (%d) write failed, addr=%x val=%x status=%x cnt=%d\n", __LINE__, (int) ptr, *w, status, j); /* Reset FLASH unit */ *((volatile unsigned short *) ptr) = 0xf0f0; failures++; } } }#ifdef CONFIG_LEDMAN ledman_cmd(LEDMAN_CMD_RESET, LEDMAN_NVRAM_1); ledman_cmd(LEDMAN_CMD_RESET, LEDMAN_NVRAM_2);#endif if (failures > 0) { printk("FLASH: %d failures programming FLASH!\n", failures); return; }#if 0 printk("\nFLASH: programming successful!\n");#endif if (prog->reset) { printk("FLASH: rebooting...\n\n"); HARD_RESET_NOW(); }}#endif /* !CONFIG_FLASH8BIT *//****************************************************************************//* INTEL FLASH *//****************************************************************************/#if defined(CONFIG_INTELFLASH)#if defined(CONFIG_FLASH16BIT) typedef unsigned short itype;#else typedef unsigned char itype;#endif/* * FLASH erase routine for the Intel Strata FLASH. */void flash_intel_erase(struct arena_t *a, unsigned long pos){ volatile itype *address; unsigned long fbase = a->address; unsigned long flags; itype status; int i; #if 0 printk("%s(%d): flash_intel_erase(a=%x,pos=%x)\n", __FILE__, __LINE__, (int) a, (int) pos);#endif if (pos >= a->length) return;#ifdef CONFIG_LEDMAN ledman_cmd(LEDMAN_CMD_OFF, (pos&0x20000) ? LEDMAN_NVRAM_1 : LEDMAN_NVRAM_2); ledman_cmd(LEDMAN_CMD_ON, (pos&0x20000) ? LEDMAN_NVRAM_2 : LEDMAN_NVRAM_1);#endif address = (volatile itype *) (fbase + pos); /* Mutex all access to FLASH memory */ down(&spare_lock); save_flags(flags); cli();#if defined(CONFIG_WATCHDOG) watchdog_disable();#endif#if 0 /* add this in if you want sectors unlocked as you erase them */ /* Unlock this sector */ *address = 0x60; *address = 0xd0; for (i = 0; (i < FTIMEOUT); i++) { status = *address; if (status & 0x80) break; } /* Restore FLASH to normal read mode */ *address = 0xff;#endif *address = 0x20; *address = 0xd0; for (i = 0; (i < FTIMEOUT); i++) { status = *address; if (status & 0x80) break; } /* Restore FLASH to normal read mode */ *address = 0xff; if (*address != (itype) 0xffff) { printk("FLASH: (%d): erase failed, address %p iteration=%d " "status=%x\n", __LINE__, address, i, (int) status); }#if defined(CONFIG_WATCHDOG) watchdog_enable();#endif restore_flags(flags); up(&spare_lock);}/* * FLASH programming routine for Intel Strata FLASH. */void flash_intel_write(struct arena_t * a, unsigned long pos, unsigned long length, char * buffer){ unsigned long flags, ptr, min, max; itype *lp, *lp0, status; int failures, j, k, l; #if 0 printk("%s(%d): flash_intel_write(a=%x,pos=%x,length=%d,buf=%x)\n", __FILE__, __LINE__, (int) a, (int) pos, (int) length, (int) buffer);#endif down(&spare_lock);#if defined(CONFIG_WATCHDOG) watchdog_disable();#endif min = (a->address + pos); max = min + length; lp = (itype *) buffer; for (ptr = min; (ptr < max); ptr += l) { save_flags(flags); cli(); /* Determine write size */ lp0 = lp; j = max - ptr; l = (j < 32) ? j : 32; if ((ptr & ~0x1f) != ptr) { j = 32 - (ptr & 0x1f); l = (l < j) ? l : j; } /* Program next buffer bytes */ for (j = 0; (j < FTIMEOUT); j++) { *((volatile itype *) ptr) = 0xe8; status = *((volatile itype *) ptr); if (status & 0x80) break; } if ((status & 0x80) == 0) goto writealldone; *((volatile itype *) ptr) = (l-1)/sizeof(itype); for (j = 0; j < l; j += sizeof(itype)) *((volatile itype *) (ptr+j)) = *lp++; *((volatile itype *) ptr) = 0xd0; for (j = 0; (j < FTIMEOUT); j++) { status = *((volatile itype *) ptr); if (status & 0x80) { /* Program complete */ break; } }writealldone: /* Restore FLASH to normal read mode */ *((volatile itype *) ptr) = 0xff; for (k = 0; k < l; k += sizeof(itype), lp0++) { status = *((volatile itype *) (ptr+k)); if (status != *lp0) { printk("FLASH: (%d): write failed, addr=%08x wrote=%x " "read=%x cnt=%d len=%d\n", __LINE__, (int) (ptr+k), (int) *lp0, (int) status, j, l); failures++; } } restore_flags(flags); }#if defined(CONFIG_WATCHDOG) watchdog_enable();#endif up(&spare_lock);}#if 0/* * Slow FLASH programming routine for Intel Strata FLASH. */void flash_intel_writeslow(struct arena_t * a, unsigned long pos, unsigned long length, char * buffer){ volatile unsigned char *address; unsigned long flags, fbase = a->address; unsigned char *lbuf, status; int i; #if 0 printk("%s(%d): flash_intel_write(a=%x,pos=%x,length=%d,buf=%x)\n", __FILE__, __LINE__, (int) a, (int) pos, (int) length, (int) buffer);#endif down(&spare_lock);#if defined(CONFIG_WATCHDOG) watchdog_disable();#endif address = (unsigned volatile char *) (fbase + pos); lbuf = (unsigned char *) buffer; for (; (length > 0); length--, address++, lbuf++) { if (*address != *lbuf) { save_flags(flags); cli(); *address = 0x40; *address = *lbuf; for (i = 0; (i < FTIMEOUT); i++) { status = *address; if (status & 0x80) { /* Program complete */ break; } } /* Restore FLASH to normal read mode */ *address = 0xff; if (*address != *lbuf) { printk("FLASH: (%d): write failed i=%d, address %p -> %x(%x)\n", __LINE__, i, address, (int) *lbuf, (int) *address); } restore_flags(flags); } }#if defined(CONFIG_WATCHDOG) watchdog_enable();#endif up(&spare_lock);}#endif/* * Program a complete FLASH image into an Intel Strata FLASH part. * This runs from DRAM, so no need to worry about writing to what * we are running from... */void flash_intel_writeall(struct arena_t * a, struct blkmem_program_t * prog){ unsigned long erased[16]; unsigned long base, offset, ptr, min, max; unsigned char *lp, *lp0, status; int failures, i, j, k, l;#if defined(CONFIG_WATCHDOG) watchdog_disable();#endif#if 0 printk("FLASH: programming");#endif failures = 0; memset(&erased[0], 0, sizeof(erased)); cli(); for (i = 0; (i < prog->blocks); i++) {#if 0 printk("%s(%d): block=%d address=%x pos=%x length=%x range=%x-%x\n", __FILE__, __LINE__, i, (int) a->address, (int) prog->block[i].pos, (int) prog->block[i].length, (int) (prog->block[i].pos + a->address), (int) (prog->block[i].pos + prog->block[i].length - 1 + a->address));#endif /* * Erase FLASH sectors for this program block... */ for (l = prog->block[i].pos / a->blksize; l <= ((prog->block[i].pos+prog->block[i].length-1) / a->blksize); l++) { if (erased[(l / 32)] & (0x1 << (l % 32))) continue; ptr = l * a->blksize; offset = ptr % a->unitsize; base = ptr - offset; base += a->address; ptr += a->address; j = 0;#if 0 printk("%s(%d): ERASE BLOCK sector=%d ptr=%x\n", __FILE__, __LINE__, l, (int) ptr);#endif /* Erase this sector */ *((volatile unsigned char *) ptr) = 0x20; *((volatile unsigned char *) ptr) = 0xd0; for (k = 0; (k < FTIMEOUT); k++) { status = *((volatile unsigned char *) ptr); if (status & 0x80) { /* Erase complete */ status = *((volatile unsigned char *) ptr); break; } } /* Restore FLASH to normal read mode */ *((volatile unsigned char *) ptr) = 0xff; if (k >= FTIMEOUT) { printk("FLASH: (%d) erase failed, status=%08x\n", __LINE__, (int) status); failures++; /* Continue (with unerased sector) */ break; } erased[(l / 32)] |= (0x1 << (l % 32)); } /* * Program FLASH with the block data... */ min = prog->block[i].pos+a->address; max = prog->block[i].pos+prog->block[i].length+a->address; lp = (unsigned char *) prog->block[i].data; /* Progress indicators... */ printk(".");#ifdef CONFIG_LEDMAN ledman_cmd(LEDMAN_CMD_OFF, (i & 1) ? LEDMAN_NVRAM_1 : LEDMAN_NVRAM_2); ledman_cmd(LEDMAN_CMD_ON, (i & 1) ? LEDMAN_NVRAM_2 : LEDMAN_NVRAM_1);#endif#if 0 printk("%s(%d): PROGRAM BLOCK min=%x max=%x\n", __FILE__, __LINE__, (int) min, (int) max);#endif for (ptr = min; (ptr < max); ptr += l) { /* Determine write size */ lp0 = lp; j = max - ptr; l = (j < 32) ? j : 32; if ((ptr & ~0x1f) != ptr) { j = 32 - (ptr & 0x1f); l = (l < j) ? l : j; }#if 0 printk("%s(%d): PROGRAM ptr=%x l=%d\n", __FILE__, __LINE__, (int) ptr, l);#endif /* Program next buffer bytes */ for (j = 0; (j < FTIMEOUT); j++) { *((volatile unsigned char *) ptr) = 0xe8; status = *((volatile unsigned char *) ptr); if (status & 0x80) break; } if ((status & 0x80) == 0) goto intelwritealldone; *((volatile unsigned char *) ptr) = (l-1); for (j = 0; (j < l); j++) *((volatile unsigned char *) (ptr+j)) = *lp++; *((volatile unsigned char *) ptr) = 0xd0; for (j = 0; (j < FTIMEOUT); j++) { status = *((volatile unsigned char *) ptr); if (status & 0x80) { /* Program complete */ break; } }intelwritealldone: /* Restore FLASH to normal read mode */ *((volatile unsigned char *) ptr) = 0xff; for (k = 0; (k < l); k++, lp0++) { status = *((volatile unsigned char *) (ptr+k)); if (status != *lp0) { printk("FLASH: (%d): write failed, addr=%08x wrote=%02x " "read=%02x cnt=%d len=%d\n", __LINE__, (int) (ptr+k), (int) *lp0, (int) status, j, l); failures++; } } } }#ifdef CONFIG_LEDMAN ledman_cmd(LEDMAN_CMD_RESET, LEDMAN_NVRAM_1); ledman_cmd(LEDMAN_CMD_RESET, LEDMAN_NVRAM_2);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -