2 famicom ROM cartridge utility - unagi
5 Copyright (C) 2008-2009 ±·³«È¯¶¨Æ±Áȹç
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 flashmemory.c ¤À¤±¤Î·Ù¹ð
22 ¤³¤Î¥½¡¼¥¹¥³¡¼¥É¤ò»²¹Í¡¢Å¾ÍѤ·¤Æ¥·¥§¥¢¥¦¥§¥¢¤Ê¤É¤ÇÍø±×¤òÆÀ¤Ê¤¤¤³¤È¡£
23 ȽÌÀ¤·¤¿¾ì¹ç¤Ï LGPL ¤¬Å¬ÍѤµ¤ì¡¢³ºÅö²Õ½ê¤Î¥½¡¼¥¹¤ò¸ø³«¤¹¤ëɬÍפ¬¤¢¤ë¡£
32 #include "flashmemory.h"
38 static void sram_erase(const struct flash_order *d)
40 //bank ÀÚ¤êÂؤ¨¤¬È¼¤¦¤Î¤Ç¼ÂÁõ¤Ç¤¤Ê¤¤
44 static void init_nop(const struct flash_order *d, long wait)
48 static void init_erase(const struct flash_order *d, long wait)
50 assert(d->pagesize > 0);
51 d->erase(d->command_2aaa, true);
55 static void program_dummy(const struct flash_order *d, long address, long length, const struct memory *m)
58 static void program_sram(const struct flash_order *d, long address, long length, const struct memory *m)
60 d->write(address, length, m->data);
62 static void program_flash(const struct flash_order *d, long address, long length, const struct memory *m)
64 d->program(address, length, m->data, true, false);
70 const struct flash_driver FLASH_DRIVER_UNDEF = {
78 .productid_check = NULL,
82 static const struct flash_driver DRIVER_SRAM = {
88 .id_manufacurer = FLASH_ID_DEVICE_SRAM,
89 .id_device = FLASH_ID_DEVICE_SRAM,
90 // .productid_check = productid_sram,
92 .program = program_sram
95 static const struct flash_driver DRIVER_DUMMY = {
97 .capacity = 16 * MEGA,
101 .id_manufacurer = FLASH_ID_DEVICE_DUMMY,
102 .id_device = FLASH_ID_DEVICE_DUMMY,
103 // .productid_check = productid_sram,
105 .program = program_dummy
108 static const struct flash_driver DRIVER_W29C020 = {
110 .capacity = 2 * MEGA,
113 .command_mask = 0x7fff,
114 .id_manufacurer = 0xda,
116 // .productid_check = productid_check,
118 .program = program_flash
121 static const struct flash_driver DRIVER_W29C040 = {
123 .capacity = 4 * MEGA,
126 .command_mask = 0x7fff,
127 .id_manufacurer = 0xda,
129 // .productid_check = productid_check,
131 .program = program_flash
134 static const struct flash_driver DRIVER_W49F002 = {
136 .capacity = 2 * MEGA,
138 .erase_wait = 100, //typ 0.1, max 0.2 sec
139 .command_mask = 0x7fff,
140 .id_manufacurer = 0xda,
142 // .productid_check = productid_check,
144 .program = program_flash
148 MANUFATUTER ID 0x7f1c
149 EN29F002T DEVICE ID 0x7f92
150 EN29F002B DEVICE ID 0x7f97
152 command address ¤¬ 0x00555, 0x00aaa ¤Ë¤Ê¤Ã¤Æ¤ë
154 static const struct flash_driver DRIVER_EN29F002T = {
156 .capacity = 2 * MEGA,
158 .erase_wait = 2000, //typ 2, max 5 sec
159 .command_mask = 0x07ff,
160 .id_manufacurer = 0x1c,
162 // .productid_check = productid_check,
164 .program = program_flash
167 static const struct flash_driver DRIVER_AM29F040B = {
169 .capacity = 4 * MEGA,
171 .erase_wait = 8000, //typ 8, max 64 sec
172 .command_mask = 0x07ff,
173 .id_manufacurer = 0x01,
175 // .productid_check = productid_check,
177 .program = program_flash
180 static const struct flash_driver DRIVER_MBM29F080A = {
181 .name = "MBM29F080A",
182 .capacity = 8 * MEGA,
184 .erase_wait = 8000, //chip erase time is not written in datasheet!!
185 .command_mask = 0x07ff,
186 .id_manufacurer = 0x04,
188 // .productid_check = productid_check,
190 .program = program_flash
193 static const struct flash_driver *DRIVER_LIST[] = {
194 &DRIVER_W29C020, &DRIVER_W29C040,
195 &DRIVER_W49F002, &DRIVER_EN29F002T, &DRIVER_AM29F040B, &DRIVER_MBM29F080A,
201 const struct flash_driver *flash_driver_get(const char *name)
203 const struct flash_driver **d;
206 if(strcmp(name, (*d)->name) == 0){