blob: f2aba267d8ed95bfc32f9ed36e544517af9bca5f [file] [log] [blame]
Dave Chapman4b7e1e02006-12-13 09:02:18 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Dave Chapmane332f4c2007-02-05 01:20:20 +000010 * Copyright (C) 2006-2007 Dave Chapman
Dave Chapman4b7e1e02006-12-13 09:02:18 +000011 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef __IPODIO_H
21#define __IPODIO_H
22
Dave Chapman31aa4522007-02-04 11:42:11 +000023#include <stdint.h>
Dave Chapmanb045a242007-02-16 20:45:00 +000024#include <unistd.h>
Dave Chapman31aa4522007-02-04 11:42:11 +000025
Dave Chapman4b7e1e02006-12-13 09:02:18 +000026#ifdef __WIN32__
27#include <windows.h>
28#else
29#define HANDLE int
30#define O_BINARY 0
31#endif
32
Dave Chapman31aa4522007-02-04 11:42:11 +000033/* The maximum number of images in a firmware partition - a guess... */
34#define MAX_IMAGES 10
35
36enum firmwaretype_t {
37 FTYPE_OSOS = 0,
38 FTYPE_RSRC,
39 FTYPE_AUPD,
40 FTYPE_HIBE
41};
42
43struct ipod_directory_t {
44 enum firmwaretype_t ftype;
45 int id;
46 uint32_t devOffset; /* Offset of image relative to one sector into bootpart*/
47 uint32_t len;
48 uint32_t addr;
49 uint32_t entryOffset;
50 uint32_t chksum;
51 uint32_t vers;
52 uint32_t loadAddr;
53};
54
55struct partinfo_t {
56 unsigned long start; /* first sector (LBA) */
57 unsigned long size; /* number of sectors */
Dave Chapman6e641e82007-02-05 18:29:39 +000058 int type;
Dave Chapman31aa4522007-02-04 11:42:11 +000059};
60
61struct ipod_t {
62 HANDLE dh;
63 char diskname[4096];
64 int sector_size;
65 struct ipod_directory_t ipod_directory[MAX_IMAGES];
66 int nimages;
67 off_t diroffset;
68 off_t start; /* Offset in bytes of firmware partition from start of disk */
69 off_t fwoffset; /* Offset in bytes of start of firmware images from start of disk */
70 struct partinfo_t pinfo[4];
71 int modelnum;
72 char* modelname;
73 char* modelstr;
Dave Chapmana6d68bd2007-02-10 20:09:23 +000074 char* targetname;
Dave Chapman6e641e82007-02-05 18:29:39 +000075 int macpod;
Dave Chapmanbdc27ff2007-02-08 18:05:50 +000076#ifdef WITH_BOOTOBJS
77 unsigned char* bootloader;
78 int bootloader_len;
79#endif
Dave Chapman31aa4522007-02-04 11:42:11 +000080};
81
Dave Chapman4b7e1e02006-12-13 09:02:18 +000082void print_error(char* msg);
Dave Chapman31aa4522007-02-04 11:42:11 +000083int ipod_open(struct ipod_t* ipod, int silent);
84int ipod_reopen_rw(struct ipod_t* ipod);
85int ipod_close(struct ipod_t* ipod);
86int ipod_seek(struct ipod_t* ipod, unsigned long pos);
87int ipod_read(struct ipod_t* ipod, unsigned char* buf, int nbytes);
88int ipod_write(struct ipod_t* ipod, unsigned char* buf, int nbytes);
Dave Chapman4b7e1e02006-12-13 09:02:18 +000089int ipod_alloc_buffer(unsigned char** sectorbuf, int bufsize);
90
91#endif