2009-05-28 18:27:08 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* mkamsboot.h - 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef MKAMSBOOT_H
|
|
|
|
#define MKAMSBOOT_H
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
2009-08-15 14:09:05 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
#endif
|
2009-08-15 14:09:05 +00:00
|
|
|
|
2009-07-05 08:25:44 +00:00
|
|
|
/* Supported models */
|
|
|
|
enum {
|
|
|
|
MODEL_UNKNOWN = -1,
|
|
|
|
MODEL_FUZE = 0,
|
|
|
|
MODEL_CLIP,
|
|
|
|
MODEL_CLIPV2,
|
|
|
|
MODEL_E200V2,
|
|
|
|
MODEL_M200V4,
|
|
|
|
MODEL_C200V2,
|
2010-01-13 03:05:29 +00:00
|
|
|
MODEL_CLIPPLUS,
|
2010-02-26 13:55:17 +00:00
|
|
|
MODEL_FUZEV2,
|
2010-05-24 10:06:52 +00:00
|
|
|
/* new models go here */
|
|
|
|
|
|
|
|
NUM_MODELS
|
2009-07-05 08:25:44 +00:00
|
|
|
};
|
|
|
|
|
2009-05-28 18:27:08 +00:00
|
|
|
|
2009-07-05 02:30:33 +00:00
|
|
|
/* Holds info about the OF */
|
|
|
|
struct md5sums {
|
|
|
|
int model;
|
|
|
|
char *version;
|
|
|
|
char *md5;
|
|
|
|
};
|
|
|
|
|
2011-01-31 20:15:50 +00:00
|
|
|
struct ams_models {
|
|
|
|
unsigned short hw_revision;
|
|
|
|
unsigned short fw_revision;
|
|
|
|
/* Descriptive name of this model */
|
|
|
|
const char* model_name;
|
|
|
|
/* Dualboot functions for this model */
|
|
|
|
const unsigned char* bootloader;
|
|
|
|
/* Size of dualboot functions for this model */
|
|
|
|
int bootloader_size;
|
|
|
|
/* Model name used in the Rockbox header in ".sansa" files - these match the
|
|
|
|
-add parameter to the "scramble" tool */
|
|
|
|
const char* rb_model_name;
|
|
|
|
/* Model number used to initialise the checksum in the Rockbox header in
|
|
|
|
".sansa" files - these are the same as MODEL_NUMBER in config-target.h */
|
|
|
|
const int rb_model_num;
|
|
|
|
};
|
|
|
|
extern const struct ams_models ams_identity[];
|
2009-11-04 20:58:40 +00:00
|
|
|
|
2009-05-28 18:27:08 +00:00
|
|
|
/* load_rockbox_file()
|
|
|
|
*
|
|
|
|
* Loads a rockbox bootloader file into memory
|
|
|
|
*
|
|
|
|
* ARGUMENTS
|
|
|
|
*
|
|
|
|
* filename : bootloader file to load
|
2010-05-24 10:06:52 +00:00
|
|
|
* model : will be set to this bootloader's model
|
2009-05-28 18:27:08 +00:00
|
|
|
* 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
|
|
|
|
* errstrsize : size of provided error buffer
|
|
|
|
*
|
|
|
|
* RETURN VALUE
|
|
|
|
* pointer to allocated memory containing the content of compressed bootloader
|
|
|
|
* or NULL in case of error (errstr will hold a description of the error)
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned char* load_rockbox_file(
|
2010-05-24 10:06:52 +00:00
|
|
|
char* filename, int *model, int* bootloader_size, int* rb_packedsize,
|
2009-05-28 18:27:08 +00:00
|
|
|
char* errstr, int errstrsize);
|
|
|
|
|
|
|
|
|
|
|
|
/* load_of_file()
|
|
|
|
*
|
|
|
|
* Loads a Sansa AMS Original Firmware file into memory
|
|
|
|
*
|
|
|
|
* ARGUMENTS
|
|
|
|
*
|
|
|
|
* filename : firmware file to load
|
2010-05-24 10:06:52 +00:00
|
|
|
* model : desired player's model
|
2009-05-28 18:27:08 +00:00
|
|
|
* bufsize : set to firmware file size
|
|
|
|
* md5sum : set to file md5sum, must be at least 33 bytes long
|
|
|
|
* firmware_size : set to firmware block's size
|
|
|
|
* of_packed : pointer to allocated memory containing the compressed
|
|
|
|
* original firmware block
|
|
|
|
* of_packedsize : size of compressed original firmware block
|
|
|
|
* errstr : provided buffer to store an eventual error
|
|
|
|
* errstrsize : size of provided error buffer
|
|
|
|
*
|
|
|
|
* RETURN VALUE
|
|
|
|
* pointer to allocated memory containing the content of Original Firmware
|
|
|
|
* or NULL in case of error (errstr will hold a description of the error)
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned char* load_of_file(
|
2010-05-24 10:06:52 +00:00
|
|
|
char* filename, int model, off_t* bufsize, struct md5sums *sum,
|
2009-07-05 02:30:33 +00:00
|
|
|
int* firmware_size, unsigned char** of_packed,
|
2009-05-28 18:27:08 +00:00
|
|
|
int* of_packedsize, char* errstr, int errstrsize);
|
|
|
|
|
|
|
|
|
|
|
|
/* patch_firmware()
|
|
|
|
*
|
|
|
|
* Patches a Sansa AMS Original Firmware file
|
|
|
|
*
|
|
|
|
* ARGUMENTS
|
|
|
|
*
|
|
|
|
* model : firmware model (MODEL_XXX)
|
|
|
|
* fw_version : firmware format version (1 or 2)
|
|
|
|
* firmware_size : size of uncompressed original firmware block
|
|
|
|
* buf : pointer to original firmware file
|
|
|
|
* len : size of original firmware file
|
|
|
|
* of_packed : pointer to compressed original firmware block
|
|
|
|
* of_packedsize : size of compressed original firmware block
|
|
|
|
* rb_packed : pointer to compressed rockbox bootloader
|
|
|
|
* rb_packed_size : size of compressed rockbox bootloader
|
|
|
|
*/
|
|
|
|
|
|
|
|
void patch_firmware(
|
|
|
|
int model, int fw_version, int firmware_size, unsigned char* buf,
|
|
|
|
int len, unsigned char* of_packed, int of_packedsize,
|
|
|
|
unsigned char* rb_packed, int rb_packedsize);
|
|
|
|
|
|
|
|
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
/* check_sizes()
|
2009-05-28 18:27:08 +00:00
|
|
|
*
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
* Verify if the given bootloader can be embedded in the OF file, while still
|
|
|
|
* allowing both the bootloader and the OF to be unpacked at runtime
|
2009-05-28 18:27:08 +00:00
|
|
|
*
|
|
|
|
* ARGUMENTS
|
|
|
|
*
|
|
|
|
* model : firmware model (MODEL_XXX)
|
|
|
|
* rb_packed_size : size of compressed rockbox bootloader
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
* rb_unpacked_size : size of compressed rockbox bootloader
|
|
|
|
* of_packed_size : size of compressed original firmware block
|
|
|
|
* of_unpacked_size : size of compressed original firmware block
|
|
|
|
* total_size : will contain the size of useful data that would be
|
|
|
|
* written to the firmware block, even in case of an
|
|
|
|
* error
|
|
|
|
* errstr : provided buffer to store an eventual error
|
|
|
|
* errstrsize : size of provided error buffer
|
2009-05-28 18:27:08 +00:00
|
|
|
*
|
|
|
|
* RETURN VALUE
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
* 0 if the conditions aren't met, 1 if we can go and patch the firmware
|
2009-05-28 18:27:08 +00:00
|
|
|
*/
|
|
|
|
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
int check_sizes(int model, int rb_packed_size, int rb_unpacked_size,
|
|
|
|
int of_packed_size, int of_unpacked_size, int *total_size,
|
|
|
|
char *errstr, int errstrsize);
|
2009-05-28 18:27:08 +00:00
|
|
|
|
2009-08-15 13:04:21 +00:00
|
|
|
/* firmware_revision()
|
|
|
|
*
|
|
|
|
* returns the firmware revision for a particular model
|
|
|
|
*
|
|
|
|
* ARGUMENTS
|
|
|
|
*
|
|
|
|
* model : firmware model (MODEL_XXX)
|
|
|
|
*
|
|
|
|
* RETURN VALUE
|
|
|
|
* firmware version
|
|
|
|
*/
|
|
|
|
int firmware_revision(int model);
|
|
|
|
|
2009-08-15 14:09:05 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
};
|
mkamsboot: prevents 2 potential problems
We checked if the new firmware block (bootloader+ucl function+packed
bootloader & OF) fit in the OF file, but not if it would run properly.
For example the Clipv2 OF is bigger than 0x50000 bytes uncompressed, but
it fitted in this space when packed and concatenated to a packed
bootloader + ucl function and dualboot code (but we use 1MB of RAM and
not 0x50000 anyway).
Now we check that both bootloader and OF are small enough to be unpacked
at runtime: the unpacked data must be smaller than available memory and
not overlap with ucl function and packed data (although the unpacked and
packed data could probably overlap a bit, I don't know how to calculate
this and this could be quite complex).
total_size() is replaced by check_sizes() which will perform all the
checks and set an error string if the firmware can't be patched.
(both mkamsboot and rbutilqt modified accordingly)
The second problem is that dualboot.S assumed r3 and r5 were left
untouched in the device specific checks. This was undocumented and very
error prone when modifying these checks.
r3 is the last byte of packed copy (bootloader or OF)
r5 is the entry point of uclunpack function derived from r3, so move r5
calculation after the device specific code.
Even if r3 is currently unused in the device specific code, we store it
in memory after copying the ucl function, when it points to the last byte
of packed data (not yet copied at this point since we didn't chose if we
boot the OF or the bootloader), and restore it just before using it so no
restriction is placed on registers usage in device specific code.
Add a new variable ucl_dest in dualboot.S set by mkamsboot.c, which
represents the last bound of buffer where we copy the ucl function, and
then the packed data (bootloader or OF).
RAM_SIZE definition is moved from dualboot.S to mkamsboot.c new
model_memory_size(), where it is a bit better documented.
Tested on e200v2 and Clip+
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24772 a1c6a512-1295-4272-9138-f99709370657
2010-02-19 14:10:26 +00:00
|
|
|
#endif
|
2009-08-15 14:09:05 +00:00
|
|
|
|
2009-05-28 18:27:08 +00:00
|
|
|
#endif
|