Merge branch 'for-next/cfi-flash'
This commit is contained in:
commit
021dda6744
|
@ -20,6 +20,16 @@ config MTD_RAW_DEVICE
|
|||
default n
|
||||
prompt "mtdraw device to read/write both data+oob"
|
||||
|
||||
config MTD_CONCAT
|
||||
bool
|
||||
prompt "MTD concatenating support"
|
||||
help
|
||||
Support for concatenating several MTD devices into a single
|
||||
(virtual) one. This allows you to have -for example- a JFFS(2)
|
||||
file system spanning multiple physical flash chips. This option
|
||||
needs driver support, currently only the cfi-flash driver supports
|
||||
concatenating MTD devices.
|
||||
|
||||
source "drivers/mtd/devices/Kconfig"
|
||||
source "drivers/mtd/nor/Kconfig"
|
||||
source "drivers/mtd/nand/Kconfig"
|
||||
|
|
|
@ -6,3 +6,4 @@ obj-y += devices/
|
|||
obj-$(CONFIG_MTD) += core.o partition.o
|
||||
obj-$(CONFIG_MTD_OOB_DEVICE) += mtdoob.o
|
||||
obj-$(CONFIG_MTD_RAW_DEVICE) += mtdraw.o
|
||||
obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
|
||||
|
|
|
@ -0,0 +1,765 @@
|
|||
/*
|
||||
* MTD device concatenation layer
|
||||
*
|
||||
* Copyright © 2002 Robert Kaiser <rkaiser@sysgo.de>
|
||||
* Copyright © 2002-2010 David Woodhouse <dwmw2@infradead.org>
|
||||
*
|
||||
* NAND support by Christian Gan <cgan@iders.ca>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
#include <common.h>
|
||||
#include <malloc.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/concat.h>
|
||||
|
||||
#include <asm-generic/div64.h>
|
||||
|
||||
/*
|
||||
* Our storage structure:
|
||||
* Subdev points to an array of pointers to struct mtd_info objects
|
||||
* which is allocated along with this structure
|
||||
*
|
||||
*/
|
||||
struct mtd_concat {
|
||||
struct mtd_info mtd;
|
||||
int num_subdev;
|
||||
struct mtd_info **subdev;
|
||||
};
|
||||
|
||||
/*
|
||||
* how to calculate the size required for the above structure,
|
||||
* including the pointer array subdev points to:
|
||||
*/
|
||||
#define SIZEOF_STRUCT_MTD_CONCAT(num_subdev) \
|
||||
((sizeof(struct mtd_concat) + (num_subdev) * sizeof(struct mtd_info *)))
|
||||
|
||||
/*
|
||||
* Given a pointer to the MTD object in the mtd_concat structure,
|
||||
* we can retrieve the pointer to that structure with this macro.
|
||||
*/
|
||||
#define CONCAT(x) ((struct mtd_concat *)(x))
|
||||
|
||||
/*
|
||||
* MTD methods which look up the relevant subdevice, translate the
|
||||
* effective address and pass through to the subdevice.
|
||||
*/
|
||||
|
||||
static int
|
||||
concat_read(struct mtd_info *mtd, loff_t from, size_t len,
|
||||
size_t * retlen, u_char * buf)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
int ret = 0, err;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
size_t size, retsize;
|
||||
|
||||
if (from >= subdev->size) {
|
||||
/* Not destined for this subdev */
|
||||
size = 0;
|
||||
from -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
if (from + len > subdev->size)
|
||||
/* First part goes into this subdev */
|
||||
size = subdev->size - from;
|
||||
else
|
||||
/* Entire transaction goes into this subdev */
|
||||
size = len;
|
||||
|
||||
err = mtd_read(subdev, from, size, &retsize, buf);
|
||||
|
||||
/* Save information about bitflips! */
|
||||
if (unlikely(err)) {
|
||||
if (mtd_is_eccerr(err)) {
|
||||
mtd->ecc_stats.failed++;
|
||||
ret = err;
|
||||
} else if (mtd_is_bitflip(err)) {
|
||||
mtd->ecc_stats.corrected++;
|
||||
/* Do not overwrite -EBADMSG !! */
|
||||
if (!ret)
|
||||
ret = err;
|
||||
} else
|
||||
return err;
|
||||
}
|
||||
|
||||
*retlen += retsize;
|
||||
len -= size;
|
||||
if (len == 0)
|
||||
return ret;
|
||||
|
||||
buf += size;
|
||||
from = 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
concat_write(struct mtd_info *mtd, loff_t to, size_t len,
|
||||
size_t * retlen, const u_char * buf)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
int err = -EINVAL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
size_t size, retsize;
|
||||
|
||||
if (to >= subdev->size) {
|
||||
size = 0;
|
||||
to -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
if (to + len > subdev->size)
|
||||
size = subdev->size - to;
|
||||
else
|
||||
size = len;
|
||||
|
||||
err = mtd_write(subdev, to, size, &retsize, buf);
|
||||
if (err)
|
||||
break;
|
||||
|
||||
*retlen += retsize;
|
||||
len -= size;
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
err = -EINVAL;
|
||||
buf += size;
|
||||
to = 0;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static int
|
||||
concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
struct mtd_oob_ops devops = *ops;
|
||||
int i, err, ret = 0;
|
||||
|
||||
ops->retlen = ops->oobretlen = 0;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
|
||||
if (from >= subdev->size) {
|
||||
from -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* partial read ? */
|
||||
if (from + devops.len > subdev->size)
|
||||
devops.len = subdev->size - from;
|
||||
|
||||
err = mtd_read_oob(subdev, from, &devops);
|
||||
ops->retlen += devops.retlen;
|
||||
ops->oobretlen += devops.oobretlen;
|
||||
|
||||
/* Save information about bitflips! */
|
||||
if (unlikely(err)) {
|
||||
if (mtd_is_eccerr(err)) {
|
||||
mtd->ecc_stats.failed++;
|
||||
ret = err;
|
||||
} else if (mtd_is_bitflip(err)) {
|
||||
mtd->ecc_stats.corrected++;
|
||||
/* Do not overwrite -EBADMSG !! */
|
||||
if (!ret)
|
||||
ret = err;
|
||||
} else
|
||||
return err;
|
||||
}
|
||||
|
||||
if (devops.datbuf) {
|
||||
devops.len = ops->len - ops->retlen;
|
||||
if (!devops.len)
|
||||
return ret;
|
||||
devops.datbuf += devops.retlen;
|
||||
}
|
||||
if (devops.oobbuf) {
|
||||
devops.ooblen = ops->ooblen - ops->oobretlen;
|
||||
if (!devops.ooblen)
|
||||
return ret;
|
||||
devops.oobbuf += ops->oobretlen;
|
||||
}
|
||||
|
||||
from = 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int
|
||||
concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
struct mtd_oob_ops devops = *ops;
|
||||
int i, err;
|
||||
|
||||
if (!(mtd->flags & MTD_WRITEABLE))
|
||||
return -EROFS;
|
||||
|
||||
ops->retlen = ops->oobretlen = 0;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
|
||||
if (to >= subdev->size) {
|
||||
to -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* partial write ? */
|
||||
if (to + devops.len > subdev->size)
|
||||
devops.len = subdev->size - to;
|
||||
|
||||
err = mtd_write_oob(subdev, to, &devops);
|
||||
ops->retlen += devops.retlen;
|
||||
ops->oobretlen += devops.oobretlen;
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (devops.datbuf) {
|
||||
devops.len = ops->len - ops->retlen;
|
||||
if (!devops.len)
|
||||
return 0;
|
||||
devops.datbuf += devops.retlen;
|
||||
}
|
||||
if (devops.oobbuf) {
|
||||
devops.ooblen = ops->ooblen - ops->oobretlen;
|
||||
if (!devops.ooblen)
|
||||
return 0;
|
||||
devops.oobbuf += devops.oobretlen;
|
||||
}
|
||||
to = 0;
|
||||
}
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase)
|
||||
{
|
||||
int err;
|
||||
wait_queue_head_t waitq;
|
||||
|
||||
erase->mtd = mtd;
|
||||
erase->priv = (unsigned long) &waitq;
|
||||
|
||||
err = mtd_erase(mtd, erase);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int concat_erase(struct mtd_info *mtd, struct erase_info *instr)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
struct mtd_info *subdev;
|
||||
int i, err;
|
||||
uint64_t length, offset = 0;
|
||||
struct erase_info *erase;
|
||||
|
||||
/*
|
||||
* Check for proper erase block alignment of the to-be-erased area.
|
||||
* It is easier to do this based on the super device's erase
|
||||
* region info rather than looking at each particular sub-device
|
||||
* in turn.
|
||||
*/
|
||||
if (!concat->mtd.numeraseregions) {
|
||||
/* the easy case: device has uniform erase block size */
|
||||
if (instr->addr & (concat->mtd.erasesize - 1))
|
||||
return -EINVAL;
|
||||
if (instr->len & (concat->mtd.erasesize - 1))
|
||||
return -EINVAL;
|
||||
} else {
|
||||
/* device has variable erase size */
|
||||
struct mtd_erase_region_info *erase_regions =
|
||||
concat->mtd.eraseregions;
|
||||
|
||||
/*
|
||||
* Find the erase region where the to-be-erased area begins:
|
||||
*/
|
||||
for (i = 0; i < concat->mtd.numeraseregions &&
|
||||
instr->addr >= erase_regions[i].offset; i++) ;
|
||||
--i;
|
||||
|
||||
/*
|
||||
* Now erase_regions[i] is the region in which the
|
||||
* to-be-erased area begins. Verify that the starting
|
||||
* offset is aligned to this region's erase size:
|
||||
*/
|
||||
if (i < 0 || instr->addr & (erase_regions[i].erasesize - 1))
|
||||
return -EINVAL;
|
||||
|
||||
/*
|
||||
* now find the erase region where the to-be-erased area ends:
|
||||
*/
|
||||
for (; i < concat->mtd.numeraseregions &&
|
||||
(instr->addr + instr->len) >= erase_regions[i].offset;
|
||||
++i) ;
|
||||
--i;
|
||||
/*
|
||||
* check if the ending offset is aligned to this region's erase size
|
||||
*/
|
||||
if (i < 0 || ((instr->addr + instr->len) &
|
||||
(erase_regions[i].erasesize - 1)))
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* make a local copy of instr to avoid modifying the caller's struct */
|
||||
erase = kmalloc(sizeof (struct erase_info), GFP_KERNEL);
|
||||
|
||||
if (!erase)
|
||||
return -ENOMEM;
|
||||
|
||||
*erase = *instr;
|
||||
length = instr->len;
|
||||
|
||||
/*
|
||||
* find the subdevice where the to-be-erased area begins, adjust
|
||||
* starting offset to be relative to the subdevice start
|
||||
*/
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
subdev = concat->subdev[i];
|
||||
if (subdev->size <= erase->addr) {
|
||||
erase->addr -= subdev->size;
|
||||
offset += subdev->size;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* must never happen since size limit has been verified above */
|
||||
BUG_ON(i >= concat->num_subdev);
|
||||
|
||||
/* now do the erase: */
|
||||
err = 0;
|
||||
for (; length > 0; i++) {
|
||||
/* loop for all subdevices affected by this request */
|
||||
subdev = concat->subdev[i]; /* get current subdevice */
|
||||
|
||||
/* limit length to subdevice's size: */
|
||||
if (erase->addr + length > subdev->size)
|
||||
erase->len = subdev->size - erase->addr;
|
||||
else
|
||||
erase->len = length;
|
||||
|
||||
length -= erase->len;
|
||||
if ((err = concat_dev_erase(subdev, erase))) {
|
||||
/* sanity check: should never happen since
|
||||
* block alignment has been checked above */
|
||||
BUG_ON(err == -EINVAL);
|
||||
if (erase->fail_addr != 0xffffffff)
|
||||
instr->fail_addr = erase->fail_addr + offset;
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* erase->addr specifies the offset of the area to be
|
||||
* erased *within the current subdevice*. It can be
|
||||
* non-zero only the first time through this loop, i.e.
|
||||
* for the first subdevice where blocks need to be erased.
|
||||
* All the following erases must begin at the start of the
|
||||
* current subdevice, i.e. at offset zero.
|
||||
*/
|
||||
erase->addr = 0;
|
||||
offset += subdev->size;
|
||||
}
|
||||
instr->state = erase->state;
|
||||
kfree(erase);
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
if (instr->callback)
|
||||
instr->callback(instr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int concat_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
int i, err = -EINVAL;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
uint64_t size;
|
||||
|
||||
if (ofs >= subdev->size) {
|
||||
size = 0;
|
||||
ofs -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
if (ofs + len > subdev->size)
|
||||
size = subdev->size - ofs;
|
||||
else
|
||||
size = len;
|
||||
|
||||
err = mtd_lock(subdev, ofs, size);
|
||||
if (err)
|
||||
break;
|
||||
|
||||
len -= size;
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
err = -EINVAL;
|
||||
ofs = 0;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int concat_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
int i, err = 0;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
uint64_t size;
|
||||
|
||||
if (ofs >= subdev->size) {
|
||||
size = 0;
|
||||
ofs -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
if (ofs + len > subdev->size)
|
||||
size = subdev->size - ofs;
|
||||
else
|
||||
size = len;
|
||||
|
||||
err = mtd_unlock(subdev, ofs, size);
|
||||
if (err)
|
||||
break;
|
||||
|
||||
len -= size;
|
||||
if (len == 0)
|
||||
break;
|
||||
|
||||
err = -EINVAL;
|
||||
ofs = 0;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
int i, res = 0;
|
||||
|
||||
if (!mtd_can_have_bb(concat->subdev[0]))
|
||||
return res;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
|
||||
if (ofs >= subdev->size) {
|
||||
ofs -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
|
||||
res = mtd_block_isbad(subdev, ofs);
|
||||
break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
int i, err = -EINVAL;
|
||||
|
||||
for (i = 0; i < concat->num_subdev; i++) {
|
||||
struct mtd_info *subdev = concat->subdev[i];
|
||||
|
||||
if (ofs >= subdev->size) {
|
||||
ofs -= subdev->size;
|
||||
continue;
|
||||
}
|
||||
|
||||
err = mtd_block_markbad(subdev, ofs);
|
||||
if (!err)
|
||||
mtd->ecc_stats.badblocks++;
|
||||
break;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function constructs a virtual MTD device by concatenating
|
||||
* num_devs MTD devices. A pointer to the new device object is
|
||||
* stored to *new_dev upon success. This function does _not_
|
||||
* register any devices: this is the caller's responsibility.
|
||||
*/
|
||||
struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to concatenate */
|
||||
int num_devs, /* number of subdevices */
|
||||
const char *name)
|
||||
{ /* name for the new device */
|
||||
int i;
|
||||
size_t size;
|
||||
struct mtd_concat *concat;
|
||||
uint32_t max_erasesize, curr_erasesize;
|
||||
int num_erase_region;
|
||||
int max_writebufsize = 0;
|
||||
|
||||
printk(KERN_NOTICE "Concatenating MTD devices:\n");
|
||||
for (i = 0; i < num_devs; i++)
|
||||
printk(KERN_NOTICE "(%d): \"%s\"\n", i, subdev[i]->name);
|
||||
printk(KERN_NOTICE "into device \"%s\"\n", name);
|
||||
|
||||
/* allocate the device structure */
|
||||
size = SIZEOF_STRUCT_MTD_CONCAT(num_devs);
|
||||
concat = kzalloc(size, GFP_KERNEL);
|
||||
if (!concat) {
|
||||
printk
|
||||
("memory allocation error while creating concatenated device \"%s\"\n",
|
||||
name);
|
||||
return NULL;
|
||||
}
|
||||
concat->subdev = (struct mtd_info **) (concat + 1);
|
||||
|
||||
/*
|
||||
* Set up the new "super" device's MTD object structure, check for
|
||||
* incompatibilities between the subdevices.
|
||||
*/
|
||||
concat->mtd.type = subdev[0]->type;
|
||||
concat->mtd.flags = subdev[0]->flags;
|
||||
concat->mtd.size = subdev[0]->size;
|
||||
concat->mtd.erasesize = subdev[0]->erasesize;
|
||||
concat->mtd.writesize = subdev[0]->writesize;
|
||||
|
||||
for (i = 0; i < num_devs; i++)
|
||||
if (max_writebufsize < subdev[i]->writebufsize)
|
||||
max_writebufsize = subdev[i]->writebufsize;
|
||||
concat->mtd.writebufsize = max_writebufsize;
|
||||
|
||||
concat->mtd.subpage_sft = subdev[0]->subpage_sft;
|
||||
concat->mtd.oobsize = subdev[0]->oobsize;
|
||||
concat->mtd.oobavail = subdev[0]->oobavail;
|
||||
if (subdev[0]->read_oob)
|
||||
concat->mtd.read_oob = concat_read_oob;
|
||||
if (subdev[0]->write_oob)
|
||||
concat->mtd.write_oob = concat_write_oob;
|
||||
if (subdev[0]->block_isbad)
|
||||
concat->mtd.block_isbad = concat_block_isbad;
|
||||
if (subdev[0]->block_markbad)
|
||||
concat->mtd.block_markbad = concat_block_markbad;
|
||||
|
||||
concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks;
|
||||
|
||||
concat->subdev[0] = subdev[0];
|
||||
|
||||
for (i = 1; i < num_devs; i++) {
|
||||
if (concat->mtd.type != subdev[i]->type) {
|
||||
kfree(concat);
|
||||
printk("Incompatible device type on \"%s\"\n",
|
||||
subdev[i]->name);
|
||||
return NULL;
|
||||
}
|
||||
if (concat->mtd.flags != subdev[i]->flags) {
|
||||
/*
|
||||
* Expect all flags except MTD_WRITEABLE to be
|
||||
* equal on all subdevices.
|
||||
*/
|
||||
if ((concat->mtd.flags ^ subdev[i]->
|
||||
flags) & ~MTD_WRITEABLE) {
|
||||
kfree(concat);
|
||||
printk("Incompatible device flags on \"%s\"\n",
|
||||
subdev[i]->name);
|
||||
return NULL;
|
||||
} else
|
||||
/* if writeable attribute differs,
|
||||
make super device writeable */
|
||||
concat->mtd.flags |=
|
||||
subdev[i]->flags & MTD_WRITEABLE;
|
||||
}
|
||||
|
||||
concat->mtd.size += subdev[i]->size;
|
||||
concat->mtd.ecc_stats.badblocks +=
|
||||
subdev[i]->ecc_stats.badblocks;
|
||||
if (concat->mtd.writesize != subdev[i]->writesize ||
|
||||
concat->mtd.subpage_sft != subdev[i]->subpage_sft ||
|
||||
concat->mtd.oobsize != subdev[i]->oobsize ||
|
||||
!concat->mtd.read_oob != !subdev[i]->read_oob ||
|
||||
!concat->mtd.write_oob != !subdev[i]->write_oob) {
|
||||
kfree(concat);
|
||||
printk("Incompatible OOB or ECC data on \"%s\"\n",
|
||||
subdev[i]->name);
|
||||
return NULL;
|
||||
}
|
||||
concat->subdev[i] = subdev[i];
|
||||
|
||||
}
|
||||
|
||||
concat->mtd.ecclayout = subdev[0]->ecclayout;
|
||||
|
||||
concat->num_subdev = num_devs;
|
||||
concat->mtd.name = xstrdup(name);
|
||||
|
||||
concat->mtd.erase = concat_erase;
|
||||
concat->mtd.read = concat_read;
|
||||
concat->mtd.write = concat_write;
|
||||
concat->mtd.lock = concat_lock;
|
||||
concat->mtd.unlock = concat_unlock;
|
||||
|
||||
/*
|
||||
* Combine the erase block size info of the subdevices:
|
||||
*
|
||||
* first, walk the map of the new device and see how
|
||||
* many changes in erase size we have
|
||||
*/
|
||||
max_erasesize = curr_erasesize = subdev[0]->erasesize;
|
||||
num_erase_region = 1;
|
||||
for (i = 0; i < num_devs; i++) {
|
||||
if (subdev[i]->numeraseregions == 0) {
|
||||
/* current subdevice has uniform erase size */
|
||||
if (subdev[i]->erasesize != curr_erasesize) {
|
||||
/* if it differs from the last subdevice's erase size, count it */
|
||||
++num_erase_region;
|
||||
curr_erasesize = subdev[i]->erasesize;
|
||||
if (curr_erasesize > max_erasesize)
|
||||
max_erasesize = curr_erasesize;
|
||||
}
|
||||
} else {
|
||||
/* current subdevice has variable erase size */
|
||||
int j;
|
||||
for (j = 0; j < subdev[i]->numeraseregions; j++) {
|
||||
|
||||
/* walk the list of erase regions, count any changes */
|
||||
if (subdev[i]->eraseregions[j].erasesize !=
|
||||
curr_erasesize) {
|
||||
++num_erase_region;
|
||||
curr_erasesize =
|
||||
subdev[i]->eraseregions[j].
|
||||
erasesize;
|
||||
if (curr_erasesize > max_erasesize)
|
||||
max_erasesize = curr_erasesize;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (num_erase_region == 1) {
|
||||
/*
|
||||
* All subdevices have the same uniform erase size.
|
||||
* This is easy:
|
||||
*/
|
||||
concat->mtd.erasesize = curr_erasesize;
|
||||
concat->mtd.numeraseregions = 0;
|
||||
} else {
|
||||
uint64_t tmp64;
|
||||
|
||||
/*
|
||||
* erase block size varies across the subdevices: allocate
|
||||
* space to store the data describing the variable erase regions
|
||||
*/
|
||||
struct mtd_erase_region_info *erase_region_p;
|
||||
uint64_t begin, position;
|
||||
|
||||
concat->mtd.erasesize = max_erasesize;
|
||||
concat->mtd.numeraseregions = num_erase_region;
|
||||
concat->mtd.eraseregions = erase_region_p =
|
||||
kmalloc(num_erase_region *
|
||||
sizeof (struct mtd_erase_region_info), GFP_KERNEL);
|
||||
if (!erase_region_p) {
|
||||
kfree(concat);
|
||||
printk
|
||||
("memory allocation error while creating erase region list"
|
||||
" for device \"%s\"\n", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* walk the map of the new device once more and fill in
|
||||
* in erase region info:
|
||||
*/
|
||||
curr_erasesize = subdev[0]->erasesize;
|
||||
begin = position = 0;
|
||||
for (i = 0; i < num_devs; i++) {
|
||||
if (subdev[i]->numeraseregions == 0) {
|
||||
/* current subdevice has uniform erase size */
|
||||
if (subdev[i]->erasesize != curr_erasesize) {
|
||||
/*
|
||||
* fill in an mtd_erase_region_info structure for the area
|
||||
* we have walked so far:
|
||||
*/
|
||||
erase_region_p->offset = begin;
|
||||
erase_region_p->erasesize =
|
||||
curr_erasesize;
|
||||
tmp64 = position - begin;
|
||||
do_div(tmp64, curr_erasesize);
|
||||
erase_region_p->numblocks = tmp64;
|
||||
begin = position;
|
||||
|
||||
curr_erasesize = subdev[i]->erasesize;
|
||||
++erase_region_p;
|
||||
}
|
||||
position += subdev[i]->size;
|
||||
} else {
|
||||
/* current subdevice has variable erase size */
|
||||
int j;
|
||||
for (j = 0; j < subdev[i]->numeraseregions; j++) {
|
||||
/* walk the list of erase regions, count any changes */
|
||||
if (subdev[i]->eraseregions[j].
|
||||
erasesize != curr_erasesize) {
|
||||
erase_region_p->offset = begin;
|
||||
erase_region_p->erasesize =
|
||||
curr_erasesize;
|
||||
tmp64 = position - begin;
|
||||
do_div(tmp64, curr_erasesize);
|
||||
erase_region_p->numblocks = tmp64;
|
||||
begin = position;
|
||||
|
||||
curr_erasesize =
|
||||
subdev[i]->eraseregions[j].
|
||||
erasesize;
|
||||
++erase_region_p;
|
||||
}
|
||||
position +=
|
||||
subdev[i]->eraseregions[j].
|
||||
numblocks * (uint64_t)curr_erasesize;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Now write the final entry */
|
||||
erase_region_p->offset = begin;
|
||||
erase_region_p->erasesize = curr_erasesize;
|
||||
tmp64 = position - begin;
|
||||
do_div(tmp64, curr_erasesize);
|
||||
erase_region_p->numblocks = tmp64;
|
||||
}
|
||||
|
||||
return &concat->mtd;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function destroys an MTD object obtained from concat_mtd_devs()
|
||||
*/
|
||||
|
||||
void mtd_concat_destroy(struct mtd_info *mtd)
|
||||
{
|
||||
struct mtd_concat *concat = CONCAT(mtd);
|
||||
if (concat->mtd.numeraseregions)
|
||||
kfree(concat->mtd.eraseregions);
|
||||
kfree(concat);
|
||||
}
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Robert Kaiser <rkaiser@sysgo.de>");
|
||||
MODULE_DESCRIPTION("Generic support for concatenating of MTD devices");
|
File diff suppressed because it is too large
Load Diff
|
@ -49,32 +49,32 @@ struct cfi_cmd_set;
|
|||
|
||||
struct flash_info {
|
||||
struct device_d *dev;
|
||||
ulong size; /* total bank size in bytes */
|
||||
ushort sector_count; /* number of erase units */
|
||||
ulong flash_id; /* combined device & manufacturer code */
|
||||
ulong *start; /* physical sector start addresses */
|
||||
uchar *protect; /* sector protection status */
|
||||
unsigned long size; /* total bank size in bytes */
|
||||
unsigned int sector_count; /* number of erase units */
|
||||
unsigned long flash_id; /* combined device & manufacturer code */
|
||||
unsigned long *start; /* physical sector start addresses */
|
||||
unsigned char *protect; /* sector protection status */
|
||||
|
||||
uchar portwidth; /* the width of the port */
|
||||
uchar chipwidth; /* the width of the chip */
|
||||
uchar chip_lsb; /* extra Least Significant Bit in the */
|
||||
unsigned int portwidth; /* the width of the port */
|
||||
unsigned int chipwidth; /* the width of the chip */
|
||||
unsigned int chip_lsb; /* extra Least Significant Bit in the */
|
||||
/* address of chip. */
|
||||
ushort buffer_size; /* # of bytes in write buffer */
|
||||
ulong erase_blk_tout; /* maximum block erase timeout */
|
||||
ulong write_tout; /* maximum write timeout */
|
||||
ulong buffer_write_tout; /* maximum buffer write timeout */
|
||||
ushort vendor; /* the primary vendor id */
|
||||
ushort cmd_reset; /* vendor specific reset command */
|
||||
ushort interface; /* used for x8/x16 adjustments */
|
||||
ushort legacy_unlock; /* support Intel legacy (un)locking */
|
||||
uchar manufacturer_id; /* manufacturer id */
|
||||
ushort device_id; /* device id */
|
||||
ushort device_id2; /* extended device id */
|
||||
ushort ext_addr; /* extended query table address */
|
||||
ushort cfi_version; /* cfi version */
|
||||
ushort cfi_offset; /* offset for cfi query */
|
||||
ulong addr_unlock1; /* unlock address 1 for AMD flash roms */
|
||||
ulong addr_unlock2; /* unlock address 2 for AMD flash roms */
|
||||
unsigned int buffer_size; /* # of bytes in write buffer */
|
||||
unsigned long erase_blk_tout; /* maximum block erase timeout */
|
||||
unsigned long write_tout; /* maximum write timeout */
|
||||
unsigned long buffer_write_tout;/* maximum buffer write timeout */
|
||||
unsigned int vendor; /* the primary vendor id */
|
||||
unsigned int cmd_reset; /* vendor specific reset command */
|
||||
unsigned int interface; /* used for x8/x16 adjustments */
|
||||
unsigned int legacy_unlock; /* support Intel legacy (un)locking */
|
||||
unsigned int manufacturer_id; /* manufacturer id */
|
||||
unsigned int device_id; /* device id */
|
||||
unsigned int device_id2; /* extended device id */
|
||||
unsigned int ext_addr; /* extended query table address */
|
||||
unsigned int cfi_version; /* cfi version */
|
||||
unsigned int cfi_offset; /* offset for cfi query */
|
||||
unsigned long addr_unlock1; /* unlock address 1 for AMD flash roms */
|
||||
unsigned long addr_unlock2; /* unlock address 2 for AMD flash roms */
|
||||
struct cfi_cmd_set *cfi_cmd_set;
|
||||
struct mtd_info mtd;
|
||||
int numeraseregions;
|
||||
|
@ -118,14 +118,16 @@ struct cfi_pri_hdr {
|
|||
|
||||
|
||||
struct cfi_cmd_set {
|
||||
int (*flash_write_cfibuffer) (struct flash_info *info, ulong dest, const uchar * cp, int len);
|
||||
int (*flash_erase_one) (struct flash_info *info, long sect);
|
||||
int (*flash_is_busy) (struct flash_info *info, flash_sect_t sect);
|
||||
void (*flash_read_jedec_ids) (struct flash_info *info);
|
||||
void (*flash_prepare_write) (struct flash_info *info);
|
||||
int (*flash_status_check) (struct flash_info *info, flash_sect_t sector, uint64_t tout, char *prompt);
|
||||
int (*flash_real_protect) (struct flash_info *info, long sector, int prot);
|
||||
void (*flash_fixup) (struct flash_info *info, struct cfi_qry *qry);
|
||||
int (*flash_write_cfibuffer)(struct flash_info *info, unsigned long dest,
|
||||
const u8 *cp, int len);
|
||||
int (*flash_erase_one)(struct flash_info *info, long sect);
|
||||
int (*flash_is_busy)(struct flash_info *info, flash_sect_t sect);
|
||||
void (*flash_read_jedec_ids)(struct flash_info *info);
|
||||
void (*flash_prepare_write)(struct flash_info *info);
|
||||
int (*flash_status_check)(struct flash_info *info, flash_sect_t sector,
|
||||
u64 tout, char *prompt);
|
||||
int (*flash_real_protect)(struct flash_info *info, long sector, int prot);
|
||||
void (*flash_fixup)(struct flash_info *info, struct cfi_qry *qry);
|
||||
};
|
||||
|
||||
extern struct cfi_cmd_set cfi_cmd_set_intel;
|
||||
|
@ -241,17 +243,17 @@ extern struct cfi_cmd_set cfi_cmd_set_amd;
|
|||
/* Prototypes */
|
||||
|
||||
int flash_isset(struct flash_info *info, flash_sect_t sect,
|
||||
uint offset, u32 cmd);
|
||||
unsigned int offset, u32 cmd);
|
||||
void flash_write_cmd(struct flash_info *info, flash_sect_t sect,
|
||||
uint offset, u32 cmd);
|
||||
flash_sect_t find_sector (struct flash_info *info, ulong addr);
|
||||
int flash_status_check (struct flash_info *info, flash_sect_t sector,
|
||||
uint64_t tout, char *prompt);
|
||||
int flash_generic_status_check (struct flash_info *info, flash_sect_t sector,
|
||||
uint64_t tout, char *prompt);
|
||||
unsigned int offset, u32 cmd);
|
||||
flash_sect_t find_sector(struct flash_info *info, unsigned long addr);
|
||||
int flash_status_check(struct flash_info *info, flash_sect_t sector,
|
||||
u64 tout, char *prompt);
|
||||
int flash_generic_status_check(struct flash_info *info, flash_sect_t sector,
|
||||
u64 tout, char *prompt);
|
||||
|
||||
int flash_isequal(struct flash_info *info, flash_sect_t sect,
|
||||
uint offset, u32 cmd);
|
||||
unsigned int offset, u32 cmd);
|
||||
void flash_make_cmd(struct flash_info *info, u32 cmd, cfiword_t *cmdbuf);
|
||||
|
||||
static inline void flash_write8(u8 value, void *addr)
|
||||
|
@ -298,12 +300,13 @@ static inline u64 flash_read64(void *addr)
|
|||
/*
|
||||
* create an address based on the offset and the port width
|
||||
*/
|
||||
static inline uchar *flash_make_addr (struct flash_info *info, flash_sect_t sect, uint offset)
|
||||
static inline u8 *flash_make_addr(struct flash_info *info, flash_sect_t sect,
|
||||
unsigned int offset)
|
||||
{
|
||||
return ((uchar *) (info->start[sect] + ((offset * info->portwidth) << info->chip_lsb)));
|
||||
return ((u8 *)(info->start[sect] + ((offset * info->portwidth) << info->chip_lsb)));
|
||||
}
|
||||
|
||||
uchar flash_read_uchar (struct flash_info *info, uint offset);
|
||||
u8 flash_read_uchar(struct flash_info *info, unsigned int offset);
|
||||
u32 jedec_read_mfr(struct flash_info *info);
|
||||
|
||||
#ifdef CONFIG_DRIVER_CFI_BANK_WIDTH_1
|
||||
|
@ -332,49 +335,25 @@ u32 jedec_read_mfr(struct flash_info *info);
|
|||
|
||||
static inline void flash_write_word(struct flash_info *info, cfiword_t datum, void *addr)
|
||||
{
|
||||
if (bankwidth_is_1(info)) {
|
||||
debug("fw addr %p val %02x\n", addr, (u8)datum);
|
||||
if (bankwidth_is_1(info))
|
||||
flash_write8(datum, addr);
|
||||
} else if (bankwidth_is_2(info)) {
|
||||
debug("fw addr %p val %04x\n", addr, (u16)datum);
|
||||
else if (bankwidth_is_2(info))
|
||||
flash_write16(datum, addr);
|
||||
} else if (bankwidth_is_4(info)) {
|
||||
debug("fw addr %p val %08x\n", addr, (u32)datum);
|
||||
else if (bankwidth_is_4(info))
|
||||
flash_write32(datum, addr);
|
||||
} else if (bankwidth_is_8(info)) {
|
||||
else if (bankwidth_is_8(info))
|
||||
flash_write64(datum, addr);
|
||||
}
|
||||
}
|
||||
|
||||
extern void flash_print_info (struct flash_info *);
|
||||
extern int flash_sect_erase (ulong addr_first, ulong addr_last);
|
||||
extern int flash_sect_protect (int flag, ulong addr_first, ulong addr_last);
|
||||
extern void flash_print_info(struct flash_info *);
|
||||
extern int flash_sect_erase(unsigned long addr_first, unsigned long addr_last);
|
||||
extern int flash_sect_protect(int flag, unsigned long addr_first,
|
||||
unsigned long addr_last);
|
||||
|
||||
/* common/flash.c */
|
||||
extern void flash_protect (int flag, ulong from, ulong to, struct flash_info *info);
|
||||
extern int flash_write (char *, ulong, ulong);
|
||||
extern struct flash_info *addr2info (ulong);
|
||||
//extern int write_buff (flash_info_t *info, const uchar *src, ulong addr, ulong cnt);
|
||||
|
||||
/* board/?/flash.c */
|
||||
#if defined(CFG_FLASH_PROTECTION)
|
||||
extern int flash_real_protect(struct flash_info *info, long sector, int prot);
|
||||
extern void flash_read_user_serial(struct flash_info *info, void * buffer, int offset, int len);
|
||||
extern void flash_read_factory_serial(struct flash_info *info, void * buffer, int offset, int len);
|
||||
#endif /* CFG_FLASH_PROTECTION */
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
* return codes from flash_write():
|
||||
*/
|
||||
#define ERR_OK 0
|
||||
#define ERR_TIMOUT 1
|
||||
#define ERR_NOT_ERASED 2
|
||||
#define ERR_PROTECTED 4
|
||||
#define ERR_INVAL 8
|
||||
#define ERR_ALIGN 16
|
||||
#define ERR_UNKNOWN_FLASH_VENDOR 32
|
||||
#define ERR_UNKNOWN_FLASH_TYPE 64
|
||||
#define ERR_PROG_ERROR 128
|
||||
extern void flash_protect(int flag, unsigned long from, unsigned long to,
|
||||
struct flash_info *info);
|
||||
extern int flash_write(char *, unsigned long, unsigned long);
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
* Protection Flags for flash_protect():
|
||||
|
@ -729,4 +708,3 @@ extern void flash_read_factory_serial(struct flash_info *info, void * buffer, in
|
|||
#define FLASH_WRITE_TIMEOUT 500 /* timeout for writes in ms */
|
||||
|
||||
#endif /* __CFI_FLASH_H */
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ static void cfi_reverse_geometry(struct cfi_qry *qry)
|
|||
}
|
||||
}
|
||||
|
||||
static void flash_unlock_seq (struct flash_info *info)
|
||||
static void flash_unlock_seq(struct flash_info *info)
|
||||
{
|
||||
flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_UNLOCK_START);
|
||||
flash_write_cmd (info, 0, info->addr_unlock2, AMD_CMD_UNLOCK_ACK);
|
||||
|
@ -31,7 +31,7 @@ static void flash_unlock_seq (struct flash_info *info)
|
|||
* Note: assume cfi->vendor, cfi->portwidth and cfi->chipwidth are correct
|
||||
*
|
||||
*/
|
||||
static void amd_read_jedec_ids (struct flash_info *info)
|
||||
static void amd_read_jedec_ids(struct flash_info *info)
|
||||
{
|
||||
info->cmd_reset = AMD_CMD_RESET;
|
||||
info->manufacturer_id = 0;
|
||||
|
@ -62,20 +62,21 @@ static void amd_read_jedec_ids (struct flash_info *info)
|
|||
udelay(1000); /* some flash are slow to respond */
|
||||
|
||||
info->manufacturer_id = jedec_read_mfr(info);
|
||||
info->device_id = flash_read_uchar (info,
|
||||
info->device_id = flash_read_uchar(info,
|
||||
FLASH_OFFSET_DEVICE_ID);
|
||||
if (info->device_id == 0x7E) {
|
||||
/* AMD 3-byte (expanded) device ids */
|
||||
info->device_id2 = flash_read_uchar (info,
|
||||
info->device_id2 = flash_read_uchar(info,
|
||||
FLASH_OFFSET_DEVICE_ID2);
|
||||
info->device_id2 <<= 8;
|
||||
info->device_id2 |= flash_read_uchar (info,
|
||||
info->device_id2 |= flash_read_uchar(info,
|
||||
FLASH_OFFSET_DEVICE_ID3);
|
||||
}
|
||||
flash_write_cmd(info, 0, 0, info->cmd_reset);
|
||||
}
|
||||
|
||||
static int flash_toggle (struct flash_info *info, flash_sect_t sect, uint offset, uchar cmd)
|
||||
static int flash_toggle(struct flash_info *info, flash_sect_t sect,
|
||||
unsigned int offset, u8 cmd)
|
||||
{
|
||||
void *addr;
|
||||
cfiword_t cword;
|
||||
|
@ -83,6 +84,7 @@ static int flash_toggle (struct flash_info *info, flash_sect_t sect, uint offset
|
|||
|
||||
addr = flash_make_addr (info, sect, offset);
|
||||
flash_make_cmd (info, cmd, &cword);
|
||||
|
||||
if (bankwidth_is_1(info)) {
|
||||
retval = flash_read8(addr) != flash_read8(addr);
|
||||
} else if (bankwidth_is_2(info)) {
|
||||
|
@ -92,8 +94,9 @@ static int flash_toggle (struct flash_info *info, flash_sect_t sect, uint offset
|
|||
} else if (bankwidth_is_8(info)) {
|
||||
retval = ( (flash_read32( addr ) != flash_read32( addr )) ||
|
||||
(flash_read32(addr+4) != flash_read32(addr+4)) );
|
||||
} else
|
||||
} else {
|
||||
retval = 0;
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
@ -102,12 +105,12 @@ static int flash_toggle (struct flash_info *info, flash_sect_t sect, uint offset
|
|||
* flash_is_busy - check to see if the flash is busy
|
||||
* This routine checks the status of the chip and returns true if the chip is busy
|
||||
*/
|
||||
static int amd_flash_is_busy (struct flash_info *info, flash_sect_t sect)
|
||||
static int amd_flash_is_busy(struct flash_info *info, flash_sect_t sect)
|
||||
{
|
||||
return flash_toggle (info, sect, 0, AMD_STATUS_TOGGLE);
|
||||
}
|
||||
|
||||
static int amd_flash_erase_one (struct flash_info *info, long sect)
|
||||
static int amd_flash_erase_one(struct flash_info *info, long sect)
|
||||
{
|
||||
flash_unlock_seq(info);
|
||||
flash_write_cmd (info, 0, info->addr_unlock1, AMD_CMD_ERASE_START);
|
||||
|
@ -124,13 +127,12 @@ static void amd_flash_prepare_write(struct flash_info *info)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_CFI_BUFFER_WRITE
|
||||
static int amd_flash_write_cfibuffer (struct flash_info *info, ulong dest, const uchar * cp,
|
||||
int len)
|
||||
static int amd_flash_write_cfibuffer(struct flash_info *info, unsigned long dest,
|
||||
const u8 *cp, int len)
|
||||
{
|
||||
flash_sect_t sector;
|
||||
int cnt;
|
||||
int retcode;
|
||||
void *src = (void*)cp;
|
||||
void *src = (void *)cp;
|
||||
void *dst = (void *)dest;
|
||||
cfiword_t cword;
|
||||
|
||||
|
@ -170,18 +172,18 @@ static int amd_flash_write_cfibuffer (struct flash_info *info, ulong dest, const
|
|||
}
|
||||
}
|
||||
|
||||
flash_write_cmd (info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
|
||||
retcode = flash_status_check (info, sector, info->buffer_write_tout,
|
||||
flash_write_cmd(info, sector, 0, AMD_CMD_WRITE_BUFFER_CONFIRM);
|
||||
|
||||
return flash_status_check(info, sector, info->buffer_write_tout,
|
||||
"buffer write");
|
||||
return retcode;
|
||||
}
|
||||
#else
|
||||
#define amd_flash_write_cfibuffer NULL
|
||||
#endif /* CONFIG_CFI_BUFFER_WRITE */
|
||||
|
||||
static int amd_flash_real_protect (struct flash_info *info, long sector, int prot)
|
||||
static int amd_flash_real_protect(struct flash_info *info, long sector, int prot)
|
||||
{
|
||||
if (info->manufacturer_id != (uchar)ATM_MANUFACT)
|
||||
if (info->manufacturer_id != (u8)ATM_MANUFACT)
|
||||
return 0;
|
||||
|
||||
if (prot) {
|
||||
|
@ -205,7 +207,7 @@ static int amd_flash_real_protect (struct flash_info *info, long sector, int pro
|
|||
* Manufacturer-specific quirks. Add workarounds for geometry
|
||||
* reversal, etc. here.
|
||||
*/
|
||||
static void flash_fixup_amd (struct flash_info *info, struct cfi_qry *qry)
|
||||
static void flash_fixup_amd(struct flash_info *info, struct cfi_qry *qry)
|
||||
{
|
||||
/* check if flash geometry needs reversal */
|
||||
if (qry->num_erase_regions > 1) {
|
||||
|
@ -265,4 +267,3 @@ struct cfi_cmd_set cfi_cmd_set_amd = {
|
|||
.flash_real_protect = amd_flash_real_protect,
|
||||
.flash_fixup = amd_flash_fixup,
|
||||
};
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
*
|
||||
* Note: assume cfi->vendor, cfi->portwidth and cfi->chipwidth are correct
|
||||
*
|
||||
*/
|
||||
static void intel_read_jedec_ids (struct flash_info *info)
|
||||
*/
|
||||
static void intel_read_jedec_ids(struct flash_info *info)
|
||||
{
|
||||
info->cmd_reset = FLASH_CMD_RESET;
|
||||
info->manufacturer_id = 0;
|
||||
|
@ -19,7 +19,7 @@ static void intel_read_jedec_ids (struct flash_info *info)
|
|||
udelay(1000); /* some flash are slow to respond */
|
||||
|
||||
info->manufacturer_id = jedec_read_mfr(info);
|
||||
info->device_id = flash_read_uchar (info,
|
||||
info->device_id = flash_read_uchar(info,
|
||||
FLASH_OFFSET_DEVICE_ID);
|
||||
flash_write_cmd(info, 0, 0, info->cmd_reset);
|
||||
}
|
||||
|
@ -28,16 +28,16 @@ static void intel_read_jedec_ids (struct flash_info *info)
|
|||
* flash_is_busy - check to see if the flash is busy
|
||||
* This routine checks the status of the chip and returns true if the chip is busy
|
||||
*/
|
||||
static int intel_flash_is_busy (struct flash_info *info, flash_sect_t sect)
|
||||
static int intel_flash_is_busy(struct flash_info *info, flash_sect_t sect)
|
||||
{
|
||||
return !flash_isset (info, sect, 0, FLASH_STATUS_DONE);
|
||||
}
|
||||
|
||||
static int intel_flash_erase_one (struct flash_info *info, long sect)
|
||||
static int intel_flash_erase_one(struct flash_info *info, long sect)
|
||||
{
|
||||
flash_write_cmd (info, sect, 0, FLASH_CMD_CLEAR_STATUS);
|
||||
flash_write_cmd (info, sect, 0, FLASH_CMD_BLOCK_ERASE);
|
||||
flash_write_cmd (info, sect, 0, FLASH_CMD_ERASE_CONFIRM);
|
||||
flash_write_cmd(info, sect, 0, FLASH_CMD_CLEAR_STATUS);
|
||||
flash_write_cmd(info, sect, 0, FLASH_CMD_BLOCK_ERASE);
|
||||
flash_write_cmd(info, sect, 0, FLASH_CMD_ERASE_CONFIRM);
|
||||
|
||||
return flash_status_check(info, sect, info->erase_blk_tout, "erase");
|
||||
}
|
||||
|
@ -49,26 +49,26 @@ static void intel_flash_prepare_write(struct flash_info *info)
|
|||
}
|
||||
|
||||
#ifdef CONFIG_CFI_BUFFER_WRITE
|
||||
static int intel_flash_write_cfibuffer (struct flash_info *info, ulong dest, const uchar * cp,
|
||||
int len)
|
||||
static int intel_flash_write_cfibuffer(struct flash_info *info,
|
||||
unsigned long dest, const u8 *cp, int len)
|
||||
{
|
||||
flash_sect_t sector;
|
||||
int cnt;
|
||||
int retcode;
|
||||
int ret;
|
||||
void *src = (void*)cp;
|
||||
void *dst = (void *)dest;
|
||||
/* reduce width due to possible alignment problems */
|
||||
const unsigned long ptr = (unsigned long)dest | (unsigned long)cp | info->portwidth;
|
||||
const int width = ptr & -ptr;
|
||||
|
||||
sector = find_sector (info, dest);
|
||||
flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
|
||||
flash_write_cmd (info, sector, 0, FLASH_CMD_WRITE_TO_BUFFER);
|
||||
sector = find_sector(info, dest);
|
||||
flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS);
|
||||
flash_write_cmd(info, sector, 0, FLASH_CMD_WRITE_TO_BUFFER);
|
||||
|
||||
retcode = flash_generic_status_check (info, sector, info->buffer_write_tout,
|
||||
ret = flash_generic_status_check(info, sector, info->buffer_write_tout,
|
||||
"write to buffer");
|
||||
if (retcode != ERR_OK)
|
||||
return retcode;
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* reduce the number of loops by the width of the port */
|
||||
cnt = len / width;
|
||||
|
@ -95,69 +95,65 @@ static int intel_flash_write_cfibuffer (struct flash_info *info, ulong dest, con
|
|||
}
|
||||
}
|
||||
|
||||
flash_write_cmd (info, sector, 0, FLASH_CMD_WRITE_BUFFER_CONFIRM);
|
||||
retcode = flash_status_check (info, sector,
|
||||
flash_write_cmd(info, sector, 0, FLASH_CMD_WRITE_BUFFER_CONFIRM);
|
||||
ret = flash_status_check(info, sector,
|
||||
info->buffer_write_tout,
|
||||
"buffer write");
|
||||
return retcode;
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
#define intel_flash_write_cfibuffer NULL
|
||||
#endif /* CONFIG_CFI_BUFFER_WRITE */
|
||||
|
||||
static int intel_flash_status_check (struct flash_info *info, flash_sect_t sector,
|
||||
uint64_t tout, char *prompt)
|
||||
static int intel_flash_status_check(struct flash_info *info, flash_sect_t sector,
|
||||
u64 tout, char *prompt)
|
||||
{
|
||||
int retcode;
|
||||
int ret;
|
||||
|
||||
retcode = flash_generic_status_check (info, sector, tout, prompt);
|
||||
|
||||
if ((retcode == ERR_OK)
|
||||
&& !flash_isequal (info, sector, 0, FLASH_STATUS_DONE)) {
|
||||
retcode = ERR_INVAL;
|
||||
printf ("Flash %s error at address %lx\n", prompt,
|
||||
ret = flash_generic_status_check(info, sector, tout, prompt);
|
||||
if (!ret && !flash_isequal(info, sector, 0, FLASH_STATUS_DONE)) {
|
||||
ret = -EINVAL;
|
||||
printf("Flash %s error at address %lx\n", prompt,
|
||||
info->start[sector]);
|
||||
if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) {
|
||||
puts ("Command Sequence Error.\n");
|
||||
} else if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS)) {
|
||||
puts ("Block Erase Error.\n");
|
||||
retcode = ERR_NOT_ERASED;
|
||||
} else if (flash_isset (info, sector, 0, FLASH_STATUS_PSLBS)) {
|
||||
puts ("Locking Error\n");
|
||||
}
|
||||
if (flash_isset (info, sector, 0, FLASH_STATUS_DPS)) {
|
||||
puts ("Block locked.\n");
|
||||
retcode = ERR_PROTECTED;
|
||||
}
|
||||
if (flash_isset (info, sector, 0, FLASH_STATUS_VPENS))
|
||||
puts ("Vpp Low Error.\n");
|
||||
}
|
||||
flash_write_cmd (info, sector, 0, info->cmd_reset);
|
||||
|
||||
return retcode;
|
||||
if (flash_isset(info, sector, 0, FLASH_STATUS_ECLBS | FLASH_STATUS_PSLBS)) {
|
||||
printf("Command Sequence Error.\n");
|
||||
} else if (flash_isset (info, sector, 0, FLASH_STATUS_ECLBS)) {
|
||||
printf("Block Erase Error.\n");
|
||||
ret = -EIO;
|
||||
} else if (flash_isset(info, sector, 0, FLASH_STATUS_PSLBS)) {
|
||||
printf("Locking Error\n");
|
||||
}
|
||||
|
||||
if (flash_isset(info, sector, 0, FLASH_STATUS_DPS)) {
|
||||
printf("Block locked.\n");
|
||||
ret = -EROFS;
|
||||
}
|
||||
|
||||
if (flash_isset(info, sector, 0, FLASH_STATUS_VPENS))
|
||||
printf("Vpp Low Error.\n");
|
||||
}
|
||||
|
||||
flash_write_cmd(info, sector, 0, info->cmd_reset);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int intel_flash_real_protect (struct flash_info *info, long sector, int prot)
|
||||
static int intel_flash_real_protect(struct flash_info *info, long sector, int prot)
|
||||
{
|
||||
flash_write_cmd (info, sector, 0, FLASH_CMD_CLEAR_STATUS);
|
||||
flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT);
|
||||
flash_write_cmd(info, sector, 0, FLASH_CMD_CLEAR_STATUS);
|
||||
flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT);
|
||||
|
||||
if (prot)
|
||||
flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_SET);
|
||||
flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_SET);
|
||||
else
|
||||
flash_write_cmd (info, sector, 0, FLASH_CMD_PROTECT_CLEAR);
|
||||
flash_write_cmd(info, sector, 0, FLASH_CMD_PROTECT_CLEAR);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void intel_flash_fixup (struct flash_info *info, struct cfi_qry *qry)
|
||||
static void intel_flash_fixup(struct flash_info *info, struct cfi_qry *qry)
|
||||
{
|
||||
#ifdef CFG_FLASH_PROTECTION
|
||||
/* read legacy lock/unlock bit from intel flash */
|
||||
if (info->ext_addr) {
|
||||
info->legacy_unlock = flash_read_uchar (info,
|
||||
info->ext_addr + 5) & 0x08;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
struct cfi_cmd_set cfi_cmd_set_intel = {
|
||||
|
@ -170,4 +166,3 @@ struct cfi_cmd_set cfi_cmd_set_intel = {
|
|||
.flash_real_protect = intel_flash_real_protect,
|
||||
.flash_fixup = intel_flash_fixup,
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* MTD device concatenation layer definitions
|
||||
*
|
||||
* Copyright © 2002 Robert Kaiser <rkaiser@sysgo.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MTD_CONCAT_H
|
||||
#define MTD_CONCAT_H
|
||||
|
||||
|
||||
struct mtd_info *mtd_concat_create(
|
||||
struct mtd_info *subdev[], /* subdevices to concatenate */
|
||||
int num_devs, /* number of subdevices */
|
||||
const char *name); /* name for the new device */
|
||||
|
||||
void mtd_concat_destroy(struct mtd_info *mtd);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue