]> git.sur5r.net Git - u-boot/blobdiff - drivers/dfu/dfu_nand.c
reset: uniphier: sync reset data with Linux 4.18-rc1
[u-boot] / drivers / dfu / dfu_nand.c
index 23f15716e09413284e826a07c653c14ab1420626..0bfdbf942898d391e993213573153dd4ec96c436 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * dfu_nand.c -- DFU for NAND routines.
  *
@@ -6,8 +7,6 @@
  * Based on dfu_mmc.c which is:
  * Copyright (C) 2012 Samsung Electronics
  * author: Lukasz Majewski <l.majewski@samsung.com>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -37,15 +36,15 @@ static int nand_block_op(enum dfu_op op, struct dfu_entity *dfu,
        lim = dfu->data.nand.start + dfu->data.nand.size - start;
        count = *len;
 
+       mtd = get_nand_dev_by_index(nand_curr_device);
+
        if (nand_curr_device < 0 ||
            nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
-           !nand_info[nand_curr_device]) {
+           !mtd) {
                printf("%s: invalid nand device\n", __func__);
                return -1;
        }
 
-       mtd = nand_info[nand_curr_device];
-
        if (op == DFU_OP_READ) {
                ret = nand_read_skip_bad(mtd, start, &count, &actual,
                                         lim, buf);
@@ -114,9 +113,11 @@ static int dfu_write_medium_nand(struct dfu_entity *dfu,
        return ret;
 }
 
-long dfu_get_medium_size_nand(struct dfu_entity *dfu)
+int dfu_get_medium_size_nand(struct dfu_entity *dfu, u64 *size)
 {
-       return dfu->data.nand.size;
+       *size = dfu->data.nand.size;
+
+       return 0;
 }
 
 static int dfu_read_medium_nand(struct dfu_entity *dfu, u64 offset, void *buf,
@@ -143,18 +144,16 @@ static int dfu_flush_medium_nand(struct dfu_entity *dfu)
 
        /* in case of ubi partition, erase rest of the partition */
        if (dfu->data.nand.ubi) {
-               struct mtd_info *mtd;
+               struct mtd_info *mtd = get_nand_dev_by_index(nand_curr_device);
                nand_erase_options_t opts;
 
                if (nand_curr_device < 0 ||
                    nand_curr_device >= CONFIG_SYS_MAX_NAND_DEVICE ||
-                   !nand_info[nand_curr_device]) {
+                   !mtd) {
                        printf("%s: invalid nand device\n", __func__);
                        return -1;
                }
 
-               mtd = nand_info[nand_curr_device];
-
                memset(&opts, 0, sizeof(opts));
                off = dfu->offset;
                if ((off & (mtd->erasesize - 1)) != 0) {