From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: Juergen Beisert <jbe@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [SPAM] [PATCH 2/3] FPGA: add a programming command
Date: Thu, 7 Nov 2013 11:04:56 +0100 [thread overview]
Message-ID: <20131107100456.GJ26639@ns203013.ovh.net> (raw)
In-Reply-To: <1383747881-15698-3-git-send-email-jbe@pengutronix.de>
Hi,
I really do not like it
we need to have an API to load firmware same a Linux
and then provide the file name to the dev via params
Best Regards,
J.
On 15:24 Wed 06 Nov , Juergen Beisert wrote:
> This command is a simple frontend to the FPGA programming handler manager.
>
> Signed-off-by: Juergen Beisert <jbe@pengutronix.de>
> ---
> commands/Kconfig | 10 +++++
> commands/Makefile | 1 +
> commands/fpgaload.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 128 insertions(+)
> create mode 100644 commands/fpgaload.c
>
> diff --git a/commands/Kconfig b/commands/Kconfig
> index 9738ec4..bb4ccaf 100644
> --- a/commands/Kconfig
> +++ b/commands/Kconfig
> @@ -605,6 +605,16 @@ config CMD_BAREBOX_UPDATE
> select BAREBOX_UPDATE
> prompt "barebox-update"
>
> +config CMD_FPGALOAD
> + bool
> + select FPGAMANAGER
> + prompt "fpgaload"
> + help
> + Provides the "fpgaload" command which deals with FPGA firmware to
> + download it into an FPGA device. This command uses the FPGA manager
> + framework to hide the details about how program a specific FPGA
> + device.
> +
> config CMD_TIMEOUT
> tristate
> prompt "timeout"
> diff --git a/commands/Makefile b/commands/Makefile
> index 58d27fa..864ca0c 100644
> --- a/commands/Makefile
> +++ b/commands/Makefile
> @@ -93,3 +93,4 @@ obj-$(CONFIG_CMD_MIITOOL) += miitool.o
> obj-$(CONFIG_CMD_DETECT) += detect.o
> obj-$(CONFIG_CMD_BOOT) += boot.o
> obj-$(CONFIG_CMD_DEVINFO) += devinfo.o
> +obj-$(CONFIG_CMD_FPGALOAD) += fpgaload.o
> diff --git a/commands/fpgaload.c b/commands/fpgaload.c
> new file mode 100644
> index 0000000..677ff73
> --- /dev/null
> +++ b/commands/fpgaload.c
> @@ -0,0 +1,117 @@
> +/*
> + * 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 <fpgamgr.h>
> +#include <fs.h>
> +#include <fcntl.h>
> +#include <linux/stat.h>
> +
> +static int fpgaload_write_data(struct fpga_mgr *mgr, const char *firmware)
> +{
> + int fd, ret;
> + struct stat s;
> + size_t sz;
> + unsigned char buffer[256]; /* must always be a multiple of 8 bytes! */
> +
> + ret = stat(firmware, &s);
> + if (ret != 0) {
> + printf("Unable to access file '%s'\n", firmware);
> + return -EINVAL;
> + }
> +
> + fd = open(firmware, O_RDONLY);
> + if (fd < 0)
> + return fd;
> +
> + do {
> + sz = read(fd, buffer, sizeof(buffer));
> + if (sz == 0)
> + break;
> + ret = fpgamgr_prog_fpga(mgr, buffer, sz);
> + if (ret < 0)
> + break;
> + } while (1);
> +
> + close(fd);
> + return 0;
> +}
> +
> +static int do_fpgaload(int argc, char *argv[])
> +{
> + int ret, opt, index = -1;
> + const char *name = NULL, *firmware;
> + struct fpga_mgr *mgr;
> +
> + while ((opt = getopt(argc, argv, "t:i:l")) > 0) {
> + switch (opt) {
> + case 't':
> + name = optarg;
> + break;
> + case 'i':
> + index = simple_strtoul(optarg, NULL, 0);
> + break;
> + case 'l':
> + printf("registered programming handlers:\n");
> + fpgamgr_handlers_list();
> + return 0;
> + default:
> + return COMMAND_ERROR_USAGE;
> + }
> + }
> +
> + if (!(argc - optind))
> + return COMMAND_ERROR_USAGE;
> +
> + firmware = argv[optind];
> +
> + mgr = fpgamgr_find_handler(name, index);
> + if (mgr == NULL) {
> + printf("No such programming handler found\n");
> + return 1;
> + }
> +
> + ret = fpgamgr_open_fpga(mgr);
> + if (ret == -ENOSYS) {
> + /* this might be a bug... */
> + pr_debug("No programming initiater function defined\n");
> + }
> +
> + ret = fpgaload_write_data(mgr, firmware);
> + if (ret != 0)
> + return 1;
> +
> + ret = fpgamgr_close_fpga(mgr);
> + if (ret == -ENOSYS) {
> + /* this might be a bug... */
> + pr_debug("No programming finisher function defined\n");
> + }
> +
> + return 0;
> +}
> +
> +BAREBOX_CMD_HELP_START(fpgaload)
> +BAREBOX_CMD_HELP_USAGE("fpgaload [OPTIONS] <firmware>\n")
> +BAREBOX_CMD_HELP_SHORT("Program a firmware file content into an FPGA\n")
> +BAREBOX_CMD_HELP_OPT("-t <target>", "define the FPGA handler by name\n")
> +BAREBOX_CMD_HELP_OPT("-i <index>", "define the FPGA handler by index\n")
> +BAREBOX_CMD_HELP_OPT("-l\t", "list registered FPGAs\n")
> +BAREBOX_CMD_HELP_END
> +
> +BAREBOX_CMD_START(fpgaload)
> + .cmd = do_fpgaload,
> + .usage = "program an FPGA",
> + BAREBOX_CMD_HELP(cmd_fpgaload_help)
> +BAREBOX_CMD_END
> --
> 1.8.4.rc3
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-11-07 10:03 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-06 14:24 [RFC] FPGA: add a simple framework for firmware programming Juergen Beisert
2013-11-06 14:24 ` [PATCH 1/3] FPGA: add a simple programming handler framework Juergen Beisert
2013-11-06 14:36 ` Alexander Shiyan
2013-11-06 14:24 ` [PATCH 2/3] FPGA: add a programming command Juergen Beisert
2013-11-07 10:04 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-11-07 11:09 ` [SPAM] " Sascha Hauer
2013-11-07 14:37 ` Jean-Christophe PLAGNIOL-VILLARD
2013-11-07 14:37 ` Lucas Stach
2013-11-07 15:27 ` Jean-Christophe PLAGNIOL-VILLARD
2013-11-08 8:22 ` Sascha Hauer
2013-11-06 14:24 ` [PATCH 3/3] FPGA: provide a handler to program ALTERA FPGAs Juergen Beisert
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=20131107100456.GJ26639@ns203013.ovh.net \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
--cc=jbe@pengutronix.de \
/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