* [PATCH 1/2] ARM: AM33xx: swap MLO SPI image automatically
@ 2014-05-15 10:45 Sascha Hauer
2014-05-15 10:45 ` [PATCH 2/2] ARM: AM33xx: Add SPI bbu handler Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2014-05-15 10:45 UTC (permalink / raw)
To: barebox
The MLO image for SPI differs in the normal MLO in that the
SPI version is big endian. As both types of images are floating
around detect whether or not the image is swapped automatically.
This also adds a check whether we have a valid MLO image.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
arch/arm/mach-omap/am33xx_bbu_spi_mlo.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
index ff9f8a6..1aa3d7b 100644
--- a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
+++ b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
@@ -32,6 +32,18 @@ static int spi_nor_mlo_handler(struct bbu_handler *handler,
uint32_t readbuf;
int size = data->len;
void *image = data->image;
+ uint32_t *header;
+ int swap = 0;
+
+ header = data->image;
+ if (header[5] == 0x43485345) {
+ swap = 0;
+ } else if (header[5] == 0x45534843) {
+ swap = 1;
+ } else {
+ if (!bbu_force(data, "Not a MLO image"))
+ return -EINVAL;
+ }
dstfd = open(data->devicefile, O_WRONLY);
if (dstfd < 0) {
@@ -49,7 +61,8 @@ static int spi_nor_mlo_handler(struct bbu_handler *handler,
for (; size >= 0; size -= 4) {
memcpy((char *)&readbuf, image, 4);
- readbuf = cpu_to_be32(readbuf);
+ if (swap)
+ readbuf = cpu_to_be32(readbuf);
ret = write(dstfd, &readbuf, 4);
if (ret < 0) {
perror("write");
--
2.0.0.rc0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] ARM: AM33xx: Add SPI bbu handler
2014-05-15 10:45 [PATCH 1/2] ARM: AM33xx: swap MLO SPI image automatically Sascha Hauer
@ 2014-05-15 10:45 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2014-05-15 10:45 UTC (permalink / raw)
To: barebox
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>
---
arch/arm/mach-omap/am33xx_bbu_spi_mlo.c | 56 +++++++++++++++++++++++++++++++++
arch/arm/mach-omap/include/mach/bbu.h | 6 ++++
2 files changed, 62 insertions(+)
diff --git a/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c b/arch/arm/mach-omap/am33xx_bbu_spi_mlo.c
index 1aa3d7b..8ac0a18 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;
+}
diff --git a/arch/arm/mach-omap/include/mach/bbu.h b/arch/arm/mach-omap/include/mach/bbu.h
index 9556ad6..9b0e4bf 100644
--- a/arch/arm/mach-omap/include/mach/bbu.h
+++ b/arch/arm/mach-omap/include/mach/bbu.h
@@ -5,11 +5,17 @@
#ifdef CONFIG_BAREBOX_UPDATE_AM33XX_SPI_NOR_MLO
int am33xx_bbu_spi_nor_mlo_register_handler(const char *name, char *devicefile);
+int am33xx_bbu_spi_nor_register_handler(const char *name, char *devicefile);
#else
static inline int am33xx_bbu_spi_nor_mlo_register_handler(const char *name, char *devicefile)
{
return 0;
}
+
+static inline int am33xx_bbu_spi_nor_register_handler(const char *name, char *devicefile)
+{
+ return 0;
+}
#endif
#endif
--
2.0.0.rc0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-05-15 10:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-05-15 10:45 [PATCH 1/2] ARM: AM33xx: swap MLO SPI image automatically Sascha Hauer
2014-05-15 10:45 ` [PATCH 2/2] ARM: AM33xx: Add SPI bbu handler Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox