Commit 14ed66ea authored by Tristan Gingold's avatar Tristan Gingold

wrtd-boot: display list of MT, display needed firmwares.

parent f99f8986
......@@ -43,6 +43,8 @@ enum wrtd_status wrtd_init(const char *resource_name,
const char *options_str,
struct wrtd_dev **dev)
{
struct trtl_dev *trtl;
/* In case of error... */
*dev = NULL;
......@@ -51,18 +53,24 @@ enum wrtd_status wrtd_init(const char *resource_name,
init ();
/* Resource is MTxxx where xxx is the mock-turtle device id. */
if (resource_name[0] != 'M'
|| resource_name[1] != 'T')
return WRTD_ERROR_RESOURCE_UNKNOWN;
unsigned long dev_id;
char *eptr;
dev_id = strtoul(resource_name + 2, &eptr, 0);
if (*eptr != 0) {
/* Invalid characters. */
if (resource_name[0] == 'M' && resource_name[1] == 'T') {
unsigned long dev_id;
char *eptr;
dev_id = strtoul(resource_name + 2, &eptr, 0);
if (*eptr != 0) {
/* Invalid characters. */
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
trtl = trtl_open_by_id(dev_id);
}
else if (strncmp(resource_name, "trtl-", 5) == 0) {
trtl = trtl_open(resource_name);
}
else {
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
if (trtl == NULL)
return WRTD_ERROR_RESOURCE_UNKNOWN;
struct wrtd_dev *res;
......@@ -71,11 +79,7 @@ enum wrtd_status wrtd_init(const char *resource_name,
return WRTD_ERROR_OUT_OF_MEMORY;
memset(res, 0, sizeof(*res));
res->trtl = trtl_open_by_id(dev_id);
if (!res->trtl) {
free(res);
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
res->trtl = trtl;
*dev = res;
return WRTD_SUCCESS;
......@@ -98,6 +102,26 @@ 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)
{
const struct wrtd_mt_config *cfg;
enum wrtd_status status;
int i;
/* Find config. */
status = wrtd_find_config(dev, &cfg);
WRTD_RETURN_IF_ERROR(status);
/* Find firmwares. */
*nbr_ids = cfg->nbr_cpus;
for (i = 0; i < cfg->nbr_cpus; i++) {
ids[i] = cfg->cpus[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)
......
......@@ -7,7 +7,9 @@
#include "libwrtd.h"
#include "libwrtd-private.h"
#include "hw/fmctdc-direct.h"
#include "wrtd-rt-tdc.h"
/* FIXME: duplicated macro. */
#define BASE_DP_TDC_DIRECT 0x8000
static enum wrtd_status wrtd_none_configure(struct wrtd_dev *wrtd,
unsigned cpu, unsigned dev,
......
......@@ -78,6 +78,12 @@ 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;
......
......@@ -184,14 +184,17 @@ int main(int argc, char *argv[])
}
if (dev_name == NULL) {
fprintf(stderr, "missing trtl device\n");
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 (optind == argc) {
fprintf(stderr, "no firmware\n");
exit(1);
}
if ((argc - optind) % 2 != 0) {
fprintf(stderr, "badly built ID FW\n");
exit(1);
......@@ -218,10 +221,29 @@ int main(int argc, char *argv[])
res = wrtd_init(dev_name, false, NULL, &wrtd);
if (res != WRTD_SUCCESS) {
fprintf(stderr, "Cannot open WRTD\n");
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",
......
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