title: Run arduino sketch from an sd card
body: <p>Is it possible to put a sketch (.HEX file) to an SD card and run it from there? 
  My objective is to utilize SD storage instead of flash memory for a program.</p>
  
  <p>If yes, are there any libraries doing exactly this? </p>
  
  <p>All i found was "flashing arduino from sd card", which is <strong>not</strong> what i need.</p>
  
  <h2>UPDATE:</h2>
  
  <p>the sketch's <code>loop</code> calling is implemented in the bootloader. 
  so i assume there is something like this in the bootloader:</p>
  
  <pre><code>while(true)
  {
      call_sketch_loop();
  }
  </code></pre>
  
  <p>can it be changed to this? :</p>
  
  <pre><code>//signature changed from void loop() to int loop()
  while(true)
  {
      int retval = call_sketch_loop(); //get loop call's return value
  
      if( 0 == retval )
          continue; // if 0, iterate the loop as usual
      else
      {
          //copy 1.HEX from sd to flash and reboot
          copy_hex_from_sd_to_flash( retval + ".HEX" );
          reboot();
      }
  }
  </code></pre>
  
  <ol>
  <li>change loop singature to <code>int loop()</code></li>
  <li>put {int}.HEX files to an SD card - <code>1.HEX , 2.HEX , 3.HEX</code></li>
  <li>the loop() call returns <code>0</code></li>
  <li>continue with next iteration as usual</li>
  <li>the loop() call returns <code>2</code></li>
  <li>copy file <code>2.HEX</code> from SD card into program flash memory</li>
  <li>reboot device</li>
  </ol>
  
  <p>with this approach, we can run flash-capacity-exceeding programs if we split them up to smaller subprograms.</p>