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) \
49 || defined(TOSHIBA_GIGABEAT_S)
56 #ifdef HAVE_REMOTE_LCD
62 void reset_screen(void)
66 #ifdef HAVE_REMOTE_LCD
67 lcd_remote_clear_display();
72 int printf(const char *format
, ...)
80 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
83 lcd_puts(0, line
++, ptr
);
86 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
88 #ifdef HAVE_REMOTE_LCD
89 lcd_remote_puts(0, remote_line
++, ptr
);
92 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
98 char *strerror(int error
)
104 case EFILE_NOT_FOUND
:
105 return "File not found";
106 case EREAD_CHKSUM_FAILED
:
107 return "Read failed (chksum)";
108 case EREAD_MODEL_FAILED
:
109 return "Read failed (model)";
110 case EREAD_IMAGE_FAILED
:
111 return "Read failed (image)";
113 return "Bad checksum";
115 return "File too big";
116 case EINVALID_FORMAT
:
117 return "Invalid file format";
123 void error(int errortype
, int error
, bool shutdown
)
128 printf("ATA error: %d", error
);
132 printf("No partition found");
136 printf(strerror(error
));
146 /* Load firmware image in a format created by tools/scramble */
147 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
152 unsigned long chksum
;
156 char filename
[MAX_PATH
];
158 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s",firmware
);
159 fd
= open(filename
, O_RDONLY
);
162 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
163 fd
= open(filename
, O_RDONLY
);
165 return EFILE_NOT_FOUND
;
168 len
= filesize(fd
) - 8;
170 printf("Length: %x", len
);
172 if (len
> buffer_size
)
173 return EFILE_TOO_BIG
;
175 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
177 rc
= read(fd
, &chksum
, 4);
178 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
180 return EREAD_CHKSUM_FAILED
;
182 printf("Checksum: %x", chksum
);
184 rc
= read(fd
, model
, 4);
186 return EREAD_MODEL_FAILED
;
190 printf("Model name: %s", model
);
191 printf("Loading %s", firmware
);
193 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
195 rc
= read(fd
, buf
, len
);
197 return EREAD_IMAGE_FAILED
;
203 for(i
= 0;i
< len
;i
++) {
207 printf("Sum: %x", sum
);
215 /* Load raw binary image. */
216 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
221 char filename
[MAX_PATH
];
223 snprintf(filename
,sizeof(filename
),"%s",firmware
);
224 fd
= open(filename
, O_RDONLY
);
227 return EFILE_NOT_FOUND
;
232 if (len
> buffer_size
)
233 return EFILE_TOO_BIG
;
235 rc
= read(fd
, buf
, len
);
237 return EREAD_IMAGE_FAILED
;
243 /* These functions are present in the firmware library, but we reimplement
244 them here because the originals do a lot more than we want */
254 #ifdef ROCKBOX_HAS_LOGF /* Logf display helper for the bootloader */
256 #define LINES (LCD_HEIGHT/SYSFONT_HEIGHT)
257 #define COLUMNS ((LCD_WIDTH/SYSFONT_WIDTH) > MAX_LOGF_ENTRY ? \
258 MAX_LOGF_ENTRY : (LCD_WIDTH/SYSFONT_WIDTH))
261 #define LOGF_UP BUTTON_VOL_UP
262 #define LOGF_DOWN BUTTON_VOL_DOWN
263 #define LOGF_CLEAR BUTTON_MENU
265 #warning No keymap defined for this target
268 void display_logf(void) /* Doesn't return! */
270 int i
, index
, button
, user_index
=0;
271 #ifdef HAVE_TOUCHSCREEN
274 char buffer
[COLUMNS
+1];
278 index
= logfindex
+ user_index
;
281 for(i
= LINES
-1; i
>=0; i
--)
286 index
= MAX_LOGF_LINES
-1;
291 memcpy(buffer
, logfbuffer
[index
], COLUMNS
);
293 if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_CONTINUE_LINE
)
294 buffer
[MAX_LOGF_ENTRY
-1] = '>';
295 else if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_MULTI_LINE
)
296 buffer
[MAX_LOGF_ENTRY
-1] = '\0';
298 buffer
[COLUMNS
] = '\0';
300 lcd_puts(0, i
, buffer
);
303 button
= button_get(false);
304 if(button
== SYS_USB_CONNECTED
)
305 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
306 else if(button
== SYS_USB_DISCONNECTED
)
308 else if(button
& LOGF_UP
)
310 else if(button
& LOGF_DOWN
)
312 else if(button
& LOGF_CLEAR
)
314 #ifdef HAVE_TOUCHSCREEN
315 else if(button
& BUTTON_TOUCHSCREEN
)
317 touch
= button_get_data();
319 if(button
& BUTTON_REL
)
323 user_index
+= (prev_y
- (touch
& 0xFFFF)) / SYSFONT_HEIGHT
;
324 prev_y
= touch
& 0xFFFF;