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 int 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
)
97 char *strerror(int error
)
103 case EFILE_NOT_FOUND
:
104 return "File not found";
105 case EREAD_CHKSUM_FAILED
:
106 return "Read failed (chksum)";
107 case EREAD_MODEL_FAILED
:
108 return "Read failed (model)";
109 case EREAD_IMAGE_FAILED
:
110 return "Read failed (image)";
112 return "Bad checksum";
114 return "File too big";
115 case EINVALID_FORMAT
:
116 return "Invalid file format";
122 void error(int errortype
, int error
, bool shutdown
)
127 printf("ATA error: %d", error
);
131 printf("No partition found");
135 printf(strerror(error
));
145 /* Load firmware image in a format created by tools/scramble */
146 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
151 unsigned long chksum
;
155 char filename
[MAX_PATH
];
157 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s",firmware
);
158 fd
= open(filename
, O_RDONLY
);
161 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
162 fd
= open(filename
, O_RDONLY
);
164 return EFILE_NOT_FOUND
;
167 len
= filesize(fd
) - 8;
169 printf("Length: %x", len
);
171 if (len
> buffer_size
)
172 return EFILE_TOO_BIG
;
174 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
176 rc
= read(fd
, &chksum
, 4);
177 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
179 return EREAD_CHKSUM_FAILED
;
181 printf("Checksum: %x", chksum
);
183 rc
= read(fd
, model
, 4);
185 return EREAD_MODEL_FAILED
;
189 printf("Model name: %s", model
);
190 printf("Loading %s", firmware
);
192 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
194 rc
= read(fd
, buf
, len
);
196 return EREAD_IMAGE_FAILED
;
202 for(i
= 0;i
< len
;i
++) {
206 printf("Sum: %x", sum
);
214 /* Load raw binary image. */
215 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
220 char filename
[MAX_PATH
];
222 snprintf(filename
,sizeof(filename
),"%s",firmware
);
223 fd
= open(filename
, O_RDONLY
);
226 return EFILE_NOT_FOUND
;
231 if (len
> buffer_size
)
232 return EFILE_TOO_BIG
;
234 rc
= read(fd
, buf
, len
);
236 return EREAD_IMAGE_FAILED
;
242 /* These functions are present in the firmware library, but we reimplement
243 them here because the originals do a lot more than we want */
253 #ifdef ROCKBOX_HAS_LOGF /* Logf display helper for the bootloader */
255 #define LINES (LCD_HEIGHT/SYSFONT_HEIGHT)
256 #define COLUMNS ((LCD_WIDTH/SYSFONT_WIDTH) > MAX_LOGF_ENTRY ? \
257 MAX_LOGF_ENTRY : (LCD_WIDTH/SYSFONT_WIDTH))
260 #define LOGF_UP BUTTON_VOL_UP
261 #define LOGF_DOWN BUTTON_VOL_DOWN
262 #define LOGF_CLEAR BUTTON_MENU
264 #warning No keymap defined for this target
267 void display_logf(void) /* Doesn't return! */
269 int i
, index
, button
, user_index
=0;
270 #ifdef HAVE_TOUCHSCREEN
273 char buffer
[COLUMNS
+1];
277 index
= logfindex
+ user_index
;
280 for(i
= LINES
-1; i
>=0; i
--)
285 index
= MAX_LOGF_LINES
-1;
290 memcpy(buffer
, logfbuffer
[index
], COLUMNS
);
292 if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_CONTINUE_LINE
)
293 buffer
[MAX_LOGF_ENTRY
-1] = '>';
294 else if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_MULTI_LINE
)
295 buffer
[MAX_LOGF_ENTRY
-1] = '\0';
297 buffer
[COLUMNS
] = '\0';
299 lcd_puts(0, i
, buffer
);
302 button
= button_get(false);
303 if(button
== SYS_USB_CONNECTED
)
304 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
305 else if(button
== SYS_USB_DISCONNECTED
)
306 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
307 else if(button
& LOGF_UP
)
309 else if(button
& LOGF_DOWN
)
311 else if(button
& LOGF_CLEAR
)
313 #ifdef HAVE_TOUCHSCREEN
314 else if(button
& BUTTON_TOUCHSCREEN
)
316 touch
= button_get_data();
318 if(button
& BUTTON_REL
)
322 user_index
+= (prev_y
- (touch
& 0xFFFF)) / SYSFONT_HEIGHT
;
323 prev_y
= touch
& 0xFFFF;