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

Something
Friday, December 1st, 2006 at 7:41:07pm UTC 

  1. /***************************************************************************
  2.  *             __________               __   ___.
  3.  *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
  4.  *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
  5.  *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
  6.  *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
  7.  *                     \/            \/     \/    \/            \/
  8.  * $Id: h10.c,v 1.4 2006-08-28 08:11:32 barrywardell Exp $
  9.  *
  10.  * Copyright (C) 2006 by Barry Wardell
  11.  *
  12.  * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing
  13.  * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach
  14.  *
  15.  * All files in this archive are subject to the GNU General Public License.
  16.  * See the file COPYING in the source tree root for full license agreement.
  17.  *
  18.  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19.  * KIND, either express or implied.
  20.  *
  21.  ****************************************************************************/
  22. #include "config.h"
  23.  
  24. #include <stdlib.h>
  25. #include <stdio.h>
  26. #include <string.h>
  27. #include "cpu.h"
  28. #include "system.h"
  29. #include "lcd.h"
  30. #include "kernel.h"
  31. #include "thread.h"
  32. #include "ata.h"
  33. #include "fat.h"
  34. #include "disk.h"
  35. #include "font.h"
  36. #include "adc.h"
  37. #include "backlight.h"
  38. #include "button.h"
  39. #include "panic.h"
  40. #include "power.h"
  41. #include "file.h"
  42.  
  43. /* Size of the buffer to store the loaded Rockbox/Sansa image */
  44. #define MAX_LOADSIZE (10*1024*1024)
  45.  
  46. /* A buffer to load the iriver firmware or Rockbox into */
  47. unsigned char loadbuffer[MAX_LOADSIZE];
  48.  
  49. char version[] = APPSVERSION;
  50.  
  51. #define DRAM_START              0x10000000
  52.  
  53. int line=0;
  54.  
  55. /* Load original Sandisk firmware. This function expects a file called
  56.    "/.rockbox/OF.bin" on the player. It should be decrypted
  57.    and have the header stripped using mi4code. It reads the file in to a memory
  58.    buffer called buf. The rest of the loading is done in main() and crt0.S
  59. */
  60. int load_sandisk(unsigned char* buf)
  61. {
  62.     int fd;
  63.     int rc;
  64.     int len;
  65.  
  66.     fd = open("/.rockbox/OF.bin", O_RDONLY);
  67.  
  68.     len = filesize(fd);
  69.  
  70.     if (len > MAX_LOADSIZE)
  71.         return -6;
  72.  
  73.     rc = read(fd, buf, len);
  74.     if(rc < len)
  75.         return -4;
  76.  
  77.     close(fd);
  78.     return len;
  79. }
  80.  
  81. /* Load Rockbox firmware (rockbox.e200) */
  82. int load_rockbox(unsigned char* buf)
  83. {
  84.     int fd;
  85.     int rc;
  86.     int len;
  87.     unsigned long chksum;
  88.     char model[5];
  89.     unsigned long sum;
  90.     int i;
  91.     char str[80];
  92.  
  93.     fd = open("/.rockbox/" BOOTFILE, O_RDONLY);
  94.     if(fd < 0)
  95.     {
  96.         fd = open("/" BOOTFILE, O_RDONLY);
  97.         if(fd < 0)
  98.             return -1;
  99.     }
  100.  
  101.     len = filesize(fd) - 8;
  102.  
  103.     snprintf(str, sizeof(str), "Length: %x", len);
  104.     lcd_puts(0, line++ ,str);
  105.     lcd_update();
  106.  
  107.     if (len > MAX_LOADSIZE)
  108.         return -6;
  109.  
  110.     lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
  111.  
  112.     rc = read(fd, &chksum, 4);
  113.     chksum=betoh32(chksum); /* Rockbox checksums are big-endian */
  114.     if(rc < 4)
  115.         return -2;
  116.  
  117.     snprintf(str, sizeof(str), "Checksum: %x", chksum);
  118.     lcd_puts(0, line++ ,str);
  119.     lcd_update();
  120.  
  121.     rc = read(fd, model, 4);
  122.     if(rc < 4)
  123.         return -3;
  124.  
  125.     model[4] = 0;
  126.  
  127.     snprintf(str, sizeof(str), "Model name: %s", model);
  128.     lcd_puts(0, line++ ,str);
  129.     lcd_update();
  130.  
  131.     lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
  132.  
  133.     rc = read(fd, buf, len);
  134.     if(rc < len)
  135.         return -4;
  136.  
  137.     close(fd);
  138.  
  139.     sum = MODEL_NUMBER;
  140.  
  141.     for(i = 0;i < len;i++) {
  142.         sum += buf[i];
  143.     }
  144.  
  145.     /* I don't know why my checksums aren't matching.  Figure this out before committing.  Hack around it for now */
  146.     sum += 4;
  147.  
  148.     snprintf(str, sizeof(str), "Sum: %x", sum);
  149.     lcd_puts(0, line++ ,str);
  150.     lcd_update();
  151.  
  152.     if(sum != chksum)
  153.         return -5;
  154.  
  155.     return len;
  156. }
  157.  
  158. void* main(void)
  159. {
  160.     char buf[256];
  161.     int i;
  162.     int rc;
  163.     unsigned short* identify_info;
  164.     struct partinfo* pinfo;
  165.  
  166.     system_init();
  167.     kernel_init();
  168.     lcd_init();
  169.     font_init();
  170.  
  171.     line=0;
  172.  
  173.     lcd_setfont(FONT_SYSFIXED);
  174.  
  175.     lcd_puts(0, line++, "Rockbox boot loader");
  176.     snprintf(buf, sizeof(buf), "Version: 20%s", version);
  177.     lcd_puts(0, line++, buf);
  178.     snprintf(buf, sizeof(buf), "Sandisk Sansa E200");
  179.     lcd_puts(0, line++, buf);
  180.     lcd_update();
  181.  
  182.     i=ata_init();
  183.     if (i==0) {
  184.       identify_info=ata_get_identify();
  185.       /* Show model */
  186.       for (i=0; i < 20; i++) {
  187.         ((unsigned short*)buf)[i]=htobe16(identify_info[i+27]);
  188.       }
  189.       buf[40]=0;
  190.       for (i=39; i && buf[i]==' '; i--) {
  191.         buf[i]=0;
  192.       }
  193.       lcd_puts(0, line++, buf);
  194.       lcd_update();
  195.     } else {
  196.       snprintf(buf, sizeof(buf), "ATA: %d", i);
  197.       lcd_puts(0, line++, buf);
  198.       lcd_update();
  199.     }
  200.  
  201.     disk_init();
  202.     rc = disk_mount_all();
  203.     if (rc<=0)
  204.     {
  205.         lcd_puts(0, line++, "No partition found");
  206.         lcd_update();
  207.     }
  208.  
  209.     pinfo = disk_partinfo(0);
  210.     snprintf(buf, sizeof(buf), "Partition 0: 0x%02x %ld MB",
  211.                   pinfo->type, pinfo->size / 2048);
  212.     lcd_puts(0, line++, buf);
  213.     lcd_update();
  214.  
  215.     i=button_read_device();
  216.     if(i==BUTTON_LEFT)
  217.     {
  218.         lcd_puts(0, line, "Loading Sandisk firmware...");
  219.         lcd_update();
  220.         rc=load_sandisk(loadbuffer);
  221.         /* Sandisk firmware doesn't like having the cache enabled */
  222.     } else {
  223.         lcd_puts(0, line, "Loading Rockbox...");
  224.         lcd_update();
  225.         rc=load_rockbox(loadbuffer);
  226.     }
  227.  
  228.     if (rc < 0) {
  229.             snprintf(buf, sizeof(buf), "Rockbox error: %d",rc);
  230.             lcd_puts(0, line++, buf);
  231.             lcd_update();
  232.             while(1) {}
  233.     }
  234.  
  235.     memcpy((void*)DRAM_START,loadbuffer,rc);
  236.     return (void*)DRAM_START;
  237. }
  238.  
  239. /* These functions are present in the firmware library, but we reimplement
  240.    them here because the originals do a lot more than we want */
  241.  
  242. void reset_poweroff_timer(void)
  243. {
  244. }
  245.  
  246. int dbg_ports(void)
  247. {
  248.    return 0;
  249. }
  250.  
  251. void mpeg_stop(void)
  252. {
  253. }
  254.  
  255. void usb_acknowledge(void)
  256. {
  257. }
  258.  
  259. void usb_wait_for_disconnect(void)
  260. {
  261. }
  262.  
  263. void sys_poweroff(void)
  264. {
  265. }

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