1 2 Previous Next 15 Replies Latest reply on Oct 8, 2014 1:50 PM by AlexT_Intel

    Can I start a sketch that is stored on a USB drive?

    Clayton Hofrock

      Instead of buying an SD card, could I use an old usb thumb drive to store my sketch?

       

      If so, how do I start the sketch? Is it possible to start the sketch during bootup, just like one stored on an SD Card?

        • 1. Re: Can I start a sketch that is stored on a USB drive?
          AlexT_Intel

          There's obviously no support for that out of the box, but as it's Linux after all, we might be able to plug into existing startup scripts to do something like that. The exact way of doing this, hmm... Needs some analysis :-) I'll think about that and post my thoughts.

          1 of 1 people found this helpful
          • 2. Re: Can I start a sketch that is stored on a USB drive?
            AlexT_Intel

            chofrock, could you please describe the exact scenario you have in mind for that, to make sure I'll be trying exactly the thing you want?

             

            Is it something like you want to boot from SPI and if there's a USB flash drive connected, which has a /sketch directory - you want Galileo to use it as a persistent storage for sketches and run a sketch, if one is found there?

            What about creating that dir, if it doesn't exist, but the drive is found during boot? What about the fallback - if the drive is not connected, do you want it to use the current method (tmpfs)? Do you want this functionality to be available for SD card image too?

             

            And another question - to everyone, does anyone else is interested in this functionality? The more people are interested, the more motivation I'll have for digging into this :-) Right now we're in a quite interesting stage of Galileo ecosystem creation, so there are quite a few projects I have on the list competing for my free time, which is rather limited anyway :-)

            • 3. Re: Can I start a sketch that is stored on a USB drive?
              Clayton Hofrock

              Really how this came about was I was trying to find my micro SD card (they are so small and easy to misplace) and I was frustrated that I could not just use one of the USB thumb drives I had laying around. This led me to  about how many people will not have a spare micro SD card laying around, but everyone has a spare USB thumb drive. It would be nice if we could use a thumb drive instead of using a micro SD card.

               

              Of course using the thumb drive requires an adaptor which people might not have laying around. But still the price of an adapter is much less (~$5) than that of a micro SD card (~$20 depending on the size). I happened to have one laying around from when I was connecting a USB drive to my tablet.

               

              Plus if we could use a thumb drive, then using a USB hard drive has the potential to be able to store a lot of data.

              1 of 1 people found this helpful
              • 4. Re: Can I start a sketch that is stored on a USB drive?
                AlexT_Intel

                Yep, that makes sense to me. So we are talking about SPI image + thumbdrive as a persistent storage. Does the below scenario looks like what you'd want?

                 

                1) SPI image boots and checks if there's a thumbdrive available on the USB

                     a) if no - it just uses the standard tmpfs-based /sketch location, like it does now;

                     b) if yes - it checks if there's a sketch dir in the root of the thumbdrive

                          b1) if yes - it uses it as a persistent sketch storage;

                          b2) if no - do we want it to create one and use as a persistent storage (like the SD image does), or just not touch anything, implying that user doesn't want to use the drive as a sketch storage and just left it plugged in for whatever reason?

                • 5. Re: Can I start a sketch that is stored on a USB drive?
                  Clayton Hofrock

                  That is what I would like it to do.

                   

                  Another problem is the IDE. It would have to be changed to also look and see if there is a USB and store the sketch on the USB thumb drive.

                   

                  So the IDE could store the sketch in one of three places:

                  1. In virtual memory (if running with no SD card or USB)
                  2. Store it on the the USB thumb drive, if one is attached.
                  3. Store it on the SD card, if one was attached.

                   

                  I thin the preferred storage would be fist the SD card, second the USB thumb drive, and lastly in virtual memory if nothing is attached.

                  • 6. Re: Can I start a sketch that is stored on a USB drive?
                    DAM

                    I liked all of this and the direction headed.
                    on a separate note, does the sd card actually let you create a new non-existing file?

                    • 7. Re: Can I start a sketch that is stored on a USB drive?
                      Clayton Hofrock

                      You can create new files on the SD card from the Linux console. Currently, there is a bug in the Arduino SD library that keeps a new file from being created (should be fixed in the next release).

                       

                      There is a work around for the SD card issue. It is documented here:

                      https://communities.intel.com/thread/46635

                      • 8. Re: Can I start a sketch that is stored on a USB drive?
                        AlexT_Intel

                        So here's an initial solution to that: https://github.com/alext-mkrs/meta-alext-galileo/tree/master/recipes-addfeatures/sketch_on_thumbdrive

                        Make sure to read the README in that dir as well as in the root dir of that repo - it describes the way to use those recipes.

                         

                        It implements the logic we've discussed before by adding an init script to the image, which checks if we're booting off SPI and have a USB thumbdrive connected with "sketch" dir on it. If all that is true - it replaces the in-memory dir with symlink to the thumbdrive dir. If it's booted off SD card - it does nothing.

                         

                        As a result it implements exactly the logic you described, SD card first, then USB thumbdrive, then in-memory dir.

                         

                        Feel free to try it out and let me know how it goes. Pull requests are more than welcome too.

                        • 9. Re: Can I start a sketch that is stored on a USB drive?
                          Clayton Hofrock

                          Thanks I will give this a try.

                           

                          I was hoping that I could use a Thumbdrive without needing an SD card installed at all, but that would probably require editing the SPI image, which may not be very easy.

                          • 10. Re: Can I start a sketch that is stored on a USB drive?
                            AlexT_Intel

                            I was hoping that I could use a Thumbdrive without needing an SD card installed at all, but that would probably require editing the SPI image, which may not be very easy.

                            Yes, that's exactly what the recipe does - it embeds the init script, which does the job, into the boot sequence.

                             

                            With SD card, to be honest, it doesn't make too much sense (IMHO) to use USB drive (unless you want to move the sketch binaries between Galileo and some other computer), so as I mentioned - when booting off SD card the script won't redirect sketch dir to USB drive.

                             

                            Real value, as I see it, comes from usign USB thumbdrive when booting off SPI image and for that you need to rebuild it and reflash the board, yes.

                             

                            But that's quite simple, actually. Take a look at the README file at the root of that layer repo I linked above. It has a very condensed version of commands needed to build the image. Just use "bitbake image-spi" instead of image-full at the end. And after that - pass the paths to the built kernel, initramfs and grub,efi to another my script - and it will build a firmware image (cap) for you, which you can flash using serial console and CapsuleApp.efi. If you need a step-by-step instruction for the whole process - feel free to ask, I'll try to arrange something.

                            • 11. Re: Can I start a sketch that is stored on a USB drive?
                              Clayton Hofrock

                              I am not sure I fully understand the directions. Here is what I think I understand. In the sketch_on _thumbdrive repository there is a file: set_sketch_dir.sh. This is the file that actually changes the directory to point to the directory on the thumb drive. This file should be in the directory: /etc/init.d/set_sketch_dir.sh.

                               

                              What I do not understand is how that file gets into that directory? Is that done automatically if I use your script to build the SPI image? Can I just start my Galileo (booting from the SPI) and transfer the file to that directory? Will the file be there the next time I restart the Galileo?

                               

                              If I need to use your script to build the SPI, where do I get the files from? I have built the 0.8.0 firmware, but only for the SD card. Maybe the BSP has directions on how to create those files? But I am not clear on which steps your script replaces.

                              • 12. Re: Can I start a sketch that is stored on a USB drive?
                                AlexT_Intel

                                Sure, no worries, let me elaborate.

                                 

                                You've got the core of it just right - the set_sketch_dir.sh script should end up in the /etc/init.d/ dir of the SPI image. Unfortunately (or fortunately - depending on the point of view) the SPI image is "read-only in a sense - after booting everything is in memory, so you can't just drop the script to /etc/init.d as in the SD card boot case - it will simply disappear after reboot.

                                 

                                To do that you'd need to:

                                • rebuild the SPI image with additional build instructions to Yocto, which will put the script into relevant place;
                                • "package" it as a UEFI capsule file (that's what my script in galileo-fw git repo does) - that produces the *.cap or *.bin file ready to be flashed to the board;
                                • Flash it to the board using the serial console or DediProg;

                                 

                                 

                                Here's the exact list of steps, assuming you're doing everything from scratch. Meta-clanton_v0.8.0.tar.gz can be found in the BSP 7z file you can get here

                                 

                                mkdir /tmp/build && cd /tmp/image

                                tar xzvf meta-clanton_v0.8.0.tar.gz
                                cd meta-clanton_0.8.0

                                # meta-alex-galileo is Yocto layer - the Yocto way of adding

                                # new functions or modifying existing build recipes

                                git clone https://github.com/alext-mkrs/meta-alext-galileo

                                ./setup.sh -e "meta-clanton-galileo meta-alext-galileo"

                                # The below is one single command line, renaming the bbappend file

                                mv meta-alext-galileo/recipes-addfeatures/sketch_on_thumbdrive/initscripts_1.0.bbappend.disabled meta-alext-galileo/recipes-addfeatures/sketch_on_thumbdrive/initscripts_1.0.bbappend


                                source poky/oe-init-build-env yocto_build/
                                bitbake image-spi

                                # Now we've got the kernel & filesystem image built, let's create the firmware file

                                mkdir /tmp/fw && cd /tmp/fw

                                git clone https://github.com/alext-mkrs/galileo-fw ./

                                # The below is one single command line, we'll build a UEFI capsule file,

                                # which is flashed using serial console, which is simpler than dealing with *.bin

                                build_galileo_fw.sh -k /tmp/image/meta-clanton_0.8.0/yocto_build/tmp/deploy/images/bzImage -i /tmp/image/meta-clanton_0.8.0/yocto_build/tmp/deploy/images/image-spi-clanton.cpio.lzma -g /tmp/image/meta-clanton_0.8.0/yocto_build/tmp/deploy/images/grub.efi -t cap


                                # After command finishes you will get a Flash-missingPDAT.cap in the same dir as the script

                                # Download the respective CapsuleApp.efi file from here:

                                # http://downloadmirror.intel.com/23197/eng/CapsuleApp.efi

                                # Copy the Flash-missing.PDAT.cap and CapsuleApp.efi to an SD card and flash the board using

                                # instructions in Section 8 of the BSP Build Guide:

                                # http://downloadmirror.intel.com/23197/eng/Quark_BSP_BuildGuide_329687_003.pdf

                                # Note: instead of step 5, just hit F7 when prompted by the board, right after power on

                                # and you'll immediately see the menu referenced in step 6


                                 

                                After flashing process finished, the board will reboot and you can start playing with it and with this script.

                                 

                                Hope this helps. Let me know if something is unclear or doesn't work.

                                 

                                Message was edited by: AlexT: corrected formatting

                                • 13. Re: Can I start a sketch that is stored on a USB drive?
                                  AlexT_Intel

                                  By the way, while working on the above I realized you can actually boot the "SD card image" off the USB thumbdrive instead of the SD card (the UEFI looks not only at the SD card but the USB devices too when determining where to boot from). The steps are the same - just unpack that 7z file with "SD card" image, or put the below four items you get after compiling image-full by yourself into the root of the FAT or FAT32-formatted thumbdrive, connect it to the USB host port and power the Galileo on.

                                   

                                  Files to copy to the USB thumbdrive:

                                  bzImage

                                  core-image-minimal-initramfs-clanton.cpio.gz

                                  image-full-clanton.ext3

                                  boot (a directory)

                                   

                                  I don't know why it's not advertised, as USB thumbdrives are even more ubiquitous than SD cards (though bulkier - maybe that's the reason). Maybe there are some side effects I don't know of, but so far it booted just fine and I had no problems with the Blink sketch, so all the basics are there.

                                   

                                  Coupled with the set_sketch_dir.sh in its current form (which doesn't account for such a use case) you get an interesting side effect of having the writeable Linux image where you can change things unlike in the SPI one, but the sketch dir is outside of that loop-mounted file, so you can access your sketches from any other computer - something chofrock was asking about a while ago on this forum.

                                  • 14. Re: Can I start a sketch that is stored on a USB drive?
                                    osquillar

                                    Hi Alex, do you know any system to decrement the boot time of the galileo board when the linux is in the SD?. More than 20 seconds seems to be too much for many applications.

                                    Is there any lite version of the linux to speed up this sequence and make it more close to an microcontroller system?

                                     

                                    Regards

                                    Óscar

                                    1 2 Previous Next