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)
41 #ifdef HAVE_REMOTE_LCD
47 void reset_screen(void)
51 #ifdef HAVE_REMOTE_LCD
52 lcd_remote_clear_display();
57 void printf(const char *format
, ...)
65 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
68 lcd_puts(0, line
++, ptr
);
71 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
73 #ifdef HAVE_REMOTE_LCD
74 lcd_remote_puts(0, remote_line
++, ptr
);
77 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
82 char *strerror(int error
)
89 return "File not found";
90 case EREAD_CHKSUM_FAILED
:
91 return "Read failed (chksum)";
92 case EREAD_MODEL_FAILED
:
93 return "Read failed (model)";
94 case EREAD_IMAGE_FAILED
:
95 return "Read failed (image)";
97 return "Bad checksum";
99 return "File too big";
100 case EINVALID_FORMAT
:
101 return "Invalid file format";
107 void error(int errortype
, int error
)
112 printf("ATA error: %d", error
);
116 printf("No partition found");
120 printf(strerror(error
));
129 /* Load firmware image in a format created by tools/scramble */
130 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
135 unsigned long chksum
;
139 char filename
[MAX_PATH
];
141 snprintf(filename
,sizeof(filename
),"/.rockbox/%s",firmware
);
142 fd
= open(filename
, O_RDONLY
);
145 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
146 fd
= open(filename
, O_RDONLY
);
148 return EFILE_NOT_FOUND
;
151 len
= filesize(fd
) - 8;
153 printf("Length: %x", len
);
155 if (len
> buffer_size
)
156 return EFILE_TOO_BIG
;
158 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
160 rc
= read(fd
, &chksum
, 4);
161 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
163 return EREAD_CHKSUM_FAILED
;
165 printf("Checksum: %x", chksum
);
167 rc
= read(fd
, model
, 4);
169 return EREAD_MODEL_FAILED
;
173 printf("Model name: %s", model
);
174 printf("Loading %s", firmware
);
176 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
178 rc
= read(fd
, buf
, len
);
180 return EREAD_IMAGE_FAILED
;
186 for(i
= 0;i
< len
;i
++) {
190 printf("Sum: %x", sum
);
198 /* Load raw binary image. */
199 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
204 char filename
[MAX_PATH
];
206 snprintf(filename
,sizeof(filename
),"%s",firmware
);
207 fd
= open(filename
, O_RDONLY
);
210 return EFILE_NOT_FOUND
;
215 if (len
> buffer_size
)
216 return EFILE_TOO_BIG
;
218 rc
= read(fd
, buf
, len
);
220 return EREAD_IMAGE_FAILED
;
226 /* These functions are present in the firmware library, but we reimplement
227 them here because the originals do a lot more than we want */
228 void reset_poweroff_timer(void)
241 void sys_poweroff(void)