mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] ARM: omap: barebox update spi nor MLO handler
@ 2013-08-22 12:05 Shravan Kumar
  2013-08-22 12:05 ` [PATCH 2/2] PCM051: Added barebox update SPI NOR " Shravan Kumar
  2013-08-23  6:46 ` [PATCH 1/2] ARM: omap: barebox update spi nor " Sascha Hauer
  0 siblings, 2 replies; 3+ messages in thread
From: Shravan Kumar @ 2013-08-22 12:05 UTC (permalink / raw)
  To: barebox; +Cc: shravan

From: shravan <shravan.k@phytec.in>

	-Added mlo spi NOR copy handler
	-This handler will convert the MLO to big endian
	-Tested with pcm051 board

Signed-off-by: shravan <shravan.k@phytec.in>
---
 arch/arm/mach-omap/Kconfig            |    8 +++
 arch/arm/mach-omap/Makefile           |    1 +
 arch/arm/mach-omap/include/mach/bbu.h |   15 ++++++
 arch/arm/mach-omap/omap_bbu_spi_mlo.c |   88 +++++++++++++++++++++++++++++++++
 4 files changed, 112 insertions(+)
 create mode 100644 arch/arm/mach-omap/include/mach/bbu.h
 create mode 100644 arch/arm/mach-omap/omap_bbu_spi_mlo.c

diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 3ec18f0..e137961 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -90,6 +90,14 @@ config OMAP_BUILD_SPI
 	  Say Y here if you want to build an barebox.spi image as used
 	  on the AM35xx chips when booting from SPI NOR flash.
 
+config BAREBOX_UPDATE_OMAP_SPI_NOR_MLO
+	prompt "barebox update SPI NOR MLO handler"
+	bool
+	depends on BAREBOX_UPDATE
+	help
+          Say Y for barebox update SPI NOR MLO handler.
+          AM35xx, AM33xx chips use big endian MLO for SPI NOR flash.
+
 config ARCH_TEXT_BASE
 	hex
 	default 0x80e80000 if MACH_OMAP343xSDP
diff --git a/arch/arm/mach-omap/Makefile b/arch/arm/mach-omap/Makefile
index d42de48..e90b350 100644
--- a/arch/arm/mach-omap/Makefile
+++ b/arch/arm/mach-omap/Makefile
@@ -32,3 +32,4 @@ obj-$(CONFIG_MFD_TWL6030) += omap4_twl6030_mmc.o
 obj-$(CONFIG_OMAP4_USBBOOT) += omap4_rom_usb.o
 obj-$(CONFIG_CMD_BOOT_ORDER) += boot_order.o
 obj-y += gpio.o
+obj-$(CONFIG_BAREBOX_UPDATE_OMAP_SPI_NOR_MLO) += omap_bbu_spi_mlo.o
diff --git a/arch/arm/mach-omap/include/mach/bbu.h b/arch/arm/mach-omap/include/mach/bbu.h
new file mode 100644
index 0000000..b9df835
--- /dev/null
+++ b/arch/arm/mach-omap/include/mach/bbu.h
@@ -0,0 +1,15 @@
+#ifndef __MACH_BBU_H
+#define __MACH_BBU_H
+
+#include <bbu.h>
+
+#ifdef CONFIG_BAREBOX_UPDATE_OMAP_SPI_NOR_MLO
+int omap_bbu_spi_nor_mlo_register_handler(const char *name, char *devicefile);
+#else
+int omap_bbu_spi_nor_mlo_register_handler(const char *name, char *devicefile)
+{
+	return 0;
+}
+#endif
+
+#endif
diff --git a/arch/arm/mach-omap/omap_bbu_spi_mlo.c b/arch/arm/mach-omap/omap_bbu_spi_mlo.c
new file mode 100644
index 0000000..4fe0014
--- /dev/null
+++ b/arch/arm/mach-omap/omap_bbu_spi_mlo.c
@@ -0,0 +1,88 @@
+/*
+ * omap_bbu_spi_mlo.c - am35xx and am33xx specific MLO
+ *	update handler for SPI NOR flash
+ *
+ * Copyright (c) 2013 Sharavn kumar <shravan.k@phytec.in>, Phytec
+ *
+ * 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>
+#include <malloc.h>
+#include <bbu.h>
+#include <fs.h>
+#include <fcntl.h>
+
+/*
+ * AM35xx, AM33xx chips use big endian MLO for SPI NOR flash
+ * This handler converting MLO to big endian and write to SPI NOR
+ */
+static int spi_nor_mlo_handler(struct bbu_handler *handler,
+					struct bbu_data *data)
+{
+	int dstfd = 0;
+	int ret = 0;
+	uint32_t readbuf;
+	int size = data->len;
+	void *image = data->image;
+
+	dstfd = open(data->devicefile, O_WRONLY);
+	if (dstfd < 0) {
+		printf("could not open %s: %s", data->devicefile, errno_str());
+		ret = dstfd;
+		goto out;
+	}
+
+	ret = erase(dstfd, ~0, 0);
+	if (ret < 0) {
+		printf("could not erase %s: %s", data->devicefile, errno_str());
+		goto out1;
+	}
+
+	for (; size >= 0; size -= 4) {
+		memcpy((char *)&readbuf, image, 4);
+
+		readbuf = cpu_to_be32(readbuf);
+		ret = write(dstfd, &readbuf, 4);
+		if (ret < 0) {
+			perror("write");
+			goto out1;
+		}
+
+		image = image + 4;
+	}
+
+	ret = 0;
+out1:
+	close(dstfd);
+out:
+	return ret;
+}
+
+/*
+ * Register a omap MLO update handler for SPI NOR
+ */
+int omap_bbu_spi_nor_mlo_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_mlo_handler;
+
+	ret = bbu_register_handler(handler);
+
+	if (ret)
+		free(handler);
+
+	return ret;
+}
-- 
1.7.9.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] PCM051: Added barebox update SPI NOR MLO handler
  2013-08-22 12:05 [PATCH 1/2] ARM: omap: barebox update spi nor MLO handler Shravan Kumar
@ 2013-08-22 12:05 ` Shravan Kumar
  2013-08-23  6:46 ` [PATCH 1/2] ARM: omap: barebox update spi nor " Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Shravan Kumar @ 2013-08-22 12:05 UTC (permalink / raw)
  To: barebox; +Cc: shravan

From: shravan <shravan.k@phytec.in>

Signed-off-by: shravan <shravan.k@phytec.in>
---
 arch/arm/boards/pcm051/board.c    |    3 +++
 arch/arm/configs/pcm051_defconfig |    1 +
 2 files changed, 4 insertions(+)

diff --git a/arch/arm/boards/pcm051/board.c b/arch/arm/boards/pcm051/board.c
index 35a3a25..8ce3953 100644
--- a/arch/arm/boards/pcm051/board.c
+++ b/arch/arm/boards/pcm051/board.c
@@ -39,6 +39,7 @@
 #include <spi/flash.h>
 #include <i2c/i2c.h>
 #include <i2c/at24.h>
+#include <mach/bbu.h>
 
 #include "mux.h"
 
@@ -209,6 +210,8 @@ static int pcm051_devices_init(void)
 	armlinux_set_bootparams((void *)(AM33XX_DRAM_ADDR_SPACE_START + 0x100));
 	armlinux_set_architecture(MACH_TYPE_PCM051);
 
+	omap_bbu_spi_nor_mlo_register_handler("MLO.spi", "/dev/m25p0.xload");
+
 	return 0;
 }
 device_initcall(pcm051_devices_init);
diff --git a/arch/arm/configs/pcm051_defconfig b/arch/arm/configs/pcm051_defconfig
index 0bc7c90..13ddf07 100644
--- a/arch/arm/configs/pcm051_defconfig
+++ b/arch/arm/configs/pcm051_defconfig
@@ -1,5 +1,6 @@
 CONFIG_ARCH_OMAP=y
 CONFIG_ARCH_AM33XX=y
+CONFIG_BAREBOX_UPDATE_OMAP_SPI_NOR_MLO=y
 CONFIG_MACH_PCM051=y
 CONFIG_OMAP_UART1=y
 CONFIG_AEABI=y
-- 
1.7.9.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] ARM: omap: barebox update spi nor MLO handler
  2013-08-22 12:05 [PATCH 1/2] ARM: omap: barebox update spi nor MLO handler Shravan Kumar
  2013-08-22 12:05 ` [PATCH 2/2] PCM051: Added barebox update SPI NOR " Shravan Kumar
@ 2013-08-23  6:46 ` Sascha Hauer
  1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2013-08-23  6:46 UTC (permalink / raw)
  To: Shravan Kumar; +Cc: barebox

Hi Shravan,

On Thu, Aug 22, 2013 at 02:05:36PM +0200, Shravan Kumar wrote:
> From: shravan <shravan.k@phytec.in>
> 
> 	-Added mlo spi NOR copy handler
> 	-This handler will convert the MLO to big endian
> 	-Tested with pcm051 board
> 
> +/*
> + * Register a omap MLO update handler for SPI NOR
> + */
> +int omap_bbu_spi_nor_mlo_register_handler(const char *name, char *devicefile)
> +{

Does this work with "real" omaps? The comment in the header seems to
imply that it only works for am33xx. If this is the case, the function
should be named am33xx_bbu_spi_nor_mlo_register_handler.

Otherwise this series looks fine.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-08-23  6:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-22 12:05 [PATCH 1/2] ARM: omap: barebox update spi nor MLO handler Shravan Kumar
2013-08-22 12:05 ` [PATCH 2/2] PCM051: Added barebox update SPI NOR " Shravan Kumar
2013-08-23  6:46 ` [PATCH 1/2] ARM: omap: barebox update spi nor " Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox