Getting a mtd_info with a valid map.
Ken Gordon
kengordon at magneticscrolls.com
Wed Jun 18 06:45:54 EDT 2003
I'm trying to read the serial number from my Intel Strataflash (J3) suing
mtd->read_user_prot_reg and mtd->read_fact_prot_reg. This code below looks
to me like it should do the job but explodes because the mtd_info returned
by get_mtd_device has a NULL priv field.
Adding printk's into drivers/mtd/chips/cfi_probe.c I see an mtd_info being
created (not the one I get) and filled in with a valid priv pointing at a
map.
I'm a bit confused since mtd_info seem to refer to named partitions but I'm
after a per set of flash chips physical sort of thing. Am I am on the wrong
planet?
It looks like I could keep hold of the mtd_info that is returned to the
original probe in my file in drivers/mtd/maps but SURELY that isn't the way.
Ken
PS This is using linux 2.4.19-rmk6-pxa1
static int handle_proc_flashid(char *page,
char **start, off_t requested_offset,
int requested_len, int *eof, void *data)
{
int len = 0; /* which means that the bottom 4 bits are inverted */
char buf[1024]; /* wrt what is written on the bits !!*/
char *p = buf;
int f[4], s[4];
struct mtd_info *mtd = get_mtd_device(NULL, 0);
if (!mtd) {
sprintf(buf, "unable to get mtd device!\n");
} else {
// int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len,
size_t *retlen, u_char
*buf);
size_t slen=0, flen=0;
int sret = -1, fret = -1;
struct map_info *map;
struct cfi_private *cfi;
struct cfi_pri_intelext *extp;
printk("about to get mtd->priv & is %x mtd is %x\n", &mtd->priv,
mtd);
map = mtd->priv;
printk("map %x\n", map); // map is ALWAYS 0 here - boo
hoo!
if (map) {
cfi = map->fldrv_priv;
printk("cfi %x\n", cfi);
if (cfi) {
extp=cfi->cmdset_priv;
printk("extp %x\n", extp);
}
}
printk("fn ptrs %x %x\n", mtd->read_user_prot_reg,
mtd->read_fact_prot_reg);
printk("name: %s\n", mtd->name);
if (mtd->read_user_prot_reg)
sret = mtd->read_user_prot_reg(mtd, 0, sizeof(s), &slen,
(unsigned char *)s);
printk("done user\n");
if (mtd->read_user_prot_reg)
fret = mtd->read_fact_prot_reg(mtd, 0, sizeof(f), &flen,
(unsigned char *)f);
printk("done fact\n");
sprintf(buf, "flen %d slen %d factory id =
%08x:%08x:%08x:%08x\nsystem id = %08x:%08x:%08x:%
08x\n",
flen, slen, f[0], f[1], f[2], f[3], s[0], s[1], s[2],
s[3]);
}
if (strlen(buf) < requested_len) {
strcpy(page, buf);
*start = page + requested_offset;
len = strlen(*start);
} else
*page = 0;
if (mtd)
put_mtd_device(mtd);
return len;
}
More information about the linux-mtd
mailing list