blob: 084bec61f9a6b0774964bd4e99c69348bfd68650 [file] [log] [blame]
Cástor Muñoz346423c2016-02-04 23:05:17 +01001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:$
9 *
10 * Copyright (C) 2015 by Cástor Muñoz
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __MK6GBOOT_H__
22#define __MK6GBOOT_H__
23
24/* useful for dualboot.lds */
25#define DFU_LOADADDR 0x22000000
26#define DFU_MAXSIZE 0x20000 /* maximum .dfu file size */
27
28#define CERT_OFFSET 0x50 /* IM3INFO_SZ */
29#define CERT_SIZE 698
30#define BIN_OFFSET (CERT_OFFSET + ((CERT_SIZE + 0x3) & ~ 0x3))
31#define MAX_PAYLOAD (DFU_MAXSIZE - BIN_OFFSET)
32
33#ifndef ASM
34#include <stddef.h>
35#include <stdint.h>
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41#define IM3_IDENT "8702"
42#define IM3_VERSION "1.0"
43#define IM3HDR_SZ 0x800
44#define IM3INFO_SZ (sizeof(struct Im3Info))
45#define IM3INFOSIGN_SZ (offsetof(struct Im3Info, info_sign))
46
47#define SIGN_SZ 16
48
49struct Im3Info
50{
51 uint8_t ident[4];
52 uint8_t version[3];
53 uint8_t enc_type;
54 uint8_t entry[4]; /* LE */
55 uint8_t data_sz[4]; /* LE */
56 union {
57 struct {
58 uint8_t data_sign[SIGN_SZ];
59 uint8_t _reserved[32];
60 } enc12;
61 struct {
62 uint8_t sign_off[4]; /* LE */
63 uint8_t cert_off[4]; /* LE */
64 uint8_t cert_sz[4]; /* LE */
65 uint8_t _reserved[36];
66 } enc34;
67 } u;
68 uint8_t info_sign[SIGN_SZ];
69} __attribute__ ((packed));
70
71struct Im3Hdr
72{
73 struct Im3Info info;
74 uint8_t _zero[IM3HDR_SZ - sizeof(struct Im3Info)];
75} __attribute__ ((packed));
76
77
78/* Supported models */
79enum {
80 MODEL_UNKNOWN = -1,
81 MODEL_IPOD6G = 0,
82 /* new models go here */
83
84 NUM_MODELS
85};
86
87struct ipod_models {
88 /* Descriptive name of this model */
89 const char* model_name;
90 /* for bootloader uninstallers */
91 const char* platform_name;
92 /* Model name used in the Rockbox header in ".ipod" files - these match the
93 -add parameter to the "scramble" tool */
94 const char* rb_model_name;
95 /* Model number used to initialise the checksum in the Rockbox header in
96 ".ipod" files - these are the same as MODEL_NUMBER in config-target.h */
97 const int rb_model_num;
98 /* Dualboot functions for this model */
99 const unsigned char* dualboot_install;
100 int dualboot_install_size;
101 const unsigned char* dualboot_uninstall;
102 int dualboot_uninstall_size;
103};
104extern const struct ipod_models ipod_identity[];
105
106
107enum {
108 DFU_NONE = -1,
109 DFU_INST, /* RB installer */
110 DFU_INST_SINGLE, /* RB installer (single) */
111 DFU_UNINST, /* RB uninstaller */
112 DFU_RAW /* raw binary */
113};
114
115unsigned char *mkdfu(int dfu_type, char *dfu_arg, int* dfu_size,
116 char* errstr, int errstrsize);
117
118int ipoddfu_send(int pid, unsigned char *buf, int size,
119 char* errstr, int errstrsize);
120int ipoddfu_scan(int pid, int *state, int reset,
121 char* errstr, int errstrsize);
122void ipoddfu_debug(int debug);
123
124#ifdef __cplusplus
125};
126#endif
127#endif /* ASM */
128
129#endif /* __MK6GBOOT_H__ */