diff options
Diffstat (limited to 'arch/arm/mach-imx/imx-bbu-external-nand.c')
-rw-r--r-- | arch/arm/mach-imx/imx-bbu-external-nand.c | 60 |
1 files changed, 28 insertions, 32 deletions
diff --git a/arch/arm/mach-imx/imx-bbu-external-nand.c b/arch/arm/mach-imx/imx-bbu-external-nand.c index fa43d2e8dc..7523008cdb 100644 --- a/arch/arm/mach-imx/imx-bbu-external-nand.c +++ b/arch/arm/mach-imx/imx-bbu-external-nand.c @@ -1,20 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-only +// SPDX-FileCopyrightText: 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix + /* * imx-bbu-external-nand.c - i.MX specific update functions for external * nand boot - * - * Copyright (c) 2013 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix - * - * See file CREDITS for list of people who contributed to this - * project. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 - * as published by the Free Software Foundation. - * - * 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. */ #include <common.h> @@ -28,8 +17,8 @@ #include <linux/mtd/mtd-abi.h> #include <linux/stat.h> #include <ioctl.h> -#include <mach/bbu.h> -#include <mach/imx-nand.h> +#include <mach/imx/bbu.h> +#include <mach/imx/imx-nand.h> #include <asm/barebox-arm-head.h> static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_data *data) @@ -40,9 +29,9 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ int size_available, size_need; int ret; uint32_t num_bb = 0, bbt = 0; - loff_t offset = 0; + loff_t nand_offset = 0, image_offset = 0; int block = 0, len, now, blocksize; - void *image = data->image; + void *image = NULL; ret = stat(data->devicefile, &s); if (ret) @@ -58,6 +47,12 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ if (ret) goto out; + image = memdup(data->image, data->len); + if (!image) { + ret = -ENOMEM; + goto out; + } + blocksize = meminfo.erasesize; size_need = data->len; @@ -66,27 +61,27 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ * Collect bad blocks and construct BBT */ while (size_need > 0) { - ret = ioctl(fd, MEMGETBADBLOCK, &offset); + ret = ioctl(fd, MEMGETBADBLOCK, &nand_offset); if (ret < 0) goto out; if (ret) { - if (!offset) { + if (!nand_offset) { printf("1st block is bad. This is not supported\n"); ret = -EINVAL; goto out; } - debug("bad block at 0x%08llx\n", offset); + debug("bad block at 0x%08llx\n", nand_offset); num_bb++; bbt |= (1 << block); - offset += blocksize; + nand_offset += blocksize; block++; continue; } size_need -= blocksize; size_available -= blocksize; - offset += blocksize; + nand_offset += blocksize; block++; if (size_available < 0) { @@ -129,7 +124,7 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ } len = data->len; - offset = 0; + nand_offset = 0; /* last chance before erasing the flash */ ret = bbu_confirm(data); @@ -142,13 +137,13 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ while (len > 0) { now = min(len, blocksize); - ret = ioctl(fd, MEMGETBADBLOCK, &offset); + ret = ioctl(fd, MEMGETBADBLOCK, &nand_offset); if (ret < 0) goto out; if (ret) { - offset += blocksize; - if (lseek(fd, offset, SEEK_SET) != offset) { + nand_offset += blocksize; + if (lseek(fd, nand_offset, SEEK_SET) != nand_offset) { ret = -errno; goto out; } @@ -156,25 +151,26 @@ static int imx_bbu_external_nand_update(struct bbu_handler *handler, struct bbu_ continue; } - debug("writing %d bytes at 0x%08llx\n", now, offset); + debug("writing %d bytes at 0x%08llx\n", now, nand_offset); - ret = erase(fd, blocksize, offset); + ret = erase(fd, blocksize, nand_offset); if (ret) goto out; - ret = write(fd, image, now); + ret = write(fd, image + image_offset, now); if (ret < 0) goto out; len -= now; - image += now; - offset += now; + image_offset += now; + nand_offset += now; } ret = 0; out: close(fd); + free(image); return ret; } |