From dde262b58a8bb908278179e916e0d91068d6987f Mon Sep 17 00:00:00 2001 From: Dominik Wenger Date: Thu, 3 May 2007 20:07:57 +0000 Subject: Support for Sansa E200 in rbutil git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13315 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/sansapatcher/sansaio-posix.c | 2 ++ rbutil/sansapatcher/sansaio-win32.c | 17 +++++++++-------- rbutil/sansapatcher/sansaio.h | 4 ++-- rbutil/sansapatcher/sansapatcher.c | 18 ++++++++++++------ 4 files changed, 25 insertions(+), 16 deletions(-) (limited to 'rbutil/sansapatcher') diff --git a/rbutil/sansapatcher/sansaio-posix.c b/rbutil/sansapatcher/sansaio-posix.c index e2b5496b32..bf72718d64 100644 --- a/rbutil/sansapatcher/sansaio-posix.c +++ b/rbutil/sansapatcher/sansaio-posix.c @@ -42,10 +42,12 @@ #include "sansaio.h" +#ifndef RBUTIL void print_error(char* msg) { perror(msg); } +#endif int sansa_open(struct sansa_t* sansa, int silent) { diff --git a/rbutil/sansapatcher/sansaio-win32.c b/rbutil/sansapatcher/sansaio-win32.c index 7335ab614c..e9b8819f19 100644 --- a/rbutil/sansapatcher/sansaio-win32.c +++ b/rbutil/sansapatcher/sansaio-win32.c @@ -37,22 +37,23 @@ #include "sansaio.h" -static int lock_volume(HANDLE hDisk) -{ +static int lock_volume(HANDLE hDisk) +{ DWORD dummy; return DeviceIoControl(hDisk, FSCTL_LOCK_VOLUME, NULL, 0, NULL, 0, - &dummy, NULL); + &dummy, NULL); } -static int unlock_volume(HANDLE hDisk) -{ +static int unlock_volume(HANDLE hDisk) +{ DWORD dummy; return DeviceIoControl(hDisk, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, - &dummy, NULL); -} + &dummy, NULL); +} +#ifndef RBUTIL void print_error(char* msg) { char* pMsgBuf; @@ -65,7 +66,7 @@ void print_error(char* msg) printf(pMsgBuf); LocalFree(pMsgBuf); } - +#endif int sansa_open(struct sansa_t* sansa, int silent) { DISK_GEOMETRY_EX diskgeometry_ex; diff --git a/rbutil/sansapatcher/sansaio.h b/rbutil/sansapatcher/sansaio.h index f30884887c..2ef88fd384 100644 --- a/rbutil/sansapatcher/sansaio.h +++ b/rbutil/sansapatcher/sansaio.h @@ -38,7 +38,7 @@ #endif -struct partinfo_t { +struct sansa_partinfo_t { unsigned long start; /* first sector (LBA) */ unsigned long size; /* number of sectors */ int type; @@ -57,7 +57,7 @@ struct sansa_t { HANDLE dh; char diskname[4096]; int sector_size; - struct partinfo_t pinfo[4]; + struct sansa_partinfo_t pinfo[4]; int hasoldbootloader; loff_t start; /* Offset in bytes of firmware partition from start of disk */ }; diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c index 2081e396c2..310f312052 100644 --- a/rbutil/sansapatcher/sansapatcher.c +++ b/rbutil/sansapatcher/sansapatcher.c @@ -28,14 +28,16 @@ #include "sansaio.h" #include "sansapatcher.h" -#include "bootimg.h" +#ifndef RBUTIL + #include "bootimg.h" +#endif /* The offset of the MI4 image header in the firmware partition */ #define PPMI_OFFSET 0x80000 extern int verbose; -/* Windows requires the buffer for disk I/O to be aligned in memory on a +/* Windows requires the buffer for disk I/O to be aligned in memory on a multiple of the disk volume size - so we use a single global variable and initialise it with sansa_alloc_buf() in main(). */ @@ -369,8 +371,8 @@ int is_e200(struct sansa_t* sansa) sansa->hasoldbootloader = 0; if (memcmp(sectorbuf+0x1f8,"RBBL",4)==0) { /* Look for an original firmware after the first image */ - if (sansa_seek_and_read(sansa, - sansa->start + PPMI_OFFSET + 0x200 + ppmi_length, + if (sansa_seek_and_read(sansa, + sansa->start + PPMI_OFFSET + 0x200 + ppmi_length, sectorbuf, 512) < 0) { return -7; } @@ -461,14 +463,14 @@ static int load_original_firmware(struct sansa_t* sansa, unsigned char* buf, str if (get_mi4header(buf,mi4header)==0) { /* We have a valid MI4 file after a bootloader, so we use this. */ - if ((n = sansa_seek_and_read(sansa, + if ((n = sansa_seek_and_read(sansa, sansa->start + PPMI_OFFSET + 0x200 + ppmi_length, buf, mi4header->mi4size)) < 0) { return -1; } } else { /* No valid MI4 file, so read the first image. */ - if ((n = sansa_seek_and_read(sansa, + if ((n = sansa_seek_and_read(sansa, sansa->start + PPMI_OFFSET + 0x200, buf, ppmi_length)) < 0) { return -1; @@ -571,7 +573,9 @@ int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type) bl_length = filesize(infile); } else { + #ifndef RBUTIL bl_length = LEN_bootimg; + #endif } /* Create PPMI header */ @@ -595,7 +599,9 @@ int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type) return -1; } } else { + #ifndef RBUTIL memcpy(sectorbuf+0x200,bootimg,LEN_bootimg); + #endif } /* Load original firmware from Sansa to the space after the bootloader */ -- cgit v1.2.3