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"
39 /* TODO: Other bootloaders need to be adjusted to set this variable to true
40 on a button press - currently only the ipod, H10, Vibe 500 and Sansa versions do. */
41 #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined(IRIVER_H10_5GB) \
42 || defined(SANSA_E200) || defined(SANSA_C200) || defined(GIGABEAT_F) \
43 || (CONFIG_CPU == AS3525) || (CONFIG_CPU == AS3525v2) || defined(COWON_D2) \
44 || defined(MROBE_100) || defined(MROBE_500) \
45 || defined(SAMSUNG_YH925) || defined(SAMSUNG_YH920) \
46 || defined(SAMSUNG_YH820) || defined(PHILIPS_SA9200) \
47 || defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330) \
48 || defined(ONDA_VX747) || defined(PBELL_VIBE500)
55 #ifdef HAVE_REMOTE_LCD
61 void reset_screen(void)
65 #ifdef HAVE_REMOTE_LCD
66 lcd_remote_clear_display();
71 void printf(const char *format
, ...)
79 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
82 lcd_puts(0, line
++, ptr
);
85 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
87 #ifdef HAVE_REMOTE_LCD
88 lcd_remote_puts(0, remote_line
++, ptr
);
91 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
96 char *strerror(int error
)
102 case EFILE_NOT_FOUND
:
103 return "File not found";
104 case EREAD_CHKSUM_FAILED
:
105 return "Read failed (chksum)";
106 case EREAD_MODEL_FAILED
:
107 return "Read failed (model)";
108 case EREAD_IMAGE_FAILED
:
109 return "Read failed (image)";
111 return "Bad checksum";
113 return "File too big";
114 case EINVALID_FORMAT
:
115 return "Invalid file format";
121 void error(int errortype
, int error
, bool shutdown
)
126 printf("ATA error: %d", error
);
130 printf("No partition found");
134 printf(strerror(error
));
144 /* Load firmware image in a format created by tools/scramble */
145 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
150 unsigned long chksum
;
154 char filename
[MAX_PATH
];
156 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s",firmware
);
157 fd
= open(filename
, O_RDONLY
);
160 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
161 fd
= open(filename
, O_RDONLY
);
163 return EFILE_NOT_FOUND
;
166 len
= filesize(fd
) - 8;
168 printf("Length: %x", len
);
170 if (len
> buffer_size
)
171 return EFILE_TOO_BIG
;
173 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
175 rc
= read(fd
, &chksum
, 4);
176 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
178 return EREAD_CHKSUM_FAILED
;
180 printf("Checksum: %x", chksum
);
182 rc
= read(fd
, model
, 4);
184 return EREAD_MODEL_FAILED
;
188 printf("Model name: %s", model
);
189 printf("Loading %s", firmware
);
191 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
193 rc
= read(fd
, buf
, len
);
195 return EREAD_IMAGE_FAILED
;
201 for(i
= 0;i
< len
;i
++) {
205 printf("Sum: %x", sum
);
213 /* Load raw binary image. */
214 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
219 char filename
[MAX_PATH
];
221 snprintf(filename
,sizeof(filename
),"%s",firmware
);
222 fd
= open(filename
, O_RDONLY
);
225 return EFILE_NOT_FOUND
;
230 if (len
> buffer_size
)
231 return EFILE_TOO_BIG
;
233 rc
= read(fd
, buf
, len
);
235 return EREAD_IMAGE_FAILED
;
241 /* These functions are present in the firmware library, but we reimplement
242 them here because the originals do a lot more than we want */
252 #ifdef ROCKBOX_HAS_LOGF /* Logf display helper for the bootloader */
254 #define LINES (LCD_HEIGHT/SYSFONT_HEIGHT)
255 #define COLUMNS ((LCD_WIDTH/SYSFONT_WIDTH) > MAX_LOGF_ENTRY ? \
256 MAX_LOGF_ENTRY : (LCD_WIDTH/SYSFONT_WIDTH))
259 #define LOGF_UP BUTTON_VOL_UP
260 #define LOGF_DOWN BUTTON_VOL_DOWN
261 #define LOGF_CLEAR BUTTON_MENU
263 #warning No keymap defined for this target
266 void display_logf(void) /* Doesn't return! */
268 int i
, index
, button
, user_index
=0;
269 #ifdef HAVE_TOUCHSCREEN
272 char buffer
[COLUMNS
+1];
276 index
= logfindex
+ user_index
;
279 for(i
= LINES
-1; i
>=0; i
--)
284 index
= MAX_LOGF_LINES
-1;
289 memcpy(buffer
, logfbuffer
[index
], COLUMNS
);
291 if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_CONTINUE_LINE
)
292 buffer
[MAX_LOGF_ENTRY
-1] = '>';
293 else if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_MULTI_LINE
)
294 buffer
[MAX_LOGF_ENTRY
-1] = '\0';
296 buffer
[COLUMNS
] = '\0';
298 lcd_puts(0, i
, buffer
);
301 button
= button_get(false);
302 if(button
== SYS_USB_CONNECTED
)
303 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
304 else if(button
== SYS_USB_DISCONNECTED
)
305 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
306 else if(button
& LOGF_UP
)
308 else if(button
& LOGF_DOWN
)
310 else if(button
& LOGF_CLEAR
)
312 #ifdef HAVE_TOUCHSCREEN
313 else if(button
& BUTTON_TOUCHSCREEN
)
315 touch
= button_get_data();
317 if(button
& BUTTON_REL
)
321 user_index
+= (prev_y
- (touch
& 0xFFFF)) / SYSFONT_HEIGHT
;
322 prev_y
= touch
& 0xFFFF;