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 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "lcd-remote.h"
29 /* TODO: Other bootloaders need to be adjusted to set this variable to true
30 on a button press - currently only the ipod version does. */
38 #ifdef HAVE_REMOTE_LCD
44 void reset_screen(void)
48 #ifdef HAVE_REMOTE_LCD
49 lcd_remote_clear_display();
54 void printf(const char *format
, ...)
62 len
= vsnprintf(ptr
, sizeof(printfbuf
), format
, ap
);
65 lcd_puts(0, line
++, ptr
);
68 if(line
>= LCD_HEIGHT
/SYSFONT_HEIGHT
)
70 #ifdef HAVE_REMOTE_LCD
71 lcd_remote_puts(0, remote_line
++, ptr
);
74 if(remote_line
>= LCD_REMOTE_HEIGHT
/SYSFONT_HEIGHT
)
79 char *strerror(int error
)
86 return "File not found";
87 case EREAD_CHKSUM_FAILED
:
88 return "Read failed (chksum)";
89 case EREAD_MODEL_FAILED
:
90 return "Read failed (model)";
91 case EREAD_IMAGE_FAILED
:
92 return "Read failed (image)";
94 return "Bad checksum";
96 return "File too big";
102 /* Load firmware image in a format created by tools/scramble */
103 int load_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
108 unsigned long chksum
;
112 char filename
[MAX_PATH
];
114 snprintf(filename
,sizeof(filename
),"/.rockbox/%s",firmware
);
115 fd
= open(filename
, O_RDONLY
);
118 snprintf(filename
,sizeof(filename
),"/%s",firmware
);
119 fd
= open(filename
, O_RDONLY
);
121 return EFILE_NOT_FOUND
;
124 len
= filesize(fd
) - 8;
126 printf("Length: %x", len
);
128 if (len
> buffer_size
)
129 return EFILE_TOO_BIG
;
131 lseek(fd
, FIRMWARE_OFFSET_FILE_CRC
, SEEK_SET
);
133 rc
= read(fd
, &chksum
, 4);
134 chksum
=betoh32(chksum
); /* Rockbox checksums are big-endian */
136 return EREAD_CHKSUM_FAILED
;
138 printf("Checksum: %x", chksum
);
140 rc
= read(fd
, model
, 4);
142 return EREAD_MODEL_FAILED
;
146 printf("Model name: %s", model
);
147 printf("Loading %s", firmware
);
149 lseek(fd
, FIRMWARE_OFFSET_FILE_DATA
, SEEK_SET
);
151 rc
= read(fd
, buf
, len
);
153 return EREAD_IMAGE_FAILED
;
159 for(i
= 0;i
< len
;i
++) {
163 printf("Sum: %x", sum
);
171 /* Load raw binary image. */
172 int load_raw_firmware(unsigned char* buf
, char* firmware
, int buffer_size
)
177 char filename
[MAX_PATH
];
179 snprintf(filename
,sizeof(filename
),"%s",firmware
);
180 fd
= open(filename
, O_RDONLY
);
183 return EFILE_NOT_FOUND
;
188 if (len
> buffer_size
)
189 return EFILE_TOO_BIG
;
191 rc
= read(fd
, buf
, len
);
193 return EREAD_IMAGE_FAILED
;
199 /* These functions are present in the firmware library, but we reimplement
200 them here because the originals do a lot more than we want */
201 void reset_poweroff_timer(void)
214 void sys_poweroff(void)