Mark const return value; correct the comment about valid menu items for the hotkey
[kugel-rb.git] / rbutil / mkamsboot / mkamsboot.h
blob835d024d989af9e8d5461d3aeef2b3e794b04c0f
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,
49 /* Holds info about the OF */
50 struct md5sums {
51 int model;
52 char *version;
53 char *md5;
56 extern const unsigned short hw_revisions[];
57 extern const unsigned short fw_revisions[];
58 extern const char* model_names[];
59 extern const int bootloader_sizes[];
61 /* load_rockbox_file()
63 * Loads a rockbox bootloader file into memory
65 * ARGUMENTS
67 * filename : bootloader file to load
68 * model : a 4 characters string representing the Sansa model
69 * ("fuze", "clip", "e2v2", "m2v4", or "c2v2")
70 * bootloader_size : set to the uncompressed bootloader size
71 * rb_packed_size : set to the size of compressed bootloader
72 * errstr : provided buffer to store an eventual error
73 * errstrsize : size of provided error buffer
75 * RETURN VALUE
76 * pointer to allocated memory containing the content of compressed bootloader
77 * or NULL in case of error (errstr will hold a description of the error)
80 unsigned char* load_rockbox_file(
81 char* filename, int model, int* bootloader_size, int* rb_packedsize,
82 char* errstr, int errstrsize);
85 /* load_of_file()
87 * Loads a Sansa AMS Original Firmware file into memory
89 * ARGUMENTS
91 * filename : firmware file to load
92 * bufsize : set to firmware file size
93 * md5sum : set to file md5sum, must be at least 33 bytes long
94 * model : set to firmware model (MODEL_XXX)
95 * fw_version : set to firmware format version (1 or 2)
96 * firmware_size : set to firmware block's size
97 * of_packed : pointer to allocated memory containing the compressed
98 * original firmware block
99 * of_packedsize : size of compressed original firmware block
100 * errstr : provided buffer to store an eventual error
101 * errstrsize : size of provided error buffer
103 * RETURN VALUE
104 * pointer to allocated memory containing the content of Original Firmware
105 * or NULL in case of error (errstr will hold a description of the error)
108 unsigned char* load_of_file(
109 char* filename, off_t* bufsize, struct md5sums *sum,
110 int* firmware_size, unsigned char** of_packed,
111 int* of_packedsize, char* errstr, int errstrsize);
114 /* patch_firmware()
116 * Patches a Sansa AMS Original Firmware file
118 * ARGUMENTS
120 * model : firmware model (MODEL_XXX)
121 * fw_version : firmware format version (1 or 2)
122 * firmware_size : size of uncompressed original firmware block
123 * buf : pointer to original firmware file
124 * len : size of original firmware file
125 * of_packed : pointer to compressed original firmware block
126 * of_packedsize : size of compressed original firmware block
127 * rb_packed : pointer to compressed rockbox bootloader
128 * rb_packed_size : size of compressed rockbox bootloader
131 void patch_firmware(
132 int model, int fw_version, int firmware_size, unsigned char* buf,
133 int len, unsigned char* of_packed, int of_packedsize,
134 unsigned char* rb_packed, int rb_packedsize);
137 /* check_sizes()
139 * Verify if the given bootloader can be embedded in the OF file, while still
140 * allowing both the bootloader and the OF to be unpacked at runtime
142 * ARGUMENTS
144 * model : firmware model (MODEL_XXX)
145 * rb_packed_size : size of compressed rockbox bootloader
146 * rb_unpacked_size : size of compressed rockbox bootloader
147 * of_packed_size : size of compressed original firmware block
148 * of_unpacked_size : size of compressed original firmware block
149 * total_size : will contain the size of useful data that would be
150 * written to the firmware block, even in case of an
151 * error
152 * errstr : provided buffer to store an eventual error
153 * errstrsize : size of provided error buffer
155 * RETURN VALUE
156 * 0 if the conditions aren't met, 1 if we can go and patch the firmware
159 int check_sizes(int model, int rb_packed_size, int rb_unpacked_size,
160 int of_packed_size, int of_unpacked_size, int *total_size,
161 char *errstr, int errstrsize);
163 /* firmware_revision()
165 * returns the firmware revision for a particular model
167 * ARGUMENTS
169 * model : firmware model (MODEL_XXX)
171 * RETURN VALUE
172 * firmware version
174 int firmware_revision(int model);
176 #ifdef __cplusplus
178 #endif
180 #endif