2022-08-30 10:01:12 -05:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2022-06-26 18:26:22 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Dominic Rath *
|
|
|
|
* Dominic.Rath@gmx.de *
|
|
|
|
***************************************************************************/
|
2012-01-27 10:45:29 -06:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "pld.h"
|
2022-12-14 02:27:38 -06:00
|
|
|
#include <sys/stat.h>
|
2009-12-03 06:14:28 -06:00
|
|
|
#include <helper/log.h>
|
2021-04-19 15:04:30 -05:00
|
|
|
#include <helper/replacements.h>
|
2009-12-03 06:14:29 -06:00
|
|
|
#include <helper/time_support.h>
|
2006-11-22 07:03:10 -06:00
|
|
|
|
|
|
|
|
|
|
|
/* pld drivers
|
|
|
|
*/
|
2022-12-12 02:49:51 -06:00
|
|
|
extern struct pld_driver efinix_pld;
|
2022-12-12 02:49:51 -06:00
|
|
|
extern struct pld_driver intel_pld;
|
2022-12-12 02:49:51 -06:00
|
|
|
extern struct pld_driver lattice_pld;
|
2009-11-13 10:14:52 -06:00
|
|
|
extern struct pld_driver virtex2_pld;
|
2006-11-22 07:03:10 -06:00
|
|
|
|
2012-01-27 10:45:29 -06:00
|
|
|
static struct pld_driver *pld_drivers[] = {
|
2022-12-12 02:49:51 -06:00
|
|
|
&efinix_pld,
|
2022-12-12 02:49:51 -06:00
|
|
|
&intel_pld,
|
2022-12-12 02:49:51 -06:00
|
|
|
&lattice_pld,
|
2006-11-22 07:03:10 -06:00
|
|
|
&virtex2_pld,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2009-11-13 10:15:00 -06:00
|
|
|
static struct pld_device *pld_devices;
|
2006-11-22 07:03:10 -06:00
|
|
|
|
2009-11-13 10:15:00 -06:00
|
|
|
struct pld_device *get_pld_device_by_num(int num)
|
2006-11-22 07:03:10 -06:00
|
|
|
{
|
2009-11-13 10:15:00 -06:00
|
|
|
struct pld_device *p;
|
2006-11-22 07:03:10 -06:00
|
|
|
int i = 0;
|
|
|
|
|
2012-01-27 10:45:29 -06:00
|
|
|
for (p = pld_devices; p; p = p->next) {
|
2006-11-22 07:03:10 -06:00
|
|
|
if (i++ == num)
|
|
|
|
return p;
|
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pld device <driver> [driver_options ...]
|
|
|
|
*/
|
2009-11-10 01:56:52 -06:00
|
|
|
COMMAND_HANDLER(handle_pld_device_command)
|
2006-11-22 07:03:10 -06:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int found = 0;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2009-11-15 06:57:12 -06:00
|
|
|
if (CMD_ARGC < 1)
|
2011-12-16 00:48:39 -06:00
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2012-01-27 10:45:29 -06:00
|
|
|
for (i = 0; pld_drivers[i]; i++) {
|
|
|
|
if (strcmp(CMD_ARGV[0], pld_drivers[i]->name) == 0) {
|
2009-11-13 10:15:00 -06:00
|
|
|
struct pld_device *p, *c;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
/* register pld specific commands */
|
2009-11-23 11:30:02 -06:00
|
|
|
int retval;
|
|
|
|
if (pld_drivers[i]->commands) {
|
2021-11-08 17:04:52 -06:00
|
|
|
retval = register_commands(CMD_CTX, NULL, pld_drivers[i]->commands);
|
2021-07-03 09:47:35 -05:00
|
|
|
if (retval != ERROR_OK) {
|
2009-11-23 11:30:02 -06:00
|
|
|
LOG_ERROR("couldn't register '%s' commands", CMD_ARGV[0]);
|
|
|
|
return ERROR_FAIL;
|
|
|
|
}
|
2006-11-22 07:03:10 -06:00
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2009-11-13 10:15:00 -06:00
|
|
|
c = malloc(sizeof(struct pld_device));
|
2006-11-22 07:03:10 -06:00
|
|
|
c->driver = pld_drivers[i];
|
|
|
|
c->next = NULL;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2010-01-09 01:23:55 -06:00
|
|
|
retval = CALL_COMMAND_HANDLER(
|
|
|
|
pld_drivers[i]->pld_device_command, c);
|
2021-07-03 09:47:35 -05:00
|
|
|
if (retval != ERROR_OK) {
|
2010-01-09 01:23:55 -06:00
|
|
|
LOG_ERROR("'%s' driver rejected pld device",
|
2012-01-27 10:45:29 -06:00
|
|
|
CMD_ARGV[0]);
|
2006-11-22 07:03:10 -06:00
|
|
|
free(c);
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
/* put pld device in linked list */
|
2012-01-27 10:45:29 -06:00
|
|
|
if (pld_devices) {
|
2006-11-22 07:03:10 -06:00
|
|
|
/* find last pld device */
|
2012-01-27 10:45:29 -06:00
|
|
|
for (p = pld_devices; p && p->next; p = p->next)
|
|
|
|
;
|
2006-11-22 07:03:10 -06:00
|
|
|
if (p)
|
|
|
|
p->next = c;
|
2012-01-27 10:45:29 -06:00
|
|
|
} else
|
2006-11-22 07:03:10 -06:00
|
|
|
pld_devices = c;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
/* no matching pld driver found */
|
2012-01-27 10:45:29 -06:00
|
|
|
if (!found) {
|
2009-11-15 10:15:59 -06:00
|
|
|
LOG_ERROR("pld driver '%s' not found", CMD_ARGV[0]);
|
2006-11-22 07:03:10 -06:00
|
|
|
exit(-1);
|
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-10 01:56:52 -06:00
|
|
|
COMMAND_HANDLER(handle_pld_devices_command)
|
2006-11-22 07:03:10 -06:00
|
|
|
{
|
2009-11-13 10:15:00 -06:00
|
|
|
struct pld_device *p;
|
2006-11-22 07:03:10 -06:00
|
|
|
int i = 0;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2012-01-27 10:45:29 -06:00
|
|
|
if (!pld_devices) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "no pld devices configured");
|
2006-11-22 07:03:10 -06:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
for (p = pld_devices; p; p = p->next)
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "#%i: %s", i++, p->driver->name);
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-10 01:56:52 -06:00
|
|
|
COMMAND_HANDLER(handle_pld_load_command)
|
2006-11-22 07:03:10 -06:00
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
struct timeval start, end, duration;
|
2009-11-13 10:15:00 -06:00
|
|
|
struct pld_device *p;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
gettimeofday(&start, NULL);
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2009-11-15 06:57:12 -06:00
|
|
|
if (CMD_ARGC < 2)
|
2011-12-16 00:48:39 -06:00
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2009-10-24 03:22:58 -05:00
|
|
|
unsigned dev_id;
|
2009-11-15 10:15:59 -06:00
|
|
|
COMMAND_PARSE_NUMBER(uint, CMD_ARGV[0], dev_id);
|
2009-10-24 03:22:58 -05:00
|
|
|
p = get_pld_device_by_num(dev_id);
|
2012-01-27 10:45:29 -06:00
|
|
|
if (!p) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "pld device '#%s' is out of bounds", CMD_ARGV[0]);
|
2006-11-22 07:03:10 -06:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2022-12-14 02:27:38 -06:00
|
|
|
struct stat input_stat;
|
|
|
|
if (stat(CMD_ARGV[1], &input_stat) == -1) {
|
|
|
|
LOG_ERROR("couldn't stat() %s: %s", CMD_ARGV[1], strerror(errno));
|
|
|
|
return ERROR_PLD_FILE_LOAD_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (S_ISDIR(input_stat.st_mode)) {
|
|
|
|
LOG_ERROR("%s is a directory", CMD_ARGV[1]);
|
|
|
|
return ERROR_PLD_FILE_LOAD_FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input_stat.st_size == 0) {
|
|
|
|
LOG_ERROR("Empty file %s", CMD_ARGV[1]);
|
|
|
|
return ERROR_PLD_FILE_LOAD_FAILED;
|
|
|
|
}
|
|
|
|
|
2012-01-27 10:45:29 -06:00
|
|
|
retval = p->driver->load(p, CMD_ARGV[1]);
|
|
|
|
if (retval != ERROR_OK) {
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "failed loading file %s to pld device %u",
|
2009-11-15 10:15:59 -06:00
|
|
|
CMD_ARGV[1], dev_id);
|
2012-01-27 10:45:29 -06:00
|
|
|
switch (retval) {
|
2006-11-22 07:03:10 -06:00
|
|
|
}
|
2009-10-24 03:22:58 -05:00
|
|
|
return retval;
|
2012-01-27 10:45:29 -06:00
|
|
|
} else {
|
2009-06-17 19:29:45 -05:00
|
|
|
gettimeofday(&end, NULL);
|
2006-11-22 07:03:10 -06:00
|
|
|
timeval_subtract(&duration, &end, &start);
|
2009-05-21 04:28:57 -05:00
|
|
|
|
helper/command: change prototype of command_print/command_print_sameline
To prepare for handling TCL return values consistently, all calls
to command_print/command_print_sameline should switch to CMD as
first parameter.
Change prototype of command_print() and command_print_sameline()
to pass CMD instead of CMD_CTX.
Since the first parameter is currently not used, the change can be
done though scripts without manual coding.
This patch is created using the command:
sed -i PATTERN $(find src/ doc/ -type f)
with all the following patters:
's/\(command_print(cmd\)->ctx,/\1,/'
's/\(command_print(CMD\)_CTX,/\1,/'
's/\(command_print(struct command_\)context \*context,/\1invocation *cmd,/'
's/\(command_print_sameline(cmd\)->ctx,/\1,/'
's/\(command_print_sameline(CMD\)_CTX,/\1,/'
's/\(command_print_sameline(struct command_\)context \*context,/\1invocation *cmd,/'
This change is inspired by http://openocd.zylin.com/1815 from Paul
Fertser but is now done through scripting.
Change-Id: I3386d8f96cdc477e7a2308dd18269de3bed04385
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/5081
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
2019-04-03 03:37:24 -05:00
|
|
|
command_print(CMD, "loaded file %s to pld device %u in %jis %jius",
|
2009-11-15 10:15:59 -06:00
|
|
|
CMD_ARGV[1], dev_id,
|
2009-05-22 12:41:54 -05:00
|
|
|
(intmax_t)duration.tv_sec, (intmax_t)duration.tv_usec);
|
2006-11-22 07:03:10 -06:00
|
|
|
}
|
2009-06-17 19:29:45 -05:00
|
|
|
|
2006-11-22 07:03:10 -06:00
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-22 03:50:22 -06:00
|
|
|
static const struct command_registration pld_exec_command_handlers[] = {
|
|
|
|
{
|
|
|
|
.name = "devices",
|
2010-01-09 01:23:55 -06:00
|
|
|
.handler = handle_pld_devices_command,
|
2009-11-22 03:50:22 -06:00
|
|
|
.mode = COMMAND_EXEC,
|
|
|
|
.help = "list configured pld devices",
|
2019-01-04 11:16:00 -06:00
|
|
|
.usage = "",
|
2009-11-22 03:50:22 -06:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.name = "load",
|
2010-01-09 01:23:55 -06:00
|
|
|
.handler = handle_pld_load_command,
|
2009-11-22 03:50:22 -06:00
|
|
|
.mode = COMMAND_EXEC,
|
|
|
|
.help = "load configuration file into PLD",
|
2010-01-09 01:23:55 -06:00
|
|
|
.usage = "pld_num filename",
|
2009-11-22 03:50:22 -06:00
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
2010-04-10 04:06:16 -05:00
|
|
|
|
|
|
|
static int pld_init(struct command_context *cmd_ctx)
|
2009-11-10 01:20:34 -06:00
|
|
|
{
|
|
|
|
if (!pld_devices)
|
|
|
|
return ERROR_OK;
|
|
|
|
|
2020-05-10 12:35:56 -05:00
|
|
|
return register_commands(cmd_ctx, "pld", pld_exec_command_handlers);
|
2009-11-10 01:20:34 -06:00
|
|
|
}
|
|
|
|
|
2009-11-30 19:20:18 -06:00
|
|
|
COMMAND_HANDLER(handle_pld_init_command)
|
|
|
|
{
|
|
|
|
if (CMD_ARGC != 0)
|
|
|
|
return ERROR_COMMAND_SYNTAX_ERROR;
|
|
|
|
|
2012-01-27 10:45:29 -06:00
|
|
|
static bool pld_initialized;
|
|
|
|
if (pld_initialized) {
|
2009-11-30 19:20:18 -06:00
|
|
|
LOG_INFO("'pld init' has already been called");
|
|
|
|
return ERROR_OK;
|
|
|
|
}
|
|
|
|
pld_initialized = true;
|
|
|
|
|
|
|
|
LOG_DEBUG("Initializing PLDs...");
|
|
|
|
return pld_init(CMD_CTX);
|
|
|
|
}
|
|
|
|
|
2009-11-22 03:50:22 -06:00
|
|
|
static const struct command_registration pld_config_command_handlers[] = {
|
|
|
|
{
|
|
|
|
.name = "device",
|
|
|
|
.mode = COMMAND_CONFIG,
|
2010-01-09 01:23:55 -06:00
|
|
|
.handler = handle_pld_device_command,
|
2009-11-22 03:50:22 -06:00
|
|
|
.help = "configure a PLD device",
|
2010-01-09 01:23:55 -06:00
|
|
|
.usage = "driver_name [driver_args ... ]",
|
2009-11-22 03:50:22 -06:00
|
|
|
},
|
2009-11-30 19:20:18 -06:00
|
|
|
{
|
|
|
|
.name = "init",
|
|
|
|
.mode = COMMAND_CONFIG,
|
2010-01-09 01:23:55 -06:00
|
|
|
.handler = handle_pld_init_command,
|
2009-11-30 19:20:18 -06:00
|
|
|
.help = "initialize PLD devices",
|
2012-01-16 07:35:23 -06:00
|
|
|
.usage = ""
|
2009-11-30 19:20:18 -06:00
|
|
|
},
|
2009-11-22 03:50:22 -06:00
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
|
|
|
static const struct command_registration pld_command_handler[] = {
|
|
|
|
{
|
|
|
|
.name = "pld",
|
|
|
|
.mode = COMMAND_ANY,
|
|
|
|
.help = "programmable logic device commands",
|
2012-01-16 07:35:23 -06:00
|
|
|
.usage = "",
|
2009-11-22 03:50:22 -06:00
|
|
|
.chain = pld_config_command_handlers,
|
|
|
|
},
|
|
|
|
COMMAND_REGISTRATION_DONE
|
|
|
|
};
|
2009-11-13 15:25:47 -06:00
|
|
|
int pld_register_commands(struct command_context *cmd_ctx)
|
2006-11-22 07:03:10 -06:00
|
|
|
{
|
2009-11-22 03:50:22 -06:00
|
|
|
return register_commands(cmd_ctx, NULL, pld_command_handler);
|
2006-11-22 07:03:10 -06:00
|
|
|
}
|