diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2014-06-12 08:18:51 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2014-06-13 06:22:39 +0200 |
commit | 56c00256dd249837fdd88bdf5d9bf0ae2df927ef (patch) | |
tree | ae5e524c303844f1da7de58fb4317386d1ab7757 /arch/arm/mach-imx/imx-bbu-internal.c | |
parent | 1e7380517bbaa5a4859923a69bff03272f352e81 (diff) | |
download | barebox-56c00256dd249837fdd88bdf5d9bf0ae2df927ef.tar.gz barebox-56c00256dd249837fdd88bdf5d9bf0ae2df927ef.tar.xz |
ARM: i.MX bbu: Add update handler for external NOR boot
External NOR boot only requires copying the image to NOR Flash.
This also adds (un)protecting the flash which is required for
NOR Flash.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-imx/imx-bbu-internal.c')
-rw-r--r-- | arch/arm/mach-imx/imx-bbu-internal.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/arch/arm/mach-imx/imx-bbu-internal.c b/arch/arm/mach-imx/imx-bbu-internal.c index c7cd5b8ed6..125415ec8d 100644 --- a/arch/arm/mach-imx/imx-bbu-internal.c +++ b/arch/arm/mach-imx/imx-bbu-internal.c @@ -59,7 +59,16 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler, return fd; if (imx_handler->flags & IMX_INTERNAL_FLAG_ERASE) { - debug("%s: eraseing %s from 0 to 0x%08x\n", __func__, + debug("%s: unprotecting %s from 0 to 0x%08x\n", __func__, + data->devicefile, image_len); + ret = protect(fd, image_len, 0, 0); + if (ret && ret != -ENOSYS) { + printf("unprotecting %s failed with %s\n", data->devicefile, + strerror(-ret)); + goto err_close; + } + + debug("%s: erasing %s from 0 to 0x%08x\n", __func__, data->devicefile, image_len); ret = erase(fd, image_len, 0); if (ret) { @@ -92,6 +101,16 @@ static int imx_bbu_write_device(struct imx_internal_bbu_handler *imx_handler, if (ret < 0) goto err_close; + if (imx_handler->flags & IMX_INTERNAL_FLAG_ERASE) { + debug("%s: protecting %s from 0 to 0x%08x\n", __func__, + data->devicefile, image_len); + ret = protect(fd, image_len, 0, 1); + if (ret && ret != -ENOSYS) { + printf("protecting %s failed with %s\n", data->devicefile, + strerror(-ret)); + } + } + ret = 0; err_close: @@ -351,6 +370,19 @@ static int imx_bbu_internal_v2_update(struct bbu_handler *handler, struct bbu_da return ret; } +static int imx_bbu_external_update(struct bbu_handler *handler, struct bbu_data *data) +{ + struct imx_internal_bbu_handler *imx_handler = + container_of(handler, struct imx_internal_bbu_handler, handler); + int ret; + + ret = imx_bbu_check_prereq(data); + if (ret) + return ret; + + return imx_bbu_write_device(imx_handler, data, data->image, data->len); +} + static struct imx_internal_bbu_handler *__init_handler(const char *name, char *devicefile, unsigned long flags) { @@ -484,3 +516,15 @@ int imx6_bbu_internal_spi_i2c_register_handler(const char *name, char *devicefil return __register_handler(imx_handler); } + +int imx_bbu_external_nor_register_handler(const char *name, char *devicefile, + unsigned long flags) +{ + struct imx_internal_bbu_handler *imx_handler; + + imx_handler = __init_handler(name, devicefile, flags); + imx_handler->flags = IMX_INTERNAL_FLAG_ERASE; + imx_handler->handler.handler = imx_bbu_external_update; + + return __register_handler(imx_handler); +} |