Commit a024d695b71caf33a3ec2334c235beba398393c2
1 parent
f322e8a2c6
Exists in
smarc-imx_v2018.03_4.14.78_1.0.0_ga
MA-13537-4 remove the feature that imx6 and imx7 can always unlock
now the uboot used by uuu is compiled indepently from the one flashed to the board, and for imx6 and imx7, defconfig from BSP team is used to configure the uboot for uuu, so there is no need to unlock the device when flash the board. Change-Id: Ieefbd67e095dd51eab87e9a32b586cdf88f05d81 Signed-off-by: faqiang.zhu <faqiang.zhu@nxp.com>
Showing 1 changed file with 0 additions and 6 deletions Inline Diff
drivers/usb/gadget/fastboot_lock_unlock.c
1 | /* | 1 | /* |
2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. | 2 | * Copyright (c) 2016, Freescale Semiconductor, Inc. |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without modification, | 5 | * Redistribution and use in source and binary forms, with or without modification, |
6 | * are permitted provided that the following conditions are met: | 6 | * are permitted provided that the following conditions are met: |
7 | * | 7 | * |
8 | * o Redistributions of source code must retain the above copyright notice, this list | 8 | * o Redistributions of source code must retain the above copyright notice, this list |
9 | * of conditions and the following disclaimer. | 9 | * of conditions and the following disclaimer. |
10 | * | 10 | * |
11 | * o Redistributions in binary form must reproduce the above copyright notice, this | 11 | * o Redistributions in binary form must reproduce the above copyright notice, this |
12 | * list of conditions and the following disclaimer in the documentation and/or | 12 | * list of conditions and the following disclaimer in the documentation and/or |
13 | * other materials provided with the distribution. | 13 | * other materials provided with the distribution. |
14 | * | 14 | * |
15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its | 15 | * o Neither the name of Freescale Semiconductor, Inc. nor the names of its |
16 | * contributors may be used to endorse or promote products derived from this | 16 | * contributors may be used to endorse or promote products derived from this |
17 | * software without specific prior written permission. | 17 | * software without specific prior written permission. |
18 | * | 18 | * |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR | 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 23 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | */ | 29 | */ |
30 | #include <common.h> | 30 | #include <common.h> |
31 | #include <mapmem.h> | 31 | #include <mapmem.h> |
32 | #include <linux/types.h> | 32 | #include <linux/types.h> |
33 | #include <part.h> | 33 | #include <part.h> |
34 | #include <mmc.h> | 34 | #include <mmc.h> |
35 | #include <ext_common.h> | 35 | #include <ext_common.h> |
36 | #include <stdio_dev.h> | 36 | #include <stdio_dev.h> |
37 | #include <stdlib.h> | 37 | #include <stdlib.h> |
38 | #include "fastboot_lock_unlock.h" | 38 | #include "fastboot_lock_unlock.h" |
39 | #include <fsl_fastboot.h> | 39 | #include <fsl_fastboot.h> |
40 | #include <memalign.h> | 40 | #include <memalign.h> |
41 | #include <asm/mach-imx/sys_proto.h> | 41 | #include <asm/mach-imx/sys_proto.h> |
42 | #ifdef CONFIG_IMX_TRUSTY_OS | 42 | #ifdef CONFIG_IMX_TRUSTY_OS |
43 | #include <trusty/libtipc.h> | 43 | #include <trusty/libtipc.h> |
44 | #include <asm/mach-imx/hab.h> | 44 | #include <asm/mach-imx/hab.h> |
45 | #endif | 45 | #endif |
46 | 46 | ||
47 | #ifdef FASTBOOT_ENCRYPT_LOCK | 47 | #ifdef FASTBOOT_ENCRYPT_LOCK |
48 | 48 | ||
49 | #include <hash.h> | 49 | #include <hash.h> |
50 | #include <fsl_caam.h> | 50 | #include <fsl_caam.h> |
51 | 51 | ||
52 | //Encrypted data is 80bytes length. | 52 | //Encrypted data is 80bytes length. |
53 | #define ENDATA_LEN 80 | 53 | #define ENDATA_LEN 80 |
54 | 54 | ||
55 | #endif | 55 | #endif |
56 | 56 | ||
57 | int fastboot_flash_find_index(const char *name); | 57 | int fastboot_flash_find_index(const char *name); |
58 | 58 | ||
59 | #if defined(CONFIG_IMX_TRUSTY_OS) && !defined(CONFIG_ARM64) | 59 | #if defined(CONFIG_IMX_TRUSTY_OS) && !defined(CONFIG_ARM64) |
60 | #define IVT_HEADER_MAGIC 0xD1 | 60 | #define IVT_HEADER_MAGIC 0xD1 |
61 | #define IVT_HDR_LEN 0x20 | 61 | #define IVT_HDR_LEN 0x20 |
62 | #define HAB_MAJ_VER 0x40 | 62 | #define HAB_MAJ_VER 0x40 |
63 | #define HAB_MAJ_MASK 0xF0 | 63 | #define HAB_MAJ_MASK 0xF0 |
64 | 64 | ||
65 | bool tos_flashed; | 65 | bool tos_flashed; |
66 | 66 | ||
67 | static bool tos_ivt_check(ulong start_addr, int ivt_offset) { | 67 | static bool tos_ivt_check(ulong start_addr, int ivt_offset) { |
68 | const struct ivt *ivt_initial = NULL; | 68 | const struct ivt *ivt_initial = NULL; |
69 | const uint8_t *start = (const uint8_t *)start_addr; | 69 | const uint8_t *start = (const uint8_t *)start_addr; |
70 | 70 | ||
71 | if (start_addr & 0x3) { | 71 | if (start_addr & 0x3) { |
72 | puts("Error: tos's start address is not 4 byte aligned\n"); | 72 | puts("Error: tos's start address is not 4 byte aligned\n"); |
73 | return false; | 73 | return false; |
74 | } | 74 | } |
75 | 75 | ||
76 | ivt_initial = (const struct ivt *)(start + ivt_offset); | 76 | ivt_initial = (const struct ivt *)(start + ivt_offset); |
77 | 77 | ||
78 | const struct ivt_header *ivt_hdr = &ivt_initial->hdr; | 78 | const struct ivt_header *ivt_hdr = &ivt_initial->hdr; |
79 | 79 | ||
80 | if ((ivt_hdr->magic == IVT_HEADER_MAGIC && \ | 80 | if ((ivt_hdr->magic == IVT_HEADER_MAGIC && \ |
81 | (be16_to_cpu(ivt_hdr->length) == IVT_HDR_LEN) && \ | 81 | (be16_to_cpu(ivt_hdr->length) == IVT_HDR_LEN) && \ |
82 | (ivt_hdr->version & HAB_MAJ_MASK) == HAB_MAJ_VER) && \ | 82 | (ivt_hdr->version & HAB_MAJ_MASK) == HAB_MAJ_VER) && \ |
83 | (ivt_initial->entry != 0x0) && \ | 83 | (ivt_initial->entry != 0x0) && \ |
84 | (ivt_initial->reserved1 == 0x0) && \ | 84 | (ivt_initial->reserved1 == 0x0) && \ |
85 | (ivt_initial->self == (uint32_t)ivt_initial) && \ | 85 | (ivt_initial->self == (uint32_t)ivt_initial) && \ |
86 | (ivt_initial->csf != 0x0) && \ | 86 | (ivt_initial->csf != 0x0) && \ |
87 | (ivt_initial->reserved2 == 0x0)) { | 87 | (ivt_initial->reserved2 == 0x0)) { |
88 | if (ivt_initial->dcd != 0x0) | 88 | if (ivt_initial->dcd != 0x0) |
89 | return false; | 89 | return false; |
90 | else | 90 | else |
91 | return true; | 91 | return true; |
92 | } | 92 | } |
93 | 93 | ||
94 | return false; | 94 | return false; |
95 | } | 95 | } |
96 | 96 | ||
97 | bool valid_tos() { | 97 | bool valid_tos() { |
98 | /* | 98 | /* |
99 | * If enabled SECURE_BOOT then use HAB to verify tos. | 99 | * If enabled SECURE_BOOT then use HAB to verify tos. |
100 | * Or check the IVT only. | 100 | * Or check the IVT only. |
101 | */ | 101 | */ |
102 | bool valid = false; | 102 | bool valid = false; |
103 | #ifdef CONFIG_SECURE_BOOT | 103 | #ifdef CONFIG_SECURE_BOOT |
104 | if (is_hab_enabled()) { | 104 | if (is_hab_enabled()) { |
105 | valid = authenticate_image(TRUSTY_OS_ENTRY, TRUSTY_OS_PADDED_SZ); | 105 | valid = authenticate_image(TRUSTY_OS_ENTRY, TRUSTY_OS_PADDED_SZ); |
106 | } else | 106 | } else |
107 | #endif | 107 | #endif |
108 | valid = tos_ivt_check(TRUSTY_OS_ENTRY, TRUSTY_OS_PADDED_SZ); | 108 | valid = tos_ivt_check(TRUSTY_OS_ENTRY, TRUSTY_OS_PADDED_SZ); |
109 | 109 | ||
110 | if (valid) { | 110 | if (valid) { |
111 | tos_flashed = true; | 111 | tos_flashed = true; |
112 | return true; | 112 | return true; |
113 | } else { | 113 | } else { |
114 | tos_flashed = false; | 114 | tos_flashed = false; |
115 | return false; | 115 | return false; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | 118 | ||
119 | #endif | 119 | #endif |
120 | 120 | ||
121 | #if !defined(FASTBOOT_ENCRYPT_LOCK) || defined(NON_SECURE_FASTBOOT) | 121 | #if !defined(FASTBOOT_ENCRYPT_LOCK) || defined(NON_SECURE_FASTBOOT) |
122 | 122 | ||
123 | /* | 123 | /* |
124 | * This will return FASTBOOT_LOCK, FASTBOOT_UNLOCK or FASTBOOT_ERROR | 124 | * This will return FASTBOOT_LOCK, FASTBOOT_UNLOCK or FASTBOOT_ERROR |
125 | */ | 125 | */ |
126 | #ifndef CONFIG_IMX_TRUSTY_OS | 126 | #ifndef CONFIG_IMX_TRUSTY_OS |
127 | static FbLockState decrypt_lock_store(unsigned char* bdata) { | 127 | static FbLockState decrypt_lock_store(unsigned char* bdata) { |
128 | if (!strncmp((const char *)bdata, "locked", strlen("locked"))) | 128 | if (!strncmp((const char *)bdata, "locked", strlen("locked"))) |
129 | return FASTBOOT_LOCK; | 129 | return FASTBOOT_LOCK; |
130 | else if (!strncmp((const char *)bdata, "unlocked", strlen("unlocked"))) | 130 | else if (!strncmp((const char *)bdata, "unlocked", strlen("unlocked"))) |
131 | return FASTBOOT_UNLOCK; | 131 | return FASTBOOT_UNLOCK; |
132 | else | 132 | else |
133 | return FASTBOOT_LOCK_ERROR; | 133 | return FASTBOOT_LOCK_ERROR; |
134 | } | 134 | } |
135 | static inline int encrypt_lock_store(FbLockState lock, unsigned char* bdata) { | 135 | static inline int encrypt_lock_store(FbLockState lock, unsigned char* bdata) { |
136 | if (FASTBOOT_LOCK == lock) | 136 | if (FASTBOOT_LOCK == lock) |
137 | strncpy((char *)bdata, "locked", strlen("locked")); | 137 | strncpy((char *)bdata, "locked", strlen("locked")); |
138 | else if (FASTBOOT_UNLOCK == lock) | 138 | else if (FASTBOOT_UNLOCK == lock) |
139 | strncpy((char *)bdata, "unlocked", strlen("unlocked")); | 139 | strncpy((char *)bdata, "unlocked", strlen("unlocked")); |
140 | else | 140 | else |
141 | return -1; | 141 | return -1; |
142 | return 0; | 142 | return 0; |
143 | } | 143 | } |
144 | #endif | 144 | #endif |
145 | #else | 145 | #else |
146 | 146 | ||
147 | static int sha1sum(unsigned char* data, int len, unsigned char* output) { | 147 | static int sha1sum(unsigned char* data, int len, unsigned char* output) { |
148 | struct hash_algo *algo; | 148 | struct hash_algo *algo; |
149 | void *buf; | 149 | void *buf; |
150 | if (hash_lookup_algo("sha1", &algo)) { | 150 | if (hash_lookup_algo("sha1", &algo)) { |
151 | printf("error in lookup sha1 algo!\n"); | 151 | printf("error in lookup sha1 algo!\n"); |
152 | return -1; | 152 | return -1; |
153 | } | 153 | } |
154 | buf = map_sysmem((ulong)data, len); | 154 | buf = map_sysmem((ulong)data, len); |
155 | algo->hash_func_ws(buf, len, output, algo->chunk_size); | 155 | algo->hash_func_ws(buf, len, output, algo->chunk_size); |
156 | unmap_sysmem(buf); | 156 | unmap_sysmem(buf); |
157 | 157 | ||
158 | return algo->digest_size; | 158 | return algo->digest_size; |
159 | 159 | ||
160 | } | 160 | } |
161 | 161 | ||
162 | static int generate_salt(unsigned char* salt) { | 162 | static int generate_salt(unsigned char* salt) { |
163 | unsigned long time = get_timer(0); | 163 | unsigned long time = get_timer(0); |
164 | return sha1sum((unsigned char *)&time, sizeof(unsigned long), salt); | 164 | return sha1sum((unsigned char *)&time, sizeof(unsigned long), salt); |
165 | 165 | ||
166 | } | 166 | } |
167 | 167 | ||
168 | static FbLockState decrypt_lock_store(unsigned char *bdata) { | 168 | static FbLockState decrypt_lock_store(unsigned char *bdata) { |
169 | int p = 0, ret; | 169 | int p = 0, ret; |
170 | ALLOC_CACHE_ALIGN_BUFFER(uint8_t, plain_data, ENDATA_LEN); | 170 | ALLOC_CACHE_ALIGN_BUFFER(uint8_t, plain_data, ENDATA_LEN); |
171 | 171 | ||
172 | caam_open(); | 172 | caam_open(); |
173 | ret = caam_decap_blob((uint32_t)(ulong)plain_data, | 173 | ret = caam_decap_blob((uint32_t)(ulong)plain_data, |
174 | (uint32_t)(ulong)bdata + ROUND(ENDATA_LEN, ARCH_DMA_MINALIGN), | 174 | (uint32_t)(ulong)bdata + ROUND(ENDATA_LEN, ARCH_DMA_MINALIGN), |
175 | ENDATA_LEN); | 175 | ENDATA_LEN); |
176 | if (ret != 0) { | 176 | if (ret != 0) { |
177 | printf("Error during blob decap operation: 0x%x\n",ret); | 177 | printf("Error during blob decap operation: 0x%x\n",ret); |
178 | return FASTBOOT_LOCK_ERROR; | 178 | return FASTBOOT_LOCK_ERROR; |
179 | } | 179 | } |
180 | #ifdef FASTBOOT_LOCK_DEBUG | 180 | #ifdef FASTBOOT_LOCK_DEBUG |
181 | FB_DEBUG("Decrypt data block are:\n \t=======\t\n"); | 181 | FB_DEBUG("Decrypt data block are:\n \t=======\t\n"); |
182 | for (p = 0; p < ENDATA_LEN; p++) { | 182 | for (p = 0; p < ENDATA_LEN; p++) { |
183 | FB_DEBUG("0x%2x ", *(bdata + p)); | 183 | FB_DEBUG("0x%2x ", *(bdata + p)); |
184 | if (p % 16 == 0) | 184 | if (p % 16 == 0) |
185 | FB_DEBUG("\n"); | 185 | FB_DEBUG("\n"); |
186 | } | 186 | } |
187 | FB_DEBUG("\n \t========\t\n"); | 187 | FB_DEBUG("\n \t========\t\n"); |
188 | for (p = ENDATA_LEN; p < (ENDATA_LEN + ENDATA_LEN + 48 ); p++) { | 188 | for (p = ENDATA_LEN; p < (ENDATA_LEN + ENDATA_LEN + 48 ); p++) { |
189 | FB_DEBUG("0x%2x ", *(bdata + p)); | 189 | FB_DEBUG("0x%2x ", *(bdata + p)); |
190 | if (p % 16 == 0) | 190 | if (p % 16 == 0) |
191 | FB_DEBUG("\n"); | 191 | FB_DEBUG("\n"); |
192 | } | 192 | } |
193 | 193 | ||
194 | FB_DEBUG("\n plain text are:\n"); | 194 | FB_DEBUG("\n plain text are:\n"); |
195 | for (p = 0; p < ENDATA_LEN; p++) { | 195 | for (p = 0; p < ENDATA_LEN; p++) { |
196 | FB_DEBUG("0x%2x ", plain_data[p]); | 196 | FB_DEBUG("0x%2x ", plain_data[p]); |
197 | if (p % 16 == 0) | 197 | if (p % 16 == 0) |
198 | FB_DEBUG("\n"); | 198 | FB_DEBUG("\n"); |
199 | } | 199 | } |
200 | FB_DEBUG("\n"); | 200 | FB_DEBUG("\n"); |
201 | #endif | 201 | #endif |
202 | 202 | ||
203 | for (p = 0; p < ENDATA_LEN-1; p++) { | 203 | for (p = 0; p < ENDATA_LEN-1; p++) { |
204 | if (*(bdata+p) != plain_data[p]) { | 204 | if (*(bdata+p) != plain_data[p]) { |
205 | FB_DEBUG("Verify salt in decrypt error on pointer %d\n", p); | 205 | FB_DEBUG("Verify salt in decrypt error on pointer %d\n", p); |
206 | return FASTBOOT_LOCK_ERROR; | 206 | return FASTBOOT_LOCK_ERROR; |
207 | } | 207 | } |
208 | } | 208 | } |
209 | 209 | ||
210 | if (plain_data[ENDATA_LEN - 1] >= FASTBOOT_LOCK_NUM) | 210 | if (plain_data[ENDATA_LEN - 1] >= FASTBOOT_LOCK_NUM) |
211 | return FASTBOOT_LOCK_ERROR; | 211 | return FASTBOOT_LOCK_ERROR; |
212 | else | 212 | else |
213 | return plain_data[ENDATA_LEN-1]; | 213 | return plain_data[ENDATA_LEN-1]; |
214 | } | 214 | } |
215 | 215 | ||
216 | static int encrypt_lock_store(FbLockState lock, unsigned char* bdata) { | 216 | static int encrypt_lock_store(FbLockState lock, unsigned char* bdata) { |
217 | unsigned int p = 0; | 217 | unsigned int p = 0; |
218 | int ret; | 218 | int ret; |
219 | int salt_len = generate_salt(bdata); | 219 | int salt_len = generate_salt(bdata); |
220 | if (salt_len < 0) | 220 | if (salt_len < 0) |
221 | return -1; | 221 | return -1; |
222 | 222 | ||
223 | //salt_len cannot be longer than endata block size. | 223 | //salt_len cannot be longer than endata block size. |
224 | if (salt_len >= ENDATA_LEN) | 224 | if (salt_len >= ENDATA_LEN) |
225 | salt_len = ENDATA_LEN - 1; | 225 | salt_len = ENDATA_LEN - 1; |
226 | 226 | ||
227 | p = ENDATA_LEN - 1; | 227 | p = ENDATA_LEN - 1; |
228 | 228 | ||
229 | //Set lock value | 229 | //Set lock value |
230 | *(bdata + p) = lock; | 230 | *(bdata + p) = lock; |
231 | 231 | ||
232 | caam_open(); | 232 | caam_open(); |
233 | ret = caam_gen_blob((uint32_t)(ulong)bdata, | 233 | ret = caam_gen_blob((uint32_t)(ulong)bdata, |
234 | (uint32_t)(ulong)bdata + ROUND(ENDATA_LEN, ARCH_DMA_MINALIGN), | 234 | (uint32_t)(ulong)bdata + ROUND(ENDATA_LEN, ARCH_DMA_MINALIGN), |
235 | ENDATA_LEN); | 235 | ENDATA_LEN); |
236 | if (ret != 0) { | 236 | if (ret != 0) { |
237 | printf("error in caam_gen_blob:0x%x\n", ret); | 237 | printf("error in caam_gen_blob:0x%x\n", ret); |
238 | return -1; | 238 | return -1; |
239 | } | 239 | } |
240 | 240 | ||
241 | 241 | ||
242 | #ifdef FASTBOOT_LOCK_DEBUG | 242 | #ifdef FASTBOOT_LOCK_DEBUG |
243 | int i = 0; | 243 | int i = 0; |
244 | FB_DEBUG("encrypt plain_text:\n"); | 244 | FB_DEBUG("encrypt plain_text:\n"); |
245 | for (i = 0; i < ENDATA_LEN; i++) { | 245 | for (i = 0; i < ENDATA_LEN; i++) { |
246 | FB_DEBUG("0x%2x\t", *(bdata+i)); | 246 | FB_DEBUG("0x%2x\t", *(bdata+i)); |
247 | if (i % 16 == 0) | 247 | if (i % 16 == 0) |
248 | printf("\n"); | 248 | printf("\n"); |
249 | } | 249 | } |
250 | printf("\nto:\n"); | 250 | printf("\nto:\n"); |
251 | for (i=0; i < ENDATA_LEN + 48; i++) { | 251 | for (i=0; i < ENDATA_LEN + 48; i++) { |
252 | FB_DEBUG("0x%2x\t", *(bdata + ENDATA_LEN + i)); | 252 | FB_DEBUG("0x%2x\t", *(bdata + ENDATA_LEN + i)); |
253 | if (i % 16 == 0) | 253 | if (i % 16 == 0) |
254 | printf("\n"); | 254 | printf("\n"); |
255 | } | 255 | } |
256 | printf("\n"); | 256 | printf("\n"); |
257 | 257 | ||
258 | #endif | 258 | #endif |
259 | //protect value | 259 | //protect value |
260 | *(bdata + p) = 0xff; | 260 | *(bdata + p) = 0xff; |
261 | return 0; | 261 | return 0; |
262 | } | 262 | } |
263 | 263 | ||
264 | #endif | 264 | #endif |
265 | 265 | ||
266 | static char mmc_dev_part[16]; | 266 | static char mmc_dev_part[16]; |
267 | static char* get_mmc_part(int part) { | 267 | static char* get_mmc_part(int part) { |
268 | u32 dev_no = mmc_get_env_dev(); | 268 | u32 dev_no = mmc_get_env_dev(); |
269 | sprintf(mmc_dev_part,"%x:%x",dev_no, part); | 269 | sprintf(mmc_dev_part,"%x:%x",dev_no, part); |
270 | return mmc_dev_part; | 270 | return mmc_dev_part; |
271 | } | 271 | } |
272 | 272 | ||
273 | static inline void set_lock_disable_data(unsigned char* bdata) { | 273 | static inline void set_lock_disable_data(unsigned char* bdata) { |
274 | *(bdata + SECTOR_SIZE -1) = 0; | 274 | *(bdata + SECTOR_SIZE -1) = 0; |
275 | } | 275 | } |
276 | 276 | ||
277 | /* | 277 | /* |
278 | * The enabling value is stored in the last byte of target partition. | 278 | * The enabling value is stored in the last byte of target partition. |
279 | */ | 279 | */ |
280 | static inline unsigned char lock_enable_parse(unsigned char* bdata) { | 280 | static inline unsigned char lock_enable_parse(unsigned char* bdata) { |
281 | FB_DEBUG("lock_enable_parse: 0x%x\n", *(bdata + SECTOR_SIZE -1)); | 281 | FB_DEBUG("lock_enable_parse: 0x%x\n", *(bdata + SECTOR_SIZE -1)); |
282 | if (*(bdata + SECTOR_SIZE -1) >= FASTBOOT_UL_NUM) | 282 | if (*(bdata + SECTOR_SIZE -1) >= FASTBOOT_UL_NUM) |
283 | return FASTBOOT_UL_ERROR; | 283 | return FASTBOOT_UL_ERROR; |
284 | else | 284 | else |
285 | return *(bdata + SECTOR_SIZE -1); | 285 | return *(bdata + SECTOR_SIZE -1); |
286 | } | 286 | } |
287 | 287 | ||
288 | static FbLockState g_lockstat = FASTBOOT_UNLOCK; | 288 | static FbLockState g_lockstat = FASTBOOT_UNLOCK; |
289 | 289 | ||
290 | #ifdef CONFIG_IMX_TRUSTY_OS | 290 | #ifdef CONFIG_IMX_TRUSTY_OS |
291 | FbLockState fastboot_get_lock_stat(void) { | 291 | FbLockState fastboot_get_lock_stat(void) { |
292 | uint8_t l_status; | 292 | uint8_t l_status; |
293 | int ret; | 293 | int ret; |
294 | /* | 294 | /* |
295 | * If Trusty OS not flashed, then must return | 295 | * If Trusty OS not flashed, then must return |
296 | * unlock status to make device been able | 296 | * unlock status to make device been able |
297 | * to flash Trusty OS binary. | 297 | * to flash Trusty OS binary. |
298 | */ | 298 | */ |
299 | #ifndef CONFIG_ARM64 | 299 | #ifndef CONFIG_ARM64 |
300 | if (!tos_flashed) | 300 | if (!tos_flashed) |
301 | return FASTBOOT_UNLOCK; | 301 | return FASTBOOT_UNLOCK; |
302 | #endif | 302 | #endif |
303 | ret = trusty_read_lock_state(&l_status); | 303 | ret = trusty_read_lock_state(&l_status); |
304 | if (ret < 0) | 304 | if (ret < 0) |
305 | return g_lockstat; | 305 | return g_lockstat; |
306 | else | 306 | else |
307 | return l_status; | 307 | return l_status; |
308 | 308 | ||
309 | } | 309 | } |
310 | 310 | ||
311 | int fastboot_set_lock_stat(FbLockState lock) { | 311 | int fastboot_set_lock_stat(FbLockState lock) { |
312 | int ret; | 312 | int ret; |
313 | /* | 313 | /* |
314 | * If Trusty OS not flashed, we must prevent set lock | 314 | * If Trusty OS not flashed, we must prevent set lock |
315 | * status. Due the Trusty IPC won't work here. | 315 | * status. Due the Trusty IPC won't work here. |
316 | */ | 316 | */ |
317 | #ifndef CONFIG_ARM64 | 317 | #ifndef CONFIG_ARM64 |
318 | if (!tos_flashed) | 318 | if (!tos_flashed) |
319 | return 0; | 319 | return 0; |
320 | #endif | 320 | #endif |
321 | ret = trusty_write_lock_state(lock); | 321 | ret = trusty_write_lock_state(lock); |
322 | if (ret < 0) { | 322 | if (ret < 0) { |
323 | printf("cannot set lock status due Trusty return %d\n", ret); | 323 | printf("cannot set lock status due Trusty return %d\n", ret); |
324 | return ret; | 324 | return ret; |
325 | } | 325 | } |
326 | return 0; | 326 | return 0; |
327 | } | 327 | } |
328 | #else | 328 | #else |
329 | 329 | ||
330 | /* | 330 | /* |
331 | * Set status of the lock&unlock to FSL_FASTBOOT_FB_PART | 331 | * Set status of the lock&unlock to FSL_FASTBOOT_FB_PART |
332 | * Currently use the very first Byte of FSL_FASTBOOT_FB_PART | 332 | * Currently use the very first Byte of FSL_FASTBOOT_FB_PART |
333 | * to store the fastboot lock&unlock status | 333 | * to store the fastboot lock&unlock status |
334 | */ | 334 | */ |
335 | int fastboot_set_lock_stat(FbLockState lock) { | 335 | int fastboot_set_lock_stat(FbLockState lock) { |
336 | struct blk_desc *fs_dev_desc; | 336 | struct blk_desc *fs_dev_desc; |
337 | disk_partition_t fs_partition; | 337 | disk_partition_t fs_partition; |
338 | unsigned char *bdata; | 338 | unsigned char *bdata; |
339 | int mmc_id; | 339 | int mmc_id; |
340 | int status, ret; | 340 | int status, ret; |
341 | 341 | ||
342 | bdata = (unsigned char *)memalign(ARCH_DMA_MINALIGN, SECTOR_SIZE); | 342 | bdata = (unsigned char *)memalign(ARCH_DMA_MINALIGN, SECTOR_SIZE); |
343 | if (bdata == NULL) | 343 | if (bdata == NULL) |
344 | goto fail2; | 344 | goto fail2; |
345 | memset(bdata, 0, SECTOR_SIZE); | 345 | memset(bdata, 0, SECTOR_SIZE); |
346 | 346 | ||
347 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_FBMISC); | 347 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_FBMISC); |
348 | if (mmc_id < 0) { | 348 | if (mmc_id < 0) { |
349 | printf("%s: error in get mmc part\n", __FUNCTION__); | 349 | printf("%s: error in get mmc part\n", __FUNCTION__); |
350 | ret = -1; | 350 | ret = -1; |
351 | goto fail; | 351 | goto fail; |
352 | } | 352 | } |
353 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, | 353 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, |
354 | get_mmc_part(mmc_id), | 354 | get_mmc_part(mmc_id), |
355 | &fs_dev_desc, &fs_partition, 1); | 355 | &fs_dev_desc, &fs_partition, 1); |
356 | if (status < 0) { | 356 | if (status < 0) { |
357 | printf("%s:error in getdevice partition.\n", __FUNCTION__); | 357 | printf("%s:error in getdevice partition.\n", __FUNCTION__); |
358 | ret = -1; | 358 | ret = -1; |
359 | goto fail; | 359 | goto fail; |
360 | } | 360 | } |
361 | 361 | ||
362 | status = encrypt_lock_store(lock, bdata); | 362 | status = encrypt_lock_store(lock, bdata); |
363 | if (status < 0) { | 363 | if (status < 0) { |
364 | ret = -1; | 364 | ret = -1; |
365 | goto fail; | 365 | goto fail; |
366 | } | 366 | } |
367 | status = blk_dwrite(fs_dev_desc, fs_partition.start, 1, bdata); | 367 | status = blk_dwrite(fs_dev_desc, fs_partition.start, 1, bdata); |
368 | if (!status) { | 368 | if (!status) { |
369 | printf("%s:error in block write.\n", __FUNCTION__); | 369 | printf("%s:error in block write.\n", __FUNCTION__); |
370 | ret = -1; | 370 | ret = -1; |
371 | goto fail; | 371 | goto fail; |
372 | } | 372 | } |
373 | ret = 0; | 373 | ret = 0; |
374 | fail: | 374 | fail: |
375 | free(bdata); | 375 | free(bdata); |
376 | return ret; | 376 | return ret; |
377 | fail2: | 377 | fail2: |
378 | g_lockstat = lock; | 378 | g_lockstat = lock; |
379 | return 0; | 379 | return 0; |
380 | } | 380 | } |
381 | 381 | ||
382 | FbLockState fastboot_get_lock_stat(void) { | 382 | FbLockState fastboot_get_lock_stat(void) { |
383 | struct blk_desc *fs_dev_desc; | 383 | struct blk_desc *fs_dev_desc; |
384 | disk_partition_t fs_partition; | 384 | disk_partition_t fs_partition; |
385 | unsigned char *bdata; | 385 | unsigned char *bdata; |
386 | int mmc_id; | 386 | int mmc_id; |
387 | FbLockState ret; | 387 | FbLockState ret; |
388 | 388 | ||
389 | bdata = (unsigned char *)memalign(ARCH_DMA_MINALIGN, SECTOR_SIZE); | 389 | bdata = (unsigned char *)memalign(ARCH_DMA_MINALIGN, SECTOR_SIZE); |
390 | if (bdata == NULL) | 390 | if (bdata == NULL) |
391 | return g_lockstat; | 391 | return g_lockstat; |
392 | 392 | ||
393 | int status; | 393 | int status; |
394 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_FBMISC); | 394 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_FBMISC); |
395 | if (mmc_id < 0) { | 395 | if (mmc_id < 0) { |
396 | printf("%s: error in get mmc part\n", __FUNCTION__); | 396 | printf("%s: error in get mmc part\n", __FUNCTION__); |
397 | ret = g_lockstat; | 397 | ret = g_lockstat; |
398 | goto fail; | 398 | goto fail; |
399 | } | 399 | } |
400 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, | 400 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, |
401 | get_mmc_part(mmc_id), | 401 | get_mmc_part(mmc_id), |
402 | &fs_dev_desc, &fs_partition, 1); | 402 | &fs_dev_desc, &fs_partition, 1); |
403 | 403 | ||
404 | if (status < 0) { | 404 | if (status < 0) { |
405 | printf("%s:error in getdevice partition.\n", __FUNCTION__); | 405 | printf("%s:error in getdevice partition.\n", __FUNCTION__); |
406 | ret = g_lockstat; | 406 | ret = g_lockstat; |
407 | goto fail; | 407 | goto fail; |
408 | } | 408 | } |
409 | 409 | ||
410 | status = blk_dread(fs_dev_desc, fs_partition.start, 1, bdata); | 410 | status = blk_dread(fs_dev_desc, fs_partition.start, 1, bdata); |
411 | if (!status) { | 411 | if (!status) { |
412 | printf("%s:error in block read.\n", __FUNCTION__); | 412 | printf("%s:error in block read.\n", __FUNCTION__); |
413 | ret = FASTBOOT_LOCK_ERROR; | 413 | ret = FASTBOOT_LOCK_ERROR; |
414 | goto fail; | 414 | goto fail; |
415 | } | 415 | } |
416 | 416 | ||
417 | ret = decrypt_lock_store(bdata); | 417 | ret = decrypt_lock_store(bdata); |
418 | fail: | 418 | fail: |
419 | free(bdata); | 419 | free(bdata); |
420 | return ret; | 420 | return ret; |
421 | } | 421 | } |
422 | #endif | 422 | #endif |
423 | 423 | ||
424 | 424 | ||
425 | /* Return the last byte of of FSL_FASTBOOT_PR_DATA | 425 | /* Return the last byte of of FSL_FASTBOOT_PR_DATA |
426 | * which is managed by PresistDataService | 426 | * which is managed by PresistDataService |
427 | */ | 427 | */ |
428 | 428 | ||
429 | #ifdef CONFIG_ENABLE_LOCKSTATUS_SUPPORT | 429 | #ifdef CONFIG_ENABLE_LOCKSTATUS_SUPPORT |
430 | //Brillo has no presist data partition | 430 | //Brillo has no presist data partition |
431 | FbLockEnableResult fastboot_lock_enable(void) { | 431 | FbLockEnableResult fastboot_lock_enable(void) { |
432 | return FASTBOOT_UL_ENABLE; | 432 | return FASTBOOT_UL_ENABLE; |
433 | } | 433 | } |
434 | void set_fastboot_lock_disable(void) { | 434 | void set_fastboot_lock_disable(void) { |
435 | } | 435 | } |
436 | #else | 436 | #else |
437 | void set_fastboot_lock_disable(void) { | 437 | void set_fastboot_lock_disable(void) { |
438 | struct blk_desc *fs_dev_desc; | 438 | struct blk_desc *fs_dev_desc; |
439 | disk_partition_t fs_partition; | 439 | disk_partition_t fs_partition; |
440 | unsigned char *bdata; | 440 | unsigned char *bdata; |
441 | int mmc_id; | 441 | int mmc_id; |
442 | 442 | ||
443 | bdata = (unsigned char *)memalign(ALIGN_BYTES, SECTOR_SIZE); | 443 | bdata = (unsigned char *)memalign(ALIGN_BYTES, SECTOR_SIZE); |
444 | if (bdata == NULL) | 444 | if (bdata == NULL) |
445 | return; | 445 | return; |
446 | set_lock_disable_data(bdata); | 446 | set_lock_disable_data(bdata); |
447 | int status; | 447 | int status; |
448 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_PRDATA); | 448 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_PRDATA); |
449 | if (mmc_id < 0) { | 449 | if (mmc_id < 0) { |
450 | printf("%s: error in get mmc part\n", __FUNCTION__); | 450 | printf("%s: error in get mmc part\n", __FUNCTION__); |
451 | goto fail; | 451 | goto fail; |
452 | } | 452 | } |
453 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, | 453 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, |
454 | get_mmc_part(mmc_id), | 454 | get_mmc_part(mmc_id), |
455 | &fs_dev_desc, &fs_partition, 1); | 455 | &fs_dev_desc, &fs_partition, 1); |
456 | if (status < 0) { | 456 | if (status < 0) { |
457 | printf("%s:error in getdevice partition.\n", __FUNCTION__); | 457 | printf("%s:error in getdevice partition.\n", __FUNCTION__); |
458 | goto fail; | 458 | goto fail; |
459 | } | 459 | } |
460 | 460 | ||
461 | lbaint_t target_block = fs_partition.start + fs_partition.size - 1; | 461 | lbaint_t target_block = fs_partition.start + fs_partition.size - 1; |
462 | status = blk_dwrite(fs_dev_desc, target_block, 1, bdata); | 462 | status = blk_dwrite(fs_dev_desc, target_block, 1, bdata); |
463 | if (!status) { | 463 | if (!status) { |
464 | printf("%s: error in block read\n", __FUNCTION__); | 464 | printf("%s: error in block read\n", __FUNCTION__); |
465 | goto fail; | 465 | goto fail; |
466 | } | 466 | } |
467 | 467 | ||
468 | fail: | 468 | fail: |
469 | free(bdata); | 469 | free(bdata); |
470 | return; | 470 | return; |
471 | 471 | ||
472 | } | 472 | } |
473 | FbLockEnableResult fastboot_lock_enable() { | 473 | FbLockEnableResult fastboot_lock_enable() { |
474 | struct blk_desc *fs_dev_desc; | 474 | struct blk_desc *fs_dev_desc; |
475 | disk_partition_t fs_partition; | 475 | disk_partition_t fs_partition; |
476 | unsigned char *bdata; | 476 | unsigned char *bdata; |
477 | int mmc_id; | 477 | int mmc_id; |
478 | FbLockEnableResult ret; | 478 | FbLockEnableResult ret; |
479 | 479 | ||
480 | /* for imx6 and imx7 platforms, ignore presistdata partition | ||
481 | * for the convenience of using uuu | ||
482 | */ | ||
483 | if (is_mx6() || is_mx7() || is_mx7ulp()) | ||
484 | return FASTBOOT_UL_ENABLE; | ||
485 | |||
486 | bdata = (unsigned char *)memalign(ALIGN_BYTES, SECTOR_SIZE); | 480 | bdata = (unsigned char *)memalign(ALIGN_BYTES, SECTOR_SIZE); |
487 | if (bdata == NULL) | 481 | if (bdata == NULL) |
488 | return FASTBOOT_UL_ERROR; | 482 | return FASTBOOT_UL_ERROR; |
489 | int status; | 483 | int status; |
490 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_PRDATA); | 484 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_PRDATA); |
491 | if (mmc_id < 0) { | 485 | if (mmc_id < 0) { |
492 | printf("%s: error in get mmc part\n", __FUNCTION__); | 486 | printf("%s: error in get mmc part\n", __FUNCTION__); |
493 | ret = FASTBOOT_UL_ERROR; | 487 | ret = FASTBOOT_UL_ERROR; |
494 | goto fail; | 488 | goto fail; |
495 | } | 489 | } |
496 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, | 490 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, |
497 | get_mmc_part(mmc_id), | 491 | get_mmc_part(mmc_id), |
498 | &fs_dev_desc, &fs_partition, 1); | 492 | &fs_dev_desc, &fs_partition, 1); |
499 | if (status < 0) { | 493 | if (status < 0) { |
500 | printf("%s:error in getdevice partition.\n", __FUNCTION__); | 494 | printf("%s:error in getdevice partition.\n", __FUNCTION__); |
501 | ret = FASTBOOT_UL_ERROR; | 495 | ret = FASTBOOT_UL_ERROR; |
502 | goto fail; | 496 | goto fail; |
503 | } | 497 | } |
504 | 498 | ||
505 | //The data is stored in the last blcok of this partition. | 499 | //The data is stored in the last blcok of this partition. |
506 | lbaint_t target_block = fs_partition.start + fs_partition.size - 1; | 500 | lbaint_t target_block = fs_partition.start + fs_partition.size - 1; |
507 | status = blk_dread(fs_dev_desc, target_block, 1, bdata); | 501 | status = blk_dread(fs_dev_desc, target_block, 1, bdata); |
508 | if (!status) { | 502 | if (!status) { |
509 | printf("%s: error in block read\n", __FUNCTION__); | 503 | printf("%s: error in block read\n", __FUNCTION__); |
510 | ret = FASTBOOT_UL_ERROR; | 504 | ret = FASTBOOT_UL_ERROR; |
511 | goto fail; | 505 | goto fail; |
512 | } | 506 | } |
513 | int i = 0; | 507 | int i = 0; |
514 | FB_DEBUG("\n PRIST last sector is:\n"); | 508 | FB_DEBUG("\n PRIST last sector is:\n"); |
515 | for (i = 0; i < SECTOR_SIZE; i++) { | 509 | for (i = 0; i < SECTOR_SIZE; i++) { |
516 | FB_DEBUG("0x%x ", *(bdata + i)); | 510 | FB_DEBUG("0x%x ", *(bdata + i)); |
517 | if (i % 32 == 0) | 511 | if (i % 32 == 0) |
518 | FB_DEBUG("\n"); | 512 | FB_DEBUG("\n"); |
519 | } | 513 | } |
520 | FB_DEBUG("\n"); | 514 | FB_DEBUG("\n"); |
521 | ret = lock_enable_parse(bdata); | 515 | ret = lock_enable_parse(bdata); |
522 | fail: | 516 | fail: |
523 | free(bdata); | 517 | free(bdata); |
524 | return ret; | 518 | return ret; |
525 | 519 | ||
526 | } | 520 | } |
527 | #endif | 521 | #endif |
528 | 522 | ||
529 | int display_lock(FbLockState lock, int verify) { | 523 | int display_lock(FbLockState lock, int verify) { |
530 | struct stdio_dev *disp; | 524 | struct stdio_dev *disp; |
531 | disp = stdio_get_by_name("vga"); | 525 | disp = stdio_get_by_name("vga"); |
532 | if (disp != NULL) { | 526 | if (disp != NULL) { |
533 | if (lock == FASTBOOT_UNLOCK) { | 527 | if (lock == FASTBOOT_UNLOCK) { |
534 | disp->puts(disp, "\n============= NOTICE ============\n"); | 528 | disp->puts(disp, "\n============= NOTICE ============\n"); |
535 | disp->puts(disp, "| |\n"); | 529 | disp->puts(disp, "| |\n"); |
536 | disp->puts(disp, "| Your device is NOT locked. |\n"); | 530 | disp->puts(disp, "| Your device is NOT locked. |\n"); |
537 | disp->puts(disp, "| |\n"); | 531 | disp->puts(disp, "| |\n"); |
538 | disp->puts(disp, "=================================\n"); | 532 | disp->puts(disp, "=================================\n"); |
539 | } else { | 533 | } else { |
540 | if (verify == -1) { | 534 | if (verify == -1) { |
541 | disp->puts(disp, "\n============= NOTICE ============\n"); | 535 | disp->puts(disp, "\n============= NOTICE ============\n"); |
542 | disp->puts(disp, "| |\n"); | 536 | disp->puts(disp, "| |\n"); |
543 | disp->puts(disp, "| Your device is NOT protected. |\n"); | 537 | disp->puts(disp, "| Your device is NOT protected. |\n"); |
544 | disp->puts(disp, "| |\n"); | 538 | disp->puts(disp, "| |\n"); |
545 | disp->puts(disp, "=================================\n"); | 539 | disp->puts(disp, "=================================\n"); |
546 | } else if (verify == 1) { | 540 | } else if (verify == 1) { |
547 | disp->puts(disp, "\n============= NOTICE ============\n"); | 541 | disp->puts(disp, "\n============= NOTICE ============\n"); |
548 | disp->puts(disp, "| |\n"); | 542 | disp->puts(disp, "| |\n"); |
549 | disp->puts(disp, "| Boot verify failed! |\n"); | 543 | disp->puts(disp, "| Boot verify failed! |\n"); |
550 | disp->puts(disp, "| |\n"); | 544 | disp->puts(disp, "| |\n"); |
551 | disp->puts(disp, "=================================\n"); | 545 | disp->puts(disp, "=================================\n"); |
552 | } | 546 | } |
553 | } | 547 | } |
554 | return 0; | 548 | return 0; |
555 | } else | 549 | } else |
556 | printf("not found VGA disp console.\n"); | 550 | printf("not found VGA disp console.\n"); |
557 | 551 | ||
558 | return -1; | 552 | return -1; |
559 | 553 | ||
560 | } | 554 | } |
561 | 555 | ||
562 | int fastboot_wipe_data_partition(void) | 556 | int fastboot_wipe_data_partition(void) |
563 | { | 557 | { |
564 | struct blk_desc *fs_dev_desc; | 558 | struct blk_desc *fs_dev_desc; |
565 | disk_partition_t fs_partition; | 559 | disk_partition_t fs_partition; |
566 | int status; | 560 | int status; |
567 | int mmc_id; | 561 | int mmc_id; |
568 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_DATA); | 562 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_DATA); |
569 | if (mmc_id < 0) { | 563 | if (mmc_id < 0) { |
570 | printf("%s: error in get mmc part\n", __FUNCTION__); | 564 | printf("%s: error in get mmc part\n", __FUNCTION__); |
571 | return -1; | 565 | return -1; |
572 | } | 566 | } |
573 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, | 567 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, |
574 | get_mmc_part(mmc_id), &fs_dev_desc, &fs_partition, 1); | 568 | get_mmc_part(mmc_id), &fs_dev_desc, &fs_partition, 1); |
575 | if (status < 0) { | 569 | if (status < 0) { |
576 | printf("error in get device partition for wipe /data\n"); | 570 | printf("error in get device partition for wipe /data\n"); |
577 | return -1; | 571 | return -1; |
578 | } | 572 | } |
579 | status = blk_derase(fs_dev_desc, fs_partition.start , fs_partition.size ); | 573 | status = blk_derase(fs_dev_desc, fs_partition.start , fs_partition.size ); |
580 | if (status != fs_partition.size ) { | 574 | if (status != fs_partition.size ) { |
581 | printf("erase not complete\n"); | 575 | printf("erase not complete\n"); |
582 | return -1; | 576 | return -1; |
583 | } | 577 | } |
584 | mdelay(2000); | 578 | mdelay(2000); |
585 | 579 | ||
586 | return 0; | 580 | return 0; |
587 | } | 581 | } |
588 | 582 | ||
589 | void fastboot_wipe_all(void) { | 583 | void fastboot_wipe_all(void) { |
590 | struct blk_desc *fs_dev_desc; | 584 | struct blk_desc *fs_dev_desc; |
591 | disk_partition_t fs_partition; | 585 | disk_partition_t fs_partition; |
592 | int status; | 586 | int status; |
593 | int mmc_id; | 587 | int mmc_id; |
594 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_GPT); | 588 | mmc_id = fastboot_flash_find_index(FASTBOOT_PARTITION_GPT); |
595 | if (mmc_id < 0) { | 589 | if (mmc_id < 0) { |
596 | printf("%s: error in get mmc part\n", __FUNCTION__); | 590 | printf("%s: error in get mmc part\n", __FUNCTION__); |
597 | return; | 591 | return; |
598 | } | 592 | } |
599 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, | 593 | status = blk_get_device_part_str(FSL_FASTBOOT_FB_DEV, |
600 | get_mmc_part(mmc_id), &fs_dev_desc, &fs_partition, 1); | 594 | get_mmc_part(mmc_id), &fs_dev_desc, &fs_partition, 1); |
601 | if (status < 0) { | 595 | if (status < 0) { |
602 | printf("error in get device partition for wipe user partition\n"); | 596 | printf("error in get device partition for wipe user partition\n"); |
603 | return; | 597 | return; |
604 | } | 598 | } |
605 | status = blk_derase(fs_dev_desc, fs_partition.start , fs_partition.size ); | 599 | status = blk_derase(fs_dev_desc, fs_partition.start , fs_partition.size ); |
606 | if (status != fs_partition.size ) { | 600 | if (status != fs_partition.size ) { |
607 | printf("erase not complete\n"); | 601 | printf("erase not complete\n"); |
608 | return; | 602 | return; |
609 | } | 603 | } |
610 | printf("fastboot wiped all.\n"); | 604 | printf("fastboot wiped all.\n"); |
611 | } | 605 | } |
612 | 606 |