1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * mkamsboot.h - a tool for merging bootloader code into an Sansa V2
13 * Copyright (C) 2008 Dave Chapman
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
23 ****************************************************************************/
29 #include <sys/types.h>
35 /* Supported models */
47 /* new models go here */
53 /* Holds info about the OF */
61 unsigned short hw_revision
;
62 unsigned short fw_revision
;
63 /* Descriptive name of this model */
64 const char* model_name
;
65 /* Dualboot functions for this model */
66 const unsigned char* bootloader
;
67 /* Size of dualboot functions for this model */
69 /* Model name used in the Rockbox header in ".sansa" files - these match the
70 -add parameter to the "scramble" tool */
71 const char* rb_model_name
;
72 /* Model number used to initialise the checksum in the Rockbox header in
73 ".sansa" files - these are the same as MODEL_NUMBER in config-target.h */
74 const int rb_model_num
;
76 extern const struct ams_models ams_identity
[];
78 /* load_rockbox_file()
80 * Loads a rockbox bootloader file into memory
84 * filename : bootloader file to load
85 * model : will be set to this bootloader's model
86 * bootloader_size : set to the uncompressed bootloader size
87 * rb_packed_size : set to the size of compressed bootloader
88 * errstr : provided buffer to store an eventual error
89 * errstrsize : size of provided error buffer
92 * pointer to allocated memory containing the content of compressed bootloader
93 * or NULL in case of error (errstr will hold a description of the error)
96 unsigned char* load_rockbox_file(
97 char* filename
, int *model
, int* bootloader_size
, int* rb_packedsize
,
98 char* errstr
, int errstrsize
);
103 * Loads a Sansa AMS Original Firmware file into memory
107 * filename : firmware file to load
108 * model : desired player's model
109 * bufsize : set to firmware file size
110 * md5sum : set to file md5sum, must be at least 33 bytes long
111 * firmware_size : set to firmware block's size
112 * of_packed : pointer to allocated memory containing the compressed
113 * original firmware block
114 * of_packedsize : size of compressed original firmware block
115 * errstr : provided buffer to store an eventual error
116 * errstrsize : size of provided error buffer
119 * pointer to allocated memory containing the content of Original Firmware
120 * or NULL in case of error (errstr will hold a description of the error)
123 unsigned char* load_of_file(
124 char* filename
, int model
, off_t
* bufsize
, struct md5sums
*sum
,
125 int* firmware_size
, unsigned char** of_packed
,
126 int* of_packedsize
, char* errstr
, int errstrsize
);
131 * Patches a Sansa AMS Original Firmware file
135 * model : firmware model (MODEL_XXX)
136 * fw_version : firmware format version (1 or 2)
137 * firmware_size : size of uncompressed original firmware block
138 * buf : pointer to original firmware file
139 * len : size of original firmware file
140 * of_packed : pointer to compressed original firmware block
141 * of_packedsize : size of compressed original firmware block
142 * rb_packed : pointer to compressed rockbox bootloader
143 * rb_packed_size : size of compressed rockbox bootloader
147 int model
, int fw_version
, int firmware_size
, unsigned char* buf
,
148 int len
, unsigned char* of_packed
, int of_packedsize
,
149 unsigned char* rb_packed
, int rb_packedsize
);
154 * Verify if the given bootloader can be embedded in the OF file, while still
155 * allowing both the bootloader and the OF to be unpacked at runtime
159 * model : firmware model (MODEL_XXX)
160 * rb_packed_size : size of compressed rockbox bootloader
161 * rb_unpacked_size : size of compressed rockbox bootloader
162 * of_packed_size : size of compressed original firmware block
163 * of_unpacked_size : size of compressed original firmware block
164 * total_size : will contain the size of useful data that would be
165 * written to the firmware block, even in case of an
167 * errstr : provided buffer to store an eventual error
168 * errstrsize : size of provided error buffer
171 * 0 if the conditions aren't met, 1 if we can go and patch the firmware
174 int check_sizes(int model
, int rb_packed_size
, int rb_unpacked_size
,
175 int of_packed_size
, int of_unpacked_size
, int *total_size
,
176 char *errstr
, int errstrsize
);
178 /* firmware_revision()
180 * returns the firmware revision for a particular model
184 * model : firmware model (MODEL_XXX)
189 int firmware_revision(int model
);