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"
38 /* TODO: Other bootloaders need to be adjusted to set this variable to true
39 on a button press - currently only the ipod, H10 and Sansa versions do. */
40 #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined(IRIVER_H10_5GB) \
41 || defined(SANSA_E200) || defined(SANSA_C200) || defined(GIGABEAT_F) \
42 || defined(PHILIPS_SA9200) || (CONFIG_CPU == AS3525) || defined(COWON_D2) \
43 || defined(MROBE_100) || defined(PHILIPS_HDD1630) || defined(ONDA_VX747) \
51 #ifdef HAVE_REMOTE_LCD
57 void reset_screen(void)
61 #ifdef HAVE_REMOTE_LCD
62 lcd_remote_clear_display();
67 void printf(const char *format
, ...)
75 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
78 lcd_puts(0, line
++, ptr
);
81 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
83 #ifdef HAVE_REMOTE_LCD
84 lcd_remote_puts(0, remote_line
++, ptr
);
87 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
92 char *strerror(int error
)
99 return "File not found";
100 case EREAD_CHKSUM_FAILED
:
101 return "Read failed (chksum)";
102 case EREAD_MODEL_FAILED
:
103 return "Read failed (model)";
104 case EREAD_IMAGE_FAILED
:
105 return "Read failed (image)";
107 return "Bad checksum";
109 return "File too big";
110 case EINVALID_FORMAT
:
111 return "Invalid file format";
117 void error(int errortype
, int error
)
122 printf("ATA error: %d", error
);
126 printf("No partition found");
130 printf(strerror(error
));
139 /* Load firmware image in a format created by tools/scramble */
140 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
145 unsigned long chksum
;
149 char filename
[MAX_PATH
];
151 snprintf(filename
,sizeof(filename
), BOOTDIR
"/%s",firmware
);
152 fd
= open(filename
, O_RDONLY
);
155 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
156 fd
= open(filename
, O_RDONLY
);
158 return EFILE_NOT_FOUND
;
161 len
= filesize(fd
) - 8;
163 printf("Length: %x", len
);
165 if (len
> buffer_size
)
166 return EFILE_TOO_BIG
;
168 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
170 rc
= read(fd
, &chksum
, 4);
171 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
173 return EREAD_CHKSUM_FAILED
;
175 printf("Checksum: %x", chksum
);
177 rc
= read(fd
, model
, 4);
179 return EREAD_MODEL_FAILED
;
183 printf("Model name: %s", model
);
184 printf("Loading %s", firmware
);
186 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
188 rc
= read(fd
, buf
, len
);
190 return EREAD_IMAGE_FAILED
;
196 for(i
= 0;i
< len
;i
++) {
200 printf("Sum: %x", sum
);
208 /* Load raw binary image. */
209 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
214 char filename
[MAX_PATH
];
216 snprintf(filename
,sizeof(filename
),"%s",firmware
);
217 fd
= open(filename
, O_RDONLY
);
220 return EFILE_NOT_FOUND
;
225 if (len
> buffer_size
)
226 return EFILE_TOO_BIG
;
228 rc
= read(fd
, buf
, len
);
230 return EREAD_IMAGE_FAILED
;
236 /* These functions are present in the firmware library, but we reimplement
237 them here because the originals do a lot more than we want */
247 #ifdef ROCKBOX_HAS_LOGF /* Logf display helper for the bootloader */
249 #define LINES (LCD_HEIGHT/SYSFONT_HEIGHT)
250 #define COLUMNS ((LCD_WIDTH/SYSFONT_WIDTH) > MAX_LOGF_ENTRY ? \
251 MAX_LOGF_ENTRY : (LCD_WIDTH/SYSFONT_WIDTH))
254 #define LOGF_UP BUTTON_VOL_UP
255 #define LOGF_DOWN BUTTON_VOL_DOWN
256 #define LOGF_CLEAR BUTTON_MENU
258 #warning No keymap defined for this target
261 void display_logf(void) /* Doesn't return! */
263 int i
, index
, button
, user_index
=0;
264 #ifdef HAVE_TOUCHSCREEN
267 char buffer
[COLUMNS
+1];
271 index
= logfindex
+ user_index
;
274 for(i
= LINES
-1; i
>=0; i
--)
279 index
= MAX_LOGF_LINES
-1;
284 memcpy(buffer
, logfbuffer
[index
], COLUMNS
);
286 if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_CONTINUE_LINE
)
287 buffer
[MAX_LOGF_ENTRY
-1] = '>';
288 else if (logfbuffer
[index
][MAX_LOGF_ENTRY
] == LOGF_TERMINATE_MULTI_LINE
)
289 buffer
[MAX_LOGF_ENTRY
-1] = '\0';
291 buffer
[COLUMNS
] = '\0';
293 lcd_puts(0, i
, buffer
);
296 button
= button_get(false);
297 if(button
== SYS_USB_CONNECTED
)
298 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
299 else if(button
== SYS_USB_DISCONNECTED
)
300 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
301 else if(button
& LOGF_UP
)
303 else if(button
& LOGF_DOWN
)
305 else if(button
& LOGF_CLEAR
)
307 #ifdef HAVE_TOUCHSCREEN
308 else if(button
& BUTTON_TOUCHSCREEN
)
310 touch
= button_get_data();
312 if(button
& BUTTON_REL
)
316 user_index
+= (prev_y
- (touch
& 0xFFFF)) / SYSFONT_HEIGHT
;
317 prev_y
= touch
& 0xFFFF;