Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2013, The Linux Foundation. All rights reserved. |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 6 | * |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 7 | * 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 Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 14 | * * Neither the name of The Linux Foundation nor |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 15 | * 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 Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <app.h> |
| 34 | #include <debug.h> |
| 35 | #include <arch/arm.h> |
| 36 | #include <dev/udc.h> |
| 37 | #include <string.h> |
Channagoud Kadabi | 132ff55 | 2013-04-19 14:34:44 -0700 | [diff] [blame] | 38 | #include <stdlib.h> |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 39 | #include <kernel/thread.h> |
| 40 | #include <arch/ops.h> |
| 41 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 42 | #include <dev/flash.h> |
| 43 | #include <lib/ptable.h> |
Dima Zavin | b428360 | 2009-01-26 16:36:57 -0800 | [diff] [blame] | 44 | #include <dev/keys.h> |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 45 | #include <dev/fbcon.h> |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 46 | #include <baseband.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 47 | #include <target.h> |
| 48 | #include <mmc.h> |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 49 | #include <partition_parser.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 50 | #include <platform.h> |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 51 | #include <crypto_hash.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 52 | #include <malloc.h> |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 53 | #include <boot_stats.h> |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 54 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 55 | #if DEVICE_TREE |
| 56 | #include <libfdt.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 57 | #include <dev_tree.h> |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 58 | #endif |
| 59 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 60 | #include "image_verify.h" |
Shashank Mittal | 024c033 | 2010-02-03 11:44:00 -0800 | [diff] [blame] | 61 | #include "recovery.h" |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 62 | #include "bootimg.h" |
| 63 | #include "fastboot.h" |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 64 | #include "sparse_format.h" |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 65 | #include "mmc.h" |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 66 | #include "devinfo.h" |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 67 | #include "board.h" |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 68 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 69 | #include "scm.h" |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 70 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 71 | extern bool target_use_signed_kernel(void); |
| 72 | extern void dsb(); |
| 73 | extern void isb(); |
| 74 | extern void platform_uninit(void); |
| 75 | |
| 76 | void write_device_info_mmc(device_info *dev); |
| 77 | void write_device_info_flash(device_info *dev); |
| 78 | |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 79 | #define EXPAND(NAME) #NAME |
| 80 | #define TARGET(NAME) EXPAND(NAME) |
Brian Swetland | 2defe16 | 2009-08-18 14:35:59 -0700 | [diff] [blame] | 81 | |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 82 | #ifdef MEMBASE |
| 83 | #define EMMC_BOOT_IMG_HEADER_ADDR (0xFF000+(MEMBASE)) |
| 84 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 85 | #define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000 |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 86 | #endif |
| 87 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 88 | #define RECOVERY_MODE 0x77665502 |
| 89 | #define FASTBOOT_MODE 0x77665500 |
| 90 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 91 | static const char *emmc_cmdline = " androidboot.emmc=true"; |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 92 | static const char *usb_sn_cmdline = " androidboot.serialno="; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 93 | static const char *androidboot_mode = " androidboot.mode="; |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 94 | static const char *loglevel = " quiet"; |
Ajay Dudani | ca3a33c | 2011-11-18 08:31:40 -0800 | [diff] [blame] | 95 | static const char *battchg_pause = " androidboot.mode=charger"; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 96 | static const char *auth_kernel = " androidboot.authorized_kernel=true"; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 97 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 98 | static const char *baseband_apq = " androidboot.baseband=apq"; |
| 99 | static const char *baseband_msm = " androidboot.baseband=msm"; |
| 100 | static const char *baseband_csfb = " androidboot.baseband=csfb"; |
| 101 | static const char *baseband_svlte2a = " androidboot.baseband=svlte2a"; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 102 | static const char *baseband_mdm = " androidboot.baseband=mdm"; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 103 | static const char *baseband_sglte = " androidboot.baseband=sglte"; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 104 | static const char *baseband_dsda = " androidboot.baseband=dsda"; |
| 105 | static const char *baseband_dsda2 = " androidboot.baseband=dsda2"; |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 106 | static const char *baseband_sglte2 = " androidboot.baseband=sglte2"; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 107 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 108 | /* Assuming unauthorized kernel image by default */ |
| 109 | static int auth_kernel_img = 0; |
| 110 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 111 | static device_info device = {DEVICE_MAGIC, 0, 0}; |
| 112 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 113 | static struct udc_device surf_udc_device = { |
| 114 | .vendor_id = 0x18d1, |
Chandan Uddaraju | c53a1a1 | 2009-11-18 14:53:40 -0800 | [diff] [blame] | 115 | .product_id = 0xD00D, |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 116 | .version_id = 0x0100, |
| 117 | .manufacturer = "Google", |
| 118 | .product = "Android", |
| 119 | }; |
| 120 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 121 | struct atag_ptbl_entry |
| 122 | { |
| 123 | char name[16]; |
| 124 | unsigned offset; |
| 125 | unsigned size; |
| 126 | unsigned flags; |
| 127 | }; |
| 128 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 129 | /* |
| 130 | * Partition info, required to be published |
| 131 | * for fastboot |
| 132 | */ |
| 133 | struct getvar_partition_info { |
| 134 | const char part_name[MAX_GPT_NAME_SIZE]; /* Partition name */ |
| 135 | char getvar_size[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for size */ |
| 136 | char getvar_type[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for type */ |
| 137 | char size_response[MAX_RSP_SIZE]; /* fastboot response for size */ |
| 138 | char type_response[MAX_RSP_SIZE]; /* fastboot response for type */ |
| 139 | }; |
| 140 | |
| 141 | /* |
| 142 | * Right now, we are publishing the info for only |
| 143 | * three partitions |
| 144 | */ |
| 145 | struct getvar_partition_info part_info[] = |
| 146 | { |
| 147 | { "system" , "partition-size:", "partition-type:", "", "ext4" }, |
| 148 | { "userdata", "partition-size:", "partition-type:", "", "ext4" }, |
| 149 | { "cache" , "partition-size:", "partition-type:", "", "ext4" }, |
| 150 | }; |
| 151 | |
| 152 | char max_download_size[MAX_RSP_SIZE]; |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 153 | char sn_buf[13]; |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 154 | |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 155 | extern int emmc_recovery_init(void); |
| 156 | |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 157 | #if NO_KEYPAD_DRIVER |
| 158 | extern int fastboot_trigger(void); |
| 159 | #endif |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 160 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 161 | static void update_ker_tags_rdisk_addr(struct boot_img_hdr *hdr) |
| 162 | { |
| 163 | /* overwrite the destination of specified for the project */ |
Channagoud Kadabi | 7042fa3 | 2013-04-26 16:44:14 -0700 | [diff] [blame] | 164 | #ifdef ABOOT_IGNORE_BOOT_HEADER_ADDRS |
| 165 | hdr->kernel_addr = ABOOT_FORCE_KERNEL_ADDR; |
| 166 | hdr->ramdisk_addr = ABOOT_FORCE_RAMDISK_ADDR; |
| 167 | hdr->tags_addr = ABOOT_FORCE_TAGS_ADDR; |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 168 | #endif |
| 169 | } |
| 170 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 171 | static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn) |
| 172 | { |
| 173 | struct atag_ptbl_entry atag_ptn; |
| 174 | |
| 175 | memcpy(atag_ptn.name, ptn->name, 16); |
| 176 | atag_ptn.name[15] = '\0'; |
| 177 | atag_ptn.offset = ptn->start; |
| 178 | atag_ptn.size = ptn->length; |
| 179 | atag_ptn.flags = ptn->flags; |
| 180 | memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry)); |
| 181 | *ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned); |
| 182 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 183 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 184 | unsigned char *update_cmdline(const char * cmdline) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 185 | { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 186 | int cmdline_len = 0; |
| 187 | int have_cmdline = 0; |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 188 | unsigned char *cmdline_final = NULL; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 189 | int pause_at_bootup = 0; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 190 | char ffbm[10]; |
| 191 | bool boot_into_ffbm = get_ffbm(ffbm, sizeof(ffbm)); |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 192 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 193 | if (cmdline && cmdline[0]) { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 194 | cmdline_len = strlen(cmdline); |
| 195 | have_cmdline = 1; |
| 196 | } |
| 197 | if (target_is_emmc_boot()) { |
| 198 | cmdline_len += strlen(emmc_cmdline); |
| 199 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 200 | |
| 201 | cmdline_len += strlen(usb_sn_cmdline); |
| 202 | cmdline_len += strlen(sn_buf); |
| 203 | |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 204 | if (boot_into_ffbm) { |
| 205 | cmdline_len += strlen(androidboot_mode); |
| 206 | cmdline_len += strlen(ffbm); |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 207 | /* reduce kernel console messages to speed-up boot */ |
| 208 | cmdline_len += strlen(loglevel); |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 209 | } else if (target_pause_for_battery_charge()) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 210 | pause_at_bootup = 1; |
| 211 | cmdline_len += strlen(battchg_pause); |
| 212 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 213 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 214 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 215 | cmdline_len += strlen(auth_kernel); |
| 216 | } |
| 217 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 218 | /* Determine correct androidboot.baseband to use */ |
| 219 | switch(target_baseband()) |
| 220 | { |
| 221 | case BASEBAND_APQ: |
| 222 | cmdline_len += strlen(baseband_apq); |
| 223 | break; |
| 224 | |
| 225 | case BASEBAND_MSM: |
| 226 | cmdline_len += strlen(baseband_msm); |
| 227 | break; |
| 228 | |
| 229 | case BASEBAND_CSFB: |
| 230 | cmdline_len += strlen(baseband_csfb); |
| 231 | break; |
| 232 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 233 | case BASEBAND_SVLTE2A: |
| 234 | cmdline_len += strlen(baseband_svlte2a); |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 235 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 236 | |
| 237 | case BASEBAND_MDM: |
| 238 | cmdline_len += strlen(baseband_mdm); |
| 239 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 240 | |
| 241 | case BASEBAND_SGLTE: |
| 242 | cmdline_len += strlen(baseband_sglte); |
| 243 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 244 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 245 | case BASEBAND_SGLTE2: |
| 246 | cmdline_len += strlen(baseband_sglte2); |
| 247 | break; |
| 248 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 249 | case BASEBAND_DSDA: |
| 250 | cmdline_len += strlen(baseband_dsda); |
| 251 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 252 | |
| 253 | case BASEBAND_DSDA2: |
| 254 | cmdline_len += strlen(baseband_dsda2); |
| 255 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 256 | } |
| 257 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 258 | if (cmdline_len > 0) { |
| 259 | const char *src; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 260 | unsigned char *dst = (unsigned char*) malloc((cmdline_len + 4) & (~3)); |
| 261 | ASSERT(dst != NULL); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 262 | |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 263 | /* Save start ptr for debug print */ |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 264 | cmdline_final = dst; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 265 | if (have_cmdline) { |
| 266 | src = cmdline; |
| 267 | while ((*dst++ = *src++)); |
| 268 | } |
| 269 | if (target_is_emmc_boot()) { |
| 270 | src = emmc_cmdline; |
| 271 | if (have_cmdline) --dst; |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 272 | have_cmdline = 1; |
| 273 | while ((*dst++ = *src++)); |
| 274 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 275 | |
| 276 | src = usb_sn_cmdline; |
| 277 | if (have_cmdline) --dst; |
| 278 | have_cmdline = 1; |
| 279 | while ((*dst++ = *src++)); |
| 280 | src = sn_buf; |
| 281 | if (have_cmdline) --dst; |
| 282 | have_cmdline = 1; |
| 283 | while ((*dst++ = *src++)); |
| 284 | |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 285 | if (boot_into_ffbm) { |
| 286 | src = androidboot_mode; |
| 287 | if (have_cmdline) --dst; |
| 288 | while ((*dst++ = *src++)); |
| 289 | src = ffbm; |
| 290 | if (have_cmdline) --dst; |
| 291 | while ((*dst++ = *src++)); |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 292 | src = loglevel; |
| 293 | if (have_cmdline) --dst; |
| 294 | while ((*dst++ = *src++)); |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 295 | } else if (pause_at_bootup) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 296 | src = battchg_pause; |
| 297 | if (have_cmdline) --dst; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 298 | while ((*dst++ = *src++)); |
| 299 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 300 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 301 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 302 | src = auth_kernel; |
| 303 | if (have_cmdline) --dst; |
| 304 | while ((*dst++ = *src++)); |
| 305 | } |
| 306 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 307 | switch(target_baseband()) |
| 308 | { |
| 309 | case BASEBAND_APQ: |
| 310 | src = baseband_apq; |
| 311 | if (have_cmdline) --dst; |
| 312 | while ((*dst++ = *src++)); |
| 313 | break; |
| 314 | |
| 315 | case BASEBAND_MSM: |
| 316 | src = baseband_msm; |
| 317 | if (have_cmdline) --dst; |
| 318 | while ((*dst++ = *src++)); |
| 319 | break; |
| 320 | |
| 321 | case BASEBAND_CSFB: |
| 322 | src = baseband_csfb; |
| 323 | if (have_cmdline) --dst; |
| 324 | while ((*dst++ = *src++)); |
| 325 | break; |
| 326 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 327 | case BASEBAND_SVLTE2A: |
| 328 | src = baseband_svlte2a; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 329 | if (have_cmdline) --dst; |
| 330 | while ((*dst++ = *src++)); |
| 331 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 332 | |
| 333 | case BASEBAND_MDM: |
| 334 | src = baseband_mdm; |
| 335 | if (have_cmdline) --dst; |
| 336 | while ((*dst++ = *src++)); |
| 337 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 338 | |
| 339 | case BASEBAND_SGLTE: |
| 340 | src = baseband_sglte; |
| 341 | if (have_cmdline) --dst; |
| 342 | while ((*dst++ = *src++)); |
| 343 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 344 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 345 | case BASEBAND_SGLTE2: |
| 346 | src = baseband_sglte2; |
| 347 | if (have_cmdline) --dst; |
| 348 | while ((*dst++ = *src++)); |
| 349 | break; |
| 350 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 351 | case BASEBAND_DSDA: |
| 352 | src = baseband_dsda; |
| 353 | if (have_cmdline) --dst; |
| 354 | while ((*dst++ = *src++)); |
| 355 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 356 | |
| 357 | case BASEBAND_DSDA2: |
| 358 | src = baseband_dsda2; |
| 359 | if (have_cmdline) --dst; |
| 360 | while ((*dst++ = *src++)); |
| 361 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 362 | } |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 363 | } |
Deepa Dinamani | 8b8736d | 2012-12-19 15:00:56 -0800 | [diff] [blame] | 364 | |
| 365 | dprintf(INFO, "cmdline: %s\n", cmdline_final); |
| 366 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 367 | return cmdline_final; |
| 368 | } |
| 369 | |
| 370 | unsigned *atag_core(unsigned *ptr) |
| 371 | { |
| 372 | /* CORE */ |
| 373 | *ptr++ = 2; |
| 374 | *ptr++ = 0x54410001; |
| 375 | |
| 376 | return ptr; |
| 377 | |
| 378 | } |
| 379 | |
| 380 | unsigned *atag_ramdisk(unsigned *ptr, void *ramdisk, |
| 381 | unsigned ramdisk_size) |
| 382 | { |
| 383 | if (ramdisk_size) { |
| 384 | *ptr++ = 4; |
| 385 | *ptr++ = 0x54420005; |
| 386 | *ptr++ = (unsigned)ramdisk; |
| 387 | *ptr++ = ramdisk_size; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 388 | } |
| 389 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 390 | return ptr; |
| 391 | } |
| 392 | |
| 393 | unsigned *atag_ptable(unsigned **ptr_addr) |
| 394 | { |
| 395 | int i; |
| 396 | struct ptable *ptable; |
| 397 | |
| 398 | if ((ptable = flash_get_ptable()) && (ptable->count != 0)) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 399 | *(*ptr_addr)++ = 2 + (ptable->count * (sizeof(struct atag_ptbl_entry) / |
| 400 | sizeof(unsigned))); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 401 | *(*ptr_addr)++ = 0x4d534d70; |
| 402 | for (i = 0; i < ptable->count; ++i) |
| 403 | ptentry_to_tag(ptr_addr, ptable_get(ptable, i)); |
| 404 | } |
| 405 | |
| 406 | return (*ptr_addr); |
| 407 | } |
| 408 | |
| 409 | unsigned *atag_cmdline(unsigned *ptr, const char *cmdline) |
| 410 | { |
| 411 | int cmdline_length = 0; |
| 412 | int n; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 413 | char *dest; |
| 414 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 415 | cmdline_length = strlen((const char*)cmdline); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 416 | n = (cmdline_length + 4) & (~3); |
| 417 | |
| 418 | *ptr++ = (n / 4) + 2; |
| 419 | *ptr++ = 0x54410009; |
| 420 | dest = (char *) ptr; |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 421 | while ((*dest++ = *cmdline++)); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 422 | ptr += (n / 4); |
| 423 | |
| 424 | return ptr; |
| 425 | } |
| 426 | |
| 427 | unsigned *atag_end(unsigned *ptr) |
| 428 | { |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 429 | /* END */ |
| 430 | *ptr++ = 0; |
| 431 | *ptr++ = 0; |
| 432 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 433 | return ptr; |
| 434 | } |
| 435 | |
| 436 | void generate_atags(unsigned *ptr, const char *cmdline, |
| 437 | void *ramdisk, unsigned ramdisk_size) |
| 438 | { |
| 439 | |
| 440 | ptr = atag_core(ptr); |
| 441 | ptr = atag_ramdisk(ptr, ramdisk, ramdisk_size); |
| 442 | ptr = target_atag_mem(ptr); |
| 443 | |
| 444 | /* Skip NAND partition ATAGS for eMMC boot */ |
| 445 | if (!target_is_emmc_boot()){ |
| 446 | ptr = atag_ptable(&ptr); |
| 447 | } |
| 448 | |
| 449 | ptr = atag_cmdline(ptr, cmdline); |
| 450 | ptr = atag_end(ptr); |
| 451 | } |
| 452 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 453 | typedef void entry_func_ptr(unsigned, unsigned, unsigned*); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 454 | void boot_linux(void *kernel, unsigned *tags, |
| 455 | const char *cmdline, unsigned machtype, |
| 456 | void *ramdisk, unsigned ramdisk_size) |
| 457 | { |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 458 | unsigned char *final_cmdline; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 459 | #if DEVICE_TREE |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 460 | int ret = 0; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 461 | #endif |
| 462 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 463 | void (*entry)(unsigned, unsigned, unsigned*) = (entry_func_ptr*)(PA((addr_t)kernel)); |
Deepa Dinamani | 25a9f76 | 2012-11-30 15:57:15 -0800 | [diff] [blame] | 464 | uint32_t tags_phys = PA((addr_t)tags); |
| 465 | |
| 466 | ramdisk = PA(ramdisk); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 467 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 468 | final_cmdline = update_cmdline((const char*)cmdline); |
| 469 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 470 | #if DEVICE_TREE |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 471 | dprintf(INFO, "Updating device tree: start\n"); |
| 472 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 473 | /* Update the Device Tree */ |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 474 | ret = update_device_tree((void *)tags, final_cmdline, ramdisk, ramdisk_size); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 475 | if(ret) |
| 476 | { |
| 477 | dprintf(CRITICAL, "ERROR: Updating Device Tree Failed \n"); |
| 478 | ASSERT(0); |
| 479 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 480 | dprintf(INFO, "Updating device tree: done\n"); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 481 | #else |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 482 | /* Generating the Atags */ |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 483 | generate_atags(tags, final_cmdline, ramdisk, ramdisk_size); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 484 | #endif |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 485 | |
Deepa Dinamani | 33734bc | 2013-03-06 12:16:06 -0800 | [diff] [blame] | 486 | dprintf(INFO, "booting linux @ %p, ramdisk @ %p (%d), tags/device tree @ %p\n", |
| 487 | entry, ramdisk, ramdisk_size, tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 488 | |
| 489 | enter_critical_section(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 490 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 491 | /* do any platform specific cleanup before kernel entry */ |
| 492 | platform_uninit(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 493 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 494 | arch_disable_cache(UCACHE); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 495 | |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 496 | #if ARM_WITH_MMU |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 497 | arch_disable_mmu(); |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 498 | #endif |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 499 | bs_set_timestamp(BS_KERNEL_ENTRY); |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 500 | entry(0, machtype, (unsigned*)tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 501 | } |
| 502 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 503 | unsigned page_size = 0; |
| 504 | unsigned page_mask = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 505 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 506 | #define ROUND_TO_PAGE(x,y) (((x) + (y)) & (~(y))) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 507 | |
Channagoud Kadabi | 132ff55 | 2013-04-19 14:34:44 -0700 | [diff] [blame] | 508 | BUF_DMA_ALIGN(buf, 4096); //Equal to max-supported pagesize |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 509 | #if DEVICE_TREE |
Channagoud Kadabi | 132ff55 | 2013-04-19 14:34:44 -0700 | [diff] [blame] | 510 | BUF_DMA_ALIGN(dt_buf, 4096); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 511 | #endif |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 512 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 513 | int boot_linux_from_mmc(void) |
| 514 | { |
| 515 | struct boot_img_hdr *hdr = (void*) buf; |
| 516 | struct boot_img_hdr *uhdr; |
| 517 | unsigned offset = 0; |
| 518 | unsigned long long ptn = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 519 | int index = INVALID_PTN; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 520 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 521 | unsigned char *image_addr = 0; |
| 522 | unsigned kernel_actual; |
| 523 | unsigned ramdisk_actual; |
| 524 | unsigned imagesize_actual; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 525 | unsigned second_actual = 0; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 526 | |
| 527 | #if DEVICE_TREE |
| 528 | struct dt_table *table; |
| 529 | struct dt_entry *dt_entry_ptr; |
| 530 | unsigned dt_table_offset; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 531 | uint32_t dt_actual; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 532 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 533 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 534 | uhdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
| 535 | if (!memcmp(uhdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 536 | dprintf(INFO, "Unified boot method!\n"); |
| 537 | hdr = uhdr; |
| 538 | goto unified_boot; |
| 539 | } |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 540 | if (!boot_into_recovery) { |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 541 | index = partition_get_index("boot"); |
| 542 | ptn = partition_get_offset(index); |
| 543 | if(ptn == 0) { |
Shashank Mittal | 85b91f6 | 2010-10-30 10:12:38 -0700 | [diff] [blame] | 544 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 545 | return -1; |
| 546 | } |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 547 | } |
| 548 | else { |
| 549 | index = partition_get_index("recovery"); |
| 550 | ptn = partition_get_offset(index); |
| 551 | if(ptn == 0) { |
Shashank Mittal | 85b91f6 | 2010-10-30 10:12:38 -0700 | [diff] [blame] | 552 | dprintf(CRITICAL, "ERROR: No recovery partition found\n"); |
| 553 | return -1; |
| 554 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 555 | } |
| 556 | |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 557 | if (mmc_read(ptn + offset, (unsigned int *) buf, page_size)) { |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 558 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 559 | return -1; |
| 560 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 561 | |
| 562 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 563 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 564 | return -1; |
| 565 | } |
| 566 | |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 567 | if (hdr->page_size && (hdr->page_size != page_size)) { |
| 568 | page_size = hdr->page_size; |
| 569 | page_mask = page_size - 1; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 570 | } |
| 571 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 572 | /* |
| 573 | * Update the kernel/ramdisk/tags address if the boot image header |
| 574 | * has default values, these default values come from mkbootimg when |
| 575 | * the boot image is flashed using fastboot flash:raw |
| 576 | */ |
| 577 | update_ker_tags_rdisk_addr(hdr); |
| 578 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 579 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 580 | hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr)); |
| 581 | hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr)); |
| 582 | hdr->tags_addr = VA((addr_t)(hdr->tags_addr)); |
| 583 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 584 | /* Authenticate Kernel */ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 585 | if(target_use_signed_kernel() && (!device.is_unlocked) && (!device.is_tampered)) |
Subbaraman Narayanamurthy | 958fa24 | 2011-01-27 17:42:38 -0800 | [diff] [blame] | 586 | { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 587 | image_addr = (unsigned char *)target_get_scratch_address(); |
| 588 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 589 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 590 | #if DEVICE_TREE |
| 591 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
| 592 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual); |
| 593 | #else |
Channagoud Kadabi | 4b27651 | 2012-08-28 15:16:30 +0530 | [diff] [blame] | 594 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 595 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 596 | offset = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 597 | |
| 598 | /* Assuming device rooted at this time */ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 599 | device.is_tampered = 1; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 600 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 601 | dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 602 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 603 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 604 | /* Read image without signature */ |
| 605 | if (mmc_read(ptn + offset, (void *)image_addr, imagesize_actual)) |
| 606 | { |
| 607 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 608 | return -1; |
Subbaraman Narayanamurthy | 958fa24 | 2011-01-27 17:42:38 -0800 | [diff] [blame] | 609 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 610 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 611 | dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 612 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 613 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 614 | offset = imagesize_actual; |
| 615 | /* Read signature */ |
| 616 | if(mmc_read(ptn + offset, (void *)(image_addr + offset), page_size)) |
| 617 | { |
| 618 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
| 619 | } |
| 620 | else |
| 621 | { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 622 | dprintf(INFO, "Authenticating boot image (%d): start\n", imagesize_actual); |
| 623 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 624 | auth_kernel_img = image_verify((unsigned char *)image_addr, |
| 625 | (unsigned char *)(image_addr + imagesize_actual), |
| 626 | imagesize_actual, |
| 627 | CRYPTO_AUTH_ALG_SHA256); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 628 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 629 | dprintf(INFO, "Authenticating boot image (%d): done\n", imagesize_actual); |
| 630 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 631 | if(auth_kernel_img) |
| 632 | { |
| 633 | /* Authorized kernel */ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 634 | device.is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 635 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 638 | /* Move kernel, ramdisk and device tree to correct address */ |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 639 | memmove((void*) hdr->kernel_addr, (char *)(image_addr + page_size), hdr->kernel_size); |
| 640 | memmove((void*) hdr->ramdisk_addr, (char *)(image_addr + page_size + kernel_actual), hdr->ramdisk_size); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 641 | #if DEVICE_TREE |
| 642 | memmove((void*) hdr->tags_addr, (char *)(image_addr + page_size + kernel_actual + ramdisk_actual), hdr->dt_size); |
| 643 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 644 | |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 645 | #if DEVICE_TREE |
| 646 | if(hdr->dt_size) { |
| 647 | table = (struct dt_table*) dt_buf; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 648 | dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual); |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 649 | |
| 650 | memmove((void *) dt_buf, (char *)dt_table_offset, page_size); |
| 651 | |
| 652 | /* Restriction that the device tree entry table should be less than a page*/ |
| 653 | ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size); |
| 654 | |
| 655 | /* Validate the device tree table header */ |
| 656 | if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) { |
| 657 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 658 | return -1; |
| 659 | } |
| 660 | |
| 661 | /* Find index of device tree within device tree table */ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 662 | if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){ |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 663 | dprintf(CRITICAL, "ERROR: Device Tree Blob cannot be found\n"); |
| 664 | return -1; |
| 665 | } |
| 666 | |
| 667 | /* Read device device tree in the "tags_add */ |
| 668 | memmove((void *)hdr->tags_addr, (char *)dt_table_offset + dt_entry_ptr->offset, dt_entry_ptr->size); |
Channagoud Kadabi | 3509562 | 2013-03-01 13:53:05 -0800 | [diff] [blame] | 669 | } else { |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 670 | /* |
| 671 | * If appended dev tree is found, update the atags with |
| 672 | * memory address to the DTB appended location on RAM. |
| 673 | * Else update with the atags address in the kernel header |
| 674 | */ |
| 675 | void *dtb; |
| 676 | dtb = dev_tree_appended((void*) hdr->kernel_addr, |
Channagoud Kadabi | a83a697 | 2013-04-25 15:26:04 -0700 | [diff] [blame] | 677 | (void *)hdr->tags_addr, hdr->kernel_size); |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 678 | if (!dtb) { |
| 679 | dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n"); |
| 680 | return -1; |
| 681 | } |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 682 | } |
| 683 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 684 | /* Make sure everything from scratch address is read before next step!*/ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 685 | if(device.is_tampered) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 686 | { |
| 687 | write_device_info_mmc(&device); |
| 688 | #ifdef TZ_TAMPER_FUSE |
| 689 | set_tamper_fuse_cmd(); |
| 690 | #endif |
| 691 | } |
Channagoud Kadabi | bf695c6 | 2012-04-10 13:31:56 +0530 | [diff] [blame] | 692 | #if USE_PCOM_SECBOOT |
| 693 | set_tamper_flag(device.is_tampered); |
| 694 | #endif |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 695 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 696 | else |
| 697 | { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 698 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 699 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 700 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 701 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 702 | dprintf(INFO, "Loading boot image (%d): start\n", |
| 703 | kernel_actual + ramdisk_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 704 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 705 | |
| 706 | offset = page_size; |
| 707 | |
| 708 | /* Load kernel */ |
| 709 | if (mmc_read(ptn + offset, (void *)hdr->kernel_addr, kernel_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 710 | dprintf(CRITICAL, "ERROR: Cannot read kernel image\n"); |
| 711 | return -1; |
| 712 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 713 | offset += kernel_actual; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 714 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 715 | /* Load ramdisk */ |
| 716 | if(ramdisk_actual != 0) |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 717 | { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 718 | if (mmc_read(ptn + offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 719 | dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n"); |
| 720 | return -1; |
| 721 | } |
| 722 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 723 | offset += ramdisk_actual; |
| 724 | |
| 725 | dprintf(INFO, "Loading boot image (%d): done\n", |
| 726 | kernel_actual + ramdisk_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 727 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 728 | |
| 729 | if(hdr->second_size != 0) { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 730 | offset += second_actual; |
| 731 | /* Second image loading not implemented. */ |
| 732 | ASSERT(0); |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 733 | } |
| 734 | |
| 735 | #if DEVICE_TREE |
| 736 | if(hdr->dt_size != 0) { |
| 737 | |
| 738 | /* Read the device tree table into buffer */ |
| 739 | if(mmc_read(ptn + offset,(unsigned int *) dt_buf, page_size)) { |
| 740 | dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n"); |
| 741 | return -1; |
| 742 | } |
| 743 | table = (struct dt_table*) dt_buf; |
| 744 | |
| 745 | /* Restriction that the device tree entry table should be less than a page*/ |
| 746 | ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size); |
| 747 | |
| 748 | /* Validate the device tree table header */ |
| 749 | if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) { |
| 750 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 751 | return -1; |
| 752 | } |
| 753 | |
| 754 | /* Calculate the offset of device tree within device tree table */ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 755 | if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){ |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 756 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 757 | return -1; |
| 758 | } |
| 759 | |
| 760 | /* Read device device tree in the "tags_add */ |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 761 | if(mmc_read(ptn + offset + dt_entry_ptr->offset, |
| 762 | (void *)hdr->tags_addr, dt_entry_ptr->size)) { |
| 763 | dprintf(CRITICAL, "ERROR: Cannot read device tree\n"); |
| 764 | return -1; |
| 765 | } |
Channagoud Kadabi | 3509562 | 2013-03-01 13:53:05 -0800 | [diff] [blame] | 766 | } else { |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 767 | /* |
| 768 | * If appended dev tree is found, update the atags with |
| 769 | * memory address to the DTB appended location on RAM. |
| 770 | * Else update with the atags address in the kernel header |
| 771 | */ |
| 772 | void *dtb; |
| 773 | dtb = dev_tree_appended((void*) hdr->kernel_addr, |
Channagoud Kadabi | a83a697 | 2013-04-25 15:26:04 -0700 | [diff] [blame] | 774 | (void *)hdr->tags_addr, hdr->kernel_size); |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 775 | if (!dtb) { |
| 776 | dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n"); |
| 777 | return -1; |
| 778 | } |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 779 | } |
| 780 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 781 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 782 | |
| 783 | unified_boot: |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 784 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 785 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 786 | (const char *)hdr->cmdline, board_machtype(), |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 787 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 788 | |
| 789 | return 0; |
| 790 | } |
| 791 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 792 | int boot_linux_from_flash(void) |
| 793 | { |
| 794 | struct boot_img_hdr *hdr = (void*) buf; |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 795 | struct ptentry *ptn; |
| 796 | struct ptable *ptable; |
| 797 | unsigned offset = 0; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 798 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 799 | unsigned char *image_addr = 0; |
| 800 | unsigned kernel_actual; |
| 801 | unsigned ramdisk_actual; |
| 802 | unsigned imagesize_actual; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 803 | unsigned second_actual; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 804 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 805 | #if DEVICE_TREE |
| 806 | struct dt_table *table; |
| 807 | struct dt_entry *dt_entry_ptr; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 808 | uint32_t dt_actual; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 809 | #endif |
| 810 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 811 | if (target_is_emmc_boot()) { |
| 812 | hdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
| 813 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 814 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
| 815 | return -1; |
| 816 | } |
| 817 | goto continue_boot; |
| 818 | } |
| 819 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 820 | ptable = flash_get_ptable(); |
| 821 | if (ptable == NULL) { |
| 822 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 823 | return -1; |
| 824 | } |
| 825 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 826 | if(!boot_into_recovery) |
| 827 | { |
| 828 | ptn = ptable_find(ptable, "boot"); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 829 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 830 | if (ptn == NULL) { |
| 831 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 832 | return -1; |
| 833 | } |
| 834 | } |
| 835 | else |
| 836 | { |
| 837 | ptn = ptable_find(ptable, "recovery"); |
| 838 | if (ptn == NULL) { |
| 839 | dprintf(CRITICAL, "ERROR: No recovery partition found\n"); |
| 840 | return -1; |
| 841 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 842 | } |
| 843 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 844 | if (flash_read(ptn, offset, buf, page_size)) { |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 845 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 846 | return -1; |
| 847 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 848 | |
| 849 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 850 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 851 | return -1; |
| 852 | } |
| 853 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 854 | if (hdr->page_size != page_size) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 855 | dprintf(CRITICAL, "ERROR: Invalid boot image pagesize. Device pagesize: %d, Image pagesize: %d\n",page_size,hdr->page_size); |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 856 | return -1; |
| 857 | } |
| 858 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 859 | /* |
| 860 | * Update the kernel/ramdisk/tags address if the boot image header |
| 861 | * has default values, these default values come from mkbootimg when |
| 862 | * the boot image is flashed using fastboot flash:raw |
| 863 | */ |
| 864 | update_ker_tags_rdisk_addr(hdr); |
| 865 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 866 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 867 | hdr->kernel_addr = VA(hdr->kernel_addr); |
| 868 | hdr->ramdisk_addr = VA(hdr->ramdisk_addr); |
| 869 | hdr->tags_addr = VA(hdr->tags_addr); |
| 870 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 871 | /* Authenticate Kernel */ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 872 | if(target_use_signed_kernel() && (!device.is_unlocked) && (!device.is_tampered)) |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 873 | { |
| 874 | image_addr = (unsigned char *)target_get_scratch_address(); |
| 875 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 876 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 877 | #if DEVICE_TREE |
| 878 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
| 879 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual); |
| 880 | #else |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 881 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 882 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 883 | offset = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 884 | |
| 885 | /* Assuming device rooted at this time */ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 886 | device.is_tampered = 1; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 887 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 888 | dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 889 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 890 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 891 | /* Read image without signature */ |
| 892 | if (flash_read(ptn, offset, (void *)image_addr, imagesize_actual)) |
| 893 | { |
| 894 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 895 | return -1; |
| 896 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 897 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 898 | dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 899 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 900 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 901 | offset = imagesize_actual; |
| 902 | /* Read signature */ |
| 903 | if (flash_read(ptn, offset, (void *)(image_addr + offset), page_size)) |
| 904 | { |
| 905 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
| 906 | } |
| 907 | else |
| 908 | { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 909 | dprintf(INFO, "Authenticating boot image (%d): start\n", imagesize_actual); |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 910 | |
| 911 | /* Verify signature */ |
| 912 | auth_kernel_img = image_verify((unsigned char *)image_addr, |
| 913 | (unsigned char *)(image_addr + imagesize_actual), |
| 914 | imagesize_actual, |
| 915 | CRYPTO_AUTH_ALG_SHA256); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 916 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 917 | dprintf(INFO, "Authenticating boot image (%d): done\n", imagesize_actual); |
| 918 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 919 | if(auth_kernel_img) |
| 920 | { |
| 921 | /* Authorized kernel */ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 922 | device.is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 923 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | /* Move kernel and ramdisk to correct address */ |
| 927 | memmove((void*) hdr->kernel_addr, (char *)(image_addr + page_size), hdr->kernel_size); |
| 928 | memmove((void*) hdr->ramdisk_addr, (char *)(image_addr + page_size + kernel_actual), hdr->ramdisk_size); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 929 | #if DEVICE_TREE |
| 930 | memmove((void*) hdr->tags_addr, (char *)(image_addr + page_size + kernel_actual + ramdisk_actual), hdr->dt_size); |
| 931 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 932 | |
| 933 | /* Make sure everything from scratch address is read before next step!*/ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 934 | if(device.is_tampered) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 935 | { |
| 936 | write_device_info_flash(&device); |
| 937 | } |
Channagoud Kadabi | 5c86fe3 | 2012-02-16 10:58:48 +0530 | [diff] [blame] | 938 | #if USE_PCOM_SECBOOT |
| 939 | set_tamper_flag(device.is_tampered); |
| 940 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 941 | } |
| 942 | else |
| 943 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 944 | offset = page_size; |
| 945 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 946 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 947 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 948 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 949 | |
| 950 | dprintf(INFO, "Loading boot image (%d): start\n", |
| 951 | kernel_actual + ramdisk_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 952 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 953 | |
| 954 | if (flash_read(ptn, offset, (void *)hdr->kernel_addr, kernel_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 955 | dprintf(CRITICAL, "ERROR: Cannot read kernel image\n"); |
| 956 | return -1; |
| 957 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 958 | offset += kernel_actual; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 959 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 960 | if (flash_read(ptn, offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 961 | dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n"); |
| 962 | return -1; |
| 963 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 964 | offset += ramdisk_actual; |
| 965 | |
| 966 | dprintf(INFO, "Loading boot image (%d): done\n", |
| 967 | kernel_actual + ramdisk_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 968 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 969 | |
| 970 | if(hdr->second_size != 0) { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 971 | offset += second_actual; |
| 972 | /* Second image loading not implemented. */ |
| 973 | ASSERT(0); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 974 | } |
| 975 | |
| 976 | #if DEVICE_TREE |
| 977 | if(hdr->dt_size != 0) { |
| 978 | |
| 979 | /* Read the device tree table into buffer */ |
| 980 | if(flash_read(ptn, offset, (void *) dt_buf, page_size)) { |
| 981 | dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n"); |
| 982 | return -1; |
| 983 | } |
| 984 | |
| 985 | table = (struct dt_table*) dt_buf; |
| 986 | |
| 987 | /* Restriction that the device tree entry table should be less than a page*/ |
| 988 | ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size); |
| 989 | |
| 990 | /* Validate the device tree table header */ |
| 991 | if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) { |
| 992 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 993 | return -1; |
| 994 | } |
| 995 | |
| 996 | /* Calculate the offset of device tree within device tree table */ |
| 997 | if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){ |
| 998 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 999 | return -1; |
| 1000 | } |
| 1001 | |
| 1002 | /* Read device device tree in the "tags_add */ |
| 1003 | if(flash_read(ptn, offset + dt_entry_ptr->offset, |
| 1004 | (void *)hdr->tags_addr, dt_entry_ptr->size)) { |
| 1005 | dprintf(CRITICAL, "ERROR: Cannot read device tree\n"); |
| 1006 | return -1; |
| 1007 | } |
| 1008 | } |
| 1009 | #endif |
| 1010 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1011 | } |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 1012 | continue_boot: |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1013 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1014 | /* TODO: create/pass atags to kernel */ |
| 1015 | |
Ajay Dudani | e28a607 | 2011-07-01 13:59:46 -0700 | [diff] [blame] | 1016 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 1017 | (const char *)hdr->cmdline, board_machtype(), |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1018 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 1019 | |
| 1020 | return 0; |
| 1021 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1022 | |
Channagoud Kadabi | 132ff55 | 2013-04-19 14:34:44 -0700 | [diff] [blame] | 1023 | BUF_DMA_ALIGN(info_buf, 4096); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1024 | void write_device_info_mmc(device_info *dev) |
| 1025 | { |
| 1026 | struct device_info *info = (void*) info_buf; |
| 1027 | unsigned long long ptn = 0; |
| 1028 | unsigned long long size; |
| 1029 | int index = INVALID_PTN; |
| 1030 | |
| 1031 | index = partition_get_index("aboot"); |
| 1032 | ptn = partition_get_offset(index); |
| 1033 | if(ptn == 0) |
| 1034 | { |
| 1035 | return; |
| 1036 | } |
| 1037 | |
| 1038 | size = partition_get_size(index); |
| 1039 | |
| 1040 | memcpy(info, dev, sizeof(device_info)); |
| 1041 | |
| 1042 | if(mmc_write((ptn + size - 512), 512, (void *)info_buf)) |
| 1043 | { |
| 1044 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1045 | return; |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | void read_device_info_mmc(device_info *dev) |
| 1050 | { |
| 1051 | struct device_info *info = (void*) info_buf; |
| 1052 | unsigned long long ptn = 0; |
| 1053 | unsigned long long size; |
| 1054 | int index = INVALID_PTN; |
| 1055 | |
| 1056 | index = partition_get_index("aboot"); |
| 1057 | ptn = partition_get_offset(index); |
| 1058 | if(ptn == 0) |
| 1059 | { |
| 1060 | return; |
| 1061 | } |
| 1062 | |
| 1063 | size = partition_get_size(index); |
| 1064 | |
| 1065 | if(mmc_read((ptn + size - 512), (void *)info_buf, 512)) |
| 1066 | { |
| 1067 | dprintf(CRITICAL, "ERROR: Cannot read device info\n"); |
| 1068 | return; |
| 1069 | } |
| 1070 | |
| 1071 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 1072 | { |
| 1073 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
| 1074 | info->is_unlocked = 0; |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1075 | info->is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1076 | |
| 1077 | write_device_info_mmc(info); |
| 1078 | } |
| 1079 | memcpy(dev, info, sizeof(device_info)); |
| 1080 | } |
| 1081 | |
| 1082 | void write_device_info_flash(device_info *dev) |
| 1083 | { |
| 1084 | struct device_info *info = (void *) info_buf; |
| 1085 | struct ptentry *ptn; |
| 1086 | struct ptable *ptable; |
| 1087 | |
| 1088 | ptable = flash_get_ptable(); |
| 1089 | if (ptable == NULL) |
| 1090 | { |
| 1091 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1092 | return; |
| 1093 | } |
| 1094 | |
| 1095 | ptn = ptable_find(ptable, "devinfo"); |
| 1096 | if (ptn == NULL) |
| 1097 | { |
| 1098 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 1099 | return; |
| 1100 | } |
| 1101 | |
| 1102 | memcpy(info, dev, sizeof(device_info)); |
| 1103 | |
| 1104 | if (flash_write(ptn, 0, (void *)info_buf, page_size)) |
| 1105 | { |
| 1106 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1107 | return; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | void read_device_info_flash(device_info *dev) |
| 1112 | { |
| 1113 | struct device_info *info = (void*) info_buf; |
| 1114 | struct ptentry *ptn; |
| 1115 | struct ptable *ptable; |
| 1116 | |
| 1117 | ptable = flash_get_ptable(); |
| 1118 | if (ptable == NULL) |
| 1119 | { |
| 1120 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1121 | return; |
| 1122 | } |
| 1123 | |
| 1124 | ptn = ptable_find(ptable, "devinfo"); |
| 1125 | if (ptn == NULL) |
| 1126 | { |
| 1127 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 1128 | return; |
| 1129 | } |
| 1130 | |
| 1131 | if (flash_read(ptn, 0, (void *)info_buf, page_size)) |
| 1132 | { |
| 1133 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1134 | return; |
| 1135 | } |
| 1136 | |
| 1137 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 1138 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1139 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
| 1140 | info->is_unlocked = 0; |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1141 | info->is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1142 | write_device_info_flash(info); |
| 1143 | } |
| 1144 | memcpy(dev, info, sizeof(device_info)); |
| 1145 | } |
| 1146 | |
| 1147 | void write_device_info(device_info *dev) |
| 1148 | { |
| 1149 | if(target_is_emmc_boot()) |
| 1150 | { |
| 1151 | write_device_info_mmc(dev); |
| 1152 | } |
| 1153 | else |
| 1154 | { |
| 1155 | write_device_info_flash(dev); |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | void read_device_info(device_info *dev) |
| 1160 | { |
| 1161 | if(target_is_emmc_boot()) |
| 1162 | { |
| 1163 | read_device_info_mmc(dev); |
| 1164 | } |
| 1165 | else |
| 1166 | { |
| 1167 | read_device_info_flash(dev); |
| 1168 | } |
| 1169 | } |
| 1170 | |
| 1171 | void reset_device_info() |
| 1172 | { |
| 1173 | dprintf(ALWAYS, "reset_device_info called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1174 | device.is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1175 | write_device_info(&device); |
| 1176 | } |
| 1177 | |
| 1178 | void set_device_root() |
| 1179 | { |
| 1180 | dprintf(ALWAYS, "set_device_root called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1181 | device.is_tampered = 1; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1182 | write_device_info(&device); |
| 1183 | } |
| 1184 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1185 | #if DEVICE_TREE |
| 1186 | int copy_dtb(uint8_t *boot_image_start) |
| 1187 | { |
| 1188 | uint32 dt_image_offset = 0; |
| 1189 | uint32_t n; |
| 1190 | struct dt_table *table; |
| 1191 | struct dt_entry *dt_entry_ptr; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1192 | |
| 1193 | struct boot_img_hdr *hdr = (struct boot_img_hdr *) (boot_image_start); |
| 1194 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1195 | if(hdr->dt_size != 0) { |
| 1196 | |
| 1197 | /* add kernel offset */ |
| 1198 | dt_image_offset += page_size; |
| 1199 | n = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1200 | dt_image_offset += n; |
| 1201 | |
| 1202 | /* add ramdisk offset */ |
| 1203 | n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 1204 | dt_image_offset += n; |
| 1205 | |
| 1206 | /* add second offset */ |
| 1207 | if(hdr->second_size != 0) { |
| 1208 | n = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 1209 | dt_image_offset += n; |
| 1210 | } |
| 1211 | |
| 1212 | /* offset now point to start of dt.img */ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1213 | table = (struct dt_table*)(boot_image_start + dt_image_offset); |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1214 | |
| 1215 | /* Restriction that the device tree entry table should be less than a page*/ |
| 1216 | ASSERT(((table->num_entries * sizeof(struct dt_entry))+ DEV_TREE_HEADER_SIZE) < hdr->page_size); |
| 1217 | |
| 1218 | /* Validate the device tree table header */ |
| 1219 | if((table->magic != DEV_TREE_MAGIC) && (table->version != DEV_TREE_VERSION)) { |
| 1220 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1221 | return -1; |
| 1222 | } |
| 1223 | |
| 1224 | /* Calculate the offset of device tree within device tree table */ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1225 | if((dt_entry_ptr = dev_tree_get_entry_ptr(table)) == NULL){ |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1226 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1227 | return -1; |
| 1228 | } |
| 1229 | |
| 1230 | /* Read device device tree in the "tags_add */ |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1231 | memmove((void*) hdr->tags_addr, |
| 1232 | boot_image_start + dt_image_offset + dt_entry_ptr->offset, |
| 1233 | dt_entry_ptr->size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1234 | } else |
| 1235 | return -1; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1236 | |
| 1237 | /* Everything looks fine. Return success. */ |
| 1238 | return 0; |
| 1239 | } |
| 1240 | #endif |
| 1241 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1242 | void cmd_boot(const char *arg, void *data, unsigned sz) |
| 1243 | { |
| 1244 | unsigned kernel_actual; |
| 1245 | unsigned ramdisk_actual; |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1246 | struct boot_img_hdr *hdr; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1247 | char *ptr = ((char*) data); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1248 | int ret = 0; |
| 1249 | uint8_t dtb_copied = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1250 | |
| 1251 | if (sz < sizeof(hdr)) { |
| 1252 | fastboot_fail("invalid bootimage header"); |
| 1253 | return; |
| 1254 | } |
| 1255 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1256 | hdr = (struct boot_img_hdr *)data; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1257 | |
| 1258 | /* ensure commandline is terminated */ |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1259 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1260 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1261 | if(target_is_emmc_boot() && hdr->page_size) { |
| 1262 | page_size = hdr->page_size; |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 1263 | page_mask = page_size - 1; |
| 1264 | } |
| 1265 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1266 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1267 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 1268 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1269 | /* |
| 1270 | * Update the kernel/ramdisk/tags address if the boot image header |
| 1271 | * has default values, these default values come from mkbootimg when |
| 1272 | * the boot image is flashed using fastboot flash:raw |
| 1273 | */ |
| 1274 | update_ker_tags_rdisk_addr(hdr); |
Dima Zavin | 3cadfff | 2013-03-21 14:30:48 -0700 | [diff] [blame] | 1275 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1276 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 1277 | hdr->kernel_addr = VA(hdr->kernel_addr); |
| 1278 | hdr->ramdisk_addr = VA(hdr->ramdisk_addr); |
| 1279 | hdr->tags_addr = VA(hdr->tags_addr); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1280 | |
Shashank Mittal | 1f0e266 | 2011-09-01 15:06:00 -0700 | [diff] [blame] | 1281 | /* sz should have atleast raw boot image */ |
| 1282 | if (page_size + kernel_actual + ramdisk_actual > sz) { |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1283 | fastboot_fail("incomplete bootimage"); |
| 1284 | return; |
| 1285 | } |
| 1286 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1287 | #if DEVICE_TREE |
| 1288 | /* find correct dtb and copy it to right location */ |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1289 | ret = copy_dtb(data); |
| 1290 | |
| 1291 | dtb_copied = !ret ? 1 : 0; |
| 1292 | #endif |
| 1293 | |
| 1294 | /* Load ramdisk & kernel */ |
| 1295 | memmove((void*) hdr->ramdisk_addr, ptr + page_size + kernel_actual, hdr->ramdisk_size); |
| 1296 | memmove((void*) hdr->kernel_addr, ptr + page_size, hdr->kernel_size); |
| 1297 | |
| 1298 | #if DEVICE_TREE |
| 1299 | /* |
| 1300 | * If dtb is not found look for appended DTB in the kernel. |
| 1301 | * If appended dev tree is found, update the atags with |
| 1302 | * memory address to the DTB appended location on RAM. |
| 1303 | * Else update with the atags address in the kernel header |
| 1304 | */ |
| 1305 | if (!dtb_copied) { |
| 1306 | void *dtb; |
Channagoud Kadabi | a83a697 | 2013-04-25 15:26:04 -0700 | [diff] [blame] | 1307 | dtb = dev_tree_appended((void *)hdr->kernel_addr, (void *)hdr->tags_addr, hdr->kernel_size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1308 | if (!dtb) { |
| 1309 | fastboot_fail("dtb not found"); |
| 1310 | return; |
| 1311 | } |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1312 | } |
| 1313 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1314 | |
| 1315 | fastboot_okay(""); |
| 1316 | udc_stop(); |
| 1317 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 1318 | boot_linux((void*) hdr->kernel_addr, (void*) hdr->tags_addr, |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1319 | (const char*) hdr->cmdline, board_machtype(), |
| 1320 | (void*) hdr->ramdisk_addr, hdr->ramdisk_size); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1321 | } |
| 1322 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1323 | void cmd_erase(const char *arg, void *data, unsigned sz) |
| 1324 | { |
| 1325 | struct ptentry *ptn; |
| 1326 | struct ptable *ptable; |
| 1327 | |
| 1328 | ptable = flash_get_ptable(); |
| 1329 | if (ptable == NULL) { |
| 1330 | fastboot_fail("partition table doesn't exist"); |
| 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | ptn = ptable_find(ptable, arg); |
| 1335 | if (ptn == NULL) { |
| 1336 | fastboot_fail("unknown partition name"); |
| 1337 | return; |
| 1338 | } |
| 1339 | |
| 1340 | if (flash_erase(ptn)) { |
| 1341 | fastboot_fail("failed to erase partition"); |
| 1342 | return; |
| 1343 | } |
| 1344 | fastboot_okay(""); |
| 1345 | } |
| 1346 | |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1347 | |
| 1348 | void cmd_erase_mmc(const char *arg, void *data, unsigned sz) |
| 1349 | { |
Channagoud Kadabi | 132ff55 | 2013-04-19 14:34:44 -0700 | [diff] [blame] | 1350 | BUF_DMA_ALIGN(out, 512); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1351 | unsigned long long ptn = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1352 | int index = INVALID_PTN; |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1353 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1354 | index = partition_get_index(arg); |
| 1355 | ptn = partition_get_offset(index); |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 1356 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1357 | if(ptn == 0) { |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 1358 | fastboot_fail("Partition table doesn't exist\n"); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1359 | return; |
| 1360 | } |
neetid | b4b24d6 | 2012-01-20 12:13:09 -0800 | [diff] [blame] | 1361 | /* Simple inefficient version of erase. Just writing |
| 1362 | 0 in first block */ |
| 1363 | if (mmc_write(ptn , 512, (unsigned int *)out)) { |
| 1364 | fastboot_fail("failed to erase partition"); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1365 | return; |
| 1366 | } |
| 1367 | fastboot_okay(""); |
| 1368 | } |
| 1369 | |
| 1370 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1371 | void cmd_flash_mmc_img(const char *arg, void *data, unsigned sz) |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1372 | { |
| 1373 | unsigned long long ptn = 0; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 1374 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1375 | int index = INVALID_PTN; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 1376 | |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 1377 | if (!strcmp(arg, "partition")) |
| 1378 | { |
| 1379 | dprintf(INFO, "Attempt to write partition image.\n"); |
Neeti Desai | 5f26aff | 2011-09-30 10:27:40 -0700 | [diff] [blame] | 1380 | if (write_partition(sz, (unsigned char *) data)) { |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 1381 | fastboot_fail("failed to write partition"); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1382 | return; |
| 1383 | } |
| 1384 | } |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 1385 | else |
| 1386 | { |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1387 | index = partition_get_index(arg); |
| 1388 | ptn = partition_get_offset(index); |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 1389 | if(ptn == 0) { |
| 1390 | fastboot_fail("partition table doesn't exist"); |
| 1391 | return; |
| 1392 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1393 | |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 1394 | if (!strcmp(arg, "boot") || !strcmp(arg, "recovery")) { |
| 1395 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 1396 | fastboot_fail("image is not a boot image"); |
| 1397 | return; |
| 1398 | } |
| 1399 | } |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 1400 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1401 | size = partition_get_size(index); |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 1402 | if (ROUND_TO_PAGE(sz,511) > size) { |
| 1403 | fastboot_fail("size too large"); |
| 1404 | return; |
| 1405 | } |
| 1406 | else if (mmc_write(ptn , sz, (unsigned int *)data)) { |
| 1407 | fastboot_fail("flash write failure"); |
| 1408 | return; |
| 1409 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1410 | } |
| 1411 | fastboot_okay(""); |
| 1412 | return; |
| 1413 | } |
| 1414 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1415 | void cmd_flash_mmc_sparse_img(const char *arg, void *data, unsigned sz) |
| 1416 | { |
| 1417 | unsigned int chunk; |
| 1418 | unsigned int chunk_data_sz; |
| 1419 | sparse_header_t *sparse_header; |
| 1420 | chunk_header_t *chunk_header; |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 1421 | uint32_t total_blocks = 0; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1422 | unsigned long long ptn = 0; |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 1423 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1424 | int index = INVALID_PTN; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1425 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1426 | index = partition_get_index(arg); |
| 1427 | ptn = partition_get_offset(index); |
| 1428 | if(ptn == 0) { |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1429 | fastboot_fail("partition table doesn't exist"); |
| 1430 | return; |
| 1431 | } |
| 1432 | |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 1433 | size = partition_get_size(index); |
| 1434 | if (ROUND_TO_PAGE(sz,511) > size) { |
| 1435 | fastboot_fail("size too large"); |
| 1436 | return; |
| 1437 | } |
| 1438 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1439 | /* Read and skip over sparse image header */ |
| 1440 | sparse_header = (sparse_header_t *) data; |
Ajay Dudani | 876b328 | 2012-12-21 14:12:17 -0800 | [diff] [blame] | 1441 | if ((sparse_header->total_blks * sparse_header->blk_sz) > size) { |
| 1442 | fastboot_fail("size too large"); |
| 1443 | return; |
| 1444 | } |
| 1445 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1446 | data += sparse_header->file_hdr_sz; |
| 1447 | if(sparse_header->file_hdr_sz > sizeof(sparse_header_t)) |
| 1448 | { |
| 1449 | /* Skip the remaining bytes in a header that is longer than |
| 1450 | * we expected. |
| 1451 | */ |
| 1452 | data += (sparse_header->file_hdr_sz - sizeof(sparse_header_t)); |
| 1453 | } |
| 1454 | |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 1455 | dprintf (SPEW, "=== Sparse Image Header ===\n"); |
| 1456 | dprintf (SPEW, "magic: 0x%x\n", sparse_header->magic); |
| 1457 | dprintf (SPEW, "major_version: 0x%x\n", sparse_header->major_version); |
| 1458 | dprintf (SPEW, "minor_version: 0x%x\n", sparse_header->minor_version); |
| 1459 | dprintf (SPEW, "file_hdr_sz: %d\n", sparse_header->file_hdr_sz); |
| 1460 | dprintf (SPEW, "chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz); |
| 1461 | dprintf (SPEW, "blk_sz: %d\n", sparse_header->blk_sz); |
| 1462 | dprintf (SPEW, "total_blks: %d\n", sparse_header->total_blks); |
| 1463 | dprintf (SPEW, "total_chunks: %d\n", sparse_header->total_chunks); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1464 | |
| 1465 | /* Start processing chunks */ |
| 1466 | for (chunk=0; chunk<sparse_header->total_chunks; chunk++) |
| 1467 | { |
| 1468 | /* Read and skip over chunk header */ |
| 1469 | chunk_header = (chunk_header_t *) data; |
| 1470 | data += sizeof(chunk_header_t); |
| 1471 | |
| 1472 | dprintf (SPEW, "=== Chunk Header ===\n"); |
| 1473 | dprintf (SPEW, "chunk_type: 0x%x\n", chunk_header->chunk_type); |
| 1474 | dprintf (SPEW, "chunk_data_sz: 0x%x\n", chunk_header->chunk_sz); |
| 1475 | dprintf (SPEW, "total_size: 0x%x\n", chunk_header->total_sz); |
| 1476 | |
| 1477 | if(sparse_header->chunk_hdr_sz > sizeof(chunk_header_t)) |
| 1478 | { |
| 1479 | /* Skip the remaining bytes in a header that is longer than |
| 1480 | * we expected. |
| 1481 | */ |
| 1482 | data += (sparse_header->chunk_hdr_sz - sizeof(chunk_header_t)); |
| 1483 | } |
| 1484 | |
| 1485 | chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz; |
| 1486 | switch (chunk_header->chunk_type) |
| 1487 | { |
| 1488 | case CHUNK_TYPE_RAW: |
| 1489 | if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz + |
| 1490 | chunk_data_sz)) |
| 1491 | { |
| 1492 | fastboot_fail("Bogus chunk size for chunk type Raw"); |
| 1493 | return; |
| 1494 | } |
| 1495 | |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 1496 | if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz), |
| 1497 | chunk_data_sz, |
| 1498 | (unsigned int*)data)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1499 | { |
| 1500 | fastboot_fail("flash write failure"); |
| 1501 | return; |
| 1502 | } |
| 1503 | total_blocks += chunk_header->chunk_sz; |
| 1504 | data += chunk_data_sz; |
| 1505 | break; |
| 1506 | |
| 1507 | case CHUNK_TYPE_DONT_CARE: |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 1508 | total_blocks += chunk_header->chunk_sz; |
| 1509 | break; |
| 1510 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1511 | case CHUNK_TYPE_CRC: |
| 1512 | if(chunk_header->total_sz != sparse_header->chunk_hdr_sz) |
| 1513 | { |
| 1514 | fastboot_fail("Bogus chunk size for chunk type Dont Care"); |
| 1515 | return; |
| 1516 | } |
| 1517 | total_blocks += chunk_header->chunk_sz; |
| 1518 | data += chunk_data_sz; |
| 1519 | break; |
| 1520 | |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 1521 | default: |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1522 | fastboot_fail("Unknown chunk type"); |
| 1523 | return; |
| 1524 | } |
| 1525 | } |
| 1526 | |
Ajay Dudani | 0c6927b | 2011-05-18 11:12:16 -0700 | [diff] [blame] | 1527 | dprintf(INFO, "Wrote %d blocks, expected to write %d blocks\n", |
| 1528 | total_blocks, sparse_header->total_blks); |
| 1529 | |
| 1530 | if(total_blocks != sparse_header->total_blks) |
| 1531 | { |
| 1532 | fastboot_fail("sparse image write failure"); |
| 1533 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1534 | |
| 1535 | fastboot_okay(""); |
| 1536 | return; |
| 1537 | } |
| 1538 | |
| 1539 | void cmd_flash_mmc(const char *arg, void *data, unsigned sz) |
| 1540 | { |
| 1541 | sparse_header_t *sparse_header; |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 1542 | /* 8 Byte Magic + 2048 Byte xml + Encrypted Data */ |
| 1543 | unsigned int *magic_number = (unsigned int *) data; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1544 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 1545 | #ifdef SSD_ENABLE |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 1546 | int ret=0; |
| 1547 | uint32 major_version=0; |
| 1548 | uint32 minor_version=0; |
| 1549 | |
| 1550 | ret = scm_svc_version(&major_version,&minor_version); |
| 1551 | if(!ret) |
| 1552 | { |
| 1553 | if(major_version >= 2) |
| 1554 | { |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 1555 | if( !strcmp(arg, "ssd") || !strcmp(arg, "tqs") ) |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 1556 | { |
| 1557 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 1558 | if (ret != 0) { |
| 1559 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 1560 | return; |
| 1561 | } |
| 1562 | |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 1563 | /* Protect only for SSD */ |
| 1564 | if (!strcmp(arg, "ssd")) { |
| 1565 | ret = scm_protect_keystore((uint32 *) data, sz); |
| 1566 | if (ret != 0) { |
| 1567 | dprintf(CRITICAL, "ERROR: scm_protect_keystore Failed\n"); |
| 1568 | return; |
| 1569 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | else |
| 1573 | { |
| 1574 | ret = decrypt_scm_v2((uint32 **) &data, &sz); |
| 1575 | if(ret != 0) |
| 1576 | { |
| 1577 | dprintf(CRITICAL,"ERROR: Decryption Failure\n"); |
| 1578 | return; |
| 1579 | } |
| 1580 | } |
| 1581 | } |
| 1582 | else |
| 1583 | { |
| 1584 | if (magic_number[0] == DECRYPT_MAGIC_0 && |
| 1585 | magic_number[1] == DECRYPT_MAGIC_1) |
| 1586 | { |
| 1587 | ret = decrypt_scm((uint32 **) &data, &sz); |
| 1588 | if (ret != 0) { |
| 1589 | dprintf(CRITICAL, "ERROR: Invalid secure image\n"); |
| 1590 | return; |
| 1591 | } |
| 1592 | } |
| 1593 | else if (magic_number[0] == ENCRYPT_MAGIC_0 && |
| 1594 | magic_number[1] == ENCRYPT_MAGIC_1) |
| 1595 | { |
| 1596 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 1597 | if (ret != 0) { |
| 1598 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 1599 | return; |
| 1600 | } |
| 1601 | } |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 1602 | } |
| 1603 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 1604 | else |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 1605 | { |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 1606 | dprintf(CRITICAL,"INVALID SVC Version\n"); |
| 1607 | return; |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 1608 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 1609 | #endif /* SSD_ENABLE */ |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 1610 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 1611 | sparse_header = (sparse_header_t *) data; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1612 | if (sparse_header->magic != SPARSE_HEADER_MAGIC) |
| 1613 | cmd_flash_mmc_img(arg, data, sz); |
| 1614 | else |
| 1615 | cmd_flash_mmc_sparse_img(arg, data, sz); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 1616 | return; |
| 1617 | } |
| 1618 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1619 | void cmd_flash(const char *arg, void *data, unsigned sz) |
| 1620 | { |
| 1621 | struct ptentry *ptn; |
| 1622 | struct ptable *ptable; |
| 1623 | unsigned extra = 0; |
| 1624 | |
| 1625 | ptable = flash_get_ptable(); |
| 1626 | if (ptable == NULL) { |
| 1627 | fastboot_fail("partition table doesn't exist"); |
| 1628 | return; |
| 1629 | } |
| 1630 | |
| 1631 | ptn = ptable_find(ptable, arg); |
| 1632 | if (ptn == NULL) { |
| 1633 | fastboot_fail("unknown partition name"); |
| 1634 | return; |
| 1635 | } |
| 1636 | |
| 1637 | if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) { |
| 1638 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 1639 | fastboot_fail("image is not a boot image"); |
| 1640 | return; |
| 1641 | } |
| 1642 | } |
| 1643 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 1644 | if (!strcmp(ptn->name, "system") |
Deepa Dinamani | 13e32c4 | 2012-03-12 14:34:17 -0700 | [diff] [blame] | 1645 | || !strcmp(ptn->name, "userdata") |
| 1646 | || !strcmp(ptn->name, "persist") |
| 1647 | || !strcmp(ptn->name, "recoveryfs")) { |
Channagoud Kadabi | 404a706 | 2011-03-21 19:27:50 +0530 | [diff] [blame] | 1648 | if (flash_ecc_bch_enabled()) |
| 1649 | /* Spare data bytes for 8 bit ECC increased by 4 */ |
| 1650 | extra = ((page_size >> 9) * 20); |
| 1651 | else |
| 1652 | extra = ((page_size >> 9) * 16); |
| 1653 | } else |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 1654 | sz = ROUND_TO_PAGE(sz, page_mask); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1655 | |
| 1656 | dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name); |
| 1657 | if (flash_write(ptn, extra, data, sz)) { |
| 1658 | fastboot_fail("flash write failure"); |
| 1659 | return; |
| 1660 | } |
| 1661 | dprintf(INFO, "partition '%s' updated\n", ptn->name); |
| 1662 | fastboot_okay(""); |
| 1663 | } |
| 1664 | |
| 1665 | void cmd_continue(const char *arg, void *data, unsigned sz) |
| 1666 | { |
| 1667 | fastboot_okay(""); |
| 1668 | udc_stop(); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1669 | if (target_is_emmc_boot()) |
| 1670 | { |
| 1671 | boot_linux_from_mmc(); |
| 1672 | } |
| 1673 | else |
| 1674 | { |
| 1675 | boot_linux_from_flash(); |
| 1676 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 1679 | void cmd_reboot(const char *arg, void *data, unsigned sz) |
| 1680 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1681 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 1682 | fastboot_okay(""); |
| 1683 | reboot_device(0); |
| 1684 | } |
| 1685 | |
| 1686 | void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz) |
| 1687 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1688 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 1689 | fastboot_okay(""); |
| 1690 | reboot_device(FASTBOOT_MODE); |
| 1691 | } |
| 1692 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1693 | void cmd_oem_unlock(const char *arg, void *data, unsigned sz) |
| 1694 | { |
| 1695 | if(!device.is_unlocked) |
| 1696 | { |
| 1697 | device.is_unlocked = 1; |
| 1698 | write_device_info(&device); |
| 1699 | } |
| 1700 | fastboot_okay(""); |
| 1701 | } |
| 1702 | |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1703 | void cmd_oem_devinfo(const char *arg, void *data, unsigned sz) |
| 1704 | { |
| 1705 | char response[64]; |
| 1706 | snprintf(response, 64, "\tDevice tampered: %s", (device.is_tampered ? "true" : "false")); |
| 1707 | fastboot_info(response); |
| 1708 | snprintf(response, 64, "\tDevice unlocked: %s", (device.is_unlocked ? "true" : "false")); |
| 1709 | fastboot_info(response); |
| 1710 | fastboot_okay(""); |
| 1711 | } |
| 1712 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 1713 | void cmd_preflash(const char *arg, void *data, unsigned sz) |
| 1714 | { |
| 1715 | fastboot_okay(""); |
| 1716 | } |
| 1717 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 1718 | void splash_screen () |
| 1719 | { |
| 1720 | struct ptentry *ptn; |
| 1721 | struct ptable *ptable; |
| 1722 | struct fbcon_config *fb_display = NULL; |
| 1723 | |
| 1724 | if (!target_is_emmc_boot()) |
| 1725 | { |
| 1726 | ptable = flash_get_ptable(); |
| 1727 | if (ptable == NULL) { |
| 1728 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 1729 | return; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
| 1732 | ptn = ptable_find(ptable, "splash"); |
| 1733 | if (ptn == NULL) { |
| 1734 | dprintf(CRITICAL, "ERROR: No splash partition found\n"); |
| 1735 | } else { |
| 1736 | fb_display = fbcon_display(); |
| 1737 | if (fb_display) { |
| 1738 | if (flash_read(ptn, 0, fb_display->base, |
| 1739 | (fb_display->width * fb_display->height * fb_display->bpp/8))) { |
| 1740 | fbcon_clear(); |
| 1741 | dprintf(CRITICAL, "ERROR: Cannot read splash image\n"); |
| 1742 | } |
| 1743 | } |
| 1744 | } |
| 1745 | } |
| 1746 | } |
| 1747 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 1748 | /* Get the size from partiton name */ |
| 1749 | static void get_partition_size(const char *arg, char *response) |
| 1750 | { |
| 1751 | uint64_t ptn = 0; |
| 1752 | uint64_t size; |
| 1753 | int index = INVALID_PTN; |
| 1754 | |
| 1755 | index = partition_get_index(arg); |
| 1756 | |
| 1757 | if (index == INVALID_PTN) |
| 1758 | { |
| 1759 | dprintf(CRITICAL, "Invalid partition index\n"); |
| 1760 | return; |
| 1761 | } |
| 1762 | |
| 1763 | ptn = partition_get_offset(index); |
| 1764 | |
| 1765 | if(!ptn) |
| 1766 | { |
| 1767 | dprintf(CRITICAL, "Invalid partition name %s\n", arg); |
| 1768 | return; |
| 1769 | } |
| 1770 | |
| 1771 | size = partition_get_size(index); |
| 1772 | |
| 1773 | snprintf(response, MAX_RSP_SIZE, "\t 0x%llx", size); |
| 1774 | return; |
| 1775 | } |
| 1776 | |
| 1777 | /* |
| 1778 | * Publish the partition type & size info |
| 1779 | * fastboot getvar will publish the required information. |
| 1780 | * fastboot getvar partition_size:<partition_name>: partition size in hex |
| 1781 | * fastboot getvar partition_type:<partition_name>: partition type (ext/fat) |
| 1782 | */ |
| 1783 | static void publish_getvar_partition_info(struct getvar_partition_info *info, uint8_t num_parts) |
| 1784 | { |
| 1785 | uint8_t i; |
| 1786 | |
| 1787 | for (i = 0; i < num_parts; i++) { |
| 1788 | get_partition_size(info[i].part_name, info[i].size_response); |
| 1789 | |
| 1790 | if (strlcat(info[i].getvar_size, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 1791 | { |
| 1792 | dprintf(CRITICAL, "partition size name truncated\n"); |
| 1793 | return; |
| 1794 | } |
| 1795 | if (strlcat(info[i].getvar_type, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 1796 | { |
| 1797 | dprintf(CRITICAL, "partition type name truncated\n"); |
| 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | /* publish partition size & type info */ |
| 1802 | fastboot_publish((const char *) info[i].getvar_size, (const char *) info[i].size_response); |
| 1803 | fastboot_publish((const char *) info[i].getvar_type, (const char *) info[i].type_response); |
| 1804 | } |
| 1805 | } |
| 1806 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1807 | void aboot_init(const struct app_descriptor *app) |
| 1808 | { |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 1809 | unsigned reboot_mode = 0; |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1810 | unsigned usb_init = 0; |
Vivek Mehta | 5f1c9d4 | 2011-04-01 20:11:59 -0700 | [diff] [blame] | 1811 | unsigned sz = 0; |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1812 | bool boot_into_fastboot = false; |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 1813 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 1814 | /* Setup page size information for nand/emmc reads */ |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1815 | if (target_is_emmc_boot()) |
| 1816 | { |
| 1817 | page_size = 2048; |
| 1818 | page_mask = page_size - 1; |
| 1819 | } |
| 1820 | else |
| 1821 | { |
| 1822 | page_size = flash_page_size(); |
| 1823 | page_mask = page_size - 1; |
| 1824 | } |
| 1825 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1826 | if(target_use_signed_kernel()) |
| 1827 | { |
| 1828 | read_device_info(&device); |
| 1829 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1830 | } |
| 1831 | |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 1832 | target_serialno((unsigned char *) sn_buf); |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 1833 | dprintf(SPEW,"serial number: %s\n",sn_buf); |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 1834 | surf_udc_device.serialno = sn_buf; |
| 1835 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 1836 | /* Check if we should do something other than booting up */ |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame^] | 1837 | if (keys_get_state(KEY_VOLUMEUP) && keys_get_state(KEY_VOLUMEDOWN)) |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 1838 | { |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame^] | 1839 | dprintf(ALWAYS,"dload mode key sequence detected"); |
| 1840 | if (set_download_mode()) |
| 1841 | { |
| 1842 | dprintf(CRITICAL,"dload mode not supported by target"); |
| 1843 | } |
| 1844 | else |
| 1845 | { |
| 1846 | reboot_device(0); |
| 1847 | dprintf(CRITICAL,"Failed to reboot into dload mode"); |
| 1848 | } |
| 1849 | boot_into_fastboot = true; |
| 1850 | } |
| 1851 | if (!boot_into_fastboot) |
| 1852 | { |
| 1853 | if (keys_get_state(KEY_HOME) || keys_get_state(KEY_VOLUMEUP)) |
| 1854 | boot_into_recovery = 1; |
| 1855 | if (!boot_into_recovery && |
| 1856 | (keys_get_state(KEY_BACK) || keys_get_state(KEY_VOLUMEDOWN))) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1857 | boot_into_fastboot = true; |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 1858 | } |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1859 | #if NO_KEYPAD_DRIVER |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 1860 | if (fastboot_trigger()) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1861 | boot_into_fastboot = true; |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1862 | #endif |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 1863 | |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 1864 | reboot_mode = check_reboot_mode(); |
| 1865 | if (reboot_mode == RECOVERY_MODE) { |
| 1866 | boot_into_recovery = 1; |
| 1867 | } else if(reboot_mode == FASTBOOT_MODE) { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1868 | boot_into_fastboot = true; |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1871 | if (!boot_into_fastboot) |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1872 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1873 | if (target_is_emmc_boot()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1874 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1875 | if(emmc_recovery_init()) |
| 1876 | dprintf(ALWAYS,"error in emmc_recovery_init\n"); |
| 1877 | if(target_use_signed_kernel()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1878 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1879 | if((device.is_unlocked) || (device.is_tampered)) |
| 1880 | { |
| 1881 | #ifdef TZ_TAMPER_FUSE |
| 1882 | set_tamper_fuse_cmd(); |
| 1883 | #endif |
| 1884 | #if USE_PCOM_SECBOOT |
| 1885 | set_tamper_flag(device.is_tampered); |
| 1886 | #endif |
| 1887 | } |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1888 | } |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1889 | boot_linux_from_mmc(); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1890 | } |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 1891 | else |
| 1892 | { |
| 1893 | recovery_init(); |
| 1894 | #if USE_PCOM_SECBOOT |
| 1895 | if((device.is_unlocked) || (device.is_tampered)) |
| 1896 | set_tamper_flag(device.is_tampered); |
| 1897 | #endif |
| 1898 | boot_linux_from_flash(); |
| 1899 | } |
| 1900 | dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting " |
| 1901 | "to fastboot mode.\n"); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1902 | } |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 1903 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 1904 | sz = target_get_max_flash_size(); |
| 1905 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1906 | target_fastboot_init(); |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 1907 | |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1908 | if(!usb_init) |
| 1909 | udc_init(&surf_udc_device); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1910 | |
| 1911 | fastboot_register("boot", cmd_boot); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1912 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1913 | if (target_is_emmc_boot()) |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1914 | { |
| 1915 | fastboot_register("flash:", cmd_flash_mmc); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1916 | fastboot_register("erase:", cmd_erase_mmc); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1917 | } |
| 1918 | else |
| 1919 | { |
| 1920 | fastboot_register("flash:", cmd_flash); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1921 | fastboot_register("erase:", cmd_erase); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
| 1924 | fastboot_register("continue", cmd_continue); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 1925 | fastboot_register("reboot", cmd_reboot); |
| 1926 | fastboot_register("reboot-bootloader", cmd_reboot_bootloader); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1927 | fastboot_register("oem unlock", cmd_oem_unlock); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1928 | fastboot_register("oem device-info", cmd_oem_devinfo); |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 1929 | fastboot_register("preflash", cmd_preflash); |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 1930 | fastboot_publish("product", TARGET(BOARD)); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1931 | fastboot_publish("kernel", "lk"); |
Trevor Bourget | 59b25d5 | 2012-01-13 18:43:36 -0800 | [diff] [blame] | 1932 | fastboot_publish("serialno", sn_buf); |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 1933 | publish_getvar_partition_info(part_info, ARRAY_SIZE(part_info)); |
| 1934 | /* Max download size supported */ |
| 1935 | snprintf(max_download_size, MAX_RSP_SIZE, "\t0x%x", sz); |
| 1936 | fastboot_publish("max-download-size", (const char *) max_download_size); |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1937 | partition_dump(); |
Vivek Mehta | 5f1c9d4 | 2011-04-01 20:11:59 -0700 | [diff] [blame] | 1938 | fastboot_init(target_get_scratch_address(), sz); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1939 | udc_start(); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | APP_START(aboot) |
| 1943 | .init = aboot_init, |
| 1944 | APP_END |