2007-03-15 22:55:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2007-03-15 23:02:37 +00:00
|
|
|
* $Id$
|
2007-03-15 22:55:36 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2007 Dave Chapman
|
|
|
|
*
|
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.
|
2007-03-15 22:55:36 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include "sansapatcher.h"
|
|
|
|
#include "sansaio.h"
|
2007-03-16 00:23:23 +00:00
|
|
|
#include "parttypes.h"
|
2011-12-16 20:10:33 +00:00
|
|
|
#ifdef WITH_BOOTOBJS
|
2011-12-04 19:40:43 +00:00
|
|
|
#include "bootimg_c200.h"
|
|
|
|
#include "bootimg_e200.h"
|
2011-12-16 20:10:33 +00:00
|
|
|
#endif
|
2007-03-15 22:55:36 +00:00
|
|
|
|
2011-12-16 20:10:33 +00:00
|
|
|
#ifndef VERSION
|
2009-07-10 16:52:02 +00:00
|
|
|
#define VERSION "0.8 with v6.0 bootloaders"
|
2011-12-16 20:10:33 +00:00
|
|
|
#endif
|
2007-03-15 22:55:36 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
NONE,
|
|
|
|
INSTALL,
|
|
|
|
INTERACTIVE,
|
|
|
|
SHOW_INFO,
|
|
|
|
LIST_IMAGES,
|
|
|
|
DELETE_BOOTLOADER,
|
|
|
|
ADD_BOOTLOADER,
|
|
|
|
READ_FIRMWARE,
|
|
|
|
WRITE_FIRMWARE,
|
|
|
|
READ_PARTITION,
|
2007-08-02 11:39:43 +00:00
|
|
|
WRITE_PARTITION,
|
2007-10-14 18:09:40 +00:00
|
|
|
UPDATE_OF,
|
|
|
|
UPDATE_PPBL
|
2007-03-15 22:55:36 +00:00
|
|
|
};
|
|
|
|
|
2008-07-14 16:43:47 +00:00
|
|
|
static void print_usage(void)
|
2007-03-15 22:55:36 +00:00
|
|
|
{
|
|
|
|
fprintf(stderr,"Usage: sansapatcher --scan\n");
|
|
|
|
#ifdef __WIN32__
|
|
|
|
fprintf(stderr," or sansapatcher [DISKNO] [action]\n");
|
|
|
|
#else
|
|
|
|
fprintf(stderr," or sansapatcher [device] [action]\n");
|
|
|
|
#endif
|
|
|
|
fprintf(stderr,"\n");
|
|
|
|
fprintf(stderr,"Where [action] is one of the following options:\n");
|
|
|
|
fprintf(stderr," --install\n");
|
|
|
|
fprintf(stderr," -l, --list\n");
|
2007-08-02 11:39:43 +00:00
|
|
|
fprintf(stderr," -rf, --read-firmware filename.mi4\n");
|
|
|
|
fprintf(stderr," -a, --add-bootloader filename.mi4\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
fprintf(stderr," -d, --delete-bootloader\n");
|
2007-08-02 11:39:43 +00:00
|
|
|
fprintf(stderr," -of --update-original-firmware filename.mi4\n");
|
2007-10-14 18:09:40 +00:00
|
|
|
fprintf(stderr," -bl --update-ppbl filename.bin\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
fprintf(stderr,"\n");
|
|
|
|
|
|
|
|
#ifdef __WIN32__
|
|
|
|
fprintf(stderr,"DISKNO is the number (e.g. 2) Windows has assigned to your sansa's hard disk.\n");
|
|
|
|
fprintf(stderr,"The first hard disk in your computer (i.e. C:\\) will be disk 0, the next disk\n");
|
|
|
|
fprintf(stderr,"will be disk 1 etc. sansapatcher will refuse to access a disk unless it\n");
|
2007-09-19 18:46:54 +00:00
|
|
|
fprintf(stderr,"can identify it as being an E200 or C200.\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
fprintf(stderr,"\n");
|
|
|
|
#else
|
|
|
|
#if defined(linux) || defined (__linux)
|
|
|
|
fprintf(stderr,"\"device\" is the device node (e.g. /dev/sda) assigned to your sansa.\n");
|
|
|
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
|
|
|
|
fprintf(stderr,"\"device\" is the device node (e.g. /dev/da1) assigned to your sansa.\n");
|
|
|
|
#elif defined(__APPLE__) && defined(__MACH__)
|
|
|
|
fprintf(stderr,"\"device\" is the device node (e.g. /dev/disk1) assigned to your sansa.\n");
|
|
|
|
#endif
|
|
|
|
fprintf(stderr,"sansapatcher will refuse to access a disk unless it can identify it as being\n");
|
2007-09-19 18:46:54 +00:00
|
|
|
fprintf(stderr,"an E200 or C200.\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-07-14 16:43:47 +00:00
|
|
|
static const char* get_parttype(int pt)
|
2007-03-16 00:23:23 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-07-14 16:43:47 +00:00
|
|
|
static const char unknown[]="Unknown";
|
2007-03-16 00:23:23 +00:00
|
|
|
|
|
|
|
if (pt == -1) {
|
|
|
|
return "HFS/HFS+";
|
|
|
|
}
|
|
|
|
|
|
|
|
i=0;
|
|
|
|
while (parttypes[i].name != NULL) {
|
|
|
|
if (parttypes[i].type == pt) {
|
|
|
|
return (parttypes[i].name);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return unknown;
|
|
|
|
}
|
|
|
|
|
2008-07-14 16:43:47 +00:00
|
|
|
static void display_partinfo(struct sansa_t* sansa)
|
2007-03-15 22:55:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
double sectors_per_MB = (1024.0*1024.0)/sansa->sector_size;
|
|
|
|
|
|
|
|
printf("[INFO] Part Start Sector End Sector Size (MB) Type\n");
|
|
|
|
for ( i = 0; i < 4; i++ ) {
|
|
|
|
if (sansa->pinfo[i].start != 0) {
|
|
|
|
printf("[INFO] %d %10ld %10ld %10.1f %s (0x%02x)\n",
|
|
|
|
i,
|
|
|
|
sansa->pinfo[i].start,
|
|
|
|
sansa->pinfo[i].start+sansa->pinfo[i].size-1,
|
|
|
|
sansa->pinfo[i].size/sectors_per_MB,
|
|
|
|
get_parttype(sansa->pinfo[i].type),
|
|
|
|
sansa->pinfo[i].type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
|
|
|
char yesno[4];
|
|
|
|
int i;
|
|
|
|
int n;
|
|
|
|
char* filename;
|
|
|
|
int action = SHOW_INFO;
|
|
|
|
struct sansa_t sansa;
|
2007-03-21 11:05:38 +00:00
|
|
|
int res = 0;
|
2011-12-04 19:40:43 +00:00
|
|
|
unsigned char* buf = NULL;
|
|
|
|
unsigned int len;
|
2007-03-15 22:55:36 +00:00
|
|
|
|
|
|
|
fprintf(stderr,"sansapatcher v" VERSION " - (C) Dave Chapman 2006-2007\n");
|
|
|
|
fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
|
|
|
|
fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
|
|
|
|
|
|
|
|
if ((argc > 1) && ((strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"--help")==0))) {
|
|
|
|
print_usage();
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_OK;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 22:36:00 +00:00
|
|
|
if (sansa_alloc_buffer(&sansa, BUFFER_SIZE) < 0) {
|
2007-03-15 22:55:36 +00:00
|
|
|
fprintf(stderr,"Failed to allocate memory buffer\n");
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_INTERNAL_ERROR;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((argc > 1) && (strcmp(argv[1],"--scan")==0)) {
|
|
|
|
if (sansa_scan(&sansa) == 0)
|
2007-09-19 18:46:54 +00:00
|
|
|
fprintf(stderr,"[ERR] No E200s or C200s found.\n");
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_NOT_FOUND;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the first parameter doesn't start with -, then we interpret it as a device */
|
|
|
|
if ((argc > 1) && (argv[1][0] != '-')) {
|
|
|
|
sansa.diskname[0]=0;
|
|
|
|
#ifdef __WIN32__
|
|
|
|
snprintf(sansa.diskname,sizeof(sansa.diskname),"\\\\.\\PhysicalDrive%s",argv[1]);
|
|
|
|
#else
|
|
|
|
strncpy(sansa.diskname,argv[1],sizeof(sansa.diskname));
|
|
|
|
#endif
|
|
|
|
i = 2;
|
|
|
|
} else {
|
2007-09-19 18:46:54 +00:00
|
|
|
/* Autoscan for C200/E200s */
|
2007-03-15 22:55:36 +00:00
|
|
|
n = sansa_scan(&sansa);
|
|
|
|
if (n==0) {
|
2007-09-19 18:46:54 +00:00
|
|
|
fprintf(stderr,"[ERR] No E200s or C200s found, aborting\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
fprintf(stderr,"[ERR] Please connect your sansa and ensure it is in UMS mode\n");
|
|
|
|
#if defined(__APPLE__) && defined(__MACH__)
|
2007-09-19 18:46:54 +00:00
|
|
|
fprintf(stderr,"[ERR] Also ensure that your Sansa's main partition is not mounted.\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
#elif !defined(__WIN32__)
|
|
|
|
if (geteuid()!=0) {
|
|
|
|
fprintf(stderr,"[ERR] You may also need to run sansapatcher as root.\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
fprintf(stderr,"[ERR] Please refer to the Rockbox manual if you continue to have problems.\n");
|
|
|
|
} else if (n > 1) {
|
2007-09-19 18:46:54 +00:00
|
|
|
fprintf(stderr,"[ERR] %d Sansas found, aborting\n",n);
|
|
|
|
fprintf(stderr,"[ERR] Please connect only one Sansa and re-run sansapatcher.\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n != 1) {
|
2020-09-25 20:48:00 +00:00
|
|
|
#ifdef WITH_BOOTOBJS
|
2007-03-15 22:55:36 +00:00
|
|
|
if (argc==1) {
|
|
|
|
printf("\nPress ENTER to exit sansapatcher :");
|
|
|
|
fgets(yesno,4,stdin);
|
|
|
|
}
|
2020-09-25 20:48:00 +00:00
|
|
|
#endif
|
|
|
|
return n > 1 ? SANSA_MULTIPLE_DEVICES : SANSA_NOT_FOUND;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
i = 1;
|
|
|
|
}
|
|
|
|
|
2011-12-16 20:10:33 +00:00
|
|
|
#ifdef WITH_BOOTOBJS
|
2007-03-15 22:55:36 +00:00
|
|
|
action = INTERACTIVE;
|
2011-12-16 20:10:33 +00:00
|
|
|
#endif
|
2007-03-15 22:55:36 +00:00
|
|
|
|
|
|
|
while (i < argc) {
|
|
|
|
if ((strcmp(argv[i],"-l")==0) || (strcmp(argv[i],"--list")==0)) {
|
|
|
|
action = LIST_IMAGES;
|
|
|
|
i++;
|
|
|
|
} else if (strcmp(argv[i],"--install")==0) {
|
|
|
|
action = INSTALL;
|
|
|
|
i++;
|
|
|
|
} else if ((strcmp(argv[i],"-d")==0) ||
|
|
|
|
(strcmp(argv[i],"--delete-bootloader")==0)) {
|
|
|
|
action = DELETE_BOOTLOADER;
|
|
|
|
i++;
|
|
|
|
} else if ((strcmp(argv[i],"-a")==0) ||
|
|
|
|
(strcmp(argv[i],"--add-bootloader")==0)) {
|
|
|
|
action = ADD_BOOTLOADER;
|
|
|
|
i++;
|
2020-09-25 20:48:00 +00:00
|
|
|
if (i == argc) { print_usage(); return SANSA_WRONG_ARGUMENTS; }
|
2007-03-15 22:55:36 +00:00
|
|
|
filename=argv[i];
|
|
|
|
i++;
|
2007-08-02 11:39:43 +00:00
|
|
|
} else if ((strcmp(argv[i],"-of")==0) ||
|
|
|
|
(strcmp(argv[i],"--update-original-firmware")==0)) {
|
|
|
|
action = UPDATE_OF;
|
|
|
|
i++;
|
2020-09-25 20:48:00 +00:00
|
|
|
if (i == argc) { print_usage(); return SANSA_WRONG_ARGUMENTS; }
|
2007-08-02 11:39:43 +00:00
|
|
|
filename=argv[i];
|
|
|
|
i++;
|
2007-10-14 18:09:40 +00:00
|
|
|
} else if ((strcmp(argv[i],"-bl")==0) ||
|
|
|
|
(strcmp(argv[i],"--update-ppbl")==0)) {
|
|
|
|
action = UPDATE_PPBL;
|
|
|
|
i++;
|
2020-09-25 20:48:00 +00:00
|
|
|
if (i == argc) { print_usage(); return SANSA_WRONG_ARGUMENTS; }
|
2007-10-14 18:09:40 +00:00
|
|
|
filename=argv[i];
|
|
|
|
i++;
|
2007-03-15 22:55:36 +00:00
|
|
|
} else if ((strcmp(argv[i],"-rf")==0) ||
|
|
|
|
(strcmp(argv[i],"--read-firmware")==0)) {
|
|
|
|
action = READ_FIRMWARE;
|
|
|
|
i++;
|
2020-09-25 20:48:00 +00:00
|
|
|
if (i == argc) { print_usage(); return SANSA_WRONG_ARGUMENTS; }
|
2007-03-15 22:55:36 +00:00
|
|
|
filename=argv[i];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sansa.diskname[0]==0) {
|
|
|
|
print_usage();
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_WRONG_ARGUMENTS;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sansa_open(&sansa, 0) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_ACCESS_DENIED;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr,"[INFO] Reading partition table from %s\n",sansa.diskname);
|
|
|
|
fprintf(stderr,"[INFO] Sector size is %d bytes\n",sansa.sector_size);
|
|
|
|
|
2007-03-16 00:23:23 +00:00
|
|
|
if (sansa_read_partinfo(&sansa,0) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_PARTITION_ERROR;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
display_partinfo(&sansa);
|
|
|
|
|
2007-09-19 18:46:54 +00:00
|
|
|
i = is_sansa(&sansa);
|
2007-03-15 22:55:36 +00:00
|
|
|
if (i < 0) {
|
2007-09-19 18:46:54 +00:00
|
|
|
fprintf(stderr,"[ERR] Disk is not an E200 or C200 (%d), aborting.\n",i);
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_WRONG_TYPE;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sansa.hasoldbootloader) {
|
|
|
|
printf("[ERR] ************************************************************************\n");
|
|
|
|
printf("[ERR] *** OLD ROCKBOX INSTALLATION DETECTED, ABORTING.\n");
|
|
|
|
printf("[ERR] *** You must reinstall the original Sansa firmware before running\n");
|
|
|
|
printf("[ERR] *** sansapatcher for the first time.\n");
|
2020-06-07 01:37:17 +00:00
|
|
|
printf("[ERR] *** See http://www.rockbox.org/wiki/SansaE200Install\n");
|
2007-03-15 22:55:36 +00:00
|
|
|
printf("[ERR] ************************************************************************\n");
|
2020-09-25 20:48:00 +00:00
|
|
|
res = SANSA_OLD_INSTALL;
|
2007-03-21 11:05:38 +00:00
|
|
|
} else {
|
|
|
|
if (action==LIST_IMAGES) {
|
|
|
|
sansa_list_images(&sansa);
|
2011-12-16 20:10:33 +00:00
|
|
|
#ifdef WITH_BOOTOBJS
|
2007-03-21 11:05:38 +00:00
|
|
|
} else if (action==INTERACTIVE) {
|
|
|
|
|
|
|
|
printf("Enter i to install the Rockbox bootloader, u to uninstall\n or c to cancel and do nothing (i/u/c) :");
|
|
|
|
|
|
|
|
if (fgets(yesno,4,stdin)) {
|
|
|
|
if (yesno[0]=='i') {
|
|
|
|
if (sansa_reopen_rw(&sansa) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
res = SANSA_CANNOT_REOPEN;
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
2011-12-04 19:40:43 +00:00
|
|
|
if (strcmp(sansa.targetname,"c200") == 0) {
|
|
|
|
len = LEN_bootimg_c200;
|
|
|
|
buf = bootimg_c200;
|
|
|
|
} else {
|
|
|
|
len = LEN_bootimg_e200;
|
|
|
|
buf = bootimg_e200;
|
|
|
|
}
|
|
|
|
if (sansa_add_bootloader(&sansa, buf, len)==0) {
|
2007-03-21 11:05:38 +00:00
|
|
|
fprintf(stderr,"[INFO] Bootloader installed successfully.\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] --install failed.\n");
|
2020-09-25 20:48:00 +00:00
|
|
|
res = SANSA_INSTALL_FAILED;
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
|
|
|
} else if (yesno[0]=='u') {
|
|
|
|
if (sansa_reopen_rw(&sansa) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
res = SANSA_CANNOT_REOPEN;
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sansa_delete_bootloader(&sansa)==0) {
|
|
|
|
fprintf(stderr,"[INFO] Bootloader removed.\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] Bootloader removal failed.\n");
|
2020-09-25 20:48:00 +00:00
|
|
|
res = SANSA_UNINSTALL_FAILED;
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
2007-03-15 23:26:47 +00:00
|
|
|
}
|
|
|
|
}
|
2011-12-16 20:10:33 +00:00
|
|
|
#endif
|
2007-03-21 11:05:38 +00:00
|
|
|
} else if (action==READ_FIRMWARE) {
|
|
|
|
if (sansa_read_firmware(&sansa, filename)==0) {
|
|
|
|
fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] --read-firmware failed.\n");
|
|
|
|
}
|
2011-12-16 20:10:33 +00:00
|
|
|
#ifdef WITH_BOOTOBJS
|
2007-03-21 11:05:38 +00:00
|
|
|
} else if (action==INSTALL) {
|
|
|
|
if (sansa_reopen_rw(&sansa) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_CANNOT_REOPEN;
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
2007-03-15 23:26:47 +00:00
|
|
|
|
2011-12-04 19:40:43 +00:00
|
|
|
if (strcmp(sansa.targetname,"c200") == 0) {
|
|
|
|
len = LEN_bootimg_c200;
|
|
|
|
buf = bootimg_c200;
|
|
|
|
} else {
|
|
|
|
len = LEN_bootimg_e200;
|
|
|
|
buf = bootimg_e200;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sansa_add_bootloader(&sansa, buf, len)==0) {
|
2007-03-21 11:05:38 +00:00
|
|
|
fprintf(stderr,"[INFO] Bootloader installed successfully.\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] --install failed.\n");
|
|
|
|
}
|
2011-12-16 20:10:33 +00:00
|
|
|
#endif
|
2007-03-21 11:05:38 +00:00
|
|
|
} else if (action==ADD_BOOTLOADER) {
|
|
|
|
if (sansa_reopen_rw(&sansa) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_CANNOT_REOPEN;
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
2007-03-15 22:55:36 +00:00
|
|
|
|
2011-12-04 19:40:43 +00:00
|
|
|
len = sansa_read_bootloader(&sansa, filename, &buf);
|
|
|
|
if (len > 0) {
|
|
|
|
if (sansa_add_bootloader(&sansa, buf, len)==0) {
|
|
|
|
fprintf(stderr,"[INFO] Bootloader %s written to device.\n",filename);
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] --add-bootloader failed.\n");
|
|
|
|
}
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
|
|
|
} else if (action==DELETE_BOOTLOADER) {
|
|
|
|
if (sansa_reopen_rw(&sansa) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_CANNOT_REOPEN;
|
2007-03-21 11:05:38 +00:00
|
|
|
}
|
2007-03-15 22:55:36 +00:00
|
|
|
|
2007-03-21 11:05:38 +00:00
|
|
|
if (sansa_delete_bootloader(&sansa)==0) {
|
|
|
|
fprintf(stderr,"[INFO] Bootloader removed successfully.\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] --delete-bootloader failed.\n");
|
|
|
|
}
|
2007-08-02 11:39:43 +00:00
|
|
|
} else if (action==UPDATE_OF) {
|
|
|
|
if (sansa_reopen_rw(&sansa) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_CANNOT_REOPEN;
|
2007-08-02 11:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sansa_update_of(&sansa, filename)==0) {
|
|
|
|
fprintf(stderr,"[INFO] OF updated successfully.\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] --update-original-firmware failed.\n");
|
|
|
|
}
|
2007-10-14 18:09:40 +00:00
|
|
|
} else if (action==UPDATE_PPBL) {
|
|
|
|
printf("[WARN] PPBL installation will overwrite your bootloader. This will lead to a\n");
|
|
|
|
printf(" Sansa that won't boot if the bootloader file is invalid. Only continue if\n");
|
|
|
|
printf(" you're sure you know what you're doing.\n");
|
|
|
|
printf(" Continue (y/n)? ");
|
|
|
|
|
|
|
|
if (fgets(yesno,4,stdin)) {
|
|
|
|
if (yesno[0]=='y') {
|
|
|
|
if (sansa_reopen_rw(&sansa) < 0) {
|
2020-09-25 20:48:00 +00:00
|
|
|
return SANSA_CANNOT_REOPEN;
|
2007-10-14 18:09:40 +00:00
|
|
|
}
|
2020-09-25 20:48:00 +00:00
|
|
|
|
2007-10-14 18:09:40 +00:00
|
|
|
if (sansa_update_ppbl(&sansa, filename)==0) {
|
|
|
|
fprintf(stderr,"[INFO] PPBL updated successfully.\n");
|
|
|
|
} else {
|
|
|
|
fprintf(stderr,"[ERR] --update-ppbl failed.\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sansa_close(&sansa);
|
2013-01-01 12:23:47 +00:00
|
|
|
sansa_dealloc_buffer(&sansa);
|
2007-03-15 22:55:36 +00:00
|
|
|
|
2020-09-25 20:48:00 +00:00
|
|
|
#ifdef WITH_BOOTOBJS
|
2007-03-15 22:55:36 +00:00
|
|
|
if (action==INTERACTIVE) {
|
|
|
|
printf("Press ENTER to exit sansapatcher :");
|
|
|
|
fgets(yesno,4,stdin);
|
|
|
|
}
|
2020-09-25 20:48:00 +00:00
|
|
|
#endif
|
2007-03-15 22:55:36 +00:00
|
|
|
|
2007-03-21 11:05:38 +00:00
|
|
|
return res;
|
2007-03-15 22:55:36 +00:00
|
|
|
}
|