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 @@
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 */
......
......@@ -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,12 +50,13 @@ 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);
......
......@@ -152,7 +152,7 @@ int main(int argc, char **argv)
fs->entrypoint = opt_entry;
fs->data = mapaddr;
err = sdbfs_dev_create(fs, 0);
err = sdbfs_dev_create(fs);
if (err) {
fprintf(stderr, "%s: sdbfs_dev_create(): %s\n", prgname,
strerror(-err));
......
......@@ -232,8 +232,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));
......
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