Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Untitled
Sunday, September 9th, 2007 at 10:45:11am UTC 

  1. /***************************************************************************
  2.  *             __________               __   ___.
  3.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  4.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  5.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  6.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  7.  *                     \/            \/     \/    \/            \/
  8.  * $Id: crt0-pp-bl.S 11815 2006-12-19 11:33:53Z barrywardell $
  9.  *
  10.  * Copyright (C) 2007 by Jonathan Gordon
  11.  *
  12.  * All files in this archive are subject to the GNU General Public License.
  13.  * See the file COPYING in the source tree root for full license agreement.
  14.  *
  15.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  16.  * KIND, either express or implied.
  17.  *
  18.  ****************************************************************************/
  19.  
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <stdint.h>
  24. #include <ctype.h>
  25. #include <stdbool.h>
  26. #include "bootimg.h"
  27.  
  28. #include <usb.h> /* This tool requires libusb */
  29.  
  30.  
  31. #define E200_INTERFACE 0
  32. #define E200_ENDPOINT  1
  33.  
  34. #define E200_TIMEOUT    5000
  35. #define PROGRAM_TIMEOUT 120000
  36.  
  37. #define SANDISK_VENDOR_ID  0x0781
  38. #define SANDISK_PRODUCT_ID 0x0720
  39. #define PP_VENDOR_ID       0x0b70
  40. #define PP_PRODUCT_ID      0x0003
  41.  
  42. void put_le32(void * ptr, uint32_t val)
  43. {
  44.     uint8_t * b = ptr;
  45.    
  46.     b[0] = val;
  47.     b[1] = val >> 8;
  48.     b[2] = val >> 16;
  49.     b[3] = val >> 24;
  50. }
  51.  
  52.  
  53. int send_dev(usb_dev_handle * ud, const void * data, uint32_t len)
  54. {
  55.     char * buf = (char *)data;
  56.     int32_t todo;
  57.     int ret;
  58.  
  59.     while (len > 0)
  60.     {
  61.         todo = len > BUFSIZE ? BUFSIZE : len;
  62.  
  63.         ret = usb_bulk_write(ud, E200_ENDPOINT, buf, todo, E200_TIMEOUT);
  64.  
  65.         if (ret < 0)
  66.         {
  67.             fprintf(stderr, "\nBulk write error (%d, %s)\n", ret, strerror(-ret));
  68.             return ret;
  69.         }
  70.  
  71.         buf += ret;
  72.         len -= ret;
  73.     }
  74.     return 0;
  75. }
  76.  
  77. usb_dev_handle *device_get(int vendor, int product)
  78. {
  79.     struct usb_bus * bus, * busses;
  80.     struct usb_device * dev;
  81.     usb_dev_handle * ud;
  82.     int ret, retries = 10;
  83.     bool found = false;
  84.    
  85.     fprintf(stderr, "Searching for device %04x:%04x ... ", vendor, product);
  86.  
  87.  retry:
  88.     found = false;
  89.     usb_find_busses();
  90.     usb_find_devices();
  91.  
  92.     busses = usb_get_busses();
  93.  
  94.     for (bus = busses; !found && bus; bus = bus->next)
  95.     {
  96.         for (dev = bus->devices; dev; dev = dev->next)
  97.         {
  98.             if ((dev->descriptor.idVendor        == vendor  &&
  99.                  dev->descriptor.idProduct       == product &&
  100.                  dev->descriptor.bDeviceClass    == 0xff    &&
  101.                  dev->descriptor.bDeviceSubClass == 0xff    &&
  102.                  dev->descriptor.bDeviceProtocol == 0xff))
  103.             {
  104.                 found = true;
  105.                 break;
  106.             }
  107.         }
  108.         if (found)
  109.         {
  110.             fprintf(stderr, "found!\n");
  111.             ud = usb_open(dev);
  112.             if (!ud)
  113.             {
  114.                 fprintf(stderr, "Failed to open the device!\n");
  115.                 return NULL;
  116.             }
  117.             ret = usb_claim_interface(ud, E200_INTERFACE);
  118.  
  119.             if (ret < 0)
  120.             {
  121.                 fprintf(stderr, "Failed to claim the interface (%d, %s)\n",
  122.                         ret, strerror(-ret));
  123.                 usb_close(ud);
  124.                 return NULL;
  125.             }
  126.             return ud;
  127.         }
  128.     }
  129.  
  130.     if (retries-- > 0)
  131.     {
  132.         do_delay(1);
  133.         fprintf(stderr, "%d ", retries);
  134.         goto retry;
  135.     }
  136.     fprintf(stderr, "not found!\n");
  137.     return NULL;
  138. }
  139.  
  140. int main(int argc, char * argv[])
  141. {
  142.     (void)argc;(void)argv;
  143.     usb_dev_handle * ud;
  144.     int ret;
  145.     char buffer[16];
  146.     fprintf(stderr, "e200r-installer, (c) Jonathan Gordon 2007\n%s\n", "$Revision$");
  147.     usb_init();
  148.     ud = device_get(SANDISK_VENDOR_ID, SANDISK_PRODUCT_ID);
  149.     if (!ud)
  150.     {
  151.         ud = device_get(PP_VENDOR_ID, PP_PRODUCT_ID);
  152.         if (!ud)
  153.             return 1;
  154.     }
  155.     fprintf(stderr, "Transferring Installer to Sansa...\n");
  156.     put_le32(buffer, LEN_bootimg);
  157.     ret = usb_bulk_write(ud, E200_ENDPOINT, buffer, sizeof LEN_bootimg, E200_TIMEOUT);
  158.     if (ret < 0)
  159.     {
  160.         fprintf(stderr, "\nLength write error (%d, %s)\n", ret, strerror(-ret));
  161.         return 1;
  162.     }
  163.     ret = send_dev(ud, bootimg, LEN_bootimg);
  164.     fprintf(stderr, "%d bytes LEN_bootimg\n", ret);
  165.  
  166.     usb_release_interface(ud, E200_INTERFACE);
  167.     usb_close(ud);
  168.     return 0;
  169. }

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right