Commit 9da6cd3b authored by Dimitris Lampridis's avatar Dimitris Lampridis Committed by Dimitris Lampridis

sw: remove load_firmware() function

This is too low-level for WRTD. If necessary during development, it can be done directly through MockTurtle
parent d744cedf
......@@ -286,101 +286,6 @@ enum wrtd_status wrtd_reset(struct wrtd_dev *dev)
}
enum wrtd_status wrtd_get_firmware_id(struct wrtd_dev *dev,
unsigned *nbr_ids,
uint32_t *ids)
{
enum wrtd_status status;
int i;
status = wrtd_fill_roots(dev);
WRTD_RETURN_IF_ERROR(status);
*nbr_ids = dev->nbr_cpus;
for (i = 0; i < dev->nbr_cpus; i++) {
ids[i] = dev->roots[i].fw_id;
}
return WRTD_SUCCESS;
}
enum wrtd_status wrtd_load_firmware(struct wrtd_dev *dev, unsigned verbose,
unsigned int nbr_firmwares,
struct wrtd_firmware *fw)
{
struct trtl_fw_version version;
enum wrtd_status status;
int err;
int i, j;
struct wrtd_firmware *map[WRTD_MAX_CPUS];
status = wrtd_fill_roots(dev);
WRTD_RETURN_IF_ERROR(status);
/* Find firmwares. */
for (i = 0; i < dev->nbr_cpus; i++) {
map[i] = NULL;
for (j = 0; j < nbr_firmwares; j++)
if (dev->roots[i].fw_id == fw[j].id) {
map[i] = &fw[j];
break;
}
if (map[i] == NULL) {
/* Missing firmware. */
return wrtd_return_error
(dev, WRTD_ERROR_RESOURCE_UNKNOWN,
"no firmware for app 0x%x",
dev->roots[i].fw_id);
}
}
/* Load firmwares. */
for (i = 0; i < dev->nbr_cpus; i++) {
if (verbose)
printf("loading cpu %d with %s\n", i, map[i]->path);
err = trtl_cpu_load_application_file (dev->trtl,
i, map[i]->path);
if (err)
return wrtd_return_error
(dev, WRTD_ERROR_UNEXPECTED_RESPONSE,
"cannot load application");
if (verbose)
printf("start cpu %d\n", i);
err = trtl_cpu_enable(dev->trtl, i);
if (err)
return wrtd_return_error
(dev, WRTD_ERROR_UNEXPECTED_RESPONSE,
"cannot start cpu");
}
/* Check CPUs. */
for (i = 0; i < dev->nbr_cpus; i++) {
if (verbose)
printf("waiting cpu %d to be ready\n", i);
/* Do a ping, but wait for 5sec for the FW to be ready. */
err = trtl_fw_ping_timeout(dev->trtl, i, 0, 5000);
if (err)
return wrtd_return_error
(dev, WRTD_ERROR_UNEXPECTED_RESPONSE,
"ping failed on cpu %d", i);
err = trtl_fw_version(dev->trtl, i, 0, &version);
if (err)
return wrtd_return_error
(dev, WRTD_ERROR_UNEXPECTED_RESPONSE,
"cannot get version on cpu %d", i);
if (version.rt_id != map[i]->id)
return wrtd_return_error
(dev, WRTD_ERROR_UNEXPECTED_RESPONSE,
"firmware id mismatch on cpu %d", i);
}
return WRTD_SUCCESS;
}
enum wrtd_status wrtd_msg_get_config(struct wrtd_dev *wrtd, unsigned cpu,
struct wrtd_config_msg *res)
{
......
......@@ -79,22 +79,6 @@ extern enum wrtd_status wrtd_return_error(struct wrtd_dev *dev,
/* Get current error message. Simpler than the official API. */
extern const char *wrtd_get_error_msg(struct wrtd_dev *dev);
/* Get the list of firmware expected by cpus.
IDS must be at least WRTD_MAX_CPUS long. */
extern enum wrtd_status wrtd_get_firmware_id(struct wrtd_dev *dev,
unsigned *nbr_ids,
uint32_t *ids);
/* For wrtd_load_firmware. */
struct wrtd_firmware {
const char *path;
uint32_t id;
};
enum wrtd_status wrtd_load_firmware(struct wrtd_dev *dev, unsigned verbose,
unsigned int nbr_firmwares,
struct wrtd_firmware *fw);
/* Do the get_config action. */
enum wrtd_status wrtd_msg_get_config(struct wrtd_dev *wrtd, unsigned cpu,
struct wrtd_config_msg *res);
......
......@@ -18,7 +18,7 @@ CFLAGS += $(EXTRACFLAGS)
CFLAGS += $(EXTRACFLAGS)
LDLIBS += ../lib/libwrtd.a $(WRTD_DEP_TRTL)/software/lib/libmockturtle.a
PROGS := wrtd-boot wrtd-config wrtd-logging
PROGS := wrtd-config wrtd-logging
all: $(PROGS)
......
/*
* Copyright (C) 2014-2016 CERN (www.cern.ch)
* Author: Federico Vaga <federico.vaga@cern.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <inttypes.h>
#include <libgen.h>
#include "libwrtd.h"
#include "libwrtd-private.h"
#define WRTD_BOOT_WR_FMC_OFFSET 0x2
static int setoff;
enum wrtb_boot_tdc_offset_type {
OFFSET_ZERO,
OFFSET_USER,
OFFSET_WR,
};
static void help(void)
{
fprintf(stderr, "wrtd-boot [options] -D <device> [-t] ID FW ...\n");
fprintf(stderr, "Load the white-rabbit trigger-distribution application into the mockturtle CPUs\n\n");
fprintf(stderr, "-D Mockturtle device identificator\n");
fprintf(stderr, "-t set timebase offset for TDC\n");
exit(1);
}
#if 0
static const char *strtype[] = {
"zero-offset",
"user-offset",
"wr-offset",
};
static inline const char *stroffset(enum wrtb_boot_tdc_offset_type type) {
return strtype[type];
}
/**
* Get a timeoffset form the TDC driver
*/
static int partial_offset_get(unsigned int dev_id,
unsigned int channel,
int32_t *offset,
enum wrtb_boot_tdc_offset_type type)
{
char path[255];
FILE *f;
int ret;
uint32_t val;
if (type == OFFSET_WR)
sprintf(path, "/sys/bus/zio/devices/tdc-1n5c-%04x/%s",
dev_id - WRTD_BOOT_WR_FMC_OFFSET, stroffset(type));
else
sprintf(path, "/sys/bus/zio/devices/tdc-1n5c-%04x/ft-ch%d/%s",
dev_id - WRTD_BOOT_WR_FMC_OFFSET, channel + 1,
stroffset(type));
f = fopen(path, "r");
if (!f)
return -1;
ret = fscanf(f, "%"SCNu32, &val);
if (ret != 1) {
fclose(f);
if (!errno)
errno = EINVAL;
return -1;
}
fclose(f);
*offset = (int32_t) val;
return 0;
}
/**
* It compute the final time stamp (as it is done on the fmc-tdc driver)
*/
static int offset_get(unsigned int dev_id, unsigned int channel, int32_t *offset)
{
int32_t tmp;
int err;
fprintf(stdout, "Building timestamp offset\n");
/* Get zero offset */
err = partial_offset_get(dev_id, channel, &tmp, OFFSET_ZERO);
if (err)
return -1;
*offset = tmp;
fprintf(stdout, " zero offset : %"PRIi32"\n", tmp);
/* Get White Rabbit offset */
err = partial_offset_get(dev_id, channel, &tmp, OFFSET_WR);
if (err)
return -1;
*offset -= tmp;
fprintf(stdout, " wr offset : %"PRIi32"\n", tmp);
/* Get user offset */
err = partial_offset_get(dev_id, channel, &tmp, OFFSET_USER);
if (err)
return -1;
*offset += tmp;
fprintf(stdout, " user offset : %"PRIi32"\n", tmp);
fprintf(stdout, "final offset : %"PRIi32"\n", *offset);
return 0;
}
static int wrtd_tdc_set_off(struct wrtd_dev *wrtd)
{
int err = -1, i;
int32_t offset;
/* Inform the input real-time channels about the offset */
for (i = 0; i < TDC_NUM_CHANNELS; ++i) {
err = offset_get(dev_id, i, &offset);
if (err) {
fprintf(stderr,
"Channel %d cannot calculate offset\n", i);
continue;
}
err = wrtd_in_timebase_offset_set(wrtd, i, offset);
if (err) {
fprintf(stderr,
"Channel %d cannot set offset\n", i);
continue;
}
}
return 0;
}
#endif
int main(int argc, char *argv[])
{
enum wrtd_status res;
const char *dev_name;
char c;
struct wrtd_dev *wrtd;
unsigned int nbr_fw = 0;
struct wrtd_firmware map[8];
dev_name = NULL;
while ((c = getopt (argc, argv, "hD:t")) != -1) {
switch (c) {
case 'h':
case '?':
help();
break;
case 'D':
dev_name = optarg;
break;
case 't':
setoff = 1;
break;
}
}
if (dev_name == NULL) {
char **list;
int i;
fprintf(stderr, "missing trtl device, use -D DEVICE\n");
list = trtl_list();
printf("List of mock turtle devices:\n");
for (i = 0; list[i]; i++)
printf(" %s\n", list[i]);
exit(1);
}
if ((argc - optind) % 2 != 0) {
fprintf(stderr, "badly built ID FW\n");
exit(1);
}
while (optind < argc) {
char *eptr;
if (nbr_fw >= sizeof(map)/sizeof(map[0])) {
fprintf(stderr, "too many firmwares\n");
exit(1);
}
map[nbr_fw].id = strtoul(argv[optind++], &eptr, 0);
if (*eptr != 0) {
fprintf(stderr, "cannot extract ID from '%s'\n",
argv[optind]);
exit(1);
}
map[nbr_fw].path = argv[optind++];
nbr_fw++;
}
res = wrtd_init(dev_name, false, NULL, &wrtd);
if (res != WRTD_SUCCESS) {
fprintf(stderr, "Cannot open WRTD %s (errno=%s)\n",
dev_name, strerror(errno));
exit(1);
}
if (nbr_fw == 0) {
uint32_t ids[WRTD_MAX_CPUS];
unsigned nids;
fprintf(stderr, "no firmware on the command line\n");
res = wrtd_get_firmware_id(wrtd, &nids, ids);
if (res != WRTD_SUCCESS) {
fprintf(stderr, "cannot get list of firmwares: %s\n",
wrtd_get_error_msg(wrtd));
}
else {
int i;
printf("list of expected firmwares:\n");
for (i = 0; i < nids; i++)
printf(" cpu %d: 0x%04x\n", i, ids[i]);
}
exit(1);
}
res = wrtd_load_firmware(wrtd, 1, nbr_fw, map);
if (res != WRTD_SUCCESS) {
fprintf(stderr, "error loading firmware: %s\n",
wrtd_get_error_msg(wrtd));
exit(1);
}
wrtd_close(wrtd);
exit(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment