summaryrefslogtreecommitdiffstats
path: root/arch/arm/mach-mvebu
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2018-06-08 10:42:44 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2018-06-13 10:27:51 +0200
commit1088743f7901d02e8af9c6d615976322e7b04a32 (patch)
tree89d8031295946eb4d9f27d3c1c203cdce37f6464 /arch/arm/mach-mvebu
parentea76b4c386b231233222d6adf1d93776600f8899 (diff)
downloadbarebox-1088743f7901d02e8af9c6d615976322e7b04a32.tar.gz
barebox-1088743f7901d02e8af9c6d615976322e7b04a32.tar.xz
mvebu: create bbu handler for kwb images and use it on cubox
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch/arm/mach-mvebu')
-rw-r--r--arch/arm/mach-mvebu/Makefile1
-rw-r--r--arch/arm/mach-mvebu/include/mach/bbu.h12
-rw-r--r--arch/arm/mach-mvebu/kwb_bbu.c54
3 files changed, 67 insertions, 0 deletions
diff --git a/arch/arm/mach-mvebu/Makefile b/arch/arm/mach-mvebu/Makefile
index 87a8511919..6079403b83 100644
--- a/arch/arm/mach-mvebu/Makefile
+++ b/arch/arm/mach-mvebu/Makefile
@@ -4,4 +4,5 @@ obj-$(CONFIG_ARCH_ARMADA_XP) += armada-370-xp.o
obj-$(CONFIG_ARCH_ARMADA_38X) += armada-370-xp.o
obj-$(CONFIG_ARCH_DOVE) += dove.o
obj-$(CONFIG_ARCH_KIRKWOOD) += kirkwood.o
+obj-$(CONFIG_BAREBOX_UPDATE) += kwb_bbu.o
obj-$(CONFIG_BOOTM) += kwbootimage.o
diff --git a/arch/arm/mach-mvebu/include/mach/bbu.h b/arch/arm/mach-mvebu/include/mach/bbu.h
new file mode 100644
index 0000000000..a06db2b144
--- /dev/null
+++ b/arch/arm/mach-mvebu/include/mach/bbu.h
@@ -0,0 +1,12 @@
+#ifdef CONFIG_BAREBOX_UPDATE
+int mvebu_bbu_flash_register_handler(const char *name,
+ char *devicefile, int version,
+ bool isdefault);
+#else
+int mvebu_bbu_flash_register_handler(const char *name,
+ char *devicefile, int version,
+ bool isdefault)
+{
+ return -ENOSYS;
+}
+#endif
diff --git a/arch/arm/mach-mvebu/kwb_bbu.c b/arch/arm/mach-mvebu/kwb_bbu.c
new file mode 100644
index 0000000000..f79464fe53
--- /dev/null
+++ b/arch/arm/mach-mvebu/kwb_bbu.c
@@ -0,0 +1,54 @@
+#include <bbu.h>
+#include <libfile.h>
+#include <printk.h>
+
+#include <mach/bbu.h>
+
+struct mvebu_bbu_handler {
+ struct bbu_handler bbuh;
+ int version;
+};
+
+static int mvebu_bbu_flash_update_handler(struct bbu_handler *bbuh,
+ struct bbu_data *data)
+{
+ struct mvebu_bbu_handler *mbbuh =
+ container_of(bbuh, struct mvebu_bbu_handler, bbuh);
+ const void *image = data->image;
+ size_t size = data->len;
+ enum filetype ft = file_detect_type(image, size);
+
+ if ((mbbuh->version == 0 && ft == filetype_kwbimage_v0) ||
+ (mbbuh->version == 1 && ft == filetype_kwbimage_v1) ||
+ data->flags & BBU_FLAG_FORCE) {
+ int ret = bbu_confirm(data);
+ if (ret)
+ return ret;
+
+ return write_file_flash(bbuh->devicefile, image, size);
+ } else {
+ pr_err("%s is not a valid kwbimage\n", data->imagefile);
+ return -EINVAL;
+ }
+}
+
+int mvebu_bbu_flash_register_handler(const char *name,
+ char *devicefile, int version,
+ bool isdefault)
+{
+ struct mvebu_bbu_handler *mbbuh;
+ int ret;
+
+ mbbuh = xzalloc(sizeof(*mbbuh));
+ mbbuh->bbuh.devicefile = devicefile;
+ mbbuh->bbuh.handler = mvebu_bbu_flash_update_handler;
+ mbbuh->bbuh.flags = isdefault ? BBU_HANDLER_FLAG_DEFAULT : 0;
+ mbbuh->bbuh.name = name;
+ mbbuh->version = version;
+
+ ret = bbu_register_handler(&mbbuh->bbuh);
+ if (ret)
+ free(mbbuh);
+
+ return ret;
+}