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, ...@@ -43,6 +43,8 @@ enum wrtd_status wrtd_init(const char *resource_name,
const char *options_str, const char *options_str,
struct wrtd_dev **dev) struct wrtd_dev **dev)
{ {
struct trtl_dev *trtl;
/* In case of error... */ /* In case of error... */
*dev = NULL; *dev = NULL;
...@@ -51,18 +53,24 @@ enum wrtd_status wrtd_init(const char *resource_name, ...@@ -51,18 +53,24 @@ enum wrtd_status wrtd_init(const char *resource_name,
init (); init ();
/* Resource is MTxxx where xxx is the mock-turtle device id. */ /* Resource is MTxxx where xxx is the mock-turtle device id. */
if (resource_name[0] != 'M' if (resource_name[0] == 'M' && resource_name[1] == 'T') {
|| resource_name[1] != 'T') unsigned long dev_id;
return WRTD_ERROR_RESOURCE_UNKNOWN; char *eptr;
dev_id = strtoul(resource_name + 2, &eptr, 0);
if (*eptr != 0) {
unsigned long dev_id; /* Invalid characters. */
char *eptr; return WRTD_ERROR_RESOURCE_UNKNOWN;
dev_id = strtoul(resource_name + 2, &eptr, 0); }
if (*eptr != 0) { trtl = trtl_open_by_id(dev_id);
/* Invalid characters. */ }
else if (strncmp(resource_name, "trtl-", 5) == 0) {
trtl = trtl_open(resource_name);
}
else {
return WRTD_ERROR_RESOURCE_UNKNOWN; return WRTD_ERROR_RESOURCE_UNKNOWN;
} }
if (trtl == NULL)
return WRTD_ERROR_RESOURCE_UNKNOWN;
struct wrtd_dev *res; struct wrtd_dev *res;
...@@ -71,11 +79,7 @@ enum wrtd_status wrtd_init(const char *resource_name, ...@@ -71,11 +79,7 @@ enum wrtd_status wrtd_init(const char *resource_name,
return WRTD_ERROR_OUT_OF_MEMORY; return WRTD_ERROR_OUT_OF_MEMORY;
memset(res, 0, sizeof(*res)); memset(res, 0, sizeof(*res));
res->trtl = trtl_open_by_id(dev_id); res->trtl = trtl;
if (!res->trtl) {
free(res);
return WRTD_ERROR_RESOURCE_UNKNOWN;
}
*dev = res; *dev = res;
return WRTD_SUCCESS; return WRTD_SUCCESS;
...@@ -98,6 +102,26 @@ enum wrtd_status wrtd_reset(struct wrtd_dev *dev) ...@@ -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, enum wrtd_status wrtd_load_firmware(struct wrtd_dev *dev, unsigned verbose,
unsigned int nbr_firmwares, unsigned int nbr_firmwares,
struct wrtd_firmware *fw) struct wrtd_firmware *fw)
......
...@@ -7,7 +7,9 @@ ...@@ -7,7 +7,9 @@
#include "libwrtd.h" #include "libwrtd.h"
#include "libwrtd-private.h" #include "libwrtd-private.h"
#include "hw/fmctdc-direct.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, static enum wrtd_status wrtd_none_configure(struct wrtd_dev *wrtd,
unsigned cpu, unsigned dev, unsigned cpu, unsigned dev,
......
...@@ -78,6 +78,12 @@ extern enum wrtd_status wrtd_return_error(struct wrtd_dev *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. */ /* Get current error message. Simpler than the official API. */
extern const char *wrtd_get_error_msg(struct wrtd_dev *dev); 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. */ /* For wrtd_load_firmware. */
struct wrtd_firmware { struct wrtd_firmware {
const char *path; const char *path;
......
...@@ -184,14 +184,17 @@ int main(int argc, char *argv[]) ...@@ -184,14 +184,17 @@ int main(int argc, char *argv[])
} }
if (dev_name == NULL) { 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); exit(1);
} }
if (optind == argc) {
fprintf(stderr, "no firmware\n");
exit(1);
}
if ((argc - optind) % 2 != 0) { if ((argc - optind) % 2 != 0) {
fprintf(stderr, "badly built ID FW\n"); fprintf(stderr, "badly built ID FW\n");
exit(1); exit(1);
...@@ -218,10 +221,29 @@ int main(int argc, char *argv[]) ...@@ -218,10 +221,29 @@ int main(int argc, char *argv[])
res = wrtd_init(dev_name, false, NULL, &wrtd); res = wrtd_init(dev_name, false, NULL, &wrtd);
if (res != WRTD_SUCCESS) { 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); 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); res = wrtd_load_firmware(wrtd, 1, nbr_fw, map);
if (res != WRTD_SUCCESS) { if (res != WRTD_SUCCESS) {
fprintf(stderr, "error loading firmware: %s\n", 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