blob: 72830ebd326126bdc0437f867ad7df43f599bffd
1 | #ifndef _AML_MMC_H |
2 | #define _AML_MMC_H |
3 | |
4 | #include <asm/io.h> |
5 | #include <config.h> |
6 | #include <common.h> |
7 | #include <command.h> |
8 | #include <mmc.h> |
9 | #include <part.h> |
10 | #include <malloc.h> |
11 | #include <linux/list.h> |
12 | #include <mmc.h> |
13 | #include <div64.h> |
14 | #include <environment.h> |
15 | #include <malloc.h> |
16 | #include <asm/cache.h> |
17 | #include <asm/arch/clock.h> |
18 | #include<partition_table.h> |
19 | #include <storage.h> |
20 | #include <linux/sizes.h> |
21 | |
22 | #define AML_MMC_DBG |
23 | |
24 | #define MAX_DEVICE_NUM 32 |
25 | #define MAX_DEVICE_NAME_LEN 16 |
26 | #define MAX_MMC_PART_NUM 32 |
27 | #define MAX_MMC_PART_NAME_LEN 16 |
28 | |
29 | #ifndef CONFIG_AML_MMC_INHERENT_PART |
30 | #define PARTITION_RESERVED (8*SZ_1M) // 8MB |
31 | #define MMC_BOOT_PARTITION_RESERVED (32*SZ_1M) // 32MB |
32 | |
33 | #define MMC_BOOT_NAME "bootloader" |
34 | #define MMC_BOOT_NAME0 "bootloader-boot0" |
35 | #define MMC_BOOT_NAME1 "bootloader-boot1" |
36 | #define MMC_BOOT_DEVICE_SIZE (0x4*SZ_1M) |
37 | |
38 | #define MMC_RESERVED_NAME "reserved" |
39 | #define MMC_RESERVED_SIZE (64*SZ_1M) |
40 | #define MMC_BOTTOM_RSV_SIZE (0) |
41 | #endif /* CONFIG_AML_MMC_INHERENT_PART */ |
42 | |
43 | #define MMC_CACHE_NAME "cache" |
44 | // #define MMC_CACHE_SIZE (512*SZ_1M) // this is not used and should be get from spl |
45 | |
46 | #define MMC_ENV_NAME "env" |
47 | #define MMC_ENV_SIZE (8*SZ_1M) |
48 | |
49 | #define MMC_KEY_NAME "key" |
50 | #define MMC_KEY_SIZE (256*1024) |
51 | #define EMMCKEY_RESERVE_OFFSET (0x4000) |
52 | #define MMC_RESERVED_OFFSET (36*SZ_1M) |
53 | #define MMC_BLOCK_SIZE (512) |
54 | // #define MMC_SECURE_NAME "secure" |
55 | // #define MMC_SECURE_SIZE (0x1*SZ_1M) |
56 | |
57 | #define MMC_MPT_VERSION_1 "01.00.00" |
58 | #define MMC_MPT_VERSION_2 "01.02.00" |
59 | /* version in use, fixme when kenel driver is updated. */ |
60 | #define MMC_MPT_VERSION MMC_MPT_VERSION_1 |
61 | |
62 | #define MMC_PARTITIONS_MAGIC "MPT" // MMC Partition Table |
63 | #define MMC_CARD_PARTITION_NAME "card" |
64 | |
65 | /* virtual partitions*/ |
66 | |
67 | #define MMC_MBR_NAME ("AML_MBR") |
68 | /* offset&size of mbr will not be used */ |
69 | #define MMC_MBR_OFFSET (0x0) |
70 | #define MMC_MBR_SIZE (0x200) |
71 | |
72 | /* |
73 | * partition table |
74 | * |<----partition_table---->|<----key---->| |
75 | * |
76 | */ |
77 | #define MMC_TABLE_NAME ("AML_TABLE") |
78 | #define MMC_TABLE_OFFSET (0x0) |
79 | #define MMC_TABLE_SIZE (16*1024) |
80 | |
81 | /* |
82 | * write 128KB data pattern |
83 | * |<----pattern---->||<------DTB------>| |
84 | */ |
85 | #define MMC_PATTERN_NAME "pattern" |
86 | #define CALI_PATTERN_OFFSET (SZ_1M * 3) |
87 | #define CALI_PATTERN_SIZE (256 * 512) |
88 | #define CALI_BLOCK_SIZE (512) |
89 | #define CALI_PATTERN (0x55aa55aa) |
90 | |
91 | #define MMC_MAGIC_NAME "magic" |
92 | #define MAGIC_OFFSET (SZ_1M * 6) |
93 | #define MAGIC_SIZE (256 * 512) |
94 | #define MAGIC_BLOCK_SIZE (512) |
95 | #define MAGIC_PATTERN (0X00FF00FF) |
96 | |
97 | #define MMC_RANDOM_NAME "random" |
98 | #define RANDOM_OFFSET (SZ_1M * 7) |
99 | #define RANDOM_SIZE (256 * 512) |
100 | #define RANDOM_BLOCK_SIZE (512) |
101 | #define RANDOM_PATTERN (0X52414E44) |
102 | |
103 | #define MMC_DDR_PARAMETER_NAME "ddr-parameter" |
104 | #define DDR_PARAMETER_OFFSET (SZ_1M * 8) |
105 | #define DDR_PARAMETER_SIZE (4 * 512) |
106 | |
107 | /* |
108 | * 2 copies dtb were stored in dtb area. |
109 | * each is 256K. |
110 | * timestamp&checksum are in the tail. |
111 | * |<--------------DTB Area-------------->| |
112 | * |<------DTB1------->|<------DTB2------>| |
113 | */ |
114 | #define MMC_DTB_NAME "dtb" |
115 | #define DTB_OFFSET (SZ_1M * 4) |
116 | #define DTB_BLK_SIZE (512) |
117 | #define DTB_BLK_CNT (512) |
118 | #define DTB_SIZE (DTB_BLK_CNT * DTB_BLK_SIZE) |
119 | #define DTB_COPIES (2) |
120 | #define DTB_AREA_BLK_CNT (DTB_BLK_CNT * DTB_COPIES) |
121 | #define EMMC_DTB_DEV (1) |
122 | #define EMMC_FASTBOOT_CONTEXT_DEV (1) |
123 | |
124 | #define MMC_FASTBOOT_CONTEXT_NAME "fastboot_context" |
125 | #define FASTBOOT_CONTEXT_OFFSET (SZ_1M * 5) |
126 | #define FASTBOOT_CONTEXT_SIZE (512) |
127 | |
128 | struct virtual_partition { |
129 | char name[MAX_MMC_PART_NAME_LEN]; |
130 | uint64_t offset; |
131 | uint64_t size; |
132 | }; |
133 | |
134 | #define VIRTUAL_PARTITION_ELEMENT(na, of, sz) {.name = na, .offset = of, .size = sz,} |
135 | |
136 | struct aml_pattern { |
137 | char name[MAX_MMC_PART_NAME_LEN]; |
138 | unsigned int pattern; |
139 | }; |
140 | #define AML_PATTERN_ELEMENT(na, pa) {.name = na, .pattern = pa,} |
141 | |
142 | #ifdef AML_MMC_DBG |
143 | #define aml_mmc_dbg(fmt, ...) printk( "%s: line:%d " fmt "\n", \ |
144 | __func__, __LINE__, ##__VA_ARGS__) |
145 | |
146 | #define aml_mmc_msg(fmt, ...) printk( "%s: line:%d " fmt "\n", \ |
147 | __func__, __LINE__, ##__VA_ARGS__) |
148 | #else |
149 | #define aml_mmc_dbg(fmt, ...) |
150 | #define aml_mmc_msg(fmt, ...) printk( fmt "\n", ##__VA_ARGS__) |
151 | #endif |
152 | |
153 | #define DOS_MBR 0 |
154 | #define DOS_PBR 1 |
155 | |
156 | #define DOS_PBR_FSTYPE_OFFSET 0x36 |
157 | #define DOS_PBR32_FSTYPE_OFFSET 0x52 |
158 | |
159 | #define DOS_PART_DISKSIG_OFFSET 0x1b8 |
160 | #define DOS_PART_TBL_OFFSET 0x1be |
161 | #define DOS_PART_MAGIC_OFFSET 0x1fe |
162 | #define DOS_PBR_MEDIA_TYPE_OFFSET 0x15 |
163 | |
164 | #define DOS_PARTITION_COUNT 32 |
165 | |
166 | typedef struct dos_partition { |
167 | unsigned char boot_ind; /* 0x80 - active */ |
168 | unsigned char head; /* starting head */ |
169 | unsigned char sector; /* starting sector */ |
170 | unsigned char cyl; /* starting cylinder */ |
171 | unsigned char sys_ind; /* What partition type */ |
172 | unsigned char end_head; /* end head */ |
173 | unsigned char end_sector; /* end sector */ |
174 | unsigned char end_cyl; /* end cylinder */ |
175 | unsigned char start4[4]; /* starting sector counting from 0 */ |
176 | unsigned char size4[4]; /* nr of sectors in partition */ |
177 | } dos_partition_t; |
178 | |
179 | struct dos_mbr_or_ebr{ |
180 | unsigned char bootstart[446]; |
181 | struct dos_partition part_entry[4]; |
182 | unsigned char magic[2]; |
183 | }; |
184 | |
185 | struct mmc_partitions_fmt { |
186 | char magic[4]; |
187 | unsigned char version[12]; |
188 | int part_num; |
189 | int checksum; |
190 | struct partitions partitions[MAX_MMC_PART_NUM]; |
191 | }; |
192 | |
193 | struct mmc_partition_config{ |
194 | unsigned char version[12]; |
195 | int part_num; |
196 | struct partitions partitions[MAX_MMC_PART_NUM]; |
197 | unsigned option; |
198 | void * private_data; |
199 | }; |
200 | |
201 | /* |
202 | struct _mmc_device{ |
203 | char name[MAX_DEVICE_NAME_LEN]; |
204 | uint64_t offset; |
205 | uint64_t size; |
206 | void * private_data; |
207 | struct list_head list; |
208 | }; |
209 | */ |
210 | |
211 | #define LOCK_MAJOR_VERSION 1 |
212 | #define LOCK_MINOR_VERSION 0 |
213 | |
214 | #define LOCK_DATA_SIZE 8 |
215 | |
216 | typedef struct LockData { |
217 | uint8_t version_major; |
218 | uint8_t version_minor; |
219 | |
220 | /* Padding to eight bytes. */ |
221 | uint8_t reserved1[2]; |
222 | |
223 | /* 0: unlock 1: lock*/ |
224 | uint8_t lock_state; |
225 | |
226 | /* 0: unlock 1: lock*/ |
227 | uint8_t lock_critical_state; |
228 | |
229 | /* 0: enable bootloader version rollback 1: prevent bootloader version rollback*/ |
230 | uint8_t lock_bootloader; |
231 | uint8_t reserved2[1]; |
232 | } LockData_t; |
233 | |
234 | /*512Bytes*/ |
235 | typedef struct FastbootContext { |
236 | /* locks */ |
237 | LockData_t lock; |
238 | uint8_t rsv[248]; |
239 | /* checksum, storage driver care */ |
240 | uint32_t crc32; |
241 | } FastbootContext_t; |
242 | |
243 | extern bool is_partition_checked; |
244 | extern struct partitions emmc_partition_table[]; |
245 | |
246 | extern int get_emmc_partition_arraysize(void); |
247 | |
248 | /* |
249 | * get the partition number by name |
250 | * return value |
251 | * < 0 means no partition found |
252 | * >= 0 means valid partition |
253 | */ |
254 | extern int get_partition_num_by_name(char *name); |
255 | |
256 | struct partitions* find_mmc_partition_by_name (char *name); |
257 | struct partitions *aml_get_partition_by_name(const char *name); |
258 | int mmc_boot_size(char *name, uint64_t* size); |
259 | struct virtual_partition *aml_get_virtual_partition_by_name(const char *name); |
260 | bool aml_is_emmc_tsd (struct mmc *mmc); |
261 | int mmc_device_init (struct mmc *mmc); |
262 | ulong _get_inherent_offset(const char *name); |
263 | |
264 | #define PARTITION_ELEMENT(na, sz, flags) {.name = na, .size = sz, .mask_flags = flags,} |
265 | |
266 | #endif |
267 |