#include <sys/param.h>
#include <sys/disklabel.h>
#include <netinet/in.h>
#include <lib/libkern/libkern.h>
#include <lib/libsa/stand.h>
#include <lib/libsa/nfs.h>
#include <lib/libsa/tftp.h>
#include <lib/libsa/ext2fs.h>
#include <lib/libsa/dosfs.h>
#include <lib/libsa/ufs.h>
#include "dev_sdmmc.h"
#include <arch/evbarm/mini2440/mini2440_bootinfo.h>
int net_open(struct open_file *, ...);
int net_close(struct open_file *);
int net_strategy(void *, int, daddr_t, size_t, void *, size_t *);
int sdmmc_open(struct open_file *, ...);
int sdmmc_close(struct open_file *);
int sdmmc_strategy(void *, int, daddr_t, size_t, void *, size_t *);
int sdmmc_get_fstype(void*);
struct devsw devsw[] = {
{ "dm9000", net_strategy, net_open, net_close, noioctl },
{ "s3c sdio", sdmmc_strategy, sdmmc_open, sdmmc_close, noioctl }
};
struct fs_ops ops_nfs = FS_OPS(nfs);
struct fs_ops ops_tftp = FS_OPS(tftp);
struct fs_ops ops_ext2fs = FS_OPS(ext2fs);
struct fs_ops ops_dosfs = FS_OPS(dosfs);
struct fs_ops ops_bsdfs = FS_OPS(ufs);
struct fs_ops file_system[1];
int nfsys = 1;
extern struct btinfo_bootpath bi_path;
extern struct btinfo_rootdevice bi_rdev;
static void parseunit(const char *name, int *unitp, int *partp, char **pathp);
int
devopen(struct open_file *of, const char *name, char **file)
{
int error;
extern char bootfile[];
if (strncmp("net:", name, 4) == 0 ||
strncmp("nfs:", name, 4) == 0 ) {
of->f_dev = &devsw[0];
if ((error = net_open(of, name+4, "nfs")) != 0)
return error;
file_system[0] = ops_nfs;
*file = bootfile;
strncpy(bi_path.bootpath, bootfile, sizeof(bi_path.bootpath));
return 0;
} else if (strncmp("tftp:", name, 5) == 0) {
of->f_dev = &devsw[0];
if ((error = net_open(of, name+5, "tftp")) != 0) {
return error;
}
file_system[0] = ops_tftp;
*file = bootfile;
strncpy(bi_path.bootpath, bootfile, sizeof(bi_path.bootpath));
return 0;
} else if (name[0] == 'l' && name[1] == 'd') {
int unit, part;
parseunit(&name[2], &unit, &part, file);
if (*file == NULL || strlen(*file) == 0) {
strcpy(*file, "netbsd");
}
of->f_dev = &devsw[1];
if ((error = sdmmc_open(of, unit, part)) != 0)
return error;
strncpy(bi_path.bootpath, *file, sizeof(bi_path.bootpath));
snprintf(bi_rdev.devname, sizeof(bi_rdev.devname), "ld");
bi_rdev.cookie = unit;
bi_rdev.partition = part;
switch(sdmmc_get_fstype(of->f_devdata)) {
case FS_EX2FS:
file_system[0] = ops_ext2fs;
break;
case FS_MSDOS:
file_system[0] = ops_dosfs;
break;
case FS_BSDFFS:
file_system[0] = ops_bsdfs;
break;
default:
return ENOENT;
}
return 0;
}
return ENOENT;
}
static void
parseunit(const char *name, int *unitp, int *partp, char **pathp)
{
const char *p = name;
int unit, part;
unit = part = -1;
while (*p != ':' && *p != '\0') {
if (unit == -1 && *p >= '0' && *p <= '9')
unit = *p - '0';
if (part == -1 && *p >= 'a' && *p < 'a' + 16)
part = *p - 'a';
p += 1;
}
*unitp = (unit == -1) ? 0 : unit;
*partp = (part == -1) ? 0 : part;
*pathp = (*p == ':') ? (char *)p + 1 : NULL;
}