Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 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 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 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. |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #include "lcd.h" |
| 22 | #include "lcd-remote.h" |
| 23 | #include "font.h" |
| 24 | #include "system.h" |
| 25 | #include <stdarg.h> |
| 26 | #include <stdio.h> |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 27 | #include <stdbool.h> |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 28 | #include "cpu.h" |
| 29 | #include "common.h" |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame] | 30 | #include "power.h" |
| 31 | #include "kernel.h" |
Björn Stenberg | b69be10 | 2008-11-23 22:07:48 +0000 | [diff] [blame] | 32 | #include "config.h" |
Maurus Cuelenaere | c33209e | 2009-02-07 13:52:03 +0000 | [diff] [blame] | 33 | #include "logf.h" |
| 34 | #include "button.h" |
| 35 | #include "string.h" |
| 36 | #include "usb.h" |
Nils Wallménius | 47608e0 | 2009-08-19 22:15:45 +0000 | [diff] [blame] | 37 | #include "file.h" |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 38 | #include "loader_strerror.h" |
| 39 | #if defined(MI4_FORMAT) |
| 40 | #include "mi4-loader.h" |
| 41 | #elif defined(RKW_FORMAT) |
| 42 | #include "rkw-loader.h" |
| 43 | #else |
| 44 | #include "rb-loader.h" |
| 45 | #endif |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 46 | |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 47 | /* TODO: Other bootloaders need to be adjusted to set this variable to true |
Szymon Dziok | 492fafe | 2010-03-23 21:28:25 +0000 | [diff] [blame] | 48 | on a button press - currently only the ipod, H10, Vibe 500 and Sansa versions do. */ |
Jens Arnold | c41470d | 2007-09-12 22:21:03 +0000 | [diff] [blame] | 49 | #if defined(IPOD_ARCH) || defined(IRIVER_H10) || defined(IRIVER_H10_5GB) \ |
Mark Arigo | b4275d4 | 2008-05-21 03:55:17 +0000 | [diff] [blame] | 50 | || defined(SANSA_E200) || defined(SANSA_C200) || defined(GIGABEAT_F) \ |
Rafaël Carré | dee432f | 2010-03-28 04:10:40 +0000 | [diff] [blame] | 51 | || (CONFIG_CPU == AS3525) || (CONFIG_CPU == AS3525v2) || defined(COWON_D2) \ |
Mark Arigo | 6908cc5 | 2009-12-25 04:05:01 +0000 | [diff] [blame] | 52 | || defined(MROBE_100) || defined(MROBE_500) \ |
| 53 | || defined(SAMSUNG_YH925) || defined(SAMSUNG_YH920) \ |
| 54 | || defined(SAMSUNG_YH820) || defined(PHILIPS_SA9200) \ |
| 55 | || defined(PHILIPS_HDD1630) || defined(PHILIPS_HDD6330) \ |
Michael Sevakis | 863c03f | 2011-01-21 07:05:51 +0000 | [diff] [blame] | 56 | || defined(ONDA_VX747) || defined(PBELL_VIBE500) \ |
Solomon Peachy | d4942cc | 2018-06-29 16:09:28 -0400 | [diff] [blame] | 57 | || defined(TOSHIBA_GIGABEAT_S) || defined(XDUOO_X3) \ |
| 58 | || defined(IHIFI770) || defined(IHIFI770C) || defined(IHIFI800) |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 59 | bool verbose = false; |
| 60 | #else |
| 61 | bool verbose = true; |
| 62 | #endif |
| 63 | |
Amaury Pouly | 1d121e8 | 2017-02-23 11:33:19 +0100 | [diff] [blame] | 64 | #if !(CONFIG_PLATFORM & PLATFORM_HOSTED) |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 65 | int line = 0; |
| 66 | #ifdef HAVE_REMOTE_LCD |
| 67 | int remote_line = 0; |
| 68 | #endif |
| 69 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 70 | void reset_screen(void) |
| 71 | { |
| 72 | lcd_clear_display(); |
| 73 | line = 0; |
| 74 | #ifdef HAVE_REMOTE_LCD |
| 75 | lcd_remote_clear_display(); |
| 76 | remote_line = 0; |
| 77 | #endif |
| 78 | } |
| 79 | |
Thomas Martitz | 240923a | 2010-08-02 20:34:47 +0000 | [diff] [blame] | 80 | int printf(const char *format, ...) |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 81 | { |
Rafaël Carré | e595582 | 2011-07-02 02:49:15 +0000 | [diff] [blame] | 82 | static char printfbuf[256]; |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 83 | int len; |
| 84 | unsigned char *ptr; |
| 85 | va_list ap; |
| 86 | va_start(ap, format); |
| 87 | |
| 88 | ptr = printfbuf; |
| 89 | len = vsnprintf(ptr, sizeof(printfbuf), format, ap); |
| 90 | va_end(ap); |
| 91 | |
| 92 | lcd_puts(0, line++, ptr); |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 93 | if (verbose) |
| 94 | lcd_update(); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 95 | if(line >= LCD_HEIGHT/SYSFONT_HEIGHT) |
| 96 | line = 0; |
| 97 | #ifdef HAVE_REMOTE_LCD |
| 98 | lcd_remote_puts(0, remote_line++, ptr); |
Dave Chapman | 4d25bff | 2007-03-05 23:56:28 +0000 | [diff] [blame] | 99 | if (verbose) |
| 100 | lcd_remote_update(); |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 101 | if(remote_line >= LCD_REMOTE_HEIGHT/SYSFONT_HEIGHT) |
| 102 | remote_line = 0; |
| 103 | #endif |
Thomas Martitz | 240923a | 2010-08-02 20:34:47 +0000 | [diff] [blame] | 104 | return len; |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 105 | } |
Amaury Pouly | 1d121e8 | 2017-02-23 11:33:19 +0100 | [diff] [blame] | 106 | #endif |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 107 | |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 108 | void error(int errortype, int error, bool shutdown) |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame] | 109 | { |
| 110 | switch(errortype) |
| 111 | { |
| 112 | case EATA: |
| 113 | printf("ATA error: %d", error); |
| 114 | break; |
| 115 | |
| 116 | case EDISK: |
| 117 | printf("No partition found"); |
| 118 | break; |
| 119 | |
| 120 | case EBOOTFILE: |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 121 | printf(loader_strerror(error)); |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame] | 122 | break; |
| 123 | } |
| 124 | |
| 125 | lcd_update(); |
| 126 | sleep(5*HZ); |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 127 | |
Rafaël Carré | 1ec8212 | 2010-06-23 05:08:36 +0000 | [diff] [blame] | 128 | if(shutdown) |
| 129 | power_off(); |
Barry Wardell | 2370998 | 2007-03-12 22:12:20 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Barry Wardell | 84b509d | 2007-01-28 18:42:11 +0000 | [diff] [blame] | 132 | /* Load raw binary image. */ |
| 133 | int load_raw_firmware(unsigned char* buf, char* firmware, int buffer_size) |
| 134 | { |
| 135 | int fd; |
| 136 | int rc; |
| 137 | int len; |
| 138 | char filename[MAX_PATH]; |
| 139 | |
| 140 | snprintf(filename,sizeof(filename),"%s",firmware); |
| 141 | fd = open(filename, O_RDONLY); |
| 142 | if(fd < 0) |
| 143 | { |
| 144 | return EFILE_NOT_FOUND; |
| 145 | } |
| 146 | |
| 147 | len = filesize(fd); |
| 148 | |
| 149 | if (len > buffer_size) |
| 150 | return EFILE_TOO_BIG; |
| 151 | |
| 152 | rc = read(fd, buf, len); |
| 153 | if(rc < len) |
| 154 | return EREAD_IMAGE_FAILED; |
| 155 | |
| 156 | close(fd); |
| 157 | return len; |
| 158 | } |
| 159 | |
Cástor Muñoz | c31fcdd | 2016-05-02 01:17:05 +0200 | [diff] [blame] | 160 | /* FIXME?: unused broken code */ |
| 161 | #if 0 |
Maurus Cuelenaere | c33209e | 2009-02-07 13:52:03 +0000 | [diff] [blame] | 162 | #ifdef ROCKBOX_HAS_LOGF /* Logf display helper for the bootloader */ |
| 163 | |
| 164 | #define LINES (LCD_HEIGHT/SYSFONT_HEIGHT) |
| 165 | #define COLUMNS ((LCD_WIDTH/SYSFONT_WIDTH) > MAX_LOGF_ENTRY ? \ |
| 166 | MAX_LOGF_ENTRY : (LCD_WIDTH/SYSFONT_WIDTH)) |
| 167 | |
| 168 | #ifdef ONDA_VX747 |
| 169 | #define LOGF_UP BUTTON_VOL_UP |
| 170 | #define LOGF_DOWN BUTTON_VOL_DOWN |
| 171 | #define LOGF_CLEAR BUTTON_MENU |
| 172 | #else |
| 173 | #warning No keymap defined for this target |
| 174 | #endif |
| 175 | |
| 176 | void display_logf(void) /* Doesn't return! */ |
| 177 | { |
| 178 | int i, index, button, user_index=0; |
| 179 | #ifdef HAVE_TOUCHSCREEN |
| 180 | int touch, prev_y=0; |
| 181 | #endif |
| 182 | char buffer[COLUMNS+1]; |
| 183 | |
| 184 | while(1) |
| 185 | { |
| 186 | index = logfindex + user_index; |
| 187 | |
| 188 | lcd_clear_display(); |
| 189 | for(i = LINES-1; i>=0; i--) |
| 190 | { |
| 191 | if(--index < 0) |
| 192 | { |
| 193 | if(logfwrap) |
| 194 | index = MAX_LOGF_LINES-1; |
| 195 | else |
| 196 | break; /* done */ |
| 197 | } |
| 198 | |
| 199 | memcpy(buffer, logfbuffer[index], COLUMNS); |
| 200 | |
| 201 | if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_CONTINUE_LINE) |
| 202 | buffer[MAX_LOGF_ENTRY-1] = '>'; |
| 203 | else if (logfbuffer[index][MAX_LOGF_ENTRY] == LOGF_TERMINATE_MULTI_LINE) |
| 204 | buffer[MAX_LOGF_ENTRY-1] = '\0'; |
| 205 | |
| 206 | buffer[COLUMNS] = '\0'; |
| 207 | |
| 208 | lcd_puts(0, i, buffer); |
| 209 | } |
| 210 | |
| 211 | button = button_get(false); |
| 212 | if(button == SYS_USB_CONNECTED) |
| 213 | usb_acknowledge(SYS_USB_CONNECTED_ACK); |
| 214 | else if(button == SYS_USB_DISCONNECTED) |
Michael Sevakis | 453550a | 2011-01-18 14:10:06 +0000 | [diff] [blame] | 215 | ; |
Maurus Cuelenaere | c33209e | 2009-02-07 13:52:03 +0000 | [diff] [blame] | 216 | else if(button & LOGF_UP) |
| 217 | user_index++; |
| 218 | else if(button & LOGF_DOWN) |
| 219 | user_index--; |
| 220 | else if(button & LOGF_CLEAR) |
| 221 | user_index = 0; |
| 222 | #ifdef HAVE_TOUCHSCREEN |
Maurus Cuelenaere | 935fad7 | 2009-02-26 21:07:27 +0000 | [diff] [blame] | 223 | else if(button & BUTTON_TOUCHSCREEN) |
Maurus Cuelenaere | c33209e | 2009-02-07 13:52:03 +0000 | [diff] [blame] | 224 | { |
| 225 | touch = button_get_data(); |
| 226 | |
| 227 | if(button & BUTTON_REL) |
| 228 | prev_y = 0; |
| 229 | |
| 230 | if(prev_y != 0) |
| 231 | user_index += (prev_y - (touch & 0xFFFF)) / SYSFONT_HEIGHT; |
| 232 | prev_y = touch & 0xFFFF; |
| 233 | } |
| 234 | #endif |
| 235 | |
| 236 | lcd_update(); |
| 237 | sleep(HZ/16); |
| 238 | } |
| 239 | } |
| 240 | #endif |
Cástor Muñoz | c31fcdd | 2016-05-02 01:17:05 +0200 | [diff] [blame] | 241 | #endif |