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 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "lcd-remote.h"
33 /* TODO: Other bootloaders need to be adjusted to set this variable to true
34 on a button press - currently only the ipod, H10 and Sansa versions do. */
35 #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined(IRIVER_H10_5GB) \
36 || defined(SANSA_E200) || defined(SANSA_C200) || defined(GIGABEAT_F) \
37 || defined(PHILIPS_SA9200)
44 #ifdef HAVE_REMOTE_LCD
50 void reset_screen(void)
54 #ifdef HAVE_REMOTE_LCD
55 lcd_remote_clear_display();
60 void printf(const char *format
, ...)
68 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
71 lcd_puts(0, line
++, ptr
);
74 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
76 #ifdef HAVE_REMOTE_LCD
77 lcd_remote_puts(0, remote_line
++, ptr
);
80 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
85 char *strerror(int error
)
92 return "File not found";
93 case EREAD_CHKSUM_FAILED
:
94 return "Read failed (chksum)";
95 case EREAD_MODEL_FAILED
:
96 return "Read failed (model)";
97 case EREAD_IMAGE_FAILED
:
98 return "Read failed (image)";
100 return "Bad checksum";
102 return "File too big";
103 case EINVALID_FORMAT
:
104 return "Invalid file format";
110 void error(int errortype
, int error
)
115 printf("ATA error: %d", error
);
119 printf("No partition found");
123 printf(strerror(error
));
132 /* Load firmware image in a format created by tools/scramble */
133 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
138 unsigned long chksum
;
142 char filename
[MAX_PATH
];
144 snprintf(filename
,sizeof(filename
),"/.rockbox/%s",firmware
);
145 fd
= open(filename
, O_RDONLY
);
148 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
149 fd
= open(filename
, O_RDONLY
);
151 return EFILE_NOT_FOUND
;
154 len
= filesize(fd
) - 8;
156 printf("Length: %x", len
);
158 if (len
> buffer_size
)
159 return EFILE_TOO_BIG
;
161 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
163 rc
= read(fd
, &chksum
, 4);
164 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
166 return EREAD_CHKSUM_FAILED
;
168 printf("Checksum: %x", chksum
);
170 rc
= read(fd
, model
, 4);
172 return EREAD_MODEL_FAILED
;
176 printf("Model name: %s", model
);
177 printf("Loading %s", firmware
);
179 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
181 rc
= read(fd
, buf
, len
);
183 return EREAD_IMAGE_FAILED
;
189 for(i
= 0;i
< len
;i
++) {
193 printf("Sum: %x", sum
);
201 /* Load raw binary image. */
202 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
207 char filename
[MAX_PATH
];
209 snprintf(filename
,sizeof(filename
),"%s",firmware
);
210 fd
= open(filename
, O_RDONLY
);
213 return EFILE_NOT_FOUND
;
218 if (len
> buffer_size
)
219 return EFILE_TOO_BIG
;
221 rc
= read(fd
, buf
, len
);
223 return EREAD_IMAGE_FAILED
;
229 /* These functions are present in the firmware library, but we reimplement
230 them here because the originals do a lot more than we want */
231 void reset_poweroff_timer(void)
244 void sys_poweroff(void)