blob: 3e17f066dd69ec07ce72112be1c62b24ec32ecb6 [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)
Chandan Uddarajuda919832009-11-17 01:06:11 -080080#define DEFAULT_CMDLINE "mem=100M console=null";
Brian Swetland2defe162009-08-18 14:35:59 -070081
Ajay Dudanicd01f9b2010-02-23 21:13:04 -080082#ifdef MEMBASE
83#define EMMC_BOOT_IMG_HEADER_ADDR (0xFF000+(MEMBASE))
84#else
David Ng183a7422009-12-07 14:55:21 -080085#define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000
Ajay Dudanicd01f9b2010-02-23 21:13:04 -080086#endif
87
Chandan Uddarajude85d3f2010-01-05 16:32:33 -080088#define RECOVERY_MODE 0x77665502
89#define FASTBOOT_MODE 0x77665500
90
David Ng183a7422009-12-07 14:55:21 -080091static const char *emmc_cmdline = " androidboot.emmc=true";
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -080092static const char *usb_sn_cmdline = " androidboot.serialno=";
Ajay Dudanica3a33c2011-11-18 08:31:40 -080093static const char *battchg_pause = " androidboot.mode=charger";
Shashank Mittalcd98d472011-08-02 14:29:24 -070094static const char *auth_kernel = " androidboot.authorized_kernel=true";
David Ng183a7422009-12-07 14:55:21 -080095
Ajay Dudani6cff85e2011-02-04 16:02:16 -080096static const char *baseband_apq = " androidboot.baseband=apq";
97static const char *baseband_msm = " androidboot.baseband=msm";
98static const char *baseband_csfb = " androidboot.baseband=csfb";
99static const char *baseband_svlte2a = " androidboot.baseband=svlte2a";
Ajay Dudani403bc492011-09-30 16:17:21 -0700100static const char *baseband_mdm = " androidboot.baseband=mdm";
Amol Jadi5c61a952012-05-04 17:05:35 -0700101static const char *baseband_sglte = " androidboot.baseband=sglte";
Amol Jadi2a15a272013-01-22 12:03:36 -0800102static const char *baseband_dsda = " androidboot.baseband=dsda";
103static const char *baseband_dsda2 = " androidboot.baseband=dsda2";
sundarajan srinivasanf8e9f3f2013-03-04 15:56:58 -0800104static const char *baseband_sglte2 = " androidboot.baseband=sglte2";
Ajay Dudanid04110c2011-01-17 23:55:07 -0800105
Shashank Mittalcd98d472011-08-02 14:29:24 -0700106/* Assuming unauthorized kernel image by default */
107static int auth_kernel_img = 0;
108
Shashank Mittal162244e2011-08-08 19:01:25 -0700109static device_info device = {DEVICE_MAGIC, 0, 0};
110
Brian Swetland9c4c0752009-01-25 16:23:50 -0800111static struct udc_device surf_udc_device = {
112 .vendor_id = 0x18d1,
Chandan Uddarajuc53a1a12009-11-18 14:53:40 -0800113 .product_id = 0xD00D,
Brian Swetland9c4c0752009-01-25 16:23:50 -0800114 .version_id = 0x0100,
115 .manufacturer = "Google",
116 .product = "Android",
117};
118
Dima Zavin42168f22009-01-30 11:52:22 -0800119struct atag_ptbl_entry
120{
121 char name[16];
122 unsigned offset;
123 unsigned size;
124 unsigned flags;
125};
126
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800127char sn_buf[13];
Greg Griscod6250552011-06-29 14:40:23 -0700128
Greg Griscod2471ef2011-07-14 13:00:42 -0700129extern int emmc_recovery_init(void);
130
Kinson Chik0b1c8162011-08-31 16:31:57 -0700131#if NO_KEYPAD_DRIVER
132extern int fastboot_trigger(void);
133#endif
Greg Griscod2471ef2011-07-14 13:00:42 -0700134
Channagoud Kadabia22144f2013-03-20 11:49:01 -0700135static void update_ker_tags_rdisk_addr(struct boot_img_hdr *hdr)
136{
137 /* overwrite the destination of specified for the project */
138 /*
139 * Update the value to sane values only when the boot image
140 * header does not have sane values, this is added to make sure
141 * that we always use values from boot.img header and use the
142 * force values when boot image header has default values.
143 */
144#ifdef ABOOT_FORCE_KERNEL_ADDR
145 if (hdr->kernel_addr == ABOOT_DEFAULT_KERNEL_ADDR)
146 hdr->kernel_addr = ABOOT_FORCE_KERNEL_ADDR;
147#endif
148#ifdef ABOOT_FORCE_RAMDISK_ADDR
149 if (hdr->ramdisk_addr == ABOOT_DEFAULT_RAMDISK_ADDR)
150 hdr->ramdisk_addr = ABOOT_FORCE_RAMDISK_ADDR;
151#endif
152#ifdef ABOOT_FORCE_TAGS_ADDR
153 if (hdr->tags_addr == ABOOT_DEFAULT_TAGS_ADDR)
154 hdr->tags_addr = ABOOT_FORCE_TAGS_ADDR;
155#endif
156}
157
Dima Zavin42168f22009-01-30 11:52:22 -0800158static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn)
159{
160 struct atag_ptbl_entry atag_ptn;
161
162 memcpy(atag_ptn.name, ptn->name, 16);
163 atag_ptn.name[15] = '\0';
164 atag_ptn.offset = ptn->start;
165 atag_ptn.size = ptn->length;
166 atag_ptn.flags = ptn->flags;
167 memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry));
168 *ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned);
169}
Brian Swetland9c4c0752009-01-25 16:23:50 -0800170
Neeti Desaie245d492012-06-01 12:52:13 -0700171unsigned char *update_cmdline(const char * cmdline)
Brian Swetland9c4c0752009-01-25 16:23:50 -0800172{
David Ng183a7422009-12-07 14:55:21 -0800173 int cmdline_len = 0;
174 int have_cmdline = 0;
Amol Jadi168b7712012-03-06 16:15:00 -0800175 unsigned char *cmdline_final = NULL;
Neeti Desaie245d492012-06-01 12:52:13 -0700176 int pause_at_bootup = 0;
Dima Zavin42168f22009-01-30 11:52:22 -0800177
Brian Swetland9c4c0752009-01-25 16:23:50 -0800178 if (cmdline && cmdline[0]) {
David Ng183a7422009-12-07 14:55:21 -0800179 cmdline_len = strlen(cmdline);
180 have_cmdline = 1;
181 }
182 if (target_is_emmc_boot()) {
183 cmdline_len += strlen(emmc_cmdline);
184 }
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800185
186 cmdline_len += strlen(usb_sn_cmdline);
187 cmdline_len += strlen(sn_buf);
188
David Ngf773dde2010-07-26 19:55:08 -0700189 if (target_pause_for_battery_charge()) {
190 pause_at_bootup = 1;
191 cmdline_len += strlen(battchg_pause);
192 }
Ajay Dudanid04110c2011-01-17 23:55:07 -0800193
Shashank Mittalcd98d472011-08-02 14:29:24 -0700194 if(target_use_signed_kernel() && auth_kernel_img) {
195 cmdline_len += strlen(auth_kernel);
196 }
197
Ajay Dudanid04110c2011-01-17 23:55:07 -0800198 /* Determine correct androidboot.baseband to use */
199 switch(target_baseband())
200 {
201 case BASEBAND_APQ:
202 cmdline_len += strlen(baseband_apq);
203 break;
204
205 case BASEBAND_MSM:
206 cmdline_len += strlen(baseband_msm);
207 break;
208
209 case BASEBAND_CSFB:
210 cmdline_len += strlen(baseband_csfb);
211 break;
212
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800213 case BASEBAND_SVLTE2A:
214 cmdline_len += strlen(baseband_svlte2a);
Ajay Dudanid04110c2011-01-17 23:55:07 -0800215 break;
Ajay Dudani403bc492011-09-30 16:17:21 -0700216
217 case BASEBAND_MDM:
218 cmdline_len += strlen(baseband_mdm);
219 break;
Amol Jadi5c61a952012-05-04 17:05:35 -0700220
221 case BASEBAND_SGLTE:
222 cmdline_len += strlen(baseband_sglte);
223 break;
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530224
sundarajan srinivasanf8e9f3f2013-03-04 15:56:58 -0800225 case BASEBAND_SGLTE2:
226 cmdline_len += strlen(baseband_sglte2);
227 break;
228
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530229 case BASEBAND_DSDA:
230 cmdline_len += strlen(baseband_dsda);
231 break;
Amol Jadi2a15a272013-01-22 12:03:36 -0800232
233 case BASEBAND_DSDA2:
234 cmdline_len += strlen(baseband_dsda2);
235 break;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800236 }
237
David Ng183a7422009-12-07 14:55:21 -0800238 if (cmdline_len > 0) {
239 const char *src;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700240 unsigned char *dst = (unsigned char*) malloc((cmdline_len + 4) & (~3));
241 ASSERT(dst != NULL);
Neeti Desaie245d492012-06-01 12:52:13 -0700242
Amol Jadi168b7712012-03-06 16:15:00 -0800243 /* Save start ptr for debug print */
Neeti Desaie245d492012-06-01 12:52:13 -0700244 cmdline_final = dst;
David Ng183a7422009-12-07 14:55:21 -0800245 if (have_cmdline) {
246 src = cmdline;
247 while ((*dst++ = *src++));
248 }
249 if (target_is_emmc_boot()) {
250 src = emmc_cmdline;
251 if (have_cmdline) --dst;
David Ngf773dde2010-07-26 19:55:08 -0700252 have_cmdline = 1;
253 while ((*dst++ = *src++));
254 }
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -0800255
256 src = usb_sn_cmdline;
257 if (have_cmdline) --dst;
258 have_cmdline = 1;
259 while ((*dst++ = *src++));
260 src = sn_buf;
261 if (have_cmdline) --dst;
262 have_cmdline = 1;
263 while ((*dst++ = *src++));
264
David Ngf773dde2010-07-26 19:55:08 -0700265 if (pause_at_bootup) {
266 src = battchg_pause;
267 if (have_cmdline) --dst;
David Ng183a7422009-12-07 14:55:21 -0800268 while ((*dst++ = *src++));
269 }
Ajay Dudanid04110c2011-01-17 23:55:07 -0800270
Shashank Mittalcd98d472011-08-02 14:29:24 -0700271 if(target_use_signed_kernel() && auth_kernel_img) {
272 src = auth_kernel;
273 if (have_cmdline) --dst;
274 while ((*dst++ = *src++));
275 }
276
Ajay Dudanid04110c2011-01-17 23:55:07 -0800277 switch(target_baseband())
278 {
279 case BASEBAND_APQ:
280 src = baseband_apq;
281 if (have_cmdline) --dst;
282 while ((*dst++ = *src++));
283 break;
284
285 case BASEBAND_MSM:
286 src = baseband_msm;
287 if (have_cmdline) --dst;
288 while ((*dst++ = *src++));
289 break;
290
291 case BASEBAND_CSFB:
292 src = baseband_csfb;
293 if (have_cmdline) --dst;
294 while ((*dst++ = *src++));
295 break;
296
Ajay Dudani6cff85e2011-02-04 16:02:16 -0800297 case BASEBAND_SVLTE2A:
298 src = baseband_svlte2a;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800299 if (have_cmdline) --dst;
300 while ((*dst++ = *src++));
301 break;
Ajay Dudani403bc492011-09-30 16:17:21 -0700302
303 case BASEBAND_MDM:
304 src = baseband_mdm;
305 if (have_cmdline) --dst;
306 while ((*dst++ = *src++));
307 break;
Amol Jadi5c61a952012-05-04 17:05:35 -0700308
309 case BASEBAND_SGLTE:
310 src = baseband_sglte;
311 if (have_cmdline) --dst;
312 while ((*dst++ = *src++));
313 break;
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530314
sundarajan srinivasanf8e9f3f2013-03-04 15:56:58 -0800315 case BASEBAND_SGLTE2:
316 src = baseband_sglte2;
317 if (have_cmdline) --dst;
318 while ((*dst++ = *src++));
319 break;
320
Channagoud Kadabi141f2982012-10-31 11:23:02 +0530321 case BASEBAND_DSDA:
322 src = baseband_dsda;
323 if (have_cmdline) --dst;
324 while ((*dst++ = *src++));
325 break;
Amol Jadi2a15a272013-01-22 12:03:36 -0800326
327 case BASEBAND_DSDA2:
328 src = baseband_dsda2;
329 if (have_cmdline) --dst;
330 while ((*dst++ = *src++));
331 break;
Ajay Dudanid04110c2011-01-17 23:55:07 -0800332 }
Neeti Desaie245d492012-06-01 12:52:13 -0700333 }
Deepa Dinamani8b8736d2012-12-19 15:00:56 -0800334
335 dprintf(INFO, "cmdline: %s\n", cmdline_final);
336
Neeti Desaie245d492012-06-01 12:52:13 -0700337 return cmdline_final;
338}
339
340unsigned *atag_core(unsigned *ptr)
341{
342 /* CORE */
343 *ptr++ = 2;
344 *ptr++ = 0x54410001;
345
346 return ptr;
347
348}
349
350unsigned *atag_ramdisk(unsigned *ptr, void *ramdisk,
351 unsigned ramdisk_size)
352{
353 if (ramdisk_size) {
354 *ptr++ = 4;
355 *ptr++ = 0x54420005;
356 *ptr++ = (unsigned)ramdisk;
357 *ptr++ = ramdisk_size;
Brian Swetland9c4c0752009-01-25 16:23:50 -0800358 }
359
Neeti Desaie245d492012-06-01 12:52:13 -0700360 return ptr;
361}
362
363unsigned *atag_ptable(unsigned **ptr_addr)
364{
365 int i;
366 struct ptable *ptable;
367
368 if ((ptable = flash_get_ptable()) && (ptable->count != 0)) {
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700369 *(*ptr_addr)++ = 2 + (ptable->count * (sizeof(struct atag_ptbl_entry) /
370 sizeof(unsigned)));
Neeti Desaie245d492012-06-01 12:52:13 -0700371 *(*ptr_addr)++ = 0x4d534d70;
372 for (i = 0; i < ptable->count; ++i)
373 ptentry_to_tag(ptr_addr, ptable_get(ptable, i));
374 }
375
376 return (*ptr_addr);
377}
378
379unsigned *atag_cmdline(unsigned *ptr, const char *cmdline)
380{
381 int cmdline_length = 0;
382 int n;
Neeti Desaie245d492012-06-01 12:52:13 -0700383 char *dest;
384
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800385 cmdline_length = strlen((const char*)cmdline);
Neeti Desaie245d492012-06-01 12:52:13 -0700386 n = (cmdline_length + 4) & (~3);
387
388 *ptr++ = (n / 4) + 2;
389 *ptr++ = 0x54410009;
390 dest = (char *) ptr;
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800391 while ((*dest++ = *cmdline++));
Neeti Desaie245d492012-06-01 12:52:13 -0700392 ptr += (n / 4);
393
394 return ptr;
395}
396
397unsigned *atag_end(unsigned *ptr)
398{
Brian Swetland9c4c0752009-01-25 16:23:50 -0800399 /* END */
400 *ptr++ = 0;
401 *ptr++ = 0;
402
Neeti Desaie245d492012-06-01 12:52:13 -0700403 return ptr;
404}
405
406void generate_atags(unsigned *ptr, const char *cmdline,
407 void *ramdisk, unsigned ramdisk_size)
408{
409
410 ptr = atag_core(ptr);
411 ptr = atag_ramdisk(ptr, ramdisk, ramdisk_size);
412 ptr = target_atag_mem(ptr);
413
414 /* Skip NAND partition ATAGS for eMMC boot */
415 if (!target_is_emmc_boot()){
416 ptr = atag_ptable(&ptr);
417 }
418
419 ptr = atag_cmdline(ptr, cmdline);
420 ptr = atag_end(ptr);
421}
422
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700423typedef void entry_func_ptr(unsigned, unsigned, unsigned*);
Neeti Desaie245d492012-06-01 12:52:13 -0700424void boot_linux(void *kernel, unsigned *tags,
425 const char *cmdline, unsigned machtype,
426 void *ramdisk, unsigned ramdisk_size)
427{
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800428 unsigned char *final_cmdline;
Amol Jadib6be5c12012-11-14 13:39:51 -0800429#if DEVICE_TREE
Neeti Desai17379b82012-06-04 18:42:53 -0700430 int ret = 0;
Amol Jadib6be5c12012-11-14 13:39:51 -0800431#endif
432
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700433 void (*entry)(unsigned, unsigned, unsigned*) = (entry_func_ptr*)(PA((addr_t)kernel));
Deepa Dinamani25a9f762012-11-30 15:57:15 -0800434 uint32_t tags_phys = PA((addr_t)tags);
435
436 ramdisk = PA(ramdisk);
Neeti Desaie245d492012-06-01 12:52:13 -0700437
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800438 final_cmdline = update_cmdline((const char*)cmdline);
439
Neeti Desai17379b82012-06-04 18:42:53 -0700440#if DEVICE_TREE
Amol Jadib6be5c12012-11-14 13:39:51 -0800441 dprintf(INFO, "Updating device tree: start\n");
442
Neeti Desai17379b82012-06-04 18:42:53 -0700443 /* Update the Device Tree */
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800444 ret = update_device_tree((void *)tags, final_cmdline, ramdisk, ramdisk_size);
Neeti Desai17379b82012-06-04 18:42:53 -0700445 if(ret)
446 {
447 dprintf(CRITICAL, "ERROR: Updating Device Tree Failed \n");
448 ASSERT(0);
449 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800450 dprintf(INFO, "Updating device tree: done\n");
Neeti Desai17379b82012-06-04 18:42:53 -0700451#else
Neeti Desaie245d492012-06-01 12:52:13 -0700452 /* Generating the Atags */
Amol Jadi10c7d1c2013-01-25 13:24:29 -0800453 generate_atags(tags, final_cmdline, ramdisk, ramdisk_size);
Neeti Desai17379b82012-06-04 18:42:53 -0700454#endif
Neeti Desaie245d492012-06-01 12:52:13 -0700455
Deepa Dinamani33734bc2013-03-06 12:16:06 -0800456 dprintf(INFO, "booting linux @ %p, ramdisk @ %p (%d), tags/device tree @ %p\n",
457 entry, ramdisk, ramdisk_size, tags_phys);
Brian Swetland9c4c0752009-01-25 16:23:50 -0800458
459 enter_critical_section();
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700460
Amol Jadi4421e652011-06-16 15:00:48 -0700461 /* do any platform specific cleanup before kernel entry */
462 platform_uninit();
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700463
Brian Swetland9c4c0752009-01-25 16:23:50 -0800464 arch_disable_cache(UCACHE);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700465
Amol Jadi504f9fe2012-08-16 13:56:48 -0700466#if ARM_WITH_MMU
Brian Swetland9c4c0752009-01-25 16:23:50 -0800467 arch_disable_mmu();
Amol Jadi504f9fe2012-08-16 13:56:48 -0700468#endif
Amol Jadi492d5a52013-03-15 16:12:34 -0700469 bs_set_timestamp(BS_KERNEL_ENTRY);
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700470 entry(0, machtype, (unsigned*)tags_phys);
Brian Swetland9c4c0752009-01-25 16:23:50 -0800471}
472
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800473unsigned page_size = 0;
474unsigned page_mask = 0;
Brian Swetland9c4c0752009-01-25 16:23:50 -0800475
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800476#define ROUND_TO_PAGE(x,y) (((x) + (y)) & (~(y)))
Brian Swetland9c4c0752009-01-25 16:23:50 -0800477
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800478static unsigned char buf[4096]; //Equal to max-supported pagesize
Amol Jadib6be5c12012-11-14 13:39:51 -0800479#if DEVICE_TREE
Neeti Desai465491e2012-07-31 12:53:35 -0700480static unsigned char dt_buf[4096];
Amol Jadib6be5c12012-11-14 13:39:51 -0800481#endif
Dima Zavin214cc642009-01-26 11:16:21 -0800482
Shashank Mittal23b8f422010-04-16 19:27:21 -0700483int boot_linux_from_mmc(void)
484{
485 struct boot_img_hdr *hdr = (void*) buf;
486 struct boot_img_hdr *uhdr;
487 unsigned offset = 0;
488 unsigned long long ptn = 0;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700489 const char *cmdline;
Kinson Chikf1a43512011-07-14 11:28:39 -0700490 int index = INVALID_PTN;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700491
Shashank Mittalcd98d472011-08-02 14:29:24 -0700492 unsigned char *image_addr = 0;
493 unsigned kernel_actual;
494 unsigned ramdisk_actual;
495 unsigned imagesize_actual;
Neeti Desai465491e2012-07-31 12:53:35 -0700496 unsigned second_actual = 0;
Neeti Desai465491e2012-07-31 12:53:35 -0700497
498#if DEVICE_TREE
499 struct dt_table *table;
500 struct dt_entry *dt_entry_ptr;
501 unsigned dt_table_offset;
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800502 uint32_t dt_actual;
Neeti Desai465491e2012-07-31 12:53:35 -0700503#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700504
Shashank Mittal23b8f422010-04-16 19:27:21 -0700505 uhdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR;
506 if (!memcmp(uhdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
507 dprintf(INFO, "Unified boot method!\n");
508 hdr = uhdr;
509 goto unified_boot;
510 }
Greg Griscod6250552011-06-29 14:40:23 -0700511 if (!boot_into_recovery) {
Kinson Chikf1a43512011-07-14 11:28:39 -0700512 index = partition_get_index("boot");
513 ptn = partition_get_offset(index);
514 if(ptn == 0) {
Shashank Mittal85b91f62010-10-30 10:12:38 -0700515 dprintf(CRITICAL, "ERROR: No boot partition found\n");
516 return -1;
517 }
Kinson Chikf1a43512011-07-14 11:28:39 -0700518 }
519 else {
520 index = partition_get_index("recovery");
521 ptn = partition_get_offset(index);
522 if(ptn == 0) {
Shashank Mittal85b91f62010-10-30 10:12:38 -0700523 dprintf(CRITICAL, "ERROR: No recovery partition found\n");
524 return -1;
525 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700526 }
527
Greg Griscod6250552011-06-29 14:40:23 -0700528 if (mmc_read(ptn + offset, (unsigned int *) buf, page_size)) {
Shashank Mittal23b8f422010-04-16 19:27:21 -0700529 dprintf(CRITICAL, "ERROR: Cannot read boot image header\n");
530 return -1;
531 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700532
533 if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
Kinson Chik kchik@codeaurora.org82e4ae62011-04-12 17:42:07 -0700534 dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
Shashank Mittal23b8f422010-04-16 19:27:21 -0700535 return -1;
536 }
537
Subbaraman Narayanamurthyfbe13a02010-09-10 11:51:12 -0700538 if (hdr->page_size && (hdr->page_size != page_size)) {
539 page_size = hdr->page_size;
540 page_mask = page_size - 1;
Shashank Mittal23b8f422010-04-16 19:27:21 -0700541 }
542
Channagoud Kadabia22144f2013-03-20 11:49:01 -0700543 /*
544 * Update the kernel/ramdisk/tags address if the boot image header
545 * has default values, these default values come from mkbootimg when
546 * the boot image is flashed using fastboot flash:raw
547 */
548 update_ker_tags_rdisk_addr(hdr);
549
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700550 /* Get virtual addresses since the hdr saves physical addresses. */
551 hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr));
552 hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr));
553 hdr->tags_addr = VA((addr_t)(hdr->tags_addr));
554
Shashank Mittalcd98d472011-08-02 14:29:24 -0700555 /* Authenticate Kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700556 if(target_use_signed_kernel() && (!device.is_unlocked) && (!device.is_tampered))
Subbaraman Narayanamurthy958fa242011-01-27 17:42:38 -0800557 {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700558 image_addr = (unsigned char *)target_get_scratch_address();
559 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
560 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800561#if DEVICE_TREE
562 dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask);
563 imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual);
564#else
Channagoud Kadabi4b276512012-08-28 15:16:30 +0530565 imagesize_actual = (page_size + kernel_actual + ramdisk_actual);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800566#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700567 offset = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700568
569 /* Assuming device rooted at this time */
Shashank Mittala0032282011-08-26 14:50:11 -0700570 device.is_tampered = 1;
Shashank Mittal162244e2011-08-08 19:01:25 -0700571
Amol Jadib6be5c12012-11-14 13:39:51 -0800572 dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700573 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800574
Shashank Mittalcd98d472011-08-02 14:29:24 -0700575 /* Read image without signature */
576 if (mmc_read(ptn + offset, (void *)image_addr, imagesize_actual))
577 {
578 dprintf(CRITICAL, "ERROR: Cannot read boot image\n");
579 return -1;
Subbaraman Narayanamurthy958fa242011-01-27 17:42:38 -0800580 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700581
Amol Jadib6be5c12012-11-14 13:39:51 -0800582 dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700583 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Amol Jadib6be5c12012-11-14 13:39:51 -0800584
Shashank Mittalcd98d472011-08-02 14:29:24 -0700585 offset = imagesize_actual;
586 /* Read signature */
587 if(mmc_read(ptn + offset, (void *)(image_addr + offset), page_size))
588 {
589 dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n");
590 }
591 else
592 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800593 dprintf(INFO, "Authenticating boot image (%d): start\n", imagesize_actual);
594
Shashank Mittalcd98d472011-08-02 14:29:24 -0700595 auth_kernel_img = image_verify((unsigned char *)image_addr,
596 (unsigned char *)(image_addr + imagesize_actual),
597 imagesize_actual,
598 CRYPTO_AUTH_ALG_SHA256);
Shashank Mittal162244e2011-08-08 19:01:25 -0700599
Amol Jadib6be5c12012-11-14 13:39:51 -0800600 dprintf(INFO, "Authenticating boot image (%d): done\n", imagesize_actual);
601
Shashank Mittal162244e2011-08-08 19:01:25 -0700602 if(auth_kernel_img)
603 {
604 /* Authorized kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700605 device.is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700606 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700607 }
608
Neeti Desai465491e2012-07-31 12:53:35 -0700609 /* Move kernel, ramdisk and device tree to correct address */
Shashank Mittalcd98d472011-08-02 14:29:24 -0700610 memmove((void*) hdr->kernel_addr, (char *)(image_addr + page_size), hdr->kernel_size);
611 memmove((void*) hdr->ramdisk_addr, (char *)(image_addr + page_size + kernel_actual), hdr->ramdisk_size);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800612#if DEVICE_TREE
613 memmove((void*) hdr->tags_addr, (char *)(image_addr + page_size + kernel_actual + ramdisk_actual), hdr->dt_size);
614#endif
Shashank Mittal162244e2011-08-08 19:01:25 -0700615
Neeti Desai465491e2012-07-31 12:53:35 -0700616 #if DEVICE_TREE
617 if(hdr->dt_size) {
618 table = (struct dt_table*) dt_buf;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700619 dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual);
Neeti Desai465491e2012-07-31 12:53:35 -0700620
621 memmove((void *) dt_buf, (char *)dt_table_offset, page_size);
622
623 /* Restriction that the device tree entry table should be less than a page*/
624 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
625
626 /* Validate the device tree table header */
627 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
628 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
629 return -1;
630 }
631
632 /* Find index of device tree within device tree table */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700633 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
Neeti Desai465491e2012-07-31 12:53:35 -0700634 dprintf(CRITICAL, "ERROR: Device Tree Blob cannot be found\n");
635 return -1;
636 }
637
638 /* Read device device tree in the "tags_add */
639 memmove((void *)hdr->tags_addr, (char *)dt_table_offset + dt_entry_ptr->offset, dt_entry_ptr->size);
Channagoud Kadabi35095622013-03-01 13:53:05 -0800640 } else {
Dima Zavin77e41f32013-03-06 16:10:43 -0800641 /*
642 * If appended dev tree is found, update the atags with
643 * memory address to the DTB appended location on RAM.
644 * Else update with the atags address in the kernel header
645 */
646 void *dtb;
647 dtb = dev_tree_appended((void*) hdr->kernel_addr,
648 (void *)hdr->tags_addr);
649 if (!dtb) {
650 dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n");
651 return -1;
652 }
Neeti Desai465491e2012-07-31 12:53:35 -0700653 }
654 #endif
Shashank Mittal162244e2011-08-08 19:01:25 -0700655 /* Make sure everything from scratch address is read before next step!*/
Shashank Mittala0032282011-08-26 14:50:11 -0700656 if(device.is_tampered)
Shashank Mittal162244e2011-08-08 19:01:25 -0700657 {
658 write_device_info_mmc(&device);
659 #ifdef TZ_TAMPER_FUSE
660 set_tamper_fuse_cmd();
661 #endif
662 }
Channagoud Kadabibf695c62012-04-10 13:31:56 +0530663 #if USE_PCOM_SECBOOT
664 set_tamper_flag(device.is_tampered);
665 #endif
Shashank Mittal23b8f422010-04-16 19:27:21 -0700666 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700667 else
668 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800669 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
670 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
671 second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask);
Shashank Mittalcd98d472011-08-02 14:29:24 -0700672
Amol Jadib6be5c12012-11-14 13:39:51 -0800673 dprintf(INFO, "Loading boot image (%d): start\n",
674 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700675 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800676
677 offset = page_size;
678
679 /* Load kernel */
680 if (mmc_read(ptn + offset, (void *)hdr->kernel_addr, kernel_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700681 dprintf(CRITICAL, "ERROR: Cannot read kernel image\n");
682 return -1;
683 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800684 offset += kernel_actual;
Shashank Mittalcd98d472011-08-02 14:29:24 -0700685
Amol Jadib6be5c12012-11-14 13:39:51 -0800686 /* Load ramdisk */
687 if(ramdisk_actual != 0)
Shashank Mittalcd98d472011-08-02 14:29:24 -0700688 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800689 if (mmc_read(ptn + offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700690 dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n");
691 return -1;
692 }
693 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800694 offset += ramdisk_actual;
695
696 dprintf(INFO, "Loading boot image (%d): done\n",
697 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700698 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Neeti Desai465491e2012-07-31 12:53:35 -0700699
700 if(hdr->second_size != 0) {
Amol Jadib6be5c12012-11-14 13:39:51 -0800701 offset += second_actual;
702 /* Second image loading not implemented. */
703 ASSERT(0);
Neeti Desai465491e2012-07-31 12:53:35 -0700704 }
705
706 #if DEVICE_TREE
707 if(hdr->dt_size != 0) {
708
709 /* Read the device tree table into buffer */
710 if(mmc_read(ptn + offset,(unsigned int *) dt_buf, page_size)) {
711 dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n");
712 return -1;
713 }
714 table = (struct dt_table*) dt_buf;
715
716 /* Restriction that the device tree entry table should be less than a page*/
717 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
718
719 /* Validate the device tree table header */
720 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
721 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
722 return -1;
723 }
724
725 /* Calculate the offset of device tree within device tree table */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700726 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
Neeti Desai465491e2012-07-31 12:53:35 -0700727 dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
728 return -1;
729 }
730
731 /* Read device device tree in the "tags_add */
Neeti Desai465491e2012-07-31 12:53:35 -0700732 if(mmc_read(ptn + offset + dt_entry_ptr->offset,
733 (void *)hdr->tags_addr, dt_entry_ptr->size)) {
734 dprintf(CRITICAL, "ERROR: Cannot read device tree\n");
735 return -1;
736 }
Channagoud Kadabi35095622013-03-01 13:53:05 -0800737 } else {
Dima Zavin77e41f32013-03-06 16:10:43 -0800738 /*
739 * If appended dev tree is found, update the atags with
740 * memory address to the DTB appended location on RAM.
741 * Else update with the atags address in the kernel header
742 */
743 void *dtb;
744 dtb = dev_tree_appended((void*) hdr->kernel_addr,
745 (void *)hdr->tags_addr);
746 if (!dtb) {
747 dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n");
748 return -1;
749 }
Neeti Desai465491e2012-07-31 12:53:35 -0700750 }
751 #endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700752 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700753
754unified_boot:
Shashank Mittal23b8f422010-04-16 19:27:21 -0700755
756 if(hdr->cmdline[0]) {
757 cmdline = (char*) hdr->cmdline;
758 } else {
759 cmdline = DEFAULT_CMDLINE;
760 }
Shashank Mittal23b8f422010-04-16 19:27:21 -0700761
Dima Zavin77e41f32013-03-06 16:10:43 -0800762 boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr,
Shashank Mittal23b8f422010-04-16 19:27:21 -0700763 (const char *)cmdline, board_machtype(),
764 (void *)hdr->ramdisk_addr, hdr->ramdisk_size);
765
766 return 0;
767}
768
Dima Zavin214cc642009-01-26 11:16:21 -0800769int boot_linux_from_flash(void)
770{
771 struct boot_img_hdr *hdr = (void*) buf;
Dima Zavin214cc642009-01-26 11:16:21 -0800772 struct ptentry *ptn;
773 struct ptable *ptable;
774 unsigned offset = 0;
775 const char *cmdline;
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800776
Shashank Mittalcd98d472011-08-02 14:29:24 -0700777 unsigned char *image_addr = 0;
778 unsigned kernel_actual;
779 unsigned ramdisk_actual;
780 unsigned imagesize_actual;
Amol Jadib6be5c12012-11-14 13:39:51 -0800781 unsigned second_actual;
Shashank Mittalcd98d472011-08-02 14:29:24 -0700782
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700783#if DEVICE_TREE
784 struct dt_table *table;
785 struct dt_entry *dt_entry_ptr;
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800786 uint32_t dt_actual;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700787#endif
788
David Ng183a7422009-12-07 14:55:21 -0800789 if (target_is_emmc_boot()) {
790 hdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR;
791 if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
792 dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
793 return -1;
794 }
795 goto continue_boot;
796 }
797
Dima Zavin214cc642009-01-26 11:16:21 -0800798 ptable = flash_get_ptable();
799 if (ptable == NULL) {
800 dprintf(CRITICAL, "ERROR: Partition table not found\n");
801 return -1;
802 }
803
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800804 if(!boot_into_recovery)
805 {
806 ptn = ptable_find(ptable, "boot");
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700807
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800808 if (ptn == NULL) {
809 dprintf(CRITICAL, "ERROR: No boot partition found\n");
810 return -1;
811 }
812 }
813 else
814 {
815 ptn = ptable_find(ptable, "recovery");
816 if (ptn == NULL) {
817 dprintf(CRITICAL, "ERROR: No recovery partition found\n");
818 return -1;
819 }
Dima Zavin214cc642009-01-26 11:16:21 -0800820 }
821
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800822 if (flash_read(ptn, offset, buf, page_size)) {
Dima Zavin214cc642009-01-26 11:16:21 -0800823 dprintf(CRITICAL, "ERROR: Cannot read boot image header\n");
824 return -1;
825 }
Dima Zavin214cc642009-01-26 11:16:21 -0800826
827 if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
Kinson Chik kchik@codeaurora.org82e4ae62011-04-12 17:42:07 -0700828 dprintf(CRITICAL, "ERROR: Invalid boot image header\n");
Dima Zavin214cc642009-01-26 11:16:21 -0800829 return -1;
830 }
831
Shashank Mittaldcc2e352009-11-19 19:11:16 -0800832 if (hdr->page_size != page_size) {
Kinson Chik kchik@codeaurora.org82e4ae62011-04-12 17:42:07 -0700833 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 -0800834 return -1;
835 }
836
Channagoud Kadabia22144f2013-03-20 11:49:01 -0700837 /*
838 * Update the kernel/ramdisk/tags address if the boot image header
839 * has default values, these default values come from mkbootimg when
840 * the boot image is flashed using fastboot flash:raw
841 */
842 update_ker_tags_rdisk_addr(hdr);
843
Deepa Dinamani0bf2f442012-10-19 11:41:06 -0700844 /* Get virtual addresses since the hdr saves physical addresses. */
845 hdr->kernel_addr = VA(hdr->kernel_addr);
846 hdr->ramdisk_addr = VA(hdr->ramdisk_addr);
847 hdr->tags_addr = VA(hdr->tags_addr);
848
Shashank Mittalcd98d472011-08-02 14:29:24 -0700849 /* Authenticate Kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700850 if(target_use_signed_kernel() && (!device.is_unlocked) && (!device.is_tampered))
Shashank Mittalcd98d472011-08-02 14:29:24 -0700851 {
852 image_addr = (unsigned char *)target_get_scratch_address();
853 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
854 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800855#if DEVICE_TREE
856 dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask);
857 imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual);
858#else
Shashank Mittalcd98d472011-08-02 14:29:24 -0700859 imagesize_actual = (page_size + kernel_actual + ramdisk_actual);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800860#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700861 offset = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700862
863 /* Assuming device rooted at this time */
Shashank Mittala0032282011-08-26 14:50:11 -0700864 device.is_tampered = 1;
Shashank Mittal162244e2011-08-08 19:01:25 -0700865
Amol Jadib6be5c12012-11-14 13:39:51 -0800866 dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700867 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800868
Shashank Mittalcd98d472011-08-02 14:29:24 -0700869 /* Read image without signature */
870 if (flash_read(ptn, offset, (void *)image_addr, imagesize_actual))
871 {
872 dprintf(CRITICAL, "ERROR: Cannot read boot image\n");
873 return -1;
874 }
Dima Zavin214cc642009-01-26 11:16:21 -0800875
Amol Jadib6be5c12012-11-14 13:39:51 -0800876 dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700877 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Amol Jadib6be5c12012-11-14 13:39:51 -0800878
Shashank Mittalcd98d472011-08-02 14:29:24 -0700879 offset = imagesize_actual;
880 /* Read signature */
881 if (flash_read(ptn, offset, (void *)(image_addr + offset), page_size))
882 {
883 dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n");
884 }
885 else
886 {
Amol Jadib6be5c12012-11-14 13:39:51 -0800887 dprintf(INFO, "Authenticating boot image (%d): start\n", imagesize_actual);
Shashank Mittalcd98d472011-08-02 14:29:24 -0700888
889 /* Verify signature */
890 auth_kernel_img = image_verify((unsigned char *)image_addr,
891 (unsigned char *)(image_addr + imagesize_actual),
892 imagesize_actual,
893 CRYPTO_AUTH_ALG_SHA256);
Shashank Mittal162244e2011-08-08 19:01:25 -0700894
Amol Jadib6be5c12012-11-14 13:39:51 -0800895 dprintf(INFO, "Authenticating boot image (%d): done\n", imagesize_actual);
896
Shashank Mittal162244e2011-08-08 19:01:25 -0700897 if(auth_kernel_img)
898 {
899 /* Authorized kernel */
Shashank Mittala0032282011-08-26 14:50:11 -0700900 device.is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -0700901 }
Shashank Mittalcd98d472011-08-02 14:29:24 -0700902 }
903
904 /* Move kernel and ramdisk to correct address */
905 memmove((void*) hdr->kernel_addr, (char *)(image_addr + page_size), hdr->kernel_size);
906 memmove((void*) hdr->ramdisk_addr, (char *)(image_addr + page_size + kernel_actual), hdr->ramdisk_size);
Deepa Dinamani7aaf83d2012-12-21 11:27:01 -0800907#if DEVICE_TREE
908 memmove((void*) hdr->tags_addr, (char *)(image_addr + page_size + kernel_actual + ramdisk_actual), hdr->dt_size);
909#endif
Shashank Mittal162244e2011-08-08 19:01:25 -0700910
911 /* Make sure everything from scratch address is read before next step!*/
Shashank Mittala0032282011-08-26 14:50:11 -0700912 if(device.is_tampered)
Shashank Mittal162244e2011-08-08 19:01:25 -0700913 {
914 write_device_info_flash(&device);
915 }
Channagoud Kadabi5c86fe32012-02-16 10:58:48 +0530916#if USE_PCOM_SECBOOT
917 set_tamper_flag(device.is_tampered);
918#endif
Shashank Mittalcd98d472011-08-02 14:29:24 -0700919 }
920 else
921 {
Shashank Mittal162244e2011-08-08 19:01:25 -0700922 offset = page_size;
923
Amol Jadib6be5c12012-11-14 13:39:51 -0800924 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
925 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
926 second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask);
927
928 dprintf(INFO, "Loading boot image (%d): start\n",
929 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700930 bs_set_timestamp(BS_KERNEL_LOAD_START);
Amol Jadib6be5c12012-11-14 13:39:51 -0800931
932 if (flash_read(ptn, offset, (void *)hdr->kernel_addr, kernel_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700933 dprintf(CRITICAL, "ERROR: Cannot read kernel image\n");
934 return -1;
935 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800936 offset += kernel_actual;
Shashank Mittalcd98d472011-08-02 14:29:24 -0700937
Amol Jadib6be5c12012-11-14 13:39:51 -0800938 if (flash_read(ptn, offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) {
Shashank Mittalcd98d472011-08-02 14:29:24 -0700939 dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n");
940 return -1;
941 }
Amol Jadib6be5c12012-11-14 13:39:51 -0800942 offset += ramdisk_actual;
943
944 dprintf(INFO, "Loading boot image (%d): done\n",
945 kernel_actual + ramdisk_actual);
Amol Jadi492d5a52013-03-15 16:12:34 -0700946 bs_set_timestamp(BS_KERNEL_LOAD_DONE);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700947
948 if(hdr->second_size != 0) {
Amol Jadib6be5c12012-11-14 13:39:51 -0800949 offset += second_actual;
950 /* Second image loading not implemented. */
951 ASSERT(0);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700952 }
953
954#if DEVICE_TREE
955 if(hdr->dt_size != 0) {
956
957 /* Read the device tree table into buffer */
958 if(flash_read(ptn, offset, (void *) dt_buf, page_size)) {
959 dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n");
960 return -1;
961 }
962
963 table = (struct dt_table*) dt_buf;
964
965 /* Restriction that the device tree entry table should be less than a page*/
966 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
967
968 /* Validate the device tree table header */
969 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
970 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
971 return -1;
972 }
973
974 /* Calculate the offset of device tree within device tree table */
975 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
976 dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
977 return -1;
978 }
979
980 /* Read device device tree in the "tags_add */
981 if(flash_read(ptn, offset + dt_entry_ptr->offset,
982 (void *)hdr->tags_addr, dt_entry_ptr->size)) {
983 dprintf(CRITICAL, "ERROR: Cannot read device tree\n");
984 return -1;
985 }
986 }
987#endif
988
Shashank Mittalcd98d472011-08-02 14:29:24 -0700989 }
David Ng183a7422009-12-07 14:55:21 -0800990continue_boot:
Dima Zavin214cc642009-01-26 11:16:21 -0800991
992 if(hdr->cmdline[0]) {
993 cmdline = (char*) hdr->cmdline;
994 } else {
995 cmdline = DEFAULT_CMDLINE;
996 }
997 dprintf(INFO, "cmdline = '%s'\n", cmdline);
998
999 /* TODO: create/pass atags to kernel */
1000
Ajay Dudanie28a6072011-07-01 13:59:46 -07001001 boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr,
Chandan Uddaraju885e4db2009-12-03 22:45:26 -08001002 (const char *)cmdline, board_machtype(),
Dima Zavin214cc642009-01-26 11:16:21 -08001003 (void *)hdr->ramdisk_addr, hdr->ramdisk_size);
1004
1005 return 0;
1006}
Brian Swetland9c4c0752009-01-25 16:23:50 -08001007
Shashank Mittal162244e2011-08-08 19:01:25 -07001008unsigned char info_buf[4096];
1009void write_device_info_mmc(device_info *dev)
1010{
1011 struct device_info *info = (void*) info_buf;
1012 unsigned long long ptn = 0;
1013 unsigned long long size;
1014 int index = INVALID_PTN;
1015
1016 index = partition_get_index("aboot");
1017 ptn = partition_get_offset(index);
1018 if(ptn == 0)
1019 {
1020 return;
1021 }
1022
1023 size = partition_get_size(index);
1024
1025 memcpy(info, dev, sizeof(device_info));
1026
1027 if(mmc_write((ptn + size - 512), 512, (void *)info_buf))
1028 {
1029 dprintf(CRITICAL, "ERROR: Cannot write device info\n");
1030 return;
1031 }
1032}
1033
1034void read_device_info_mmc(device_info *dev)
1035{
1036 struct device_info *info = (void*) info_buf;
1037 unsigned long long ptn = 0;
1038 unsigned long long size;
1039 int index = INVALID_PTN;
1040
1041 index = partition_get_index("aboot");
1042 ptn = partition_get_offset(index);
1043 if(ptn == 0)
1044 {
1045 return;
1046 }
1047
1048 size = partition_get_size(index);
1049
1050 if(mmc_read((ptn + size - 512), (void *)info_buf, 512))
1051 {
1052 dprintf(CRITICAL, "ERROR: Cannot read device info\n");
1053 return;
1054 }
1055
1056 if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE))
1057 {
1058 memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE);
1059 info->is_unlocked = 0;
Shashank Mittala0032282011-08-26 14:50:11 -07001060 info->is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -07001061
1062 write_device_info_mmc(info);
1063 }
1064 memcpy(dev, info, sizeof(device_info));
1065}
1066
1067void write_device_info_flash(device_info *dev)
1068{
1069 struct device_info *info = (void *) info_buf;
1070 struct ptentry *ptn;
1071 struct ptable *ptable;
1072
1073 ptable = flash_get_ptable();
1074 if (ptable == NULL)
1075 {
1076 dprintf(CRITICAL, "ERROR: Partition table not found\n");
1077 return;
1078 }
1079
1080 ptn = ptable_find(ptable, "devinfo");
1081 if (ptn == NULL)
1082 {
1083 dprintf(CRITICAL, "ERROR: No boot partition found\n");
1084 return;
1085 }
1086
1087 memcpy(info, dev, sizeof(device_info));
1088
1089 if (flash_write(ptn, 0, (void *)info_buf, page_size))
1090 {
1091 dprintf(CRITICAL, "ERROR: Cannot write device info\n");
1092 return;
1093 }
1094}
1095
1096void read_device_info_flash(device_info *dev)
1097{
1098 struct device_info *info = (void*) info_buf;
1099 struct ptentry *ptn;
1100 struct ptable *ptable;
1101
1102 ptable = flash_get_ptable();
1103 if (ptable == NULL)
1104 {
1105 dprintf(CRITICAL, "ERROR: Partition table not found\n");
1106 return;
1107 }
1108
1109 ptn = ptable_find(ptable, "devinfo");
1110 if (ptn == NULL)
1111 {
1112 dprintf(CRITICAL, "ERROR: No boot partition found\n");
1113 return;
1114 }
1115
1116 if (flash_read(ptn, 0, (void *)info_buf, page_size))
1117 {
1118 dprintf(CRITICAL, "ERROR: Cannot write device info\n");
1119 return;
1120 }
1121
1122 if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE))
1123 {
Shashank Mittal162244e2011-08-08 19:01:25 -07001124 memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE);
1125 info->is_unlocked = 0;
Shashank Mittala0032282011-08-26 14:50:11 -07001126 info->is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -07001127 write_device_info_flash(info);
1128 }
1129 memcpy(dev, info, sizeof(device_info));
1130}
1131
1132void write_device_info(device_info *dev)
1133{
1134 if(target_is_emmc_boot())
1135 {
1136 write_device_info_mmc(dev);
1137 }
1138 else
1139 {
1140 write_device_info_flash(dev);
1141 }
1142}
1143
1144void read_device_info(device_info *dev)
1145{
1146 if(target_is_emmc_boot())
1147 {
1148 read_device_info_mmc(dev);
1149 }
1150 else
1151 {
1152 read_device_info_flash(dev);
1153 }
1154}
1155
1156void reset_device_info()
1157{
1158 dprintf(ALWAYS, "reset_device_info called.");
Shashank Mittala0032282011-08-26 14:50:11 -07001159 device.is_tampered = 0;
Shashank Mittal162244e2011-08-08 19:01:25 -07001160 write_device_info(&device);
1161}
1162
1163void set_device_root()
1164{
1165 dprintf(ALWAYS, "set_device_root called.");
Shashank Mittala0032282011-08-26 14:50:11 -07001166 device.is_tampered = 1;
Shashank Mittal162244e2011-08-08 19:01:25 -07001167 write_device_info(&device);
1168}
1169
Amol Jadicb524072012-08-09 16:40:18 -07001170#if DEVICE_TREE
1171int copy_dtb(uint8_t *boot_image_start)
1172{
1173 uint32 dt_image_offset = 0;
1174 uint32_t n;
1175 struct dt_table *table;
1176 struct dt_entry *dt_entry_ptr;
Amol Jadicb524072012-08-09 16:40:18 -07001177
1178 struct boot_img_hdr *hdr = (struct boot_img_hdr *) (boot_image_start);
1179
Amol Jadicb524072012-08-09 16:40:18 -07001180 if(hdr->dt_size != 0) {
1181
1182 /* add kernel offset */
1183 dt_image_offset += page_size;
1184 n = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
1185 dt_image_offset += n;
1186
1187 /* add ramdisk offset */
1188 n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
1189 dt_image_offset += n;
1190
1191 /* add second offset */
1192 if(hdr->second_size != 0) {
1193 n = ROUND_TO_PAGE(hdr->second_size, page_mask);
1194 dt_image_offset += n;
1195 }
1196
1197 /* offset now point to start of dt.img */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001198 table = (struct dt_table*)(boot_image_start + dt_image_offset);
Amol Jadicb524072012-08-09 16:40:18 -07001199
1200 /* Restriction that the device tree entry table should be less than a page*/
1201 ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size);
1202
1203 /* Validate the device tree table header */
1204 if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) {
1205 dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n");
1206 return -1;
1207 }
1208
1209 /* Calculate the offset of device tree within device tree table */
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07001210 if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){
Amol Jadicb524072012-08-09 16:40:18 -07001211 dprintf(CRITICAL, "ERROR: Getting device tree address failed\n");
1212 return -1;
1213 }
1214
1215 /* Read device device tree in the "tags_add */
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001216 memmove((void*) hdr->tags_addr,
1217 boot_image_start + dt_image_offset + dt_entry_ptr->offset,
1218 dt_entry_ptr->size);
Channagoud Kadabi35095622013-03-01 13:53:05 -08001219 } else {
1220 /*
Dima Zavin77e41f32013-03-06 16:10:43 -08001221 * If appended dev tree is found, update the atags with
1222 * memory address to the DTB appended location on RAM.
1223 * Else update with the atags address in the kernel header
Channagoud Kadabi35095622013-03-01 13:53:05 -08001224 */
Dima Zavin77e41f32013-03-06 16:10:43 -08001225 void *dtb;
1226 dtb = dev_tree_appended((void *)hdr->kernel_addr,
1227 (void *)hdr->tags_addr);
1228 if (!dtb) {
Channagoud Kadabi35095622013-03-01 13:53:05 -08001229 dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n");
1230 return -1;
1231 }
Amol Jadicb524072012-08-09 16:40:18 -07001232 }
1233
1234 /* Everything looks fine. Return success. */
1235 return 0;
1236}
1237#endif
1238
Brian Swetland9c4c0752009-01-25 16:23:50 -08001239void cmd_boot(const char *arg, void *data, unsigned sz)
1240{
1241 unsigned kernel_actual;
1242 unsigned ramdisk_actual;
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001243 struct boot_img_hdr *hdr;
Brian Swetland9c4c0752009-01-25 16:23:50 -08001244 char *ptr = ((char*) data);
1245
1246 if (sz < sizeof(hdr)) {
1247 fastboot_fail("invalid bootimage header");
1248 return;
1249 }
1250
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001251 hdr = (struct boot_img_hdr *)data;
Brian Swetland9c4c0752009-01-25 16:23:50 -08001252
1253 /* ensure commandline is terminated */
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001254 hdr->cmdline[BOOT_ARGS_SIZE-1] = 0;
Brian Swetland9c4c0752009-01-25 16:23:50 -08001255
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001256 if(target_is_emmc_boot() && hdr->page_size) {
1257 page_size = hdr->page_size;
Subbaraman Narayanamurthyfbe13a02010-09-10 11:51:12 -07001258 page_mask = page_size - 1;
1259 }
1260
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001261 kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask);
1262 ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask);
1263
Channagoud Kadabia22144f2013-03-20 11:49:01 -07001264 /*
1265 * Update the kernel/ramdisk/tags address if the boot image header
1266 * has default values, these default values come from mkbootimg when
1267 * the boot image is flashed using fastboot flash:raw
1268 */
1269 update_ker_tags_rdisk_addr(hdr);
Dima Zavin3cadfff2013-03-21 14:30:48 -07001270
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001271 /* Get virtual addresses since the hdr saves physical addresses. */
1272 hdr->kernel_addr = VA(hdr->kernel_addr);
1273 hdr->ramdisk_addr = VA(hdr->ramdisk_addr);
1274 hdr->tags_addr = VA(hdr->tags_addr);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001275
Shashank Mittal1f0e2662011-09-01 15:06:00 -07001276 /* sz should have atleast raw boot image */
1277 if (page_size + kernel_actual + ramdisk_actual > sz) {
Brian Swetland9c4c0752009-01-25 16:23:50 -08001278 fastboot_fail("incomplete bootimage");
1279 return;
1280 }
1281
Dima Zavin77e41f32013-03-06 16:10:43 -08001282 memmove((void*) hdr->kernel_addr, ptr + page_size, hdr->kernel_size);
1283 memmove((void*) hdr->ramdisk_addr, ptr + page_size + kernel_actual, hdr->ramdisk_size);
1284
Amol Jadicb524072012-08-09 16:40:18 -07001285#if DEVICE_TREE
1286 /* find correct dtb and copy it to right location */
1287 if(copy_dtb(data))
1288 {
1289 fastboot_fail("dtb not found");
1290 return;
1291 }
1292#endif
Brian Swetland9c4c0752009-01-25 16:23:50 -08001293
1294 fastboot_okay("");
1295 udc_stop();
1296
Dima Zavin77e41f32013-03-06 16:10:43 -08001297 boot_linux((void*) hdr->kernel_addr, (void*) hdr->tags_addr,
Deepa Dinamani0bf2f442012-10-19 11:41:06 -07001298 (const char*) hdr->cmdline, board_machtype(),
1299 (void*) hdr->ramdisk_addr, hdr->ramdisk_size);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001300}
1301
Dima Zavin214cc642009-01-26 11:16:21 -08001302void cmd_erase(const char *arg, void *data, unsigned sz)
1303{
1304 struct ptentry *ptn;
1305 struct ptable *ptable;
1306
1307 ptable = flash_get_ptable();
1308 if (ptable == NULL) {
1309 fastboot_fail("partition table doesn't exist");
1310 return;
1311 }
1312
1313 ptn = ptable_find(ptable, arg);
1314 if (ptn == NULL) {
1315 fastboot_fail("unknown partition name");
1316 return;
1317 }
1318
1319 if (flash_erase(ptn)) {
1320 fastboot_fail("failed to erase partition");
1321 return;
1322 }
1323 fastboot_okay("");
1324}
1325
Bikas Gurungd48bd242010-09-04 19:54:32 -07001326
1327void cmd_erase_mmc(const char *arg, void *data, unsigned sz)
1328{
1329 unsigned long long ptn = 0;
neetidb4b24d62012-01-20 12:13:09 -08001330 unsigned int out[512] = {0};
Kinson Chikf1a43512011-07-14 11:28:39 -07001331 int index = INVALID_PTN;
Bikas Gurungd48bd242010-09-04 19:54:32 -07001332
Kinson Chikf1a43512011-07-14 11:28:39 -07001333 index = partition_get_index(arg);
1334 ptn = partition_get_offset(index);
Neeti Desaica8c9602011-10-06 11:40:00 -07001335
Kinson Chikf1a43512011-07-14 11:28:39 -07001336 if(ptn == 0) {
Neeti Desaica8c9602011-10-06 11:40:00 -07001337 fastboot_fail("Partition table doesn't exist\n");
Bikas Gurungd48bd242010-09-04 19:54:32 -07001338 return;
1339 }
neetidb4b24d62012-01-20 12:13:09 -08001340 /* Simple inefficient version of erase. Just writing
1341 0 in first block */
1342 if (mmc_write(ptn , 512, (unsigned int *)out)) {
1343 fastboot_fail("failed to erase partition");
Bikas Gurungd48bd242010-09-04 19:54:32 -07001344 return;
1345 }
1346 fastboot_okay("");
1347}
1348
1349
Ajay Dudani5c761132011-04-07 20:19:04 -07001350void cmd_flash_mmc_img(const char *arg, void *data, unsigned sz)
Shashank Mittal23b8f422010-04-16 19:27:21 -07001351{
1352 unsigned long long ptn = 0;
Subbaraman Narayanamurthyc95b5b12010-08-31 13:19:48 -07001353 unsigned long long size = 0;
Kinson Chikf1a43512011-07-14 11:28:39 -07001354 int index = INVALID_PTN;
Subbaraman Narayanamurthyc95b5b12010-08-31 13:19:48 -07001355
Greg Grisco6e754772011-06-23 12:19:39 -07001356 if (!strcmp(arg, "partition"))
1357 {
1358 dprintf(INFO, "Attempt to write partition image.\n");
Neeti Desai5f26aff2011-09-30 10:27:40 -07001359 if (write_partition(sz, (unsigned char *) data)) {
Greg Grisco6e754772011-06-23 12:19:39 -07001360 fastboot_fail("failed to write partition");
Shashank Mittal23b8f422010-04-16 19:27:21 -07001361 return;
1362 }
1363 }
Greg Grisco6e754772011-06-23 12:19:39 -07001364 else
1365 {
Kinson Chikf1a43512011-07-14 11:28:39 -07001366 index = partition_get_index(arg);
1367 ptn = partition_get_offset(index);
Greg Grisco6e754772011-06-23 12:19:39 -07001368 if(ptn == 0) {
1369 fastboot_fail("partition table doesn't exist");
1370 return;
1371 }
Shashank Mittal23b8f422010-04-16 19:27:21 -07001372
Greg Grisco6e754772011-06-23 12:19:39 -07001373 if (!strcmp(arg, "boot") || !strcmp(arg, "recovery")) {
1374 if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
1375 fastboot_fail("image is not a boot image");
1376 return;
1377 }
1378 }
Subbaraman Narayanamurthyc95b5b12010-08-31 13:19:48 -07001379
Kinson Chikf1a43512011-07-14 11:28:39 -07001380 size = partition_get_size(index);
Greg Grisco6e754772011-06-23 12:19:39 -07001381 if (ROUND_TO_PAGE(sz,511) > size) {
1382 fastboot_fail("size too large");
1383 return;
1384 }
1385 else if (mmc_write(ptn , sz, (unsigned int *)data)) {
1386 fastboot_fail("flash write failure");
1387 return;
1388 }
Shashank Mittal23b8f422010-04-16 19:27:21 -07001389 }
1390 fastboot_okay("");
1391 return;
1392}
1393
Ajay Dudani5c761132011-04-07 20:19:04 -07001394void cmd_flash_mmc_sparse_img(const char *arg, void *data, unsigned sz)
1395{
1396 unsigned int chunk;
1397 unsigned int chunk_data_sz;
1398 sparse_header_t *sparse_header;
1399 chunk_header_t *chunk_header;
Ajay Dudaniab18f022011-05-12 14:39:22 -07001400 uint32_t total_blocks = 0;
Ajay Dudani5c761132011-04-07 20:19:04 -07001401 unsigned long long ptn = 0;
Channagoud Kadabi65b91002011-10-11 17:34:33 +05301402 unsigned long long size = 0;
Kinson Chikf1a43512011-07-14 11:28:39 -07001403 int index = INVALID_PTN;
Ajay Dudani5c761132011-04-07 20:19:04 -07001404
Kinson Chikf1a43512011-07-14 11:28:39 -07001405 index = partition_get_index(arg);
1406 ptn = partition_get_offset(index);
1407 if(ptn == 0) {
Ajay Dudani5c761132011-04-07 20:19:04 -07001408 fastboot_fail("partition table doesn't exist");
1409 return;
1410 }
1411
Channagoud Kadabi65b91002011-10-11 17:34:33 +05301412 size = partition_get_size(index);
1413 if (ROUND_TO_PAGE(sz,511) > size) {
1414 fastboot_fail("size too large");
1415 return;
1416 }
1417
Ajay Dudani5c761132011-04-07 20:19:04 -07001418 /* Read and skip over sparse image header */
1419 sparse_header = (sparse_header_t *) data;
1420 data += sparse_header->file_hdr_sz;
1421 if(sparse_header->file_hdr_sz > sizeof(sparse_header_t))
1422 {
1423 /* Skip the remaining bytes in a header that is longer than
1424 * we expected.
1425 */
1426 data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t));
1427 }
1428
Ajay Dudanib06c05f2011-05-12 14:46:10 -07001429 dprintf (SPEW, "=== Sparse Image Header ===\n");
1430 dprintf (SPEW, "magic: 0x%x\n", sparse_header->magic);
1431 dprintf (SPEW, "major_version: 0x%x\n", sparse_header->major_version);
1432 dprintf (SPEW, "minor_version: 0x%x\n", sparse_header->minor_version);
1433 dprintf (SPEW, "file_hdr_sz: %d\n", sparse_header->file_hdr_sz);
1434 dprintf (SPEW, "chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz);
1435 dprintf (SPEW, "blk_sz: %d\n", sparse_header->blk_sz);
1436 dprintf (SPEW, "total_blks: %d\n", sparse_header->total_blks);
1437 dprintf (SPEW, "total_chunks: %d\n", sparse_header->total_chunks);
Ajay Dudani5c761132011-04-07 20:19:04 -07001438
1439 /* Start processing chunks */
1440 for (chunk=0; chunk<sparse_header->total_chunks; chunk++)
1441 {
1442 /* Read and skip over chunk header */
1443 chunk_header = (chunk_header_t *) data;
1444 data += sizeof(chunk_header_t);
1445
1446 dprintf (SPEW, "=== Chunk Header ===\n");
1447 dprintf (SPEW, "chunk_type: 0x%x\n", chunk_header->chunk_type);
1448 dprintf (SPEW, "chunk_data_sz: 0x%x\n", chunk_header->chunk_sz);
1449 dprintf (SPEW, "total_size: 0x%x\n", chunk_header->total_sz);
1450
1451 if(sparse_header->chunk_hdr_sz > sizeof(chunk_header_t))
1452 {
1453 /* Skip the remaining bytes in a header that is longer than
1454 * we expected.
1455 */
1456 data += (sparse_header->chunk_hdr_sz - sizeof(chunk_header_t));
1457 }
1458
1459 chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz;
1460 switch (chunk_header->chunk_type)
1461 {
1462 case CHUNK_TYPE_RAW:
1463 if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz +
1464 chunk_data_sz))
1465 {
1466 fastboot_fail("Bogus chunk size for chunk type Raw");
1467 return;
1468 }
1469
Ajay Dudaniab18f022011-05-12 14:39:22 -07001470 if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz),
1471 chunk_data_sz,
1472 (unsigned int*)data))
Ajay Dudani5c761132011-04-07 20:19:04 -07001473 {
1474 fastboot_fail("flash write failure");
1475 return;
1476 }
1477 total_blocks += chunk_header->chunk_sz;
1478 data += chunk_data_sz;
1479 break;
1480
1481 case CHUNK_TYPE_DONT_CARE:
Kinson Chik kchik@codeaurora.orgda29b1e2011-05-06 17:36:39 -07001482 total_blocks += chunk_header->chunk_sz;
1483 break;
1484
Ajay Dudani5c761132011-04-07 20:19:04 -07001485 case CHUNK_TYPE_CRC:
1486 if(chunk_header->total_sz != sparse_header->chunk_hdr_sz)
1487 {
1488 fastboot_fail("Bogus chunk size for chunk type Dont Care");
1489 return;
1490 }
1491 total_blocks += chunk_header->chunk_sz;
1492 data += chunk_data_sz;
1493 break;
1494
Kinson Chik kchik@codeaurora.orgda29b1e2011-05-06 17:36:39 -07001495 default:
Ajay Dudani5c761132011-04-07 20:19:04 -07001496 fastboot_fail("Unknown chunk type");
1497 return;
1498 }
1499 }
1500
Ajay Dudani0c6927b2011-05-18 11:12:16 -07001501 dprintf(INFO, "Wrote %d blocks, expected to write %d blocks\n",
1502 total_blocks, sparse_header->total_blks);
1503
1504 if(total_blocks != sparse_header->total_blks)
1505 {
1506 fastboot_fail("sparse image write failure");
1507 }
Ajay Dudani5c761132011-04-07 20:19:04 -07001508
1509 fastboot_okay("");
1510 return;
1511}
1512
1513void cmd_flash_mmc(const char *arg, void *data, unsigned sz)
1514{
1515 sparse_header_t *sparse_header;
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001516 /* 8 Byte Magic + 2048 Byte xml + Encrypted Data */
1517 unsigned int *magic_number = (unsigned int *) data;
Ajay Dudani5c761132011-04-07 20:19:04 -07001518
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001519#ifdef SSD_ENABLE
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001520 int ret=0;
1521 uint32 major_version=0;
1522 uint32 minor_version=0;
1523
1524 ret = scm_svc_version(&major_version,&minor_version);
1525 if(!ret)
1526 {
1527 if(major_version >= 2)
1528 {
1529 if( !strcmp(arg,"ssd") || !strcmp(arg,"tqs") )
1530 {
1531 ret = encrypt_scm((uint32 **) &data, &sz);
1532 if (ret != 0) {
1533 dprintf(CRITICAL, "ERROR: Encryption Failure\n");
1534 return;
1535 }
1536
1537 ret = scm_protect_keystore((uint32 *) data, sz);
1538 if (ret != 0) {
1539 dprintf(CRITICAL, "ERROR: scm_protect_keystore Failed\n");
1540 return;
1541 }
1542 }
1543 else
1544 {
1545 ret = decrypt_scm_v2((uint32 **) &data, &sz);
1546 if(ret != 0)
1547 {
1548 dprintf(CRITICAL,"ERROR: Decryption Failure\n");
1549 return;
1550 }
1551 }
1552 }
1553 else
1554 {
1555 if (magic_number[0] == DECRYPT_MAGIC_0 &&
1556 magic_number[1] == DECRYPT_MAGIC_1)
1557 {
1558 ret = decrypt_scm((uint32 **) &data, &sz);
1559 if (ret != 0) {
1560 dprintf(CRITICAL, "ERROR: Invalid secure image\n");
1561 return;
1562 }
1563 }
1564 else if (magic_number[0] == ENCRYPT_MAGIC_0 &&
1565 magic_number[1] == ENCRYPT_MAGIC_1)
1566 {
1567 ret = encrypt_scm((uint32 **) &data, &sz);
1568 if (ret != 0) {
1569 dprintf(CRITICAL, "ERROR: Encryption Failure\n");
1570 return;
1571 }
1572 }
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001573 }
1574 }
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001575 else
Neeti Desai127b9e02012-03-20 16:11:23 -07001576 {
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001577 dprintf(CRITICAL,"INVALID SVC Version\n");
1578 return;
Neeti Desai127b9e02012-03-20 16:11:23 -07001579 }
sundarajan srinivasand4b1c482013-02-27 14:15:43 -08001580#endif /* SSD_ENABLE */
Neeti Desai127b9e02012-03-20 16:11:23 -07001581
kchik@codeaurora.orgbce18ea2011-04-18 20:22:28 -07001582 sparse_header = (sparse_header_t *) data;
Ajay Dudani5c761132011-04-07 20:19:04 -07001583 if (sparse_header->magic != SPARSE_HEADER_MAGIC)
1584 cmd_flash_mmc_img(arg, data, sz);
1585 else
1586 cmd_flash_mmc_sparse_img(arg, data, sz);
Ajay Dudani5c761132011-04-07 20:19:04 -07001587 return;
1588}
1589
Dima Zavin214cc642009-01-26 11:16:21 -08001590void cmd_flash(const char *arg, void *data, unsigned sz)
1591{
1592 struct ptentry *ptn;
1593 struct ptable *ptable;
1594 unsigned extra = 0;
1595
1596 ptable = flash_get_ptable();
1597 if (ptable == NULL) {
1598 fastboot_fail("partition table doesn't exist");
1599 return;
1600 }
1601
1602 ptn = ptable_find(ptable, arg);
1603 if (ptn == NULL) {
1604 fastboot_fail("unknown partition name");
1605 return;
1606 }
1607
1608 if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) {
1609 if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) {
1610 fastboot_fail("image is not a boot image");
1611 return;
1612 }
1613 }
1614
Amol Jadi5c61a952012-05-04 17:05:35 -07001615 if (!strcmp(ptn->name, "system")
Deepa Dinamani13e32c42012-03-12 14:34:17 -07001616 || !strcmp(ptn->name, "userdata")
1617 || !strcmp(ptn->name, "persist")
1618 || !strcmp(ptn->name, "recoveryfs")) {
Channagoud Kadabi404a7062011-03-21 19:27:50 +05301619 if (flash_ecc_bch_enabled())
1620 /* Spare data bytes for 8 bit ECC increased by 4 */
1621 extra = ((page_size >> 9) * 20);
1622 else
1623 extra = ((page_size >> 9) * 16);
1624 } else
Shashank Mittaldcc2e352009-11-19 19:11:16 -08001625 sz = ROUND_TO_PAGE(sz, page_mask);
Dima Zavin214cc642009-01-26 11:16:21 -08001626
1627 dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name);
1628 if (flash_write(ptn, extra, data, sz)) {
1629 fastboot_fail("flash write failure");
1630 return;
1631 }
1632 dprintf(INFO, "partition '%s' updated\n", ptn->name);
1633 fastboot_okay("");
1634}
1635
1636void cmd_continue(const char *arg, void *data, unsigned sz)
1637{
1638 fastboot_okay("");
1639 udc_stop();
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001640 if (target_is_emmc_boot())
1641 {
1642 boot_linux_from_mmc();
1643 }
1644 else
1645 {
1646 boot_linux_from_flash();
1647 }
Dima Zavin214cc642009-01-26 11:16:21 -08001648}
1649
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001650void cmd_reboot(const char *arg, void *data, unsigned sz)
1651{
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001652 dprintf(INFO, "rebooting the device\n");
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001653 fastboot_okay("");
1654 reboot_device(0);
1655}
1656
1657void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz)
1658{
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001659 dprintf(INFO, "rebooting the device\n");
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001660 fastboot_okay("");
1661 reboot_device(FASTBOOT_MODE);
1662}
1663
Shashank Mittal162244e2011-08-08 19:01:25 -07001664void cmd_oem_unlock(const char *arg, void *data, unsigned sz)
1665{
1666 if(!device.is_unlocked)
1667 {
1668 device.is_unlocked = 1;
1669 write_device_info(&device);
1670 }
1671 fastboot_okay("");
1672}
1673
Shashank Mittala0032282011-08-26 14:50:11 -07001674void cmd_oem_devinfo(const char *arg, void *data, unsigned sz)
1675{
1676 char response[64];
1677 snprintf(response, 64, "\tDevice tampered: %s", (device.is_tampered ? "true" : "false"));
1678 fastboot_info(response);
1679 snprintf(response, 64, "\tDevice unlocked: %s", (device.is_unlocked ? "true" : "false"));
1680 fastboot_info(response);
1681 fastboot_okay("");
1682}
1683
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001684void splash_screen ()
1685{
1686 struct ptentry *ptn;
1687 struct ptable *ptable;
1688 struct fbcon_config *fb_display = NULL;
1689
1690 if (!target_is_emmc_boot())
1691 {
1692 ptable = flash_get_ptable();
1693 if (ptable == NULL) {
1694 dprintf(CRITICAL, "ERROR: Partition table not found\n");
Greg Griscod6250552011-06-29 14:40:23 -07001695 return;
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001696 }
1697
1698 ptn = ptable_find(ptable, "splash");
1699 if (ptn == NULL) {
1700 dprintf(CRITICAL, "ERROR: No splash partition found\n");
1701 } else {
1702 fb_display = fbcon_display();
1703 if (fb_display) {
1704 if (flash_read(ptn, 0, fb_display->base,
1705 (fb_display->width * fb_display->height * fb_display->bpp/8))) {
1706 fbcon_clear();
1707 dprintf(CRITICAL, "ERROR: Cannot read splash image\n");
1708 }
1709 }
1710 }
1711 }
1712}
1713
Brian Swetland9c4c0752009-01-25 16:23:50 -08001714void aboot_init(const struct app_descriptor *app)
1715{
Shashank Mittal4f99a882010-02-01 13:58:50 -08001716 unsigned reboot_mode = 0;
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001717 unsigned usb_init = 0;
Vivek Mehta5f1c9d42011-04-01 20:11:59 -07001718 unsigned sz = 0;
Chandan Uddarajubedca152010-06-02 23:05:15 -07001719
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001720 /* Setup page size information for nand/emmc reads */
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001721 if (target_is_emmc_boot())
1722 {
1723 page_size = 2048;
1724 page_mask = page_size - 1;
1725 }
1726 else
1727 {
1728 page_size = flash_page_size();
1729 page_mask = page_size - 1;
1730 }
1731
Shashank Mittal162244e2011-08-08 19:01:25 -07001732 if(target_use_signed_kernel())
1733 {
1734 read_device_info(&device);
1735
Shashank Mittal162244e2011-08-08 19:01:25 -07001736 }
1737
Greg Griscod6250552011-06-29 14:40:23 -07001738 target_serialno((unsigned char *) sn_buf);
Ajay Dudanib06c05f2011-05-12 14:46:10 -07001739 dprintf(SPEW,"serial number: %s\n",sn_buf);
Subbaraman Narayanamurthyf17b4ae2011-02-16 20:19:56 -08001740 surf_udc_device.serialno = sn_buf;
1741
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001742 /* Check if we should do something other than booting up */
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001743 if (keys_get_state(KEY_HOME) != 0)
1744 boot_into_recovery = 1;
Wentao Xu153902c2010-12-20 16:20:52 -05001745 if (keys_get_state(KEY_VOLUMEUP) != 0)
1746 boot_into_recovery = 1;
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -07001747 if(!boot_into_recovery)
1748 {
1749 if (keys_get_state(KEY_BACK) != 0)
1750 goto fastboot;
1751 if (keys_get_state(KEY_VOLUMEDOWN) != 0)
1752 goto fastboot;
1753 }
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001754
1755 #if NO_KEYPAD_DRIVER
Kinson Chik0b1c8162011-08-31 16:31:57 -07001756 if (fastboot_trigger())
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001757 goto fastboot;
1758 #endif
Chandan Uddarajubedca152010-06-02 23:05:15 -07001759
Ajay Dudani77421292010-10-27 19:34:06 -07001760 reboot_mode = check_reboot_mode();
1761 if (reboot_mode == RECOVERY_MODE) {
1762 boot_into_recovery = 1;
1763 } else if(reboot_mode == FASTBOOT_MODE) {
1764 goto fastboot;
1765 }
1766
Shashank Mittal23b8f422010-04-16 19:27:21 -07001767 if (target_is_emmc_boot())
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001768 {
Subbaraman Narayanamurthy0e445b02011-06-19 21:34:46 -07001769 if(emmc_recovery_init())
1770 dprintf(ALWAYS,"error in emmc_recovery_init\n");
Shashank Mittala0032282011-08-26 14:50:11 -07001771 if(target_use_signed_kernel())
1772 {
1773 if((device.is_unlocked) || (device.is_tampered))
1774 {
1775 #ifdef TZ_TAMPER_FUSE
1776 set_tamper_fuse_cmd();
1777 #endif
Channagoud Kadabibf695c62012-04-10 13:31:56 +05301778 #if USE_PCOM_SECBOOT
1779 set_tamper_flag(device.is_tampered);
1780 #endif
Shashank Mittala0032282011-08-26 14:50:11 -07001781 }
1782 }
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001783 boot_linux_from_mmc();
1784 }
1785 else
1786 {
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001787 recovery_init();
Channagoud Kadabie7b66702012-03-22 15:54:30 +05301788#if USE_PCOM_SECBOOT
1789 if((device.is_unlocked) || (device.is_tampered))
1790 set_tamper_flag(device.is_tampered);
1791#endif
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001792 boot_linux_from_flash();
1793 }
Dima Zavinb4283602009-01-26 16:36:57 -08001794 dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting "
1795 "to fastboot mode.\n");
1796
1797fastboot:
Chandan Uddaraju2943fd62010-06-21 10:56:39 -07001798
Shashank Mittal162244e2011-08-08 19:01:25 -07001799 target_fastboot_init();
Amol Jadi57abe4c2011-05-24 15:47:27 -07001800
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001801 if(!usb_init)
1802 udc_init(&surf_udc_device);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001803
1804 fastboot_register("boot", cmd_boot);
Bikas Gurungd48bd242010-09-04 19:54:32 -07001805
Shashank Mittal23b8f422010-04-16 19:27:21 -07001806 if (target_is_emmc_boot())
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001807 {
1808 fastboot_register("flash:", cmd_flash_mmc);
Bikas Gurungd48bd242010-09-04 19:54:32 -07001809 fastboot_register("erase:", cmd_erase_mmc);
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001810 }
1811 else
1812 {
1813 fastboot_register("flash:", cmd_flash);
Bikas Gurungd48bd242010-09-04 19:54:32 -07001814 fastboot_register("erase:", cmd_erase);
Shashank Mittald8c42bf2010-06-09 15:44:28 -07001815 }
1816
1817 fastboot_register("continue", cmd_continue);
Chandan Uddaraju94183c02010-01-15 15:13:59 -08001818 fastboot_register("reboot", cmd_reboot);
1819 fastboot_register("reboot-bootloader", cmd_reboot_bootloader);
Shashank Mittal162244e2011-08-08 19:01:25 -07001820 fastboot_register("oem unlock", cmd_oem_unlock);
Shashank Mittala0032282011-08-26 14:50:11 -07001821 fastboot_register("oem device-info", cmd_oem_devinfo);
Subbaraman Narayanamurthyeb92bcc2010-07-20 14:32:46 -07001822 fastboot_publish("product", TARGET(BOARD));
Brian Swetland9c4c0752009-01-25 16:23:50 -08001823 fastboot_publish("kernel", "lk");
Trevor Bourget59b25d52012-01-13 18:43:36 -08001824 fastboot_publish("serialno", sn_buf);
Kinson Chikf1a43512011-07-14 11:28:39 -07001825 partition_dump();
Vivek Mehta5f1c9d42011-04-01 20:11:59 -07001826 sz = target_get_max_flash_size();
1827 fastboot_init(target_get_scratch_address(), sz);
Brian Swetland9c4c0752009-01-25 16:23:50 -08001828 udc_start();
Brian Swetland9c4c0752009-01-25 16:23:50 -08001829}
1830
1831APP_START(aboot)
1832 .init = aboot_init,
1833APP_END