mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-08 12:45:26 -05:00
Clean up mkamsboot building. No functional changes.
- split out standalone functions to a separate file. - adjust and clean up Makefile. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23520 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
33d3b54abc
commit
ea6178065c
4 changed files with 199 additions and 151 deletions
|
|
@ -1,12 +1,13 @@
|
||||||
# We use the UCL code available in the Rockbox tools/ directory
|
|
||||||
CFLAGS=-I../../tools/ucl/include -Wall
|
|
||||||
CC = gcc
|
|
||||||
|
|
||||||
#change for releases
|
#change for releases
|
||||||
ifndef APPVERSION
|
ifndef APPVERSION
|
||||||
APPVERSION=`../../tools/version.sh`
|
APPVERSION=`../../tools/version.sh`
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# We use the UCL code available in the Rockbox tools/ directory
|
||||||
|
CFLAGS=-I../../tools/ucl/include -Wall -DVERSION=\"$(APPVERSION)\"
|
||||||
|
CC = gcc
|
||||||
|
|
||||||
ifndef V
|
ifndef V
|
||||||
SILENT = @
|
SILENT = @
|
||||||
endif
|
endif
|
||||||
|
|
@ -34,38 +35,36 @@ OUT = $(TARGET_DIR)build$(RBARCH)
|
||||||
|
|
||||||
all: $(OUTPUT)
|
all: $(OUTPUT)
|
||||||
|
|
||||||
# Dependant modules
|
# additional link dependencies for the standalone executable
|
||||||
LIBUCL=../../tools/ucl/src/libucl$(RBARCH).a
|
LIBUCL=../../tools/ucl/src/libucl$(RBARCH).a
|
||||||
|
|
||||||
$(LIBUCL):
|
$(LIBUCL):
|
||||||
make -C ../../tools/ucl/src $(TARGET_DIR)libucl$(RBARCH).a
|
make -C ../../tools/ucl/src $(TARGET_DIR)libucl$(RBARCH).a
|
||||||
|
|
||||||
# This file can be generated in the dualboot/ directory
|
# inputs
|
||||||
$(OUT)/dualboot.o: dualboot.[ch]
|
LIBSOURCES := dualboot.c md5.c mkamsboot.c
|
||||||
@echo CC $<
|
SOURCES := $(LIBSOURCES) main.c
|
||||||
$(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/dualboot.o dualboot.c
|
OBJS := $(patsubst %.c,%.o,$(addprefix $(OUT)/,$(SOURCES)))
|
||||||
|
LIBOBJS := $(patsubst %.c,%.o,$(addprefix $(OUT)/,$(LIBSOURCES)))
|
||||||
|
EXTRADEPS := $(LIBUCL)
|
||||||
|
|
||||||
$(OUT)/md5.o: md5.[ch]
|
$(OUT)/%.o: %.c $(OUT)
|
||||||
@echo CC $<
|
@echo CC $< $
|
||||||
$(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/md5.o -W -Wall md5.c
|
$(SILENT)$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
DEPENDANT_OBJS=$(LIBUCL) $(OUT)/dualboot.o $(OUT)/md5.o
|
|
||||||
|
|
||||||
$(OUT)/mkamsboot.o: mkamsboot.[ch] $(DEPENDANT_OBJS)
|
|
||||||
@echo CC $<
|
|
||||||
$(SILENT)$(CC) $(CFLAGS) -c -o $(OUT)/mkamsboot.o -W -Wall mkamsboot.c -DVERSION=\"$(APPVERSION)\"
|
|
||||||
|
|
||||||
$(OUTPUT): $(OUT) $(OUT)/mkamsboot.o
|
|
||||||
@echo CC $<
|
|
||||||
$(SILENT)$(CC) $(CFLAGS) -o $(OUTPUT) $(OUT)/mkamsboot.o $(DEPENDANT_OBJS)
|
|
||||||
|
|
||||||
|
# building the library archive
|
||||||
$(OUT)/libmkamsboot.o: $(OUT)/mkamsboot.o
|
$(OUT)/libmkamsboot.o: $(OUT)/mkamsboot.o
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
$(SILENT)$(CC) $(CFLAGS) -DLIB -c -o $(OUT)/libmkamsboot.o -W -Wall mkamsboot.c
|
$(SILENT)$(CC) $(CFLAGS) -DLIB -c -o $(OUT)/libmkamsboot.o -W -Wall mkamsboot.c
|
||||||
|
|
||||||
libmkamsboot$(RBARCH).a: $(OUT) $(OUT)/libmkamsboot.o
|
libmkamsboot$(RBARCH).a: $(LIBOBJS)
|
||||||
@echo AR $@
|
@echo AR $@
|
||||||
$(SILENT)$(AR) ruc $(TARGET_DIR)libmkamsboot$(RBARCH).a $(OUT)/libmkamsboot.o $(OUT)/md5.o $(OUT)/dualboot.o
|
$(SILENT)$(AR) ruc $(TARGET_DIR)$@ $^
|
||||||
|
|
||||||
|
# building the standalone executable
|
||||||
|
$(OUTPUT): $(OBJS) $(EXTRADEPS)
|
||||||
|
@echo LD $@
|
||||||
|
$(SILENT)$(CC) $(CFLAGS) -o$(OUTPUT) $(OBJS) $(EXTRADEPS)
|
||||||
|
|
||||||
# some trickery to build ppc and i386 from a single call
|
# some trickery to build ppc and i386 from a single call
|
||||||
ifeq ($(RBARCH),)
|
ifeq ($(RBARCH),)
|
||||||
|
|
|
||||||
168
rbutil/mkamsboot/main.c
Normal file
168
rbutil/mkamsboot/main.c
Normal file
|
|
@ -0,0 +1,168 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* __________ __ ___.
|
||||||
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||||
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||||
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||||
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||||
|
* \/ \/ \/ \/ \/
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
* mkamsboot - a tool for merging bootloader code into an Sansa V2
|
||||||
|
* (AMS) firmware file
|
||||||
|
*
|
||||||
|
* Copyright (C) 2008 Dave Chapman
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||||
|
* KIND, either express or implied.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <ucl/ucl.h>
|
||||||
|
|
||||||
|
#include "mkamsboot.h"
|
||||||
|
|
||||||
|
/* Header for ARM code binaries */
|
||||||
|
#include "dualboot.h"
|
||||||
|
|
||||||
|
/* Win32 compatibility */
|
||||||
|
#ifndef O_BINARY
|
||||||
|
#define O_BINARY 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* standalone executable */
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
char *infile, *bootfile, *outfile;
|
||||||
|
int fdout;
|
||||||
|
off_t len;
|
||||||
|
uint32_t n;
|
||||||
|
unsigned char* buf;
|
||||||
|
int firmware_size;
|
||||||
|
int bootloader_size;
|
||||||
|
unsigned char* of_packed;
|
||||||
|
int of_packedsize;
|
||||||
|
unsigned char* rb_packed;
|
||||||
|
int rb_packedsize;
|
||||||
|
int totalsize;
|
||||||
|
char errstr[200];
|
||||||
|
struct md5sums sum;
|
||||||
|
char md5sum[33]; /* 32 digits + \0 */
|
||||||
|
|
||||||
|
sum.md5 = md5sum;
|
||||||
|
|
||||||
|
/* VERSION comes frome the Makefile */
|
||||||
|
fprintf(stderr,
|
||||||
|
"mkamsboot Version " VERSION "\n"
|
||||||
|
"This is free software; see the source for copying conditions. There is NO\n"
|
||||||
|
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
|
||||||
|
"\n");
|
||||||
|
|
||||||
|
if(argc != 4) {
|
||||||
|
printf("Usage: mkamsboot <firmware file> <boot file> <output file>\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
infile = argv[1];
|
||||||
|
bootfile = argv[2];
|
||||||
|
outfile = argv[3];
|
||||||
|
|
||||||
|
/* Load original firmware file */
|
||||||
|
buf = load_of_file(infile, &len, &sum,
|
||||||
|
&firmware_size, &of_packed, &of_packedsize, errstr, sizeof(errstr));
|
||||||
|
|
||||||
|
if (buf == NULL) {
|
||||||
|
fprintf(stderr, "%s", errstr);
|
||||||
|
fprintf(stderr, "[ERR] Could not load %s\n", infile);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "[INFO] Original firmware MD5 checksum match\n");
|
||||||
|
fprintf(stderr, "[INFO] Model: Sansa %s v%d - Firmware version: %s\n",
|
||||||
|
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",
|
||||||
|
firmware_size);
|
||||||
|
fprintf(stderr, "[INFO] Packed OF size: %d bytes\n",
|
||||||
|
of_packedsize);
|
||||||
|
fprintf(stderr, "[INFO] Bootloader size: %d bytes\n",
|
||||||
|
(int)bootloader_size);
|
||||||
|
fprintf(stderr, "[INFO] Packed bootloader size: %d bytes\n",
|
||||||
|
rb_packedsize);
|
||||||
|
fprintf(stderr, "[INFO] Dual-boot function size: %d bytes\n",
|
||||||
|
bootloader_sizes[sum.model]);
|
||||||
|
fprintf(stderr, "[INFO] UCL unpack function size: %u bytes\n",
|
||||||
|
(unsigned int)sizeof(nrv2e_d8));
|
||||||
|
|
||||||
|
totalsize = total_size(sum.model, of_packedsize, rb_packedsize);
|
||||||
|
|
||||||
|
fprintf(stderr, "[INFO] Total size of new image: %d bytes\n", totalsize);
|
||||||
|
|
||||||
|
if (totalsize > firmware_size) {
|
||||||
|
fprintf(stderr, "[ERR] No room to insert bootloader, aborting\n");
|
||||||
|
free(buf);
|
||||||
|
free(of_packed);
|
||||||
|
free(rb_packed);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
patch_firmware(sum.model, fw_revisions[sum.model], firmware_size, buf, len,
|
||||||
|
of_packed, of_packedsize, rb_packed, rb_packedsize);
|
||||||
|
|
||||||
|
/* Write the new firmware */
|
||||||
|
fdout = open(outfile, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666);
|
||||||
|
|
||||||
|
if (fdout < 0) {
|
||||||
|
fprintf(stderr, "[ERR] Could not open %s for writing\n", outfile);
|
||||||
|
free(buf);
|
||||||
|
free(of_packed);
|
||||||
|
free(rb_packed);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
n = write(fdout, buf, len);
|
||||||
|
|
||||||
|
if (n != (unsigned)len) {
|
||||||
|
fprintf(stderr, "[ERR] Could not write firmware file\n");
|
||||||
|
free(buf);
|
||||||
|
free(of_packed);
|
||||||
|
free(rb_packed);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
close(fdout);
|
||||||
|
free(buf);
|
||||||
|
free(of_packed);
|
||||||
|
free(rb_packed);
|
||||||
|
fprintf(stderr, "\n[INFO] Patching succeeded!\n");
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -110,7 +110,7 @@ execution to the uncompressed firmware.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* 4 for m200, 2 for e200/c200, 1 or 2 for fuze/clop */
|
/* 4 for m200, 2 for e200/c200, 1 or 2 for fuze/clop */
|
||||||
static const unsigned short hw_revisions[] = {
|
const unsigned short hw_revisions[] = {
|
||||||
[MODEL_FUZE] = 1,
|
[MODEL_FUZE] = 1,
|
||||||
[MODEL_CLIP] = 1,
|
[MODEL_CLIP] = 1,
|
||||||
[MODEL_CLIPV2] = 2,
|
[MODEL_CLIPV2] = 2,
|
||||||
|
|
@ -120,7 +120,7 @@ static const unsigned short hw_revisions[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* version 2 is used in Clipv2 and Fuzev2 firmwares */
|
/* version 2 is used in Clipv2 and Fuzev2 firmwares */
|
||||||
static const unsigned short fw_revisions[] = {
|
const unsigned short fw_revisions[] = {
|
||||||
[MODEL_FUZE] = 1,
|
[MODEL_FUZE] = 1,
|
||||||
[MODEL_CLIP] = 1,
|
[MODEL_CLIP] = 1,
|
||||||
[MODEL_CLIPV2] = 2,
|
[MODEL_CLIPV2] = 2,
|
||||||
|
|
@ -130,7 +130,7 @@ static const unsigned short fw_revisions[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Descriptive name of these models */
|
/* Descriptive name of these models */
|
||||||
static const char* model_names[] = {
|
const char* model_names[] = {
|
||||||
[MODEL_FUZE] = "Fuze",
|
[MODEL_FUZE] = "Fuze",
|
||||||
[MODEL_CLIP] = "Clip",
|
[MODEL_CLIP] = "Clip",
|
||||||
[MODEL_CLIPV2] = "Clip",
|
[MODEL_CLIPV2] = "Clip",
|
||||||
|
|
@ -150,7 +150,7 @@ static const unsigned char* bootloaders[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Size of dualboot functions for these models */
|
/* Size of dualboot functions for these models */
|
||||||
static const int bootloader_sizes[] = {
|
const int bootloader_sizes[] = {
|
||||||
[MODEL_FUZE] = sizeof(dualboot_fuze),
|
[MODEL_FUZE] = sizeof(dualboot_fuze),
|
||||||
[MODEL_CLIP] = sizeof(dualboot_clip),
|
[MODEL_CLIP] = sizeof(dualboot_clip),
|
||||||
[MODEL_CLIPV2] = sizeof(dualboot_clipv2),
|
[MODEL_CLIPV2] = sizeof(dualboot_clipv2),
|
||||||
|
|
@ -574,127 +574,3 @@ int total_size(int model, int rb_packedsize, int of_packedsize)
|
||||||
rb_packedsize;
|
rb_packedsize;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef LIB
|
|
||||||
/* standalone executable */
|
|
||||||
int main(int argc, char* argv[])
|
|
||||||
{
|
|
||||||
char *infile, *bootfile, *outfile;
|
|
||||||
int fdout;
|
|
||||||
off_t len;
|
|
||||||
uint32_t n;
|
|
||||||
unsigned char* buf;
|
|
||||||
int firmware_size;
|
|
||||||
int bootloader_size;
|
|
||||||
unsigned char* of_packed;
|
|
||||||
int of_packedsize;
|
|
||||||
unsigned char* rb_packed;
|
|
||||||
int rb_packedsize;
|
|
||||||
int totalsize;
|
|
||||||
char errstr[200];
|
|
||||||
struct md5sums sum;
|
|
||||||
char md5sum[33]; /* 32 digits + \0 */
|
|
||||||
|
|
||||||
sum.md5 = md5sum;
|
|
||||||
|
|
||||||
/* VERSION comes frome the Makefile */
|
|
||||||
fprintf(stderr,
|
|
||||||
"mkamsboot Version " VERSION "\n"
|
|
||||||
"This is free software; see the source for copying conditions. There is NO\n"
|
|
||||||
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"
|
|
||||||
"\n");
|
|
||||||
|
|
||||||
if(argc != 4) {
|
|
||||||
printf("Usage: mkamsboot <firmware file> <boot file> <output file>\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
infile = argv[1];
|
|
||||||
bootfile = argv[2];
|
|
||||||
outfile = argv[3];
|
|
||||||
|
|
||||||
/* Load original firmware file */
|
|
||||||
buf = load_of_file(infile, &len, &sum,
|
|
||||||
&firmware_size, &of_packed, &of_packedsize, errstr, sizeof(errstr));
|
|
||||||
|
|
||||||
if (buf == NULL) {
|
|
||||||
fprintf(stderr, "%s", errstr);
|
|
||||||
fprintf(stderr, "[ERR] Could not load %s\n", infile);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "[INFO] Original firmware MD5 checksum match\n");
|
|
||||||
fprintf(stderr, "[INFO] Model: Sansa %s v%d - Firmware version: %s\n",
|
|
||||||
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",
|
|
||||||
firmware_size);
|
|
||||||
fprintf(stderr, "[INFO] Packed OF size: %d bytes\n",
|
|
||||||
of_packedsize);
|
|
||||||
fprintf(stderr, "[INFO] Bootloader size: %d bytes\n",
|
|
||||||
(int)bootloader_size);
|
|
||||||
fprintf(stderr, "[INFO] Packed bootloader size: %d bytes\n",
|
|
||||||
rb_packedsize);
|
|
||||||
fprintf(stderr, "[INFO] Dual-boot function size: %d bytes\n",
|
|
||||||
bootloader_sizes[sum.model]);
|
|
||||||
fprintf(stderr, "[INFO] UCL unpack function size: %u bytes\n",
|
|
||||||
(unsigned int)sizeof(nrv2e_d8));
|
|
||||||
|
|
||||||
totalsize = total_size(sum.model, of_packedsize, rb_packedsize);
|
|
||||||
|
|
||||||
fprintf(stderr, "[INFO] Total size of new image: %d bytes\n", totalsize);
|
|
||||||
|
|
||||||
if (totalsize > firmware_size) {
|
|
||||||
fprintf(stderr, "[ERR] No room to insert bootloader, aborting\n");
|
|
||||||
free(buf);
|
|
||||||
free(of_packed);
|
|
||||||
free(rb_packed);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
patch_firmware(sum.model, fw_revisions[sum.model], firmware_size, buf, len,
|
|
||||||
of_packed, of_packedsize, rb_packed, rb_packedsize);
|
|
||||||
|
|
||||||
/* Write the new firmware */
|
|
||||||
fdout = open(outfile, O_CREAT|O_TRUNC|O_WRONLY|O_BINARY, 0666);
|
|
||||||
|
|
||||||
if (fdout < 0) {
|
|
||||||
fprintf(stderr, "[ERR] Could not open %s for writing\n", outfile);
|
|
||||||
free(buf);
|
|
||||||
free(of_packed);
|
|
||||||
free(rb_packed);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
n = write(fdout, buf, len);
|
|
||||||
|
|
||||||
if (n != (unsigned)len) {
|
|
||||||
fprintf(stderr, "[ERR] Could not write firmware file\n");
|
|
||||||
free(buf);
|
|
||||||
free(of_packed);
|
|
||||||
free(rb_packed);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
close(fdout);
|
|
||||||
free(buf);
|
|
||||||
free(of_packed);
|
|
||||||
free(rb_packed);
|
|
||||||
fprintf(stderr, "\n[INFO] Patching succeeded!\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,11 @@ struct md5sums {
|
||||||
char *md5;
|
char *md5;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern const unsigned short hw_revisions[];
|
||||||
|
extern const unsigned short fw_revisions[];
|
||||||
|
extern const char* model_names[];
|
||||||
|
extern const int bootloader_sizes[];
|
||||||
|
|
||||||
/* load_rockbox_file()
|
/* load_rockbox_file()
|
||||||
*
|
*
|
||||||
* Loads a rockbox bootloader file into memory
|
* Loads a rockbox bootloader file into memory
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue