summaryrefslogtreecommitdiffstats
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.tar.bz2
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 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id: main.c 11997 2007-01-13 09:08:18Z miipekk $
+ *
+ * Copyright (C) 2005 by Linus Nielsen Feltzing
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "lcd.h"
+#include "lcd-remote.h"
+#include "font.h"
+#include "system.h"
+#include <stdarg.h>
+#include <stdio.h>
+#include "cpu.h"
+#include "common.h"
+
+int line = 0;
+#ifdef HAVE_REMOTE_LCD
+int remote_line = 0;
+#endif
+
+char printfbuf[256];
+
+void reset_screen(void)
+{
+ lcd_clear_display();
+ line = 0;
+#ifdef HAVE_REMOTE_LCD
+ lcd_remote_clear_display();
+ remote_line = 0;
+#endif
+}
+
+void printf(const char *format, ...)
+{
+ int len;
+ unsigned char *ptr;
+ va_list ap;
+ va_start(ap, format);
+
+ ptr = printfbuf;
+ len = vsnprintf(ptr, sizeof(printfbuf), format, ap);
+ va_end(ap);
+
+ lcd_puts(0, line++, ptr);
+ lcd_update();
+ if(line >= LCD_HEIGHT/SYSFONT_HEIGHT)
+ line = 0;
+#ifdef HAVE_REMOTE_LCD
+ lcd_remote_puts(0, remote_line++, ptr);
+ lcd_remote_update();
+ if(remote_line >= LCD_REMOTE_HEIGHT/SYSFONT_HEIGHT)
+ remote_line = 0;
+#endif
+}
+
+char *strerror(int error)
+{
+ switch(error)
+ {
+ case EOK:
+ return "OK";
+ case EFILE_NOT_FOUND:
+ return "File not found";
+ case EREAD_CHKSUM_FAILED:
+ return "Read failed (chksum)";
+ case EREAD_MODEL_FAILED:
+ return "Read failed (model)";
+ case EREAD_IMAGE_FAILED:
+ return "Read failed (image)";
+ case EBAD_CHKSUM:
+ return "Bad checksum";
+ case EFILE_TOO_BIG:
+ return "File too big";
+ default:
+ return "Unknown";
+ }
+}
+
+/* Load firmware image in a format created by tools/scramble */
+int load_firmware(unsigned char* buf, char* firmware, int buffer_size)
+{
+ int fd;
+ int rc;
+ int len;
+ unsigned long chksum;
+ char model[5];
+ unsigned long sum;
+ int i;
+ char filename[MAX_PATH];
+
+ snprintf(filename,sizeof(filename),"/.rockbox/%s",firmware);
+ fd = open(filename, O_RDONLY);
+ if(fd < 0)
+ {
+ snprintf(filename,sizeof(filename),"/%s",firmware);
+ fd = open(filename, O_RDONLY);
+ if(fd < 0)
+ return EFILE_NOT_FOUND;
+ }
+
+ len = filesize(fd) - 8;
+
+ printf("Length: %x", len);
+
+ if (len > buffer_size)
+ return EFILE_TOO_BIG;
+
+ lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET);
+
+ rc = read(fd, &chksum, 4);
+ chksum=betoh32(chksum); /* Rockbox checksums are big-endian */
+ if(rc < 4)
+ return EREAD_CHKSUM_FAILED;
+
+ printf("Checksum: %x", chksum);
+
+ rc = read(fd, model, 4);
+ if(rc < 4)
+ return EREAD_MODEL_FAILED;
+
+ model[4] = 0;
+
+ printf("Model name: %s", model);
+ printf("Loading %s", firmware);
+
+ lseek(fd, FIRMWARE_OFFSET_FILE_DATA, SEEK_SET);
+
+ rc = read(fd, buf, len);
+ if(rc < len)
+ return EREAD_IMAGE_FAILED;
+
+ close(fd);
+
+ sum = MODEL_NUMBER;
+
+ for(i = 0;i < len;i++) {
+ sum += buf[i];
+ }
+
+ printf("Sum: %x", sum);
+
+ if(sum != chksum)
+ return EBAD_CHKSUM;
+
+ return len;
+}
+
+/* Load raw binary image. */
+int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size)
+{
+ int fd;
+ int rc;
+ int len;
+ char filename[MAX_PATH];
+
+ snprintf(filename,sizeof(filename),"%s",firmware);
+ fd = open(filename, O_RDONLY);
+ if(fd < 0)
+ {
+ return EFILE_NOT_FOUND;
+ }
+
+ len = filesize(fd);
+
+ if (len > buffer_size)
+ return EFILE_TOO_BIG;
+
+ rc = read(fd, buf, len);
+ if(rc < len)
+ return EREAD_IMAGE_FAILED;
+
+ close(fd);
+ return len;
+}
+
+/* These functions are present in the firmware library, but we reimplement
+ them here because the originals do a lot more than we want */
+void reset_poweroff_timer(void)
+{
+}
+
+int dbg_ports(void)
+{
+ return 0;
+}
+
+void mpeg_stop(void)
+{
+}
+
+void sys_poweroff(void)
+{
+}