2002-09-03 09:44:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Randy D. Wood
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2002-09-03 09:44:08 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2005-02-02 21:47:08 +00:00
|
|
|
#include "config.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "lcd.h"
|
2012-01-07 19:45:09 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2006-04-24 06:45:27 +00:00
|
|
|
#include "lcd-remote.h"
|
2012-01-07 19:45:09 +00:00
|
|
|
#endif
|
2013-12-14 23:38:48 +00:00
|
|
|
#include "scroll_engine.h"
|
2007-09-28 10:20:02 +00:00
|
|
|
#include "thread.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "kernel.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "file.h"
|
2005-04-04 12:06:29 +00:00
|
|
|
#include "audio.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "system.h"
|
|
|
|
#include "i2c.h"
|
2008-03-26 23:35:34 +00:00
|
|
|
#include "adc.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
#include "string.h"
|
2011-08-30 14:01:33 +00:00
|
|
|
#include "core_alloc.h"
|
2009-10-11 02:06:42 +00:00
|
|
|
#include "storage.h"
|
2008-05-03 07:17:44 +00:00
|
|
|
#include "rolo.h"
|
2002-09-03 09:44:08 +00:00
|
|
|
|
2012-03-04 14:34:29 +00:00
|
|
|
#include "loader_strerror.h"
|
|
|
|
#if defined(MI4_FORMAT)
|
2007-06-04 13:48:21 +00:00
|
|
|
#include "crc32-mi4.h"
|
2012-03-04 14:34:29 +00:00
|
|
|
#include "mi4-loader.h"
|
2020-08-15 16:04:47 +00:00
|
|
|
#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
|
|
|
|
#include "bootdata.h"
|
|
|
|
#include "crc32.h"
|
2020-10-11 13:30:41 +00:00
|
|
|
extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*mi4-loader.c*/
|
2020-08-15 16:04:47 +00:00
|
|
|
#endif
|
2012-03-04 14:34:29 +00:00
|
|
|
#define LOAD_FIRMWARE(a,b,c) load_mi4(a,b,c)
|
|
|
|
#elif defined(RKW_FORMAT)
|
2012-03-03 23:06:20 +00:00
|
|
|
#include "rkw-loader.h"
|
2012-03-04 14:34:29 +00:00
|
|
|
#define LOAD_FIRMWARE(a,b,c) load_rkw(a,b,c)
|
|
|
|
#else
|
|
|
|
#include "rb-loader.h"
|
2020-08-08 06:33:49 +00:00
|
|
|
#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
|
|
|
|
#include "bootdata.h"
|
|
|
|
#include "crc32.h"
|
2020-10-11 13:30:41 +00:00
|
|
|
extern int write_bootdata(unsigned char* buf, int len, unsigned int boot_volume); /*rb-loader.c*/
|
2020-08-08 06:33:49 +00:00
|
|
|
#endif
|
2012-03-04 14:34:29 +00:00
|
|
|
#define LOAD_FIRMWARE(a,b,c) load_firmware(a,b,c)
|
2012-03-02 15:49:05 +00:00
|
|
|
#endif
|
|
|
|
|
2016-01-23 23:04:18 +00:00
|
|
|
#if CONFIG_CPU == AS3525v2
|
|
|
|
#include "ascodec.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-19 21:38:52 +00:00
|
|
|
#if !defined(IRIVER_IFP7XX_SERIES)
|
|
|
|
/* FIX: this doesn't work on iFP */
|
2005-02-02 21:47:08 +00:00
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
#define IRQ0_EDGE_TRIGGER 0x80
|
|
|
|
|
2011-08-30 14:01:33 +00:00
|
|
|
static int rolo_handle;
|
2007-02-27 22:55:12 +00:00
|
|
|
#ifdef CPU_PP
|
|
|
|
/* Handle the COP properly - it needs to jump to a function outside SDRAM while
|
|
|
|
* the new firmware is being loaded, and then jump to the start of SDRAM
|
|
|
|
* TODO: Use the mailboxes built into the PP processor for this
|
|
|
|
*/
|
|
|
|
|
2007-09-29 06:56:21 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-02-27 22:55:12 +00:00
|
|
|
volatile unsigned char IDATA_ATTR cpu_message = 0;
|
|
|
|
volatile unsigned char IDATA_ATTR cpu_reply = 0;
|
2007-09-28 10:20:02 +00:00
|
|
|
extern int cop_idlestackbegin[];
|
2007-02-27 22:55:12 +00:00
|
|
|
|
|
|
|
void rolo_restart_cop(void) ICODE_ATTR;
|
|
|
|
void rolo_restart_cop(void)
|
|
|
|
{
|
2007-09-28 10:20:02 +00:00
|
|
|
if (CURRENT_CORE == CPU)
|
|
|
|
{
|
|
|
|
/* There should be free thread slots aplenty */
|
|
|
|
create_thread(rolo_restart_cop, cop_idlestackbegin, IDLE_STACK_SIZE,
|
2007-10-16 01:25:17 +00:00
|
|
|
0, "rolo COP" IF_PRIO(, PRIORITY_REALTIME)
|
|
|
|
IF_COP(, COP));
|
2007-09-28 10:20:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2008-06-03 05:19:32 +00:00
|
|
|
COP_INT_DIS = -1;
|
2007-09-28 10:20:02 +00:00
|
|
|
|
2007-02-27 22:55:12 +00:00
|
|
|
/* Invalidate cache */
|
2011-12-17 07:27:24 +00:00
|
|
|
commit_discard_idcache();
|
2020-10-11 13:30:41 +00:00
|
|
|
|
2007-02-27 22:55:12 +00:00
|
|
|
/* Disable cache */
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_CTL = CACHE_CTL_DISABLE;
|
2007-02-27 22:55:12 +00:00
|
|
|
|
2007-03-04 23:53:38 +00:00
|
|
|
/* Tell the main core that we're ready to reload */
|
2007-09-28 10:20:02 +00:00
|
|
|
cpu_reply = 1;
|
2007-03-04 23:53:38 +00:00
|
|
|
|
2007-02-27 22:55:12 +00:00
|
|
|
/* Wait while RoLo loads the image into SDRAM */
|
|
|
|
/* TODO: Accept checksum failure gracefully */
|
2007-09-28 10:20:02 +00:00
|
|
|
while(cpu_message != 1);
|
2007-02-27 22:55:12 +00:00
|
|
|
|
2007-03-04 23:53:38 +00:00
|
|
|
/* Acknowledge the CPU and then reload */
|
2007-09-28 10:20:02 +00:00
|
|
|
cpu_reply = 2;
|
2007-02-27 22:55:12 +00:00
|
|
|
|
|
|
|
asm volatile(
|
2010-05-31 14:42:27 +00:00
|
|
|
"bx %0 \n"
|
|
|
|
: : "r"(DRAM_START)
|
2007-02-27 22:55:12 +00:00
|
|
|
);
|
|
|
|
}
|
2007-09-29 06:56:21 +00:00
|
|
|
#endif /* NUM_CORES > 1 */
|
|
|
|
#endif /* CPU_PP */
|
2007-02-27 22:55:12 +00:00
|
|
|
|
2004-08-16 23:37:23 +00:00
|
|
|
static void rolo_error(const char *text)
|
2002-09-03 09:44:08 +00:00
|
|
|
{
|
2011-08-30 14:01:33 +00:00
|
|
|
rolo_handle = core_free(rolo_handle);
|
2002-09-03 09:44:08 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0, 0, "ROLO error:");
|
|
|
|
lcd_puts_scroll(0, 1, text);
|
|
|
|
lcd_update();
|
|
|
|
button_get(true);
|
2003-05-09 16:01:21 +00:00
|
|
|
button_get(true);
|
|
|
|
button_get(true);
|
2013-04-03 14:33:23 +00:00
|
|
|
lcd_scroll_stop();
|
2002-09-03 09:44:08 +00:00
|
|
|
}
|
2003-10-12 16:40:45 +00:00
|
|
|
|
2020-07-15 23:40:55 +00:00
|
|
|
#if CONFIG_CPU == IMX31L || CONFIG_CPU == RK27XX
|
2010-04-23 15:32:50 +00:00
|
|
|
/* this is in firmware/target/arm/imx31/rolo_restart.c for IMX31 */
|
2012-03-02 15:49:05 +00:00
|
|
|
/* this is in firmware/target/arm/rk27xx/rolo_restart.c for rk27xx */
|
2004-08-16 23:37:23 +00:00
|
|
|
extern void rolo_restart(const unsigned char* source, unsigned char* dest,
|
|
|
|
int length);
|
2005-03-31 08:47:02 +00:00
|
|
|
#else
|
2007-07-17 14:53:44 +00:00
|
|
|
|
|
|
|
/* explicitly put this code in iram, ICODE_ATTR is defined to be null for some
|
|
|
|
targets that are low on iram, like the gigabeat F/X */
|
|
|
|
void rolo_restart(const unsigned char* source, unsigned char* dest,
|
|
|
|
long length) __attribute__ ((section(".icode")));
|
|
|
|
void rolo_restart(const unsigned char* source, unsigned char* dest,
|
|
|
|
long length)
|
2005-03-31 08:47:02 +00:00
|
|
|
{
|
|
|
|
long i;
|
2005-06-22 16:53:12 +00:00
|
|
|
unsigned char* localdest = dest;
|
2005-03-31 08:47:02 +00:00
|
|
|
|
2007-07-16 19:26:07 +00:00
|
|
|
/* This is the equivalent of a call to memcpy() but this must be done from
|
|
|
|
iram to avoid overwriting itself and we don't want to depend on memcpy()
|
|
|
|
always being in iram */
|
2005-03-31 08:47:02 +00:00
|
|
|
for(i = 0;i < length;i++)
|
2005-06-22 16:53:12 +00:00
|
|
|
*localdest++ = *source++;
|
2005-03-31 08:47:02 +00:00
|
|
|
|
2006-07-13 21:11:20 +00:00
|
|
|
#if defined(CPU_COLDFIRE)
|
2005-06-22 16:53:12 +00:00
|
|
|
asm (
|
|
|
|
"movec.l %0,%%vbr \n"
|
|
|
|
"move.l (%0)+,%%sp \n"
|
|
|
|
"move.l (%0),%0 \n"
|
|
|
|
"jmp (%0) \n"
|
|
|
|
: : "a"(dest)
|
|
|
|
);
|
2009-10-19 21:38:52 +00:00
|
|
|
#elif defined(CPU_PP)
|
2008-06-03 05:08:24 +00:00
|
|
|
CPU_INT_DIS = -1;
|
2007-02-27 22:55:12 +00:00
|
|
|
|
2006-12-10 15:20:26 +00:00
|
|
|
/* Flush cache */
|
2011-12-17 07:27:24 +00:00
|
|
|
commit_discard_idcache();
|
2006-12-10 15:20:26 +00:00
|
|
|
|
2006-07-23 14:30:10 +00:00
|
|
|
/* Disable cache */
|
2007-09-30 10:53:31 +00:00
|
|
|
CACHE_CTL = CACHE_CTL_DISABLE;
|
2006-07-23 14:30:10 +00:00
|
|
|
|
|
|
|
/* Reset the memory mapping registers to zero */
|
2007-09-30 10:53:31 +00:00
|
|
|
{
|
|
|
|
volatile unsigned long *mmap_reg;
|
|
|
|
for (mmap_reg = &MMAP_FIRST; mmap_reg <= &MMAP_LAST; mmap_reg++)
|
|
|
|
*mmap_reg = 0;
|
|
|
|
}
|
2006-07-23 14:30:10 +00:00
|
|
|
|
2007-09-29 06:56:21 +00:00
|
|
|
#if NUM_CORES > 1
|
2007-09-28 10:20:02 +00:00
|
|
|
/* Tell the COP it's safe to continue rebooting */
|
|
|
|
cpu_message = 1;
|
|
|
|
|
2007-03-04 23:53:38 +00:00
|
|
|
/* Wait for the COP to tell us it is rebooting */
|
2007-09-28 10:20:02 +00:00
|
|
|
while(cpu_reply != 2);
|
2007-09-29 06:56:21 +00:00
|
|
|
#endif
|
2007-11-15 06:44:35 +00:00
|
|
|
|
2006-07-23 14:30:10 +00:00
|
|
|
asm volatile(
|
2010-05-31 14:42:27 +00:00
|
|
|
"bx %0 \n"
|
2010-05-03 21:50:48 +00:00
|
|
|
: : "r"(DRAM_START)
|
2006-07-23 14:30:10 +00:00
|
|
|
);
|
2008-04-15 20:02:24 +00:00
|
|
|
|
2009-10-19 21:32:40 +00:00
|
|
|
#elif defined(CPU_ARM)
|
2008-04-16 23:49:21 +00:00
|
|
|
/* Flush and invalidate caches */
|
2011-12-17 07:27:24 +00:00
|
|
|
commit_discard_idcache();
|
2008-04-15 20:02:24 +00:00
|
|
|
asm volatile(
|
2010-05-31 14:42:27 +00:00
|
|
|
"bx %0 \n"
|
2008-04-15 20:02:24 +00:00
|
|
|
: : "r"(dest)
|
|
|
|
);
|
2009-02-26 21:15:40 +00:00
|
|
|
#elif defined(CPU_MIPS)
|
2020-08-29 01:45:58 +00:00
|
|
|
commit_discard_idcache();
|
2009-02-26 21:15:40 +00:00
|
|
|
asm volatile(
|
|
|
|
"jr %0 \n"
|
|
|
|
: : "r"(dest)
|
|
|
|
);
|
2005-11-11 17:51:35 +00:00
|
|
|
#endif
|
2005-03-31 08:47:02 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* This is assigned in the linker control file */
|
|
|
|
extern unsigned long loadaddress;
|
2003-10-12 16:40:45 +00:00
|
|
|
|
2002-09-03 09:44:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
*
|
2012-03-02 15:49:05 +00:00
|
|
|
* Name: rolo_load(const char *filename)
|
2002-09-03 09:44:08 +00:00
|
|
|
* Filename must be a fully defined filename including the path and extension
|
|
|
|
*
|
|
|
|
***************************************************************************/
|
2012-03-04 14:34:29 +00:00
|
|
|
#if defined(CPU_COLDFIRE) || defined(CPU_ARM) || defined(CPU_MIPS)
|
2012-03-02 15:49:05 +00:00
|
|
|
int rolo_load(const char* filename)
|
|
|
|
{
|
|
|
|
unsigned char* ramstart = (void*)&loadaddress;
|
|
|
|
unsigned char* filebuf;
|
|
|
|
size_t filebuf_size;
|
2017-11-07 21:48:07 +00:00
|
|
|
int err, length;
|
2012-03-02 15:49:05 +00:00
|
|
|
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_puts(0, 0, "ROLO...");
|
|
|
|
lcd_puts(0, 1, "Loading");
|
|
|
|
lcd_update();
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
lcd_remote_clear_display();
|
|
|
|
lcd_remote_puts(0, 0, "ROLO...");
|
|
|
|
lcd_remote_puts(0, 1, "Loading");
|
|
|
|
lcd_remote_update();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
audio_stop();
|
|
|
|
|
|
|
|
/* get the system buffer. release only in case of error, otherwise
|
|
|
|
* we don't return anyway */
|
|
|
|
rolo_handle = core_alloc_maximum("rolo", &filebuf_size, NULL);
|
|
|
|
filebuf = core_get_data(rolo_handle);
|
|
|
|
|
2017-11-07 21:48:07 +00:00
|
|
|
err = LOAD_FIRMWARE(filebuf, filename, filebuf_size);
|
2020-08-08 06:33:49 +00:00
|
|
|
#if defined(HAVE_BOOTDATA) && !defined(SIMULATOR)
|
|
|
|
/* write the bootdata as if rolo were the bootloader */
|
|
|
|
unsigned int crc = 0;
|
|
|
|
if (strcmp(filename, BOOTDIR "/" BOOTFILE) == 0)
|
|
|
|
crc = crc_32(boot_data.payload, boot_data.length, 0xffffffff);
|
|
|
|
|
|
|
|
if(crc > 0 && crc == boot_data.crc)
|
|
|
|
write_bootdata(filebuf, filebuf_size, boot_data.boot_volume); /* rb-loader.c */
|
|
|
|
#endif
|
2012-03-04 14:34:29 +00:00
|
|
|
|
2017-11-07 21:48:07 +00:00
|
|
|
if (err <= 0)
|
2012-03-02 15:49:05 +00:00
|
|
|
{
|
2017-11-07 21:48:07 +00:00
|
|
|
rolo_error(loader_strerror(err));
|
2012-03-02 15:49:05 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
else
|
2017-11-07 21:48:07 +00:00
|
|
|
length = err;
|
2012-03-02 15:49:05 +00:00
|
|
|
|
2012-03-04 14:34:29 +00:00
|
|
|
#if defined(CPU_PP) && NUM_CORES > 1
|
|
|
|
lcd_puts(0, 2, "Waiting for coprocessor...");
|
|
|
|
lcd_update();
|
|
|
|
rolo_restart_cop();
|
|
|
|
/* Wait for COP to be in safe code */
|
|
|
|
while(cpu_reply != 1);
|
|
|
|
lcd_puts(0, 2, " ");
|
|
|
|
lcd_update();
|
|
|
|
#endif
|
|
|
|
|
2012-03-02 15:49:05 +00:00
|
|
|
#ifdef HAVE_STORAGE_FLUSH
|
|
|
|
lcd_puts(0, 1, "Flushing storage buffers");
|
|
|
|
lcd_update();
|
|
|
|
storage_flush();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
lcd_puts(0, 1, "Executing");
|
|
|
|
lcd_update();
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
lcd_remote_puts(0, 1, "Executing");
|
|
|
|
lcd_remote_update();
|
|
|
|
#endif
|
2020-09-13 17:29:00 +00:00
|
|
|
#if (CONFIG_KEYPAD != XDUOO_X3_PAD) /* X3 adc hangs on ROLO */
|
2012-03-02 15:49:05 +00:00
|
|
|
adc_close();
|
2020-09-13 17:29:00 +00:00
|
|
|
#endif
|
2016-01-18 23:21:10 +00:00
|
|
|
#if CONFIG_CPU == AS3525v2
|
|
|
|
/* Set CVDD1 power supply to default*/
|
|
|
|
ascodec_write_pmu(0x17, 1, 0);
|
|
|
|
#endif
|
2016-04-22 12:17:35 +00:00
|
|
|
#if defined(SANSA_FUZEV2) || defined(SANSA_CLIPPLUS) || defined(SANSA_CLIPZIP)
|
|
|
|
/* It is necessary for proper detection AMSv2 variant 1.
|
|
|
|
* We should restore initial state of GPIOB_PIN(5) as it used for
|
|
|
|
* variant detection, but can be changed if we switch SD card. */
|
|
|
|
if (amsv2_variant == 1)
|
|
|
|
GPIOB_PIN(5) = 1 << 5;
|
|
|
|
#endif
|
2012-03-02 15:49:05 +00:00
|
|
|
|
2012-03-04 14:34:29 +00:00
|
|
|
#if CONFIG_CPU != IMX31L /* We're not finished yet */
|
|
|
|
#ifdef CPU_ARM
|
|
|
|
/* Should do these together since some ARM version should never have
|
|
|
|
* FIQ disabled and not IRQ (imx31 errata). */
|
2012-03-02 15:49:05 +00:00
|
|
|
disable_interrupt(IRQ_FIQ_STATUS);
|
2012-03-04 14:34:29 +00:00
|
|
|
#else
|
|
|
|
/* Some targets have a higher disable level than HIGEST_IRQ_LEVEL */
|
|
|
|
set_irq_level(DISABLE_INTERRUPTS);
|
|
|
|
#endif
|
|
|
|
#endif /* CONFIG_CPU == IMX31L */
|
2012-03-02 15:49:05 +00:00
|
|
|
|
|
|
|
rolo_restart(filebuf, ramstart, length);
|
|
|
|
|
|
|
|
/* never reached */
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-15 23:40:55 +00:00
|
|
|
#endif /* CPU_COLDFIRE | CPU_ARM | CPU_MIPS */
|
2006-11-10 20:26:01 +00:00
|
|
|
#else /* !defined(IRIVER_IFP7XX_SERIES) */
|
2005-02-02 21:47:08 +00:00
|
|
|
int rolo_load(const char* filename)
|
|
|
|
{
|
|
|
|
/* dummy */
|
2005-02-03 10:07:11 +00:00
|
|
|
(void)filename;
|
|
|
|
return 0;
|
2005-02-02 21:47:08 +00:00
|
|
|
}
|
|
|
|
|
2006-11-10 20:26:01 +00:00
|
|
|
#endif /* !defined(IRIVER_IFP7XX_SERIES) */
|