Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 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 Wenger | cb55d5c | 2009-08-15 14:09:05 +0000 | [diff] [blame] | 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
Rafaël Carré | b6c20c1 | 2010-02-19 14:10:26 +0000 | [diff] [blame] | 33 | #endif |
Dominik Wenger | cb55d5c | 2009-08-15 14:09:05 +0000 | [diff] [blame] | 34 | |
Rafaël Carré | ef7ad19 | 2009-07-05 08:25:44 +0000 | [diff] [blame] | 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, |
Rafaël Carré | 8b926e9 | 2010-01-13 03:05:29 +0000 | [diff] [blame] | 44 | MODEL_CLIPPLUS, |
Thomas Martitz | f6540e8 | 2010-02-26 13:55:17 +0000 | [diff] [blame] | 45 | MODEL_FUZEV2, |
Rafaël Carré | ff6b042 | 2010-05-24 10:06:52 +0000 | [diff] [blame] | 46 | /* new models go here */ |
| 47 | |
| 48 | NUM_MODELS |
Rafaël Carré | ef7ad19 | 2009-07-05 08:25:44 +0000 | [diff] [blame] | 49 | }; |
| 50 | |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 51 | |
Thomas Martitz | f9eeab2 | 2009-07-05 02:30:33 +0000 | [diff] [blame] | 52 | /* Holds info about the OF */ |
| 53 | struct md5sums { |
| 54 | int model; |
| 55 | char *version; |
| 56 | char *md5; |
| 57 | }; |
| 58 | |
Dominik Riebeling | ea61780 | 2009-11-04 20:58:40 +0000 | [diff] [blame] | 59 | extern const unsigned short hw_revisions[]; |
| 60 | extern const unsigned short fw_revisions[]; |
| 61 | extern const char* model_names[]; |
| 62 | extern const int bootloader_sizes[]; |
| 63 | |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 64 | /* load_rockbox_file() |
| 65 | * |
| 66 | * Loads a rockbox bootloader file into memory |
| 67 | * |
| 68 | * ARGUMENTS |
| 69 | * |
| 70 | * filename : bootloader file to load |
Rafaël Carré | ff6b042 | 2010-05-24 10:06:52 +0000 | [diff] [blame] | 71 | * model : will be set to this bootloader's model |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 72 | * bootloader_size : set to the uncompressed bootloader size |
| 73 | * rb_packed_size : set to the size of compressed bootloader |
| 74 | * errstr : provided buffer to store an eventual error |
| 75 | * errstrsize : size of provided error buffer |
| 76 | * |
| 77 | * RETURN VALUE |
| 78 | * pointer to allocated memory containing the content of compressed bootloader |
| 79 | * or NULL in case of error (errstr will hold a description of the error) |
| 80 | */ |
| 81 | |
| 82 | unsigned char* load_rockbox_file( |
Rafaël Carré | ff6b042 | 2010-05-24 10:06:52 +0000 | [diff] [blame] | 83 | char* filename, int *model, int* bootloader_size, int* rb_packedsize, |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 84 | char* errstr, int errstrsize); |
| 85 | |
| 86 | |
| 87 | /* load_of_file() |
| 88 | * |
| 89 | * Loads a Sansa AMS Original Firmware file into memory |
| 90 | * |
| 91 | * ARGUMENTS |
| 92 | * |
| 93 | * filename : firmware file to load |
Rafaël Carré | ff6b042 | 2010-05-24 10:06:52 +0000 | [diff] [blame] | 94 | * model : desired player's model |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 95 | * bufsize : set to firmware file size |
| 96 | * md5sum : set to file md5sum, must be at least 33 bytes long |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 97 | * firmware_size : set to firmware block's size |
| 98 | * of_packed : pointer to allocated memory containing the compressed |
| 99 | * original firmware block |
| 100 | * of_packedsize : size of compressed original firmware block |
| 101 | * errstr : provided buffer to store an eventual error |
| 102 | * errstrsize : size of provided error buffer |
| 103 | * |
| 104 | * RETURN VALUE |
| 105 | * pointer to allocated memory containing the content of Original Firmware |
| 106 | * or NULL in case of error (errstr will hold a description of the error) |
| 107 | */ |
| 108 | |
| 109 | unsigned char* load_of_file( |
Rafaël Carré | ff6b042 | 2010-05-24 10:06:52 +0000 | [diff] [blame] | 110 | char* filename, int model, off_t* bufsize, struct md5sums *sum, |
Thomas Martitz | f9eeab2 | 2009-07-05 02:30:33 +0000 | [diff] [blame] | 111 | int* firmware_size, unsigned char** of_packed, |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 112 | int* of_packedsize, char* errstr, int errstrsize); |
| 113 | |
| 114 | |
| 115 | /* patch_firmware() |
| 116 | * |
| 117 | * Patches a Sansa AMS Original Firmware file |
| 118 | * |
| 119 | * ARGUMENTS |
| 120 | * |
| 121 | * model : firmware model (MODEL_XXX) |
| 122 | * fw_version : firmware format version (1 or 2) |
| 123 | * firmware_size : size of uncompressed original firmware block |
| 124 | * buf : pointer to original firmware file |
| 125 | * len : size of original firmware file |
| 126 | * of_packed : pointer to compressed original firmware block |
| 127 | * of_packedsize : size of compressed original firmware block |
| 128 | * rb_packed : pointer to compressed rockbox bootloader |
| 129 | * rb_packed_size : size of compressed rockbox bootloader |
| 130 | */ |
| 131 | |
| 132 | void patch_firmware( |
| 133 | int model, int fw_version, int firmware_size, unsigned char* buf, |
| 134 | int len, unsigned char* of_packed, int of_packedsize, |
| 135 | unsigned char* rb_packed, int rb_packedsize); |
| 136 | |
| 137 | |
Rafaël Carré | b6c20c1 | 2010-02-19 14:10:26 +0000 | [diff] [blame] | 138 | /* check_sizes() |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 139 | * |
Rafaël Carré | b6c20c1 | 2010-02-19 14:10:26 +0000 | [diff] [blame] | 140 | * Verify if the given bootloader can be embedded in the OF file, while still |
| 141 | * allowing both the bootloader and the OF to be unpacked at runtime |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 142 | * |
| 143 | * ARGUMENTS |
| 144 | * |
| 145 | * model : firmware model (MODEL_XXX) |
| 146 | * rb_packed_size : size of compressed rockbox bootloader |
Rafaël Carré | b6c20c1 | 2010-02-19 14:10:26 +0000 | [diff] [blame] | 147 | * rb_unpacked_size : size of compressed rockbox bootloader |
| 148 | * of_packed_size : size of compressed original firmware block |
| 149 | * of_unpacked_size : size of compressed original firmware block |
| 150 | * total_size : will contain the size of useful data that would be |
| 151 | * written to the firmware block, even in case of an |
| 152 | * error |
| 153 | * errstr : provided buffer to store an eventual error |
| 154 | * errstrsize : size of provided error buffer |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 155 | * |
| 156 | * RETURN VALUE |
Rafaël Carré | b6c20c1 | 2010-02-19 14:10:26 +0000 | [diff] [blame] | 157 | * 0 if the conditions aren't met, 1 if we can go and patch the firmware |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 158 | */ |
| 159 | |
Rafaël Carré | b6c20c1 | 2010-02-19 14:10:26 +0000 | [diff] [blame] | 160 | int check_sizes(int model, int rb_packed_size, int rb_unpacked_size, |
| 161 | int of_packed_size, int of_unpacked_size, int *total_size, |
| 162 | char *errstr, int errstrsize); |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 163 | |
Dominik Wenger | a66dfa4 | 2009-08-15 13:04:21 +0000 | [diff] [blame] | 164 | /* firmware_revision() |
| 165 | * |
| 166 | * returns the firmware revision for a particular model |
| 167 | * |
| 168 | * ARGUMENTS |
| 169 | * |
| 170 | * model : firmware model (MODEL_XXX) |
| 171 | * |
| 172 | * RETURN VALUE |
| 173 | * firmware version |
| 174 | */ |
| 175 | int firmware_revision(int model); |
| 176 | |
Dominik Wenger | cb55d5c | 2009-08-15 14:09:05 +0000 | [diff] [blame] | 177 | #ifdef __cplusplus |
| 178 | }; |
Rafaël Carré | b6c20c1 | 2010-02-19 14:10:26 +0000 | [diff] [blame] | 179 | #endif |
Dominik Wenger | cb55d5c | 2009-08-15 14:09:05 +0000 | [diff] [blame] | 180 | |
Rafaël Carré | 96165ab | 2009-05-28 18:27:08 +0000 | [diff] [blame] | 181 | #endif |