blob: a2594d3c552adcfdb82b716527ffe406810b7ce0 [file] [log] [blame]
Brian Swetland9c4c0752009-01-25 16:23:50 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
4 *
Amol Jadi2a15a272013-01-22 12:03:36 -08005 * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved.
Brian Swetland9c4c0752009-01-25 16:23:50 -08006 *
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -08007 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are met:
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070014 * * Neither the name of The Linux Foundation nor
Chandan Uddaraju5fa471a2009-12-02 17:31:34 -080015 * the names of its contributors may be used to endorse or promote
16 * products derived from this software without specific prior written
17 * permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
Brian Swetland9c4c0752009-01-25 16:23:50 -080031 */
32
33#include <app.h>
34#include <debug.h>
35#include <arch/arm.h>
36#include <dev/udc.h>
37#include <string.h>
38#include <kernel/thread.h>
39#include <arch/ops.h>
40
Dima Zavin214cc642009-01-26 11:16:21 -080041#include <dev/flash.h>
42#include <lib/ptable.h>
Dima Zavinb4283602009-01-26 16:36:57 -080043#include <dev/keys.h>
Shashank Mittal4f99a882010-02-01 13:58:50 -080044#include <dev/fbcon.h>
Ajay Dudanid04110c2011-01-17 23:55:07 -080045#include <baseband.h>
Greg Griscod6250552011-06-29 14:40:23 -070046#include <target.h>
47#include <mmc.h>
Kinson Chikf1a43512011-07-14 11:28:39 -070048#include <partition_parser.h>
Greg Griscod6250552011-06-29 14:40:23 -070049#include <platform.h>
Shashank Mittalcd98d472011-08-02 14:29:24 -070050#include <crypto_hash.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070051#include <malloc.h>
Amol Jadi492d5a52013-03-15 16:12:34 -070052#include <boot_stats.h>
Dima Zavin214cc642009-01-26 11:16:21 -080053
Neeti Desai17379b82012-06-04 18:42:53 -070054#if DEVICE_TREE
55#include <libfdt.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070056#include <dev_tree.h>
Neeti Desai17379b82012-06-04 18:42:53 -070057#endif
58
Shashank Mittalcd98d472011-08-02 14:29:24 -070059#include "image_verify.h"
Shashank Mittal024c0332010-02-03 11:44:00 -080060#include "recovery.h"
Brian Swetland9c4c0752009-01-25 16:23:50 -080061#include "bootimg.h"
62#include "fastboot.h"
Ajay Dudani5c761132011-04-07 20:19:04 -070063#include "sparse_format.h"
Greg Grisco6e754772011-06-23 12:19:39 -070064#include "mmc.h"
Shashank Mittal162244e2011-08-08 19:01:25 -070065#include "devinfo.h"
Neeti Desai465491e2012-07-31 12:53:35 -070066#include "board.h"
Brian Swetland9c4c0752009-01-25 16:23:50 -080067
Shashank Mittal162244e2011-08-08 19:01:25 -070068#include "scm.h"
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -070069
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070070extern bool target_use_signed_kernel(void);
71extern void dsb();
72extern void isb();
73extern void platform_uninit(void);
74
75void write_device_info_mmc(device_info *dev);
76void write_device_info_flash(device_info *dev);
77
Subbaraman Narayanamurthyeb92bcc2010-07-20 14:32:46 -070078#define EXPAND(NAME) #NAME
79#define TARGET(NAME) EXPAND(NAME)
Brian Swetland2defe162009-08-18 14:35:59 -070080
Ajay Dudanicd01f9b2010-02-23 21:13:04 -080081#ifdef MEMBASE
82#define EMMC_BOOT_IMG_HEADER_ADDR (0xFF000+(MEMBASE))
83#else
David Ng183a7422009-12-07 14:55:21 -080084#define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000
Ajay Dudanicd01f9b2010-02-23 21:13:04 -080085#endif
86
Chandan Uddarajude85d3f2010-01-05 16:32:33 -080087#define RECOVERY_MODE 0x77665502
88#define FASTBOOT_MODE 0x77665500
89
David Ng183a7422009-12-07 14:55:21 -080090static const char *emmc_cmdline = " androidboot.emmc=true";
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -080091static const char *usb_sn_cmdline = " androidboot.serialno=";
Ajay Dudanica3a33c2011-11-18 08:31:40 -080092static const char *battchg_pause = " androidboot.mode=charger";
Shashank Mittalcd98d472011-08-02 14:29:24 -070093static const char *auth_kernel = " androidboot.authorized_kernel=true";
David Ng183a7422009-12-07 14:55:21 -080094
Ajay Dudani6cff85e2011-02-04 16:02:16 -080095static const char *baseband_apq = " androidboot.baseband=apq";
96static const char *baseband_msm = " androidboot.baseband=msm";
97static const char *baseband_csfb = " androidboot.baseband=csfb";
98static const char *baseband_svlte2a = " androidboot.baseband=svlte2a";
Ajay Dudani403bc492011-09-30 16:17:21 -070099static const char *baseband_mdm = " androidboot.baseband=mdm";
Amol Jadi5c61a952012-05-04 17:05:35 -0700100static const char *baseband_sglte = " androidboot.baseband=sglte";
Amol Jadi2a15a272013-01-22 12:03:36 -0800101static const char *baseband_dsda = " androidboot.baseband=dsda";
102static const char *baseband_dsda2 = " androidboot.baseband=dsda2";
sundarajan srinivasanf8e9f3f2013-03-04 15:56:58 -0800103static const char *baseband_sglte2 = " androidboot.baseband=sglte2";
Ajay Dudanid04110c2011-01-17 23:55:07 -0800104
Shashank Mittalcd98d472011-08-02 14:29:24 -0700105/* Assuming unauthorized kernel image by default */
106static int auth_kernel_img = 0;
107
Shashank Mittal162244e2011-08-08 19:01:25 -0700108static device_info device = {DEVICE_MAGIC, 0, 0};
109
Brian Swetland9c4c0752009-01-25 16:23:50 -0800110static struct udc_device surf_udc_device = {
111 .vendor_id = 0x18d1,
Chandan Uddarajuc53a1a12009-11-18 14:53:40 -0800112 .product_id = 0xD00D,
Brian Swetland9c4c0752009-01-25 16:23:50 -0800113 .version_id = 0x0100,
114 .manufacturer = "Google",
115 .product = "Android",
116};
117
Dima Zavin42168f22009-01-30 11:52:22 -0800118struct atag_ptbl_entry
119{
120 char name[16];
121 unsigned offset;
122 unsigned size;
123 unsigned flags;
124};
125
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800126char sn_buf[13];
Greg Griscod6250552011-06-29 14:40:23 -0700127
Greg Griscod2471ef2011-07-14 13:00:42 -0700128extern int emmc_recovery_init(void);
129
Kinson Chik0b1c8162011-08-31 16:31:57 -0700130#if NO_KEYPAD_DRIVER
131extern int fastboot_trigger(void);
132#endif
Greg Griscod2471ef2011-07-14 13:00:42 -0700133
Channagoud Kadabia22144f2013-03-20 11:49:01 -0700134static void update_ker_tags_rdisk_addr(struct boot_img_hdr *hdr)
135{
136 /* overwrite the destination of specified for the project */
137 /*
138 * Update the value to sane values only when the boot image
139 * header does not have sane values, this is added to make sure
140 * that we always use values from boot.img header and use the
141 * force values when boot image header has default values.
142 */
143#ifdef ABOOT_FORCE_KERNEL_ADDR
144 if (hdr->kernel_addr == ABOOT_DEFAULT_KERNEL_ADDR)
145 hdr->kernel_addr = ABOOT_FORCE_KERNEL_ADDR;
146#endif
147#ifdef ABOOT_FORCE_RAMDISK_ADDR
148 if (hdr->ramdisk_addr == ABOOT_DEFAULT_RAMDISK_ADDR)
149 hdr->ramdisk_addr = ABOOT_FORCE_RAMDISK_ADDR;
150#endif
151#ifdef ABOOT_FORCE_TAGS_ADDR
152 if (hdr->tags_addr == ABOOT_DEFAULT_TAGS_ADDR)
153 hdr->tags_addr = ABOOT_FORCE_TAGS_ADDR;
154#endif
155}
156
Dima Zavin42168f22009-01-30 11:52:22 -0800157static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn)
158{
159 struct atag_ptbl_entry atag_ptn;
160
161 memcpy(atag_ptn.name, ptn->name, 16);
162 atag_ptn.name[15] = '\0';
163 atag_ptn.offset = ptn->start;
164 atag_ptn.size = ptn->length;
165 atag_ptn.flags = ptn->flags;
166 memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry));
167 *ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned);
168}
Brian Swetland9c4c0752009-01-25 16:23:50 -0800169
Neeti Desaie245d492012-06-01 12:52:13 -0700170unsigned char *update_cmdline(const char * cmdline)
Brian Swetland9c4c0752009-01-25 16:23:50 -0800171{
David Ng183a7422009-12-07 14:55:21 -0800172 int cmdline_len = 0;
173 int have_cmdline = 0;
Amol Jadi168b7712012-03-06 16:15:00 -0800174 unsigned char *cmdline_final = NULL;
Neeti Desaie245d492012-06-01 12:52:13 -0700175 int pause_at_bootup = 0;
Dima Zavin42168f22009-01-30 11:52:22 -0800176
Brian Swetland9c4c0752009-01-25 16:23:50 -0800177 if (cmdline && cmdline[0]) {
David Ng183a7422009-12-07 14:55:21 -0800178 cmdline_len = strlen(cmdline);
179 have_cmdline = 1;
180 }
181 if (target_is_emmc_boot()) {
182 cmdline_len += strlen(emmc_cmdline);
183 }
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800184
185 cmdline_len += strlen(usb_sn_cmdline);
186 cmdline_len += strlen(sn_buf);
187
David Ngf773dde2010-07-26 19:55:08 -0700188 if (target_pause_for_battery_charge()) {
189 pause_at_bootup = 1;
190 cmdline_len += strlen(battchg_pause);
191 }
Ajay Dudanid04110c2011-01-17 23:55:07 -0800192
Shashank Mittalcd98d472011-08-02 14:29:24 -0700193 if(target_use_signed_kernel() && auth_kernel_img) {
194 cmdline_len += strlen(auth_kernel);
195 }
196
Ajay Dudanid04110c2011-01-17 23:55:07 -0800197 /* Determine correct androidboot.baseband to use */
198 switch(target_baseband())
199 {
200 case BASEBAND_APQ:
201 cmdline_len += strlen(baseband_apq);
202 break;
203
204 case BASEBAND_MSM:
205 cmdline_len += strlen(baseband_msm);
206 break;
207
208 case BASEBAND_CSFB:
209 cmdline_len += strlen(baseband_csfb);
210 break;
211
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800212 case BASEBAND_SVLTE2A:
213 cmdline_len += strlen(baseband_svlte2a);
Ajay Dudanid04110c2011-01-17 23:55:07 -0800214 break;
Ajay Dudani403bc492011-09-30 16:17:21 -0700215
216 case BASEBAND_MDM:
217 cmdline_len += strlen(baseband_mdm);
218 break;
Amol Jadi5c61a952012-05-04 17:05:35 -0700219
220 case BASEBAND_SGLTE:
221 cmdline_len += strlen(baseband_sglte);
222 break;
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530223
sundarajan srinivasanf8e9f3f2013-03-04 15:56:58 -0800224 case BASEBAND_SGLTE2:
225 cmdline_len += strlen(baseband_sglte2);
226 break;
227
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530228 case BASEBAND_DSDA:
229 cmdline_len += strlen(baseband_dsda);
230 break;
Amol Jadi2a15a272013-01-22 12:03:36 -0800231
232 case BASEBAND_DSDA2:
233 cmdline_len += strlen(baseband_dsda2);
234 break;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800235 }
236
David Ng183a7422009-12-07 14:55:21 -0800237 if (cmdline_len > 0) {
238 const char *src;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700239 unsigned char *dst = (unsigned char*) malloc((cmdline_len + 4) & (~3));
240 ASSERT(dst != NULL);
Neeti Desaie245d492012-06-01 12:52:13 -0700241
Amol Jadi168b7712012-03-06 16:15:00 -0800242 /* Save start ptr for debug print */
Neeti Desaie245d492012-06-01 12:52:13 -0700243 cmdline_final = dst;
David Ng183a7422009-12-07 14:55:21 -0800244 if (have_cmdline) {
245 src = cmdline;
246 while ((*dst++ = *src++));
247 }
248 if (target_is_emmc_boot()) {
249 src = emmc_cmdline;
250 if (have_cmdline) --dst;
David Ngf773dde2010-07-26 19:55:08 -0700251 have_cmdline = 1;
252 while ((*dst++ = *src++));
253 }
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800254
255 src = usb_sn_cmdline;
256 if (have_cmdline) --dst;
257 have_cmdline = 1;
258 while ((*dst++ = *src++));
259 src = sn_buf;
260 if (have_cmdline) --dst;
261 have_cmdline = 1;
262 while ((*dst++ = *src++));
263
David Ngf773dde2010-07-26 19:55:08 -0700264 if (pause_at_bootup) {
265 src = battchg_pause;
266 if (have_cmdline) --dst;
David Ng183a7422009-12-07 14:55:21 -0800267 while ((*dst++ = *src++));
268 }
Ajay Dudanid04110c2011-01-17 23:55:07 -0800269
Shashank Mittalcd98d472011-08-02 14:29:24 -0700270 if(target_use_signed_kernel() && auth_kernel_img) {
271 src = auth_kernel;
272 if (have_cmdline) --dst;
273 while ((*dst++ = *src++));
274 }
275
Ajay Dudanid04110c2011-01-17 23:55:07 -0800276 switch(target_baseband())
277 {
278 case BASEBAND_APQ:
279 src = baseband_apq;
280 if (have_cmdline) --dst;
281 while ((*dst++ = *src++));
282 break;
283
284 case BASEBAND_MSM:
285 src = baseband_msm;
286 if (have_cmdline) --dst;
287 while ((*dst++ = *src++));
288 break;
289
290 case BASEBAND_CSFB:
291 src = baseband_csfb;
292 if (have_cmdline) --dst;
293 while ((*dst++ = *src++));
294 break;
295
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800296 case BASEBAND_SVLTE2A:
297 src = baseband_svlte2a;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800298 if (have_cmdline) --dst;
299 while ((*dst++ = *src++));
300 break;
Ajay Dudani403bc492011-09-30 16:17:21 -0700301
302 case BASEBAND_MDM:
303 src = baseband_mdm;
304 if (have_cmdline) --dst;
305 while ((*dst++ = *src++));
306 break;
Amol Jadi5c61a952012-05-04 17:05:35 -0700307
308 case BASEBAND_SGLTE:
309 src = baseband_sglte;
310 if (have_cmdline) --dst;
311 while ((*dst++ = *src++));
312 break;
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530313
sundarajan srinivasanf8e9f3f2013-03-04 15:56:58 -0800314 case BASEBAND_SGLTE2:
315 src = baseband_sglte2;
316 if (have_cmdline) --dst;
317 while ((*dst++ = *src++));
318 break;
319
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530320 case BASEBAND_DSDA:
321 src = baseband_dsda;
322 if (have_cmdline) --dst;
323 while ((*dst++ = *src++));
324 break;
Amol Jadi2a15a272013-01-22 12:03:36 -0800325
326 case BASEBAND_DSDA2:
327 src = baseband_dsda2;
328 if (have_cmdline) --dst;
329 while ((*dst++ = *src++));
330 break;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800331 }
Neeti Desaie245d492012-06-01 12:52:13 -0700332 }
Deepa Dinamani8b8736d2012-12-19 15:00:56 -0800333
334 dprintf(INFO, "cmdline: %s\n", cmdline_final);
335
Neeti Desaie245d492012-06-01 12:52:13 -0700336 return cmdline_final;
337}
338
339unsigned *atag_core(unsigned *ptr)
340{
341 /* CORE */
342 *ptr++ = 2;
343 *ptr++ = 0x54410001;
344
345 return ptr;
346
347}
348
349unsigned *atag_ramdisk(unsigned *ptr, void *ramdisk,
350 unsigned ramdisk_size)
351{
352 if (ramdisk_size) {
353 *ptr++ = 4;
354 *ptr++ = 0x54420005;
355 *ptr++ = (unsigned)ramdisk;
356 *ptr++ = ramdisk_size;
Brian Swetland9c4c0752009-01-25 16:23:50 -0800357 }
358
Neeti Desaie245d492012-06-01 12:52:13 -0700359 return ptr;
360}
361
362unsigned *atag_ptable(unsigned **ptr_addr)
363{
364 int i;
365 struct ptable *ptable;
366
367 if ((ptable = flash_get_ptable()) && (ptable->count != 0)) {
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700368 *(*ptr_addr)++ = 2 + (ptable->count * (sizeof(struct atag_ptbl_entry) /
369 sizeof(unsigned)));
Neeti Desaie245d492012-06-01 12:52:13 -0700370 *(*ptr_addr)++ = 0x4d534d70;
371 for (i = 0; i < ptable->count; ++i)
372 ptentry_to_tag(ptr_addr, ptable_get(ptable, i));
373 }
374
375 return (*ptr_addr);
376}
377
378unsigned *atag_cmdline(unsigned *ptr, const char *cmdline)
379{
380 int cmdline_length = 0;
381 int n;
Neeti Desaie245d492012-06-01 12:52:13 -0700382 char *dest;
383
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800384 cmdline_length = strlen((const char*)cmdline);
Neeti Desaie245d492012-06-01 12:52:13 -0700385 n = (cmdline_length + 4) & (~3);
386
387 *ptr++ = (n / 4) + 2;
388 *ptr++ = 0x54410009;
389 dest = (char *) ptr;
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800390 while ((*dest++ = *cmdline++));
Neeti Desaie245d492012-06-01 12:52:13 -0700391 ptr += (n / 4);
392
393 return ptr;
394}
395
396unsigned *atag_end(unsigned *ptr)
397{
Brian Swetland9c4c0752009-01-25 16:23:50 -0800398 /* END */
399 *ptr++ = 0;
400 *ptr++ = 0;
401
Neeti Desaie245d492012-06-01 12:52:13 -0700402 return ptr;
403}
404
405void generate_atags(unsigned *ptr, const char *cmdline,
406 void *ramdisk, unsigned ramdisk_size)
407{
408
409 ptr = atag_core(ptr);
410 ptr = atag_ramdisk(ptr, ramdisk, ramdisk_size);
411 ptr = target_atag_mem(ptr);
412
413 /* Skip NAND partition ATAGS for eMMC boot */
414 if (!target_is_emmc_boot()){
415 ptr = atag_ptable(&ptr);
416 }
417
418 ptr = atag_cmdline(ptr, cmdline);
419 ptr = atag_end(ptr);
420}
421
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700422typedef void entry_func_ptr(unsigned, unsigned, unsigned*);
Neeti Desaie245d492012-06-01 12:52:13 -0700423void boot_linux(void *kernel, unsigned *tags,
424 const char *cmdline, unsigned machtype,
425 void *ramdisk, unsigned ramdisk_size)
426{
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800427 unsigned char *final_cmdline;
Amol Jadib6be5c12012-11-14 13:39:51 -0800428#if DEVICE_TREE
Neeti Desai17379b82012-06-04 18:42:53 -0700429 int ret = 0;
Amol Jadib6be5c12012-11-14 13:39:51 -0800430#endif
431
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700432 void (*entry)(unsigned, unsigned, unsigned*) = (entry_func_ptr*)(PA((addr_t)kernel));
Deepa Dinamani25a9f762012-11-30 15:57:15 -0800433 uint32_t tags_phys = PA((addr_t)tags);
434
435 ramdisk = PA(ramdisk);
Neeti Desaie245d492012-06-01 12:52:13 -0700436
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800437 final_cmdline = update_cmdline((const char*)cmdline);
438
Neeti Desai17379b82012-06-04 18:42:53 -0700439#if DEVICE_TREE
Amol Jadib6be5c12012-11-14 13:39:51 -0800440 dprintf(INFO, "Updating device tree: start\n");
441
Neeti Desai17379b82012-06-04 18:42:53 -0700442 /* Update the Device Tree */
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800443 ret = update_device_tree((void *)tags, final_cmdline, ramdisk, ramdisk_size);
Neeti Desai17379b82012-06-04 18:42:53 -0700444 if(ret)
445 {
446 dprintf(CRITICAL, "ERROR: Updating Device Tree Failed \n");
447 ASSERT(0);
448 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800449 dprintf(INFO, "Updating device tree: done\n");
Neeti Desai17379b82012-06-04 18:42:53 -0700450#else
Neeti Desaie245d492012-06-01 12:52:13 -0700451 /* Generating the Atags */
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800452 generate_atags(tags, final_cmdline, ramdisk, ramdisk_size);
Neeti Desai17379b82012-06-04 18:42:53 -0700453#endif
Neeti Desaie245d492012-06-01 12:52:13 -0700454
Deepa Dinamani33734bc2013-03-06 12:16:06 -0800455 dprintf(INFO, "booting linux @ %p, ramdisk @ %p (%d), tags/device tree @ %p\n",
456 entry, ramdisk, ramdisk_size, tags_phys);
Brian Swetland9c4c0752009-01-25 16:23:50 -0800457
458 enter_critical_section();
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700459
Amol Jadi4421e652011-06-16 15:00:48 -0700460 /* do any platform specific cleanup before kernel entry */
461 platform_uninit();
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700462
Brian Swetland9c4c0752009-01-25 16:23:50 -0800463 arch_disable_cache(UCACHE);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700464
Amol Jadi504f9fe2012-08-16 13:56:48 -0700465#if ARM_WITH_MMU
Brian Swetland9c4c0752009-01-25 16:23:50 -0800466 arch_disable_mmu();
Amol Jadi504f9fe2012-08-16 13:56:48 -0700467#endif
Amol Jadi492d5a52013-03-15 16:12:34 -0700468 bs_set_timestamp(BS_KERNEL_ENTRY);
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700469 entry(0, machtype, (unsigned*)tags_phys);
Brian Swetland9c4c0752009-01-25 16:23:50 -0800470}
471
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800472unsigned page_size = 0;
473unsigned page_mask = 0;
Brian Swetland9c4c0752009-01-25 16:23:50 -0800474
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800475#define ROUND_TO_PAGE(x,y) (((x) + (y)) & (~(y)))
Brian Swetland9c4c0752009-01-25 16:23:50 -0800476
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800477static unsigned char buf[4096]; //Equal to max-supported pagesize
Amol Jadib6be5c12012-11-14 13:39:51 -0800478#if DEVICE_TREE
Neeti Desai465491e2012-07-31 12:53:35 -0700479static unsigned char dt_buf[4096];
Amol Jadib6be5c12012-11-14 13:39:51 -0800480#endif
Dima Zavin214cc642009-01-26 11:16:21 -0800481
Shashank Mittal23b8f422010-04-16 19:27:21 -0700482int boot_linux_from_mmc(void)
483{
484 struct boot_img_hdr *hdr = (void*) buf;
485 struct boot_img_hdr *uhdr;
486 unsigned offset = 0;
487 unsigned long long ptn = 0;
Kinson Chikf1a43512011-07-14 11:28:39 -0700488 int index = INVALID_PTN;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700489
Shashank Mittalcd98d472011-08-02 14:29:24 -0700490 unsigned char *image_addr = 0;
491 unsigned kernel_actual;
492 unsigned ramdisk_actual;
493 unsigned imagesize_actual;
Neeti Desai465491e2012-07-31 12:53:35 -0700494 unsigned second_actual = 0;
Neeti Desai465491e2012-07-31 12:53:35 -0700495
496#if DEVICE_TREE
497 struct dt_table *table;
498 struct dt_entry *dt_entry_ptr;
499 unsigned dt_table_offset;
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800500 uint32_t dt_actual;
Neeti Desai465491e2012-07-31 12:53:35 -0700501#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700502
Shashank Mittal23b8f422010-04-16 19:27:21 -0700503 uhdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR;
504 if (!memcmp(uhdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
505 dprintf(INFO, "Unified boot method!\n");
506 hdr = uhdr;
507 goto unified_boot;
508 }
Greg Griscod6250552011-06-29 14:40:23 -0700509 if (!boot_into_recovery) {
Kinson Chikf1a43512011-07-14 11:28:39 -0700510 index = partition_get_index("boot");
511 ptn = partition_get_offset(index);
512 if(ptn == 0) {
Shashank Mittal85b91f62010-10-30 10:12:38 -0700513 dprintf(CRITICAL, "ERROR: No boot partition found\n");
514 return -1;
515 }
Kinson Chikf1a43512011-07-14 11:28:39 -0700516 }
517 else {
518 index = partition_get_index("recovery");
519 ptn = partition_get_offset(index);
520 if(ptn == 0) {
Shashank Mittal85b91f62010-10-30 10:12:38 -0700521 dprintf(CRITICAL, "ERROR: No recovery partition found\n");
522 return -1;
523 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700524 }
525
Greg Griscod6250552011-06-29 14:40:23 -0700526 if (mmc_read(ptn + offset, (unsigned int *) buf, page_size)) {
Shashank Mittal23b8f422010-04-16 19:27:21 -0700527 dprintf(CRITICAL, "ERROR: Cannot read boot image header\n");
528 return -1;
529 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700530
531 if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
Kinson Chik kchik@codeaurora.org82e4ae62011-04-12 17:42:07 -0700532 dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -0700533 return -1;
534 }
535
Subbaraman Narayanamurthyfbe13a02010-09-10 11:51:12 -0700536 if (hdr->page_size && (hdr->page_size != page_size)) {
537 page_size = hdr->page_size;
538 page_mask = page_size - 1;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700539 }
540
Channagoud Kadabia22144f2013-03-20 11:49:01 -0700541 /*
542 * Update the kernel/ramdisk/tags address if the boot image header
543 * has default values, these default values come from mkbootimg when
544 * the boot image is flashed using fastboot flash:raw
545 */
546 update_ker_tags_rdisk_addr(hdr);
547
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700548 /* Get virtual addresses since the hdr saves physical addresses. */
549 hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr));
550 hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr));
551 hdr->tags_addr = VA((addr_t)(hdr->tags_addr));
552
Shashank Mittalcd98d472011-08-02 14:29:24 -0700553 /* Authenticate Kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700554 if(target_use_signed_kernel() && (!device.is_unlocked) && (!device.is_tampered))
Subbaraman Narayanamurthy958fa242011-01-27 17:42:38 -0800555 {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700556 image_addr = (unsigned char *)target_get_scratch_address();
557 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
558 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800559#if DEVICE_TREE
560 dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask);
561 imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual);
562#else
Channagoud Kadabi4b276512012-08-28 15:16:30 +0530563 imagesize_actual = (page_size + kernel_actual + ramdisk_actual);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800564#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700565 offset = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700566
567 /* Assuming device rooted at this time */
Shashank Mittala0032282011-08-26 14:50:11 -0700568 device.is_tampered = 1;
Shashank Mittal162244e2011-08-08 19:01:25 -0700569
Amol Jadib6be5c12012-11-14 13:39:51 -0800570 dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700571 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800572
Shashank Mittalcd98d472011-08-02 14:29:24 -0700573 /* Read image without signature */
574 if (mmc_read(ptn + offset, (void *)image_addr, imagesize_actual))
575 {
576 dprintf(CRITICAL, "ERROR: Cannot read boot image\n");
577 return -1;
Subbaraman Narayanamurthy958fa242011-01-27 17:42:38 -0800578 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700579
Amol Jadib6be5c12012-11-14 13:39:51 -0800580 dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700581 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Amol Jadib6be5c12012-11-14 13:39:51 -0800582
Shashank Mittalcd98d472011-08-02 14:29:24 -0700583 offset = imagesize_actual;
584 /* Read signature */
585 if(mmc_read(ptn + offset, (void *)(image_addr + offset), page_size))
586 {
587 dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n");
588 }
589 else
590 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800591 dprintf(INFO, "Authenticating boot image (%d): start\n", imagesize_actual);
592
Shashank Mittalcd98d472011-08-02 14:29:24 -0700593 auth_kernel_img = image_verify((unsigned char *)image_addr,
594 (unsigned char *)(image_addr + imagesize_actual),
595 imagesize_actual,
596 CRYPTO_AUTH_ALG_SHA256);
Shashank Mittal162244e2011-08-08 19:01:25 -0700597
Amol Jadib6be5c12012-11-14 13:39:51 -0800598 dprintf(INFO, "Authenticating boot image (%d): done\n", imagesize_actual);
599
Shashank Mittal162244e2011-08-08 19:01:25 -0700600 if(auth_kernel_img)
601 {
602 /* Authorized kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700603 device.is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700604 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700605 }
606
Neeti Desai465491e2012-07-31 12:53:35 -0700607 /* Move kernel, ramdisk and device tree to correct address */
Shashank Mittalcd98d472011-08-02 14:29:24 -0700608 memmove((void*) hdr->kernel_addr, (char *)(image_addr + page_size), hdr->kernel_size);
609 memmove((void*) hdr->ramdisk_addr, (char *)(image_addr + page_size + kernel_actual), hdr->ramdisk_size);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800610#if DEVICE_TREE
611 memmove((void*) hdr->tags_addr, (char *)(image_addr + page_size + kernel_actual + ramdisk_actual), hdr->dt_size);
612#endif
Shashank Mittal162244e2011-08-08 19:01:25 -0700613
Neeti Desai465491e2012-07-31 12:53:35 -0700614 #if DEVICE_TREE
615 if(hdr->dt_size) {
616 table = (struct dt_table*) dt_buf;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700617 dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual);
Neeti Desai465491e2012-07-31 12:53:35 -0700618
619 memmove((void *) dt_buf, (char *)dt_table_offset, page_size);
620
621 /* Restriction that the device tree entry table should be less than a page*/
622 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
623
624 /* Validate the device tree table header */
625 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
626 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
627 return -1;
628 }
629
630 /* Find index of device tree within device tree table */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700631 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
Neeti Desai465491e2012-07-31 12:53:35 -0700632 dprintf(CRITICAL, "ERROR: Device Tree Blob cannot be found\n");
633 return -1;
634 }
635
636 /* Read device device tree in the "tags_add */
637 memmove((void *)hdr->tags_addr, (char *)dt_table_offset + dt_entry_ptr->offset, dt_entry_ptr->size);
Channagoud Kadabi35095622013-03-01 13:53:05 -0800638 } else {
Dima Zavin77e41f32013-03-06 16:10:43 -0800639 /*
640 * If appended dev tree is found, update the atags with
641 * memory address to the DTB appended location on RAM.
642 * Else update with the atags address in the kernel header
643 */
644 void *dtb;
645 dtb = dev_tree_appended((void*) hdr->kernel_addr,
646 (void *)hdr->tags_addr);
647 if (!dtb) {
648 dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n");
649 return -1;
650 }
Neeti Desai465491e2012-07-31 12:53:35 -0700651 }
652 #endif
Shashank Mittal162244e2011-08-08 19:01:25 -0700653 /* Make sure everything from scratch address is read before next step!*/
Shashank Mittala0032282011-08-26 14:50:11 -0700654 if(device.is_tampered)
Shashank Mittal162244e2011-08-08 19:01:25 -0700655 {
656 write_device_info_mmc(&device);
657 #ifdef TZ_TAMPER_FUSE
658 set_tamper_fuse_cmd();
659 #endif
660 }
Channagoud Kadabibf695c62012-04-10 13:31:56 +0530661 #if USE_PCOM_SECBOOT
662 set_tamper_flag(device.is_tampered);
663 #endif
Shashank Mittal23b8f422010-04-16 19:27:21 -0700664 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700665 else
666 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800667 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
668 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
669 second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask);
Shashank Mittalcd98d472011-08-02 14:29:24 -0700670
Amol Jadib6be5c12012-11-14 13:39:51 -0800671 dprintf(INFO, "Loading boot image (%d): start\n",
672 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700673 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800674
675 offset = page_size;
676
677 /* Load kernel */
678 if (mmc_read(ptn + offset, (void *)hdr->kernel_addr, kernel_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700679 dprintf(CRITICAL, "ERROR: Cannot read kernel image\n");
680 return -1;
681 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800682 offset += kernel_actual;
Shashank Mittalcd98d472011-08-02 14:29:24 -0700683
Amol Jadib6be5c12012-11-14 13:39:51 -0800684 /* Load ramdisk */
685 if(ramdisk_actual != 0)
Shashank Mittalcd98d472011-08-02 14:29:24 -0700686 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800687 if (mmc_read(ptn + offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700688 dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n");
689 return -1;
690 }
691 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800692 offset += ramdisk_actual;
693
694 dprintf(INFO, "Loading boot image (%d): done\n",
695 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700696 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Neeti Desai465491e2012-07-31 12:53:35 -0700697
698 if(hdr->second_size != 0) {
Amol Jadib6be5c12012-11-14 13:39:51 -0800699 offset += second_actual;
700 /* Second image loading not implemented. */
701 ASSERT(0);
Neeti Desai465491e2012-07-31 12:53:35 -0700702 }
703
704 #if DEVICE_TREE
705 if(hdr->dt_size != 0) {
706
707 /* Read the device tree table into buffer */
708 if(mmc_read(ptn + offset,(unsigned int *) dt_buf, page_size)) {
709 dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n");
710 return -1;
711 }
712 table = (struct dt_table*) dt_buf;
713
714 /* Restriction that the device tree entry table should be less than a page*/
715 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
716
717 /* Validate the device tree table header */
718 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
719 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
720 return -1;
721 }
722
723 /* Calculate the offset of device tree within device tree table */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700724 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
Neeti Desai465491e2012-07-31 12:53:35 -0700725 dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
726 return -1;
727 }
728
729 /* Read device device tree in the "tags_add */
Neeti Desai465491e2012-07-31 12:53:35 -0700730 if(mmc_read(ptn + offset + dt_entry_ptr->offset,
731 (void *)hdr->tags_addr, dt_entry_ptr->size)) {
732 dprintf(CRITICAL, "ERROR: Cannot read device tree\n");
733 return -1;
734 }
Channagoud Kadabi35095622013-03-01 13:53:05 -0800735 } else {
Dima Zavin77e41f32013-03-06 16:10:43 -0800736 /*
737 * If appended dev tree is found, update the atags with
738 * memory address to the DTB appended location on RAM.
739 * Else update with the atags address in the kernel header
740 */
741 void *dtb;
742 dtb = dev_tree_appended((void*) hdr->kernel_addr,
743 (void *)hdr->tags_addr);
744 if (!dtb) {
745 dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n");
746 return -1;
747 }
Neeti Desai465491e2012-07-31 12:53:35 -0700748 }
749 #endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700750 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700751
752unified_boot:
Shashank Mittal23b8f422010-04-16 19:27:21 -0700753
Dima Zavin77e41f32013-03-06 16:10:43 -0800754 boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr,
Dima Zavinbd3daa02013-03-26 11:06:44 -0700755 (const char *)hdr->cmdline, board_machtype(),
Shashank Mittal23b8f422010-04-16 19:27:21 -0700756 (void *)hdr->ramdisk_addr, hdr->ramdisk_size);
757
758 return 0;
759}
760
Dima Zavin214cc642009-01-26 11:16:21 -0800761int boot_linux_from_flash(void)
762{
763 struct boot_img_hdr *hdr = (void*) buf;
Dima Zavin214cc642009-01-26 11:16:21 -0800764 struct ptentry *ptn;
765 struct ptable *ptable;
766 unsigned offset = 0;
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800767
Shashank Mittalcd98d472011-08-02 14:29:24 -0700768 unsigned char *image_addr = 0;
769 unsigned kernel_actual;
770 unsigned ramdisk_actual;
771 unsigned imagesize_actual;
Amol Jadib6be5c12012-11-14 13:39:51 -0800772 unsigned second_actual;
Shashank Mittalcd98d472011-08-02 14:29:24 -0700773
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700774#if DEVICE_TREE
775 struct dt_table *table;
776 struct dt_entry *dt_entry_ptr;
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800777 uint32_t dt_actual;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700778#endif
779
David Ng183a7422009-12-07 14:55:21 -0800780 if (target_is_emmc_boot()) {
781 hdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR;
782 if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
783 dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
784 return -1;
785 }
786 goto continue_boot;
787 }
788
Dima Zavin214cc642009-01-26 11:16:21 -0800789 ptable = flash_get_ptable();
790 if (ptable == NULL) {
791 dprintf(CRITICAL, "ERROR: Partition table not found\n");
792 return -1;
793 }
794
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800795 if(!boot_into_recovery)
796 {
797 ptn = ptable_find(ptable, "boot");
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700798
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800799 if (ptn == NULL) {
800 dprintf(CRITICAL, "ERROR: No boot partition found\n");
801 return -1;
802 }
803 }
804 else
805 {
806 ptn = ptable_find(ptable, "recovery");
807 if (ptn == NULL) {
808 dprintf(CRITICAL, "ERROR: No recovery partition found\n");
809 return -1;
810 }
Dima Zavin214cc642009-01-26 11:16:21 -0800811 }
812
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800813 if (flash_read(ptn, offset, buf, page_size)) {
Dima Zavin214cc642009-01-26 11:16:21 -0800814 dprintf(CRITICAL, "ERROR: Cannot read boot image header\n");
815 return -1;
816 }
Dima Zavin214cc642009-01-26 11:16:21 -0800817
818 if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
Kinson Chik kchik@codeaurora.org82e4ae62011-04-12 17:42:07 -0700819 dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
Dima Zavin214cc642009-01-26 11:16:21 -0800820 return -1;
821 }
822
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800823 if (hdr->page_size != page_size) {
Kinson Chik kchik@codeaurora.org82e4ae62011-04-12 17:42:07 -0700824 dprintf(CRITICAL, "ERROR: Invalid boot image pagesize. Device pagesize: %d, Image pagesize: %d\n",page_size,hdr->page_size);
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800825 return -1;
826 }
827
Channagoud Kadabia22144f2013-03-20 11:49:01 -0700828 /*
829 * Update the kernel/ramdisk/tags address if the boot image header
830 * has default values, these default values come from mkbootimg when
831 * the boot image is flashed using fastboot flash:raw
832 */
833 update_ker_tags_rdisk_addr(hdr);
834
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700835 /* Get virtual addresses since the hdr saves physical addresses. */
836 hdr->kernel_addr = VA(hdr->kernel_addr);
837 hdr->ramdisk_addr = VA(hdr->ramdisk_addr);
838 hdr->tags_addr = VA(hdr->tags_addr);
839
Shashank Mittalcd98d472011-08-02 14:29:24 -0700840 /* Authenticate Kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700841 if(target_use_signed_kernel() && (!device.is_unlocked) && (!device.is_tampered))
Shashank Mittalcd98d472011-08-02 14:29:24 -0700842 {
843 image_addr = (unsigned char *)target_get_scratch_address();
844 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
845 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800846#if DEVICE_TREE
847 dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask);
848 imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual);
849#else
Shashank Mittalcd98d472011-08-02 14:29:24 -0700850 imagesize_actual = (page_size + kernel_actual + ramdisk_actual);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800851#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700852 offset = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700853
854 /* Assuming device rooted at this time */
Shashank Mittala0032282011-08-26 14:50:11 -0700855 device.is_tampered = 1;
Shashank Mittal162244e2011-08-08 19:01:25 -0700856
Amol Jadib6be5c12012-11-14 13:39:51 -0800857 dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700858 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800859
Shashank Mittalcd98d472011-08-02 14:29:24 -0700860 /* Read image without signature */
861 if (flash_read(ptn, offset, (void *)image_addr, imagesize_actual))
862 {
863 dprintf(CRITICAL, "ERROR: Cannot read boot image\n");
864 return -1;
865 }
Dima Zavin214cc642009-01-26 11:16:21 -0800866
Amol Jadib6be5c12012-11-14 13:39:51 -0800867 dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700868 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Amol Jadib6be5c12012-11-14 13:39:51 -0800869
Shashank Mittalcd98d472011-08-02 14:29:24 -0700870 offset = imagesize_actual;
871 /* Read signature */
872 if (flash_read(ptn, offset, (void *)(image_addr + offset), page_size))
873 {
874 dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n");
875 }
876 else
877 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800878 dprintf(INFO, "Authenticating boot image (%d): start\n", imagesize_actual);
Shashank Mittalcd98d472011-08-02 14:29:24 -0700879
880 /* Verify signature */
881 auth_kernel_img = image_verify((unsigned char *)image_addr,
882 (unsigned char *)(image_addr + imagesize_actual),
883 imagesize_actual,
884 CRYPTO_AUTH_ALG_SHA256);
Shashank Mittal162244e2011-08-08 19:01:25 -0700885
Amol Jadib6be5c12012-11-14 13:39:51 -0800886 dprintf(INFO, "Authenticating boot image (%d): done\n", imagesize_actual);
887
Shashank Mittal162244e2011-08-08 19:01:25 -0700888 if(auth_kernel_img)
889 {
890 /* Authorized kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700891 device.is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700892 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700893 }
894
895 /* Move kernel and ramdisk to correct address */
896 memmove((void*) hdr->kernel_addr, (char *)(image_addr + page_size), hdr->kernel_size);
897 memmove((void*) hdr->ramdisk_addr, (char *)(image_addr + page_size + kernel_actual), hdr->ramdisk_size);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800898#if DEVICE_TREE
899 memmove((void*) hdr->tags_addr, (char *)(image_addr + page_size + kernel_actual + ramdisk_actual), hdr->dt_size);
900#endif
Shashank Mittal162244e2011-08-08 19:01:25 -0700901
902 /* Make sure everything from scratch address is read before next step!*/
Shashank Mittala0032282011-08-26 14:50:11 -0700903 if(device.is_tampered)
Shashank Mittal162244e2011-08-08 19:01:25 -0700904 {
905 write_device_info_flash(&device);
906 }
Channagoud Kadabi5c86fe32012-02-16 10:58:48 +0530907#if USE_PCOM_SECBOOT
908 set_tamper_flag(device.is_tampered);
909#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700910 }
911 else
912 {
Shashank Mittal162244e2011-08-08 19:01:25 -0700913 offset = page_size;
914
Amol Jadib6be5c12012-11-14 13:39:51 -0800915 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
916 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
917 second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask);
918
919 dprintf(INFO, "Loading boot image (%d): start\n",
920 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700921 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800922
923 if (flash_read(ptn, offset, (void *)hdr->kernel_addr, kernel_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700924 dprintf(CRITICAL, "ERROR: Cannot read kernel image\n");
925 return -1;
926 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800927 offset += kernel_actual;
Shashank Mittalcd98d472011-08-02 14:29:24 -0700928
Amol Jadib6be5c12012-11-14 13:39:51 -0800929 if (flash_read(ptn, offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700930 dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n");
931 return -1;
932 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800933 offset += ramdisk_actual;
934
935 dprintf(INFO, "Loading boot image (%d): done\n",
936 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700937 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700938
939 if(hdr->second_size != 0) {
Amol Jadib6be5c12012-11-14 13:39:51 -0800940 offset += second_actual;
941 /* Second image loading not implemented. */
942 ASSERT(0);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700943 }
944
945#if DEVICE_TREE
946 if(hdr->dt_size != 0) {
947
948 /* Read the device tree table into buffer */
949 if(flash_read(ptn, offset, (void *) dt_buf, page_size)) {
950 dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n");
951 return -1;
952 }
953
954 table = (struct dt_table*) dt_buf;
955
956 /* Restriction that the device tree entry table should be less than a page*/
957 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
958
959 /* Validate the device tree table header */
960 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
961 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
962 return -1;
963 }
964
965 /* Calculate the offset of device tree within device tree table */
966 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
967 dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
968 return -1;
969 }
970
971 /* Read device device tree in the "tags_add */
972 if(flash_read(ptn, offset + dt_entry_ptr->offset,
973 (void *)hdr->tags_addr, dt_entry_ptr->size)) {
974 dprintf(CRITICAL, "ERROR: Cannot read device tree\n");
975 return -1;
976 }
977 }
978#endif
979
Shashank Mittalcd98d472011-08-02 14:29:24 -0700980 }
David Ng183a7422009-12-07 14:55:21 -0800981continue_boot:
Dima Zavin214cc642009-01-26 11:16:21 -0800982
Dima Zavin214cc642009-01-26 11:16:21 -0800983 /* TODO: create/pass atags to kernel */
984
Ajay Dudanie28a6072011-07-01 13:59:46 -0700985 boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr,
Dima Zavinbd3daa02013-03-26 11:06:44 -0700986 (const char *)hdr->cmdline, board_machtype(),
Dima Zavin214cc642009-01-26 11:16:21 -0800987 (void *)hdr->ramdisk_addr, hdr->ramdisk_size);
988
989 return 0;
990}
Brian Swetland9c4c0752009-01-25 16:23:50 -0800991
Shashank Mittal162244e2011-08-08 19:01:25 -0700992unsigned char info_buf[4096];
993void write_device_info_mmc(device_info *dev)
994{
995 struct device_info *info = (void*) info_buf;
996 unsigned long long ptn = 0;
997 unsigned long long size;
998 int index = INVALID_PTN;
999
1000 index = partition_get_index("aboot");
1001 ptn = partition_get_offset(index);
1002 if(ptn == 0)
1003 {
1004 return;
1005 }
1006
1007 size = partition_get_size(index);
1008
1009 memcpy(info, dev, sizeof(device_info));
1010
1011 if(mmc_write((ptn + size - 512), 512, (void *)info_buf))
1012 {
1013 dprintf(CRITICAL, "ERROR: Cannot write device info\n");
1014 return;
1015 }
1016}
1017
1018void read_device_info_mmc(device_info *dev)
1019{
1020 struct device_info *info = (void*) info_buf;
1021 unsigned long long ptn = 0;
1022 unsigned long long size;
1023 int index = INVALID_PTN;
1024
1025 index = partition_get_index("aboot");
1026 ptn = partition_get_offset(index);
1027 if(ptn == 0)
1028 {
1029 return;
1030 }
1031
1032 size = partition_get_size(index);
1033
1034 if(mmc_read((ptn + size - 512), (void *)info_buf, 512))
1035 {
1036 dprintf(CRITICAL, "ERROR: Cannot read device info\n");
1037 return;
1038 }
1039
1040 if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE))
1041 {
1042 memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE);
1043 info->is_unlocked = 0;
Shashank Mittala0032282011-08-26 14:50:11 -07001044 info->is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -07001045
1046 write_device_info_mmc(info);
1047 }
1048 memcpy(dev, info, sizeof(device_info));
1049}
1050
1051void write_device_info_flash(device_info *dev)
1052{
1053 struct device_info *info = (void *) info_buf;
1054 struct ptentry *ptn;
1055 struct ptable *ptable;
1056
1057 ptable = flash_get_ptable();
1058 if (ptable == NULL)
1059 {
1060 dprintf(CRITICAL, "ERROR: Partition table not found\n");
1061 return;
1062 }
1063
1064 ptn = ptable_find(ptable, "devinfo");
1065 if (ptn == NULL)
1066 {
1067 dprintf(CRITICAL, "ERROR: No boot partition found\n");
1068 return;
1069 }
1070
1071 memcpy(info, dev, sizeof(device_info));
1072
1073 if (flash_write(ptn, 0, (void *)info_buf, page_size))
1074 {
1075 dprintf(CRITICAL, "ERROR: Cannot write device info\n");
1076 return;
1077 }
1078}
1079
1080void read_device_info_flash(device_info *dev)
1081{
1082 struct device_info *info = (void*) info_buf;
1083 struct ptentry *ptn;
1084 struct ptable *ptable;
1085
1086 ptable = flash_get_ptable();
1087 if (ptable == NULL)
1088 {
1089 dprintf(CRITICAL, "ERROR: Partition table not found\n");
1090 return;
1091 }
1092
1093 ptn = ptable_find(ptable, "devinfo");
1094 if (ptn == NULL)
1095 {
1096 dprintf(CRITICAL, "ERROR: No boot partition found\n");
1097 return;
1098 }
1099
1100 if (flash_read(ptn, 0, (void *)info_buf, page_size))
1101 {
1102 dprintf(CRITICAL, "ERROR: Cannot write device info\n");
1103 return;
1104 }
1105
1106 if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE))
1107 {
Shashank Mittal162244e2011-08-08 19:01:25 -07001108 memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE);
1109 info->is_unlocked = 0;
Shashank Mittala0032282011-08-26 14:50:11 -07001110 info->is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -07001111 write_device_info_flash(info);
1112 }
1113 memcpy(dev, info, sizeof(device_info));
1114}
1115
1116void write_device_info(device_info *dev)
1117{
1118 if(target_is_emmc_boot())
1119 {
1120 write_device_info_mmc(dev);
1121 }
1122 else
1123 {
1124 write_device_info_flash(dev);
1125 }
1126}
1127
1128void read_device_info(device_info *dev)
1129{
1130 if(target_is_emmc_boot())
1131 {
1132 read_device_info_mmc(dev);
1133 }
1134 else
1135 {
1136 read_device_info_flash(dev);
1137 }
1138}
1139
1140void reset_device_info()
1141{
1142 dprintf(ALWAYS, "reset_device_info called.");
Shashank Mittala0032282011-08-26 14:50:11 -07001143 device.is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -07001144 write_device_info(&device);
1145}
1146
1147void set_device_root()
1148{
1149 dprintf(ALWAYS, "set_device_root called.");
Shashank Mittala0032282011-08-26 14:50:11 -07001150 device.is_tampered = 1;
Shashank Mittal162244e2011-08-08 19:01:25 -07001151 write_device_info(&device);
1152}
1153
Amol Jadicb524072012-08-09 16:40:18 -07001154#if DEVICE_TREE
1155int copy_dtb(uint8_t *boot_image_start)
1156{
1157 uint32 dt_image_offset = 0;
1158 uint32_t n;
1159 struct dt_table *table;
1160 struct dt_entry *dt_entry_ptr;
Amol Jadicb524072012-08-09 16:40:18 -07001161
1162 struct boot_img_hdr *hdr = (struct boot_img_hdr *) (boot_image_start);
1163
Amol Jadicb524072012-08-09 16:40:18 -07001164 if(hdr->dt_size != 0) {
1165
1166 /* add kernel offset */
1167 dt_image_offset += page_size;
1168 n = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
1169 dt_image_offset += n;
1170
1171 /* add ramdisk offset */
1172 n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
1173 dt_image_offset += n;
1174
1175 /* add second offset */
1176 if(hdr->second_size != 0) {
1177 n = ROUND_TO_PAGE(hdr->second_size, page_mask);
1178 dt_image_offset += n;
1179 }
1180
1181 /* offset now point to start of dt.img */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001182 table = (struct dt_table*)(boot_image_start + dt_image_offset);
Amol Jadicb524072012-08-09 16:40:18 -07001183
1184 /* Restriction that the device tree entry table should be less than a page*/
1185 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
1186
1187 /* Validate the device tree table header */
1188 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
1189 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
1190 return -1;
1191 }
1192
1193 /* Calculate the offset of device tree within device tree table */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001194 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
Amol Jadicb524072012-08-09 16:40:18 -07001195 dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
1196 return -1;
1197 }
1198
1199 /* Read device device tree in the "tags_add */
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001200 memmove((void*) hdr->tags_addr,
1201 boot_image_start + dt_image_offset + dt_entry_ptr->offset,
1202 dt_entry_ptr->size);
Channagoud Kadabi35095622013-03-01 13:53:05 -08001203 } else {
1204 /*
Dima Zavin77e41f32013-03-06 16:10:43 -08001205 * If appended dev tree is found, update the atags with
1206 * memory address to the DTB appended location on RAM.
1207 * Else update with the atags address in the kernel header
Channagoud Kadabi35095622013-03-01 13:53:05 -08001208 */
Dima Zavin77e41f32013-03-06 16:10:43 -08001209 void *dtb;
1210 dtb = dev_tree_appended((void *)hdr->kernel_addr,
1211 (void *)hdr->tags_addr);
1212 if (!dtb) {
Channagoud Kadabi35095622013-03-01 13:53:05 -08001213 dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n");
1214 return -1;
1215 }
Amol Jadicb524072012-08-09 16:40:18 -07001216 }
1217
1218 /* Everything looks fine. Return success. */
1219 return 0;
1220}
1221#endif
1222
Brian Swetland9c4c0752009-01-25 16:23:50 -08001223void cmd_boot(const char *arg, void *data, unsigned sz)
1224{
1225 unsigned kernel_actual;
1226 unsigned ramdisk_actual;
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001227 struct boot_img_hdr *hdr;
Brian Swetland9c4c0752009-01-25 16:23:50 -08001228 char *ptr = ((char*) data);
1229
1230 if (sz < sizeof(hdr)) {
1231 fastboot_fail("invalid bootimage header");
1232 return;
1233 }
1234
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001235 hdr = (struct boot_img_hdr *)data;
Brian Swetland9c4c0752009-01-25 16:23:50 -08001236
1237 /* ensure commandline is terminated */
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001238 hdr->cmdline[BOOT_ARGS_SIZE-1] = 0;
Brian Swetland9c4c0752009-01-25 16:23:50 -08001239
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001240 if(target_is_emmc_boot() && hdr->page_size) {
1241 page_size = hdr->page_size;
Subbaraman Narayanamurthyfbe13a02010-09-10 11:51:12 -07001242 page_mask = page_size - 1;
1243 }
1244
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001245 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
1246 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
1247
Channagoud Kadabia22144f2013-03-20 11:49:01 -07001248 /*
1249 * Update the kernel/ramdisk/tags address if the boot image header
1250 * has default values, these default values come from mkbootimg when
1251 * the boot image is flashed using fastboot flash:raw
1252 */
1253 update_ker_tags_rdisk_addr(hdr);
Dima Zavin3cadfff2013-03-21 14:30:48 -07001254
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001255 /* Get virtual addresses since the hdr saves physical addresses. */
1256 hdr->kernel_addr = VA(hdr->kernel_addr);
1257 hdr->ramdisk_addr = VA(hdr->ramdisk_addr);
1258 hdr->tags_addr = VA(hdr->tags_addr);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001259
Shashank Mittal1f0e2662011-09-01 15:06:00 -07001260 /* sz should have atleast raw boot image */
1261 if (page_size + kernel_actual + ramdisk_actual > sz) {
Brian Swetland9c4c0752009-01-25 16:23:50 -08001262 fastboot_fail("incomplete bootimage");
1263 return;
1264 }
1265
Dima Zavin77e41f32013-03-06 16:10:43 -08001266 memmove((void*) hdr->kernel_addr, ptr + page_size, hdr->kernel_size);
1267 memmove((void*) hdr->ramdisk_addr, ptr + page_size + kernel_actual, hdr->ramdisk_size);
1268
Amol Jadicb524072012-08-09 16:40:18 -07001269#if DEVICE_TREE
1270 /* find correct dtb and copy it to right location */
1271 if(copy_dtb(data))
1272 {
1273 fastboot_fail("dtb not found");
1274 return;
1275 }
1276#endif
Brian Swetland9c4c0752009-01-25 16:23:50 -08001277
1278 fastboot_okay("");
1279 udc_stop();
1280
Dima Zavin77e41f32013-03-06 16:10:43 -08001281 boot_linux((void*) hdr->kernel_addr, (void*) hdr->tags_addr,
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001282 (const char*) hdr->cmdline, board_machtype(),
1283 (void*) hdr->ramdisk_addr, hdr->ramdisk_size);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001284}
1285
Dima Zavin214cc642009-01-26 11:16:21 -08001286void cmd_erase(const char *arg, void *data, unsigned sz)
1287{
1288 struct ptentry *ptn;
1289 struct ptable *ptable;
1290
1291 ptable = flash_get_ptable();
1292 if (ptable == NULL) {
1293 fastboot_fail("partition table doesn't exist");
1294 return;
1295 }
1296
1297 ptn = ptable_find(ptable, arg);
1298 if (ptn == NULL) {
1299 fastboot_fail("unknown partition name");
1300 return;
1301 }
1302
1303 if (flash_erase(ptn)) {
1304 fastboot_fail("failed to erase partition");
1305 return;
1306 }
1307 fastboot_okay("");
1308}
1309
Bikas Gurungd48bd242010-09-04 19:54:32 -07001310
1311void cmd_erase_mmc(const char *arg, void *data, unsigned sz)
1312{
1313 unsigned long long ptn = 0;
neetidb4b24d62012-01-20 12:13:09 -08001314 unsigned int out[512] = {0};
Kinson Chikf1a43512011-07-14 11:28:39 -07001315 int index = INVALID_PTN;
Bikas Gurungd48bd242010-09-04 19:54:32 -07001316
Kinson Chikf1a43512011-07-14 11:28:39 -07001317 index = partition_get_index(arg);
1318 ptn = partition_get_offset(index);
Neeti Desaica8c9602011-10-06 11:40:00 -07001319
Kinson Chikf1a43512011-07-14 11:28:39 -07001320 if(ptn == 0) {
Neeti Desaica8c9602011-10-06 11:40:00 -07001321 fastboot_fail("Partition table doesn't exist\n");
Bikas Gurungd48bd242010-09-04 19:54:32 -07001322 return;
1323 }
neetidb4b24d62012-01-20 12:13:09 -08001324 /* Simple inefficient version of erase. Just writing
1325 0 in first block */
1326 if (mmc_write(ptn , 512, (unsigned int *)out)) {
1327 fastboot_fail("failed to erase partition");
Bikas Gurungd48bd242010-09-04 19:54:32 -07001328 return;
1329 }
1330 fastboot_okay("");
1331}
1332
1333
Ajay Dudani5c761132011-04-07 20:19:04 -07001334void cmd_flash_mmc_img(const char *arg, void *data, unsigned sz)
Shashank Mittal23b8f422010-04-16 19:27:21 -07001335{
1336 unsigned long long ptn = 0;
Subbaraman Narayanamurthyc95b5b12010-08-31 13:19:48 -07001337 unsigned long long size = 0;
Kinson Chikf1a43512011-07-14 11:28:39 -07001338 int index = INVALID_PTN;
Subbaraman Narayanamurthyc95b5b12010-08-31 13:19:48 -07001339
Greg Grisco6e754772011-06-23 12:19:39 -07001340 if (!strcmp(arg, "partition"))
1341 {
1342 dprintf(INFO, "Attempt to write partition image.\n");
Neeti Desai5f26aff2011-09-30 10:27:40 -07001343 if (write_partition(sz, (unsigned char *) data)) {
Greg Grisco6e754772011-06-23 12:19:39 -07001344 fastboot_fail("failed to write partition");
Shashank Mittal23b8f422010-04-16 19:27:21 -07001345 return;
1346 }
1347 }
Greg Grisco6e754772011-06-23 12:19:39 -07001348 else
1349 {
Kinson Chikf1a43512011-07-14 11:28:39 -07001350 index = partition_get_index(arg);
1351 ptn = partition_get_offset(index);
Greg Grisco6e754772011-06-23 12:19:39 -07001352 if(ptn == 0) {
1353 fastboot_fail("partition table doesn't exist");
1354 return;
1355 }
Shashank Mittal23b8f422010-04-16 19:27:21 -07001356
Greg Grisco6e754772011-06-23 12:19:39 -07001357 if (!strcmp(arg, "boot") || !strcmp(arg, "recovery")) {
1358 if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
1359 fastboot_fail("image is not a boot image");
1360 return;
1361 }
1362 }
Subbaraman Narayanamurthyc95b5b12010-08-31 13:19:48 -07001363
Kinson Chikf1a43512011-07-14 11:28:39 -07001364 size = partition_get_size(index);
Greg Grisco6e754772011-06-23 12:19:39 -07001365 if (ROUND_TO_PAGE(sz,511) > size) {
1366 fastboot_fail("size too large");
1367 return;
1368 }
1369 else if (mmc_write(ptn , sz, (unsigned int *)data)) {
1370 fastboot_fail("flash write failure");
1371 return;
1372 }
Shashank Mittal23b8f422010-04-16 19:27:21 -07001373 }
1374 fastboot_okay("");
1375 return;
1376}
1377
Ajay Dudani5c761132011-04-07 20:19:04 -07001378void cmd_flash_mmc_sparse_img(const char *arg, void *data, unsigned sz)
1379{
1380 unsigned int chunk;
1381 unsigned int chunk_data_sz;
1382 sparse_header_t *sparse_header;
1383 chunk_header_t *chunk_header;
Ajay Dudaniab18f022011-05-12 14:39:22 -07001384 uint32_t total_blocks = 0;
Ajay Dudani5c761132011-04-07 20:19:04 -07001385 unsigned long long ptn = 0;
Channagoud Kadabi65b91002011-10-11 17:34:33 +05301386 unsigned long long size = 0;
Kinson Chikf1a43512011-07-14 11:28:39 -07001387 int index = INVALID_PTN;
Ajay Dudani5c761132011-04-07 20:19:04 -07001388
Kinson Chikf1a43512011-07-14 11:28:39 -07001389 index = partition_get_index(arg);
1390 ptn = partition_get_offset(index);
1391 if(ptn == 0) {
Ajay Dudani5c761132011-04-07 20:19:04 -07001392 fastboot_fail("partition table doesn't exist");
1393 return;
1394 }
1395
Channagoud Kadabi65b91002011-10-11 17:34:33 +05301396 size = partition_get_size(index);
1397 if (ROUND_TO_PAGE(sz,511) > size) {
1398 fastboot_fail("size too large");
1399 return;
1400 }
1401
Ajay Dudani5c761132011-04-07 20:19:04 -07001402 /* Read and skip over sparse image header */
1403 sparse_header = (sparse_header_t *) data;
Ajay Dudani876b3282012-12-21 14:12:17 -08001404 if ((sparse_header->total_blks * sparse_header->blk_sz) > size) {
1405 fastboot_fail("size too large");
1406 return;
1407 }
1408
Ajay Dudani5c761132011-04-07 20:19:04 -07001409 data += sparse_header->file_hdr_sz;
1410 if(sparse_header->file_hdr_sz > sizeof(sparse_header_t))
1411 {
1412 /* Skip the remaining bytes in a header that is longer than
1413 * we expected.
1414 */
1415 data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t));
1416 }
1417
Ajay Dudanib06c05f2011-05-12 14:46:10 -07001418 dprintf (SPEW, "=== Sparse Image Header ===\n");
1419 dprintf (SPEW, "magic: 0x%x\n", sparse_header->magic);
1420 dprintf (SPEW, "major_version: 0x%x\n", sparse_header->major_version);
1421 dprintf (SPEW, "minor_version: 0x%x\n", sparse_header->minor_version);
1422 dprintf (SPEW, "file_hdr_sz: %d\n", sparse_header->file_hdr_sz);
1423 dprintf (SPEW, "chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz);
1424 dprintf (SPEW, "blk_sz: %d\n", sparse_header->blk_sz);
1425 dprintf (SPEW, "total_blks: %d\n", sparse_header->total_blks);
1426 dprintf (SPEW, "total_chunks: %d\n", sparse_header->total_chunks);
Ajay Dudani5c761132011-04-07 20:19:04 -07001427
1428 /* Start processing chunks */
1429 for (chunk=0; chunk<sparse_header->total_chunks; chunk++)
1430 {
1431 /* Read and skip over chunk header */
1432 chunk_header = (chunk_header_t *) data;
1433 data += sizeof(chunk_header_t);
1434
1435 dprintf (SPEW, "=== Chunk Header ===\n");
1436 dprintf (SPEW, "chunk_type: 0x%x\n", chunk_header->chunk_type);
1437 dprintf (SPEW, "chunk_data_sz: 0x%x\n", chunk_header->chunk_sz);
1438 dprintf (SPEW, "total_size: 0x%x\n", chunk_header->total_sz);
1439
1440 if(sparse_header->chunk_hdr_sz > sizeof(chunk_header_t))
1441 {
1442 /* Skip the remaining bytes in a header that is longer than
1443 * we expected.
1444 */
1445 data += (sparse_header->chunk_hdr_sz - sizeof(chunk_header_t));
1446 }
1447
1448 chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz;
1449 switch (chunk_header->chunk_type)
1450 {
1451 case CHUNK_TYPE_RAW:
1452 if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz +
1453 chunk_data_sz))
1454 {
1455 fastboot_fail("Bogus chunk size for chunk type Raw");
1456 return;
1457 }
1458
Ajay Dudaniab18f022011-05-12 14:39:22 -07001459 if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz),
1460 chunk_data_sz,
1461 (unsigned int*)data))
Ajay Dudani5c761132011-04-07 20:19:04 -07001462 {
1463 fastboot_fail("flash write failure");
1464 return;
1465 }
1466 total_blocks += chunk_header->chunk_sz;
1467 data += chunk_data_sz;
1468 break;
1469
1470 case CHUNK_TYPE_DONT_CARE:
Kinson Chik kchik@codeaurora.orgda29b1e2011-05-06 17:36:39 -07001471 total_blocks += chunk_header->chunk_sz;
1472 break;
1473
Ajay Dudani5c761132011-04-07 20:19:04 -07001474 case CHUNK_TYPE_CRC:
1475 if(chunk_header->total_sz != sparse_header->chunk_hdr_sz)
1476 {
1477 fastboot_fail("Bogus chunk size for chunk type Dont Care");
1478 return;
1479 }
1480 total_blocks += chunk_header->chunk_sz;
1481 data += chunk_data_sz;
1482 break;
1483
Kinson Chik kchik@codeaurora.orgda29b1e2011-05-06 17:36:39 -07001484 default:
Ajay Dudani5c761132011-04-07 20:19:04 -07001485 fastboot_fail("Unknown chunk type");
1486 return;
1487 }
1488 }
1489
Ajay Dudani0c6927b2011-05-18 11:12:16 -07001490 dprintf(INFO, "Wrote %d blocks, expected to write %d blocks\n",
1491 total_blocks, sparse_header->total_blks);
1492
1493 if(total_blocks != sparse_header->total_blks)
1494 {
1495 fastboot_fail("sparse image write failure");
1496 }
Ajay Dudani5c761132011-04-07 20:19:04 -07001497
1498 fastboot_okay("");
1499 return;
1500}
1501
1502void cmd_flash_mmc(const char *arg, void *data, unsigned sz)
1503{
1504 sparse_header_t *sparse_header;
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001505 /* 8 Byte Magic + 2048 Byte xml + Encrypted Data */
1506 unsigned int *magic_number = (unsigned int *) data;
Ajay Dudani5c761132011-04-07 20:19:04 -07001507
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001508#ifdef SSD_ENABLE
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001509 int ret=0;
1510 uint32 major_version=0;
1511 uint32 minor_version=0;
1512
1513 ret = scm_svc_version(&major_version,&minor_version);
1514 if(!ret)
1515 {
1516 if(major_version >= 2)
1517 {
1518 if( !strcmp(arg,"ssd") || !strcmp(arg,"tqs") )
1519 {
1520 ret = encrypt_scm((uint32 **) &data, &sz);
1521 if (ret != 0) {
1522 dprintf(CRITICAL, "ERROR: Encryption Failure\n");
1523 return;
1524 }
1525
1526 ret = scm_protect_keystore((uint32 *) data, sz);
1527 if (ret != 0) {
1528 dprintf(CRITICAL, "ERROR: scm_protect_keystore Failed\n");
1529 return;
1530 }
1531 }
1532 else
1533 {
1534 ret = decrypt_scm_v2((uint32 **) &data, &sz);
1535 if(ret != 0)
1536 {
1537 dprintf(CRITICAL,"ERROR: Decryption Failure\n");
1538 return;
1539 }
1540 }
1541 }
1542 else
1543 {
1544 if (magic_number[0] == DECRYPT_MAGIC_0 &&
1545 magic_number[1] == DECRYPT_MAGIC_1)
1546 {
1547 ret = decrypt_scm((uint32 **) &data, &sz);
1548 if (ret != 0) {
1549 dprintf(CRITICAL, "ERROR: Invalid secure image\n");
1550 return;
1551 }
1552 }
1553 else if (magic_number[0] == ENCRYPT_MAGIC_0 &&
1554 magic_number[1] == ENCRYPT_MAGIC_1)
1555 {
1556 ret = encrypt_scm((uint32 **) &data, &sz);
1557 if (ret != 0) {
1558 dprintf(CRITICAL, "ERROR: Encryption Failure\n");
1559 return;
1560 }
1561 }
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001562 }
1563 }
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001564 else
Neeti Desai127b9e02012-03-20 16:11:23 -07001565 {
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001566 dprintf(CRITICAL,"INVALID SVC Version\n");
1567 return;
Neeti Desai127b9e02012-03-20 16:11:23 -07001568 }
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001569#endif /* SSD_ENABLE */
Neeti Desai127b9e02012-03-20 16:11:23 -07001570
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001571 sparse_header = (sparse_header_t *) data;
Ajay Dudani5c761132011-04-07 20:19:04 -07001572 if (sparse_header->magic != SPARSE_HEADER_MAGIC)
1573 cmd_flash_mmc_img(arg, data, sz);
1574 else
1575 cmd_flash_mmc_sparse_img(arg, data, sz);
Ajay Dudani5c761132011-04-07 20:19:04 -07001576 return;
1577}
1578
Dima Zavin214cc642009-01-26 11:16:21 -08001579void cmd_flash(const char *arg, void *data, unsigned sz)
1580{
1581 struct ptentry *ptn;
1582 struct ptable *ptable;
1583 unsigned extra = 0;
1584
1585 ptable = flash_get_ptable();
1586 if (ptable == NULL) {
1587 fastboot_fail("partition table doesn't exist");
1588 return;
1589 }
1590
1591 ptn = ptable_find(ptable, arg);
1592 if (ptn == NULL) {
1593 fastboot_fail("unknown partition name");
1594 return;
1595 }
1596
1597 if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) {
1598 if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
1599 fastboot_fail("image is not a boot image");
1600 return;
1601 }
1602 }
1603
Amol Jadi5c61a952012-05-04 17:05:35 -07001604 if (!strcmp(ptn->name, "system")
Deepa Dinamani13e32c42012-03-12 14:34:17 -07001605 || !strcmp(ptn->name, "userdata")
1606 || !strcmp(ptn->name, "persist")
1607 || !strcmp(ptn->name, "recoveryfs")) {
Channagoud Kadabi404a7062011-03-21 19:27:50 +05301608 if (flash_ecc_bch_enabled())
1609 /* Spare data bytes for 8 bit ECC increased by 4 */
1610 extra = ((page_size >> 9) * 20);
1611 else
1612 extra = ((page_size >> 9) * 16);
1613 } else
Shashank Mittaldcc2e352009-11-19 19:11:16 -08001614 sz = ROUND_TO_PAGE(sz, page_mask);
Dima Zavin214cc642009-01-26 11:16:21 -08001615
1616 dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name);
1617 if (flash_write(ptn, extra, data, sz)) {
1618 fastboot_fail("flash write failure");
1619 return;
1620 }
1621 dprintf(INFO, "partition '%s' updated\n", ptn->name);
1622 fastboot_okay("");
1623}
1624
1625void cmd_continue(const char *arg, void *data, unsigned sz)
1626{
1627 fastboot_okay("");
1628 udc_stop();
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001629 if (target_is_emmc_boot())
1630 {
1631 boot_linux_from_mmc();
1632 }
1633 else
1634 {
1635 boot_linux_from_flash();
1636 }
Dima Zavin214cc642009-01-26 11:16:21 -08001637}
1638
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001639void cmd_reboot(const char *arg, void *data, unsigned sz)
1640{
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001641 dprintf(INFO, "rebooting the device\n");
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001642 fastboot_okay("");
1643 reboot_device(0);
1644}
1645
1646void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz)
1647{
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001648 dprintf(INFO, "rebooting the device\n");
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001649 fastboot_okay("");
1650 reboot_device(FASTBOOT_MODE);
1651}
1652
Shashank Mittal162244e2011-08-08 19:01:25 -07001653void cmd_oem_unlock(const char *arg, void *data, unsigned sz)
1654{
1655 if(!device.is_unlocked)
1656 {
1657 device.is_unlocked = 1;
1658 write_device_info(&device);
1659 }
1660 fastboot_okay("");
1661}
1662
Shashank Mittala0032282011-08-26 14:50:11 -07001663void cmd_oem_devinfo(const char *arg, void *data, unsigned sz)
1664{
1665 char response[64];
1666 snprintf(response, 64, "\tDevice tampered: %s", (device.is_tampered ? "true" : "false"));
1667 fastboot_info(response);
1668 snprintf(response, 64, "\tDevice unlocked: %s", (device.is_unlocked ? "true" : "false"));
1669 fastboot_info(response);
1670 fastboot_okay("");
1671}
1672
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001673void splash_screen ()
1674{
1675 struct ptentry *ptn;
1676 struct ptable *ptable;
1677 struct fbcon_config *fb_display = NULL;
1678
1679 if (!target_is_emmc_boot())
1680 {
1681 ptable = flash_get_ptable();
1682 if (ptable == NULL) {
1683 dprintf(CRITICAL, "ERROR: Partition table not found\n");
Greg Griscod6250552011-06-29 14:40:23 -07001684 return;
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001685 }
1686
1687 ptn = ptable_find(ptable, "splash");
1688 if (ptn == NULL) {
1689 dprintf(CRITICAL, "ERROR: No splash partition found\n");
1690 } else {
1691 fb_display = fbcon_display();
1692 if (fb_display) {
1693 if (flash_read(ptn, 0, fb_display->base,
1694 (fb_display->width * fb_display->height * fb_display->bpp/8))) {
1695 fbcon_clear();
1696 dprintf(CRITICAL, "ERROR: Cannot read splash image\n");
1697 }
1698 }
1699 }
1700 }
1701}
1702
Brian Swetland9c4c0752009-01-25 16:23:50 -08001703void aboot_init(const struct app_descriptor *app)
1704{
Shashank Mittal4f99a882010-02-01 13:58:50 -08001705 unsigned reboot_mode = 0;
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001706 unsigned usb_init = 0;
Vivek Mehta5f1c9d42011-04-01 20:11:59 -07001707 unsigned sz = 0;
Chandan Uddarajubedca152010-06-02 23:05:15 -07001708
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001709 /* Setup page size information for nand/emmc reads */
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001710 if (target_is_emmc_boot())
1711 {
1712 page_size = 2048;
1713 page_mask = page_size - 1;
1714 }
1715 else
1716 {
1717 page_size = flash_page_size();
1718 page_mask = page_size - 1;
1719 }
1720
Shashank Mittal162244e2011-08-08 19:01:25 -07001721 if(target_use_signed_kernel())
1722 {
1723 read_device_info(&device);
1724
Shashank Mittal162244e2011-08-08 19:01:25 -07001725 }
1726
Greg Griscod6250552011-06-29 14:40:23 -07001727 target_serialno((unsigned char *) sn_buf);
Ajay Dudanib06c05f2011-05-12 14:46:10 -07001728 dprintf(SPEW,"serial number: %s\n",sn_buf);
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -08001729 surf_udc_device.serialno = sn_buf;
1730
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001731 /* Check if we should do something other than booting up */
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001732 if (keys_get_state(KEY_HOME) != 0)
1733 boot_into_recovery = 1;
Wentao Xu153902c2010-12-20 16:20:52 -05001734 if (keys_get_state(KEY_VOLUMEUP) != 0)
1735 boot_into_recovery = 1;
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -07001736 if(!boot_into_recovery)
1737 {
1738 if (keys_get_state(KEY_BACK) != 0)
1739 goto fastboot;
1740 if (keys_get_state(KEY_VOLUMEDOWN) != 0)
1741 goto fastboot;
1742 }
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001743
1744 #if NO_KEYPAD_DRIVER
Kinson Chik0b1c8162011-08-31 16:31:57 -07001745 if (fastboot_trigger())
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001746 goto fastboot;
1747 #endif
Chandan Uddarajubedca152010-06-02 23:05:15 -07001748
Ajay Dudani77421292010-10-27 19:34:06 -07001749 reboot_mode = check_reboot_mode();
1750 if (reboot_mode == RECOVERY_MODE) {
1751 boot_into_recovery = 1;
1752 } else if(reboot_mode == FASTBOOT_MODE) {
1753 goto fastboot;
1754 }
1755
Shashank Mittal23b8f422010-04-16 19:27:21 -07001756 if (target_is_emmc_boot())
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001757 {
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -07001758 if(emmc_recovery_init())
1759 dprintf(ALWAYS,"error in emmc_recovery_init\n");
Shashank Mittala0032282011-08-26 14:50:11 -07001760 if(target_use_signed_kernel())
1761 {
1762 if((device.is_unlocked) || (device.is_tampered))
1763 {
1764 #ifdef TZ_TAMPER_FUSE
1765 set_tamper_fuse_cmd();
1766 #endif
Channagoud Kadabibf695c62012-04-10 13:31:56 +05301767 #if USE_PCOM_SECBOOT
1768 set_tamper_flag(device.is_tampered);
1769 #endif
Shashank Mittala0032282011-08-26 14:50:11 -07001770 }
1771 }
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001772 boot_linux_from_mmc();
1773 }
1774 else
1775 {
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001776 recovery_init();
Channagoud Kadabie7b66702012-03-22 15:54:30 +05301777#if USE_PCOM_SECBOOT
1778 if((device.is_unlocked) || (device.is_tampered))
1779 set_tamper_flag(device.is_tampered);
1780#endif
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001781 boot_linux_from_flash();
1782 }
Dima Zavinb4283602009-01-26 16:36:57 -08001783 dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting "
1784 "to fastboot mode.\n");
1785
1786fastboot:
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001787
Shashank Mittal162244e2011-08-08 19:01:25 -07001788 target_fastboot_init();
Amol Jadi57abe4c2011-05-24 15:47:27 -07001789
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001790 if(!usb_init)
1791 udc_init(&surf_udc_device);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001792
1793 fastboot_register("boot", cmd_boot);
Bikas Gurungd48bd242010-09-04 19:54:32 -07001794
Shashank Mittal23b8f422010-04-16 19:27:21 -07001795 if (target_is_emmc_boot())
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001796 {
1797 fastboot_register("flash:", cmd_flash_mmc);
Bikas Gurungd48bd242010-09-04 19:54:32 -07001798 fastboot_register("erase:", cmd_erase_mmc);
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001799 }
1800 else
1801 {
1802 fastboot_register("flash:", cmd_flash);
Bikas Gurungd48bd242010-09-04 19:54:32 -07001803 fastboot_register("erase:", cmd_erase);
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001804 }
1805
1806 fastboot_register("continue", cmd_continue);
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001807 fastboot_register("reboot", cmd_reboot);
1808 fastboot_register("reboot-bootloader", cmd_reboot_bootloader);
Shashank Mittal162244e2011-08-08 19:01:25 -07001809 fastboot_register("oem unlock", cmd_oem_unlock);
Shashank Mittala0032282011-08-26 14:50:11 -07001810 fastboot_register("oem device-info", cmd_oem_devinfo);
Subbaraman Narayanamurthyeb92bcc2010-07-20 14:32:46 -07001811 fastboot_publish("product", TARGET(BOARD));
Brian Swetland9c4c0752009-01-25 16:23:50 -08001812 fastboot_publish("kernel", "lk");
Trevor Bourget59b25d52012-01-13 18:43:36 -08001813 fastboot_publish("serialno", sn_buf);
Kinson Chikf1a43512011-07-14 11:28:39 -07001814 partition_dump();
Vivek Mehta5f1c9d42011-04-01 20:11:59 -07001815 sz = target_get_max_flash_size();
1816 fastboot_init(target_get_scratch_address(), sz);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001817 udc_start();
Brian Swetland9c4c0752009-01-25 16:23:50 -08001818}
1819
1820APP_START(aboot)
1821 .init = aboot_init,
1822APP_END