Add --write-embedded (-we) option. This replaces the Apple firmware with the bootloader embedded in ipodpatcher (equivalent to -wf bootloader-ipodxxx.ipod when using an external bootloader).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13536 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
52a64c3af9
commit
bbde44506b
2 changed files with 66 additions and 34 deletions
|
@ -765,34 +765,45 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
|
|||
unsigned long filechksum=0;
|
||||
unsigned char header[8]; /* Header for .ipod file */
|
||||
|
||||
/* First check that the input file is the correct type for this ipod. */
|
||||
infile=open(filename,O_RDONLY);
|
||||
if (infile < 0) {
|
||||
fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (type==FILETYPE_DOT_IPOD) {
|
||||
n = read(infile,header,8);
|
||||
if (n < 8) {
|
||||
fprintf(stderr,"[ERR] Failed to read header from %s\n",filename);
|
||||
close(infile);
|
||||
#ifdef WITH_BOOTOBJS
|
||||
if (type == FILETYPE_INTERNAL) {
|
||||
fprintf(stderr,"[INFO] Using internal bootloader - %d bytes\n",ipod->bootloader_len);
|
||||
length = ipod->bootloader_len;
|
||||
infile = -1;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* First check that the input file is the correct type for this ipod. */
|
||||
infile=open(filename,O_RDONLY);
|
||||
if (infile < 0) {
|
||||
fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp(header+4, ipod->modelname,4)!=0) {
|
||||
fprintf(stderr,"[ERR] Model name in input file (%c%c%c%c) doesn't match ipod model (%s)\n",
|
||||
header[4],header[5],header[6],header[7], ipod->modelname);
|
||||
close(infile);
|
||||
return -1;
|
||||
|
||||
if (type==FILETYPE_DOT_IPOD) {
|
||||
n = read(infile,header,8);
|
||||
if (n < 8) {
|
||||
fprintf(stderr,"[ERR] Failed to read header from %s\n",filename);
|
||||
close(infile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (memcmp(header+4, ipod->modelname,4)!=0) {
|
||||
fprintf(stderr,"[ERR] Model name in input file (%c%c%c%c) doesn't match ipod model (%s)\n",
|
||||
header[4],header[5],header[6],header[7], ipod->modelname);
|
||||
close(infile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
filechksum = be2int(header);
|
||||
|
||||
length = filesize(infile)-8;
|
||||
} else {
|
||||
length = filesize(infile);
|
||||
}
|
||||
|
||||
filechksum = be2int(header);
|
||||
|
||||
length = filesize(infile)-8;
|
||||
} else {
|
||||
length = filesize(infile);
|
||||
}
|
||||
|
||||
newsize=(length+ipod->sector_size-1)&~(ipod->sector_size-1);
|
||||
|
||||
fprintf(stderr,"[INFO] Padding input file from 0x%08x to 0x%08x bytes\n",
|
||||
|
@ -800,7 +811,7 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
|
|||
|
||||
if (newsize > BUFFER_SIZE) {
|
||||
fprintf(stderr,"[ERR] Input file too big for buffer\n");
|
||||
close(infile);
|
||||
if (infile >= 0) close(infile);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -818,16 +829,26 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
|
|||
}
|
||||
}
|
||||
|
||||
fprintf(stderr,"[INFO] Reading input file...\n");
|
||||
/* We now know we have enough space, so write it. */
|
||||
memset(sectorbuf+length,0,newsize-length);
|
||||
n = read(infile,sectorbuf,length);
|
||||
if (n < 0) {
|
||||
fprintf(stderr,"[ERR] Couldn't read input file\n");
|
||||
#ifdef WITH_BOOTOBJS
|
||||
if (type == FILETYPE_INTERNAL) {
|
||||
memcpy(sectorbuf,ipod->bootloader,ipod->bootloader_len);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
fprintf(stderr,"[INFO] Reading input file...\n");
|
||||
/* We now know we have enough space, so write it. */
|
||||
n = read(infile,sectorbuf,length);
|
||||
if (n < 0) {
|
||||
fprintf(stderr,"[ERR] Couldn't read input file\n");
|
||||
close(infile);
|
||||
return -1;
|
||||
}
|
||||
close(infile);
|
||||
return -1;
|
||||
}
|
||||
close(infile);
|
||||
|
||||
/* Pad the data with zeros */
|
||||
memset(sectorbuf+length,0,newsize-length);
|
||||
|
||||
if (type==FILETYPE_DOT_IPOD) {
|
||||
chksum = ipod->modelnum;
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#include "ipodpatcher.h"
|
||||
#include "ipodio.h"
|
||||
|
||||
#define VERSION "1.0 with v1.1 bootloaders"
|
||||
#define VERSION "1.1-svn"
|
||||
|
||||
int verbose = 0;
|
||||
|
||||
|
@ -79,6 +79,9 @@ void print_usage(void)
|
|||
fprintf(stderr," -rfb, --read-firmware-bin filename.bin\n");
|
||||
fprintf(stderr," -wf, --write-firmware filename.ipod\n");
|
||||
fprintf(stderr," -wfb, --write-firmware-bin filename.bin\n");
|
||||
#ifdef WITH_BOOTOBJS
|
||||
fprintf(stderr," -we, --write-embedded\n");
|
||||
#endif
|
||||
fprintf(stderr," -a, --add-bootloader filename.ipod\n");
|
||||
fprintf(stderr," -ab, --add-bootloader-bin filename.bin\n");
|
||||
fprintf(stderr," -d, --delete-bootloader\n");
|
||||
|
@ -248,6 +251,14 @@ int main(int argc, char* argv[])
|
|||
if (i == argc) { print_usage(); return 1; }
|
||||
filename=argv[i];
|
||||
i++;
|
||||
#ifdef WITH_BOOTOBJS
|
||||
} else if ((strcmp(argv[i],"-we")==0) ||
|
||||
(strcmp(argv[i],"--write-embedded")==0)) {
|
||||
action = WRITE_FIRMWARE;
|
||||
type = FILETYPE_INTERNAL;
|
||||
filename="[embedded bootloader]"; /* Only displayed for user */
|
||||
i++;
|
||||
#endif
|
||||
} else if ((strcmp(argv[i],"-wf")==0) ||
|
||||
(strcmp(argv[i],"--write-firmware")==0)) {
|
||||
action = WRITE_FIRMWARE;
|
||||
|
|
Loading…
Reference in a new issue