From: Vicente <vicencb@gmail.com>
To: barebox@lists.infradead.org
Cc: Vicente <vicencb@gmail.com>
Subject: [PATCH 12/14] omap4: add filesystem support over usb boot
Date: Tue, 9 Oct 2012 00:55:22 +0200 [thread overview]
Message-ID: <1349736924-24667-13-git-send-email-vicencb@gmail.com> (raw)
In-Reply-To: <1349736924-24667-1-git-send-email-vicencb@gmail.com>
Signed-off-by: Vicente <vicencb@gmail.com>
---
fs/Kconfig | 5 ++
fs/Makefile | 1 +
fs/omap4_usbbootfs.c | 219 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 225 insertions(+)
create mode 100644 fs/omap4_usbbootfs.c
diff --git a/fs/Kconfig b/fs/Kconfig
index 4c66543..0ab69d7 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -29,6 +29,11 @@ config FS_TFTP
prompt "tftp support"
depends on NET
+config FS_OMAP4_USBBOOT
+ bool
+ prompt "Filesystem over usb boot"
+ depends on OMAP4_USBBOOT
+
config FS_NFS
depends on NET
bool
diff --git a/fs/Makefile b/fs/Makefile
index 1b52bee..ad745d9 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -5,4 +5,5 @@ obj-$(CONFIG_FS_DEVFS) += devfs.o
obj-$(CONFIG_FS_FAT) += fat/
obj-y += fs.o
obj-$(CONFIG_FS_TFTP) += tftp.o
+obj-$(CONFIG_FS_OMAP4_USBBOOT) += omap4_usbbootfs.o
obj-$(CONFIG_FS_NFS) += nfs.o
diff --git a/fs/omap4_usbbootfs.c b/fs/omap4_usbbootfs.c
new file mode 100644
index 0000000..0dc7682
--- /dev/null
+++ b/fs/omap4_usbbootfs.c
@@ -0,0 +1,219 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <common.h>
+#include <malloc.h>
+#include <fs.h>
+#include <fcntl.h>
+#include <init.h>
+#include <linux/stat.h>
+#include <linux/err.h>
+#include <mach/omap4_rom_usb.h>
+
+#define OMAP4_USBBOOT_FS_MAGIC 0x5562464D
+#define OMAP4_USBBOOT_FS_CMD_OPEN 0x46530000
+#define OMAP4_USBBOOT_FS_CMD_CLOSE 0x46530001
+#define OMAP4_USBBOOT_FS_CMD_READ 0x46530002
+#define OMAP4_USBBOOT_FS_CMD_END 0x4653FFFF
+
+struct file_priv {
+ s32 id;
+ u32 size;
+};
+/*
+static int omap4_usbbootfs_create(
+ struct device_d *dev, const char *pathname, mode_t mode)
+{
+ return -ENOSYS;
+}
+
+static int omap4_usbbootfs_unlink(struct device_d *dev, const char *pathname)
+{
+ return -ENOSYS;
+}
+
+static int omap4_usbbootfs_mkdir(struct device_d *dev, const char *pathname)
+{
+ return -ENOSYS;
+}
+
+static int omap4_usbbootfs_rmdir(struct device_d *dev, const char *pathname)
+{
+ return -ENOSYS;
+}
+
+static int omap4_usbbootfs_write(
+ struct device_d *_dev, FILE *f, const void *inbuf, size_t size)
+{
+ return -ENOSYS;
+}
+
+static int omap4_usbbootfs_truncate(struct device_d *dev, FILE *f, ulong size)
+{
+ return -ENOSYS;
+}
+*/
+
+static struct file_priv *omap4_usbbootfs_do_open(
+ struct device_d *dev, int accmode, const char *filename)
+{
+ struct file_priv *priv;
+ u32 data;
+
+ if (accmode & O_ACCMODE)
+ return ERR_PTR(-ENOSYS);
+
+ priv = xzalloc(sizeof(*priv));
+ if (!priv)
+ return ERR_PTR(-ENOMEM);
+
+ data = OMAP4_USBBOOT_FS_MAGIC ; omap4_usbboot_write(&data, 4);
+ data = OMAP4_USBBOOT_FS_CMD_OPEN; omap4_usbboot_write(&data, 4);
+ omap4_usbboot_puts(filename);
+ data = OMAP4_USBBOOT_FS_CMD_END ; omap4_usbboot_write(&data, 4);
+
+ if (omap4_usbboot_read(&priv->id, 4) ||
+ omap4_usbboot_read(&priv->size, 4)
+ ) {
+ free(priv);
+ return ERR_PTR(-EIO);
+ }
+ if (priv->id < 0) {
+ free(priv);
+ return ERR_PTR(-ENOENT);
+ }
+
+ return priv;
+}
+
+static int omap4_usbbootfs_open(
+ struct device_d *dev, FILE *file, const char *filename)
+{
+ struct file_priv *priv;
+
+ priv = omap4_usbbootfs_do_open(dev, file->flags, filename);
+ if (IS_ERR(priv))
+ return PTR_ERR(priv);
+
+ file->inode = priv;
+ file->size = priv->size;
+
+ return 0;
+}
+
+static int omap4_usbbootfs_do_close(struct file_priv *priv)
+{
+ u32 data;
+ data = OMAP4_USBBOOT_FS_MAGIC ; omap4_usbboot_write(&data, 4);
+ data = OMAP4_USBBOOT_FS_CMD_CLOSE; omap4_usbboot_write(&data, 4);
+ omap4_usbboot_write(&priv->id, 4);
+ data = OMAP4_USBBOOT_FS_CMD_END ; omap4_usbboot_write(&data, 4);
+ free(priv);
+ return 0;
+}
+
+static int omap4_usbbootfs_close(struct device_d *dev, FILE *f)
+{
+ struct file_priv *priv = f->inode;
+ return omap4_usbbootfs_do_close(priv);
+}
+
+static int omap4_usbbootfs_read(
+ struct device_d *dev, FILE *f, void *buf, size_t size)
+{
+ struct file_priv *priv = f->inode;
+ u32 data;
+
+ if (size > priv->size - f->pos)
+ size = priv->size - f->pos;
+ if (!size)
+ return 0;
+
+ data = OMAP4_USBBOOT_FS_MAGIC ; omap4_usbboot_write(&data, 4);
+ data = OMAP4_USBBOOT_FS_CMD_READ; omap4_usbboot_write(&data, 4);
+ omap4_usbboot_write(&priv->id, 4);
+ omap4_usbboot_write(&f->pos, 4);
+ omap4_usbboot_write(&size, 4);
+ data = OMAP4_USBBOOT_FS_CMD_END ; omap4_usbboot_write(&data, 4);
+
+ if (omap4_usbboot_read(buf, size))
+ return -EIO;
+
+ return size;
+}
+
+static loff_t omap4_usbbootfs_lseek(struct device_d *dev, FILE *f, loff_t pos)
+{
+ f->pos = pos;
+ return pos;
+}
+
+static DIR *omap4_usbbootfs_opendir(struct device_d *dev, const char *pathname)
+{
+ return NULL;
+}
+
+static int omap4_usbbootfs_stat(
+ struct device_d *dev, const char *filename, struct stat *s)
+{
+ struct file_priv *priv;
+
+ priv = omap4_usbbootfs_do_open(dev, O_RDONLY, filename);
+ if (IS_ERR(priv))
+ return PTR_ERR(priv);
+
+ s->st_mode = S_IFREG |
+ S_IRUSR | S_IRGRP | S_IROTH |
+ S_IXUSR | S_IXGRP | S_IXOTH ;
+ s->st_size = priv->size;
+
+ omap4_usbbootfs_do_close(priv);
+
+ return 0;
+}
+
+static int omap4_usbbootfs_probe(struct device_d *dev)
+{
+ return 0;
+}
+static void omap4_usbbootfs_remove(struct device_d *dev)
+{
+}
+
+static struct fs_driver_d omap4_usbbootfs_driver = {
+ .open = omap4_usbbootfs_open,
+ .close = omap4_usbbootfs_close,
+ .read = omap4_usbbootfs_read,
+ .lseek = omap4_usbbootfs_lseek,
+ .opendir = omap4_usbbootfs_opendir,
+ .stat = omap4_usbbootfs_stat,
+/*
+ .create = omap4_usbbootfs_create,
+ .unlink = omap4_usbbootfs_unlink,
+ .mkdir = omap4_usbbootfs_mkdir,
+ .rmdir = omap4_usbbootfs_rmdir,
+ .write = omap4_usbbootfs_write,
+ .truncate= omap4_usbbootfs_truncate,
+*/
+ .flags = 0,
+ .drv = {
+ .probe = omap4_usbbootfs_probe,
+ .remove = omap4_usbbootfs_remove,
+ .name = "omap4_usbbootfs",
+ }
+};
+
+static int omap4_usbbootfs_init(void)
+{
+ return register_fs_driver(&omap4_usbbootfs_driver);
+}
+coredevice_initcall(omap4_usbbootfs_init);
--
1.7.12.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2012-10-08 22:56 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-08 22:55 [PATCH 00/14] archosg9: add support for tablet Vicente
2012-10-08 22:55 ` [PATCH 01/14] twl6030: add debug info Vicente
2012-10-08 22:55 ` [PATCH 02/14] omap4: add rename definitions to match datasheet Vicente
2012-10-08 22:55 ` [PATCH 03/14] ARM: import irq handling from linux Vicente
2012-10-08 22:55 ` [PATCH 04/14] ARM: ensure irqs are disabled Vicente
2012-10-08 22:55 ` [PATCH 05/14] omap: revert gpiolib Vicente
2012-10-08 22:55 ` [PATCH 06/14] omap4: add usb boot source Vicente
2012-10-08 22:55 ` [PATCH 07/14] bootm: close open files Vicente
2012-10-08 22:55 ` [PATCH 08/14] uimage: improve transfer speed Vicente
2012-10-08 22:55 ` [PATCH 09/14] fs: improve robustness Vicente
2012-10-08 22:55 ` [PATCH 10/14] omap4: add support for booting cpu from usb Vicente
2012-10-08 22:55 ` [PATCH 11/14] omap4: add serial communications over usb boot Vicente
2012-10-08 22:55 ` Vicente [this message]
2012-10-08 22:55 ` [PATCH 13/14] omap4: add support for loading second stage from usb Vicente
2012-10-08 22:55 ` [PATCH 14/14] Add support for Archos G9 tablet Vicente
2012-10-19 11:10 ` Jan Weitzel
2012-10-21 1:00 ` vj
2012-10-22 6:50 ` Jan Weitzel
2012-10-10 7:40 ` [PATCH 00/14] archosg9: add support for tablet Sascha Hauer
[not found] ` <CAAMcf8D0Xn6aWztkD=8dnv3P1qxNgxSV-2Q37kGOaRsOQE7xVA@mail.gmail.com>
2012-10-10 9:32 ` Sascha Hauer
2012-10-12 1:12 ` vj
[not found] ` <CAAMcf8CLimKWZddBfctSCct0wOJOk7tgTJpM7m_w8h5dOQRt1Q@mail.gmail.com>
2012-10-12 8:39 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1349736924-24667-13-git-send-email-vicencb@gmail.com \
--to=vicencb@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox