Commit 22cc346c authored by Alessandro Rubini's avatar Alessandro Rubini

sdbfs/lib: add flag ZEROBASED and remove verbose argument to register()

Adding ZEROBASED allows the lm32 to enumerate fpga cores without
prviding a specific read() method.

Removing "verbose" as an argument to sdbfs_dev_create (and allowing
the user to set it in fs->flags) is a minor cleanup, though incompatible.
Userspace is fixed to deal with this incompatibility.

This is a slight incompatibility, but it's worh doing.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>

s
parent 95bef107
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
static struct sdbfs *sdbfs_list; static struct sdbfs *sdbfs_list;
/* All fields unused by the caller are expected to be zeroed */ /* 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; unsigned int magic;
/* First, check we have the 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); magic = *(unsigned int *)(fs->data + fs->entrypoint);
else else
fs->read(fs, fs->entrypoint, &magic, sizeof(magic)); fs->read(fs, fs->entrypoint, &magic, sizeof(magic));
...@@ -33,8 +33,6 @@ int sdbfs_dev_create(struct sdbfs *fs, int verbose) ...@@ -33,8 +33,6 @@ int sdbfs_dev_create(struct sdbfs *fs, int verbose)
return -ENOTDIR; return -ENOTDIR;
} }
if (verbose)
fs->flags |= SDBFS_F_VERBOSE;
fs->next = sdbfs_list; fs->next = sdbfs_list;
sdbfs_list = fs; sdbfs_list = fs;
...@@ -77,7 +75,7 @@ static struct sdb_device *sdbfs_readentry(struct sdbfs *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 * returns the pointer to the entry, which may be stored in
* the fs structure itself. Only touches fs->current_record. * 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)) if (!(fs->flags & SDBFS_F_CONVERT32))
return (struct sdb_device *)(fs->data + offset); return (struct sdb_device *)(fs->data + offset);
/* copy to local storage for conversion */ /* copy to local storage for conversion */
......
...@@ -27,6 +27,7 @@ struct sdbfs { ...@@ -27,6 +27,7 @@ struct sdbfs {
void *drvdata; /* driver may need some detail.. */ void *drvdata; /* driver may need some detail.. */
unsigned long blocksize; unsigned long blocksize;
unsigned long entrypoint; unsigned long entrypoint;
unsigned long flags;
/* The "driver" must offer some methods */ /* The "driver" must offer some methods */
void *data; /* Use this if directly mapped */ void *data; /* Use this if directly mapped */
...@@ -35,13 +36,12 @@ struct sdbfs { ...@@ -35,13 +36,12 @@ struct sdbfs {
int (*write)(struct sdbfs *fs, int offset, void *buf, int count); int (*write)(struct sdbfs *fs, int offset, void *buf, int count);
int (*erase)(struct sdbfs *fs, int offset, 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 *currentp;
struct sdb_device current_record; struct sdb_device current_record;
unsigned long f_len; unsigned long f_len;
unsigned long f_offset; /* start of file */ unsigned long f_offset; /* start of file */
unsigned long read_offset; /* current location */ unsigned long read_offset; /* current location */
unsigned long flags;
struct sdbfs *next; struct sdbfs *next;
/* The following ones are directory-aware */ /* The following ones are directory-aware */
unsigned long base[SDBFS_DEPTH]; /* for relative addresses */ unsigned long base[SDBFS_DEPTH]; /* for relative addresses */
...@@ -50,12 +50,13 @@ struct sdbfs { ...@@ -50,12 +50,13 @@ struct sdbfs {
int depth; 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_CONVERT32 0x0002 /* swap SDB words as they are read */
#define SDBFS_F_ZEROBASED 0x0004 /* zero is a valid data pointer */
/* Defined in glue.c */ /* 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); int sdbfs_dev_destroy(struct sdbfs *fs);
struct sdbfs *sdbfs_dev_find(const char *name); struct sdbfs *sdbfs_dev_find(const char *name);
unsigned long sdbfs_find_name(struct sdbfs *fs, const char *name); unsigned long sdbfs_find_name(struct sdbfs *fs, const char *name);
......
...@@ -152,7 +152,7 @@ int main(int argc, char **argv) ...@@ -152,7 +152,7 @@ int main(int argc, char **argv)
fs->entrypoint = opt_entry; fs->entrypoint = opt_entry;
fs->data = mapaddr; fs->data = mapaddr;
err = sdbfs_dev_create(fs, 0); err = sdbfs_dev_create(fs);
if (err) { if (err) {
fprintf(stderr, "%s: sdbfs_dev_create(): %s\n", prgname, fprintf(stderr, "%s: sdbfs_dev_create(): %s\n", prgname,
strerror(-err)); strerror(-err));
......
...@@ -232,8 +232,9 @@ int main(int argc, char **argv) ...@@ -232,8 +232,9 @@ int main(int argc, char **argv)
fs->read = do_read; fs->read = do_read;
else else
fs->data = mapaddr; fs->data = mapaddr;
if (opt_verbose)
err = sdbfs_dev_create(fs, opt_verbose); fs->flags |= SDBFS_F_VERBOSE;
err = sdbfs_dev_create(fs);
if (err) { if (err) {
fprintf(stderr, "%s: sdbfs_dev_create(): %s\n", prgname, fprintf(stderr, "%s: sdbfs_dev_create(): %s\n", prgname,
strerror(-err)); strerror(-err));
......
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