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 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 || defined(PHILIPS_SA9200) || (CONFIG_CPU == AS3525) || defined(COWON_D2) \
44 || defined(MROBE_100) || defined(PHILIPS_HDD1630) || defined(MROBE_500) \
45 || defined(ONDA_VX747)
52 #ifdef HAVE_REMOTE_LCD
58 void reset_screen(void)
62 #ifdef HAVE_REMOTE_LCD
63 lcd_remote_clear_display();
68 void printf(const char *format
, ...)
76 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
79 lcd_puts(0, line
++, ptr
);
82 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
84 #ifdef HAVE_REMOTE_LCD
85 lcd_remote_puts(0, remote_line
++, ptr
);
88 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
93 char *strerror(int error
)
100 return "File not found";
101 case EREAD_CHKSUM_FAILED
:
102 return "Read failed (chksum)";
103 case EREAD_MODEL_FAILED
:
104 return "Read failed (model)";
105 case EREAD_IMAGE_FAILED
:
106 return "Read failed (image)";
108 return "Bad checksum";
110 return "File too big";
111 case EINVALID_FORMAT
:
112 return "Invalid file format";
118 void error(int errortype
, int error
)
123 printf("ATA error: %d", error
);
127 printf("No partition found");
131 printf(strerror(error
));
140 /* Load firmware image in a format created by tools/scramble */
141 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
146 unsigned long chksum
;
150 char filename
[MAX_PATH
];
152 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s",firmware
);
153 fd
= open(filename
, O_RDONLY
);
156 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
157 fd
= open(filename
, O_RDONLY
);
159 return EFILE_NOT_FOUND
;
162 len
= filesize(fd
) - 8;
164 printf("Length: %x", len
);
166 if (len
> buffer_size
)
167 return EFILE_TOO_BIG
;
169 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
171 rc
= read(fd
, &chksum
, 4);
172 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
174 return EREAD_CHKSUM_FAILED
;
176 printf("Checksum: %x", chksum
);
178 rc
= read(fd
, model
, 4);
180 return EREAD_MODEL_FAILED
;
184 printf("Model name: %s", model
);
185 printf("Loading %s", firmware
);
187 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
189 rc
= read(fd
, buf
, len
);
191 return EREAD_IMAGE_FAILED
;
197 for(i
= 0;i
< len
;i
++) {
201 printf("Sum: %x", sum
);
209 /* Load raw binary image. */
210 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
215 char filename
[MAX_PATH
];
217 snprintf(filename
,sizeof(filename
),"%s",firmware
);
218 fd
= open(filename
, O_RDONLY
);
221 return EFILE_NOT_FOUND
;
226 if (len
> buffer_size
)
227 return EFILE_TOO_BIG
;
229 rc
= read(fd
, buf
, len
);
231 return EREAD_IMAGE_FAILED
;
237 /* These functions are present in the firmware library, but we reimplement
238 them here because the originals do a lot more than we want */
248 #ifdef ROCKBOX_HAS_LOGF /* Logf display helper for the bootloader */
250 #define LINES (LCD_HEIGHT/SYSFONT_HEIGHT)
251 #define COLUMNS ((LCD_WIDTH/SYSFONT_WIDTH) > MAX_LOGF_ENTRY ? \
252 MAX_LOGF_ENTRY : (LCD_WIDTH/SYSFONT_WIDTH))
255 #define LOGF_UP BUTTON_VOL_UP
256 #define LOGF_DOWN BUTTON_VOL_DOWN
257 #define LOGF_CLEAR BUTTON_MENU
259 #warning No keymap defined for this target
262 void display_logf(void) /* Doesn't return! */
264 int i
, index
, button
, user_index
=0;
265 #ifdef HAVE_TOUCHSCREEN
268 char buffer
[COLUMNS
+1];
272 index
= logfindex
+ user_index
;
275 for(i
= LINES
-1; i
>=0; i
--)
280 index
= MAX_LOGF_LINES
-1;
285 memcpy(buffer
, logfbuffer
[index
], COLUMNS
);
287 if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_CONTINUE_LINE
)
288 buffer
[MAX_LOGF_ENTRY
-1] = '>';
289 else if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_MULTI_LINE
)
290 buffer
[MAX_LOGF_ENTRY
-1] = '\0';
292 buffer
[COLUMNS
] = '\0';
294 lcd_puts(0, i
, buffer
);
297 button
= button_get(false);
298 if(button
== SYS_USB_CONNECTED
)
299 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
300 else if(button
== SYS_USB_DISCONNECTED
)
301 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
302 else if(button
& LOGF_UP
)
304 else if(button
& LOGF_DOWN
)
306 else if(button
& LOGF_CLEAR
)
308 #ifdef HAVE_TOUCHSCREEN
309 else if(button
& BUTTON_TOUCHSCREEN
)
311 touch
= button_get_data();
313 if(button
& BUTTON_REL
)
317 user_index
+= (prev_y
- (touch
& 0xFFFF)) / SYSFONT_HEIGHT
;
318 prev_y
= touch
& 0xFFFF;