X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fdfu%2Fdfu_nand.c;h=0bfdbf942898d391e993213573153dd4ec96c436;hb=82a248df9af7057152a1359e7405585419accc1e;hp=23f15716e09413284e826a07c653c14ab1420626;hpb=8b7d51249eca113c4965a7c417f33d7eb569434b;p=u-boot diff --git a/drivers/dfu/dfu_nand.c b/drivers/dfu/dfu_nand.c index 23f15716e0..0bfdbf9428 100644 --- a/drivers/dfu/dfu_nand.c +++ b/drivers/dfu/dfu_nand.c @@ -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 - * - * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -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) {