New committer!
[kugel-rb.git] / rbutil / mkamsboot / mkamsboot.h
bloba14b3206850cf5211fd10dd1f4c1eaf470f8a6aa
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 /* Supported models */
32 enum {
33 MODEL_UNKNOWN = -1,
34 MODEL_FUZE = 0,
35 MODEL_CLIP,
36 MODEL_CLIPV2,
37 MODEL_E200V2,
38 MODEL_M200V4,
39 MODEL_C200V2,
43 /* Holds info about the OF */
44 struct md5sums {
45 int model;
46 char *version;
47 char *md5;
50 /* load_rockbox_file()
52 * Loads a rockbox bootloader file into memory
54 * ARGUMENTS
56 * filename : bootloader file to load
57 * model : a 4 characters string representing the Sansa model
58 * ("fuze", "clip", "e2v2", "m2v4", or "c2v2")
59 * bootloader_size : set to the uncompressed bootloader size
60 * rb_packed_size : set to the size of compressed bootloader
61 * errstr : provided buffer to store an eventual error
62 * errstrsize : size of provided error buffer
64 * RETURN VALUE
65 * pointer to allocated memory containing the content of compressed bootloader
66 * or NULL in case of error (errstr will hold a description of the error)
69 unsigned char* load_rockbox_file(
70 char* filename, int model, int* bootloader_size, int* rb_packedsize,
71 char* errstr, int errstrsize);
74 /* load_of_file()
76 * Loads a Sansa AMS Original Firmware file into memory
78 * ARGUMENTS
80 * filename : firmware file to load
81 * bufsize : set to firmware file size
82 * md5sum : set to file md5sum, must be at least 33 bytes long
83 * model : set to firmware model (MODEL_XXX)
84 * fw_version : set to firmware format version (1 or 2)
85 * firmware_size : set to firmware block's size
86 * of_packed : pointer to allocated memory containing the compressed
87 * original firmware block
88 * of_packedsize : size of compressed original firmware block
89 * errstr : provided buffer to store an eventual error
90 * errstrsize : size of provided error buffer
92 * RETURN VALUE
93 * pointer to allocated memory containing the content of Original Firmware
94 * or NULL in case of error (errstr will hold a description of the error)
97 unsigned char* load_of_file(
98 char* filename, off_t* bufsize, struct md5sums *sum,
99 int* firmware_size, unsigned char** of_packed,
100 int* of_packedsize, char* errstr, int errstrsize);
103 /* patch_firmware()
105 * Patches a Sansa AMS Original Firmware file
107 * ARGUMENTS
109 * model : firmware model (MODEL_XXX)
110 * fw_version : firmware format version (1 or 2)
111 * firmware_size : size of uncompressed original firmware block
112 * buf : pointer to original firmware file
113 * len : size of original firmware file
114 * of_packed : pointer to compressed original firmware block
115 * of_packedsize : size of compressed original firmware block
116 * rb_packed : pointer to compressed rockbox bootloader
117 * rb_packed_size : size of compressed rockbox bootloader
120 void patch_firmware(
121 int model, int fw_version, int firmware_size, unsigned char* buf,
122 int len, unsigned char* of_packed, int of_packedsize,
123 unsigned char* rb_packed, int rb_packedsize);
126 /* total_size()
128 * Calculates the size of the new firmware block
130 * ARGUMENTS
132 * model : firmware model (MODEL_XXX)
133 * rb_packed_size : size of compressed rockbox bootloader
134 * of_packedsize : size of compressed original firmware block
136 * RETURN VALUE
137 * Size of new firmware block
140 int total_size(int model, int rb_packedsize, int of_packedsize);
142 #endif