forked from len0rd/rockbox
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 long filechksum=0;
|
||||||
unsigned char header[8]; /* Header for .ipod file */
|
unsigned char header[8]; /* Header for .ipod file */
|
||||||
|
|
||||||
/* First check that the input file is the correct type for this ipod. */
|
#ifdef WITH_BOOTOBJS
|
||||||
infile=open(filename,O_RDONLY);
|
if (type == FILETYPE_INTERNAL) {
|
||||||
if (infile < 0) {
|
fprintf(stderr,"[INFO] Using internal bootloader - %d bytes\n",ipod->bootloader_len);
|
||||||
fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
|
length = ipod->bootloader_len;
|
||||||
return -1;
|
infile = -1;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
if (type==FILETYPE_DOT_IPOD) {
|
#endif
|
||||||
n = read(infile,header,8);
|
{
|
||||||
if (n < 8) {
|
/* First check that the input file is the correct type for this ipod. */
|
||||||
fprintf(stderr,"[ERR] Failed to read header from %s\n",filename);
|
infile=open(filename,O_RDONLY);
|
||||||
close(infile);
|
if (infile < 0) {
|
||||||
|
fprintf(stderr,"[ERR] Couldn't open input file %s\n",filename);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memcmp(header+4, ipod->modelname,4)!=0) {
|
if (type==FILETYPE_DOT_IPOD) {
|
||||||
fprintf(stderr,"[ERR] Model name in input file (%c%c%c%c) doesn't match ipod model (%s)\n",
|
n = read(infile,header,8);
|
||||||
header[4],header[5],header[6],header[7], ipod->modelname);
|
if (n < 8) {
|
||||||
close(infile);
|
fprintf(stderr,"[ERR] Failed to read header from %s\n",filename);
|
||||||
return -1;
|
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);
|
newsize=(length+ipod->sector_size-1)&~(ipod->sector_size-1);
|
||||||
|
|
||||||
fprintf(stderr,"[INFO] Padding input file from 0x%08x to 0x%08x bytes\n",
|
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) {
|
if (newsize > BUFFER_SIZE) {
|
||||||
fprintf(stderr,"[ERR] Input file too big for buffer\n");
|
fprintf(stderr,"[ERR] Input file too big for buffer\n");
|
||||||
close(infile);
|
if (infile >= 0) close(infile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -818,16 +829,26 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr,"[INFO] Reading input file...\n");
|
#ifdef WITH_BOOTOBJS
|
||||||
/* We now know we have enough space, so write it. */
|
if (type == FILETYPE_INTERNAL) {
|
||||||
memset(sectorbuf+length,0,newsize-length);
|
memcpy(sectorbuf,ipod->bootloader,ipod->bootloader_len);
|
||||||
n = read(infile,sectorbuf,length);
|
|
||||||
if (n < 0) {
|
|
||||||
fprintf(stderr,"[ERR] Couldn't read input file\n");
|
|
||||||
close(infile);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
close(infile);
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pad the data with zeros */
|
||||||
|
memset(sectorbuf+length,0,newsize-length);
|
||||||
|
|
||||||
if (type==FILETYPE_DOT_IPOD) {
|
if (type==FILETYPE_DOT_IPOD) {
|
||||||
chksum = ipod->modelnum;
|
chksum = ipod->modelnum;
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@
|
||||||
#include "ipodpatcher.h"
|
#include "ipodpatcher.h"
|
||||||
#include "ipodio.h"
|
#include "ipodio.h"
|
||||||
|
|
||||||
#define VERSION "1.0 with v1.1 bootloaders"
|
#define VERSION "1.1-svn"
|
||||||
|
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
|
|
||||||
|
|
@ -79,6 +79,9 @@ void print_usage(void)
|
||||||
fprintf(stderr," -rfb, --read-firmware-bin filename.bin\n");
|
fprintf(stderr," -rfb, --read-firmware-bin filename.bin\n");
|
||||||
fprintf(stderr," -wf, --write-firmware filename.ipod\n");
|
fprintf(stderr," -wf, --write-firmware filename.ipod\n");
|
||||||
fprintf(stderr," -wfb, --write-firmware-bin filename.bin\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," -a, --add-bootloader filename.ipod\n");
|
||||||
fprintf(stderr," -ab, --add-bootloader-bin filename.bin\n");
|
fprintf(stderr," -ab, --add-bootloader-bin filename.bin\n");
|
||||||
fprintf(stderr," -d, --delete-bootloader\n");
|
fprintf(stderr," -d, --delete-bootloader\n");
|
||||||
|
|
@ -248,6 +251,14 @@ int main(int argc, char* argv[])
|
||||||
if (i == argc) { print_usage(); return 1; }
|
if (i == argc) { print_usage(); return 1; }
|
||||||
filename=argv[i];
|
filename=argv[i];
|
||||||
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) ||
|
} else if ((strcmp(argv[i],"-wf")==0) ||
|
||||||
(strcmp(argv[i],"--write-firmware")==0)) {
|
(strcmp(argv[i],"--write-firmware")==0)) {
|
||||||
action = WRITE_FIRMWARE;
|
action = WRITE_FIRMWARE;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue