📄 blkmem.c
字号:
* snapgear image. We've got a disproportionately large config area which * we've splatted to the end of the flash, rather than the start. This lets * us adjust sizes more easily later but hurts if we change flash size. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (1792k) * rom5 -- FLASH config file-system (192k) * rom6 -- FLASH the whole damn thing (2Mb)! * rom7 -- FLASH spare block (32k) */ {1,0xf0000000,0x004000,flash_writeall, 0, 0, 0, 0x04000,0x004000,0xff}, {1,0xf0004000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0006000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0010000,0x1c0000,flash_writeall, 0, 0, 0, 0x10000,0x1e0000,0xff}, {1,0xf01d0000,0x030000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0000000,0x200000,flash_writeall, 0, 0, 0, 0x10000,0x200000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff},#elif defined(CONFIG_FLASH_SNAPGEAR)#if defined(CONFIG_FLASH8MB)/* * SnapGear hardware with 8MB FLASH. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (128k) * rom2 -- FLASH boot arguments (128k) * rom3 -- FLASH MAC addresses (128k) * rom4 -- FLASH kernel+file-system binary (7mb) * rom5 -- FLASH config file-system (512k) * rom6 -- FLASH the whole damn thing (8Mb)! * rom7 -- FLASH spare block (128k) */ {1,0xf0000000,0x020000,flash_writeall, 0, 0, 0, 0x20000,0x020000,0xff}, {1,0xf0020000,0x020000,0,0,flash_write,flash_erase,0x20000,0x020000,0xff}, {1,0xf0040000,0x020000,0,0,flash_write,flash_erase,0x20000,0x020000,0xff}, {1,0xf0100000,0x700000,flash_writeall, 0, 0, 0, 0x20000,0x700000,0xff}, {1,0xf0080000,0x080000,0,0,flash_write,flash_erase,0x20000,0x080000,0xff}, {1,0xf0000000,0x800000,flash_writeall, 0, 0, 0, 0x20000,0x800000,0xff}, {1,0xf0060000,0x020000,flash_writeall,0,flash_write,flash_erase,0x20000,0x02000,0xff},#if defined(CONFIG_EXTRA_FLASH)/* * rom8 -- FLASH extra. */ {1,0xf0800000,0x800000,flash_writeall, 0, 0, 0, 0x10000,0x800000,0xff},#endif /* CONFIG_EXTRA_FLASH */#elif defined(CONFIG_FLASH4MB)/* * SnapGear hardware with 4MB FLASH. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (3920k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (4Mb)! * rom7 -- FLASH spare block (32k) */ {1,0xf0000000,0x004000,flash_writeall, 0, 0, 0, 0x04000,0x004000,0xff}, {1,0xf0004000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0006000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0020000,0x3e0000,flash_writeall, 0, 0, 0, 0x10000,0x3e0000,0xff}, {1,0xf0010000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0000000,0x400000,flash_writeall, 0, 0, 0, 0x10000,0x400000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff},#if defined(CONFIG_EXTRA_FLASH)/* * rom8 -- FLASH extra. */ {1,0xf0400000,0x400000,flash_writeall, 0, 0, 0, 0x10000,0x400000,0xff},#endif /* CONFIG_EXTRA_FLASH */#elif defined(CONFIG_FLASH2MB)/* * SnapGear hardware with primary 2MB FLASH. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (1920k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (2Mb)! * rom7 -- FLASH spare block (32k) */ {1,0xf0000000,0x004000,flash_writeall, 0, 0, 0, 0x04000,0x004000,0xff}, {1,0xf0004000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0006000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0020000,0x1e0000,flash_writeall, 0, 0, 0, 0x10000,0x1e0000,0xff}, {1,0xf0010000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0000000,0x200000,flash_writeall, 0, 0, 0, 0x10000,0x200000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff},#if defined(CONFIG_EXTRA_FLASH)/* * rom8 -- FLASH extra. */ {1,0xf0200000,0x200000,flash_writeall, 0, 0, 0, 0x10000,0x200000,0xff},#endif /* CONFIG_EXTRA_FLASH */#else/* * SnapGear hardware FLASH erase/program entry points (1MB FLASH). * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (896k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (1Mb)! * rom7 -- FLASH spare block (32k) */ {1,0xf0000000,0x04000,flash_writeall, 0, 0, 0, 0x04000,0x04000,0xff}, {1,0xf0004000,0x02000,0,0,flash_write,flash_erase,0x02000,0x02000,0xff}, {1,0xf0006000,0x02000,0,0,flash_write,flash_erase,0x02000,0x02000,0xff}, {1,0xf0010000,0xe0000,flash_writeall, 0, 0, 0, 0x10000,0xe0000,0xff}, {1,0xf00f0000,0x10000,0,0,flash_write,flash_erase,0x10000,0x10000,0xff}, {1,0xf0000000,0x100000,flash_writeall, 0, 0, 0, 0x10000,0x100000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff},#if defined(CONFIG_EXTRA_FLASH)/* * rom8 -- FLASH extra. where the NETtel3540 stores the dsl image */ {1,0xf0100000,0x100000,flash_writeall, 0, 0, 0, 0x10000,0x100000,0xff},#endif /* CONFIG_EXTRA_FLASH */#endif /* CONFIG_FLASH2MB */#endif /* CONFIG_FLASH_SNAPGEAR */#if defined(CONFIG_HW_FEITH)#if defined(CONFIG_CLEOPATRA) || defined(CONFIG_SCALES)/* * CLEOPATRA with 2MB/4MB FLASH erase/program entry points. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (16k) * rom2 -- FLASH boot arguments (8k) * rom3 -- FLASH MAC addresses (8k) * rom4 -- FLASH kernel+file-system binary (1792k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (2Mb)! * rom7 -- FLASH spare block (32k) * rom8 -- FLASH application config (128k) * rom9 -- FLASH user block (1536k) (4MB only) * rom10-- FLASH user block (512k) (4MB only) * rom11-- FLASH user block (2048k) (6MB only) */ {1,0xf0000000,0x004000,flash_writeall, 0, 0, 0, 0x04000,0x004000,0xff}, {1,0xf0004000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0006000,0x002000,0,0,flash_write,flash_erase,0x02000,0x002000,0xff}, {1,0xf0020000,0x1c0000,flash_writeall, 0, 0, 0, 0x10000,0x1c0000,0xff}, {1,0xf0010000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0000000,0x200000,flash_writeall, 0, 0, 0, 0x10000,0x200000,0xff}, {1,0xf0008000,0x08000,flash_writeall,0,flash_write,flash_erase,0x08000,0x08000,0xff}, {1,0xf01e0000,0x020000,0,0,flash_write,flash_erase,0x10000,0x020000,0xff},#if defined(CONFIG_FLASH4MB) {1,0xf0200000,0x180000,0,0,flash_write,flash_erase,0x10000,0x180000,0xff}, {1,0xf0380000,0x080000,0,0,flash_write,flash_erase,0x10000,0x080000,0xff},#endif#if defined(CONFIG_FLASH6MB) {1,0xf0200000,0x180000,0,0,flash_write,flash_erase,0x10000,0x180000,0xff}, {1,0xf0380000,0x080000,0,0,flash_write,flash_erase,0x10000,0x080000,0xff}, // old settings {1,0xf0400000,0x200000,0,0,flash_write,flash_erase,0x10000,0x200000,0xff}, // new settings// {1,0xf0410000,0x040000,flash_writeall,0, flash_write,flash_erase,0x10000,0x040000,0xff},// {1,0xf0450000,0x1b0000,0,0,flash_write,flash_erase,0x10000,0x1b0000,0xff},#endif#endif /* CONFIG_CLEOPATRA || CONFIG_SCALES */#if defined(CONFIG_CANCam)/* * CanCam with 8MB FLASH erase/program entry points. * The following devices are supported: * rom0 -- root file-system (actually in RAM) * rom1 -- FLASH boot block (64k) * rom2 -- FLASH boot arguments (64k) * rom3 -- FLASH MAC addresses (64k) * rom4 -- FLASH kernel+file-system binary (1728k) * rom5 -- FLASH config file-system (64k) * rom6 -- FLASH the whole damn thing (8Mb)! * rom7 -- FLASH spare block (64k) * rom8 -- FLASH user block (6MB) */ {1,0xf0000000,0x010000,flash_writeall, 0, 0, 0, 0x10000,0x010000,0xff}, {1,0xf0010000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0020000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0050000,0x1b0000,flash_writeall, 0, 0, 0, 0x10000,0x1b0000,0xff}, {1,0xf0040000,0x010000,0,0,flash_write,flash_erase,0x10000,0x010000,0xff}, {1,0xf0000000,0x800000,flash_writeall, 0, 0, 0, 0x10000,0x800000,0xff}, {1,0xf0030000,0x010000,flash_writeall,0,flash_write,flash_erase,0x10000,0x10000,0xff}, {1,0xf0200000,0x600000,0,0,flash_write,flash_erase,0x10000,0x600000,0xff},#endif /* CONFIG_CanCam */#endif /* CONFIG_HW_FEITH */#endif /* CONFIG_COLDFIRE */#ifdef CONFIG_SHGLCORE#ifdef CONFIG_SHGLCORE_2MEG {0, 0x0A0000, 0x200000-0x0A0000}, /* ROM FS */ {1, SHGLCORE_FLASH_BANK_0_ADDR, 0x80000, 0, 0, write_spare, erase_spare, 0x10000, 0x80000, 0xff}, {1, 0x000000, 0x200000, program_main, 0,0,0, 0x20000, 0x100000}, /* All main FLASH */#else {0, 0x0A0000, 0x100000-0x0A0000}, /* ROM FS */ {1, SHGLCORE_FLASH_BANK_0_ADDR, 0x80000, 0, 0, write_spare, erase_spare, 0x10000, 0x80000, 0xff}, {1, 0x000000, 0x100000, program_main, 0,0,0, 0x20000, 0x100000}, /* All main FLASH */#endif#define FIXUP_ARENAS \ extern unsigned long rom_length; \ arena[0].length = (unsigned long)rom_length - 0xA0000; \ arena[2].length = (unsigned long)rom_length;#endif};#define arenas (sizeof(arena) / sizeof(struct arena_t))static int blkmem_blocksizes[arenas];static int blkmem_sizes[arenas];static devfs_handle_t devfs_handle;#if defined(CONFIG_ARNEWSH) || defined(CONFIG_M5206eC3)static DECLARE_MUTEX(spare_lock);/* * FLASH erase and programming routines for the odd/even FLASH * pair on the ColdFire eval boards. */void flash_amd8_pair_write(struct arena_t * a, unsigned long pos, unsigned long length, char * buffer){ volatile unsigned short *address; unsigned short *wbuf, word; unsigned short result, prevresult; unsigned long flags, start; unsigned long fbase = a->address; int i; #if 0 printk("%s(%d): flash_amd8_pair_write(a=%x,pos=%x,length=%d,buf=%x)\n", __FILE__, __LINE__, (int) a, (int) pos, (int) length, (int) buffer);#endif down(&spare_lock); start = jiffies; address = (unsigned volatile short *) (fbase + pos); wbuf = (unsigned short *) buffer; for (length >>= 1; (length > 0); length--, address++) { word = *wbuf++; if (*address != word) { save_flags(flags); cli(); *((unsigned volatile short *) (fbase | (0x5555 << 1))) = 0xaaaa; *((unsigned volatile short *) (fbase | (0x2aaa << 1))) = 0x5555; *((unsigned volatile short *) (fbase | (0x5555 << 1))) = 0xa0a0; *address = word; udelay(1); /* Wait for write to complete, timeout after a few tries */ for (prevresult = 0, i = 0; (i < 0x10000); i++) { result = *address; if ((result & 0x8080) == (word & 0x8080)) break; if ((result & 0x4040) == (prevresult & 0x4040)) break; prevresult = result; } if (*address != word) { printk("%s(%d): FLASH write failed, address %p, write value %x" " (now %x, previous %x), count=%d\n", __FILE__, __LINE__, address, word, *address, prevresult, i); printk("%s(%d): count=%d word=%x prevresult=%x result=%x\n", __FILE__, __LINE__, i, word, prevresult, result); *((unsigned volatile short *) fbase) = 0xf0f0; /* Reset */ } restore_flags(flags); } } up(&spare_lock);}void flash_amd8_pair_erase(struct arena_t * a, unsigned long pos){ unsigned volatile short *address; unsigned short result; unsigned long fbase = a->address; unsigned long flags; #if 0 printk("%s(%d): flash_amd8_pair_erase(): addr:%x, len:%x, pos:%x\n", __FILE__, __LINE__, a->address, a->length, pos);#endif if (pos >= a->length) return; address = (unsigned volatile short *) (fbase + pos); /* Mutex all access to FLASH memory */ down(&spare_lock); save_flags(flags); cli(); /* Initiate erase of FLASH sector */#ifdef CONFIG_ARN5206 *((unsigned volatile short *) (fbase | (0x5555 << 1))) = 0xaaaa; *((unsigned volatile short *) (fbase | (0x2aaa << 1))) = 0x5555; *((unsigned volatile short *) (fbase | (0x5555 << 1))) = 0x8080; *((unsigned volatile short *) (fbase | (0x5555 << 1))) = 0xaaaa; *((unsigned volatile short *) (fbase | (0x2aaa << 1))) = 0x5555; *address = 0x3030;#else *((unsigned volatile short *) (fbase | (0x0555 << 1))) = 0xaaaa;/*first*/ *((unsigned volatile short *) (fbase | (0x02aa << 1))) = 0x5555;/*second*/ *((unsigned volatile short *) (fbase | (0x0555 << 1))) = 0x8080;/*third*/ *((unsigned volatile short *) (fbase | (0x0555 << 1))) = 0xaaaa;/*fourth*/ *((unsigned volatile short *) (fbase | (0x02aa << 1))) = 0x5555;/*fifth*/ *address = 0x3030; /* sixth (0x30 to sector address) */#endif for (;;) { result = *address;/* printk("result: %x\n", result); */ if ((result & 0x8080) == 0x8080) break; /* sucessful erase */ if (((result & 0xff00) != 0xff00) && (result & 0x2000)) { printk("%s(%d): erase failed: high byte, address %p\n", __FILE__, __LINE__, address); *((unsigned volatile short *) fbase) = 0xf0f0; /* Reset */ break; } if (((result & 0x00ff) != 0x00ff) && (result & 0x0020)) { printk("%s(%d): erase failed: low byte, address %p\n", __FILE__, __LINE__, address); *((unsigned volatile short *) fbase) = 0xf0f0; /* Reset */ break; } } restore_flags(flags); up(&spare_lock);}#endif /* CONFIG_ARNEWSH || CONFIG_M5206eC3 *//****************************************************************************//* SNAPGEAR FLASH SUPPORT *//****************************************************************************/#if defined(CONFIG_FLASH_SNAPGEAR) || defined(CONFIG_HW_FEITH) || defined(CONFIG_M5272C3) || defined(CONFIG_COBRA5272)static DECLARE_MUTEX(spare_lock);/* * Offsets to support the small boot segments of bottom booter flash. */unsigned long flash_bootsegs[] = {#if defined(CONFIG_FLASH4MB) /* This supports the AMD 29lv320 -- 8 * 8k segments */ 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000, 0x2000,#else /* This supports the AMD 29lv800, 29lv160, etc -- 16k + 8k + 8k + 32k */ 0x4000, 0x2000, 0x2000, 0x8000,#endif};#if defined(CONFIG_FLASH2MB)#define FLASHMASK 0x001fffff#elif defined(CONFIG_FLASH4MB)#define FLASHMASK 0x003fffff#elif defined(CONFIG_FLASH8MB)#define FLASHMASK 0x007fffff#elif defined(CONFIG_FLASH16MB)#define FLASHMASK 0x00ffffff#else#define FLASHMASK 0x000fffff#endif/* * Support erasing and dumping to scratch FLASH segment. */unsigned long flash_dumpoffset = 0;void flash_erasedump(void){ flash_erase(arena + 7, 0);}void flash_writedump(char *buf, int len){ flash_write(arena + 7, 0, len, (char *) buf);}/****************************************************************************//* AMD 8bit FLASH *//****************************************************************************/#if defined(CONFIG_FLASH8BIT)/* * FLASH erase routine for the AMD 29LVX00 family devices. */static void flash_amd8_erase(struct arena_t *a, unsigned long pos){ unsigned volatile char *address; unsigned long fbase = a->address; unsigned long flags; unsigned char status; int i; #if 0 printk("%s(%d): flash_amd8_erase(a=%x,pos=%x)\n", __FILE__, __LINE__, (int) a, (int) pos);#endif if (pos >= a->length) return; address = (unsigned volatile char *) (fbase + pos); /* Mutex all access to FLASH memory */ down(&spare_lock); save_flags(flags); cli();#if defined(CONFIG_WATCHDOG) watchdog_disable();#endif /* Erase this sector */ *((volatile unsigned char *) (fbase | 0xaaa)) = 0xaa; *((volatile unsigned char *) (fbase | 0x555)) = 0x55; *((volatile unsigned char *) (fbase | 0xaaa)) = 0x80; *((volatile unsigned char *) (fbase | 0xaaa)) = 0xaa; *((volatile unsigned char *) (fbase | 0x555)) = 0x55; *address = 0x30; for (i = 0; (i < FTIMEOUT); i++) { status = *address; if ((status & 0x80) || (status & 0x20)) break; } if (*address != 0xff) { printk("%s(%d): FLASH erase failed, address %p iteration=%d status=%x\n", __FILE__, __LINE__, address, i, status); *((unsigned volatile char *) fbase) = 0xf0; /* Reset */ }#if defined(CONFIG_WATCHDOG) watchdog_enable();#endif restore_flags(flags); up(&spare_lock);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -