1 diff -urN linux-2.6.17/drivers/mtd/maps/imghdr.h linux-2.6.17.new/drivers/mtd/maps/imghdr.h
2 --- linux-2.6.17/drivers/mtd/maps/imghdr.h 1970-01-01 01:00:00.000000000 +0100
3 +++ linux-2.6.17.new/drivers/mtd/maps/imghdr.h 2006-09-24 20:29:20.000000000 +0200
8 +#define GTIMG_MAGIC "GMTK"
11 +#define PID_RTL_AIRGO 1
12 +#define PID_RTL_RALINK 2
13 +#define PID_RDC_AIRGO 3
14 +#define PID_RDC_RALINK 5 /* White Lable */
19 + UINT8 magic[4]; /* ASICII: GMTK */
20 + UINT32 checksum; /* CRC32 */
21 + UINT32 version; /* x.x.x.x */
22 + UINT32 kernelsz; /* The size of the kernel image */
23 + UINT32 imagesz; /* The length of this image file ( kernel + romfs + this header) */
24 + UINT32 pid; /* Product ID */
25 + UINT32 fastcksum; /* Partial CRC32 on (First(256), medium(256), last(512)) */
30 diff -urN linux-2.6.17/drivers/mtd/maps/Kconfig linux-2.6.17.new/drivers/mtd/maps/Kconfig
31 --- linux-2.6.17/drivers/mtd/maps/Kconfig 2006-06-18 03:49:35.000000000 +0200
32 +++ linux-2.6.17.new/drivers/mtd/maps/Kconfig 2006-09-24 20:28:11.000000000 +0200
34 PNC-2000 is the name of Network Camera product from PHOTRON
35 Ltd. in Japan. It uses CFI-compliant flash.
38 + tristate "CFI Flash devcie mapped on RDC3210"
39 + depends on X86 && MTD_CFI && MTD_PARTITIONS
41 + RDC-3210 is the flash device we find on Ralink reference board
44 tristate "CFI Flash device mapped on AMD SC520 CDP"
45 depends on X86 && MTD_CFI
46 diff -urN linux-2.6.17/drivers/mtd/maps/Makefile linux-2.6.17.new/drivers/mtd/maps/Makefile
47 --- linux-2.6.17/drivers/mtd/maps/Makefile 2006-06-18 03:49:35.000000000 +0200
48 +++ linux-2.6.17.new/drivers/mtd/maps/Makefile 2006-09-24 20:26:10.000000000 +0200
50 obj-$(CONFIG_MTD_PHYSMAP) += physmap.o
51 obj-$(CONFIG_MTD_PNC2000) += pnc2000.o
52 obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o
53 +obj-$(CONFIG_MTD_RDC3210) += rdc3210.o
54 obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o
55 obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o
56 obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o
57 diff -urN linux-2.6.17/drivers/mtd/maps/rdc3210.c linux-2.6.17.new/drivers/mtd/maps/rdc3210.c
58 --- linux-2.6.17/drivers/mtd/maps/rdc3210.c 1970-01-01 01:00:00.000000000 +0100
59 +++ linux-2.6.17.new/drivers/mtd/maps/rdc3210.c 2006-09-24 22:55:20.000000000 +0200
61 +/*******************************************************************
62 + * Simple Flash mapping for RDC3210 *
65 + * Dante Su (dante_su@gemtek.com.tw) *
66 + * Copyright (C) 2005 Gemtek Corporation *
67 + *******************************************************************/
69 +#include <linux/module.h>
70 +#include <linux/slab.h>
71 +#include <linux/types.h>
72 +#include <linux/kernel.h>
74 +#include <linux/mtd/mtd.h>
75 +#include <linux/mtd/map.h>
76 +#include <linux/mtd/partitions.h>
77 +#include <linux/autoconf.h>
79 +#define WINDOW_ADDR 0xFFC00000
80 +#define WINDOW_SIZE 0x00400000
84 +static struct mtd_info *rdc3210_mtd_info;
86 +__u8 rdc3210_map_read8(struct map_info *map, unsigned long ofs)
88 + return *(__u8 *)(map->map_priv_1 + ofs);
91 +__u16 rdc3210_map_read16(struct map_info *map, unsigned long ofs)
93 + return *(__u16 *)(map->map_priv_1 + ofs);
96 +__u32 rdc3210_map_read32(struct map_info *map, unsigned long ofs)
98 + return *(__u32 *)(map->map_priv_1 + ofs);
101 +void rdc3210_map_write8(struct map_info *map, __u8 d, unsigned long adr)
103 + *(__u8 *)(map->map_priv_1 + adr) = d;
106 +void rdc3210_map_write16(struct map_info *map, __u16 d, unsigned long adr)
108 + *(__u16 *)(map->map_priv_1 + adr) = d;
111 +void rdc3210_map_write32(struct map_info *map, __u32 d, unsigned long adr)
113 + *(__u32 *)(map->map_priv_1 + adr) = d;
116 +void rdc3210_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
119 + u16 *dst = (u16 *)(to);
120 + u16 *src = (u16 *)(map->map_priv_1 + from);
122 + for(i = 0; i < (len / 2); ++i)
127 + printk("# WARNNING!!! rdc3210_map_copy_from has odd length\n");
128 + //dst[len - 1] = B0(src[i]);
132 +void rdc3210_map_copy_to(struct map_info *map, void *to, unsigned long from, ssize_t len)
135 + u16 *dst = (u16 *)(map->map_priv_1 + to);
136 + u16 *src = (u16 *)(from);
138 + for(i = 0; i < (len / 2); ++i)
143 + printk("# WARNNING!!! rdc3210_map_copy_from has odd length\n");
144 + //dst[len - 1] = B0(src[i]);
148 +static struct map_info rdc3210_map =
150 + .name = "RDC3210 Flash",
151 + .size = WINDOW_SIZE,
152 + .bankwidth = BUSWIDTH,
153 + .phys = WINDOW_ADDR,
156 +/* Dante: This is the default static mapping, however this is nothing but a hint. (Say dynamic mapping) */
157 +static struct mtd_partition rdc3210_parts[] =
159 + { .name = "linux", .offset = 0, .size = 0x003C0000 }, /* 3840 KB = (Kernel + ROMFS) = (768 KB + 3072 KB) */
160 + { .name = "romfs", .offset = 0x000C0000, .size = 0x00300000 }, /* 3072 KB */
161 + { .name = "nvram", .offset = 0x003C0000, .size = 0x00010000 }, /* 64 KB */
162 + { .name = "factory", .offset = 0x003D0000, .size = 0x00010000 }, /* 64 KB */
163 + { .name = "bootldr", .offset = 0x003E0000, .size = 0x00020000 }, /* 128 KB */
166 +static int __init rdc3210_mtd_init(void)
168 + printk(KERN_NOTICE "flash device: 0x%x at 0x%x\n", WINDOW_SIZE, WINDOW_ADDR);
170 + rdc3210_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
172 + if (!rdc3210_map.virt)
174 + printk("Failed to ioremap\n");
178 + simple_map_init(&rdc3210_map);
180 + rdc3210_mtd_info = do_map_probe("cfi_probe", &rdc3210_map);
181 + /* Dante: This is for fixed map */
182 + if (rdc3210_mtd_info)
184 + rdc3210_mtd_info->owner = THIS_MODULE;
185 + add_mtd_partitions(rdc3210_mtd_info, rdc3210_parts, sizeof(rdc3210_parts)/sizeof(rdc3210_parts[0]));
188 + /* Dante: This is for dynamic mapping */
190 + if (rdc3210_mtd_info)
195 + hdr = (gt_imghdr_t *)(rdc3210_map.virt);
197 + if(memcmp(hdr->magic, GTIMG_MAGIC, 4))
199 + printk("Invalid MAGIC for Firmware Image!!!\n");
203 + /* 1. Adjust Redboot */
204 + tmp = flashdrv_get_size() - rdc3210_parts[4].size;
205 + rdc3210_parts[4].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
206 + rdc3210_parts[4].size = flashdrv_get_size() - rdc3210_parts[4].offset;
208 + /* 2. Adjust NVRAM */
209 + tmp -= rdc3210_parts[3].size;
210 + rdc3210_parts[3].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
211 + rdc3210_parts[3].size = rdc3210_parts[4].offset - rdc3210_parts[3].offset;
213 + /* 3. Adjust Factory Default */
214 + tmp -= rdc3210_parts[2].size;
215 + rdc3210_parts[2].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
216 + rdc3210_parts[2].size = rdc3210_parts[3].offset - rdc3210_parts[2].offset;
218 + /* 4. Adjust Linux (Kernel + ROMFS) */
219 + rdc3210_parts[0].size = rdc3210_parts[2].offset - rdc3210_parts[0].offset;
221 + /* 5. Adjust ROMFS */
222 + tmp = hdr->kernelsz + sizeof(gt_imghdr_t);
223 + rdc3210_parts[1].offset = rdc3210_parts[0].offset + (((tmp / 32) + ((tmp % 32) ? 1 : 0)) * 32);
224 + rdc3210_parts[1].size = rdc3210_parts[2].offset - rdc3210_parts[1].offset;
226 + /* 1. Adjust Redboot */
227 + tmp = flashdrv_get_size() - rdc3210_parts[3].size;
228 + rdc3210_parts[3].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
229 + rdc3210_parts[3].size = flashdrv_get_size() - rdc3210_parts[3].offset;
231 + /* 2. Adjust NVRAM */
232 + tmp -= rdc3210_parts[2].size;
233 + rdc3210_parts[2].offset = flashdrv_get_sector_addr(flashdrv_get_sector(tmp));
234 + rdc3210_parts[2].size = rdc3210_parts[3].offset - rdc3210_parts[2].offset;
236 + /* 4. Adjust Linux (Kernel + ROMFS) */
237 + rdc3210_parts[0].size = rdc3210_parts[2].offset - rdc3210_parts[0].offset;
239 + /* 5. Adjust ROMFS */
240 + tmp = hdr->kernelsz + sizeof(gt_imghdr_t);
241 + rdc3210_parts[1].offset = rdc3210_parts[0].offset + (((tmp / 32) + ((tmp % 32) ? 1 : 0)) * 32);
242 + rdc3210_parts[1].size = rdc3210_parts[2].offset - rdc3210_parts[1].offset;
244 + rdc3210_mtd_info->owner = THIS_MODULE;
245 + add_mtd_partitions(rdc3210_mtd_info, rdc3210_parts, sizeof(rdc3210_parts)/sizeof(rdc3210_parts[0]));
249 + iounmap((void *)rdc3210_map.virt);
253 +static void __exit rdc3210_mtd_exit(void)
255 + if (rdc3210_mtd_info)
257 + del_mtd_partitions(rdc3210_mtd_info);
258 + map_destroy(rdc3210_mtd_info);
261 + if (rdc3210_map.virt)
263 + iounmap(rdc3210_map.virt);
264 + rdc3210_map.virt = 0;
268 +module_init(rdc3210_mtd_init);
269 +module_exit(rdc3210_mtd_exit);
270 +MODULE_LICENSE("GPL");