summaryrefslogtreecommitdiff
path: root/bootloader/common.c
diff options
context:
space:
mode:
authorBarry Wardell <rockbox@barrywardell.net>2007-01-28 18:42:11 +0000
committerBarry Wardell <rockbox@barrywardell.net>2007-01-28 18:42:11 +0000
commit84b509dc43cf84ef16fcd4a57b167351f146cd11 (patch)
tree57eca4b44db56e11c1a3d9dde5d0e4ef8e830686 /bootloader/common.c
parent6c3a44643590f8cbc925375c2dc8393cc7f9d55e (diff)
downloadrockbox-84b509dc43cf84ef16fcd4a57b167351f146cd11.tar.gz
rockbox-84b509dc43cf84ef16fcd4a57b167351f146cd11.zip
FS#6554. Move bootloader code into a common file. Only PortalPlayer devices (iPods, H10, Sansa) are affected for the moment. Someone with access to (and no fear of bricking) an X5, H100, H300 and Gigabeat should try to adapt those bootloaders to also use the code in common.c. The (non-working) patch in the tracker would be a good place to start with this.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12136 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'bootloader/common.c')
-rw-r--r--bootloader/common.c205
1 files changed, 205 insertions, 0 deletions
diff --git a/bootloader/common.c b/bootloader/common.c
new file mode 100644
index 0000000000..410fd42cd8
--- /dev/null
+++ b/bootloader/common.c
@@ -0,0 +1,205 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: main.c 11997 2007-01-13 09:08:18Z miipekk $
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "lcd.h"
20#include "lcd-remote.h"
21#include "font.h"
22#include "system.h"
23#include <stdarg.h>
24#include <stdio.h>
25#include "cpu.h"
26#include "common.h"
27
28int line = 0;
29#ifdef HAVE_REMOTE_LCD
30int remote_line = 0;
31#endif
32
33char printfbuf[256];
34
35void reset_screen(void)
36{
37 lcd_clear_display();
38 line = 0;
39#ifdef HAVE_REMOTE_LCD
40 lcd_remote_clear_display();
41 remote_line = 0;
42#endif
43}
44
45void printf(const char *format, ...)
46{
47 int len;
48 unsigned char *ptr;
49 va_list ap;
50 va_start(ap, format);
51
52 ptr = printfbuf;
53 len = vsnprintf(ptr, sizeof(printfbuf), format, ap);
54 va_end(ap);
55
56 lcd_puts(0, line++, ptr);
57 lcd_update();
58 if(line >= LCD_HEIGHT/SYSFONT_HEIGHT)
59 line = 0;
60#ifdef HAVE_REMOTE_LCD
61 lcd_remote_puts(0, remote_line++, ptr);
62 lcd_remote_update();
63 if(remote_line >= LCD_REMOTE_HEIGHT/SYSFONT_HEIGHT)
64 remote_line = 0;
65#endif
66}
67
68char *strerror(int error)
69{
70 switch(error)
71 {
72 case EOK:
73 return "OK";
74 case EFILE_NOT_FOUND:
75 return "File not found";
76 case EREAD_CHKSUM_FAILED:
77 return "Read failed (chksum)";
78 case EREAD_MODEL_FAILED:
79 return "Read failed (model)";
80 case EREAD_IMAGE_FAILED:
81 return "Read failed (image)";
82 case EBAD_CHKSUM:
83 return "Bad checksum";
84 case EFILE_TOO_BIG:
85 return "File too big";
86 default:
87 return "Unknown";
88 }
89}
90
91/* Load firmware image in a format created by tools/scramble */
92int load_firmware(unsigned char* buf, char* firmware, int buffer_size)
93{
94 int fd;
95 int rc;
96 int len;
97 unsigned long chksum;
98 char model[5];
99 unsigned long sum;
100 int i;
101 char filename[MAX_PATH];
102
103 snprintf(filename,sizeof(filename),"/.rockbox/%s",firmware);
104 fd = open(filename, O_RDONLY);
105 if(fd < 0)
106 {
107 snprintf(filename,sizeof(filename),"/%s",firmware);
108 fd = open(filename, O_RDONLY);
109 if(fd < 0)
110 return EFILE_NOT_FOUND;
111 }
112
113 len = filesize(fd) - 8;
114
115 printf("Length: %x", len);
116
117 if (len > buffer_size)
118 return EFILE_TOO_BIG;
119
120 lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
121
122 rc = read(fd, &chksum, 4);
123 chksum=betoh32(chksum); /* Rockbox checksums are big-endian */
124 if(rc < 4)
125 return EREAD_CHKSUM_FAILED;
126
127 printf("Checksum: %x", chksum);
128
129 rc = read(fd, model, 4);
130 if(rc < 4)
131 return EREAD_MODEL_FAILED;
132
133 model[4] = 0;
134
135 printf("Model name: %s", model);
136 printf("Loading %s", firmware);
137
138 lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
139
140 rc = read(fd, buf, len);
141 if(rc < len)
142 return EREAD_IMAGE_FAILED;
143
144 close(fd);
145
146 sum = MODEL_NUMBER;
147
148 for(i = 0;i < len;i++) {
149 sum += buf[i];
150 }
151
152 printf("Sum: %x", sum);
153
154 if(sum != chksum)
155 return EBAD_CHKSUM;
156
157 return len;
158}
159
160/* Load raw binary image. */
161int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size)
162{
163 int fd;
164 int rc;
165 int len;
166 char filename[MAX_PATH];
167
168 snprintf(filename,sizeof(filename),"%s",firmware);
169 fd = open(filename, O_RDONLY);
170 if(fd < 0)
171 {
172 return EFILE_NOT_FOUND;
173 }
174
175 len = filesize(fd);
176
177 if (len > buffer_size)
178 return EFILE_TOO_BIG;
179
180 rc = read(fd, buf, len);
181 if(rc < len)
182 return EREAD_IMAGE_FAILED;
183
184 close(fd);
185 return len;
186}
187
188/* These functions are present in the firmware library, but we reimplement
189 them here because the originals do a lot more than we want */
190void reset_poweroff_timer(void)
191{
192}
193
194int dbg_ports(void)
195{
196 return 0;
197}
198
199void mpeg_stop(void)
200{
201}
202
203void sys_poweroff(void)
204{
205}