blob: 263fe9e9c15160ed00f598aee563efbbcfb5aeda [file] [log] [blame]
Rafaël Carré96165ab2009-05-28 18:27:08 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * mkamsboot.h - a tool for merging bootloader code into an Sansa V2
11 * (AMS) firmware file
12 *
13 * Copyright (C) 2008 Dave Chapman
14 *
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.
19 *
20 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21 * KIND, either express or implied.
22 *
23 ****************************************************************************/
24
25#ifndef MKAMSBOOT_H
26#define MKAMSBOOT_H
27
28#include <stdint.h>
29#include <sys/types.h>
30
Dominik Wengercb55d5c2009-08-15 14:09:05 +000031#ifdef __cplusplus
32extern "C" {
Rafaël Carréb6c20c12010-02-19 14:10:26 +000033#endif
Dominik Wengercb55d5c2009-08-15 14:09:05 +000034
Rafaël Carréef7ad192009-07-05 08:25:44 +000035/* Supported models */
36enum {
37 MODEL_UNKNOWN = -1,
38 MODEL_FUZE = 0,
39 MODEL_CLIP,
40 MODEL_CLIPV2,
41 MODEL_E200V2,
42 MODEL_M200V4,
43 MODEL_C200V2,
Rafaël Carré8b926e92010-01-13 03:05:29 +000044 MODEL_CLIPPLUS,
Thomas Martitzf6540e82010-02-26 13:55:17 +000045 MODEL_FUZEV2,
Bertrik Sikken463b3ed2011-08-27 16:21:19 +000046 MODEL_CLIPZIP,
Rafaël Carréff6b0422010-05-24 10:06:52 +000047 /* new models go here */
48
49 NUM_MODELS
Rafaël Carréef7ad192009-07-05 08:25:44 +000050};
51
Rafaël Carré96165ab2009-05-28 18:27:08 +000052
Thomas Martitzf9eeab22009-07-05 02:30:33 +000053/* Holds info about the OF */
54struct md5sums {
55 int model;
56 char *version;
57 char *md5;
58};
59
Dominik Riebeling02dce452011-01-31 20:15:50 +000060struct ams_models {
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 */
68 int bootloader_size;
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;
75};
76extern const struct ams_models ams_identity[];
Dominik Riebelingea617802009-11-04 20:58:40 +000077
Rafaël Carré96165ab2009-05-28 18:27:08 +000078/* load_rockbox_file()
79 *
80 * Loads a rockbox bootloader file into memory
81 *
82 * ARGUMENTS
83 *
84 * filename : bootloader file to load
Rafaël Carréff6b0422010-05-24 10:06:52 +000085 * model : will be set to this bootloader's model
Rafaël Carré96165ab2009-05-28 18:27:08 +000086 * 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
90 *
91 * RETURN VALUE
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)
94 */
95
96unsigned char* load_rockbox_file(
Rafaël Carréff6b0422010-05-24 10:06:52 +000097 char* filename, int *model, int* bootloader_size, int* rb_packedsize,
Rafaël Carré96165ab2009-05-28 18:27:08 +000098 char* errstr, int errstrsize);
99
100
101/* load_of_file()
102 *
103 * Loads a Sansa AMS Original Firmware file into memory
104 *
105 * ARGUMENTS
106 *
107 * filename : firmware file to load
Rafaël Carréff6b0422010-05-24 10:06:52 +0000108 * model : desired player's model
Rafaël Carré96165ab2009-05-28 18:27:08 +0000109 * bufsize : set to firmware file size
110 * md5sum : set to file md5sum, must be at least 33 bytes long
Rafaël Carré96165ab2009-05-28 18:27:08 +0000111 * 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
117 *
118 * RETURN VALUE
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)
121 */
122
123unsigned char* load_of_file(
Rafaël Carréff6b0422010-05-24 10:06:52 +0000124 char* filename, int model, off_t* bufsize, struct md5sums *sum,
Thomas Martitzf9eeab22009-07-05 02:30:33 +0000125 int* firmware_size, unsigned char** of_packed,
Rafaël Carré96165ab2009-05-28 18:27:08 +0000126 int* of_packedsize, char* errstr, int errstrsize);
127
128
129/* patch_firmware()
130 *
131 * Patches a Sansa AMS Original Firmware file
132 *
133 * ARGUMENTS
134 *
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
144 */
145
146void patch_firmware(
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);
150
151
Rafaël Carréb6c20c12010-02-19 14:10:26 +0000152/* check_sizes()
Rafaël Carré96165ab2009-05-28 18:27:08 +0000153 *
Rafaël Carréb6c20c12010-02-19 14:10:26 +0000154 * 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
Rafaël Carré96165ab2009-05-28 18:27:08 +0000156 *
157 * ARGUMENTS
158 *
159 * model : firmware model (MODEL_XXX)
160 * rb_packed_size : size of compressed rockbox bootloader
Rafaël Carréb6c20c12010-02-19 14:10:26 +0000161 * 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
166 * error
167 * errstr : provided buffer to store an eventual error
168 * errstrsize : size of provided error buffer
Rafaël Carré96165ab2009-05-28 18:27:08 +0000169 *
170 * RETURN VALUE
Rafaël Carréb6c20c12010-02-19 14:10:26 +0000171 * 0 if the conditions aren't met, 1 if we can go and patch the firmware
Rafaël Carré96165ab2009-05-28 18:27:08 +0000172*/
173
Rafaël Carréb6c20c12010-02-19 14:10:26 +0000174int 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);
Rafaël Carré96165ab2009-05-28 18:27:08 +0000177
Dominik Wengera66dfa42009-08-15 13:04:21 +0000178/* firmware_revision()
179 *
180 * returns the firmware revision for a particular model
181 *
182 * ARGUMENTS
183 *
184 * model : firmware model (MODEL_XXX)
185 *
186 * RETURN VALUE
187 * firmware version
188*/
189int firmware_revision(int model);
190
Dominik Wengercb55d5c2009-08-15 14:09:05 +0000191#ifdef __cplusplus
192};
Rafaël Carréb6c20c12010-02-19 14:10:26 +0000193#endif
Dominik Wengercb55d5c2009-08-15 14:09:05 +0000194
Rafaël Carré96165ab2009-05-28 18:27:08 +0000195#endif