diff options
author | Cástor Muñoz <cmvidal@gmail.com> | 2016-02-05 00:49:33 +0100 |
---|---|---|
committer | Cástor Muñoz <cmvidal@gmail.com> | 2016-08-19 00:15:59 +0200 |
commit | 7083110f8154f6ca47845fc747bad5062515658c (patch) | |
tree | 2c3bf23060d0435be9966c152710e93b2272516b /firmware/target/arm/s5l8702/nor-target.h | |
parent | bf89c757ddee815ebdd42bba91413daa96d50b75 (diff) | |
download | rockbox-7083110f8154f6ca47845fc747bad5062515658c.tar.gz rockbox-7083110f8154f6ca47845fc747bad5062515658c.zip |
iPod Classic: NOR support for bootloader
- NOR driver (based on emCORE)
- read/write IM3 images
- read 'flsh' files
Change-Id: Ie0654e0d298affc0f47ed64b823767118bd1aa3f
Diffstat (limited to 'firmware/target/arm/s5l8702/nor-target.h')
-rw-r--r-- | firmware/target/arm/s5l8702/nor-target.h | 167 |
1 files changed, 167 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8702/nor-target.h b/firmware/target/arm/s5l8702/nor-target.h new file mode 100644 index 0000000000..4ebe1d58d4 --- /dev/null +++ b/firmware/target/arm/s5l8702/nor-target.h | |||
@@ -0,0 +1,167 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: | ||
9 | * | ||
10 | * Copyright © 2009 Michael Sparmann | ||
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 __NOR_TARGET_H__ | ||
22 | #define __NOR_TARGET_H__ | ||
23 | |||
24 | #include <stdint.h> | ||
25 | #include <stdbool.h> | ||
26 | |||
27 | #include "config.h" | ||
28 | #include "crypto-s5l8702.h" | ||
29 | |||
30 | |||
31 | /* NOR memory map (Classic 6G): | ||
32 | * | ||
33 | * 1MB ______________ | ||
34 | * | | | ||
35 | * | flsh DIR | | ||
36 | * 1MB-0x200 |______________| | ||
37 | * | | | ||
38 | * | File 1 | | ||
39 | * |..............| | ||
40 | * | | | ||
41 | * | File 2 | | ||
42 | * |..............| | ||
43 | * | | | ||
44 | * . . | ||
45 | * . . | ||
46 | * . . | ||
47 | * | | | ||
48 | * |..............| | ||
49 | * | | | ||
50 | * | File N | | ||
51 | * |______________| | ||
52 | * | | | ||
53 | * | | | ||
54 | * | | | ||
55 | * | | IM3 (128KB) | ||
56 | * | Unused | . . . . . . ______________ | ||
57 | * | | / | | | ||
58 | * | | / | | | ||
59 | * | | / | | | ||
60 | * 160KB |______________|/ | | | ||
61 | * | | | | | ||
62 | * | | | EFI | | ||
63 | * | Original | | Volumen | | ||
64 | * | NOR Boot | | | | ||
65 | * | | | | | ||
66 | * | | | | | ||
67 | * 32KB |______________| | | | ||
68 | * | |\ 0x800 |______________| | ||
69 | * | | \ | | | ||
70 | * | | \ | IM3 Header | | ||
71 | * |______________| \ . . . . . . |______________| | ||
72 | * | | | ||
73 | * | SysCfg | | ||
74 | * 0 |______________| | ||
75 | */ | ||
76 | |||
77 | #define SPI_PORT 0 | ||
78 | |||
79 | #define NOR_SZ 0x100000 | ||
80 | #define NORBOOT_OFF 0x8000 | ||
81 | #define NORBOOT_MAXSZ 0x20000 | ||
82 | |||
83 | void bootflash_init(int port); | ||
84 | void bootflash_read(int port, uint32_t addr, uint32_t size, void* buf); | ||
85 | void bootflash_write(int port, int offset, void* addr, int size); | ||
86 | int bootflash_compare(int port, int offset, void* addr, int size); | ||
87 | void bootflash_erase_blocks(int port, int first, int n); | ||
88 | void bootflash_close(int port); | ||
89 | |||
90 | |||
91 | /* | ||
92 | * IM3 | ||
93 | */ | ||
94 | #define IM3_IDENT "8702" | ||
95 | #define IM3_VERSION "1.0" | ||
96 | #define IM3HDR_SZ 0x800 | ||
97 | #define IM3INFO_SZ (sizeof(struct Im3Info)) | ||
98 | #define IM3INFOSIGN_SZ (offsetof(struct Im3Info, info_sign)) | ||
99 | |||
100 | #define SIGN_SZ 16 | ||
101 | |||
102 | struct Im3Info | ||
103 | { | ||
104 | uint8_t ident[4]; | ||
105 | uint8_t version[3]; | ||
106 | uint8_t enc_type; | ||
107 | uint8_t entry[4]; /* LE */ | ||
108 | uint8_t data_sz[4]; /* LE */ | ||
109 | union { | ||
110 | struct { | ||
111 | uint8_t data_sign[SIGN_SZ]; | ||
112 | uint8_t _reserved[32]; | ||
113 | } enc12; | ||
114 | struct { | ||
115 | uint8_t sign_off[4]; /* LE */ | ||
116 | uint8_t cert_off[4]; /* LE */ | ||
117 | uint8_t cert_sz[4]; /* LE */ | ||
118 | uint8_t _reserved[36]; | ||
119 | } enc34; | ||
120 | } u; | ||
121 | uint8_t info_sign[SIGN_SZ]; | ||
122 | } __attribute__ ((packed)); | ||
123 | |||
124 | struct Im3Hdr | ||
125 | { | ||
126 | struct Im3Info info; | ||
127 | uint8_t _zero[IM3HDR_SZ - sizeof(struct Im3Info)]; | ||
128 | } __attribute__ ((packed)); | ||
129 | |||
130 | unsigned im3_nor_sz(struct Im3Info* hinfo); | ||
131 | void im3_sign(uint32_t keyidx, void* data, uint32_t size, void* sign); | ||
132 | void im3_crypt(enum hwkeyaes_direction direction, | ||
133 | struct Im3Info *hinfo, void *fw_addr); | ||
134 | int im3_read(uint32_t offset, struct Im3Info *hinfo, void *fw_addr); | ||
135 | bool im3_write(int offset, void *im3_addr); | ||
136 | |||
137 | |||
138 | /* | ||
139 | * flsh FS | ||
140 | */ | ||
141 | #define DIR_SZ 0x200 | ||
142 | #define DIR_OFF (NOR_SZ - DIR_SZ) | ||
143 | #define ENTRY_SZ ((int)sizeof(image_t)) | ||
144 | #define MAX_ENTRY (DIR_SZ / ENTRY_SZ) | ||
145 | |||
146 | #define FILEHDR_SZ 0x200 | ||
147 | |||
148 | /* from tools/ipod_fw.c */ | ||
149 | typedef struct _image { | ||
150 | char type[4]; /* '' */ | ||
151 | unsigned id; /* */ | ||
152 | char pad1[4]; /* 0000 0000 */ | ||
153 | unsigned devOffset; /* byte offset of start of image code */ | ||
154 | unsigned len; /* length in bytes of image */ | ||
155 | unsigned addr; /* load address */ | ||
156 | unsigned entryOffset; /* execution start within image */ | ||
157 | unsigned chksum; /* checksum for image */ | ||
158 | unsigned vers; /* image version */ | ||
159 | unsigned loadAddr; /* load address for image */ | ||
160 | } image_t; | ||
161 | |||
162 | int flsh_get_info(int *used, int *unused); | ||
163 | unsigned flsh_get_unused(void); | ||
164 | int flsh_find_file(char *name, image_t *entry); | ||
165 | int flsh_load_file(image_t *entry, void *hdr, void *data); | ||
166 | |||
167 | #endif /* __NOR_TARGET_H__ */ | ||