1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: main.c 11997 2007-01-13 09:08:18Z miipekk $
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "lcd-remote.h"
31 /* TODO: Other bootloaders need to be adjusted to set this variable to true
32 on a button press - currently only the ipod, H10 and Sansa versions do. */
33 #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined(IRIVER_H10_5GB) \
34 || defined(SANSA_E200) || defined(SANSA_C200) || defined(GIGABEAT_F) \
35 || defined(PHILIPS_SA9200)
42 #ifdef HAVE_REMOTE_LCD
48 void reset_screen(void)
52 #ifdef HAVE_REMOTE_LCD
53 lcd_remote_clear_display();
58 void printf(const char *format
, ...)
66 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
69 lcd_puts(0, line
++, ptr
);
72 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
74 #ifdef HAVE_REMOTE_LCD
75 lcd_remote_puts(0, remote_line
++, ptr
);
78 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
83 char *strerror(int error
)
90 return "File not found";
91 case EREAD_CHKSUM_FAILED
:
92 return "Read failed (chksum)";
93 case EREAD_MODEL_FAILED
:
94 return "Read failed (model)";
95 case EREAD_IMAGE_FAILED
:
96 return "Read failed (image)";
98 return "Bad checksum";
100 return "File too big";
101 case EINVALID_FORMAT
:
102 return "Invalid file format";
108 void error(int errortype
, int error
)
113 printf("ATA error: %d", error
);
117 printf("No partition found");
121 printf(strerror(error
));
130 /* Load firmware image in a format created by tools/scramble */
131 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
136 unsigned long chksum
;
140 char filename
[MAX_PATH
];
142 snprintf(filename
,sizeof(filename
),"/.rockbox/%s",firmware
);
143 fd
= open(filename
, O_RDONLY
);
146 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
147 fd
= open(filename
, O_RDONLY
);
149 return EFILE_NOT_FOUND
;
152 len
= filesize(fd
) - 8;
154 printf("Length: %x", len
);
156 if (len
> buffer_size
)
157 return EFILE_TOO_BIG
;
159 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
161 rc
= read(fd
, &chksum
, 4);
162 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
164 return EREAD_CHKSUM_FAILED
;
166 printf("Checksum: %x", chksum
);
168 rc
= read(fd
, model
, 4);
170 return EREAD_MODEL_FAILED
;
174 printf("Model name: %s", model
);
175 printf("Loading %s", firmware
);
177 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
179 rc
= read(fd
, buf
, len
);
181 return EREAD_IMAGE_FAILED
;
187 for(i
= 0;i
< len
;i
++) {
191 printf("Sum: %x", sum
);
199 /* Load raw binary image. */
200 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
205 char filename
[MAX_PATH
];
207 snprintf(filename
,sizeof(filename
),"%s",firmware
);
208 fd
= open(filename
, O_RDONLY
);
211 return EFILE_NOT_FOUND
;
216 if (len
> buffer_size
)
217 return EFILE_TOO_BIG
;
219 rc
= read(fd
, buf
, len
);
221 return EREAD_IMAGE_FAILED
;
227 /* These functions are present in the firmware library, but we reimplement
228 them here because the originals do a lot more than we want */
229 void reset_poweroff_timer(void)
242 void sys_poweroff(void)