2003-09-09 07:02:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Plugin for reprogramming the whole Flash ROM chip with a new content.
|
2004-06-29 13:12:07 +00:00
|
|
|
* !!! DON'T MESS WITH THIS CODE UNLESS YOU'RE ABSOLUTELY SURE WHAT YOU DO !!!
|
2003-09-09 07:02:53 +00:00
|
|
|
*
|
2008-05-05 10:32:46 +00:00
|
|
|
* Copyright (C) 2003 Jörg Hohensohn [IDC]Dragon
|
2003-09-09 07:02:53 +00:00
|
|
|
*
|
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.
|
2003-09-09 07:02:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
/* define DUMMY if you only want to "play" with the UI, does no harm */
|
|
|
|
/* #define DUMMY */
|
|
|
|
|
|
|
|
#ifndef UINT8
|
|
|
|
#define UINT8 unsigned char
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef UINT16
|
|
|
|
#define UINT16 unsigned short
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef UINT32
|
|
|
|
#define UINT32 unsigned long
|
|
|
|
#endif
|
|
|
|
|
2003-11-30 17:24:42 +00:00
|
|
|
/* platform IDs as I have used them in my firmware templates */
|
|
|
|
#define ID_RECORDER 0
|
|
|
|
#define ID_FM 1
|
|
|
|
#define ID_PLAYER 2
|
|
|
|
#define ID_REC_V2 3
|
2004-10-07 17:16:27 +00:00
|
|
|
#define ID_ONDIO_FM 4
|
|
|
|
#define ID_ONDIO_SP 5
|
2003-11-30 17:24:42 +00:00
|
|
|
|
2004-01-02 07:48:02 +00:00
|
|
|
/* Here I have to check for ARCHOS_* defines in source code, which is
|
|
|
|
generally strongly discouraged. But here I'm not checking for a certain
|
|
|
|
feature, I'm checking for the model itself. */
|
2003-09-09 07:02:53 +00:00
|
|
|
#if defined(ARCHOS_PLAYER)
|
2003-10-26 21:23:04 +00:00
|
|
|
#define FILE_TYPE "player"
|
2003-09-09 07:02:53 +00:00
|
|
|
#define KEEP VERSION_ADR /* keep the firmware version */
|
2003-11-30 17:24:42 +00:00
|
|
|
#define PLATFORM_ID ID_PLAYER
|
2003-09-09 07:02:53 +00:00
|
|
|
#elif defined(ARCHOS_RECORDER)
|
2003-10-26 21:23:04 +00:00
|
|
|
#define FILE_TYPE "rec"
|
2003-09-09 07:02:53 +00:00
|
|
|
#define KEEP MASK_ADR /* keep the mask value */
|
2003-11-30 17:24:42 +00:00
|
|
|
#define PLATFORM_ID ID_RECORDER
|
|
|
|
#elif defined(ARCHOS_RECORDERV2)
|
|
|
|
#define FILE_TYPE "v2"
|
|
|
|
#define KEEP MASK_ADR /* keep the mask value */
|
|
|
|
#define PLATFORM_ID ID_REC_V2
|
2003-09-09 07:02:53 +00:00
|
|
|
#elif defined(ARCHOS_FMRECORDER)
|
2003-10-26 21:23:04 +00:00
|
|
|
#define FILE_TYPE "fm"
|
2003-09-09 07:02:53 +00:00
|
|
|
#define KEEP MASK_ADR /* keep the mask value */
|
2003-11-30 17:24:42 +00:00
|
|
|
#define PLATFORM_ID ID_FM
|
2004-10-07 17:16:27 +00:00
|
|
|
#elif defined(ARCHOS_ONDIOFM)
|
|
|
|
#define FILE_TYPE "ondiofm"
|
|
|
|
#define KEEP MASK_ADR /* keep the mask value */
|
|
|
|
#define PLATFORM_ID ID_ONDIO_FM
|
|
|
|
#elif defined(ARCHOS_ONDIOSP)
|
|
|
|
#define FILE_TYPE "ondiosp"
|
|
|
|
#define KEEP MASK_ADR /* keep the mask value */
|
|
|
|
#define PLATFORM_ID ID_ONDIO_SP
|
2003-09-09 07:02:53 +00:00
|
|
|
#else
|
2010-05-31 00:02:20 +00:00
|
|
|
#error this platform is not (yet) flashable
|
2003-09-09 07:02:53 +00:00
|
|
|
#endif
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2004-10-07 17:16:27 +00:00
|
|
|
#if CONFIG_KEYPAD == ONDIO_PAD /* limited keypad */
|
2004-10-22 20:21:00 +00:00
|
|
|
#define KEY1 BUTTON_LEFT
|
|
|
|
#define KEY2 BUTTON_UP
|
|
|
|
#define KEY3 BUTTON_RIGHT
|
|
|
|
#define KEYNAME1 "[Left]"
|
|
|
|
#define KEYNAME2 "[Up]"
|
|
|
|
#define KEYNAME3 "[Right]"
|
2004-10-07 17:16:27 +00:00
|
|
|
#else /* recorder keypad */
|
|
|
|
#define KEY1 BUTTON_F1
|
|
|
|
#define KEY2 BUTTON_F2
|
|
|
|
#define KEY3 BUTTON_F3
|
|
|
|
#define KEYNAME1 "[F1]"
|
|
|
|
#define KEYNAME2 "[F2]"
|
|
|
|
#define KEYNAME3 "[F3]"
|
|
|
|
#endif
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
/* result of the CheckFirmwareFile() function */
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
eOK = 0,
|
|
|
|
eFileNotFound, /* errors from here on */
|
|
|
|
eTooBig,
|
|
|
|
eTooSmall,
|
|
|
|
eReadErr,
|
|
|
|
eBadContent,
|
|
|
|
eCrcErr,
|
2003-11-30 17:24:42 +00:00
|
|
|
eBadPlatform,
|
2003-09-09 07:02:53 +00:00
|
|
|
} tCheckResult;
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
/* result of the CheckBootROM() function */
|
|
|
|
typedef enum
|
|
|
|
{
|
2005-01-08 01:06:15 +00:00
|
|
|
eBootROM, /* the supported boot ROM(s) */
|
2003-10-26 21:23:04 +00:00
|
|
|
eUnknown, /* unknown boot ROM */
|
|
|
|
eROMless, /* flash mapped to zero */
|
|
|
|
} tCheckROM;
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
UINT8 manufacturer;
|
|
|
|
UINT8 id;
|
|
|
|
int size;
|
|
|
|
char name[32];
|
|
|
|
} tFlashInfo;
|
|
|
|
|
2003-11-30 17:24:42 +00:00
|
|
|
#define MASK_ADR 0xFC /* position of hardware mask value in Flash */
|
|
|
|
#define VERSION_ADR 0xFE /* position of firmware version value in Flash */
|
|
|
|
#define PLATFORM_ADR 0xFB /* position of my platform ID value in Flash */
|
2003-09-09 07:02:53 +00:00
|
|
|
#define SEC_SIZE 4096 /* size of one flash sector */
|
|
|
|
static UINT8* sector; /* better not place this on the stack... */
|
|
|
|
static volatile UINT8* FB = (UINT8*)0x02000000; /* Flash base address */
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Flash Functions *****************/
|
|
|
|
|
|
|
|
|
|
|
|
/* read the manufacturer and device ID */
|
|
|
|
bool ReadID(volatile UINT8* pBase, UINT8* pManufacturerID, UINT8* pDeviceID)
|
|
|
|
{
|
|
|
|
UINT8 not_manu, not_id; /* read values before switching to ID mode */
|
|
|
|
UINT8 manu, id; /* read values when in ID mode */
|
|
|
|
|
|
|
|
pBase = (UINT8*)((UINT32)pBase & 0xFFF80000); /* down to 512k align */
|
|
|
|
|
|
|
|
/* read the normal content */
|
|
|
|
not_manu = pBase[0]; /* should be 'A' (0x41) and 'R' (0x52) */
|
|
|
|
not_id = pBase[1]; /* from the "ARCH" marker */
|
|
|
|
|
|
|
|
pBase[0x5555] = 0xAA; /* enter command mode */
|
|
|
|
pBase[0x2AAA] = 0x55;
|
|
|
|
pBase[0x5555] = 0x90; /* ID command */
|
|
|
|
rb->sleep(HZ/50); /* Atmel wants 20ms pause here */
|
|
|
|
|
|
|
|
manu = pBase[0];
|
|
|
|
id = pBase[1];
|
|
|
|
|
|
|
|
pBase[0] = 0xF0; /* reset flash (back to normal read mode) */
|
|
|
|
rb->sleep(HZ/50); /* Atmel wants 20ms pause here */
|
|
|
|
|
|
|
|
/* I assume success if the obtained values are different from
|
|
|
|
the normal flash content. This is not perfectly bulletproof, they
|
|
|
|
could theoretically be the same by chance, causing us to fail. */
|
|
|
|
if (not_manu != manu || not_id != id) /* a value has changed */
|
|
|
|
{
|
|
|
|
*pManufacturerID = manu; /* return the results */
|
|
|
|
*pDeviceID = id;
|
|
|
|
return true; /* success */
|
|
|
|
}
|
|
|
|
return false; /* fail */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* erase the sector which contains the given address */
|
|
|
|
bool EraseSector(volatile UINT8* pAddr)
|
|
|
|
{
|
|
|
|
#ifdef DUMMY
|
|
|
|
(void)pAddr; /* prevents warning */
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
volatile UINT8* pBase = (UINT8*)((UINT32)pAddr & 0xFFF80000); /* round down to 512k align */
|
|
|
|
unsigned timeout = 43000; /* the timeout loop should be no less than 25ms */
|
|
|
|
|
|
|
|
pBase[0x5555] = 0xAA; /* enter command mode */
|
|
|
|
pBase[0x2AAA] = 0x55;
|
|
|
|
pBase[0x5555] = 0x80; /* erase command */
|
|
|
|
pBase[0x5555] = 0xAA; /* enter command mode */
|
|
|
|
pBase[0x2AAA] = 0x55;
|
|
|
|
*pAddr = 0x30; /* erase the sector */
|
|
|
|
|
|
|
|
/* I counted 7 instructions for this loop -> min. 0.58 us per round */
|
|
|
|
/* Plus memory waitstates it will be much more, gives margin */
|
|
|
|
while (*pAddr != 0xFF && --timeout); /* poll for erased */
|
|
|
|
|
|
|
|
return (timeout != 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* address must be in an erased location */
|
|
|
|
inline bool ProgramByte(volatile UINT8* pAddr, UINT8 data)
|
|
|
|
{
|
|
|
|
#ifdef DUMMY
|
|
|
|
(void)pAddr; /* prevents warnings */
|
|
|
|
(void)data;
|
|
|
|
return true;
|
|
|
|
#else
|
|
|
|
unsigned timeout = 35; /* the timeout loop should be no less than 20us */
|
|
|
|
|
|
|
|
if (~*pAddr & data) /* just a safety feature, not really necessary */
|
|
|
|
return false; /* can't set any bit from 0 to 1 */
|
|
|
|
|
|
|
|
FB[0x5555] = 0xAA; /* enter command mode */
|
|
|
|
FB[0x2AAA] = 0x55;
|
|
|
|
FB[0x5555] = 0xA0; /* byte program command */
|
|
|
|
|
|
|
|
*pAddr = data;
|
|
|
|
|
|
|
|
/* I counted 7 instructions for this loop -> min. 0.58 us per round */
|
|
|
|
/* Plus memory waitstates it will be much more, gives margin */
|
|
|
|
while (*pAddr != data && --timeout); /* poll for programmed */
|
|
|
|
|
|
|
|
return (timeout != 0);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* this returns true if supported and fills the info struct */
|
|
|
|
bool GetFlashInfo(tFlashInfo* pInfo)
|
|
|
|
{
|
|
|
|
rb->memset(pInfo, 0, sizeof(tFlashInfo));
|
|
|
|
|
|
|
|
if (!ReadID(FB, &pInfo->manufacturer, &pInfo->id))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (pInfo->manufacturer == 0xBF) /* SST */
|
|
|
|
{
|
|
|
|
if (pInfo->id == 0xD6)
|
|
|
|
{
|
|
|
|
pInfo->size = 256* 1024; /* 256k */
|
|
|
|
rb->strcpy(pInfo->name, "SST39VF020");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (pInfo->id == 0xD7)
|
|
|
|
{
|
|
|
|
pInfo->size = 512* 1024; /* 512k */
|
|
|
|
rb->strcpy(pInfo->name, "SST39VF040");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-11-30 17:24:42 +00:00
|
|
|
/*********** Firmware File Functions + helpers ************/
|
|
|
|
|
|
|
|
/* test if the version number is consistent with the platform */
|
|
|
|
bool CheckPlatform(int platform_id, UINT16 version)
|
|
|
|
{
|
2003-12-07 08:21:09 +00:00
|
|
|
if (version == 200)
|
|
|
|
{ /* for my very first firmwares, I foolishly changed it to 200 */
|
|
|
|
return (platform_id == ID_RECORDER || platform_id == ID_FM);
|
|
|
|
}
|
|
|
|
else if (version == 123)
|
2003-11-30 17:24:42 +00:00
|
|
|
{ /* it can be a FM or V2 recorder */
|
|
|
|
return (platform_id == ID_FM || platform_id == ID_REC_V2);
|
|
|
|
}
|
2004-01-05 07:26:59 +00:00
|
|
|
else if (version == 132)
|
2004-10-22 20:21:00 +00:00
|
|
|
{ /* newer Ondio, and seen on a V2 recorder */
|
2004-10-07 17:16:27 +00:00
|
|
|
return (platform_id == ID_ONDIO_SP || platform_id == ID_ONDIO_FM
|
|
|
|
|| platform_id == ID_REC_V2);
|
2004-01-05 07:26:59 +00:00
|
|
|
}
|
2004-10-22 20:21:00 +00:00
|
|
|
else if (version == 104)
|
|
|
|
{ /* classic Ondio128 */
|
|
|
|
return (platform_id == ID_ONDIO_FM);
|
|
|
|
}
|
2004-01-02 07:48:02 +00:00
|
|
|
else if (version >= 115 && version <= 129)
|
2003-12-07 08:21:09 +00:00
|
|
|
{ /* the range of Recorders seen so far */
|
2003-11-30 17:24:42 +00:00
|
|
|
return (platform_id == ID_RECORDER);
|
|
|
|
}
|
2004-12-30 21:51:58 +00:00
|
|
|
else if (version == 0 || (version >= 300 && version <= 508))
|
2003-11-30 17:24:42 +00:00
|
|
|
{ /* for very old players, I've seen zero */
|
|
|
|
return (platform_id == ID_PLAYER);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; /* unknown */
|
|
|
|
}
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
tCheckResult CheckFirmwareFile(char* filename, int chipsize, bool is_romless)
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int fd;
|
|
|
|
int fileleft; /* size info, how many left for reading */
|
|
|
|
int fileread = 0; /* total size as read from the file */
|
|
|
|
int read_now; /* how many to read for this sector */
|
|
|
|
int got_now; /* how many gotten for this sector */
|
|
|
|
unsigned crc32 = 0xFFFFFFFF; /* CCITT init value */
|
|
|
|
unsigned file_crc; /* CRC value read from file */
|
|
|
|
bool has_crc;
|
|
|
|
|
|
|
|
fd = rb->open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return eFileNotFound;
|
|
|
|
|
|
|
|
fileleft = rb->filesize(fd);
|
|
|
|
if (fileleft > chipsize)
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eTooBig;
|
|
|
|
}
|
2005-08-23 08:00:16 +00:00
|
|
|
else if (fileleft < 20000) /* give it some reasonable lower limit */
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eTooSmall;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileleft == 256*1024)
|
2006-03-03 08:14:44 +00:00
|
|
|
{ /* original dumped firmware file has no CRC nor platform ID */
|
2003-09-09 07:02:53 +00:00
|
|
|
has_crc = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
has_crc = true;
|
2006-03-03 08:14:44 +00:00
|
|
|
fileleft -= sizeof(unsigned); /* exclude the last 4 bytes */
|
2003-09-09 07:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* do some sanity checks */
|
|
|
|
|
|
|
|
got_now = rb->read(fd, sector, SEC_SIZE); /* read first sector */
|
|
|
|
fileread += got_now;
|
|
|
|
fileleft -= got_now;
|
|
|
|
if (got_now != SEC_SIZE)
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eReadErr;
|
|
|
|
}
|
|
|
|
|
2003-12-12 10:45:50 +00:00
|
|
|
/* version number in file plausible with this hardware? */
|
2003-11-30 17:24:42 +00:00
|
|
|
if (!CheckPlatform(PLATFORM_ID, *(UINT16*)(sector + VERSION_ADR)))
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eBadPlatform;
|
|
|
|
}
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
if (has_crc)
|
2003-11-30 17:24:42 +00:00
|
|
|
{
|
2009-11-22 19:08:29 +00:00
|
|
|
crc32 = rb->crc_32(sector, SEC_SIZE, crc32); /* checksum */
|
2003-11-30 17:24:42 +00:00
|
|
|
|
|
|
|
/* in addition to the CRC, my files also have a platform ID */
|
|
|
|
if (sector[PLATFORM_ADR] != PLATFORM_ID) /* for our hardware? */
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eBadPlatform;
|
|
|
|
}
|
|
|
|
}
|
2003-09-09 07:02:53 +00:00
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
if (is_romless)
|
|
|
|
{ /* in this case, there is not much we can check */
|
|
|
|
if (*(UINT32*)sector != 0x00000200) /* reset vector */
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eBadContent;
|
|
|
|
}
|
2003-09-09 07:02:53 +00:00
|
|
|
}
|
2003-10-26 21:23:04 +00:00
|
|
|
else
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
2003-10-26 21:23:04 +00:00
|
|
|
/* compare some bytes which have to be identical */
|
|
|
|
if (*(UINT32*)sector != 0x41524348) /* "ARCH" */
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eBadContent;
|
|
|
|
}
|
2003-10-26 21:23:04 +00:00
|
|
|
|
2004-10-07 17:16:27 +00:00
|
|
|
for (i = 0x30; i<MASK_ADR-2; i++) /* leave two bytes for me */
|
2003-10-26 21:23:04 +00:00
|
|
|
{
|
|
|
|
if (sector[i] != FB[i])
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eBadContent;
|
|
|
|
}
|
|
|
|
}
|
2003-09-09 07:02:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* check if we can read the whole file, and do checksum */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
read_now = MIN(SEC_SIZE, fileleft);
|
|
|
|
got_now = rb->read(fd, sector, read_now);
|
|
|
|
fileread += got_now;
|
|
|
|
fileleft -= got_now;
|
|
|
|
|
|
|
|
if (read_now != got_now)
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eReadErr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (has_crc)
|
|
|
|
{
|
2009-11-22 19:08:29 +00:00
|
|
|
crc32 = rb->crc_32(sector, got_now, crc32); /* checksum */
|
2003-09-09 07:02:53 +00:00
|
|
|
}
|
|
|
|
} while (fileleft);
|
|
|
|
|
|
|
|
if (has_crc)
|
|
|
|
{
|
|
|
|
got_now = rb->read(fd, &file_crc, sizeof(file_crc));
|
|
|
|
if (got_now != sizeof(file_crc))
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
return eReadErr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* must be EOF now */
|
|
|
|
got_now = rb->read(fd, sector, SEC_SIZE);
|
|
|
|
rb->close(fd);
|
|
|
|
if (got_now != 0)
|
|
|
|
return eReadErr;
|
|
|
|
|
|
|
|
if (has_crc && file_crc != crc32)
|
|
|
|
return eCrcErr;
|
|
|
|
|
|
|
|
return eOK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* returns the # of failures, 0 on success */
|
|
|
|
unsigned ProgramFirmwareFile(char* filename, int chipsize)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
int fd;
|
|
|
|
int read = SEC_SIZE; /* how many for this sector */
|
|
|
|
UINT16 keep = *(UINT16*)(FB + KEEP); /* we must keep this! */
|
|
|
|
unsigned failures = 0;
|
|
|
|
|
|
|
|
fd = rb->open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (i=0; i<chipsize; i+=SEC_SIZE)
|
|
|
|
{
|
|
|
|
if (!EraseSector(FB + i))
|
|
|
|
{
|
|
|
|
/* nothing we can do, let the programming count the errors */
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read == SEC_SIZE) /* not EOF yet */
|
|
|
|
{
|
|
|
|
read = rb->read(fd, sector, SEC_SIZE);
|
|
|
|
if (i==0)
|
|
|
|
{ /* put original value back in */
|
|
|
|
*(UINT16*)(sector + KEEP) = keep;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (j=0; j<read; j++)
|
|
|
|
{
|
|
|
|
if (!ProgramByte(FB + i + j, sector[j]))
|
|
|
|
{
|
|
|
|
failures++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->close(fd);
|
|
|
|
|
|
|
|
return failures;
|
|
|
|
}
|
|
|
|
|
2003-11-30 17:24:42 +00:00
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
/* returns the # of failures, 0 on success */
|
|
|
|
unsigned VerifyFirmwareFile(char* filename)
|
|
|
|
{
|
|
|
|
int i=0, j;
|
|
|
|
int fd;
|
|
|
|
int read = SEC_SIZE; /* how many for this sector */
|
|
|
|
unsigned failures = 0;
|
|
|
|
|
|
|
|
fd = rb->open(filename, O_RDONLY);
|
|
|
|
if (fd < 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
read = rb->read(fd, sector, SEC_SIZE);
|
|
|
|
|
|
|
|
for (j=0; j<read; j++)
|
|
|
|
{
|
|
|
|
/* position of keep value is no error */
|
|
|
|
if (FB[i] != sector[j] && i != KEEP && i != (KEEP+1))
|
|
|
|
{
|
|
|
|
failures++;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (read == SEC_SIZE);
|
|
|
|
|
|
|
|
rb->close(fd);
|
|
|
|
|
|
|
|
return failures;
|
|
|
|
}
|
|
|
|
|
2003-11-30 17:24:42 +00:00
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
/***************** Support Functions *****************/
|
|
|
|
|
|
|
|
/* check if we have "normal" boot ROM or flash mirrored to zero */
|
|
|
|
tCheckROM CheckBootROM(void)
|
|
|
|
{
|
|
|
|
unsigned boot_crc;
|
|
|
|
unsigned* pFlash = (unsigned*)FB;
|
|
|
|
unsigned* pRom = (unsigned*)0x0;
|
|
|
|
unsigned i;
|
|
|
|
|
2009-11-22 19:30:14 +00:00
|
|
|
boot_crc = rb->crc_32((unsigned char*)0x0, 64*1024, 0xFFFFFFFF);
|
2005-01-08 01:06:15 +00:00
|
|
|
if (boot_crc == 0x56DBA4EE /* the known boot ROM */
|
|
|
|
#if PLATFORM_ID == ID_PLAYER
|
|
|
|
/* alternative boot ROM found in one single player so far */
|
|
|
|
|| boot_crc == 0x358099E8
|
|
|
|
#endif
|
|
|
|
)
|
2003-10-26 21:23:04 +00:00
|
|
|
return eBootROM;
|
|
|
|
|
|
|
|
/* check if ROM is a flash mirror */
|
|
|
|
for (i=0; i<256*1024/sizeof(unsigned); i++)
|
|
|
|
{
|
|
|
|
if (*pRom++ != *pFlash++)
|
|
|
|
{ /* difference means no mirror */
|
|
|
|
return eUnknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return eROMless;
|
|
|
|
}
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
/***************** User Interface Functions *****************/
|
|
|
|
|
|
|
|
int WaitForButton(void)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
button = rb->button_get(true);
|
2009-01-03 13:27:19 +00:00
|
|
|
} while (IS_SYSEVENT(button) || (button & BUTTON_REL));
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
/* Recorder implementation */
|
|
|
|
|
|
|
|
/* helper for DoUserDialog() */
|
|
|
|
void ShowFlashInfo(tFlashInfo* pInfo)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
if (!pInfo->manufacturer)
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, 0, "Flash: M=?? D=??");
|
|
|
|
rb->lcd_puts(0, 1, "Impossible to program");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Flash: M=%02x D=%02x",
|
|
|
|
pInfo->manufacturer, pInfo->id);
|
|
|
|
rb->lcd_puts(0, 0, buf);
|
|
|
|
|
|
|
|
|
|
|
|
if (pInfo->size)
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, 1, pInfo->name);
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Size: %d KB", pInfo->size / 1024);
|
|
|
|
rb->lcd_puts(0, 2, buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, 1, "Unsupported chip");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Kind of our main function, defines the application flow. */
|
2003-10-26 21:23:04 +00:00
|
|
|
void DoUserDialog(char* filename)
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
tFlashInfo FlashInfo;
|
|
|
|
char buf[32];
|
2003-10-26 21:23:04 +00:00
|
|
|
char default_filename[32];
|
2003-09-09 07:02:53 +00:00
|
|
|
int button;
|
|
|
|
int rc; /* generic return code */
|
2010-05-07 19:27:42 +00:00
|
|
|
size_t memleft;
|
2003-10-26 21:23:04 +00:00
|
|
|
tCheckROM result;
|
|
|
|
bool is_romless;
|
2003-09-09 07:02:53 +00:00
|
|
|
|
2004-07-20 22:54:04 +00:00
|
|
|
/* this can only work if Rockbox runs in DRAM, not flash ROM */
|
|
|
|
if ((UINT8*)rb >= FB && (UINT8*)rb < FB + 4096*1024) /* 4 MB max */
|
|
|
|
{ /* we're running from flash */
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Not from ROM");
|
2004-07-20 22:54:04 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2003-11-30 17:24:42 +00:00
|
|
|
/* test if the user is running the correct plugin for this box */
|
|
|
|
if (!CheckPlatform(PLATFORM_ID, *(UINT16*)(FB + VERSION_ADR)))
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Wrong plugin");
|
2003-11-30 17:24:42 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2004-10-23 16:28:06 +00:00
|
|
|
/* refuse to work if the power may fail meanwhile */
|
|
|
|
if (!rb->battery_level_safe())
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Battery too low!");
|
2004-10-23 16:28:06 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
/* check boot ROM */
|
2003-10-26 21:23:04 +00:00
|
|
|
result = CheckBootROM();
|
|
|
|
if (result == eUnknown)
|
2003-09-09 07:02:53 +00:00
|
|
|
{ /* no support for any other yet */
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Wrong boot ROM");
|
2003-09-09 07:02:53 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
2003-10-26 21:23:04 +00:00
|
|
|
is_romless = (result == eROMless);
|
|
|
|
|
|
|
|
/* compose filename if none given */
|
|
|
|
if (filename == NULL)
|
|
|
|
{
|
|
|
|
rb->snprintf(
|
|
|
|
default_filename,
|
|
|
|
sizeof(default_filename),
|
|
|
|
"/firmware_%s%s.bin",
|
|
|
|
FILE_TYPE,
|
|
|
|
is_romless ? "_norom" : "");
|
|
|
|
filename = default_filename;
|
|
|
|
}
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
/* "allocate" memory */
|
2010-05-07 19:27:42 +00:00
|
|
|
sector = rb->plugin_get_buffer(&memleft);
|
2003-09-09 07:02:53 +00:00
|
|
|
if (memleft < SEC_SIZE) /* need buffer for a flash sector */
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Out of memory");
|
2003-09-09 07:02:53 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2004-10-23 16:28:06 +00:00
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
rc = GetFlashInfo(&FlashInfo);
|
|
|
|
ShowFlashInfo(&FlashInfo);
|
|
|
|
if (FlashInfo.size == 0) /* no valid chip */
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Sorry!");
|
2003-09-09 07:02:53 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_puts(0, 3, "using file:");
|
2003-10-26 21:23:04 +00:00
|
|
|
rb->lcd_puts_scroll(0, 4, filename);
|
2004-10-07 17:16:27 +00:00
|
|
|
rb->lcd_puts(0, 6, KEYNAME1 " to check file");
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts(0, 7, "other key to exit");
|
|
|
|
rb->lcd_update();
|
|
|
|
|
|
|
|
button = WaitForButton();
|
2004-10-07 17:16:27 +00:00
|
|
|
if (button != KEY1)
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "checking...");
|
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
rc = CheckFirmwareFile(filename, FlashInfo.size, is_romless);
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts(0, 0, "checked:");
|
|
|
|
switch (rc)
|
|
|
|
{
|
|
|
|
case eOK:
|
|
|
|
rb->lcd_puts(0, 1, "File OK.");
|
|
|
|
break;
|
|
|
|
case eFileNotFound:
|
|
|
|
rb->lcd_puts(0, 1, "File not found.");
|
|
|
|
rb->lcd_puts(0, 2, "Put this in root:");
|
2003-10-26 21:23:04 +00:00
|
|
|
rb->lcd_puts_scroll(0, 4, filename);
|
2003-09-09 07:02:53 +00:00
|
|
|
break;
|
|
|
|
case eTooBig:
|
|
|
|
rb->lcd_puts(0, 1, "File too big,");
|
|
|
|
rb->lcd_puts(0, 2, "larger than chip.");
|
|
|
|
break;
|
|
|
|
case eTooSmall:
|
|
|
|
rb->lcd_puts(0, 1, "File too small.");
|
|
|
|
rb->lcd_puts(0, 2, "Incomplete?");
|
|
|
|
break;
|
|
|
|
case eReadErr:
|
|
|
|
rb->lcd_puts(0, 1, "Read error.");
|
|
|
|
break;
|
|
|
|
case eBadContent:
|
|
|
|
rb->lcd_puts(0, 1, "File invalid.");
|
|
|
|
rb->lcd_puts(0, 2, "Sanity check fail.");
|
|
|
|
break;
|
|
|
|
case eCrcErr:
|
|
|
|
rb->lcd_puts(0, 1, "File invalid.");
|
|
|
|
rb->lcd_puts(0, 2, "CRC check failed,");
|
|
|
|
rb->lcd_puts(0, 3, "checksum mismatch.");
|
|
|
|
break;
|
2003-11-30 17:24:42 +00:00
|
|
|
case eBadPlatform:
|
|
|
|
rb->lcd_puts(0, 1, "Wrong file for");
|
|
|
|
rb->lcd_puts(0, 2, "this hardware.");
|
|
|
|
break;
|
2003-09-09 07:02:53 +00:00
|
|
|
default:
|
|
|
|
rb->lcd_puts(0, 1, "Check failed.");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rc == eOK)
|
|
|
|
{
|
2004-10-07 17:16:27 +00:00
|
|
|
rb->lcd_puts(0, 6, KEYNAME2 " to program");
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts(0, 7, "other key to exit");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* error occured */
|
|
|
|
rb->lcd_puts(0, 6, "Any key to exit");
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
|
|
|
|
button = WaitForButton();
|
2004-10-07 17:16:27 +00:00
|
|
|
if (button != KEY2 || rc != eOK)
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "Program all Flash?");
|
2004-06-29 13:12:07 +00:00
|
|
|
rb->lcd_puts(0, 1, "Are you sure?");
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts(0, 2, "If it goes wrong,");
|
|
|
|
rb->lcd_puts(0, 3, "it kills your box!");
|
|
|
|
rb->lcd_puts(0, 4, "See documentation.");
|
|
|
|
|
2004-10-07 17:16:27 +00:00
|
|
|
rb->lcd_puts(0, 6, KEYNAME3 " to proceed");
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts(0, 7, "other key to exit");
|
|
|
|
rb->lcd_update();
|
|
|
|
|
|
|
|
button = WaitForButton();
|
2004-10-07 17:16:27 +00:00
|
|
|
if (button != KEY3)
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "Programming...");
|
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
rc = ProgramFirmwareFile(filename, FlashInfo.size);
|
2003-09-09 07:02:53 +00:00
|
|
|
if (rc)
|
|
|
|
{ /* errors */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "Panic:");
|
|
|
|
rb->lcd_puts(0, 1, "Programming fail!");
|
|
|
|
rb->snprintf(buf, sizeof(buf), "%d errors", rc);
|
|
|
|
rb->lcd_puts(0, 2, buf);
|
|
|
|
rb->lcd_update();
|
|
|
|
button = WaitForButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "Verifying...");
|
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
rc = VerifyFirmwareFile(filename);
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, 0, "Verify OK.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, 0, "Panic:");
|
|
|
|
rb->lcd_puts(0, 1, "Verify fail!");
|
|
|
|
rb->snprintf(buf, sizeof(buf), "%d errors", rc);
|
|
|
|
rb->lcd_puts(0, 2, buf);
|
|
|
|
}
|
|
|
|
rb->lcd_puts(0, 7, "Any key to exit");
|
|
|
|
rb->lcd_update();
|
|
|
|
|
|
|
|
button = WaitForButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* HAVE_LCD_BITMAP */
|
|
|
|
/* Player implementation */
|
|
|
|
|
|
|
|
/* helper for DoUserDialog() */
|
|
|
|
void ShowFlashInfo(tFlashInfo* pInfo)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
if (!pInfo->manufacturer)
|
|
|
|
{
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Flash: M=? D=?");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "Impossible to program");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2003-09-09 07:02:53 +00:00
|
|
|
WaitForButton();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Flash: M=%02x D=%02x",
|
|
|
|
pInfo->manufacturer, pInfo->id);
|
|
|
|
rb->lcd_puts_scroll(0, 0, buf);
|
|
|
|
|
|
|
|
if (pInfo->size)
|
|
|
|
{
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Size: %d KB", pInfo->size / 1024);
|
|
|
|
rb->lcd_puts_scroll(0, 1, buf);
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2003-09-09 07:02:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->lcd_puts_scroll(0, 1, "Unsupported chip");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2003-09-09 07:02:53 +00:00
|
|
|
WaitForButton();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
void DoUserDialog(char* filename)
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
|
|
|
tFlashInfo FlashInfo;
|
|
|
|
char buf[32];
|
2003-10-26 21:23:04 +00:00
|
|
|
char default_filename[32];
|
2003-09-09 07:02:53 +00:00
|
|
|
int button;
|
|
|
|
int rc; /* generic return code */
|
2010-05-07 19:27:42 +00:00
|
|
|
size_t memleft;
|
2003-10-26 21:23:04 +00:00
|
|
|
tCheckROM result;
|
|
|
|
bool is_romless;
|
2003-09-09 07:02:53 +00:00
|
|
|
|
2004-07-20 22:54:04 +00:00
|
|
|
/* this can only work if Rockbox runs in DRAM, not flash ROM */
|
|
|
|
if ((UINT8*)rb >= FB && (UINT8*)rb < FB + 4096*1024) /* 4 MB max */
|
|
|
|
{ /* we're running from flash */
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Not from ROM");
|
2004-07-20 22:54:04 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2003-11-30 17:24:42 +00:00
|
|
|
/* test if the user is running the correct plugin for this box */
|
|
|
|
if (!CheckPlatform(PLATFORM_ID, *(UINT16*)(FB + VERSION_ADR)))
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Wrong version");
|
2003-11-30 17:24:42 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2004-10-23 16:28:06 +00:00
|
|
|
/* refuse to work if the power may fail meanwhile */
|
|
|
|
if (!rb->battery_level_safe())
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Batt. too low!");
|
2004-10-23 16:28:06 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
/* check boot ROM */
|
2003-10-26 21:23:04 +00:00
|
|
|
result = CheckBootROM();
|
|
|
|
if (result == eUnknown)
|
2003-09-09 07:02:53 +00:00
|
|
|
{ /* no support for any other yet */
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Wrong boot ROM");
|
2003-09-09 07:02:53 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
2003-10-26 21:23:04 +00:00
|
|
|
is_romless = (result == eROMless);
|
|
|
|
|
|
|
|
/* compose filename if none given */
|
|
|
|
if (filename == NULL)
|
|
|
|
{
|
|
|
|
rb->snprintf(
|
|
|
|
default_filename,
|
|
|
|
sizeof(default_filename),
|
|
|
|
"/firmware_%s%s.bin",
|
|
|
|
FILE_TYPE,
|
|
|
|
is_romless ? "_norom" : "");
|
|
|
|
filename = default_filename;
|
|
|
|
}
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
/* "allocate" memory */
|
2010-05-07 19:27:42 +00:00
|
|
|
sector = rb->plugin_get_buffer(&memleft);
|
2003-09-09 07:02:53 +00:00
|
|
|
if (memleft < SEC_SIZE) /* need buffer for a flash sector */
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ*3, "Out of memory");
|
2003-09-09 07:02:53 +00:00
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = GetFlashInfo(&FlashInfo);
|
|
|
|
ShowFlashInfo(&FlashInfo);
|
|
|
|
|
|
|
|
if (FlashInfo.size == 0) /* no valid chip */
|
|
|
|
{
|
|
|
|
return; /* exit */
|
|
|
|
}
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
rb->lcd_puts_scroll(0, 0, filename);
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts_scroll(0, 1, "[Menu] to check");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
button = WaitForButton();
|
|
|
|
if (button != BUTTON_MENU)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts(0, 0, "Checking...");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
rc = CheckFirmwareFile(filename, FlashInfo.size, is_romless);
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts(0, 0, "Checked:");
|
|
|
|
switch (rc)
|
|
|
|
{
|
|
|
|
case eOK:
|
|
|
|
rb->lcd_puts(0, 1, "File OK.");
|
|
|
|
break;
|
|
|
|
case eFileNotFound:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "File not found:");
|
2003-10-26 21:23:04 +00:00
|
|
|
rb->lcd_puts_scroll(0, 1, filename);
|
2003-09-09 07:02:53 +00:00
|
|
|
break;
|
|
|
|
case eTooBig:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "File too big,");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "larger than chip.");
|
|
|
|
break;
|
|
|
|
case eTooSmall:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "File too small.");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "Incomplete?");
|
|
|
|
break;
|
|
|
|
case eReadErr:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Read error.");
|
|
|
|
break;
|
|
|
|
case eBadContent:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "File invalid.");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "Sanity check failed.");
|
|
|
|
break;
|
|
|
|
case eCrcErr:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "File invalid.");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "CRC check failed.");
|
|
|
|
break;
|
2003-11-30 17:24:42 +00:00
|
|
|
case eBadPlatform:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Wrong file for");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "this hardware.");
|
|
|
|
break;
|
2003-09-09 07:02:53 +00:00
|
|
|
default:
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Check failed.");
|
|
|
|
break;
|
|
|
|
}
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
rb->sleep(HZ*3);
|
|
|
|
|
|
|
|
if (rc == eOK)
|
|
|
|
{
|
|
|
|
rb->lcd_puts_scroll(0, 0, "[On] to program,");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "other key to exit.");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2003-09-09 07:02:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* error occured */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
button = WaitForButton();
|
|
|
|
|
|
|
|
if (button != BUTTON_ON)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Are you sure?");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "[+] to proceed.");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
button = WaitForButton();
|
|
|
|
|
|
|
|
if (button != BUTTON_RIGHT)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Programming...");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
rc = ProgramFirmwareFile(filename, FlashInfo.size);
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
if (rc)
|
|
|
|
{ /* errors */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Programming failed!");
|
|
|
|
rb->snprintf(buf, sizeof(buf), "%d errors", rc);
|
|
|
|
rb->lcd_puts_scroll(0, 1, buf);
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2003-09-09 07:02:53 +00:00
|
|
|
WaitForButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Verifying...");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
|
2003-10-26 21:23:04 +00:00
|
|
|
rc = VerifyFirmwareFile(filename);
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
if (rc == 0)
|
|
|
|
{
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Verify OK.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->snprintf(buf, sizeof(buf), "Verify failed! %d errors", rc);
|
|
|
|
rb->lcd_puts_scroll(0, 0, buf);
|
|
|
|
}
|
2006-01-15 18:20:18 +00:00
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
rb->lcd_puts_scroll(0, 1, "Press any key to exit.");
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
2003-09-09 07:02:53 +00:00
|
|
|
WaitForButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* not HAVE_LCD_BITMAP */
|
|
|
|
|
|
|
|
|
|
|
|
/***************** Plugin Entry Point *****************/
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2003-09-09 07:02:53 +00:00
|
|
|
{
|
2004-08-30 19:52:45 +00:00
|
|
|
int oldmode;
|
|
|
|
|
2003-09-09 07:02:53 +00:00
|
|
|
/* now go ahead and have fun! */
|
2004-08-30 19:52:45 +00:00
|
|
|
oldmode = rb->system_memory_guard(MEMGUARD_NONE); /*disable memory guard */
|
2003-10-26 21:23:04 +00:00
|
|
|
DoUserDialog((char*) parameter);
|
2004-08-30 19:52:45 +00:00
|
|
|
rb->system_memory_guard(oldmode); /* re-enable memory guard */
|
2003-09-09 07:02:53 +00:00
|
|
|
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|