Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 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. |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +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 "config.h" |
| 22 | |
| 23 | #include <stdlib.h> |
| 24 | #include <stdio.h> |
Miika Pekkarinen | e1eb91b | 2006-08-09 12:04:13 +0000 | [diff] [blame] | 25 | #include "inttypes.h" |
| 26 | #include "string.h" |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 27 | #include "cpu.h" |
| 28 | #include "system.h" |
| 29 | #include "lcd.h" |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 30 | #include "lcd-remote.h" |
Michael Sevakis | 5832b59 | 2007-07-28 08:45:57 +0000 | [diff] [blame] | 31 | #include "scroll_engine.h" |
Michael Sevakis | 4ea4cdf | 2014-08-08 02:28:11 -0400 | [diff] [blame] | 32 | #include "../kernel-internal.h" |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 33 | #include "storage.h" |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 34 | #include "file_internal.h" |
Linus Nielsen Feltzing | 01917ec | 2005-12-06 12:12:29 +0000 | [diff] [blame] | 35 | #include "usb.h" |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 36 | #include "disk.h" |
| 37 | #include "font.h" |
| 38 | #include "adc.h" |
| 39 | #include "backlight.h" |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 40 | #include "backlight-target.h" |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 41 | #include "button.h" |
| 42 | #include "panic.h" |
| 43 | #include "power.h" |
Jens Arnold | 0b7391e | 2007-08-17 07:06:54 +0000 | [diff] [blame] | 44 | #include "powermgmt.h" |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 45 | #include "file.h" |
Miika Pekkarinen | e1eb91b | 2006-08-09 12:04:13 +0000 | [diff] [blame] | 46 | #include "eeprom_settings.h" |
Linus Nielsen Feltzing | 4855615 | 2007-03-02 13:58:00 +0000 | [diff] [blame] | 47 | #include "rbunicode.h" |
Linus Nielsen Feltzing | 46597c9 | 2007-02-22 15:09:49 +0000 | [diff] [blame] | 48 | #include "common.h" |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 49 | #include "rb-loader.h" |
| 50 | #include "loader_strerror.h" |
Rafaël Carré | 5d236b2 | 2010-05-27 09:41:46 +0000 | [diff] [blame] | 51 | #include "version.h" |
Linus Nielsen Feltzing | ce6527b | 2006-03-22 11:45:33 +0000 | [diff] [blame] | 52 | |
| 53 | #include <stdarg.h> |
| 54 | |
Linus Nielsen Feltzing | 46597c9 | 2007-02-22 15:09:49 +0000 | [diff] [blame] | 55 | /* Maximum allowed firmware image size. 10MB is more than enough */ |
| 56 | #define MAX_LOADSIZE (10*1024*1024) |
| 57 | |
Linus Nielsen Feltzing | 62c768c | 2005-07-09 07:46:42 +0000 | [diff] [blame] | 58 | #define DRAM_START 0x31000000 |
| 59 | |
Miika Pekkarinen | 886c302 | 2007-01-13 08:16:02 +0000 | [diff] [blame] | 60 | #ifdef HAVE_EEPROM_SETTINGS |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 61 | static bool recovery_mode = false; |
Miika Pekkarinen | 886c302 | 2007-01-13 08:16:02 +0000 | [diff] [blame] | 62 | #endif |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 63 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 64 | /* Reset the cookie for the crt0 crash check */ |
| 65 | inline void __reset_cookie(void) |
| 66 | { |
| 67 | asm(" move.l #0,%d0"); |
| 68 | asm(" move.l %d0,0x10017ffc"); |
Linus Nielsen Feltzing | ce6527b | 2006-03-22 11:45:33 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 71 | void start_iriver_fw(void) |
| 72 | { |
| 73 | asm(" move.w #0x2700,%sr"); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 74 | __reset_cookie(); |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 75 | asm(" movec.l %d0,%vbr"); |
| 76 | asm(" move.l 0,%sp"); |
| 77 | asm(" lea.l 8,%a0"); |
| 78 | asm(" jmp (%a0)"); |
| 79 | } |
| 80 | |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 81 | void start_firmware(void) |
| 82 | { |
| 83 | asm(" move.w #0x2700,%sr"); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 84 | __reset_cookie(); |
Linus Nielsen Feltzing | e82df4e | 2005-07-08 15:09:44 +0000 | [diff] [blame] | 85 | asm(" move.l %0,%%d0" :: "i"(DRAM_START)); |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 86 | asm(" movec.l %d0,%vbr"); |
Linus Nielsen Feltzing | e82df4e | 2005-07-08 15:09:44 +0000 | [diff] [blame] | 87 | asm(" move.l %0,%%sp" :: "m"(*(int *)DRAM_START)); |
| 88 | asm(" move.l %0,%%a0" :: "m"(*(int *)(DRAM_START+4))); |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 89 | asm(" jmp (%a0)"); |
| 90 | } |
| 91 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 92 | #ifdef IRIVER_H100_SERIES |
| 93 | void start_flashed_romimage(void) |
| 94 | { |
| 95 | uint8_t *src = (uint8_t *)FLASH_ROMIMAGE_ENTRY; |
| 96 | int *reset_vector; |
| 97 | |
| 98 | if (!detect_flashed_romimage()) |
| 99 | return ; |
| 100 | |
| 101 | reset_vector = (int *)(&src[sizeof(struct flash_header)+4]); |
| 102 | |
| 103 | asm(" move.w #0x2700,%sr"); |
| 104 | __reset_cookie(); |
| 105 | |
| 106 | asm(" move.l %0,%%d0" :: "i"(DRAM_START)); |
| 107 | asm(" movec.l %d0,%vbr"); |
| 108 | asm(" move.l %0,%%sp" :: "m"(reset_vector[0])); |
| 109 | asm(" move.l %0,%%a0" :: "m"(reset_vector[1])); |
| 110 | asm(" jmp (%a0)"); |
| 111 | |
| 112 | /* Failure */ |
| 113 | power_off(); |
| 114 | } |
| 115 | |
| 116 | void start_flashed_ramimage(void) |
| 117 | { |
| 118 | struct flash_header hdr; |
| 119 | unsigned char *buf = (unsigned char *)DRAM_START; |
| 120 | uint8_t *src = (uint8_t *)FLASH_RAMIMAGE_ENTRY; |
| 121 | |
| 122 | if (!detect_flashed_ramimage()) |
| 123 | return; |
| 124 | |
| 125 | /* Load firmware from flash */ |
| 126 | cpu_boost(true); |
| 127 | memcpy(&hdr, src, sizeof(struct flash_header)); |
| 128 | src += sizeof(struct flash_header); |
| 129 | memcpy(buf, src, hdr.length); |
| 130 | cpu_boost(false); |
| 131 | |
| 132 | start_firmware(); |
| 133 | |
| 134 | /* Failure */ |
| 135 | power_off(); |
| 136 | } |
| 137 | #endif /* IRIVER_H100_SERIES */ |
| 138 | |
| 139 | void shutdown(void) |
| 140 | { |
| 141 | printf("Shutting down..."); |
| 142 | #ifdef HAVE_EEPROM_SETTINGS |
| 143 | /* Reset the rockbox crash check. */ |
| 144 | firmware_settings.bl_version = 0; |
| 145 | eeprom_settings_store(); |
| 146 | #endif |
| 147 | |
| 148 | /* We need to gracefully spin down the disk to prevent clicks. */ |
| 149 | if (ide_powered()) |
| 150 | { |
| 151 | /* Make sure ATA has been initialized. */ |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 152 | storage_init(); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 153 | |
| 154 | /* And put the disk into sleep immediately. */ |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 155 | storage_sleepnow(); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | sleep(HZ*2); |
| 159 | |
| 160 | /* Backlight OFF */ |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 161 | backlight_hw_off(); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 162 | #ifdef HAVE_REMOTE_LCD |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 163 | remote_backlight_hw_off(); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 164 | #endif |
| 165 | |
| 166 | __reset_cookie(); |
| 167 | power_off(); |
| 168 | } |
| 169 | |
| 170 | /* Print the battery voltage (and a warning message). */ |
| 171 | void check_battery(void) |
| 172 | { |
Jens Arnold | 0fac492 | 2007-08-17 06:45:18 +0000 | [diff] [blame] | 173 | int battery_voltage, batt_int, batt_frac; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 174 | |
Thomas Martitz | c1bd9b0 | 2012-01-03 23:44:38 +0000 | [diff] [blame] | 175 | battery_voltage = _battery_voltage(); |
Jens Arnold | 0fac492 | 2007-08-17 06:45:18 +0000 | [diff] [blame] | 176 | batt_int = battery_voltage / 1000; |
| 177 | batt_frac = (battery_voltage % 1000) / 10; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 178 | |
| 179 | printf("Batt: %d.%02dV", batt_int, batt_frac); |
| 180 | |
| 181 | if (battery_voltage <= 310) |
| 182 | { |
| 183 | printf("WARNING! BATTERY LOW!!"); |
| 184 | sleep(HZ*2); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | #ifdef HAVE_EEPROM_SETTINGS |
| 189 | void initialize_eeprom(void) |
| 190 | { |
| 191 | if (detect_original_firmware()) |
| 192 | return ; |
| 193 | |
| 194 | if (!eeprom_settings_init()) |
| 195 | { |
| 196 | recovery_mode = true; |
| 197 | return ; |
| 198 | } |
| 199 | |
| 200 | /* If bootloader version has not been reset, disk might |
| 201 | * not be intact. */ |
| 202 | if (firmware_settings.bl_version || !firmware_settings.disk_clean) |
| 203 | { |
| 204 | firmware_settings.disk_clean = false; |
| 205 | recovery_mode = true; |
| 206 | } |
| 207 | |
| 208 | firmware_settings.bl_version = EEPROM_SETTINGS_BL_MINVER; |
| 209 | eeprom_settings_store(); |
| 210 | } |
| 211 | |
| 212 | void try_flashboot(void) |
| 213 | { |
| 214 | if (!firmware_settings.initialized) |
| 215 | return ; |
| 216 | |
| 217 | switch (firmware_settings.bootmethod) |
| 218 | { |
| 219 | case BOOT_DISK: |
| 220 | return; |
| 221 | |
| 222 | case BOOT_ROM: |
| 223 | start_flashed_romimage(); |
| 224 | recovery_mode = true; |
| 225 | break; |
| 226 | |
| 227 | case BOOT_RAM: |
| 228 | start_flashed_ramimage(); |
| 229 | recovery_mode = true; |
| 230 | break; |
| 231 | |
| 232 | default: |
| 233 | recovery_mode = true; |
| 234 | return; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | static const char *options[] = { |
| 239 | "Boot from disk", |
| 240 | "Boot RAM image", |
| 241 | "Boot ROM image", |
| 242 | "Shutdown" |
| 243 | }; |
| 244 | |
| 245 | #define FAILSAFE_OPTIONS 4 |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 246 | #define TIMEOUT (15*HZ) |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 247 | void failsafe_menu(void) |
| 248 | { |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 249 | long start_tick = current_tick; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 250 | int option = 3; |
| 251 | int button; |
| 252 | int defopt = -1; |
| 253 | char buf[32]; |
| 254 | int i; |
Linus Nielsen Feltzing | 46597c9 | 2007-02-22 15:09:49 +0000 | [diff] [blame] | 255 | extern int line; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 256 | |
| 257 | reset_screen(); |
Michael Sevakis | 95a4c3a | 2014-08-28 10:26:45 -0400 | [diff] [blame] | 258 | printf("Bootloader %s", rbversion); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 259 | check_battery(); |
| 260 | printf("========================="); |
| 261 | line += FAILSAFE_OPTIONS; |
| 262 | printf(""); |
| 263 | printf(" [NAVI] to confirm."); |
| 264 | printf(" [REC] to set as default."); |
| 265 | printf(""); |
| 266 | |
| 267 | if (firmware_settings.initialized) |
| 268 | { |
| 269 | defopt = firmware_settings.bootmethod; |
| 270 | if (defopt < 0 || defopt >= FAILSAFE_OPTIONS) |
| 271 | defopt = option; |
| 272 | } |
| 273 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 274 | while (current_tick - start_tick < TIMEOUT) |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 275 | { |
| 276 | /* Draw the menu. */ |
| 277 | line = 3; |
| 278 | for (i = 0; i < FAILSAFE_OPTIONS; i++) |
| 279 | { |
| 280 | char *def = "[DEF]"; |
| 281 | char *arrow = "->"; |
| 282 | |
| 283 | if (i != defopt) |
| 284 | def = ""; |
| 285 | if (i != option) |
| 286 | arrow = " "; |
| 287 | |
| 288 | printf("%s %s %s", arrow, options[i], def); |
| 289 | } |
| 290 | |
Thomas Martitz | 77dfff5 | 2010-05-06 21:37:03 +0000 | [diff] [blame] | 291 | snprintf(buf, sizeof(buf), "Time left: %lds", |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 292 | (TIMEOUT - (current_tick - start_tick)) / HZ); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 293 | lcd_puts(0, 10, buf); |
| 294 | lcd_update(); |
| 295 | button = button_get_w_tmo(HZ); |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 296 | |
| 297 | if (button == BUTTON_NONE || button & SYS_EVENT) |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 298 | continue ; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 299 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 300 | start_tick = current_tick; |
| 301 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 302 | /* Ignore the ON/PLAY -button because it can cause trouble |
| 303 | with the RTC alarm mod. */ |
| 304 | switch (button & ~(BUTTON_ON)) |
| 305 | { |
| 306 | case BUTTON_UP: |
| 307 | case BUTTON_RC_REW: |
| 308 | if (option > 0) |
| 309 | option--; |
| 310 | break ; |
| 311 | |
| 312 | case BUTTON_DOWN: |
| 313 | case BUTTON_RC_FF: |
| 314 | if (option < FAILSAFE_OPTIONS-1) |
| 315 | option++; |
| 316 | break ; |
| 317 | |
| 318 | case BUTTON_SELECT: |
| 319 | case BUTTON_RC_ON: |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 320 | goto execute; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 321 | |
| 322 | case BUTTON_REC: |
| 323 | case BUTTON_RC_REC: |
| 324 | if (firmware_settings.initialized) |
| 325 | { |
| 326 | firmware_settings.bootmethod = option; |
| 327 | eeprom_settings_store(); |
| 328 | defopt = option; |
| 329 | } |
| 330 | break ; |
| 331 | } |
| 332 | } |
| 333 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 334 | execute: |
| 335 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 336 | lcd_puts(0, 10, "Executing command..."); |
| 337 | lcd_update(); |
| 338 | sleep(HZ); |
| 339 | reset_screen(); |
| 340 | |
| 341 | switch (option) |
| 342 | { |
| 343 | case BOOT_DISK: |
| 344 | return ; |
| 345 | |
| 346 | case BOOT_RAM: |
| 347 | start_flashed_ramimage(); |
| 348 | printf("Image not found"); |
| 349 | break; |
| 350 | |
| 351 | case BOOT_ROM: |
| 352 | start_flashed_romimage(); |
| 353 | printf("Image not found"); |
| 354 | break; |
| 355 | } |
| 356 | |
| 357 | shutdown(); |
| 358 | } |
| 359 | #endif |
| 360 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 361 | /* get rid of a nasty humming sound during boot |
| 362 | -> RESET signal */ |
| 363 | inline static void __uda1380_reset_hi(void) |
| 364 | { |
| 365 | #ifdef HAVE_UDA1380 |
| 366 | or_l(1<<29, &GPIO_OUT); |
| 367 | or_l(1<<29, &GPIO_ENABLE); |
| 368 | or_l(1<<29, &GPIO_FUNCTION); |
| 369 | #endif |
| 370 | } |
| 371 | |
| 372 | inline static void __uda1380_reset_lo(void) |
| 373 | { |
| 374 | #ifdef HAVE_UDA1380 |
| 375 | and_l(~(1<<29), &GPIO_OUT); |
| 376 | #endif |
| 377 | } |
| 378 | |
Linus Nielsen Feltzing | b8a00d2 | 2005-02-10 21:55:48 +0000 | [diff] [blame] | 379 | void main(void) |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 380 | { |
| 381 | int i; |
| 382 | int rc; |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 383 | bool rc_on_button = false; |
| 384 | bool on_button = false; |
Miika Pekkarinen | e1eb91b | 2006-08-09 12:04:13 +0000 | [diff] [blame] | 385 | bool rec_button = false; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 386 | bool hold_status = false; |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 387 | int data; |
Linus Nielsen Feltzing | 343c428 | 2007-02-28 08:40:37 +0000 | [diff] [blame] | 388 | extern int line; /* From common.c */ |
| 389 | extern int remote_line; /* From common.c */ |
Linus Nielsen Feltzing | ec549ec | 2007-02-22 21:38:59 +0000 | [diff] [blame] | 390 | |
Linus Nielsen Feltzing | e628b5c | 2005-07-19 08:08:33 +0000 | [diff] [blame] | 391 | /* We want to read the buttons as early as possible, before the user |
| 392 | releases the ON button */ |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 393 | |
Linus Nielsen Feltzing | e628b5c | 2005-07-19 08:08:33 +0000 | [diff] [blame] | 394 | /* Set GPIO33, GPIO37, GPIO38 and GPIO52 as general purpose inputs |
| 395 | (The ON and Hold buttons on the main unit and the remote) */ |
Linus Nielsen Feltzing | d2ca7fc | 2005-07-12 05:25:42 +0000 | [diff] [blame] | 396 | or_l(0x00100062, &GPIO1_FUNCTION); |
| 397 | and_l(~0x00100062, &GPIO1_ENABLE); |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 398 | |
| 399 | data = GPIO1_READ; |
| 400 | if ((data & 0x20) == 0) |
| 401 | on_button = true; |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 402 | |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 403 | if ((data & 0x40) == 0) |
| 404 | rc_on_button = true; |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 405 | |
Linus Nielsen Feltzing | e628b5c | 2005-07-19 08:08:33 +0000 | [diff] [blame] | 406 | /* Set the default state of the hard drive power to OFF */ |
| 407 | ide_power_enable(false); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 408 | |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 409 | power_init(); |
Linus Nielsen Feltzing | e628b5c | 2005-07-19 08:08:33 +0000 | [diff] [blame] | 410 | |
Linus Nielsen Feltzing | bbe919b | 2005-11-19 01:33:28 +0000 | [diff] [blame] | 411 | /* Turn off if neither ON button is pressed */ |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 412 | if (!(on_button || rc_on_button)) |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 413 | { |
| 414 | __reset_cookie(); |
Linus Nielsen Feltzing | bbe919b | 2005-11-19 01:33:28 +0000 | [diff] [blame] | 415 | power_off(); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 416 | } |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 417 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 418 | __uda1380_reset_hi(); |
| 419 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 420 | /* Start with the main backlight OFF. */ |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 421 | backlight_hw_init(); |
| 422 | backlight_hw_off(); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 423 | |
Linus Nielsen Feltzing | bbe919b | 2005-11-19 01:33:28 +0000 | [diff] [blame] | 424 | /* Remote backlight ON */ |
| 425 | #ifdef HAVE_REMOTE_LCD |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 426 | remote_backlight_hw_on(); |
Linus Nielsen Feltzing | b68cb9b | 2005-12-03 00:54:59 +0000 | [diff] [blame] | 427 | #endif |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 428 | |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 429 | system_init(); |
| 430 | kernel_init(); |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 431 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 432 | __uda1380_reset_lo(); |
| 433 | |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 434 | #ifdef HAVE_ADJUSTABLE_CPU_FREQ |
| 435 | /* Set up waitstates for the peripherals */ |
| 436 | set_cpu_frequency(0); /* PLL off */ |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 437 | #ifdef CPU_COLDFIRE |
| 438 | coldfire_set_pllcr_audio_bits(DEFAULT_PLLCR_AUDIO_BITS); |
| 439 | #endif |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 440 | #endif |
Michael Sevakis | af395f4 | 2008-03-26 01:50:41 +0000 | [diff] [blame] | 441 | enable_irq(); |
Linus Nielsen Feltzing | d2ca7fc | 2005-07-12 05:25:42 +0000 | [diff] [blame] | 442 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 443 | #ifdef HAVE_EEPROM_SETTINGS |
| 444 | initialize_eeprom(); |
| 445 | #endif |
| 446 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 447 | usb_init(); |
| 448 | /* A small delay after usb_init is necessary to read the I/O port correctly |
| 449 | (if ports are read _immediately_ after the init). */ |
| 450 | /* sleep(1); */ |
| 451 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 452 | adc_init(); |
| 453 | button_init(); |
| 454 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 455 | /* Only check remote hold status if remote power button was actually used. */ |
| 456 | if (rc_on_button) |
| 457 | { |
| 458 | lcd_remote_init(); |
| 459 | |
| 460 | /* Allow the button driver to check the buttons */ |
| 461 | sleep(HZ/50); |
| 462 | |
| 463 | if (remote_button_hold()) |
| 464 | hold_status = true; |
| 465 | } |
| 466 | |
| 467 | /* Check main hold switch status too. */ |
| 468 | if (on_button && button_hold()) |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 469 | { |
| 470 | hold_status = true; |
| 471 | } |
| 472 | |
Linus Nielsen Feltzing | ff17905 | 2007-03-02 11:28:23 +0000 | [diff] [blame] | 473 | /* Power on the hard drive early, to speed up the loading. */ |
Miika Pekkarinen | 20171c1 | 2007-01-13 09:08:18 +0000 | [diff] [blame] | 474 | if (!hold_status |
| 475 | # ifdef HAVE_EEPROM_SETTINGS |
| 476 | && !recovery_mode |
| 477 | # endif |
| 478 | ) |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 479 | { |
| 480 | ide_power_enable(true); |
| 481 | } |
| 482 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 483 | # ifdef HAVE_EEPROM_SETTINGS |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 484 | if (!hold_status && (usb_detect() != USB_INSERTED) && !recovery_mode) |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 485 | try_flashboot(); |
Miika Pekkarinen | 20171c1 | 2007-01-13 09:08:18 +0000 | [diff] [blame] | 486 | # endif |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 487 | |
| 488 | backlight_init(); |
Christian Gmeiner | 21ac311 | 2007-11-20 12:09:59 +0000 | [diff] [blame] | 489 | |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 490 | |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 491 | lcd_init(); |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 492 | |
| 493 | if (!rc_on_button) |
| 494 | lcd_remote_init(); |
| 495 | |
| 496 | /* Bootloader uses simplified backlight thread, so we need to enable |
| 497 | remote display here. */ |
| 498 | if (remote_detect()) |
| 499 | lcd_remote_on(); |
| 500 | |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 501 | font_init(); |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 502 | |
| 503 | lcd_setfont(FONT_SYSFIXED); |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 504 | |
Linus Nielsen Feltzing | ce6527b | 2006-03-22 11:45:33 +0000 | [diff] [blame] | 505 | printf("Rockbox boot loader"); |
Michael Sevakis | 95a4c3a | 2014-08-28 10:26:45 -0400 | [diff] [blame] | 506 | printf("Version %s", rbversion); |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 507 | |
Miika Pekkarinen | 698113d | 2008-02-09 15:06:09 +0000 | [diff] [blame] | 508 | /* No need to wait here more because lcd_init and others already do that. */ |
| 509 | // sleep(HZ/50); /* Allow the button driver to check the buttons */ |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 510 | rec_button = ((button_status() & BUTTON_REC) == BUTTON_REC) |
Miika Pekkarinen | e1eb91b | 2006-08-09 12:04:13 +0000 | [diff] [blame] | 511 | || ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 512 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 513 | check_battery(); |
| 514 | |
Miika Pekkarinen | 22860a9 | 2006-08-11 19:59:16 +0000 | [diff] [blame] | 515 | /* Don't start if the Hold button is active on the device you |
| 516 | are starting with */ |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 517 | if ((usb_detect() != USB_INSERTED) && (hold_status |
Miika Pekkarinen | 20171c1 | 2007-01-13 09:08:18 +0000 | [diff] [blame] | 518 | #ifdef HAVE_EEPROM_SETTINGS |
| 519 | || recovery_mode |
| 520 | #endif |
| 521 | )) |
Miika Pekkarinen | 22860a9 | 2006-08-11 19:59:16 +0000 | [diff] [blame] | 522 | { |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 523 | if (detect_original_firmware()) |
| 524 | { |
| 525 | printf("Hold switch on"); |
| 526 | shutdown(); |
| 527 | } |
| 528 | |
Miika Pekkarinen | 20171c1 | 2007-01-13 09:08:18 +0000 | [diff] [blame] | 529 | #ifdef HAVE_EEPROM_SETTINGS |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 530 | failsafe_menu(); |
Miika Pekkarinen | 22860a9 | 2006-08-11 19:59:16 +0000 | [diff] [blame] | 531 | #endif |
Miika Pekkarinen | 22860a9 | 2006-08-11 19:59:16 +0000 | [diff] [blame] | 532 | } |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 533 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 534 | /* Holding REC while starting runs the original firmware */ |
| 535 | if (detect_original_firmware() && rec_button) |
Miika Pekkarinen | e1eb91b | 2006-08-09 12:04:13 +0000 | [diff] [blame] | 536 | { |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 537 | printf("Starting original firmware..."); |
| 538 | start_iriver_fw(); |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 539 | } |
| 540 | |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 541 | /* A hack to enter USB mode without using the USB thread */ |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 542 | if(usb_detect() == USB_INSERTED) |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 543 | { |
Linus Nielsen Feltzing | 01917ec | 2005-12-06 12:12:29 +0000 | [diff] [blame] | 544 | const char msg[] = "Bootloader USB mode"; |
| 545 | int w, h; |
| 546 | font_getstringsize(msg, &w, &h, FONT_SYSFIXED); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 547 | reset_screen(); |
Linus Nielsen Feltzing | 01917ec | 2005-12-06 12:12:29 +0000 | [diff] [blame] | 548 | lcd_putsxy((LCD_WIDTH-w)/2, (LCD_HEIGHT-h)/2, msg); |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 549 | lcd_update(); |
| 550 | |
Linus Nielsen Feltzing | 343c428 | 2007-02-28 08:40:37 +0000 | [diff] [blame] | 551 | #ifdef HAVE_REMOTE_LCD |
| 552 | lcd_remote_puts(0, 3, msg); |
| 553 | lcd_remote_update(); |
| 554 | #endif |
| 555 | |
Peter D'Hoye | c4a59a2 | 2006-08-15 22:54:06 +0000 | [diff] [blame] | 556 | #ifdef HAVE_EEPROM_SETTINGS |
Miika Pekkarinen | e1eb91b | 2006-08-09 12:04:13 +0000 | [diff] [blame] | 557 | if (firmware_settings.initialized) |
| 558 | { |
| 559 | firmware_settings.disk_clean = false; |
| 560 | eeprom_settings_store(); |
| 561 | } |
| 562 | #endif |
Linus Nielsen Feltzing | 237ff9e | 2007-02-28 00:06:35 +0000 | [diff] [blame] | 563 | ide_power_enable(true); |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 564 | storage_enable(false); |
Linus Nielsen Feltzing | 237ff9e | 2007-02-28 00:06:35 +0000 | [diff] [blame] | 565 | sleep(HZ/20); |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 566 | usb_enable(true); |
Linus Nielsen Feltzing | 01917ec | 2005-12-06 12:12:29 +0000 | [diff] [blame] | 567 | cpu_idle_mode(true); |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 568 | while (usb_detect() == USB_INSERTED) |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 569 | { |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 570 | /* Print the battery status. */ |
| 571 | line = 0; |
Linus Nielsen Feltzing | 343c428 | 2007-02-28 08:40:37 +0000 | [diff] [blame] | 572 | remote_line = 0; |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 573 | check_battery(); |
| 574 | |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 575 | storage_spin(); /* Prevent the drive from spinning down */ |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 576 | sleep(HZ); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 577 | |
Linus Nielsen Feltzing | e628b5c | 2005-07-19 08:08:33 +0000 | [diff] [blame] | 578 | /* Backlight OFF */ |
Marcin Bukat | 89ba7e8 | 2015-01-09 00:22:40 +0100 | [diff] [blame] | 579 | backlight_hw_off(); |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 580 | } |
| 581 | |
Linus Nielsen Feltzing | 01917ec | 2005-12-06 12:12:29 +0000 | [diff] [blame] | 582 | cpu_idle_mode(false); |
Linus Nielsen Feltzing | 1310390 | 2005-07-19 11:03:00 +0000 | [diff] [blame] | 583 | usb_enable(false); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 584 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 585 | reset_screen(); |
Linus Nielsen Feltzing | 1310390 | 2005-07-19 11:03:00 +0000 | [diff] [blame] | 586 | lcd_update(); |
Linus Nielsen Feltzing | 8e958b5 | 2005-05-20 18:16:45 +0000 | [diff] [blame] | 587 | } |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 588 | |
Frank Gevaerts | 2f8a008 | 2008-11-01 16:14:28 +0000 | [diff] [blame] | 589 | rc = storage_init(); |
Linus Nielsen Feltzing | 237ff9e | 2007-02-28 00:06:35 +0000 | [diff] [blame] | 590 | if(rc) |
| 591 | { |
| 592 | reset_screen(); |
| 593 | printf("ATA error: %d", rc); |
| 594 | printf("Insert USB cable and press"); |
| 595 | printf("a button"); |
| 596 | while(!(button_get(true) & BUTTON_REL)); |
| 597 | } |
| 598 | |
| 599 | |
Michael Sevakis | 7d1a47c | 2013-08-05 22:02:45 -0400 | [diff] [blame] | 600 | filesystem_init(); |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 601 | |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 602 | rc = disk_mount_all(); |
| 603 | if (rc<=0) |
| 604 | { |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 605 | reset_screen(); |
Linus Nielsen Feltzing | ce6527b | 2006-03-22 11:45:33 +0000 | [diff] [blame] | 606 | printf("No partition found"); |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 607 | while(button_get(true) != SYS_USB_CONNECTED) {}; |
| 608 | } |
| 609 | |
Linus Nielsen Feltzing | ce6527b | 2006-03-22 11:45:33 +0000 | [diff] [blame] | 610 | printf("Loading firmware"); |
Linus Nielsen Feltzing | 46597c9 | 2007-02-22 15:09:49 +0000 | [diff] [blame] | 611 | i = load_firmware((unsigned char *)DRAM_START, BOOTFILE, MAX_LOADSIZE); |
Linus Nielsen Feltzing | 343c428 | 2007-02-28 08:40:37 +0000 | [diff] [blame] | 612 | if(i < 0) |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 613 | printf("Error: %s", loader_strerror(i)); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 614 | |
Marcin Bukat | 0b29691 | 2012-03-04 15:34:29 +0100 | [diff] [blame] | 615 | if (i > 0) |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 616 | start_firmware(); |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 617 | |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 618 | if (!detect_original_firmware()) |
Miika Pekkarinen | 973ee5d | 2006-09-04 16:06:11 +0000 | [diff] [blame] | 619 | { |
| 620 | printf("No firmware found on disk"); |
Linus Nielsen Feltzing | 46597c9 | 2007-02-22 15:09:49 +0000 | [diff] [blame] | 621 | sleep(HZ*2); |
Miika Pekkarinen | 35b0c3f | 2007-01-12 20:45:37 +0000 | [diff] [blame] | 622 | shutdown(); |
Miika Pekkarinen | 973ee5d | 2006-09-04 16:06:11 +0000 | [diff] [blame] | 623 | } |
Linus Nielsen Feltzing | 343c428 | 2007-02-28 08:40:37 +0000 | [diff] [blame] | 624 | else { |
| 625 | sleep(HZ*2); |
Miika Pekkarinen | 973ee5d | 2006-09-04 16:06:11 +0000 | [diff] [blame] | 626 | start_iriver_fw(); |
Linus Nielsen Feltzing | 343c428 | 2007-02-28 08:40:37 +0000 | [diff] [blame] | 627 | } |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /* These functions are present in the firmware library, but we reimplement |
| 631 | them here because the originals do a lot more than we want */ |
Linus Nielsen Feltzing | d397145 | 2005-01-28 12:51:10 +0000 | [diff] [blame] | 632 | void screen_dump(void) |
| 633 | { |
| 634 | } |
Linus Nielsen Feltzing | ff17905 | 2007-03-02 11:28:23 +0000 | [diff] [blame] | 635 | |
| 636 | int usb_screen(void) |
| 637 | { |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | unsigned short *bidi_l2v(const unsigned char *str, int orientation) |
| 642 | { |
| 643 | static unsigned short utf16_buf[SCROLL_LINE_SIZE]; |
| 644 | unsigned short *target; |
| 645 | (void)orientation; |
| 646 | |
| 647 | target = utf16_buf; |
| 648 | |
| 649 | while (*str) |
| 650 | str = utf8decode(str, target++); |
| 651 | *target = 0; |
| 652 | return utf16_buf; |
| 653 | } |