Commit e0f6fa9e authored by Alessandro Rubini's avatar Alessandro Rubini

userspace: update sdb code and tools to upstream commit d22c178

This upgrades user-space sdb code the new upstream commit.

This is the result of sdb-read on the switch, for the fpga area:

  wrs-192.168.16.242#sdb-read -l -m 0x100000@0x10000000 -e 0x70000 /dev/mem
  0000000000000651:e6a542c9 @ 00000000-0007ffff WB4-Crossbar-GSI
  0000000000000651:eef0b198 @ 00000000-0001ffff WB4-Bridge-GSI
  0000000000000651:e6a542c9 @ 00000000-0001ffff   WB4-Crossbar-GSI
  000000000000ce42:66cfeb52 @ 00000000-0000ffff   WB4-BlockRAM
  000000000000ce42:e2d13d04 @ 00010000-000100ff   WR-Periph-UART
  000000000000ce42:65158dc0 @ 00010100-000101ff   WR-Soft-PLL
  000000000000ce42:e503947e @ 00010200-0001021f   WB-SPI.Control
  000000000000ce42:441c5143 @ 00010300-000103ff   WB-GPIO-Port
  000000000000ce42:57494266 @ 00010400-000104ff   WB Simple Timer
  000000000000ce42:de0d8ced @ 00010500-000105ff   WR-PPS-Generator
  000000000000ce42:ba07b9d3 @ 00020000-0002ffff WRSW NIC
  0000000000000651:eef0b198 @ 00030000-00037fff WB4-Bridge-GSI
  0000000000000651:e6a542c9 @ 00030000-00037fff   WB4-Crossbar-GSI
  000000000000ce42:650c2d4f @ 00030000-000300ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00030400-000304ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00030800-000308ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00030c00-00030cff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00031000-000310ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00031400-000314ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00031800-000318ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00031c00-00031cff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00032000-000320ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00032400-000324ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00032800-000328ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00032c00-00032cff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00033000-000330ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00033400-000334ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00033800-000338ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00033c00-00033cff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00034000-000340ff   WR-Endpoint
  000000000000ce42:650c2d4f @ 00034400-000344ff   WR-Endpoint
  000000000000ce42:00000013 @ 00050000-000500ff WB-VIC-Int.Control
  000000000000ce42:a027fd6e @ 00051000-000510ff WR Tx Tstamp Unit
  000000000000ce42:2e8524c7 @ 00060000-0006ffff WRSW RTU
  000000000000ce42:441c5143 @ 00053000-000530ff WB-GPIO-Port
  000000000000ce42:123c5443 @ 00054000-000540ff WB-I2C-Master
  000000000000ce42:91446863 @ 00055000-000550ff WB Simple PWM
  000000000000ce42:53bf6e6f @ 00056000-000560ff WRSW TRU
  000000000000ce42:0c0a9cc1 @ 00057000-000570ff WRSW TATSU
  000000000000ce42:6c21e54e @ 00058000-000580ff WRSW PSTATS
  000000000000ce42:11f10474 @ 00059000-000590ff WRSW HWIU
  repo-url: git@ohwr.org:white-rabbit/wr-switch-hdl.git
  synthesis-name: WRS18p
    commit-id: 000000000000000000000000a98ffb3f
     tool-name: ISE
    tool-version: 0x00000145
    build-date: 20141002
    build-user: GDaniluk
  synthesis-name: general-cores
    commit-id: 000000000000000000000000aa9ff5ea
  synthesis-name: wr-cores
    commit-id: 0000000000000000000000000791d3ed
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 945de6ef
......@@ -14,12 +14,12 @@
static struct sdbfs *sdbfs_list;
/* All fields unused by the caller are expected to be zeroed */
int sdbfs_dev_create(struct sdbfs *fs, int verbose)
int sdbfs_dev_create(struct sdbfs *fs)
{
unsigned int magic;
/* First, check we have the magic */
if (fs->data)
if (fs->data || (fs->flags & SDBFS_F_ZEROBASED))
magic = *(unsigned int *)(fs->data + fs->entrypoint);
else
fs->read(fs, fs->entrypoint, &magic, sizeof(magic));
......@@ -33,8 +33,6 @@ int sdbfs_dev_create(struct sdbfs *fs, int verbose)
return -ENOTDIR;
}
if (verbose)
fs->flags |= SDBFS_F_VERBOSE;
fs->next = sdbfs_list;
sdbfs_list = fs;
......@@ -77,7 +75,7 @@ static struct sdb_device *sdbfs_readentry(struct sdbfs *fs,
* returns the pointer to the entry, which may be stored in
* the fs structure itself. Only touches fs->current_record.
*/
if (fs->data) {
if (fs->data || (fs->flags & SDBFS_F_ZEROBASED)) {
if (!(fs->flags & SDBFS_F_CONVERT32))
return (struct sdb_device *)(fs->data + offset);
/* copy to local storage for conversion */
......@@ -159,7 +157,7 @@ scan:
if (newdir) {
dev = scan_newdir(fs, depth);
if (dev)
return dev;
goto out;
/* Otherwise the directory is not there: no intercon */
if (!depth)
return NULL; /* no entries at all */
......@@ -177,6 +175,9 @@ scan:
dev = fs->currentp = sdbfs_readentry(fs, fs->this[depth]);
fs->this[depth] += sizeof(*dev);
fs->nleft[depth]--;
out:
fs->f_offset = fs->base[fs->depth]
+ htonll(fs->currentp->sdb_component.addr_first);
return dev;
}
......@@ -232,3 +233,31 @@ int sdbfs_close(struct sdbfs *fs)
return 0;
}
/* to "find" a device, open it, get the current offset, then close */
unsigned long sdbfs_find_name(struct sdbfs *fs, const char *name)
{
unsigned long offset;
int ret;
ret = sdbfs_open_name(fs, name);
if (ret < 0)
return (unsigned long)ret;
offset = fs->f_offset;
sdbfs_close(fs);
return offset;
}
unsigned long sdbfs_find_id(struct sdbfs *fs, uint64_t vid, uint32_t did)
{
unsigned long offset;
int ret;
ret = sdbfs_open_id(fs, vid, did);
if (ret < 0)
return (unsigned long)ret;
offset = fs->f_offset;
sdbfs_close(fs);
return offset;
}
......@@ -24,7 +24,7 @@
* we are picking the correct header, because the library is only built
* within the barebox source tree.
*/
#if !defided(DECLARE_BITMAP) && !defined(__BAREBOX__)
#if !defined(DECLARE_BITMAP) && !defined(__BAREBOX__)
# error "Please point LINUX to a source tree if you define __KERNEL__"
#endif
......
......@@ -27,6 +27,7 @@ struct sdbfs {
void *drvdata; /* driver may need some detail.. */
unsigned long blocksize;
unsigned long entrypoint;
unsigned long flags;
/* The "driver" must offer some methods */
void *data; /* Use this if directly mapped */
......@@ -35,13 +36,12 @@ struct sdbfs {
int (*write)(struct sdbfs *fs, int offset, void *buf, int count);
int (*erase)(struct sdbfs *fs, int offset, int count);
/* All fields from here onwards are library-private */
/* The following fields are library-private */
struct sdb_device *currentp;
struct sdb_device current_record;
unsigned long f_len;
unsigned long f_offset; /* start of file */
unsigned long read_offset; /* current location */
unsigned long flags;
struct sdbfs *next;
/* The following ones are directory-aware */
unsigned long base[SDBFS_DEPTH]; /* for relative addresses */
......@@ -50,14 +50,17 @@ struct sdbfs {
int depth;
};
#define SDBFS_F_VERBOSE 0x0001
/* Some flags are set by the user, some (convert32) by the library */
#define SDBFS_F_VERBOSE 0x0001 /* not really used yet */
#define SDBFS_F_CONVERT32 0x0002 /* swap SDB words as they are read */
#define SDBFS_F_ZEROBASED 0x0004 /* zero is a valid data pointer */
/* Defined in glue.c */
int sdbfs_dev_create(struct sdbfs *fs, int verbose);
int sdbfs_dev_create(struct sdbfs *fs);
int sdbfs_dev_destroy(struct sdbfs *fs);
struct sdbfs *sdbfs_dev_find(const char *name);
unsigned long sdbfs_find_name(struct sdbfs *fs, const char *name);
unsigned long sdbfs_find_id(struct sdbfs *fs, uint64_t vid, uint32_t did);
int sdbfs_open_name(struct sdbfs *fs, const char *name);
int sdbfs_open_id(struct sdbfs *fs, uint64_t vid, uint32_t did);
int sdbfs_close(struct sdbfs *fs);
......
......@@ -68,49 +68,142 @@ static int do_read(struct sdbfs *fs, int offset, void *buf, int count)
}
/* Boring ascii representation of a device */
static void list_device(struct sdb_device *d, int depth, int base)
static int list_device(struct sdb_device *d, int depth, int base)
{
struct sdb_product *p;
struct sdb_component *c;
struct sdb_synthesis *s;
unsigned char *data;
static int warned;
int i;
char *warn;
int i, ret;
c = &d->sdb_component;
p = &c->product;
s = (void *)d;
if (!opt_long) {
printf("%.19s\n", p->name);
return;
}
if (!warned) {
if (!warned && opt_long) {
fprintf(stderr, "%s: listing format is to be defined\n",
prgname);
warned = 1;
}
/* hack: show directory level looking at the internals */
printf("%016llx:%08x @ %08llx-%08llx ",
ntohll(p->vendor_id), ntohl(p->device_id),
base + ntohll(c->addr_first), base + ntohll(c->addr_last));
for (i = 0; i < depth; i++)
printf(" ");
printf("%.19s\n", p->name);
/* Different sdb items are listed in different ways */
switch(p->record_type) {
/* The following items are components, and are listed as such */
case sdb_type_interconnect:
case sdb_type_device:
case sdb_type_bridge:
if (!opt_long) {
printf("%.19s\n", p->name);
return 0;
}
/* hack: show directory level looking at the internals */
printf("%016llx:%08x @ %08llx-%08llx ",
(long long)ntohll(p->vendor_id), ntohl(p->device_id),
(long long)base + ntohll(c->addr_first),
(long long)base + ntohll(c->addr_last));
for (i = 0; i < depth; i++)
printf(" ");
printf("%.19s\n", p->name);
return 0;
/* A product, but not a component (no address range) */
case sdb_type_integration:
if (!opt_long) {
printf("%.19s\n", p->name);
return 0;
}
printf("%016llx:%08x ",
(long long)ntohll(p->vendor_id), ntohl(p->device_id));
/* like above, show directory level */
for (i = 0; i < depth; i++)
printf(" ");
printf("%.19s\n", p->name);
return 0;
/* Just a string */
case sdb_type_repo_url:
if (opt_long)
printf("repo-url: %.63s\n",
((struct sdb_repo_url *)d)->repo_url);
return 0;
/* Some metadata */
case sdb_type_synthesis:
if (!opt_long)
return 0;
printf("synthesis-name: %.16s\n", s->syn_name);
printf(" commit-id: ");
for (i = 0; i < sizeof(s->commit_id); i++)
printf("%02x", s->commit_id[i]);
printf("\n");
/* Some of the following fields are sometimes empty */
if (s->tool_name[0] && s->tool_name[0] != ' ')
printf(" tool-name: %.8s\n", s->tool_name);
if (s->tool_version)
printf(" tool-version: 0x%08x\n",
ntohl(s->tool_version));
if (s->date)
printf(" build-date: %08x\n", ntohl(s->date));
if (s->user_name[0] && s->tool_name[0] != ' ')
printf(" build-user: %.15s\n", s->user_name);
return 0;
case sdb_type_empty:
return 0;
default:
break;
}
/* Unknown record type */
if (p->record_type & 0x80) {
warn = "Warning";
ret = 0;
} else {
warn = "Error";
ret = -1;
}
fprintf(stderr, "%s: unknown record type 0x%02x\n", warn,
p->record_type);
if (!opt_long) {
printf("Unknown-record\n");
return ret;
}
/* long listing of unknown record */
printf("Unknown-record:\n");
data = (void *)d;
for (i = 0; i < sizeof(struct sdb_empty); i++)
printf("%s%02x%c",
(i & 0xf) == 0 ? " " : "",
data[i],
(i & 0xf) == 0xf ? '\n' : ' ');
return ret;
}
/* The following three function perform the real work, main() is just glue */
static void do_list(struct sdbfs *fs)
static int do_list(struct sdbfs *fs)
{
struct sdb_device *d;
int new = 1;
int err = 0;
while ( (d = sdbfs_scan(fs, new)) != NULL) {
list_device(d, fs->depth, fs->base[fs->depth]);
err += list_device(d, fs->depth, fs->base[fs->depth]);
new = 0;
}
return err;
}
static void do_cat_name(struct sdbfs *fs, char *name)
static int do_cat_name(struct sdbfs *fs, char *name)
{
char buf[4096];
int i;
......@@ -123,22 +216,24 @@ static void do_cat_name(struct sdbfs *fs, char *name)
while ( (i = sdbfs_fread(fs, -1, buf, sizeof(buf))) > 0)
fwrite(buf, 1, i, stdout);
sdbfs_close(fs);
return 0;
}
static void do_cat_id(struct sdbfs *fs, uint64_t vendor, uint32_t dev)
static int do_cat_id(struct sdbfs *fs, uint64_t vendor, uint32_t dev)
{
char buf[4096];
int i;
i = sdbfs_open_id(fs, htonll(vendor), htonl(dev));
if (i < 0) {
fprintf(stderr, "%s: %016llx-%08x: %s\n", prgname, vendor,
dev, strerror(-i));
fprintf(stderr, "%s: %016llx-%08x: %s\n", prgname,
(long long)vendor, dev, strerror(-i));
exit(1);
}
while ( (i = sdbfs_fread(fs, -1, buf, sizeof(buf))) > 0)
fwrite(buf, 1, i, stdout);
sdbfs_close(fs);
return 0;
}
/* As promised, here's the user-interface glue (and initialization, I admit) */
......@@ -231,8 +326,9 @@ int main(int argc, char **argv)
fs->read = do_read;
else
fs->data = mapaddr;
err = sdbfs_dev_create(fs, opt_verbose);
if (opt_verbose)
fs->flags |= SDBFS_F_VERBOSE;
err = sdbfs_dev_create(fs);
if (err) {
fprintf(stderr, "%s: sdbfs_dev_create(): %s\n", prgname,
strerror(-err));
......@@ -242,12 +338,12 @@ int main(int argc, char **argv)
}
/* Now use the thing: either scan, or look for name, or look for id */
if (!filearg)
do_list(fs);
err = do_list(fs);
else if (sscanf(filearg, "%llx:%lx", &int64, &int32) != 2)
do_cat_name(fs, filearg);
err = do_cat_name(fs, filearg);
else
do_cat_id(fs, int64, int32);
err = do_cat_id(fs, int64, int32);
sdbfs_dev_destroy(fs);
return 0;
return err;
}
......@@ -100,7 +100,7 @@ static char *sdb_get(char *fname, char *tagname)
return unknown;
}
drvdata.f = f;
i = sdbfs_dev_create(&sdb_instance, 0 /* verbose */);
i = sdbfs_dev_create(&sdb_instance);
if (i != 0) {
printf("Error accessing SDB filesystem in \"%s\"\n",
SDBFS_NAME);
......
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