Add "elfzip" target to make which creates a zip of all elf files, as mapzip does...
[maemo-rb.git] / rbutil / mkamsboot / mkamsboot.h
blob156315e4e471182be23916c78c2991a5cae55f5f
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * mkamsboot.h - a tool for merging bootloader code into an Sansa V2
11 * (AMS) firmware file
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 ****************************************************************************/
25 #ifndef MKAMSBOOT_H
26 #define MKAMSBOOT_H
28 #include <stdint.h>
29 #include <sys/types.h>
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
35 /* Supported models */
36 enum {
37 MODEL_UNKNOWN = -1,
38 MODEL_FUZE = 0,
39 MODEL_CLIP,
40 MODEL_CLIPV2,
41 MODEL_E200V2,
42 MODEL_M200V4,
43 MODEL_C200V2,
44 MODEL_CLIPPLUS,
45 MODEL_FUZEV2,
46 /* new models go here */
48 NUM_MODELS
52 /* Holds info about the OF */
53 struct md5sums {
54 int model;
55 char *version;
56 char *md5;
59 struct ams_models {
60 unsigned short hw_revision;
61 unsigned short fw_revision;
62 /* Descriptive name of this model */
63 const char* model_name;
64 /* Dualboot functions for this model */
65 const unsigned char* bootloader;
66 /* Size of dualboot functions for this model */
67 int bootloader_size;
68 /* Model name used in the Rockbox header in ".sansa" files - these match the
69 -add parameter to the "scramble" tool */
70 const char* rb_model_name;
71 /* Model number used to initialise the checksum in the Rockbox header in
72 ".sansa" files - these are the same as MODEL_NUMBER in config-target.h */
73 const int rb_model_num;
75 extern const struct ams_models ams_identity[];
77 /* load_rockbox_file()
79 * Loads a rockbox bootloader file into memory
81 * ARGUMENTS
83 * filename : bootloader file to load
84 * model : will be set to this bootloader's model
85 * bootloader_size : set to the uncompressed bootloader size
86 * rb_packed_size : set to the size of compressed bootloader
87 * errstr : provided buffer to store an eventual error
88 * errstrsize : size of provided error buffer
90 * RETURN VALUE
91 * pointer to allocated memory containing the content of compressed bootloader
92 * or NULL in case of error (errstr will hold a description of the error)
95 unsigned char* load_rockbox_file(
96 char* filename, int *model, int* bootloader_size, int* rb_packedsize,
97 char* errstr, int errstrsize);
100 /* load_of_file()
102 * Loads a Sansa AMS Original Firmware file into memory
104 * ARGUMENTS
106 * filename : firmware file to load
107 * model : desired player's model
108 * bufsize : set to firmware file size
109 * md5sum : set to file md5sum, must be at least 33 bytes long
110 * firmware_size : set to firmware block's size
111 * of_packed : pointer to allocated memory containing the compressed
112 * original firmware block
113 * of_packedsize : size of compressed original firmware block
114 * errstr : provided buffer to store an eventual error
115 * errstrsize : size of provided error buffer
117 * RETURN VALUE
118 * pointer to allocated memory containing the content of Original Firmware
119 * or NULL in case of error (errstr will hold a description of the error)
122 unsigned char* load_of_file(
123 char* filename, int model, off_t* bufsize, struct md5sums *sum,
124 int* firmware_size, unsigned char** of_packed,
125 int* of_packedsize, char* errstr, int errstrsize);
128 /* patch_firmware()
130 * Patches a Sansa AMS Original Firmware file
132 * ARGUMENTS
134 * model : firmware model (MODEL_XXX)
135 * fw_version : firmware format version (1 or 2)
136 * firmware_size : size of uncompressed original firmware block
137 * buf : pointer to original firmware file
138 * len : size of original firmware file
139 * of_packed : pointer to compressed original firmware block
140 * of_packedsize : size of compressed original firmware block
141 * rb_packed : pointer to compressed rockbox bootloader
142 * rb_packed_size : size of compressed rockbox bootloader
145 void patch_firmware(
146 int model, int fw_version, int firmware_size, unsigned char* buf,
147 int len, unsigned char* of_packed, int of_packedsize,
148 unsigned char* rb_packed, int rb_packedsize);
151 /* check_sizes()
153 * Verify if the given bootloader can be embedded in the OF file, while still
154 * allowing both the bootloader and the OF to be unpacked at runtime
156 * ARGUMENTS
158 * model : firmware model (MODEL_XXX)
159 * rb_packed_size : size of compressed rockbox bootloader
160 * rb_unpacked_size : size of compressed rockbox bootloader
161 * of_packed_size : size of compressed original firmware block
162 * of_unpacked_size : size of compressed original firmware block
163 * total_size : will contain the size of useful data that would be
164 * written to the firmware block, even in case of an
165 * error
166 * errstr : provided buffer to store an eventual error
167 * errstrsize : size of provided error buffer
169 * RETURN VALUE
170 * 0 if the conditions aren't met, 1 if we can go and patch the firmware
173 int check_sizes(int model, int rb_packed_size, int rb_unpacked_size,
174 int of_packed_size, int of_unpacked_size, int *total_size,
175 char *errstr, int errstrsize);
177 /* firmware_revision()
179 * returns the firmware revision for a particular model
181 * ARGUMENTS
183 * model : firmware model (MODEL_XXX)
185 * RETURN VALUE
186 * firmware version
188 int firmware_revision(int model);
190 #ifdef __cplusplus
192 #endif
194 #endif