Getting a mtd_info with a valid map.
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;
}Quoted 4 lines · Ken Gordon
I'm trying to read the serial number from my Intel Strataflash (J3) suing
mtd->read_user_prot_regandmtd->read_fact_prot_reg. This code below looks to me like it should do the job but explodes because themtd_inforeturned byget_mtd_devicehas a NULL priv field.
I don't understand. When the 'map' is NULL you still call mtd->read_user_prot_reg() anyway... doesn't it work?
What do you think that 'priv' is an abbreviation for, by the way? Under what circumstances do you think a programmer would name a variable like that? :)
Signature · 1 line
dwmw2
Quoted 2 lines
From
cfi_cmdset_0001.c
static int cfi_intelext_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *r
etlen, u_char *buf)
{
struct map_info *map = mtd->priv;
struct cfi_private *cfi = map->fldrv_priv; EXPODE HERE is map ==
NULL
struct cfi_pri_intelext *extp=cfi->cmdset_priv;
int base_offst,reg_sz;
/* Check that we actually have some protection registers */
if(!(extp->FeatureSupport&64)){
printk(KERN_WARNING "%s: This flash device has no protection data to
read!\n",map->name);
return 0;
}
base_offst=(1<<extp->FactProtRegSize);
reg_sz=(1<<extp->UserProtRegSize);
return cfi_intelext_read_prot_reg(mtd, from, len, retlen, buf,base_offst, reg_sz);
}
----- Original Message -----
From: "David Woodhouse" <[email protected]>
To: "Ken Gordon" <[email protected]>
Cc: <[email protected]>
Sent: Wednesday, June 18, 2003 11:54 AM
Subject: Re: Getting a mtd_info with a valid map.
Quoted 2 lines · Ken Gordon
Quoted 1 line
I'm trying to read the serial number from my Intel Strataflash (J3)
suing
Quoted 1 line
Quoted 1 line
mtd->read_user_prot_regandmtd->read_fact_prot_reg. This code below
looks
Quoted 1 line
Quoted 1 line
to me like it should do the job but explodes because the
mtd_info
returned
Quoted 12 lines
Quoted 1 line
by
get_mtd_devicehas a NULL priv field.I don't understand. When the 'map' is NULL you still call
mtd->read_user_prot_reg()anyway... doesn't it work?What do you think that 'priv' is an abbreviation for, by the way? Under what circumstances do you think a programmer would name a variable like that? :)
Signature · 1 line
dwmw2
Quoted 2 lines · Ken Gordon
Quoted 2 lines
From
cfi_cmdset_0001.c
Good. And now look into devices/*.c and figure out, what mtd->priv means for those. Why again do you think, it was called priv and not map?
Jörn
Signature · 4 lines
To announce that there must be no criticism of the President, or that we are to stand by the President, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public. -- Theodore Roosevelt, Kansas City Star, 1918
Quoted 1 line · Ken Gordon
Quoted 1 line
From
cfi_cmdset_0001.c
Oh, I see. Do you have a version of mtdpart.c older than v1.28 then?
Signature · 1 line
dwmw2
I do. It is 1.27. So I should be getting newer sources then?
Ken
----- Original Message -----
From: "David Woodhouse" <[email protected]>
To: "Ken Gordon" <[email protected]>
Cc: <[email protected]>
Sent: Wednesday, June 18, 2003 12:33 PM
Subject: Re: Getting a mtd_info with a valid map.
Quoted 8 lines · Ken Gordon
Quoted 1 line
Quoted 1 line
From
cfi_cmdset_0001.cOh, I see. Do you have a version of
mtdpart.colder than v1.28 then?Signature · 1 line
dwmw2
Quoted 1 line · Ken Gordon
I do. It is 1.27. So I should be getting newer sources then?
Please don't top-post. Yes, you should be getting newer sources. v1.28 fixed this bug.
Signature · 1 line
dwmw2