summaryrefslogtreecommitdiffstats
path: root/commands/firmwareload.c
diff options
context:
space:
mode:
authorJuergen Beisert <jbe@pengutronix.de>2014-09-08 11:29:07 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2014-09-09 10:30:25 +0200
commita6982e2e262440f551fe4dac0378d2dea76c86f5 (patch)
tree931c5e1661eb0c3971ea5407ee1e1dd115253d1f /commands/firmwareload.c
parent5a5ba5ad30f22f0e3a4c0c56d180261136e3dfe4 (diff)
downloadbarebox-a6982e2e262440f551fe4dac0378d2dea76c86f5.tar.gz
Add a Firmware programming framework
This framework handles a list of registered Firmware programming handlers to unify a firmware programming interface by hiding the details how to program a specific Firmware in its handler. This is created with FPGAs in mind but should be usable for other devices aswell. A user has two possibilities to load a firmware. A device file is create under /dev/ which can be used to copy a firmware to. Additionally a firmwareload command is introduced which can list the registered firmware handlers and also to upload a firmware. Signed-off-by: Juergen Beisert <jbe@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/firmwareload.c')
-rw-r--r--commands/firmwareload.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/commands/firmwareload.c b/commands/firmwareload.c
new file mode 100644
index 0000000..a259695
--- /dev/null
+++ b/commands/firmwareload.c
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Juergen Beisert <kernel@pengutronix.de>, Pengutronix
+ *
+ * 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 <command.h>
+#include <getopt.h>
+#include <firmware.h>
+
+static int do_firmwareload(int argc, char *argv[])
+{
+ int ret, opt;
+ const char *name = NULL, *firmware;
+ struct firmware_mgr *mgr;
+
+ while ((opt = getopt(argc, argv, "t:l")) > 0) {
+ switch (opt) {
+ case 't':
+ name = optarg;
+ break;
+ case 'l':
+ firmwaremgr_list_handlers();
+ return 0;
+ default:
+ return COMMAND_ERROR_USAGE;
+ }
+ }
+
+ if (!(argc - optind))
+ return COMMAND_ERROR_USAGE;
+
+ firmware = argv[optind];
+
+ mgr = firmwaremgr_find(name);
+
+ if (!mgr) {
+ printf("No such programming handler found: %s\n",
+ name ? name : "default");
+ return 1;
+ }
+
+ ret = firmwaremgr_load_file(mgr, firmware);
+
+ return ret;
+}
+
+BAREBOX_CMD_HELP_START(firmwareload)
+BAREBOX_CMD_HELP_TEXT("Options:")
+BAREBOX_CMD_HELP_OPT("-t <target>", "define the firmware handler by name\n")
+BAREBOX_CMD_HELP_OPT("-l\t", "list devices capable of firmware loading\n")
+BAREBOX_CMD_HELP_END
+
+BAREBOX_CMD_START(firmwareload)
+ .cmd = do_firmwareload,
+ BAREBOX_CMD_DESC("Program a firmware file into a device")
+ BAREBOX_CMD_HELP(cmd_firmwareload_help)
+BAREBOX_CMD_END