From: Wadim Egorov <w.egorov@phytec.de>
To: barebox@lists.infradead.org
Subject: [PATCH 3/4] ARM: omap: barebox update nand xloadslots handler
Date: Mon, 12 May 2014 14:24:21 +0200 [thread overview]
Message-ID: <1399897462-21433-3-git-send-email-w.egorov@phytec.de> (raw)
In-Reply-To: <1399897462-21433-1-git-send-email-w.egorov@phytec.de>
- Added barebox nand xloadslots update handler
- This handler updates all given xload slots in nand
Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
---
arch/arm/mach-omap/Kconfig | 9 ++
arch/arm/mach-omap/Makefile | 1 +
arch/arm/mach-omap/am33xx_bbu_nand_xloadslots.c | 114 +++++++++++++++++++++++
arch/arm/mach-omap/include/mach/bbu.h | 11 ++
4 files changed, 135 insertions(+), 0 deletions(-)
create mode 100644 arch/arm/mach-omap/am33xx_bbu_nand_xloadslots.c
diff --git a/arch/arm/mach-omap/Kconfig b/arch/arm/mach-omap/Kconfig
index 12b9c1f..22bb878 100644
--- a/arch/arm/mach-omap/Kconfig
+++ b/arch/arm/mach-omap/Kconfig
@@ -93,6 +93,15 @@ config BAREBOX_UPDATE_AM33XX_SPI_NOR_MLO
Say Y for barebox update SPI NOR MLO handler.
AM35xx, AM33xx chips use big endian MLO for SPI NOR flash.
+config BAREBOX_UPDATE_AM33XX_NAND_XLOADSLOTS
+ prompt "barebox update nand xload slots handler"
+ bool
+ depends on BAREBOX_UPDATE
+ help
+ Say Y for barebox update nand xload slots handler.
+ This update handler updates N nand xload slots with a single command.
+ The Handler also checks if the given image has a valid CH header.
+
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 81a771e..c9b6f4b 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-$(CONFIG_BAREBOX_UPDATE_AM33XX_SPI_NOR_MLO) += am33xx_bbu_spi_mlo.o
+obj-$(CONFIG_BAREBOX_UPDATE_AM33XX_NAND_XLOADSLOTS) += am33xx_bbu_nand_xloadslots.o
diff --git a/arch/arm/mach-omap/am33xx_bbu_nand_xloadslots.c b/arch/arm/mach-omap/am33xx_bbu_nand_xloadslots.c
new file mode 100644
index 0000000..593da02
--- /dev/null
+++ b/arch/arm/mach-omap/am33xx_bbu_nand_xloadslots.c
@@ -0,0 +1,114 @@
+/*
+ * am33xx_bbu_nand_xloadslots.c - barebox update handler for
+ * the nand xload slots.
+ *
+ * Copyright (c) 2014 Wadim Egorov <w.egorov@phytec.de>, 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 <errno.h>
+#include <bbu.h>
+#include <fs.h>
+#include <fcntl.h>
+#include <filetype.h>
+
+/*
+ * This handler updates all given xload slots in nand with an image.
+ * The handler expects one or more device files in the bbu_data struct.
+ * If more than one device file needs to be updated, seperate
+ * device files with a comma. e.g.: data->devicefile = "dev1,dev2,dev3";
+ */
+static int nand_xloadslots_update_handler(struct bbu_handler *handler,
+ struct bbu_data *data)
+{
+ int ret = 0;
+ int fd = 0;
+ const void *image = data->image;
+ size_t size = data->len;
+ char *devfile;
+ const char *delimiter = ",";
+ char *devfilecopy;
+
+ if (file_detect_type(image, size) != filetype_ch_image) {
+ pr_err("%s is not a valid ch-image\n", data->imagefile);
+ return -EINVAL;
+ }
+
+ ret = bbu_confirm(data);
+ if (ret != 0)
+ return ret;
+
+ devfilecopy = (char *)malloc(strlen(data->devicefile));
+ if (!devfilecopy) {
+ pr_err("could not allocate enough memory: %s\n", errno_str());
+ return errno;
+ }
+ strcpy(devfilecopy, data->devicefile);
+
+ devfile = strtok(devfilecopy, delimiter);
+ while (devfile != NULL) {
+ ret = fd = open(devfile, O_WRONLY);
+ if (fd < 0) {
+ pr_err("could not open %s: %s\n", devfile,
+ errno_str());
+ goto out;
+ }
+
+ ret = erase(fd, ~0, 0);
+ if (ret < 0) {
+ pr_err("could not erase %s: %s\n", devfile,
+ errno_str());
+ close(fd);
+ goto out;
+ }
+
+ ret = write(fd, image, size);
+ if (ret < 0) {
+ pr_err("could not write to fd %s: %s\n", devfile,
+ errno_str());
+ close(fd);
+ goto out;
+ }
+
+ close(fd);
+ devfile = strtok(NULL, delimiter);
+ }
+
+ ret = 0;
+out:
+ free(devfilecopy);
+
+ return ret;
+}
+
+/*
+ * Register an am33xx xload slots update handler
+ */
+int am33xx_bbu_nand_xloadslots_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 = nand_xloadslots_update_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 6d4b70f..1960a38 100644
--- a/arch/arm/mach-omap/include/mach/bbu.h
+++ b/arch/arm/mach-omap/include/mach/bbu.h
@@ -12,4 +12,15 @@ int am33xx_bbu_spi_nor_mlo_register_handler(const char *name, char *devicefile)
}
#endif
+#ifdef CONFIG_BAREBOX_UPDATE_AM33XX_NAND_XLOADSLOTS
+int am33xx_bbu_nand_xloadslots_register_handler(const char *name,
+ char *devicefile);
+#else
+int am33xx_bbu_nand_xloadslots_register_handler(const char *name,
+ char *devicefile)
+{
+ return 0;
+}
+#endif
+
#endif
--
1.7.0.4
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2014-05-12 12:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-12 12:24 [PATCH 1/4] PCM051: Update RAM timings Wadim Egorov
2014-05-12 12:24 ` [PATCH 2/4] barebox: common: added new filetypes Wadim Egorov
2014-05-12 12:24 ` Wadim Egorov [this message]
2014-05-13 8:38 ` [PATCH 3/4] ARM: omap: barebox update nand xloadslots handler Sascha Hauer
2014-05-13 9:46 ` Alexander Aring
2014-05-12 12:24 ` [PATCH 4/4] phycore-am335x: Added bbu " Wadim Egorov
2014-05-12 14:13 ` Holger Schurig
2014-05-14 7:21 ` [PATCH 1/4] PCM051: Update RAM timings Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1399897462-21433-3-git-send-email-w.egorov@phytec.de \
--to=w.egorov@phytec.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox