* the DEVOFFSET (dev) block. On NOR the loop is only run once.
*/
static int flash_read_buf (int dev, int fd, void *buf, size_t count,
- off_t offset, uint8_t mtd_type)
+ off_t offset)
{
size_t blocklen; /* erase / write length - one block on NAND,
0 on NOR */
/* Offset inside a block */
block_seek = offset - blockstart;
- if (mtd_type == MTD_NANDFLASH) {
+ if (DEVTYPE(dev) == MTD_NANDFLASH) {
/*
* NAND: calculate which blocks we are reading. We have
* to read one block at a time to skip bad blocks.
/* This only runs once on NOR flash */
while (processed < count) {
- rc = flash_bad_block(fd, mtd_type, blockstart);
+ rc = flash_bad_block(fd, DEVTYPE(dev), blockstart);
if (rc < 0) /* block test failed */
return -1;
* erase and write the whole data at once.
*/
static int flash_write_buf (int dev, int fd, void *buf, size_t count,
- off_t offset, uint8_t mtd_type)
+ off_t offset)
{
void *data;
struct erase_info_user erase;
/*
* For mtd devices only offset and size of the environment do matter
*/
- if (mtd_type == MTD_ABSENT) {
+ if (DEVTYPE(dev) == MTD_ABSENT) {
blocklen = count;
erase_len = blocklen;
blockstart = offset;
return -1;
}
- rc = flash_read_buf (dev, fd, data, write_total, erase_offset,
- mtd_type);
+ rc = flash_read_buf(dev, fd, data, write_total, erase_offset);
if (write_total != rc)
return -1;
data = buf;
}
- if (mtd_type == MTD_NANDFLASH) {
+ if (DEVTYPE(dev) == MTD_NANDFLASH) {
/*
* NAND: calculate which blocks we are writing. We have
* to write one block at a time to skip bad blocks.
/* This only runs once on NOR flash and SPI-dataflash */
while (processed < write_total) {
- rc = flash_bad_block(fd, mtd_type, blockstart);
+ rc = flash_bad_block(fd, DEVTYPE(dev), blockstart);
if (rc < 0) /* block test failed */
return rc;
continue;
}
- if (mtd_type != MTD_ABSENT) {
+ if (DEVTYPE(dev) != MTD_ABSENT) {
erase.start = blockstart;
ioctl(fd, MEMUNLOCK, &erase);
/* These do not need an explicit erase cycle */
- if (mtd_type != MTD_DATAFLASH)
+ if (DEVTYPE(dev) != MTD_DATAFLASH)
if (ioctl(fd, MEMERASE, &erase) != 0) {
fprintf(stderr,
"MTD erase error on %s: %s\n",
return -1;
}
- if (mtd_type != MTD_ABSENT)
+ if (DEVTYPE(dev) != MTD_ABSENT)
ioctl(fd, MEMLOCK, &erase);
processed += erasesize;
#endif
rc = flash_write_buf(dev_target, fd_target, environment.image,
- CUR_ENVSIZE, DEVOFFSET(dev_target),
- DEVTYPE(dev_target));
+ CUR_ENVSIZE, DEVOFFSET(dev_target));
if (rc < 0)
return rc;
int rc;
rc = flash_read_buf(dev_current, fd, environment.image, CUR_ENVSIZE,
- DEVOFFSET(dev_current), DEVTYPE(dev_current));
+ DEVOFFSET(dev_current));
if (rc != CUR_ENVSIZE)
return -1;