{"id":590,"date":"2011-11-28T11:19:56","date_gmt":"2011-11-28T11:19:56","guid":{"rendered":"http:\/\/41j.com\/blog\/?p=590"},"modified":"2011-12-01T14:03:43","modified_gmt":"2011-12-01T14:03:43","slug":"gumstix-as-usb-storage-device","status":"publish","type":"post","link":"https:\/\/41j.com\/blog\/2011\/11\/gumstix-as-usb-storage-device\/","title":{"rendered":"Gumstix as USB Storage device"},"content":{"rendered":"<p>These are my notes as of 28Nov 2011..<\/p>\n<p>Download the build system, but don&#8217;t build, just get it all setup as <a href=\"http:\/\/www.gumstix.org\/software-development\/open-embedded\/61-using-the-open-embedded-build-system.html\">here<\/a>.<\/p>\n<p>Add <\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nCONFIG_USB_GADGET_MUSB_HDRC=y\r\n<\/pre>\n<p>to org.openembedded.dev\/recipes\/linux\/linux-omap3\/overo\/defconfig<\/p>\n<p>Add<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\nMUSB_MODE = &quot;peripheral&quot;\r\n<\/pre>\n<p>to:<\/p>\n<p>${OVEROTOP}\/build\/conf\/local.conf<\/p>\n<p>bitbake linux-omap3<\/p>\n<p>This actually worked and resulted in a completed build! Though when I tried it multiple time before it failed.<\/p>\n<p>You can then build a complete image, for example:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nbitbake omap3-console-image\r\n<\/pre>\n<p>Once the build is complete install the image on your device\/SD Card for example, as <a href=\"http:\/\/41j.com\/blog\/2011\/11\/setting-up-a-gumstix-sd-card\/\">here<\/a>. MLO didn&#8217;t appear to be built as part of the build process, I just used a copy from the gumstix site.<\/p>\n<p>If you don&#8217;t want\/can&#8217;t complete the build, see the precompiled files below.<\/p>\n<p>You can now load the file storage device kernel module, for example:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nroot@overo:~# cat \/dev\/zero &gt; \/tmp\/file # best to control-C it before you use up all the SD free space.\r\nroot@overo:~# modprobe g_file_storage file=\/tmp\/file # load the kernel module!\r\n<\/pre>\n<p>You can mount the filesystem on the gumstix too via a loopback interface:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nlosetup \/dev\/loop0 \/tmp\/file\r\nmkfs.vfat \/dev\/loop0\r\nmkdir \/media\/t\r\nmount \/dev\/loop0 \/media\/t\r\n<\/pre>\n<p>You may run in to trouble reading\/writing from the gumstix and host at the same time though.<\/p>\n<p>Here are the compiled rootfs\/uImage\/uboot for overo in peripheral mode:<\/p>\n<p><a href=\"http:\/\/41j.com\/~new\/overoperipheral\/Angstrom-omap3-console-image-glibc-ipk-2011.03-overo.rootfs.tar.bz2\">RootFS<\/a><\/p>\n<p><a href=\"http:\/\/41j.com\/~new\/overoperipheral\/u-boot-overo-2011.09+r76+gitr0f331e606c80166c1bfe5cac40dfc0616708f31b-r76.bin\">UBoot<\/a><\/p>\n<p><a href=\"http:\/\/41j.com\/~new\/overoperipheral\/uImage-3.0-r103-overo.bin\">uImage<\/a><\/p>\n<h2>Composite device notes<\/h2>\n<p>&#8220;Composite device&#8221; is provided by the g_multi kernel module, so you need to add it (it&#8217;s not in the above images, I&#8217;m still trying this out)<\/p>\n<p>set:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nCONFIG_USB_G_MULTI=m\r\n<\/pre>\n<p>in org.openembedded.dev\/recipes\/linux\/linux-omap3\/overo\/defconfig<\/p>\n<p>Clean the build&#8230;<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nbitbake linux-omap3 -c clean\r\n<\/pre>\n<p>and rebuild as above.<\/p>\n<h2>Other notes<\/h2>\n<p>http:\/\/wiki.gumstix.org\/index.php?title=Category:How_to_-_usb<\/p>\n<p>Open Embedded build system setup:<\/p>\n<p>http:\/\/www.gumstix.org\/software-development\/open-embedded\/61-using-the-open-embedded-build-system.html<\/p>\n<p>fakeroot failed on my first attempt, but not my second&#8230; hmmm. I needed to do this:<\/p>\n<p>ERROR: The checksums for &#8220;\/home\/new\/overo-oe\/sources\/fakeroot_1.9.6.tar.gz&#8221; did not match. so had to:<\/p>\n<p>Because this version of fakeroot is no longer present in the Debian repositories.<\/p>\n<p>Edit:  ~\/overo-oe\/org.openembedded.dev\/recipes\/fakeroot\/fakeroot_1.9.6.bb<\/p>\n<p>Change: <\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nSRC_URI = &quot;${DEBIAN_MIRROR}\/main\/f\/fakeroot\/fakeroot_${PV}.tar.gz \\\r\n           file:\/\/configure-libtool.patch&quot;\r\n<\/pre>\n<p>to<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nSRC_URI = &quot;http:\/\/www.atmel.no\/buildroot\/source\/mirror\/fakeroot_1.9.6.tar.gz \\\r\n           file:\/\/configure-libtool.patch&quot;\r\n<\/pre>\n<p>To clean a build:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nbitbake linux-omap3 -c clean\r\n<\/pre>\n<p>Composite device notes:<\/p>\n<p>From http:\/\/blog.felipebalbi.com\/?p=44 (now offline):<\/p>\n<p>USB Composite Gadget Framework<\/p>\n<p>Hi all,<\/p>\n<p>Let&#8217;s take a look at the brand new, yet-to-be-merged USB Composite Gadget Framework.<\/p>\n<p>The framework was introduced by Linux USB Developer David Brownell and, thanks to his great work, we&#8217;re gonna be able to reuse what we now call usb function drivers into another entities, combining them to create a usb composite gadget.<\/p>\n<p>Quoting Dave himself:<\/p>\n<p>    We want to split most of the current gadget drivers into reusable\/combinable &#8220;usb_function&#8221; entities, making it easier to set up composite and multi-configuration gadgets.<\/p>\n<p>The framework allowed us to write simpler usb function drivers and glue code between the various kernel APIs and later on, with the framework provided in drivers\/usb\/gadget\/composite.c, create our own composite gadget.<\/p>\n<p>Basically, we just have to provide a struct usb_function with the correct function pointers to the upper layer and that&#8217;s all. This is how struct usb_function is defined:<\/p>\n<p>struct usb_function {<br \/>\n\tconst char\t\t\t*name;<br \/>\n\tstruct usb_gadget_strings\t**strings;<br \/>\n\tstruct usb_descriptor_header\t**descriptors;<br \/>\n\tstruct usb_descriptor_header\t**hs_descriptors;<\/p>\n<p>\tstruct usb_configuration\t*config;<\/p>\n<p>\tint\t\t\t(*bind)(struct usb_configuration *,<br \/>\n\t\t\t\t\tstruct usb_function *);<br \/>\n\tvoid\t\t\t(*unbind)(struct usb_configuration *,<br \/>\n\t\t\t\t\tstruct usb_function *);<br \/>\n\tint\t\t\t(*set_alt)(struct usb_function *,<br \/>\n\t\t\t\t\tunsigned interface, unsigned alt);<br \/>\n\tint\t\t\t(*get_alt)(struct usb_function *,<br \/>\n\t\t\t\t\tunsigned interface);<br \/>\n\tvoid\t\t\t(*disable)(struct usb_function *);<br \/>\n\tint\t\t\t(*setup)(struct usb_function *,<br \/>\n\t\t\t\t\tconst struct usb_ctrlrequest *);<\/p>\n<p>\tvoid\t\t\t(*suspend)(struct usb_function *);<br \/>\n\tvoid\t\t\t(*resume)(struct usb_function *);<\/p>\n<p>\tstruct list_head\t\tlist;<br \/>\n};<\/p>\n<p>Let me explain each member of this structure.<\/p>\n<p>    name: give a name to this usb_function<br \/>\n    descriptors: fullspeed descriptor headers<br \/>\n    hs_descriptors: same as above but with highspeed endpoints<br \/>\n    config: the configuration<br \/>\n    bind: will be called on an upper layer (likely) to bind this interface and combine it into the device structure, also allocate any needed resources<br \/>\n    unbind: release used resources<br \/>\n    set_alt: set alternate setting we need to use now<br \/>\n    get_alt: get the current alternate setting been used<br \/>\n    disable: disable endpoints<br \/>\n    setup: setup ep0 functionality<br \/>\n    suspend: put the function driver in suspend mode (for pm)<br \/>\n    resume: wake function driver up from suspend mode<\/p>\n<p>In Dave&#8217;s series, he already splitted (the example gadget) and Gadget Serial into reusable function drivers. In the case of Gadget Serial he also wrote the glue code for the TTY over USB.<\/p>\n<p>All of you are invited to help us writing other function drivers and also splitting the existing gadget drivers into reusable entities like it was done for Gadget Serial.<\/p>\n<p>I&#8217;m putting together some small tips in this page so feel free to take a look and start hacking the Linux Kernel.<\/p>\n<p>Don&#8217;t forget to check out linux-usb archives here to keep track of what&#8217;s happening with this framework.<\/p>\n<p>See y&#8217;all<\/p>\n<p>That links to this post:<\/p>\n<p>http:\/\/marc.info\/?l=linux-usb&#038;m=121130809918740&#038;w=2 text:<\/p>\n<p>We&#8217;ve had various discussions on this topic in the past, and I think<br \/>\nthis approach is pretty much ready to go now, apart from finishing<br \/>\nsome of the gadget driver conversions.  (Which I&#8217;m on the hook for&#8230;)<\/p>\n<p>A brief recap:  we want to split most of the current gadget drivers<br \/>\ninto reusable\/combinable &#8220;usb_function&#8221; entities, making it easier to<br \/>\nset up composite and multi-configuration gadgets.  Examples include<br \/>\nCDC WHCM (wireless handsets) and utility combinations like combining<br \/>\nan Ethernet model network link and a mass storage function.  A device<br \/>\nclass that&#8217;s standardized by USB-IF is an especially good candidate<br \/>\nfor combining in this way with other functions.<\/p>\n<p>Following this are eight patches:<\/p>\n<p> &#8211; Add some new utilities to support descriptor copying.  When<br \/>\n   one function shows up multiple times (in the same configuration<br \/>\n   or different ones) each instance generally needs new descriptors<br \/>\n   because the endpoint and interface IDs are not the same.<\/p>\n<p> &#8211; <linux\/usb\/composite.h> framework &#8230; think of it as a mid-layer<br \/>\n   into which functions can be plugged by the gadget driver.<\/p>\n<p> &#8211; Gadget Zero updated to use this framework, in three parts.<br \/>\n   This driver is just for testing, and isn&#8217;t aiming for re-use<br \/>\n   so much as simplified code; its current clients don&#8217;t expect<br \/>\n   to talk to composite devices.<\/p>\n<p>     * Split out a source\/sink configuration driver.<br \/>\n     * And a loopback configuration driver<br \/>\n     * Convert the core to use those split-out drivers,<br \/>\n       along with the new mid-layer code<\/p>\n<p> &#8211; Serial gadget (with recent updates posted last week) updated,<br \/>\n   also in three parts.  This is more of a real-world example of<br \/>\n   how this framework can work and add value.<\/p>\n<p>     * Split out a CDC ACM function driver<br \/>\n     * And a &#8220;generic serial&#8221; one<br \/>\n     * Convert the core to use those split-out drivers, etc<\/p>\n<p>Unfortunately these changes are extensive enough that intermediate<br \/>\npatches wouldn&#8217;t be even vaguely useful &#8230; the only patch splitting<br \/>\nthat seemed like it would facilitate review is what I did here:  to<br \/>\nshow the split-out functions (reviewable in conjunction with original<br \/>\ncode) in patches of their own, and then a conversion patch which is<br \/>\nprobably not very reviewable.<\/p>\n<p>That is:  the easiest review is probably of the resulting files,<br \/>\nnot the conversion patches.  I suspect you&#8217;ll agree that these<br \/>\nfunction drivers are a *lot* cleaner looking than the gadget<br \/>\ndrivers they came from!<\/p>\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<\/p>\n<p>More composite device info here: http:\/\/lwn.net\/Articles\/395712\/<\/p>\n","protected":false},"excerpt":{"rendered":"<p>These are my notes as of 28Nov 2011.. Download the build system, but don&#8217;t build, just get it all setup as here. Add CONFIG_USB_GADGET_MUSB_HDRC=y to org.openembedded.dev\/recipes\/linux\/linux-omap3\/overo\/defconfig Add MUSB_MODE = &quot;peripheral&quot; to: ${OVEROTOP}\/build\/conf\/local.conf bitbake linux-omap3 This actually worked and resulted in a completed build! Though when I tried it multiple time before it failed. You can [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-590","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1RRoU-9w","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/comments?post=590"}],"version-history":[{"count":32,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/590\/revisions"}],"predecessor-version":[{"id":638,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/posts\/590\/revisions\/638"}],"wp:attachment":[{"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/media?parent=590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/categories?post=590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/41j.com\/blog\/wp-json\/wp\/v2\/tags?post=590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}