summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2014-05-15 12:43:32 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-05-15 12:45:23 +0200
commitfb061bffe4b2017046094c370370cb75a495145e (patch)
tree15d6a6d010a084594bb6418113e28d0a4ac87194 /arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
parent22b722902ca6d0eb80aaca91ce469e4c85494127 (diff)
downloadbarebox-fb061bffe4b2017046094c370370cb75a495145e.tar.gz
barebox-fb061bffe4b2017046094c370370cb75a495145e.tar.xz
ARM: AM33xx: Add SPI bbu handler
We already have an update handler for the MLO on SPI, add a update handler for the regular barebox aswell. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-omap/am33xx_bbu_spi_mlo.c')
-rw-r--r--arch/arm/mach-omap/am33xx_bbu_spi_mlo.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
index 1aa3d7b524..8ac0a185c0 100644
--- a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
+++ b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
@@ -79,6 +79,41 @@ out:
return ret;
}
+static int spi_nor_handler(struct bbu_handler *handler,
+ struct bbu_data *data)
+{
+ int fd, ret;
+
+ if (file_detect_type(data->image, data->len) != filetype_arm_barebox) {
+ if (!bbu_force(data, "Not an ARM barebox image"))
+ return -EINVAL;
+ }
+
+ fd = open(data->devicefile, O_RDWR | O_CREAT);
+ if (fd < 0)
+ return fd;
+
+ debug("%s: eraseing %s from 0 to 0x%08x\n", __func__,
+ data->devicefile, data->len);
+ ret = erase(fd, data->len, 0);
+ if (ret) {
+ printf("erasing %s failed with %s\n", data->devicefile,
+ strerror(-ret));
+ goto err_close;
+ }
+
+ ret = write(fd, data->image, data->len);
+ if (ret < 0)
+ goto err_close;
+
+ ret = 0;
+
+err_close:
+ close(fd);
+
+ return ret;
+}
+
/*
* Register a am33xx MLO update handler for SPI NOR
*/
@@ -99,3 +134,24 @@ int am33xx_bbu_spi_nor_mlo_register_handler(const char *name, char *devicefile)
return ret;
}
+
+/*
+ * Register a am33xx update handler for SPI NOR
+ */
+int am33xx_bbu_spi_nor_register_handler(const char *name, char *devicefile)
+{
+ struct bbu_handler *handler;
+ int ret;
+
+ handler = xzalloc(sizeof(*handler));
+ handler->devicefile = devicefile;
+ handler->name = name;
+ handler->handler = spi_nor_handler;
+
+ ret = bbu_register_handler(handler);
+
+ if (ret)
+ free(handler);
+
+ return ret;
+}