summaryrefslogtreecommitdiffstats
path: root/rbutil/mkamsboot
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/mkamsboot')
-rw-r--r--rbutil/mkamsboot/Makefile6
-rw-r--r--rbutil/mkamsboot/main.c24
-rw-r--r--rbutil/mkamsboot/mkamsboot.c63
-rw-r--r--rbutil/mkamsboot/mkamsboot.h13
4 files changed, 41 insertions, 65 deletions
diff --git a/rbutil/mkamsboot/Makefile b/rbutil/mkamsboot/Makefile
index 60e1ea8af8..8a9a4d3852 100644
--- a/rbutil/mkamsboot/Makefile
+++ b/rbutil/mkamsboot/Makefile
@@ -47,9 +47,9 @@ OBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(SOURCES)))
LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OBJDIR),$(LIBSOURCES)))
EXTRADEPS := $(LIBUCL)
-# explicit dependencies on dualboot.{c,h}
-$(OBJDIR)mkamsboot.o: dualboot.h dualboot.c mkamsboot.c
-$(OBJDIR)main.o: dualboot.h dualboot.c main.c
+# explicit dependencies on dualboot.{c,h} and mkamsboot.h
+$(OBJDIR)mkamsboot.o: dualboot.h dualboot.c mkamsboot.c mkamsboot.h
+$(OBJDIR)main.o: dualboot.h dualboot.c main.c mkamsboot.h
$(OBJDIR)%.o: %.c
@echo CC $< $
diff --git a/rbutil/mkamsboot/main.c b/rbutil/mkamsboot/main.c
index 1132334261..a864c2a5c1 100644
--- a/rbutil/mkamsboot/main.c
+++ b/rbutil/mkamsboot/main.c
@@ -59,6 +59,7 @@ int main(int argc, char* argv[])
int rb_packedsize;
int patchable;
int totalsize;
+ int model;
char errstr[200];
struct md5sums sum;
char md5sum[33]; /* 32 digits + \0 */
@@ -81,11 +82,21 @@ int main(int argc, char* argv[])
bootfile = argv[2];
outfile = argv[3];
+ /* Load bootloader file */
+ rb_packed = load_rockbox_file(bootfile, &model, &bootloader_size,
+ &rb_packedsize, errstr, sizeof(errstr));
+ if (rb_packed == NULL) {
+ fprintf(stderr, "%s", errstr);
+ fprintf(stderr, "[ERR] Could not load %s\n", bootfile);
+ return 1;
+ }
+
/* Load original firmware file */
- buf = load_of_file(infile, &len, &sum,
+ buf = load_of_file(infile, model, &len, &sum,
&firmware_size, &of_packed, &of_packedsize, errstr, sizeof(errstr));
if (buf == NULL) {
+ free(rb_packed);
fprintf(stderr, "%s", errstr);
fprintf(stderr, "[ERR] Could not load %s\n", infile);
return 1;
@@ -96,17 +107,6 @@ int main(int argc, char* argv[])
model_names[sum.model], hw_revisions[sum.model], sum.version);
- /* Load bootloader file */
- rb_packed = load_rockbox_file(bootfile, sum.model, &bootloader_size,
- &rb_packedsize, errstr, sizeof(errstr));
- if (rb_packed == NULL) {
- fprintf(stderr, "%s", errstr);
- fprintf(stderr, "[ERR] Could not load %s\n", bootfile);
- free(buf);
- free(of_packed);
- return 1;
- }
-
printf("[INFO] Firmware patching has begun !\n\n");
fprintf(stderr, "[INFO] Original firmware size: %d bytes\n",
diff --git a/rbutil/mkamsboot/mkamsboot.c b/rbutil/mkamsboot/mkamsboot.c
index 1ec9ec26e6..f47afe312a 100644
--- a/rbutil/mkamsboot/mkamsboot.c
+++ b/rbutil/mkamsboot/mkamsboot.c
@@ -323,30 +323,6 @@ static uint32_t calc_checksum(unsigned char* buf, uint32_t n)
return sum;
}
-static int get_model(int model_id)
-{
- switch(model_id) {
- case 0x1e:
- return MODEL_FUZE;
- case 0x22:
- return MODEL_CLIP;
- case 0x23:
- return MODEL_C200V2;
- case 0x24:
- return MODEL_E200V2;
- case 0x25:
- return MODEL_M200V4;
- case 0x27:
- return MODEL_CLIPV2;
- case 0x28:
- return MODEL_CLIPPLUS;
- case 0x70:
- return MODEL_FUZEV2;
- }
-
- return MODEL_UNKNOWN;
-}
-
/* Compress using nrv2e algorithm : Thumb decompressor fits in 168 bytes ! */
static unsigned char* uclpack(unsigned char* inbuf, int insize, int* outsize)
{
@@ -388,7 +364,7 @@ static unsigned char* uclpack(unsigned char* inbuf, int insize, int* outsize)
/* Loads a Sansa AMS Original Firmware file into memory */
unsigned char* load_of_file(
- char* filename, off_t* bufsize, struct md5sums *sum,
+ char* filename, int model, off_t* bufsize, struct md5sums *sum,
int* firmware_size, unsigned char** of_packed,
int* of_packedsize, char* errstr, int errstrsize)
{
@@ -397,7 +373,6 @@ unsigned char* load_of_file(
off_t n;
unsigned int i=0;
uint32_t checksum;
- int model_id;
unsigned int last_word;
fd = open(filename, O_RDONLY|O_BINARY);
@@ -425,21 +400,20 @@ unsigned char* load_of_file(
if (i < NUM_MD5S) {
*sum = sansasums[i];
+ if(sum->model != model) {
+ ERROR("[ERR] OF File provided is %sv%d version %s, not for %sv%d\n",
+ model_names[sum->model], hw_revisions[sum->model],
+ sum->version, model_names[model], hw_revisions[model]
+ );
+ }
} else {
- int fw_version = (get_uint32le(&buf[0x204]) == 0x0000f000) ? 2 : 1;
- model_id = buf[(fw_version == 2) ? 0x219 : 0x215];
- sum->model = get_model(model_id);
-
- if (sum->model == MODEL_UNKNOWN)
- ERROR("[ERR] Unknown firmware model (v%d) - model id 0x%02x\n",
- fw_version, model_id);
+ /* OF unknown, give a list of tested versions for the requested model */
-#if 1 /* comment to test new OFs */
char tested_versions[100];
tested_versions[0] = '\0';
for (i = 0; i < NUM_MD5S ; i++)
- if (sansasums[i].model == sum->model) {
+ if (sansasums[i].model == model) {
if (tested_versions[0] != '\0') {
strncat(tested_versions, ", ",
sizeof(tested_versions) - strlen(tested_versions) - 1);
@@ -449,9 +423,8 @@ unsigned char* load_of_file(
}
ERROR("[ERR] Original firmware unknown, please try an other version." \
- " Tested %s versions are : %s\n",
- model_names[sum->model], tested_versions);
-#endif
+ " Tested %sv%d versions are : %s\n",
+ model_names[model], hw_revisions[model], tested_versions);
}
/* TODO: Do some more sanity checks on the OF image. Some images (like
@@ -484,7 +457,7 @@ error:
/* Loads a rockbox bootloader file into memory */
unsigned char* load_rockbox_file(
- char* filename, int model, int* bufsize, int* rb_packedsize,
+ char* filename, int *model, int* bufsize, int* rb_packedsize,
char* errstr, int errstrsize)
{
int fd;
@@ -504,10 +477,12 @@ unsigned char* load_rockbox_file(
if (n != sizeof(header))
ERROR("[ERR] Could not read file %s\n", filename);
- /* Check for correct model string */
- if (memcmp(rb_model_names[model], header + 4, 4)!=0)
- ERROR("[ERR] Expected model name \"%s\" in %s, not \"%4.4s\"\n",
- rb_model_names[model], filename, (char*)header+4);
+ for(*model = 0; *model < NUM_MODELS; (*model)++)
+ if (memcmp(rb_model_names[*model], header + 4, 4) == 0)
+ break;
+
+ if(*model == NUM_MODELS)
+ ERROR("[ERR] Model name \"%4.4s\" unknown. Is this really a rockbox bootloader?\n", header + 4);
*bufsize = filesize(fd) - sizeof(header);
@@ -521,7 +496,7 @@ unsigned char* load_rockbox_file(
ERROR("[ERR] Could not read file %s\n", filename);
/* Check checksum */
- sum = rb_model_num[model];
+ sum = rb_model_num[*model];
for (i = 0; i < *bufsize; i++) {
/* add 8 unsigned bits but keep a 32 bit sum */
sum += buf[i];
diff --git a/rbutil/mkamsboot/mkamsboot.h b/rbutil/mkamsboot/mkamsboot.h
index 835d024d98..d87a5df4f7 100644
--- a/rbutil/mkamsboot/mkamsboot.h
+++ b/rbutil/mkamsboot/mkamsboot.h
@@ -43,6 +43,9 @@ enum {
MODEL_C200V2,
MODEL_CLIPPLUS,
MODEL_FUZEV2,
+ /* new models go here */
+
+ NUM_MODELS
};
@@ -65,8 +68,7 @@ extern const int bootloader_sizes[];
* ARGUMENTS
*
* filename : bootloader file to load
- * model : a 4 characters string representing the Sansa model
- * ("fuze", "clip", "e2v2", "m2v4", or "c2v2")
+ * model : will be set to this bootloader's model
* bootloader_size : set to the uncompressed bootloader size
* rb_packed_size : set to the size of compressed bootloader
* errstr : provided buffer to store an eventual error
@@ -78,7 +80,7 @@ extern const int bootloader_sizes[];
*/
unsigned char* load_rockbox_file(
- char* filename, int model, int* bootloader_size, int* rb_packedsize,
+ char* filename, int *model, int* bootloader_size, int* rb_packedsize,
char* errstr, int errstrsize);
@@ -89,10 +91,9 @@ unsigned char* load_rockbox_file(
* ARGUMENTS
*
* filename : firmware file to load
+ * model : desired player's model
* bufsize : set to firmware file size
* md5sum : set to file md5sum, must be at least 33 bytes long
- * model : set to firmware model (MODEL_XXX)
- * fw_version : set to firmware format version (1 or 2)
* firmware_size : set to firmware block's size
* of_packed : pointer to allocated memory containing the compressed
* original firmware block
@@ -106,7 +107,7 @@ unsigned char* load_rockbox_file(
*/
unsigned char* load_of_file(
- char* filename, off_t* bufsize, struct md5sums *sum,
+ char* filename, int model, off_t* bufsize, struct md5sums *sum,
int* firmware_size, unsigned char** of_packed,
int* of_packedsize, char* errstr, int errstrsize);