mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: vj <vicencb@gmail.com>
To: barebox@lists.infradead.org
Cc: vj <vicencb@gmail.com>
Subject: [PATCH 6/7] add filesystem support over the same USB used for booting
Date: Wed, 26 Sep 2012 00:59:53 +0200	[thread overview]
Message-ID: <1348613994-1793-7-git-send-email-vicencb@gmail.com> (raw)
In-Reply-To: <1348613994-1793-1-git-send-email-vicencb@gmail.com>

---
 fs/Kconfig     |   5 ++
 fs/Makefile    |   1 +
 fs/usbbootfs.c | 195 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 201 insertions(+)
 create mode 100644 fs/usbbootfs.c

diff --git a/fs/Kconfig b/fs/Kconfig
index 4c66543..1b89aec 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -29,6 +29,11 @@ config FS_TFTP
 	prompt "tftp support"
 	depends on NET
 
+config FS_USBBOOT
+	bool
+	prompt "Filesystem over usb boot"
+	depends on USB_BOOT
+
 config FS_NFS
 	depends on NET
 	bool
diff --git a/fs/Makefile b/fs/Makefile
index 1b52bee..d4f9a59 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_USBBOOT)	+= usbbootfs.o
 obj-$(CONFIG_FS_NFS)	+= nfs.o
diff --git a/fs/usbbootfs.c b/fs/usbbootfs.c
new file mode 100644
index 0000000..a40abbf
--- /dev/null
+++ b/fs/usbbootfs.c
@@ -0,0 +1,195 @@
+/*
+ * usbbootfs.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+#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 USBBOOT_FS_MAGIC     0x5562464D
+#define USBBOOT_FS_CMD_OPEN  0x46530000
+#define USBBOOT_FS_CMD_CLOSE 0x46530001
+#define USBBOOT_FS_CMD_READ  0x46530002
+#define USBBOOT_FS_CMD_END   0x4653FFFF
+
+struct file_priv {
+    s32 id;
+    u32 size;
+};
+/*
+static int usbbootfs_create(struct device_d *dev, const char *pathname, mode_t mode){
+    return -ENOSYS;
+}
+
+static int usbbootfs_unlink(struct device_d *dev, const char *pathname){
+    return -ENOSYS;
+}
+
+static int usbbootfs_mkdir(struct device_d *dev, const char *pathname){
+    return -ENOSYS;
+}
+
+static int usbbootfs_rmdir(struct device_d *dev, const char *pathname){
+    return -ENOSYS;
+}
+
+static int usbbootfs_write(struct device_d *_dev, FILE *f, const void *inbuf, size_t size){
+    return -ENOSYS;
+}
+
+static int usbbootfs_truncate(struct device_d *dev, FILE *f, ulong size){
+    return -ENOSYS;
+}
+*/
+
+static struct file_priv *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 = USBBOOT_FS_MAGIC   ; usb_write(&data, 4);
+    data = USBBOOT_FS_CMD_OPEN; usb_write(&data, 4);
+    usb_puts(filename);
+    data = USBBOOT_FS_CMD_END ; usb_write(&data, 4);
+    
+    if(usb_read(&priv->id, 4) || usb_read(&priv->size, 4)){
+        free(priv);
+        return ERR_PTR(-EIO);
+    }
+    if(priv->id<0){
+        free(priv);
+        return ERR_PTR(-ENOENT);
+    }
+    
+    return priv;
+}
+
+static int usbbootfs_open(struct device_d *dev, FILE *file, const char *filename){
+    struct file_priv *priv;
+
+    priv = 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 usbbootfs_do_close(struct file_priv *priv){
+    u32 data;
+    data = USBBOOT_FS_MAGIC    ; usb_write(&data, 4);
+    data = USBBOOT_FS_CMD_CLOSE; usb_write(&data, 4);
+    usb_write(&priv->id, 4);
+    data = USBBOOT_FS_CMD_END  ; usb_write(&data, 4);
+    free(priv);
+    return 0;
+}
+
+static int usbbootfs_close(struct device_d *dev, FILE *f){
+    struct file_priv *priv = f->inode;
+    return usbbootfs_do_close(priv);
+}
+
+static int 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 = USBBOOT_FS_MAGIC   ; usb_write(&data, 4);
+    data = USBBOOT_FS_CMD_READ; usb_write(&data, 4);
+    usb_write(&priv->id, 4);
+    usb_write(&f->pos, 4);
+    usb_write(&size, 4);
+    data = USBBOOT_FS_CMD_END ; usb_write(&data, 4);
+
+    if(usb_read(buf, size))
+        return -EIO;
+
+    return size;
+}
+
+static loff_t usbbootfs_lseek(struct device_d *dev, FILE *f, loff_t pos){
+    f->pos = pos;
+    return pos;
+}
+
+static DIR* usbbootfs_opendir(struct device_d *dev, const char *pathname){
+    return NULL;
+}
+
+static int usbbootfs_stat(struct device_d *dev, const char *filename, struct stat *s){
+    struct file_priv *priv;
+
+    priv = 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;
+
+    usbbootfs_do_close(priv);
+
+    return 0;
+}
+
+static int usbbootfs_probe(struct device_d *dev){ return 0; }
+static void usbbootfs_remove(struct device_d *dev){}
+
+static struct fs_driver_d usbbootfs_driver = {
+    .open      = usbbootfs_open,
+    .close     = usbbootfs_close,
+    .read      = usbbootfs_read,
+    .lseek     = usbbootfs_lseek,
+    .opendir   = usbbootfs_opendir,
+    .stat      = usbbootfs_stat,
+/*
+    .create    = usbbootfs_create,
+    .unlink    = usbbootfs_unlink,
+    .mkdir     = usbbootfs_mkdir,
+    .rmdir     = usbbootfs_rmdir,
+    .write     = usbbootfs_write,
+    .truncate  = usbbootfs_truncate,
+*/
+    .flags     = 0,
+    .drv = {
+        .probe  = usbbootfs_probe,
+        .remove = usbbootfs_remove,
+        .name = "usbbootfs",
+    }
+};
+
+static int usbbootfs_init(void){
+    return register_fs_driver(&usbbootfs_driver);
+}
+coredevice_initcall(usbbootfs_init);
-- 
1.7.12.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2012-09-25 23:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <[RFC][PATCH] archosg9: add support for tablet>
2012-09-25 22:59 ` [PATCH 0/7] [RFC][PATCH] archosg9: add support for tablet vj
2012-09-25 22:59   ` [PATCH 1/7] Improved an error message and solved a minor bug vj
2012-09-26  7:11     ` Sascha Hauer
2012-09-25 22:59   ` [PATCH 2/7] added debug info for twl6030 vj
2012-09-25 22:59   ` [PATCH 3/7] OMAP specific changes vj
2012-09-26  7:18     ` Sascha Hauer
2012-09-25 22:59   ` [PATCH 4/7] Add USB booting capabilities to OMAP vj
2012-09-26  7:45     ` Sascha Hauer
2012-09-28  0:27       ` vj
2012-09-28  7:32         ` Sascha Hauer
2012-09-25 22:59   ` [PATCH 5/7] add console support over the same USB used for booting vj
2012-09-25 22:59   ` vj [this message]
2012-09-25 22:59   ` [PATCH 7/7] Add support for Archos G9 tablet vj
2012-09-26  3:57   ` [PATCH 0/7] [RFC][PATCH] archosg9: add support for tablet Antony Pavlov
2012-09-26  7:06   ` Sascha Hauer
2012-09-26 22:38     ` vj
2012-09-26  8:16   ` 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=1348613994-1793-7-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