Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2016, 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> |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 36 | #include <string.h> |
Channagoud Kadabi | 132ff55 | 2013-04-19 14:34:44 -0700 | [diff] [blame] | 37 | #include <stdlib.h> |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 38 | #include <limits.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> |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 43 | #include <dev/flash-ubi.h> |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 44 | #include <lib/ptable.h> |
Dima Zavin | b428360 | 2009-01-26 16:36:57 -0800 | [diff] [blame] | 45 | #include <dev/keys.h> |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 46 | #include <dev/fbcon.h> |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 47 | #include <baseband.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 48 | #include <target.h> |
| 49 | #include <mmc.h> |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 50 | #include <partition_parser.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 51 | #include <platform.h> |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 52 | #include <crypto_hash.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 53 | #include <malloc.h> |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 54 | #include <boot_stats.h> |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 55 | #include <sha.h> |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 56 | #include <platform/iomap.h> |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 57 | #include <boot_device.h> |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 58 | #include <boot_verifier.h> |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 59 | #include <image_verify.h> |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 60 | #include <decompress.h> |
Unnati Gandhi | 17b3bfc | 2015-05-11 12:58:16 +0530 | [diff] [blame] | 61 | #include <platform/timer.h> |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 62 | #include <sys/types.h> |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 63 | #if USE_RPMB_FOR_DEVINFO |
| 64 | #include <rpmb.h> |
| 65 | #endif |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 66 | |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 67 | #if ENABLE_WBC |
| 68 | #include <pm_app_smbchg.h> |
| 69 | #endif |
| 70 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 71 | #if DEVICE_TREE |
| 72 | #include <libfdt.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 73 | #include <dev_tree.h> |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 74 | #endif |
| 75 | |
Aparna Mallavarapu | 118ccae | 2015-06-03 13:47:11 +0530 | [diff] [blame] | 76 | #if WDOG_SUPPORT |
| 77 | #include <wdog.h> |
| 78 | #endif |
| 79 | |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 80 | #include <reboot.h> |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 81 | #include "image_verify.h" |
Shashank Mittal | 024c033 | 2010-02-03 11:44:00 -0800 | [diff] [blame] | 82 | #include "recovery.h" |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 83 | #include "bootimg.h" |
| 84 | #include "fastboot.h" |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 85 | #include "sparse_format.h" |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 86 | #include "meta_format.h" |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 87 | #include "mmc.h" |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 88 | #include "devinfo.h" |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 89 | #include "board.h" |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 90 | #include "scm.h" |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 91 | #include "mdtp.h" |
Sridhar Parasuram | 32b3066 | 2015-07-10 13:33:22 -0700 | [diff] [blame] | 92 | #include "secapp_loader.h" |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 93 | #include <menu_keys_detect.h> |
| 94 | #include <display_menu.h> |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 95 | #include "fastboot_test.h" |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 96 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 97 | extern bool target_use_signed_kernel(void); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 98 | extern void platform_uninit(void); |
Channagoud Kadabi | 33defe2 | 2013-06-18 18:35:40 -0700 | [diff] [blame] | 99 | extern void target_uninit(void); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 100 | extern int get_target_boot_params(const char *cmdline, const char *part, |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 101 | char **buf); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 102 | |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 103 | void *info_buf; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 104 | void write_device_info_mmc(device_info *dev); |
| 105 | void write_device_info_flash(device_info *dev); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 106 | static int aboot_save_boot_hash_mmc(uint32_t image_addr, uint32_t image_size); |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 107 | static int aboot_frp_unlock(char *pname, void *data, unsigned sz); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 108 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 109 | /* fastboot command function pointer */ |
| 110 | typedef void (*fastboot_cmd_fn) (const char *, void *, unsigned); |
| 111 | |
| 112 | struct fastboot_cmd_desc { |
| 113 | char * name; |
| 114 | fastboot_cmd_fn cb; |
| 115 | }; |
| 116 | |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 117 | #define EXPAND(NAME) #NAME |
| 118 | #define TARGET(NAME) EXPAND(NAME) |
Brian Swetland | 2defe16 | 2009-08-18 14:35:59 -0700 | [diff] [blame] | 119 | |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 120 | #ifdef MEMBASE |
| 121 | #define EMMC_BOOT_IMG_HEADER_ADDR (0xFF000+(MEMBASE)) |
| 122 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 123 | #define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000 |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 124 | #endif |
| 125 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 126 | #ifndef MEMSIZE |
| 127 | #define MEMSIZE 1024*1024 |
| 128 | #endif |
| 129 | |
| 130 | #define MAX_TAGS_SIZE 1024 |
| 131 | |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 132 | /* make 4096 as default size to ensure EFS,EXT4's erasing */ |
| 133 | #define DEFAULT_ERASE_SIZE 4096 |
Ujwal Patel | c0b0a25 | 2015-08-16 14:05:35 -0700 | [diff] [blame] | 134 | #define MAX_PANEL_BUF_SIZE 196 |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 135 | |
Dhaval Patel | f83d73b | 2014-06-23 16:24:37 -0700 | [diff] [blame] | 136 | #define DISPLAY_DEFAULT_PREFIX "mdss_mdp" |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 137 | #define BOOT_DEV_MAX_LEN 64 |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 138 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 139 | #define IS_ARM64(ptr) (ptr->magic_64 == KERNEL64_HDR_MAGIC) ? true : false |
| 140 | |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 141 | #define ADD_OF(a, b) (UINT_MAX - b > a) ? (a + b) : UINT_MAX |
| 142 | |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 143 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 144 | static const char *emmc_cmdline = " androidboot.bootdevice="; |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 145 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 146 | static const char *emmc_cmdline = " androidboot.emmc=true"; |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 147 | #endif |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 148 | static const char *usb_sn_cmdline = " androidboot.serialno="; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 149 | static const char *androidboot_mode = " androidboot.mode="; |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 150 | static const char *alarmboot_cmdline = " androidboot.alarmboot=true"; |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 151 | static const char *loglevel = " quiet"; |
Ajay Dudani | ca3a33c | 2011-11-18 08:31:40 -0800 | [diff] [blame] | 152 | static const char *battchg_pause = " androidboot.mode=charger"; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 153 | static const char *auth_kernel = " androidboot.authorized_kernel=true"; |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 154 | static const char *secondary_gpt_enable = " gpt"; |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 155 | static const char *mdtp_activated_flag = " mdtp"; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 156 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 157 | static const char *baseband_apq = " androidboot.baseband=apq"; |
| 158 | static const char *baseband_msm = " androidboot.baseband=msm"; |
| 159 | static const char *baseband_csfb = " androidboot.baseband=csfb"; |
| 160 | static const char *baseband_svlte2a = " androidboot.baseband=svlte2a"; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 161 | static const char *baseband_mdm = " androidboot.baseband=mdm"; |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 162 | static const char *baseband_mdm2 = " androidboot.baseband=mdm2"; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 163 | static const char *baseband_sglte = " androidboot.baseband=sglte"; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 164 | static const char *baseband_dsda = " androidboot.baseband=dsda"; |
| 165 | static const char *baseband_dsda2 = " androidboot.baseband=dsda2"; |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 166 | static const char *baseband_sglte2 = " androidboot.baseband=sglte2"; |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 167 | static const char *warmboot_cmdline = " qpnp-power-on.warm_boot=1"; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 168 | |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 169 | #if VERIFIED_BOOT |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 170 | #if !VBOOT_MOTA |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 171 | static const char *verity_mode = " androidboot.veritymode="; |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 172 | static const char *verified_state= " androidboot.verifiedbootstate="; |
Parth Dixit | a5715a0 | 2015-10-29 12:25:10 +0530 | [diff] [blame] | 173 | static const char *keymaster_v1= " androidboot.keymaster=1"; |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 174 | //indexed based on enum values, green is 0 by default |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 175 | |
| 176 | struct verified_boot_verity_mode vbvm[] = |
| 177 | { |
| 178 | {false, "logging"}, |
| 179 | {true, "enforcing"}, |
| 180 | }; |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 181 | struct verified_boot_state_name vbsn[] = |
| 182 | { |
| 183 | {GREEN, "green"}, |
| 184 | {ORANGE, "orange"}, |
| 185 | {YELLOW,"yellow"}, |
| 186 | {RED,"red" }, |
| 187 | }; |
| 188 | #endif |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 189 | #endif |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 190 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 191 | static unsigned page_size = 0; |
| 192 | static unsigned page_mask = 0; |
Gaurav Nebhwani | 4d2389c | 2016-03-17 21:10:05 +0530 | [diff] [blame] | 193 | static unsigned mmc_blocksize = 0; |
| 194 | static unsigned mmc_blocksize_mask = 0; |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 195 | static char ffbm_mode_string[FFBM_MODE_BUF_SIZE]; |
| 196 | static bool boot_into_ffbm; |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 197 | static char *target_boot_params = NULL; |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 198 | static bool boot_reason_alarm; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 199 | static bool devinfo_present = true; |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 200 | bool boot_into_fastboot = false; |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 201 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 202 | /* Assuming unauthorized kernel image by default */ |
| 203 | static int auth_kernel_img = 0; |
Parth Dixit | 6f5822f | 2015-10-18 01:20:53 +0530 | [diff] [blame] | 204 | #if VBOOT_MOTA |
| 205 | static device_info device = {DEVICE_MAGIC, 0, 0, 0, 0, {0}, {0},{0}}; |
| 206 | #else |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 207 | static device_info device = {DEVICE_MAGIC, 0, 0, 0, 0, {0}, {0},{0}, 1}; |
Parth Dixit | 6f5822f | 2015-10-18 01:20:53 +0530 | [diff] [blame] | 208 | #endif |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 209 | static bool is_allow_unlock = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 210 | |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 211 | static char frp_ptns[2][8] = {"config","frp"}; |
| 212 | |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 213 | static const char *critical_flash_allowed_ptn[] = { |
| 214 | "aboot", |
| 215 | "rpm", |
| 216 | "tz", |
| 217 | "sbl", |
| 218 | "sdi", |
| 219 | "sbl1", |
| 220 | "xbl", |
| 221 | "hyp", |
| 222 | "pmic", |
| 223 | "bootloader", |
| 224 | "devinfo", |
| 225 | "partition"}; |
| 226 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 227 | struct atag_ptbl_entry |
| 228 | { |
| 229 | char name[16]; |
| 230 | unsigned offset; |
| 231 | unsigned size; |
| 232 | unsigned flags; |
| 233 | }; |
| 234 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 235 | /* |
| 236 | * Partition info, required to be published |
| 237 | * for fastboot |
| 238 | */ |
| 239 | struct getvar_partition_info { |
| 240 | const char part_name[MAX_GPT_NAME_SIZE]; /* Partition name */ |
| 241 | char getvar_size[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for size */ |
| 242 | char getvar_type[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for type */ |
| 243 | char size_response[MAX_RSP_SIZE]; /* fastboot response for size */ |
| 244 | char type_response[MAX_RSP_SIZE]; /* fastboot response for type */ |
| 245 | }; |
| 246 | |
| 247 | /* |
| 248 | * Right now, we are publishing the info for only |
| 249 | * three partitions |
| 250 | */ |
| 251 | struct getvar_partition_info part_info[] = |
| 252 | { |
| 253 | { "system" , "partition-size:", "partition-type:", "", "ext4" }, |
| 254 | { "userdata", "partition-size:", "partition-type:", "", "ext4" }, |
| 255 | { "cache" , "partition-size:", "partition-type:", "", "ext4" }, |
| 256 | }; |
| 257 | |
| 258 | char max_download_size[MAX_RSP_SIZE]; |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 259 | char charger_screen_enabled[MAX_RSP_SIZE]; |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 260 | char sn_buf[13]; |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 261 | char display_panel_buf[MAX_PANEL_BUF_SIZE]; |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 262 | char panel_display_mode[MAX_RSP_SIZE]; |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 263 | |
| 264 | #if CHECK_BAT_VOLTAGE |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 265 | char battery_voltage[MAX_RSP_SIZE]; |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 266 | char battery_soc_ok [MAX_RSP_SIZE]; |
| 267 | #endif |
| 268 | |
lijuang | f16461c | 2015-08-03 17:09:34 +0800 | [diff] [blame] | 269 | char get_variant[MAX_RSP_SIZE]; |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 270 | |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 271 | extern int emmc_recovery_init(void); |
| 272 | |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 273 | #if NO_KEYPAD_DRIVER |
| 274 | extern int fastboot_trigger(void); |
| 275 | #endif |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 276 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 277 | static void update_ker_tags_rdisk_addr(struct boot_img_hdr *hdr, bool is_arm64) |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 278 | { |
| 279 | /* overwrite the destination of specified for the project */ |
Channagoud Kadabi | 7042fa3 | 2013-04-26 16:44:14 -0700 | [diff] [blame] | 280 | #ifdef ABOOT_IGNORE_BOOT_HEADER_ADDRS |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 281 | if (is_arm64) |
| 282 | hdr->kernel_addr = ABOOT_FORCE_KERNEL64_ADDR; |
| 283 | else |
| 284 | hdr->kernel_addr = ABOOT_FORCE_KERNEL_ADDR; |
Channagoud Kadabi | 7042fa3 | 2013-04-26 16:44:14 -0700 | [diff] [blame] | 285 | hdr->ramdisk_addr = ABOOT_FORCE_RAMDISK_ADDR; |
| 286 | hdr->tags_addr = ABOOT_FORCE_TAGS_ADDR; |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 287 | #endif |
| 288 | } |
| 289 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 290 | static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn) |
| 291 | { |
| 292 | struct atag_ptbl_entry atag_ptn; |
| 293 | |
| 294 | memcpy(atag_ptn.name, ptn->name, 16); |
| 295 | atag_ptn.name[15] = '\0'; |
| 296 | atag_ptn.offset = ptn->start; |
| 297 | atag_ptn.size = ptn->length; |
| 298 | atag_ptn.flags = ptn->flags; |
| 299 | memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry)); |
| 300 | *ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned); |
| 301 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 302 | |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 303 | #if CHECK_BAT_VOLTAGE |
| 304 | void update_battery_status(void) |
| 305 | { |
| 306 | snprintf(battery_voltage,MAX_RSP_SIZE, "%d",target_get_battery_voltage()); |
| 307 | snprintf(battery_soc_ok ,MAX_RSP_SIZE, "%s",target_battery_soc_ok()? "yes":"no"); |
| 308 | } |
| 309 | #endif |
| 310 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 311 | unsigned char *update_cmdline(const char * cmdline) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 312 | { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 313 | int cmdline_len = 0; |
| 314 | int have_cmdline = 0; |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 315 | unsigned char *cmdline_final = NULL; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 316 | int pause_at_bootup = 0; |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 317 | bool warm_boot = false; |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 318 | bool gpt_exists = partition_gpt_exists(); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 319 | int have_target_boot_params = 0; |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 320 | char *boot_dev_buf = NULL; |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 321 | bool is_mdtp_activated = 0; |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 322 | #if VERIFIED_BOOT |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 323 | #if !VBOOT_MOTA |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 324 | uint32_t boot_state = boot_verify_get_state(); |
| 325 | #endif |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 326 | #endif |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 327 | |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 328 | #ifdef MDTP_SUPPORT |
| 329 | mdtp_activated(&is_mdtp_activated); |
| 330 | #endif /* MDTP_SUPPORT */ |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 331 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 332 | if (cmdline && cmdline[0]) { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 333 | cmdline_len = strlen(cmdline); |
| 334 | have_cmdline = 1; |
| 335 | } |
| 336 | if (target_is_emmc_boot()) { |
| 337 | cmdline_len += strlen(emmc_cmdline); |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 338 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 339 | boot_dev_buf = (char *) malloc(sizeof(char) * BOOT_DEV_MAX_LEN); |
| 340 | ASSERT(boot_dev_buf); |
| 341 | platform_boot_dev_cmdline(boot_dev_buf); |
| 342 | cmdline_len += strlen(boot_dev_buf); |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 343 | #endif |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 344 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 345 | |
| 346 | cmdline_len += strlen(usb_sn_cmdline); |
| 347 | cmdline_len += strlen(sn_buf); |
| 348 | |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 349 | #if VERIFIED_BOOT |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 350 | #if !VBOOT_MOTA |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 351 | cmdline_len += strlen(verified_state) + strlen(vbsn[boot_state].name); |
Sridhar Parasuram | 7d8bb9a | 2015-09-23 18:21:19 -0700 | [diff] [blame] | 352 | if ((device.verity_mode != 0 ) && (device.verity_mode != 1)) |
| 353 | { |
| 354 | dprintf(CRITICAL, "Devinfo paritition possibly corrupted!!!. Please erase devinfo partition to continue booting\n"); |
| 355 | ASSERT(0); |
| 356 | } |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 357 | cmdline_len += strlen(verity_mode) + strlen(vbvm[device.verity_mode].name); |
Parth Dixit | a5715a0 | 2015-10-29 12:25:10 +0530 | [diff] [blame] | 358 | cmdline_len += strlen(keymaster_v1); |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 359 | #endif |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 360 | #endif |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 361 | |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 362 | if (boot_into_recovery && gpt_exists) |
| 363 | cmdline_len += strlen(secondary_gpt_enable); |
| 364 | |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 365 | if(is_mdtp_activated) |
| 366 | cmdline_len += strlen(mdtp_activated_flag); |
| 367 | |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 368 | if (boot_into_ffbm) { |
| 369 | cmdline_len += strlen(androidboot_mode); |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 370 | cmdline_len += strlen(ffbm_mode_string); |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 371 | /* reduce kernel console messages to speed-up boot */ |
| 372 | cmdline_len += strlen(loglevel); |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 373 | } else if (boot_reason_alarm) { |
| 374 | cmdline_len += strlen(alarmboot_cmdline); |
Zhenhua Huang | 431dafa | 2015-06-30 16:13:37 +0800 | [diff] [blame] | 375 | } else if ((target_build_variant_user() || device.charger_screen_enabled) |
| 376 | && target_pause_for_battery_charge()) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 377 | pause_at_bootup = 1; |
| 378 | cmdline_len += strlen(battchg_pause); |
| 379 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 380 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 381 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 382 | cmdline_len += strlen(auth_kernel); |
| 383 | } |
| 384 | |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 385 | if (get_target_boot_params(cmdline, boot_into_recovery ? "recoveryfs" : |
| 386 | "system", |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 387 | &target_boot_params) == 0) { |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 388 | have_target_boot_params = 1; |
| 389 | cmdline_len += strlen(target_boot_params); |
| 390 | } |
| 391 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 392 | /* Determine correct androidboot.baseband to use */ |
| 393 | switch(target_baseband()) |
| 394 | { |
| 395 | case BASEBAND_APQ: |
| 396 | cmdline_len += strlen(baseband_apq); |
| 397 | break; |
| 398 | |
| 399 | case BASEBAND_MSM: |
| 400 | cmdline_len += strlen(baseband_msm); |
| 401 | break; |
| 402 | |
| 403 | case BASEBAND_CSFB: |
| 404 | cmdline_len += strlen(baseband_csfb); |
| 405 | break; |
| 406 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 407 | case BASEBAND_SVLTE2A: |
| 408 | cmdline_len += strlen(baseband_svlte2a); |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 409 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 410 | |
| 411 | case BASEBAND_MDM: |
| 412 | cmdline_len += strlen(baseband_mdm); |
| 413 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 414 | |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 415 | case BASEBAND_MDM2: |
| 416 | cmdline_len += strlen(baseband_mdm2); |
| 417 | break; |
| 418 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 419 | case BASEBAND_SGLTE: |
| 420 | cmdline_len += strlen(baseband_sglte); |
| 421 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 422 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 423 | case BASEBAND_SGLTE2: |
| 424 | cmdline_len += strlen(baseband_sglte2); |
| 425 | break; |
| 426 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 427 | case BASEBAND_DSDA: |
| 428 | cmdline_len += strlen(baseband_dsda); |
| 429 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 430 | |
| 431 | case BASEBAND_DSDA2: |
| 432 | cmdline_len += strlen(baseband_dsda2); |
| 433 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 434 | } |
| 435 | |
Lijuan Gao | 4a5b832 | 2014-07-24 10:38:42 +0800 | [diff] [blame] | 436 | if (cmdline) { |
| 437 | if ((strstr(cmdline, DISPLAY_DEFAULT_PREFIX) == NULL) && |
Padmanabhan Komanduru | bccbcdc | 2015-06-30 16:19:24 +0530 | [diff] [blame] | 438 | target_display_panel_node(display_panel_buf, |
| 439 | MAX_PANEL_BUF_SIZE) && |
Lijuan Gao | 4a5b832 | 2014-07-24 10:38:42 +0800 | [diff] [blame] | 440 | strlen(display_panel_buf)) { |
| 441 | cmdline_len += strlen(display_panel_buf); |
| 442 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 445 | if (target_warm_boot()) { |
| 446 | warm_boot = true; |
| 447 | cmdline_len += strlen(warmboot_cmdline); |
| 448 | } |
| 449 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 450 | if (cmdline_len > 0) { |
| 451 | const char *src; |
Maria Yu | 52254c0 | 2014-07-04 16:14:54 +0800 | [diff] [blame] | 452 | unsigned char *dst; |
| 453 | |
| 454 | cmdline_final = (unsigned char*) malloc((cmdline_len + 4) & (~3)); |
| 455 | ASSERT(cmdline_final != NULL); |
vijay kumar | 287bb54 | 2015-09-29 13:01:52 +0530 | [diff] [blame] | 456 | memset((void *)cmdline_final, 0, sizeof(*cmdline_final)); |
Maria Yu | 52254c0 | 2014-07-04 16:14:54 +0800 | [diff] [blame] | 457 | dst = cmdline_final; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 458 | |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 459 | /* Save start ptr for debug print */ |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 460 | if (have_cmdline) { |
| 461 | src = cmdline; |
| 462 | while ((*dst++ = *src++)); |
| 463 | } |
| 464 | if (target_is_emmc_boot()) { |
| 465 | src = emmc_cmdline; |
| 466 | if (have_cmdline) --dst; |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 467 | have_cmdline = 1; |
| 468 | while ((*dst++ = *src++)); |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 469 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 470 | src = boot_dev_buf; |
| 471 | if (have_cmdline) --dst; |
| 472 | while ((*dst++ = *src++)); |
| 473 | #endif |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 474 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 475 | |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 476 | #if VERIFIED_BOOT |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 477 | #if !VBOOT_MOTA |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 478 | src = verified_state; |
| 479 | if(have_cmdline) --dst; |
| 480 | have_cmdline = 1; |
| 481 | while ((*dst++ = *src++)); |
| 482 | src = vbsn[boot_state].name; |
| 483 | if(have_cmdline) --dst; |
| 484 | while ((*dst++ = *src++)); |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 485 | |
Sridhar Parasuram | 7d8bb9a | 2015-09-23 18:21:19 -0700 | [diff] [blame] | 486 | if ((device.verity_mode != 0 ) && (device.verity_mode != 1)) |
| 487 | { |
| 488 | dprintf(CRITICAL, "Devinfo paritition possibly corrupted!!!. Please erase devinfo partition to continue booting\n"); |
| 489 | ASSERT(0); |
| 490 | } |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 491 | src = verity_mode; |
| 492 | if(have_cmdline) --dst; |
| 493 | while ((*dst++ = *src++)); |
| 494 | src = vbvm[device.verity_mode].name; |
| 495 | if(have_cmdline) -- dst; |
| 496 | while ((*dst++ = *src++)); |
Parth Dixit | a5715a0 | 2015-10-29 12:25:10 +0530 | [diff] [blame] | 497 | src = keymaster_v1; |
| 498 | if(have_cmdline) --dst; |
| 499 | while ((*dst++ = *src++)); |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 500 | #endif |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 501 | #endif |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 502 | src = usb_sn_cmdline; |
| 503 | if (have_cmdline) --dst; |
| 504 | have_cmdline = 1; |
| 505 | while ((*dst++ = *src++)); |
| 506 | src = sn_buf; |
| 507 | if (have_cmdline) --dst; |
| 508 | have_cmdline = 1; |
| 509 | while ((*dst++ = *src++)); |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 510 | if (warm_boot) { |
| 511 | if (have_cmdline) --dst; |
| 512 | src = warmboot_cmdline; |
| 513 | while ((*dst++ = *src++)); |
| 514 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 515 | |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 516 | if (boot_into_recovery && gpt_exists) { |
| 517 | src = secondary_gpt_enable; |
| 518 | if (have_cmdline) --dst; |
| 519 | while ((*dst++ = *src++)); |
| 520 | } |
| 521 | |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 522 | if (is_mdtp_activated) { |
| 523 | src = mdtp_activated_flag; |
| 524 | if (have_cmdline) --dst; |
| 525 | while ((*dst++ = *src++)); |
| 526 | } |
| 527 | |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 528 | if (boot_into_ffbm) { |
| 529 | src = androidboot_mode; |
| 530 | if (have_cmdline) --dst; |
| 531 | while ((*dst++ = *src++)); |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 532 | src = ffbm_mode_string; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 533 | if (have_cmdline) --dst; |
| 534 | while ((*dst++ = *src++)); |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 535 | src = loglevel; |
| 536 | if (have_cmdline) --dst; |
| 537 | while ((*dst++ = *src++)); |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 538 | } else if (boot_reason_alarm) { |
| 539 | src = alarmboot_cmdline; |
| 540 | if (have_cmdline) --dst; |
| 541 | while ((*dst++ = *src++)); |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 542 | } else if (pause_at_bootup) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 543 | src = battchg_pause; |
| 544 | if (have_cmdline) --dst; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 545 | while ((*dst++ = *src++)); |
| 546 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 547 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 548 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 549 | src = auth_kernel; |
| 550 | if (have_cmdline) --dst; |
| 551 | while ((*dst++ = *src++)); |
| 552 | } |
| 553 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 554 | switch(target_baseband()) |
| 555 | { |
| 556 | case BASEBAND_APQ: |
| 557 | src = baseband_apq; |
| 558 | if (have_cmdline) --dst; |
| 559 | while ((*dst++ = *src++)); |
| 560 | break; |
| 561 | |
| 562 | case BASEBAND_MSM: |
| 563 | src = baseband_msm; |
| 564 | if (have_cmdline) --dst; |
| 565 | while ((*dst++ = *src++)); |
| 566 | break; |
| 567 | |
| 568 | case BASEBAND_CSFB: |
| 569 | src = baseband_csfb; |
| 570 | if (have_cmdline) --dst; |
| 571 | while ((*dst++ = *src++)); |
| 572 | break; |
| 573 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 574 | case BASEBAND_SVLTE2A: |
| 575 | src = baseband_svlte2a; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 576 | if (have_cmdline) --dst; |
| 577 | while ((*dst++ = *src++)); |
| 578 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 579 | |
| 580 | case BASEBAND_MDM: |
| 581 | src = baseband_mdm; |
| 582 | if (have_cmdline) --dst; |
| 583 | while ((*dst++ = *src++)); |
| 584 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 585 | |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 586 | case BASEBAND_MDM2: |
| 587 | src = baseband_mdm2; |
| 588 | if (have_cmdline) --dst; |
| 589 | while ((*dst++ = *src++)); |
| 590 | break; |
| 591 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 592 | case BASEBAND_SGLTE: |
| 593 | src = baseband_sglte; |
| 594 | if (have_cmdline) --dst; |
| 595 | while ((*dst++ = *src++)); |
| 596 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 597 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 598 | case BASEBAND_SGLTE2: |
| 599 | src = baseband_sglte2; |
| 600 | if (have_cmdline) --dst; |
| 601 | while ((*dst++ = *src++)); |
| 602 | break; |
| 603 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 604 | case BASEBAND_DSDA: |
| 605 | src = baseband_dsda; |
| 606 | if (have_cmdline) --dst; |
| 607 | while ((*dst++ = *src++)); |
| 608 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 609 | |
| 610 | case BASEBAND_DSDA2: |
| 611 | src = baseband_dsda2; |
| 612 | if (have_cmdline) --dst; |
| 613 | while ((*dst++ = *src++)); |
| 614 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 615 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 616 | |
| 617 | if (strlen(display_panel_buf)) { |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 618 | src = display_panel_buf; |
| 619 | if (have_cmdline) --dst; |
| 620 | while ((*dst++ = *src++)); |
| 621 | } |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 622 | |
| 623 | if (have_target_boot_params) { |
| 624 | if (have_cmdline) --dst; |
| 625 | src = target_boot_params; |
| 626 | while ((*dst++ = *src++)); |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 627 | free(target_boot_params); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 628 | } |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 629 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 630 | |
| 631 | |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 632 | if (boot_dev_buf) |
| 633 | free(boot_dev_buf); |
| 634 | |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 635 | if (cmdline_final) |
| 636 | dprintf(INFO, "cmdline: %s\n", cmdline_final); |
| 637 | else |
| 638 | dprintf(INFO, "cmdline is NULL\n"); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 639 | return cmdline_final; |
| 640 | } |
| 641 | |
| 642 | unsigned *atag_core(unsigned *ptr) |
| 643 | { |
| 644 | /* CORE */ |
| 645 | *ptr++ = 2; |
| 646 | *ptr++ = 0x54410001; |
| 647 | |
| 648 | return ptr; |
| 649 | |
| 650 | } |
| 651 | |
| 652 | unsigned *atag_ramdisk(unsigned *ptr, void *ramdisk, |
| 653 | unsigned ramdisk_size) |
| 654 | { |
| 655 | if (ramdisk_size) { |
| 656 | *ptr++ = 4; |
| 657 | *ptr++ = 0x54420005; |
| 658 | *ptr++ = (unsigned)ramdisk; |
| 659 | *ptr++ = ramdisk_size; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 660 | } |
| 661 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 662 | return ptr; |
| 663 | } |
| 664 | |
| 665 | unsigned *atag_ptable(unsigned **ptr_addr) |
| 666 | { |
| 667 | int i; |
| 668 | struct ptable *ptable; |
| 669 | |
| 670 | if ((ptable = flash_get_ptable()) && (ptable->count != 0)) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 671 | *(*ptr_addr)++ = 2 + (ptable->count * (sizeof(struct atag_ptbl_entry) / |
| 672 | sizeof(unsigned))); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 673 | *(*ptr_addr)++ = 0x4d534d70; |
| 674 | for (i = 0; i < ptable->count; ++i) |
| 675 | ptentry_to_tag(ptr_addr, ptable_get(ptable, i)); |
| 676 | } |
| 677 | |
| 678 | return (*ptr_addr); |
| 679 | } |
| 680 | |
| 681 | unsigned *atag_cmdline(unsigned *ptr, const char *cmdline) |
| 682 | { |
| 683 | int cmdline_length = 0; |
| 684 | int n; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 685 | char *dest; |
| 686 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 687 | cmdline_length = strlen((const char*)cmdline); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 688 | n = (cmdline_length + 4) & (~3); |
| 689 | |
| 690 | *ptr++ = (n / 4) + 2; |
| 691 | *ptr++ = 0x54410009; |
| 692 | dest = (char *) ptr; |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 693 | while ((*dest++ = *cmdline++)); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 694 | ptr += (n / 4); |
| 695 | |
| 696 | return ptr; |
| 697 | } |
| 698 | |
| 699 | unsigned *atag_end(unsigned *ptr) |
| 700 | { |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 701 | /* END */ |
| 702 | *ptr++ = 0; |
| 703 | *ptr++ = 0; |
| 704 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 705 | return ptr; |
| 706 | } |
| 707 | |
| 708 | void generate_atags(unsigned *ptr, const char *cmdline, |
| 709 | void *ramdisk, unsigned ramdisk_size) |
| 710 | { |
| 711 | |
| 712 | ptr = atag_core(ptr); |
| 713 | ptr = atag_ramdisk(ptr, ramdisk, ramdisk_size); |
| 714 | ptr = target_atag_mem(ptr); |
| 715 | |
| 716 | /* Skip NAND partition ATAGS for eMMC boot */ |
| 717 | if (!target_is_emmc_boot()){ |
| 718 | ptr = atag_ptable(&ptr); |
| 719 | } |
| 720 | |
| 721 | ptr = atag_cmdline(ptr, cmdline); |
| 722 | ptr = atag_end(ptr); |
| 723 | } |
| 724 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 725 | typedef void entry_func_ptr(unsigned, unsigned, unsigned*); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 726 | void boot_linux(void *kernel, unsigned *tags, |
| 727 | const char *cmdline, unsigned machtype, |
| 728 | void *ramdisk, unsigned ramdisk_size) |
| 729 | { |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 730 | unsigned char *final_cmdline; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 731 | #if DEVICE_TREE |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 732 | int ret = 0; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 733 | #endif |
| 734 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 735 | void (*entry)(unsigned, unsigned, unsigned*) = (entry_func_ptr*)(PA((addr_t)kernel)); |
Deepa Dinamani | 25a9f76 | 2012-11-30 15:57:15 -0800 | [diff] [blame] | 736 | uint32_t tags_phys = PA((addr_t)tags); |
vijay kumar | 1a50a64 | 2015-11-16 12:41:15 +0530 | [diff] [blame] | 737 | struct kernel64_hdr *kptr = ((struct kernel64_hdr*)(PA((addr_t)kernel))); |
Deepa Dinamani | 25a9f76 | 2012-11-30 15:57:15 -0800 | [diff] [blame] | 738 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 739 | ramdisk = (void *)PA((addr_t)ramdisk); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 740 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 741 | final_cmdline = update_cmdline((const char*)cmdline); |
| 742 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 743 | #if DEVICE_TREE |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 744 | dprintf(INFO, "Updating device tree: start\n"); |
| 745 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 746 | /* Update the Device Tree */ |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 747 | ret = update_device_tree((void *)tags,(const char *)final_cmdline, ramdisk, ramdisk_size); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 748 | if(ret) |
| 749 | { |
| 750 | dprintf(CRITICAL, "ERROR: Updating Device Tree Failed \n"); |
| 751 | ASSERT(0); |
| 752 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 753 | dprintf(INFO, "Updating device tree: done\n"); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 754 | #else |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 755 | /* Generating the Atags */ |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 756 | generate_atags(tags, final_cmdline, ramdisk, ramdisk_size); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 757 | #endif |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 758 | |
Maria Yu | 52254c0 | 2014-07-04 16:14:54 +0800 | [diff] [blame] | 759 | free(final_cmdline); |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 760 | |
| 761 | #if VERIFIED_BOOT |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 762 | #if !VBOOT_MOTA |
| 763 | if (device.verity_mode == 0) { |
| 764 | #if FBCON_DISPLAY_MSG |
| 765 | display_bootverify_menu(DISPLAY_MENU_LOGGING); |
| 766 | wait_for_users_action(); |
| 767 | #else |
| 768 | dprintf(CRITICAL, |
| 769 | "The dm-verity is not started in enforcing mode.\nWait for 5 seconds before proceeding\n"); |
| 770 | mdelay(5000); |
| 771 | #endif |
| 772 | } |
| 773 | |
| 774 | #endif |
| 775 | #endif |
| 776 | |
| 777 | #if VERIFIED_BOOT |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 778 | /* Write protect the device info */ |
Channagoud Kadabi | 3bd9d1e | 2015-05-05 16:18:20 -0700 | [diff] [blame] | 779 | if (!boot_into_recovery && target_build_variant_user() && devinfo_present && mmc_write_protect("devinfo", 1)) |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 780 | { |
| 781 | dprintf(INFO, "Failed to write protect dev info\n"); |
| 782 | ASSERT(0); |
| 783 | } |
| 784 | #endif |
| 785 | |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 786 | /* Turn off splash screen if enabled */ |
| 787 | #if DISPLAY_SPLASH_SCREEN |
| 788 | target_display_shutdown(); |
| 789 | #endif |
| 790 | |
Veera Sundaram Sankaran | 67ea093 | 2015-09-25 10:09:30 -0700 | [diff] [blame] | 791 | /* Perform target specific cleanup */ |
| 792 | target_uninit(); |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 793 | |
Deepa Dinamani | 33734bc | 2013-03-06 12:16:06 -0800 | [diff] [blame] | 794 | dprintf(INFO, "booting linux @ %p, ramdisk @ %p (%d), tags/device tree @ %p\n", |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 795 | entry, ramdisk, ramdisk_size, (void *)tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 796 | |
| 797 | enter_critical_section(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 798 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 799 | /* do any platform specific cleanup before kernel entry */ |
| 800 | platform_uninit(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 801 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 802 | arch_disable_cache(UCACHE); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 803 | |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 804 | #if ARM_WITH_MMU |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 805 | arch_disable_mmu(); |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 806 | #endif |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 807 | bs_set_timestamp(BS_KERNEL_ENTRY); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 808 | |
| 809 | if (IS_ARM64(kptr)) |
| 810 | /* Jump to a 64bit kernel */ |
| 811 | scm_elexec_call((paddr_t)kernel, tags_phys); |
| 812 | else |
| 813 | /* Jump to a 32bit kernel */ |
| 814 | entry(0, machtype, (unsigned*)tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 817 | /* Function to check if the memory address range falls within the aboot |
| 818 | * boundaries. |
| 819 | * start: Start of the memory region |
| 820 | * size: Size of the memory region |
| 821 | */ |
Vijay Kumar Pendoti | 9c002ad | 2016-03-09 13:52:45 +0530 | [diff] [blame^] | 822 | int check_aboot_addr_range_overlap(uintptr_t start, uint32_t size) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 823 | { |
| 824 | /* Check for boundary conditions. */ |
Sundarajan Srinivasan | ce2a0ea | 2013-12-16 17:02:56 -0800 | [diff] [blame] | 825 | if ((UINT_MAX - start) < size) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 826 | return -1; |
| 827 | |
| 828 | /* Check for memory overlap. */ |
| 829 | if ((start < MEMBASE) && ((start + size) <= MEMBASE)) |
| 830 | return 0; |
Channagoud Kadabi | 9414391 | 2013-10-15 12:53:52 -0700 | [diff] [blame] | 831 | else if (start >= (MEMBASE + MEMSIZE)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 832 | return 0; |
| 833 | else |
| 834 | return -1; |
| 835 | } |
| 836 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 837 | #define ROUND_TO_PAGE(x,y) (((x) + (y)) & (~(y))) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 838 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 839 | BUF_DMA_ALIGN(buf, BOOT_IMG_MAX_PAGE_SIZE); //Equal to max-supported pagesize |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 840 | #if DEVICE_TREE |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 841 | BUF_DMA_ALIGN(dt_buf, BOOT_IMG_MAX_PAGE_SIZE); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 842 | #endif |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 843 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 844 | static void verify_signed_bootimg(uint32_t bootimg_addr, uint32_t bootimg_size) |
| 845 | { |
| 846 | int ret; |
Channagoud Kadabi | a8c623f | 2015-01-13 14:48:48 -0800 | [diff] [blame] | 847 | |
| 848 | #if !VERIFIED_BOOT |
Sundarajan Srinivasan | ce54d6e | 2013-11-11 12:45:00 -0800 | [diff] [blame] | 849 | #if IMAGE_VERIF_ALGO_SHA1 |
| 850 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA1; |
| 851 | #else |
| 852 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA256; |
| 853 | #endif |
Channagoud Kadabi | a8c623f | 2015-01-13 14:48:48 -0800 | [diff] [blame] | 854 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 855 | |
| 856 | /* Assume device is rooted at this time. */ |
| 857 | device.is_tampered = 1; |
| 858 | |
| 859 | dprintf(INFO, "Authenticating boot image (%d): start\n", bootimg_size); |
| 860 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 861 | #if VERIFIED_BOOT |
| 862 | if(boot_into_recovery) |
| 863 | { |
| 864 | ret = boot_verify_image((unsigned char *)bootimg_addr, |
Unnati Gandhi | 4705125 | 2015-03-02 15:21:09 +0530 | [diff] [blame] | 865 | bootimg_size, "/recovery"); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 866 | } |
| 867 | else |
| 868 | { |
| 869 | ret = boot_verify_image((unsigned char *)bootimg_addr, |
Unnati Gandhi | 4705125 | 2015-03-02 15:21:09 +0530 | [diff] [blame] | 870 | bootimg_size, "/boot"); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 871 | } |
| 872 | boot_verify_print_state(); |
| 873 | #else |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 874 | ret = image_verify((unsigned char *)bootimg_addr, |
| 875 | (unsigned char *)(bootimg_addr + bootimg_size), |
| 876 | bootimg_size, |
Sundarajan Srinivasan | ce54d6e | 2013-11-11 12:45:00 -0800 | [diff] [blame] | 877 | auth_algo); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 878 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 879 | dprintf(INFO, "Authenticating boot image: done return value = %d\n", ret); |
| 880 | |
| 881 | if (ret) |
| 882 | { |
| 883 | /* Authorized kernel */ |
| 884 | device.is_tampered = 0; |
Sundarajan Srinivasan | 3fb21f1 | 2013-09-16 18:36:15 -0700 | [diff] [blame] | 885 | auth_kernel_img = 1; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 886 | } |
| 887 | |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 888 | #ifdef MDTP_SUPPORT |
| 889 | { |
| 890 | /* Verify MDTP lock. |
| 891 | * For boot & recovery partitions, use aboot's verification result. |
| 892 | */ |
| 893 | mdtp_ext_partition_verification_t ext_partition; |
| 894 | ext_partition.partition = boot_into_recovery ? MDTP_PARTITION_RECOVERY : MDTP_PARTITION_BOOT; |
| 895 | ext_partition.integrity_state = device.is_tampered ? MDTP_PARTITION_STATE_INVALID : MDTP_PARTITION_STATE_VALID; |
| 896 | ext_partition.page_size = 0; /* Not needed since already validated */ |
| 897 | ext_partition.image_addr = 0; /* Not needed since already validated */ |
| 898 | ext_partition.image_size = 0; /* Not needed since already validated */ |
| 899 | ext_partition.sig_avail = FALSE; /* Not needed since already validated */ |
| 900 | mdtp_fwlock_verify_lock(&ext_partition); |
| 901 | } |
| 902 | #endif /* MDTP_SUPPORT */ |
| 903 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 904 | #if USE_PCOM_SECBOOT |
| 905 | set_tamper_flag(device.is_tampered); |
| 906 | #endif |
| 907 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 908 | #if VERIFIED_BOOT |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 909 | switch(boot_verify_get_state()) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 910 | { |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 911 | case RED: |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 912 | #if FBCON_DISPLAY_MSG |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 913 | display_bootverify_menu(DISPLAY_MENU_RED); |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 914 | wait_for_users_action(); |
| 915 | #else |
| 916 | dprintf(CRITICAL, |
| 917 | "Your device has failed verification and may not work properly.\nWait for 5 seconds before proceeding\n"); |
| 918 | mdelay(5000); |
| 919 | #endif |
| 920 | |
| 921 | break; |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 922 | case YELLOW: |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 923 | #if FBCON_DISPLAY_MSG |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 924 | display_bootverify_menu(DISPLAY_MENU_YELLOW); |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 925 | wait_for_users_action(); |
| 926 | #else |
| 927 | dprintf(CRITICAL, |
| 928 | "Your device has loaded a different operating system.\nWait for 5 seconds before proceeding\n"); |
| 929 | mdelay(5000); |
| 930 | #endif |
| 931 | break; |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 932 | default: |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 933 | break; |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 934 | } |
| 935 | #endif |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 936 | #if !VERIFIED_BOOT |
Unnati Gandhi | 1be0475 | 2015-03-27 19:41:53 +0530 | [diff] [blame] | 937 | if(device.is_tampered) |
| 938 | { |
| 939 | write_device_info_mmc(&device); |
| 940 | #ifdef TZ_TAMPER_FUSE |
| 941 | set_tamper_fuse_cmd(); |
| 942 | #endif |
| 943 | #ifdef ASSERT_ON_TAMPER |
| 944 | dprintf(CRITICAL, "Device is tampered. Asserting..\n"); |
| 945 | ASSERT(0); |
| 946 | #endif |
| 947 | } |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 948 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 951 | static bool check_format_bit() |
| 952 | { |
| 953 | bool ret = false; |
| 954 | int index; |
| 955 | uint64_t offset; |
| 956 | struct boot_selection_info *in = NULL; |
| 957 | char *buf = NULL; |
| 958 | |
| 959 | index = partition_get_index("bootselect"); |
| 960 | if (index == INVALID_PTN) |
| 961 | { |
| 962 | dprintf(INFO, "Unable to locate /bootselect partition\n"); |
| 963 | return ret; |
| 964 | } |
| 965 | offset = partition_get_offset(index); |
| 966 | if(!offset) |
| 967 | { |
| 968 | dprintf(INFO, "partition /bootselect doesn't exist\n"); |
| 969 | return ret; |
| 970 | } |
| 971 | buf = (char *) memalign(CACHE_LINE, ROUNDUP(page_size, CACHE_LINE)); |
| 972 | ASSERT(buf); |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 973 | if (mmc_read(offset, (uint32_t *)buf, page_size)) |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 974 | { |
| 975 | dprintf(INFO, "mmc read failure /bootselect %d\n", page_size); |
| 976 | free(buf); |
| 977 | return ret; |
| 978 | } |
| 979 | in = (struct boot_selection_info *) buf; |
| 980 | if ((in->signature == BOOTSELECT_SIGNATURE) && |
| 981 | (in->version == BOOTSELECT_VERSION)) { |
| 982 | if ((in->state_info & BOOTSELECT_FORMAT) && |
| 983 | !(in->state_info & BOOTSELECT_FACTORY)) |
| 984 | ret = true; |
| 985 | } else { |
| 986 | dprintf(CRITICAL, "Signature: 0x%08x or version: 0x%08x mismatched of /bootselect\n", |
| 987 | in->signature, in->version); |
| 988 | ASSERT(0); |
| 989 | } |
| 990 | free(buf); |
| 991 | return ret; |
| 992 | } |
| 993 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 994 | void boot_verifier_init() |
| 995 | { |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 996 | uint32_t boot_state; |
| 997 | /* Check if device unlock */ |
| 998 | if(device.is_unlocked) |
| 999 | { |
| 1000 | boot_verify_send_event(DEV_UNLOCK); |
| 1001 | boot_verify_print_state(); |
| 1002 | dprintf(CRITICAL, "Device is unlocked! Skipping verification...\n"); |
| 1003 | return; |
| 1004 | } |
| 1005 | else |
| 1006 | { |
| 1007 | boot_verify_send_event(BOOT_INIT); |
| 1008 | } |
| 1009 | |
| 1010 | /* Initialize keystore */ |
| 1011 | boot_state = boot_verify_keystore_init(); |
| 1012 | if(boot_state == YELLOW) |
| 1013 | { |
| 1014 | boot_verify_print_state(); |
| 1015 | dprintf(CRITICAL, "Keystore verification failed! Continuing anyways...\n"); |
| 1016 | } |
| 1017 | } |
| 1018 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1019 | int boot_linux_from_mmc(void) |
| 1020 | { |
| 1021 | struct boot_img_hdr *hdr = (void*) buf; |
| 1022 | struct boot_img_hdr *uhdr; |
| 1023 | unsigned offset = 0; |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 1024 | int rcode; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1025 | unsigned long long ptn = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1026 | int index = INVALID_PTN; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1027 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1028 | unsigned char *image_addr = 0; |
| 1029 | unsigned kernel_actual; |
| 1030 | unsigned ramdisk_actual; |
| 1031 | unsigned imagesize_actual; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1032 | unsigned second_actual = 0; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1033 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1034 | unsigned int dtb_size = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1035 | unsigned int out_len = 0; |
| 1036 | unsigned int out_avai_len = 0; |
| 1037 | unsigned char *out_addr = NULL; |
| 1038 | uint32_t dtb_offset = 0; |
| 1039 | unsigned char *kernel_start_addr = NULL; |
| 1040 | unsigned int kernel_size = 0; |
| 1041 | int rc; |
| 1042 | |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1043 | #if DEVICE_TREE |
| 1044 | struct dt_table *table; |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1045 | struct dt_entry dt_entry; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1046 | unsigned dt_table_offset; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1047 | uint32_t dt_actual; |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1048 | uint32_t dt_hdr_size; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1049 | unsigned char *best_match_dt_addr = NULL; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1050 | #endif |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1051 | struct kernel64_hdr *kptr = NULL; |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1052 | |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 1053 | if (check_format_bit()) |
| 1054 | boot_into_recovery = 1; |
| 1055 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 1056 | if (!boot_into_recovery) { |
| 1057 | memset(ffbm_mode_string, '\0', sizeof(ffbm_mode_string)); |
| 1058 | rcode = get_ffbm(ffbm_mode_string, sizeof(ffbm_mode_string)); |
| 1059 | if (rcode <= 0) { |
| 1060 | boot_into_ffbm = false; |
| 1061 | if (rcode < 0) |
| 1062 | dprintf(CRITICAL,"failed to get ffbm cookie"); |
| 1063 | } else |
| 1064 | boot_into_ffbm = true; |
| 1065 | } else |
| 1066 | boot_into_ffbm = false; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1067 | uhdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
| 1068 | if (!memcmp(uhdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 1069 | dprintf(INFO, "Unified boot method!\n"); |
| 1070 | hdr = uhdr; |
| 1071 | goto unified_boot; |
| 1072 | } |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 1073 | if (!boot_into_recovery) { |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1074 | index = partition_get_index("boot"); |
| 1075 | ptn = partition_get_offset(index); |
| 1076 | if(ptn == 0) { |
Shashank Mittal | 85b91f6 | 2010-10-30 10:12:38 -0700 | [diff] [blame] | 1077 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 1078 | return -1; |
| 1079 | } |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1080 | } |
| 1081 | else { |
| 1082 | index = partition_get_index("recovery"); |
| 1083 | ptn = partition_get_offset(index); |
| 1084 | if(ptn == 0) { |
Shashank Mittal | 85b91f6 | 2010-10-30 10:12:38 -0700 | [diff] [blame] | 1085 | dprintf(CRITICAL, "ERROR: No recovery partition found\n"); |
| 1086 | return -1; |
| 1087 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1088 | } |
Channagoud Kadabi | ef0547c | 2015-02-10 12:57:38 -0800 | [diff] [blame] | 1089 | /* Set Lun for boot & recovery partitions */ |
| 1090 | mmc_set_lun(partition_get_lun(index)); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1091 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 1092 | if (mmc_read(ptn + offset, (uint32_t *) buf, page_size)) { |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1093 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 1094 | return -1; |
| 1095 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1096 | |
| 1097 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 1098 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1099 | return -1; |
| 1100 | } |
| 1101 | |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 1102 | if (hdr->page_size && (hdr->page_size != page_size)) { |
vijay kumar | 2e21b3a | 2014-06-26 17:40:15 +0530 | [diff] [blame] | 1103 | |
| 1104 | if (hdr->page_size > BOOT_IMG_MAX_PAGE_SIZE) { |
| 1105 | dprintf(CRITICAL, "ERROR: Invalid page size\n"); |
| 1106 | return -1; |
| 1107 | } |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 1108 | page_size = hdr->page_size; |
| 1109 | page_mask = page_size - 1; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
vijay kumar | 287bb54 | 2015-09-29 13:01:52 +0530 | [diff] [blame] | 1112 | /* ensure commandline is terminated */ |
| 1113 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
| 1114 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1115 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1116 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1117 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1118 | image_addr = (unsigned char *)target_get_scratch_address(); |
| 1119 | |
| 1120 | #if DEVICE_TREE |
| 1121 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
| 1122 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual); |
| 1123 | #else |
| 1124 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual); |
| 1125 | #endif |
| 1126 | |
| 1127 | #if VERIFIED_BOOT |
| 1128 | boot_verifier_init(); |
| 1129 | #endif |
| 1130 | |
Vijay Kumar Pendoti | 9c002ad | 2016-03-09 13:52:45 +0530 | [diff] [blame^] | 1131 | if (check_aboot_addr_range_overlap((uintptr_t) image_addr, imagesize_actual)) |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1132 | { |
| 1133 | dprintf(CRITICAL, "Boot image buffer address overlaps with aboot addresses.\n"); |
| 1134 | return -1; |
| 1135 | } |
| 1136 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1137 | /* |
| 1138 | * Update loading flow of bootimage to support compressed/uncompressed |
| 1139 | * bootimage on both 64bit and 32bit platform. |
| 1140 | * 1. Load bootimage from emmc partition onto DDR. |
| 1141 | * 2. Check if bootimage is gzip format. If yes, decompress compressed kernel |
| 1142 | * 3. Check kernel header and update kernel load addr for 64bit and 32bit |
| 1143 | * platform accordingly. |
| 1144 | * 4. Sanity Check on kernel_addr and ramdisk_addr and copy data. |
| 1145 | */ |
| 1146 | |
Channagoud Kadabi | f0705b5 | 2015-08-20 14:16:08 -0700 | [diff] [blame] | 1147 | dprintf(INFO, "Loading (%s) image (%d): start\n", |
| 1148 | (!boot_into_recovery ? "boot" : "recovery"),imagesize_actual); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1149 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
| 1150 | |
Gaurav Nebhwani | 43e2a46 | 2016-03-17 21:32:56 +0530 | [diff] [blame] | 1151 | if ((target_get_max_flash_size() - page_size) < imagesize_actual) |
| 1152 | { |
| 1153 | dprintf(CRITICAL, "booimage size is greater than DDR can hold\n"); |
| 1154 | return -1; |
| 1155 | } |
| 1156 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1157 | /* Read image without signature */ |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1158 | if (mmc_read(ptn + offset, (void *)image_addr, imagesize_actual)) |
| 1159 | { |
| 1160 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 1161 | return -1; |
| 1162 | } |
| 1163 | |
Channagoud Kadabi | f0705b5 | 2015-08-20 14:16:08 -0700 | [diff] [blame] | 1164 | dprintf(INFO, "Loading (%s) image (%d): done\n", |
| 1165 | (!boot_into_recovery ? "boot" : "recovery"),imagesize_actual); |
| 1166 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1167 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
| 1168 | |
| 1169 | /* Authenticate Kernel */ |
| 1170 | dprintf(INFO, "use_signed_kernel=%d, is_unlocked=%d, is_tampered=%d.\n", |
| 1171 | (int) target_use_signed_kernel(), |
| 1172 | device.is_unlocked, |
| 1173 | device.is_tampered); |
| 1174 | |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 1175 | /* Change the condition a little bit to include the test framework support. |
| 1176 | * We would never reach this point if device is in fastboot mode, even if we did |
| 1177 | * that means we are in test mode, so execute kernel authentication part for the |
| 1178 | * tests */ |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 1179 | if((target_use_signed_kernel() && (!device.is_unlocked)) || is_test_mode_enabled()) |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1180 | { |
| 1181 | offset = imagesize_actual; |
Vijay Kumar Pendoti | 9c002ad | 2016-03-09 13:52:45 +0530 | [diff] [blame^] | 1182 | if (check_aboot_addr_range_overlap((uintptr_t)image_addr + offset, page_size)) |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1183 | { |
| 1184 | dprintf(CRITICAL, "Signature read buffer address overlaps with aboot addresses.\n"); |
| 1185 | return -1; |
| 1186 | } |
| 1187 | |
| 1188 | /* Read signature */ |
| 1189 | if(mmc_read(ptn + offset, (void *)(image_addr + offset), page_size)) |
| 1190 | { |
| 1191 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
| 1192 | return -1; |
| 1193 | } |
| 1194 | |
| 1195 | verify_signed_bootimg((uint32_t)image_addr, imagesize_actual); |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 1196 | /* The purpose of our test is done here */ |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 1197 | if(is_test_mode_enabled() && auth_kernel_img) |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 1198 | return 0; |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1199 | } else { |
| 1200 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 1201 | #ifdef TZ_SAVE_KERNEL_HASH |
| 1202 | aboot_save_boot_hash_mmc((uint32_t) image_addr, imagesize_actual); |
| 1203 | #endif /* TZ_SAVE_KERNEL_HASH */ |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 1204 | |
| 1205 | #ifdef MDTP_SUPPORT |
| 1206 | { |
| 1207 | /* Verify MDTP lock. |
| 1208 | * For boot & recovery partitions, MDTP will use boot_verifier APIs, |
| 1209 | * since verification was skipped in aboot. The signature is not part of the loaded image. |
| 1210 | */ |
| 1211 | mdtp_ext_partition_verification_t ext_partition; |
| 1212 | ext_partition.partition = boot_into_recovery ? MDTP_PARTITION_RECOVERY : MDTP_PARTITION_BOOT; |
| 1213 | ext_partition.integrity_state = MDTP_PARTITION_STATE_UNSET; |
| 1214 | ext_partition.page_size = page_size; |
| 1215 | ext_partition.image_addr = (uint32)image_addr; |
| 1216 | ext_partition.image_size = imagesize_actual; |
| 1217 | ext_partition.sig_avail = FALSE; |
| 1218 | mdtp_fwlock_verify_lock(&ext_partition); |
| 1219 | } |
| 1220 | #endif /* MDTP_SUPPORT */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
Sridhar Parasuram | 00bfedb | 2015-05-26 14:21:27 -0700 | [diff] [blame] | 1223 | #if VERIFIED_BOOT |
Reut Zysman | ba8a9d5 | 2016-02-18 11:44:04 +0200 | [diff] [blame] | 1224 | if(boot_verify_get_state() == ORANGE) |
| 1225 | { |
| 1226 | #if FBCON_DISPLAY_MSG |
| 1227 | display_bootverify_menu(DISPLAY_MENU_ORANGE); |
| 1228 | wait_for_users_action(); |
| 1229 | #else |
| 1230 | dprintf(CRITICAL, |
| 1231 | "Your device has been unlocked and can't be trusted.\nWait for 5 seconds before proceeding\n"); |
| 1232 | mdelay(5000); |
| 1233 | #endif |
| 1234 | } |
| 1235 | #endif |
| 1236 | |
| 1237 | #if VERIFIED_BOOT |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 1238 | #if !VBOOT_MOTA |
Sridhar Parasuram | 00bfedb | 2015-05-26 14:21:27 -0700 | [diff] [blame] | 1239 | // send root of trust |
Sridhar Parasuram | 96300dc | 2015-06-11 10:37:11 -0700 | [diff] [blame] | 1240 | if(!send_rot_command((uint32_t)device.is_unlocked)) |
Sridhar Parasuram | 00bfedb | 2015-05-26 14:21:27 -0700 | [diff] [blame] | 1241 | ASSERT(0); |
| 1242 | #endif |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 1243 | #endif |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1244 | /* |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1245 | * Check if the kernel image is a gzip package. If yes, need to decompress it. |
| 1246 | * If not, continue booting. |
| 1247 | */ |
| 1248 | if (is_gzip_package((unsigned char *)(image_addr + page_size), hdr->kernel_size)) |
| 1249 | { |
| 1250 | out_addr = (unsigned char *)(image_addr + imagesize_actual + page_size); |
| 1251 | out_avai_len = target_get_max_flash_size() - imagesize_actual - page_size; |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1252 | dprintf(INFO, "decompressing kernel image: start\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1253 | rc = decompress((unsigned char *)(image_addr + page_size), |
| 1254 | hdr->kernel_size, out_addr, out_avai_len, |
| 1255 | &dtb_offset, &out_len); |
| 1256 | if (rc) |
| 1257 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1258 | dprintf(CRITICAL, "decompressing kernel image failed!!!\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1259 | ASSERT(0); |
| 1260 | } |
| 1261 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1262 | dprintf(INFO, "decompressing kernel image: done\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1263 | kptr = (struct kernel64_hdr *)out_addr; |
| 1264 | kernel_start_addr = out_addr; |
| 1265 | kernel_size = out_len; |
| 1266 | } else { |
| 1267 | kptr = (struct kernel64_hdr *)(image_addr + page_size); |
| 1268 | kernel_start_addr = (unsigned char *)(image_addr + page_size); |
| 1269 | kernel_size = hdr->kernel_size; |
| 1270 | } |
| 1271 | |
| 1272 | /* |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1273 | * Update the kernel/ramdisk/tags address if the boot image header |
| 1274 | * has default values, these default values come from mkbootimg when |
| 1275 | * the boot image is flashed using fastboot flash:raw |
| 1276 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1277 | update_ker_tags_rdisk_addr(hdr, IS_ARM64(kptr)); |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1278 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1279 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 1280 | hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr)); |
| 1281 | hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr)); |
| 1282 | hdr->tags_addr = VA((addr_t)(hdr->tags_addr)); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1283 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1284 | kernel_size = ROUND_TO_PAGE(kernel_size, page_mask); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1285 | /* Check if the addresses in the header are valid. */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1286 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_size) || |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1287 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual)) |
| 1288 | { |
| 1289 | dprintf(CRITICAL, "kernel/ramdisk addresses overlap with aboot addresses.\n"); |
| 1290 | return -1; |
| 1291 | } |
| 1292 | |
| 1293 | #ifndef DEVICE_TREE |
| 1294 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE)) |
| 1295 | { |
| 1296 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
| 1297 | return -1; |
| 1298 | } |
| 1299 | #endif |
| 1300 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1301 | /* Move kernel, ramdisk and device tree to correct address */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1302 | memmove((void*) hdr->kernel_addr, kernel_start_addr, kernel_size); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1303 | memmove((void*) hdr->ramdisk_addr, (char *)(image_addr + page_size + kernel_actual), hdr->ramdisk_size); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1304 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1305 | #if DEVICE_TREE |
| 1306 | if(hdr->dt_size) { |
| 1307 | dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual); |
| 1308 | table = (struct dt_table*) dt_table_offset; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1309 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1310 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
| 1311 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1312 | return -1; |
| 1313 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1314 | |
P.V. Phani Kumar | 8291676 | 2016-03-09 09:20:19 +0530 | [diff] [blame] | 1315 | /* Its Error if, dt_hdr_size (table->num_entries * dt_entry size + Dev_Tree Header) |
| 1316 | goes beyound hdr->dt_size*/ |
| 1317 | if (dt_hdr_size > ROUND_TO_PAGE(hdr->dt_size,hdr->page_size)) { |
| 1318 | dprintf(CRITICAL, "ERROR: Invalid Device Tree size \n"); |
| 1319 | return -1; |
| 1320 | } |
| 1321 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1322 | /* Find index of device tree within device tree table */ |
| 1323 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
| 1324 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1325 | return -1; |
| 1326 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1327 | |
P.V. Phani Kumar | 3c33320 | 2016-03-09 11:54:37 +0530 | [diff] [blame] | 1328 | if(dt_entry.offset > (UINT_MAX - dt_entry.size)) { |
| 1329 | dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n"); |
| 1330 | return -1; |
| 1331 | } |
| 1332 | |
| 1333 | /* Ensure we are not overshooting dt_size with the dt_entry selected */ |
| 1334 | if ((dt_entry.offset + dt_entry.size) > hdr->dt_size) { |
| 1335 | dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n"); |
| 1336 | return -1; |
| 1337 | } |
| 1338 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1339 | if (is_gzip_package((unsigned char *)dt_table_offset + dt_entry.offset, dt_entry.size)) |
| 1340 | { |
| 1341 | unsigned int compressed_size = 0; |
| 1342 | out_addr += out_len; |
| 1343 | out_avai_len -= out_len; |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1344 | dprintf(INFO, "decompressing dtb: start\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1345 | rc = decompress((unsigned char *)dt_table_offset + dt_entry.offset, |
| 1346 | dt_entry.size, out_addr, out_avai_len, |
| 1347 | &compressed_size, &dtb_size); |
| 1348 | if (rc) |
| 1349 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1350 | dprintf(CRITICAL, "decompressing dtb failed!!!\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1351 | ASSERT(0); |
| 1352 | } |
| 1353 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1354 | dprintf(INFO, "decompressing dtb: done\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1355 | best_match_dt_addr = out_addr; |
| 1356 | } else { |
| 1357 | best_match_dt_addr = (unsigned char *)dt_table_offset + dt_entry.offset; |
| 1358 | dtb_size = dt_entry.size; |
| 1359 | } |
| 1360 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1361 | /* Validate and Read device device tree in the tags_addr */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1362 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dtb_size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1363 | { |
| 1364 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1365 | return -1; |
| 1366 | } |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1367 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1368 | memmove((void *)hdr->tags_addr, (char *)best_match_dt_addr, dtb_size); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1369 | } else { |
| 1370 | /* Validate the tags_addr */ |
| 1371 | if (check_aboot_addr_range_overlap(hdr->tags_addr, kernel_actual)) |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 1372 | { |
| 1373 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1374 | return -1; |
| 1375 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1376 | /* |
| 1377 | * If appended dev tree is found, update the atags with |
| 1378 | * memory address to the DTB appended location on RAM. |
| 1379 | * Else update with the atags address in the kernel header |
| 1380 | */ |
| 1381 | void *dtb; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1382 | dtb = dev_tree_appended((void*)(image_addr + page_size), |
| 1383 | hdr->kernel_size, dtb_offset, |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1384 | (void *)hdr->tags_addr); |
| 1385 | if (!dtb) { |
| 1386 | dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n"); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 1387 | return -1; |
| 1388 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1389 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1390 | #endif |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1391 | |
Stanimir Varbanov | 69ec546 | 2013-07-18 18:17:42 +0300 | [diff] [blame] | 1392 | if (boot_into_recovery && !device.is_unlocked && !device.is_tampered) |
| 1393 | target_load_ssd_keystore(); |
| 1394 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1395 | unified_boot: |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1396 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 1397 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 1398 | (const char *)hdr->cmdline, board_machtype(), |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1399 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 1400 | |
| 1401 | return 0; |
| 1402 | } |
| 1403 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1404 | int boot_linux_from_flash(void) |
| 1405 | { |
| 1406 | struct boot_img_hdr *hdr = (void*) buf; |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1407 | struct ptentry *ptn; |
| 1408 | struct ptable *ptable; |
| 1409 | unsigned offset = 0; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 1410 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1411 | unsigned char *image_addr = 0; |
| 1412 | unsigned kernel_actual; |
| 1413 | unsigned ramdisk_actual; |
| 1414 | unsigned imagesize_actual; |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 1415 | unsigned second_actual = 0; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1416 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1417 | #if DEVICE_TREE |
| 1418 | struct dt_table *table; |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1419 | struct dt_entry dt_entry; |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 1420 | unsigned dt_table_offset; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1421 | uint32_t dt_actual; |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1422 | uint32_t dt_hdr_size; |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 1423 | unsigned int dtb_size = 0; |
| 1424 | unsigned char *best_match_dt_addr = NULL; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1425 | #endif |
| 1426 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 1427 | if (target_is_emmc_boot()) { |
| 1428 | hdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
| 1429 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 1430 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
| 1431 | return -1; |
| 1432 | } |
| 1433 | goto continue_boot; |
| 1434 | } |
| 1435 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1436 | ptable = flash_get_ptable(); |
| 1437 | if (ptable == NULL) { |
| 1438 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1439 | return -1; |
| 1440 | } |
| 1441 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 1442 | if(!boot_into_recovery) |
| 1443 | { |
| 1444 | ptn = ptable_find(ptable, "boot"); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1445 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 1446 | if (ptn == NULL) { |
| 1447 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 1448 | return -1; |
| 1449 | } |
| 1450 | } |
| 1451 | else |
| 1452 | { |
| 1453 | ptn = ptable_find(ptable, "recovery"); |
| 1454 | if (ptn == NULL) { |
| 1455 | dprintf(CRITICAL, "ERROR: No recovery partition found\n"); |
| 1456 | return -1; |
| 1457 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1458 | } |
| 1459 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 1460 | if (flash_read(ptn, offset, buf, page_size)) { |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1461 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 1462 | return -1; |
| 1463 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1464 | |
| 1465 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 1466 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1467 | return -1; |
| 1468 | } |
| 1469 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 1470 | if (hdr->page_size != page_size) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 1471 | 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] | 1472 | return -1; |
| 1473 | } |
| 1474 | |
vijay kumar | 287bb54 | 2015-09-29 13:01:52 +0530 | [diff] [blame] | 1475 | /* ensure commandline is terminated */ |
| 1476 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
| 1477 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1478 | /* |
| 1479 | * Update the kernel/ramdisk/tags address if the boot image header |
| 1480 | * has default values, these default values come from mkbootimg when |
| 1481 | * the boot image is flashed using fastboot flash:raw |
| 1482 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1483 | update_ker_tags_rdisk_addr(hdr, false); |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1484 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1485 | /* Get virtual addresses since the hdr saves physical addresses. */ |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1486 | hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr)); |
| 1487 | hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr)); |
| 1488 | hdr->tags_addr = VA((addr_t)(hdr->tags_addr)); |
| 1489 | |
| 1490 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1491 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 1492 | |
| 1493 | /* Check if the addresses in the header are valid. */ |
| 1494 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_actual) || |
| 1495 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual)) |
| 1496 | { |
| 1497 | dprintf(CRITICAL, "kernel/ramdisk addresses overlap with aboot addresses.\n"); |
| 1498 | return -1; |
| 1499 | } |
| 1500 | |
| 1501 | #ifndef DEVICE_TREE |
| 1502 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE)) |
| 1503 | { |
| 1504 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
| 1505 | return -1; |
| 1506 | } |
| 1507 | #endif |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1508 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1509 | /* Authenticate Kernel */ |
Deepa Dinamani | 23b60d4 | 2013-06-24 18:10:52 -0700 | [diff] [blame] | 1510 | if(target_use_signed_kernel() && (!device.is_unlocked)) |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1511 | { |
| 1512 | image_addr = (unsigned char *)target_get_scratch_address(); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1513 | offset = 0; |
| 1514 | |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1515 | #if DEVICE_TREE |
| 1516 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
vijay kumar | 966a982 | 2015-12-09 18:36:09 +0530 | [diff] [blame] | 1517 | |
| 1518 | if (UINT_MAX < ((uint64_t)kernel_actual + (uint64_t)ramdisk_actual+ (uint64_t)dt_actual + page_size)) { |
| 1519 | dprintf(CRITICAL, "Integer overflow detected in bootimage header fields\n"); |
| 1520 | return -1; |
| 1521 | } |
| 1522 | |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1523 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1524 | |
| 1525 | if (check_aboot_addr_range_overlap(hdr->tags_addr, hdr->dt_size)) |
| 1526 | { |
| 1527 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1528 | return -1; |
| 1529 | } |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1530 | #else |
vijay kumar | 966a982 | 2015-12-09 18:36:09 +0530 | [diff] [blame] | 1531 | if (UINT_MAX < ((uint64_t)kernel_actual + (uint64_t)ramdisk_actual+ page_size)) { |
| 1532 | dprintf(CRITICAL, "Integer overflow detected in bootimage header fields\n"); |
| 1533 | return -1; |
| 1534 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1535 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1536 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1537 | |
Channagoud Kadabi | f0705b5 | 2015-08-20 14:16:08 -0700 | [diff] [blame] | 1538 | dprintf(INFO, "Loading (%s) image (%d): start\n", |
| 1539 | (!boot_into_recovery ? "boot" : "recovery"),imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1540 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1541 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1542 | /* Read image without signature */ |
| 1543 | if (flash_read(ptn, offset, (void *)image_addr, imagesize_actual)) |
| 1544 | { |
| 1545 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 1546 | return -1; |
| 1547 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1548 | |
Channagoud Kadabi | f0705b5 | 2015-08-20 14:16:08 -0700 | [diff] [blame] | 1549 | dprintf(INFO, "Loading (%s) image (%d): done\n", |
| 1550 | (!boot_into_recovery ? "boot" : "recovery"), imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1551 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1552 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1553 | offset = imagesize_actual; |
| 1554 | /* Read signature */ |
| 1555 | if (flash_read(ptn, offset, (void *)(image_addr + offset), page_size)) |
| 1556 | { |
| 1557 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1558 | return -1; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1559 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1560 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 1561 | verify_signed_bootimg((uint32_t)image_addr, imagesize_actual); |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1562 | |
| 1563 | /* Move kernel and ramdisk to correct address */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1564 | memmove((void*) hdr->kernel_addr, (char*) (image_addr + page_size), hdr->kernel_size); |
| 1565 | 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] | 1566 | #if DEVICE_TREE |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 1567 | if(hdr->dt_size != 0) { |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1568 | |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 1569 | dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual); |
| 1570 | |
| 1571 | table = (struct dt_table*) dt_table_offset; |
| 1572 | |
| 1573 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0){ |
| 1574 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1575 | return -1; |
| 1576 | } |
| 1577 | |
| 1578 | /* Find index of device tree within device tree table */ |
| 1579 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
| 1580 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1581 | return -1; |
| 1582 | } |
| 1583 | |
| 1584 | /* Validate and Read device device tree in the "tags_add */ |
| 1585 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dt_entry.size)){ |
| 1586 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1587 | return -1; |
| 1588 | } |
| 1589 | |
| 1590 | best_match_dt_addr = (unsigned char *)table + dt_entry.offset; |
| 1591 | dtb_size = dt_entry.size; |
| 1592 | memmove((void *)hdr->tags_addr, (char *)best_match_dt_addr, dtb_size); |
| 1593 | } |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1594 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1595 | |
| 1596 | /* Make sure everything from scratch address is read before next step!*/ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1597 | if(device.is_tampered) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1598 | { |
| 1599 | write_device_info_flash(&device); |
| 1600 | } |
Channagoud Kadabi | 5c86fe3 | 2012-02-16 10:58:48 +0530 | [diff] [blame] | 1601 | #if USE_PCOM_SECBOOT |
| 1602 | set_tamper_flag(device.is_tampered); |
| 1603 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1604 | } |
| 1605 | else |
| 1606 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1607 | offset = page_size; |
| 1608 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1609 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1610 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 1611 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 1612 | |
Channagoud Kadabi | f0705b5 | 2015-08-20 14:16:08 -0700 | [diff] [blame] | 1613 | dprintf(INFO, "Loading (%s) image (%d): start\n", |
| 1614 | (!boot_into_recovery ? "boot" : "recovery"), kernel_actual + ramdisk_actual); |
| 1615 | |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1616 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1617 | |
| 1618 | if (flash_read(ptn, offset, (void *)hdr->kernel_addr, kernel_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1619 | dprintf(CRITICAL, "ERROR: Cannot read kernel image\n"); |
| 1620 | return -1; |
| 1621 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1622 | offset += kernel_actual; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1623 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1624 | if (flash_read(ptn, offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1625 | dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n"); |
| 1626 | return -1; |
| 1627 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1628 | offset += ramdisk_actual; |
| 1629 | |
Channagoud Kadabi | f0705b5 | 2015-08-20 14:16:08 -0700 | [diff] [blame] | 1630 | dprintf(INFO, "Loading (%s) image (%d): done\n", |
| 1631 | (!boot_into_recovery ? "boot" : "recovery"), kernel_actual + ramdisk_actual); |
| 1632 | |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1633 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1634 | |
| 1635 | if(hdr->second_size != 0) { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1636 | offset += second_actual; |
| 1637 | /* Second image loading not implemented. */ |
| 1638 | ASSERT(0); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1639 | } |
| 1640 | |
| 1641 | #if DEVICE_TREE |
| 1642 | if(hdr->dt_size != 0) { |
| 1643 | |
| 1644 | /* Read the device tree table into buffer */ |
| 1645 | if(flash_read(ptn, offset, (void *) dt_buf, page_size)) { |
| 1646 | dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n"); |
| 1647 | return -1; |
| 1648 | } |
| 1649 | |
| 1650 | table = (struct dt_table*) dt_buf; |
| 1651 | |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1652 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1653 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1654 | return -1; |
| 1655 | } |
| 1656 | |
P.V. Phani Kumar | 8291676 | 2016-03-09 09:20:19 +0530 | [diff] [blame] | 1657 | /* Its Error if, dt_hdr_size (table->num_entries * dt_entry size + Dev_Tree Header) |
| 1658 | goes beyound hdr->dt_size*/ |
| 1659 | if (dt_hdr_size > ROUND_TO_PAGE(hdr->dt_size,hdr->page_size)) { |
| 1660 | dprintf(CRITICAL, "ERROR: Invalid Device Tree size \n"); |
| 1661 | return -1; |
| 1662 | } |
| 1663 | |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1664 | table = (struct dt_table*) memalign(CACHE_LINE, dt_hdr_size); |
| 1665 | if (!table) |
| 1666 | return -1; |
| 1667 | |
| 1668 | /* Read the entire device tree table into buffer */ |
| 1669 | if(flash_read(ptn, offset, (void *)table, dt_hdr_size)) { |
| 1670 | dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n"); |
| 1671 | return -1; |
| 1672 | } |
| 1673 | |
| 1674 | |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1675 | /* Find index of device tree within device tree table */ |
| 1676 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1677 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1678 | return -1; |
| 1679 | } |
| 1680 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1681 | /* Validate and Read device device tree in the "tags_add */ |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1682 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dt_entry.size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1683 | { |
| 1684 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1685 | return -1; |
| 1686 | } |
| 1687 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1688 | /* Read device device tree in the "tags_add */ |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1689 | if(flash_read(ptn, offset + dt_entry.offset, |
| 1690 | (void *)hdr->tags_addr, dt_entry.size)) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1691 | dprintf(CRITICAL, "ERROR: Cannot read device tree\n"); |
| 1692 | return -1; |
| 1693 | } |
| 1694 | } |
| 1695 | #endif |
| 1696 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1697 | } |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 1698 | continue_boot: |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1699 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1700 | /* TODO: create/pass atags to kernel */ |
| 1701 | |
Ajay Dudani | e28a607 | 2011-07-01 13:59:46 -0700 | [diff] [blame] | 1702 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 1703 | (const char *)hdr->cmdline, board_machtype(), |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1704 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 1705 | |
| 1706 | return 0; |
| 1707 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1708 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1709 | void write_device_info_mmc(device_info *dev) |
| 1710 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1711 | unsigned long long ptn = 0; |
| 1712 | unsigned long long size; |
| 1713 | int index = INVALID_PTN; |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1714 | uint32_t blocksize; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 1715 | uint8_t lun = 0; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1716 | uint32_t ret = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1717 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1718 | if (devinfo_present) |
| 1719 | index = partition_get_index("devinfo"); |
| 1720 | else |
| 1721 | index = partition_get_index("aboot"); |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 1722 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1723 | ptn = partition_get_offset(index); |
| 1724 | if(ptn == 0) |
| 1725 | { |
| 1726 | return; |
| 1727 | } |
| 1728 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 1729 | lun = partition_get_lun(index); |
| 1730 | mmc_set_lun(lun); |
| 1731 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1732 | size = partition_get_size(index); |
| 1733 | |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1734 | blocksize = mmc_get_device_blocksize(); |
| 1735 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1736 | if (devinfo_present) |
| 1737 | ret = mmc_write(ptn, blocksize, (void *)info_buf); |
| 1738 | else |
| 1739 | ret = mmc_write((ptn + size - blocksize), blocksize, (void *)info_buf); |
| 1740 | if (ret) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1741 | { |
| 1742 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 1743 | ASSERT(0); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1744 | } |
| 1745 | } |
| 1746 | |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1747 | void read_device_info_mmc(struct device_info *info) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1748 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1749 | unsigned long long ptn = 0; |
| 1750 | unsigned long long size; |
| 1751 | int index = INVALID_PTN; |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1752 | uint32_t blocksize; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1753 | uint32_t ret = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1754 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1755 | if ((index = partition_get_index("devinfo")) < 0) |
| 1756 | { |
| 1757 | devinfo_present = false; |
| 1758 | index = partition_get_index("aboot"); |
| 1759 | } |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 1760 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1761 | ptn = partition_get_offset(index); |
| 1762 | if(ptn == 0) |
| 1763 | { |
| 1764 | return; |
| 1765 | } |
| 1766 | |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 1767 | mmc_set_lun(partition_get_lun(index)); |
| 1768 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1769 | size = partition_get_size(index); |
| 1770 | |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1771 | blocksize = mmc_get_device_blocksize(); |
| 1772 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1773 | if (devinfo_present) |
| 1774 | ret = mmc_read(ptn, (void *)info_buf, blocksize); |
| 1775 | else |
| 1776 | ret = mmc_read((ptn + size - blocksize), (void *)info_buf, blocksize); |
| 1777 | if (ret) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1778 | { |
| 1779 | dprintf(CRITICAL, "ERROR: Cannot read device info\n"); |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 1780 | ASSERT(0); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1781 | } |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | void write_device_info_flash(device_info *dev) |
| 1785 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1786 | struct device_info *info = memalign(PAGE_SIZE, ROUNDUP(BOOT_IMG_MAX_PAGE_SIZE, PAGE_SIZE)); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1787 | struct ptentry *ptn; |
| 1788 | struct ptable *ptable; |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1789 | if(info == NULL) |
| 1790 | { |
| 1791 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 1792 | ASSERT(0); |
| 1793 | } |
| 1794 | info_buf = info; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1795 | ptable = flash_get_ptable(); |
| 1796 | if (ptable == NULL) |
| 1797 | { |
| 1798 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1799 | return; |
| 1800 | } |
| 1801 | |
| 1802 | ptn = ptable_find(ptable, "devinfo"); |
| 1803 | if (ptn == NULL) |
| 1804 | { |
Smita Ghosh | 670c8b8 | 2015-05-07 09:30:03 -0700 | [diff] [blame] | 1805 | dprintf(CRITICAL, "ERROR: No devinfo partition found\n"); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1806 | return; |
| 1807 | } |
| 1808 | |
| 1809 | memcpy(info, dev, sizeof(device_info)); |
| 1810 | |
| 1811 | if (flash_write(ptn, 0, (void *)info_buf, page_size)) |
| 1812 | { |
| 1813 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1814 | return; |
| 1815 | } |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1816 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1819 | static int read_allow_oem_unlock(device_info *dev) |
| 1820 | { |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1821 | unsigned offset; |
| 1822 | int index; |
| 1823 | unsigned long long ptn; |
| 1824 | unsigned long long ptn_size; |
| 1825 | unsigned blocksize = mmc_get_device_blocksize(); |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 1826 | STACKBUF_DMA_ALIGN(buf, blocksize); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1827 | |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 1828 | index = partition_get_index(frp_ptns[0]); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1829 | if (index == INVALID_PTN) |
| 1830 | { |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 1831 | index = partition_get_index(frp_ptns[1]); |
| 1832 | if (index == INVALID_PTN) |
| 1833 | { |
| 1834 | dprintf(CRITICAL, "Neither '%s' nor '%s' partition found\n", frp_ptns[0],frp_ptns[1]); |
| 1835 | return -1; |
| 1836 | } |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | ptn = partition_get_offset(index); |
| 1840 | ptn_size = partition_get_size(index); |
| 1841 | offset = ptn_size - blocksize; |
| 1842 | |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 1843 | if (mmc_read(ptn + offset, (void *)buf, blocksize)) |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1844 | { |
| 1845 | dprintf(CRITICAL, "Reading MMC failed\n"); |
| 1846 | return -1; |
| 1847 | } |
| 1848 | |
| 1849 | /*is_allow_unlock is a bool value stored at the LSB of last byte*/ |
| 1850 | is_allow_unlock = buf[blocksize-1] & 0x01; |
| 1851 | return 0; |
| 1852 | } |
| 1853 | |
| 1854 | static int write_allow_oem_unlock(bool allow_unlock) |
| 1855 | { |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1856 | unsigned offset; |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1857 | int index; |
| 1858 | unsigned long long ptn; |
| 1859 | unsigned long long ptn_size; |
| 1860 | unsigned blocksize = mmc_get_device_blocksize(); |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 1861 | STACKBUF_DMA_ALIGN(buf, blocksize); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1862 | |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 1863 | index = partition_get_index(frp_ptns[0]); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1864 | if (index == INVALID_PTN) |
| 1865 | { |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 1866 | index = partition_get_index(frp_ptns[1]); |
| 1867 | if (index == INVALID_PTN) |
| 1868 | { |
| 1869 | dprintf(CRITICAL, "Neither '%s' nor '%s' partition found\n", frp_ptns[0],frp_ptns[1]); |
| 1870 | return -1; |
| 1871 | } |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | ptn = partition_get_offset(index); |
| 1875 | ptn_size = partition_get_size(index); |
| 1876 | offset = ptn_size - blocksize; |
| 1877 | |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 1878 | if (mmc_read(ptn + offset, (void *)buf, blocksize)) |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 1879 | { |
| 1880 | dprintf(CRITICAL, "Reading MMC failed\n"); |
| 1881 | return -1; |
| 1882 | } |
| 1883 | |
| 1884 | /*is_allow_unlock is a bool value stored at the LSB of last byte*/ |
| 1885 | buf[blocksize-1] = allow_unlock; |
| 1886 | if (mmc_write(ptn + offset, blocksize, buf)) |
| 1887 | { |
| 1888 | dprintf(CRITICAL, "Writing MMC failed\n"); |
| 1889 | return -1; |
| 1890 | } |
| 1891 | |
| 1892 | return 0; |
| 1893 | } |
| 1894 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1895 | void read_device_info_flash(device_info *dev) |
| 1896 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1897 | struct device_info *info = memalign(PAGE_SIZE, ROUNDUP(BOOT_IMG_MAX_PAGE_SIZE, PAGE_SIZE)); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1898 | struct ptentry *ptn; |
| 1899 | struct ptable *ptable; |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1900 | if(info == NULL) |
| 1901 | { |
| 1902 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 1903 | ASSERT(0); |
| 1904 | } |
| 1905 | info_buf = info; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1906 | ptable = flash_get_ptable(); |
| 1907 | if (ptable == NULL) |
| 1908 | { |
| 1909 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1910 | return; |
| 1911 | } |
| 1912 | |
| 1913 | ptn = ptable_find(ptable, "devinfo"); |
| 1914 | if (ptn == NULL) |
| 1915 | { |
Smita Ghosh | 670c8b8 | 2015-05-07 09:30:03 -0700 | [diff] [blame] | 1916 | dprintf(CRITICAL, "ERROR: No devinfo partition found\n"); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1917 | return; |
| 1918 | } |
| 1919 | |
| 1920 | if (flash_read(ptn, 0, (void *)info_buf, page_size)) |
| 1921 | { |
| 1922 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1923 | return; |
| 1924 | } |
| 1925 | |
| 1926 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 1927 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1928 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
| 1929 | info->is_unlocked = 0; |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1930 | info->is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1931 | write_device_info_flash(info); |
| 1932 | } |
| 1933 | memcpy(dev, info, sizeof(device_info)); |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1934 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1935 | } |
| 1936 | |
| 1937 | void write_device_info(device_info *dev) |
| 1938 | { |
| 1939 | if(target_is_emmc_boot()) |
| 1940 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1941 | struct device_info *info = memalign(PAGE_SIZE, ROUNDUP(BOOT_IMG_MAX_PAGE_SIZE, PAGE_SIZE)); |
| 1942 | if(info == NULL) |
| 1943 | { |
| 1944 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 1945 | ASSERT(0); |
| 1946 | } |
| 1947 | info_buf = info; |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1948 | memcpy(info, dev, sizeof(struct device_info)); |
| 1949 | |
| 1950 | #if USE_RPMB_FOR_DEVINFO |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 1951 | if (is_secure_boot_enable()) { |
| 1952 | if((write_device_info_rpmb((void*) info, PAGE_SIZE)) < 0) |
| 1953 | ASSERT(0); |
| 1954 | } |
Channagoud Kadabi | c80cb49 | 2015-04-28 16:08:28 -0700 | [diff] [blame] | 1955 | else |
| 1956 | write_device_info_mmc(info); |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1957 | #else |
| 1958 | write_device_info_mmc(info); |
| 1959 | #endif |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1960 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1961 | } |
| 1962 | else |
| 1963 | { |
| 1964 | write_device_info_flash(dev); |
| 1965 | } |
| 1966 | } |
| 1967 | |
| 1968 | void read_device_info(device_info *dev) |
| 1969 | { |
| 1970 | if(target_is_emmc_boot()) |
| 1971 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 1972 | struct device_info *info = memalign(PAGE_SIZE, ROUNDUP(BOOT_IMG_MAX_PAGE_SIZE, PAGE_SIZE)); |
| 1973 | if(info == NULL) |
| 1974 | { |
| 1975 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 1976 | ASSERT(0); |
| 1977 | } |
| 1978 | info_buf = info; |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1979 | |
| 1980 | #if USE_RPMB_FOR_DEVINFO |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 1981 | if (is_secure_boot_enable()) { |
| 1982 | if((read_device_info_rpmb((void*) info, PAGE_SIZE)) < 0) |
| 1983 | ASSERT(0); |
| 1984 | } |
Channagoud Kadabi | c80cb49 | 2015-04-28 16:08:28 -0700 | [diff] [blame] | 1985 | else |
| 1986 | read_device_info_mmc(info); |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1987 | #else |
| 1988 | read_device_info_mmc(info); |
| 1989 | #endif |
| 1990 | |
| 1991 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 1992 | { |
| 1993 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 1994 | if (is_secure_boot_enable()) { |
Channagoud Kadabi | 05f78ba | 2015-07-06 11:58:14 -0700 | [diff] [blame] | 1995 | info->is_unlocked = 0; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 1996 | #if !VBOOT_MOTA |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 1997 | info->is_unlock_critical = 0; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 1998 | #endif |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 1999 | } else { |
Channagoud Kadabi | 2fda409 | 2015-07-07 13:34:11 -0700 | [diff] [blame] | 2000 | info->is_unlocked = 1; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2001 | #if !VBOOT_MOTA |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 2002 | info->is_unlock_critical = 1; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2003 | #endif |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 2004 | } |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2005 | info->is_tampered = 0; |
| 2006 | info->charger_screen_enabled = 0; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2007 | #if !VBOOT_MOTA |
Sridhar Parasuram | 287e506 | 2015-08-24 16:17:22 -0700 | [diff] [blame] | 2008 | info->verity_mode = 1; //enforcing by default |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2009 | #endif |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2010 | write_device_info(info); |
| 2011 | } |
| 2012 | memcpy(dev, info, sizeof(device_info)); |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2013 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2014 | } |
| 2015 | else |
| 2016 | { |
| 2017 | read_device_info_flash(dev); |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | void reset_device_info() |
| 2022 | { |
| 2023 | dprintf(ALWAYS, "reset_device_info called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2024 | device.is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2025 | write_device_info(&device); |
| 2026 | } |
| 2027 | |
| 2028 | void set_device_root() |
| 2029 | { |
| 2030 | dprintf(ALWAYS, "set_device_root called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2031 | device.is_tampered = 1; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2032 | write_device_info(&device); |
| 2033 | } |
| 2034 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2035 | /* set device unlock value |
| 2036 | * Must check FRP before call this function |
| 2037 | * Need to wipe data when unlock status changed |
| 2038 | * type 0: oem unlock |
| 2039 | * type 1: unlock critical |
| 2040 | * status 0: unlock as false |
| 2041 | * status 1: lock as true |
| 2042 | */ |
| 2043 | void set_device_unlock_value(int type, bool status) |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2044 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2045 | if (type == UNLOCK) |
| 2046 | device.is_unlocked = status; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2047 | #if !VBOOT_MOTA |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2048 | else if (type == UNLOCK_CRITICAL) |
| 2049 | device.is_unlock_critical = status; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2050 | #endif |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2051 | write_device_info(&device); |
| 2052 | } |
| 2053 | |
| 2054 | static void set_device_unlock(int type, bool status) |
| 2055 | { |
| 2056 | int is_unlocked = -1; |
| 2057 | char response[MAX_RSP_SIZE]; |
| 2058 | |
| 2059 | /* check device unlock status if it is as expected */ |
| 2060 | if (type == UNLOCK) |
| 2061 | is_unlocked = device.is_unlocked; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2062 | #if !VBOOT_MOTA |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2063 | else if (type == UNLOCK_CRITICAL) |
| 2064 | is_unlocked = device.is_unlock_critical; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2065 | #endif |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2066 | if (is_unlocked == status) { |
| 2067 | snprintf(response, sizeof(response), "\tDevice already : %s", (status ? "unlocked!" : "locked!")); |
| 2068 | fastboot_info(response); |
| 2069 | fastboot_okay(""); |
| 2070 | return; |
| 2071 | } |
| 2072 | |
| 2073 | /* status is true, it means to unlock device */ |
| 2074 | if (status) { |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2075 | if(!is_allow_unlock) { |
| 2076 | fastboot_fail("oem unlock is not allowed"); |
| 2077 | return; |
| 2078 | } |
| 2079 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2080 | #if FBCON_DISPLAY_MSG |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 2081 | display_unlock_menu(type); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2082 | fastboot_okay(""); |
| 2083 | return; |
| 2084 | #else |
| 2085 | if (type == UNLOCK) { |
| 2086 | fastboot_fail("Need wipe userdata. Do 'fastboot oem unlock-go'"); |
| 2087 | return; |
| 2088 | } |
| 2089 | #endif |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2090 | } |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2091 | |
| 2092 | set_device_unlock_value(type, status); |
| 2093 | |
| 2094 | /* wipe data */ |
| 2095 | struct recovery_message msg; |
| 2096 | |
| 2097 | snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data"); |
| 2098 | write_misc(0, &msg, sizeof(msg)); |
| 2099 | |
| 2100 | fastboot_okay(""); |
| 2101 | reboot_device(RECOVERY_MODE); |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2102 | } |
| 2103 | |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 2104 | static bool critical_flash_allowed(const char * entry) |
| 2105 | { |
| 2106 | uint32_t i = 0; |
| 2107 | if (entry == NULL) |
| 2108 | return false; |
| 2109 | |
| 2110 | for (i = 0; i < ARRAY_SIZE(critical_flash_allowed_ptn); i++) { |
| 2111 | if(!strcmp(entry, critical_flash_allowed_ptn[i])) |
| 2112 | return true; |
| 2113 | } |
| 2114 | return false; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | #if DEVICE_TREE |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2118 | int copy_dtb(uint8_t *boot_image_start, unsigned int scratch_offset) |
| 2119 | { |
| 2120 | uint32 dt_image_offset = 0; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2121 | uint32_t n; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2122 | struct dt_table *table; |
| 2123 | struct dt_entry dt_entry; |
| 2124 | uint32_t dt_hdr_size; |
| 2125 | unsigned int compressed_size = 0; |
| 2126 | unsigned int dtb_size = 0; |
| 2127 | unsigned int out_avai_len = 0; |
| 2128 | unsigned char *out_addr = NULL; |
| 2129 | unsigned char *best_match_dt_addr = NULL; |
| 2130 | int rc; |
| 2131 | |
| 2132 | struct boot_img_hdr *hdr = (struct boot_img_hdr *) (boot_image_start); |
| 2133 | |
| 2134 | if(hdr->dt_size != 0) { |
| 2135 | /* add kernel offset */ |
| 2136 | dt_image_offset += page_size; |
| 2137 | n = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 2138 | dt_image_offset += n; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2139 | |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 2140 | /* add ramdisk offset */ |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2141 | n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 2142 | dt_image_offset += n; |
| 2143 | |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 2144 | /* add second offset */ |
| 2145 | if(hdr->second_size != 0) { |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2146 | n = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 2147 | dt_image_offset += n; |
| 2148 | } |
| 2149 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2150 | /* offset now point to start of dt.img */ |
| 2151 | table = (struct dt_table*)(boot_image_start + dt_image_offset); |
| 2152 | |
| 2153 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
| 2154 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2155 | return -1; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2156 | } |
P.V. Phani Kumar | 8291676 | 2016-03-09 09:20:19 +0530 | [diff] [blame] | 2157 | |
| 2158 | /* Its Error if, dt_hdr_size (table->num_entries * dt_entry size + Dev_Tree Header) |
| 2159 | goes beyound hdr->dt_size*/ |
| 2160 | if (dt_hdr_size > ROUND_TO_PAGE(hdr->dt_size,hdr->page_size)) { |
| 2161 | dprintf(CRITICAL, "ERROR: Invalid Device Tree size \n"); |
| 2162 | return -1; |
| 2163 | } |
| 2164 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2165 | /* Find index of device tree within device tree table */ |
| 2166 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
| 2167 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 2168 | return -1; |
| 2169 | } |
| 2170 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2171 | best_match_dt_addr = (unsigned char *)boot_image_start + dt_image_offset + dt_entry.offset; |
| 2172 | if (is_gzip_package(best_match_dt_addr, dt_entry.size)) |
| 2173 | { |
| 2174 | out_addr = (unsigned char *)target_get_scratch_address() + scratch_offset; |
| 2175 | out_avai_len = target_get_max_flash_size() - scratch_offset; |
| 2176 | dprintf(INFO, "decompressing dtb: start\n"); |
| 2177 | rc = decompress(best_match_dt_addr, |
| 2178 | dt_entry.size, out_addr, out_avai_len, |
| 2179 | &compressed_size, &dtb_size); |
| 2180 | if (rc) |
| 2181 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2182 | dprintf(CRITICAL, "decompressing dtb failed!!!\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2183 | ASSERT(0); |
| 2184 | } |
| 2185 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2186 | dprintf(INFO, "decompressing dtb: done\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2187 | best_match_dt_addr = out_addr; |
| 2188 | } else { |
| 2189 | dtb_size = dt_entry.size; |
| 2190 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2191 | /* Validate and Read device device tree in the "tags_add */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2192 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dtb_size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2193 | { |
| 2194 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 2195 | return -1; |
| 2196 | } |
| 2197 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2198 | /* Read device device tree in the "tags_add */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2199 | memmove((void*) hdr->tags_addr, (void *)best_match_dt_addr, dtb_size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2200 | } else |
| 2201 | return -1; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2202 | |
| 2203 | /* Everything looks fine. Return success. */ |
| 2204 | return 0; |
| 2205 | } |
| 2206 | #endif |
| 2207 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2208 | void cmd_boot(const char *arg, void *data, unsigned sz) |
| 2209 | { |
Amit Blay | 8a51030 | 2015-08-17 09:20:01 +0300 | [diff] [blame] | 2210 | #ifdef MDTP_SUPPORT |
| 2211 | static bool is_mdtp_activated = 0; |
| 2212 | #endif /* MDTP_SUPPORT */ |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2213 | unsigned kernel_actual; |
| 2214 | unsigned ramdisk_actual; |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 2215 | uint32_t image_actual; |
| 2216 | uint32_t dt_actual = 0; |
P.V. Phani Kumar | eecfd82 | 2016-03-09 20:09:03 +0530 | [diff] [blame] | 2217 | uint32_t sig_actual = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2218 | struct boot_img_hdr *hdr = NULL; |
| 2219 | struct kernel64_hdr *kptr = NULL; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2220 | char *ptr = ((char*) data); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2221 | int ret = 0; |
| 2222 | uint8_t dtb_copied = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2223 | unsigned int out_len = 0; |
| 2224 | unsigned int out_avai_len = 0; |
| 2225 | unsigned char *out_addr = NULL; |
| 2226 | uint32_t dtb_offset = 0; |
| 2227 | unsigned char *kernel_start_addr = NULL; |
| 2228 | unsigned int kernel_size = 0; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2229 | unsigned int scratch_offset = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2230 | |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2231 | #if FBCON_DISPLAY_MSG |
| 2232 | /* Exit keys' detection thread firstly */ |
| 2233 | exit_menu_keys_detection(); |
| 2234 | #endif |
| 2235 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2236 | #if VERIFIED_BOOT |
Channagoud Kadabi | 6d5375e | 2015-06-23 17:15:42 -0700 | [diff] [blame] | 2237 | if(target_build_variant_user() && !device.is_unlocked) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2238 | { |
| 2239 | fastboot_fail("unlock device to use this command"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2240 | goto boot_failed; |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2241 | } |
| 2242 | #endif |
| 2243 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2244 | if (sz < sizeof(hdr)) { |
| 2245 | fastboot_fail("invalid bootimage header"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2246 | goto boot_failed; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2247 | } |
| 2248 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2249 | hdr = (struct boot_img_hdr *)data; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2250 | |
| 2251 | /* ensure commandline is terminated */ |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2252 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2253 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2254 | if(target_is_emmc_boot() && hdr->page_size) { |
| 2255 | page_size = hdr->page_size; |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 2256 | page_mask = page_size - 1; |
| 2257 | } |
| 2258 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2259 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 2260 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 2261 | #if DEVICE_TREE |
| 2262 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
| 2263 | #endif |
| 2264 | |
| 2265 | image_actual = ADD_OF(page_size, kernel_actual); |
| 2266 | image_actual = ADD_OF(image_actual, ramdisk_actual); |
| 2267 | image_actual = ADD_OF(image_actual, dt_actual); |
| 2268 | |
P.V. Phani Kumar | eecfd82 | 2016-03-09 20:09:03 +0530 | [diff] [blame] | 2269 | if (target_use_signed_kernel() && (!device.is_unlocked)) { |
| 2270 | /* Calculate the signature length from boot image */ |
| 2271 | sig_actual = read_der_message_length( |
| 2272 | (unsigned char*)(data + image_actual),sz); |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 2273 | image_actual = ADD_OF(image_actual, sig_actual); |
P.V. Phani Kumar | eecfd82 | 2016-03-09 20:09:03 +0530 | [diff] [blame] | 2274 | } |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 2275 | |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 2276 | /* sz should have atleast raw boot image */ |
| 2277 | if (image_actual > sz) { |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 2278 | fastboot_fail("bootimage: incomplete or not signed"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2279 | goto boot_failed; |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 2280 | } |
| 2281 | |
Sridhar Parasuram | 361e4cd | 2015-09-24 11:19:19 -0700 | [diff] [blame] | 2282 | // Initialize boot state before trying to verify boot.img |
| 2283 | #if VERIFIED_BOOT |
Channagoud Kadabi | 699466e | 2015-11-03 12:37:42 -0800 | [diff] [blame] | 2284 | boot_verifier_init(); |
Channagoud Kadabi | bf6ce7d | 2015-09-17 13:25:35 -0700 | [diff] [blame] | 2285 | /* Handle overflow if the input image size is greater than |
| 2286 | * boot image buffer can hold |
| 2287 | */ |
| 2288 | if ((target_get_max_flash_size() - (image_actual - sig_actual)) < page_size) |
| 2289 | { |
| 2290 | fastboot_fail("booimage: size is greater than boot image buffer can hold"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2291 | goto boot_failed; |
Channagoud Kadabi | bf6ce7d | 2015-09-17 13:25:35 -0700 | [diff] [blame] | 2292 | } |
Sridhar Parasuram | 361e4cd | 2015-09-24 11:19:19 -0700 | [diff] [blame] | 2293 | #endif |
| 2294 | |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 2295 | /* Verify the boot image |
| 2296 | * device & page_size are initialized in aboot_init |
| 2297 | */ |
Sridhar Parasuram | 7ae9fbc | 2015-09-17 09:56:30 -0700 | [diff] [blame] | 2298 | if (target_use_signed_kernel() && (!device.is_unlocked)) { |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 2299 | /* Pass size excluding signature size, otherwise we would try to |
| 2300 | * access signature beyond its length |
| 2301 | */ |
| 2302 | verify_signed_bootimg((uint32_t)data, (image_actual - sig_actual)); |
Sridhar Parasuram | 7ae9fbc | 2015-09-17 09:56:30 -0700 | [diff] [blame] | 2303 | } |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 2304 | #ifdef MDTP_SUPPORT |
| 2305 | else |
| 2306 | { |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 2307 | /* fastboot boot is not allowed when MDTP is activated */ |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 2308 | mdtp_ext_partition_verification_t ext_partition; |
Amit Blay | 8a51030 | 2015-08-17 09:20:01 +0300 | [diff] [blame] | 2309 | |
| 2310 | if (!is_mdtp_activated) { |
| 2311 | ext_partition.partition = MDTP_PARTITION_NONE; |
| 2312 | mdtp_fwlock_verify_lock(&ext_partition); |
| 2313 | } |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 2314 | } |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 2315 | |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 2316 | mdtp_activated(&is_mdtp_activated); |
| 2317 | if(is_mdtp_activated){ |
| 2318 | dprintf(CRITICAL, "fastboot boot command is not available.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2319 | goto boot_failed; |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 2320 | } |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 2321 | #endif /* MDTP_SUPPORT */ |
| 2322 | |
Sridhar Parasuram | 361e4cd | 2015-09-24 11:19:19 -0700 | [diff] [blame] | 2323 | #if VERIFIED_BOOT |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 2324 | #if !VBOOT_MOTA |
Sridhar Parasuram | 361e4cd | 2015-09-24 11:19:19 -0700 | [diff] [blame] | 2325 | // send root of trust |
| 2326 | if(!send_rot_command((uint32_t)device.is_unlocked)) |
| 2327 | ASSERT(0); |
| 2328 | #endif |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 2329 | #endif |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 2330 | /* |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2331 | * Check if the kernel image is a gzip package. If yes, need to decompress it. |
| 2332 | * If not, continue booting. |
| 2333 | */ |
| 2334 | if (is_gzip_package((unsigned char *)(data + page_size), hdr->kernel_size)) |
| 2335 | { |
| 2336 | out_addr = (unsigned char *)target_get_scratch_address(); |
| 2337 | out_addr = (unsigned char *)(out_addr + image_actual + page_size); |
| 2338 | out_avai_len = target_get_max_flash_size() - image_actual - page_size; |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2339 | dprintf(INFO, "decompressing kernel image: start\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2340 | ret = decompress((unsigned char *)(ptr + page_size), |
| 2341 | hdr->kernel_size, out_addr, out_avai_len, |
| 2342 | &dtb_offset, &out_len); |
| 2343 | if (ret) |
| 2344 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2345 | dprintf(CRITICAL, "decompressing image failed!!!\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2346 | ASSERT(0); |
| 2347 | } |
| 2348 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2349 | dprintf(INFO, "decompressing kernel image: done\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2350 | kptr = (struct kernel64_hdr *)out_addr; |
| 2351 | kernel_start_addr = out_addr; |
| 2352 | kernel_size = out_len; |
| 2353 | } else { |
| 2354 | kptr = (struct kernel64_hdr*)((char *)data + page_size); |
| 2355 | kernel_start_addr = (unsigned char *)((char *)data + page_size); |
| 2356 | kernel_size = hdr->kernel_size; |
| 2357 | } |
| 2358 | |
| 2359 | /* |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 2360 | * Update the kernel/ramdisk/tags address if the boot image header |
| 2361 | * has default values, these default values come from mkbootimg when |
| 2362 | * the boot image is flashed using fastboot flash:raw |
| 2363 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 2364 | update_ker_tags_rdisk_addr(hdr, IS_ARM64(kptr)); |
Dima Zavin | 3cadfff | 2013-03-21 14:30:48 -0700 | [diff] [blame] | 2365 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2366 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 2367 | hdr->kernel_addr = VA(hdr->kernel_addr); |
| 2368 | hdr->ramdisk_addr = VA(hdr->ramdisk_addr); |
| 2369 | hdr->tags_addr = VA(hdr->tags_addr); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2370 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2371 | kernel_size = ROUND_TO_PAGE(kernel_size, page_mask); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2372 | /* Check if the addresses in the header are valid. */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2373 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_size) || |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2374 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual)) |
| 2375 | { |
| 2376 | dprintf(CRITICAL, "kernel/ramdisk addresses overlap with aboot addresses.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2377 | goto boot_failed; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2380 | #if DEVICE_TREE |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2381 | scratch_offset = image_actual + page_size + out_len; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2382 | /* find correct dtb and copy it to right location */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2383 | ret = copy_dtb(data, scratch_offset); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2384 | |
| 2385 | dtb_copied = !ret ? 1 : 0; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2386 | #else |
| 2387 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE)) |
| 2388 | { |
| 2389 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2390 | goto boot_failed; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2391 | } |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2392 | #endif |
| 2393 | |
| 2394 | /* Load ramdisk & kernel */ |
| 2395 | memmove((void*) hdr->ramdisk_addr, ptr + page_size + kernel_actual, hdr->ramdisk_size); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2396 | memmove((void*) hdr->kernel_addr, (char*) (kernel_start_addr), kernel_size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2397 | |
| 2398 | #if DEVICE_TREE |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2399 | if (check_aboot_addr_range_overlap(hdr->tags_addr, kernel_actual)) |
| 2400 | { |
| 2401 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2402 | goto boot_failed; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2403 | } |
| 2404 | |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2405 | /* |
| 2406 | * If dtb is not found look for appended DTB in the kernel. |
| 2407 | * If appended dev tree is found, update the atags with |
| 2408 | * memory address to the DTB appended location on RAM. |
| 2409 | * Else update with the atags address in the kernel header |
| 2410 | */ |
| 2411 | if (!dtb_copied) { |
| 2412 | void *dtb; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2413 | dtb = dev_tree_appended((void*)(ptr + page_size), |
| 2414 | hdr->kernel_size, dtb_offset, |
Dima Zavin | e63e557 | 2013-05-03 12:23:06 -0700 | [diff] [blame] | 2415 | (void *)hdr->tags_addr); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2416 | if (!dtb) { |
| 2417 | fastboot_fail("dtb not found"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2418 | goto boot_failed; |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2419 | } |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2420 | } |
| 2421 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2422 | |
| 2423 | fastboot_okay(""); |
Amol Jadi | 7c4316c | 2013-10-07 14:19:26 -0700 | [diff] [blame] | 2424 | fastboot_stop(); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2425 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 2426 | boot_linux((void*) hdr->kernel_addr, (void*) hdr->tags_addr, |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2427 | (const char*) hdr->cmdline, board_machtype(), |
| 2428 | (void*) hdr->ramdisk_addr, hdr->ramdisk_size); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2429 | |
| 2430 | /* fastboot already stop, it's no need to show fastboot menu */ |
| 2431 | return; |
| 2432 | boot_failed: |
| 2433 | #if FBCON_DISPLAY_MSG |
| 2434 | /* revert to fastboot menu if boot failed */ |
| 2435 | display_fastboot_menu(); |
| 2436 | #endif |
| 2437 | return; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2438 | } |
| 2439 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2440 | void cmd_erase_nand(const char *arg, void *data, unsigned sz) |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2441 | { |
| 2442 | struct ptentry *ptn; |
| 2443 | struct ptable *ptable; |
| 2444 | |
| 2445 | ptable = flash_get_ptable(); |
| 2446 | if (ptable == NULL) { |
| 2447 | fastboot_fail("partition table doesn't exist"); |
| 2448 | return; |
| 2449 | } |
| 2450 | |
| 2451 | ptn = ptable_find(ptable, arg); |
| 2452 | if (ptn == NULL) { |
| 2453 | fastboot_fail("unknown partition name"); |
| 2454 | return; |
| 2455 | } |
| 2456 | |
| 2457 | if (flash_erase(ptn)) { |
| 2458 | fastboot_fail("failed to erase partition"); |
| 2459 | return; |
| 2460 | } |
| 2461 | fastboot_okay(""); |
| 2462 | } |
| 2463 | |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 2464 | |
| 2465 | void cmd_erase_mmc(const char *arg, void *data, unsigned sz) |
| 2466 | { |
| 2467 | unsigned long long ptn = 0; |
Oliver Wang | cee448d | 2013-10-22 18:40:13 +0800 | [diff] [blame] | 2468 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2469 | int index = INVALID_PTN; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2470 | uint8_t lun = 0; |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 2471 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2472 | #if VERIFIED_BOOT |
| 2473 | if(!strcmp(arg, KEYSTORE_PTN_NAME)) |
| 2474 | { |
| 2475 | if(!device.is_unlocked) |
| 2476 | { |
| 2477 | fastboot_fail("unlock device to erase keystore"); |
| 2478 | return; |
| 2479 | } |
| 2480 | } |
| 2481 | #endif |
| 2482 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2483 | index = partition_get_index(arg); |
| 2484 | ptn = partition_get_offset(index); |
Oliver Wang | cee448d | 2013-10-22 18:40:13 +0800 | [diff] [blame] | 2485 | size = partition_get_size(index); |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 2486 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2487 | if(ptn == 0) { |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 2488 | fastboot_fail("Partition table doesn't exist\n"); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 2489 | return; |
| 2490 | } |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 2491 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2492 | lun = partition_get_lun(index); |
| 2493 | mmc_set_lun(lun); |
| 2494 | |
Sridhar Parasuram | d795712 | 2015-02-27 11:33:40 -0800 | [diff] [blame] | 2495 | if (platform_boot_dev_isemmc()) |
| 2496 | { |
| 2497 | if (mmc_erase_card(ptn, size)) { |
| 2498 | fastboot_fail("failed to erase partition\n"); |
| 2499 | return; |
| 2500 | } |
| 2501 | } else { |
| 2502 | BUF_DMA_ALIGN(out, DEFAULT_ERASE_SIZE); |
| 2503 | size = partition_get_size(index); |
| 2504 | if (size > DEFAULT_ERASE_SIZE) |
| 2505 | size = DEFAULT_ERASE_SIZE; |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 2506 | |
Sridhar Parasuram | d795712 | 2015-02-27 11:33:40 -0800 | [diff] [blame] | 2507 | /* Simple inefficient version of erase. Just writing |
| 2508 | 0 in first several blocks */ |
| 2509 | if (mmc_write(ptn , size, (unsigned int *)out)) { |
| 2510 | fastboot_fail("failed to erase partition"); |
| 2511 | return; |
| 2512 | } |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 2513 | } |
Sridhar Parasuram | 32b3066 | 2015-07-10 13:33:22 -0700 | [diff] [blame] | 2514 | #if VERIFIED_BOOT |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 2515 | #if !VBOOT_MOTA |
Sridhar Parasuram | 32b3066 | 2015-07-10 13:33:22 -0700 | [diff] [blame] | 2516 | if(!(strncmp(arg, "userdata", 8))) |
| 2517 | if(send_delete_keys_to_tz()) |
| 2518 | ASSERT(0); |
| 2519 | #endif |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 2520 | #endif |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 2521 | fastboot_okay(""); |
| 2522 | } |
| 2523 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2524 | void cmd_erase(const char *arg, void *data, unsigned sz) |
| 2525 | { |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 2526 | #if VERIFIED_BOOT |
Channagoud Kadabi | 3529767 | 2015-06-13 11:09:49 -0700 | [diff] [blame] | 2527 | if (target_build_variant_user()) |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 2528 | { |
Sridhar Parasuram | c32d07d | 2015-07-12 10:57:48 -0700 | [diff] [blame] | 2529 | if(!device.is_unlocked) |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 2530 | { |
Channagoud Kadabi | 3529767 | 2015-06-13 11:09:49 -0700 | [diff] [blame] | 2531 | fastboot_fail("device is locked. Cannot erase"); |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 2532 | return; |
| 2533 | } |
| 2534 | } |
| 2535 | #endif |
| 2536 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2537 | if(target_is_emmc_boot()) |
| 2538 | cmd_erase_mmc(arg, data, sz); |
| 2539 | else |
| 2540 | cmd_erase_nand(arg, data, sz); |
| 2541 | } |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 2542 | |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 2543 | static uint32_t aboot_get_secret_key() |
| 2544 | { |
| 2545 | /* 0 is invalid secret key, update this implementation to return |
| 2546 | * device specific unique secret key |
| 2547 | */ |
| 2548 | return 0; |
| 2549 | } |
| 2550 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2551 | void cmd_flash_mmc_img(const char *arg, void *data, unsigned sz) |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2552 | { |
| 2553 | unsigned long long ptn = 0; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 2554 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2555 | int index = INVALID_PTN; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2556 | char *token = NULL; |
| 2557 | char *pname = NULL; |
Sridhar Parasuram | efc133f | 2015-05-04 13:35:41 -0700 | [diff] [blame] | 2558 | char *sp; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2559 | uint8_t lun = 0; |
| 2560 | bool lun_set = false; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 2561 | |
Sridhar Parasuram | efc133f | 2015-05-04 13:35:41 -0700 | [diff] [blame] | 2562 | token = strtok_r((char *)arg, ":", &sp); |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2563 | pname = token; |
Sridhar Parasuram | efc133f | 2015-05-04 13:35:41 -0700 | [diff] [blame] | 2564 | token = strtok_r(NULL, ":", &sp); |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2565 | if(token) |
| 2566 | { |
| 2567 | lun = atoi(token); |
| 2568 | mmc_set_lun(lun); |
| 2569 | lun_set = true; |
| 2570 | } |
| 2571 | |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2572 | if (pname) |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 2573 | { |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 2574 | if (!strncmp(pname, "frp-unlock", strlen("frp-unlock"))) |
| 2575 | { |
| 2576 | if (!aboot_frp_unlock(pname, data, sz)) |
| 2577 | { |
| 2578 | fastboot_info("FRP unlock successful"); |
| 2579 | fastboot_okay(""); |
| 2580 | } |
| 2581 | else |
| 2582 | fastboot_fail("Secret key is invalid, please update the bootloader with secret key"); |
| 2583 | |
| 2584 | return; |
| 2585 | } |
| 2586 | |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2587 | if (!strcmp(pname, "partition")) |
| 2588 | { |
| 2589 | dprintf(INFO, "Attempt to write partition image.\n"); |
| 2590 | if (write_partition(sz, (unsigned char *) data)) { |
| 2591 | fastboot_fail("failed to write partition"); |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 2592 | return; |
| 2593 | } |
| 2594 | } |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2595 | else |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2596 | { |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2597 | #if VERIFIED_BOOT |
| 2598 | if(!strcmp(pname, KEYSTORE_PTN_NAME)) |
| 2599 | { |
| 2600 | if(!device.is_unlocked) |
| 2601 | { |
| 2602 | fastboot_fail("unlock device to flash keystore"); |
| 2603 | return; |
| 2604 | } |
Gaurav Nebhwani | c7313cc | 2015-12-15 22:25:04 +0530 | [diff] [blame] | 2605 | if(!boot_verify_validate_keystore((unsigned char *)data,sz)) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2606 | { |
| 2607 | fastboot_fail("image is not a keystore file"); |
| 2608 | return; |
| 2609 | } |
| 2610 | } |
| 2611 | #endif |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2612 | index = partition_get_index(pname); |
| 2613 | ptn = partition_get_offset(index); |
| 2614 | if(ptn == 0) { |
| 2615 | fastboot_fail("partition table doesn't exist"); |
| 2616 | return; |
| 2617 | } |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2618 | |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2619 | if (!strcmp(pname, "boot") || !strcmp(pname, "recovery")) { |
| 2620 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 2621 | fastboot_fail("image is not a boot image"); |
| 2622 | return; |
| 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | if(!lun_set) |
| 2627 | { |
| 2628 | lun = partition_get_lun(index); |
| 2629 | mmc_set_lun(lun); |
| 2630 | } |
| 2631 | |
| 2632 | size = partition_get_size(index); |
Gaurav Nebhwani | 4d2389c | 2016-03-17 21:10:05 +0530 | [diff] [blame] | 2633 | if (ROUND_TO_PAGE(sz, mmc_blocksize_mask) > size) { |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2634 | fastboot_fail("size too large"); |
| 2635 | return; |
| 2636 | } |
| 2637 | else if (mmc_write(ptn , sz, (unsigned int *)data)) { |
| 2638 | fastboot_fail("flash write failure"); |
| 2639 | return; |
| 2640 | } |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 2641 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2642 | } |
| 2643 | fastboot_okay(""); |
| 2644 | return; |
| 2645 | } |
| 2646 | |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2647 | void cmd_flash_meta_img(const char *arg, void *data, unsigned sz) |
| 2648 | { |
| 2649 | int i, images; |
| 2650 | meta_header_t *meta_header; |
| 2651 | img_header_entry_t *img_header_entry; |
| 2652 | |
| 2653 | meta_header = (meta_header_t*) data; |
| 2654 | img_header_entry = (img_header_entry_t*) (data+sizeof(meta_header_t)); |
| 2655 | |
| 2656 | images = meta_header->img_hdr_sz / sizeof(img_header_entry_t); |
| 2657 | |
| 2658 | for (i=0; i<images; i++) { |
| 2659 | |
| 2660 | if((img_header_entry[i].ptn_name == NULL) || |
| 2661 | (img_header_entry[i].start_offset == 0) || |
| 2662 | (img_header_entry[i].size == 0)) |
| 2663 | break; |
| 2664 | |
| 2665 | cmd_flash_mmc_img(img_header_entry[i].ptn_name, |
| 2666 | (void *) data + img_header_entry[i].start_offset, |
| 2667 | img_header_entry[i].size); |
| 2668 | } |
| 2669 | |
Channagoud Kadabi | aafbbfc | 2015-03-04 17:52:56 -0800 | [diff] [blame] | 2670 | if (!strncmp(arg, "bootloader", strlen("bootloader"))) |
| 2671 | { |
| 2672 | strlcpy(device.bootloader_version, TARGET(BOARD), MAX_VERSION_LEN); |
| 2673 | strlcat(device.bootloader_version, "-", MAX_VERSION_LEN); |
| 2674 | strlcat(device.bootloader_version, meta_header->img_version, MAX_VERSION_LEN); |
| 2675 | } |
| 2676 | else |
| 2677 | { |
| 2678 | strlcpy(device.radio_version, TARGET(BOARD), MAX_VERSION_LEN); |
| 2679 | strlcat(device.radio_version, "-", MAX_VERSION_LEN); |
| 2680 | strlcat(device.radio_version, meta_header->img_version, MAX_VERSION_LEN); |
| 2681 | } |
| 2682 | |
| 2683 | write_device_info(&device); |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2684 | fastboot_okay(""); |
| 2685 | return; |
| 2686 | } |
| 2687 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2688 | void cmd_flash_mmc_sparse_img(const char *arg, void *data, unsigned sz) |
| 2689 | { |
| 2690 | unsigned int chunk; |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2691 | uint64_t chunk_data_sz; |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2692 | uint32_t *fill_buf = NULL; |
| 2693 | uint32_t fill_val; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2694 | sparse_header_t *sparse_header; |
| 2695 | chunk_header_t *chunk_header; |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 2696 | uint32_t total_blocks = 0; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2697 | unsigned long long ptn = 0; |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 2698 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2699 | int index = INVALID_PTN; |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 2700 | uint32_t i; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2701 | uint8_t lun = 0; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2702 | /*End of the sparse image address*/ |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 2703 | uintptr_t data_end = (uintptr_t)data + sz; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2704 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2705 | index = partition_get_index(arg); |
| 2706 | ptn = partition_get_offset(index); |
| 2707 | if(ptn == 0) { |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2708 | fastboot_fail("partition table doesn't exist"); |
| 2709 | return; |
| 2710 | } |
| 2711 | |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 2712 | size = partition_get_size(index); |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 2713 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2714 | lun = partition_get_lun(index); |
| 2715 | mmc_set_lun(lun); |
| 2716 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2717 | if (sz < sizeof(sparse_header_t)) { |
| 2718 | fastboot_fail("size too low"); |
| 2719 | return; |
| 2720 | } |
| 2721 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2722 | /* Read and skip over sparse image header */ |
| 2723 | sparse_header = (sparse_header_t *) data; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2724 | |
vijay kumar | 1321f34 | 2015-03-27 12:13:42 +0530 | [diff] [blame] | 2725 | if (((uint64_t)sparse_header->total_blks * (uint64_t)sparse_header->blk_sz) > size) { |
Ajay Dudani | 876b328 | 2012-12-21 14:12:17 -0800 | [diff] [blame] | 2726 | fastboot_fail("size too large"); |
| 2727 | return; |
| 2728 | } |
| 2729 | |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 2730 | data += sizeof(sparse_header_t); |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2731 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 2732 | if (data_end < (uintptr_t)data) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2733 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2734 | return; |
| 2735 | } |
| 2736 | |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 2737 | if(sparse_header->file_hdr_sz != sizeof(sparse_header_t)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2738 | { |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 2739 | fastboot_fail("sparse header size mismatch"); |
| 2740 | return; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 2743 | dprintf (SPEW, "=== Sparse Image Header ===\n"); |
| 2744 | dprintf (SPEW, "magic: 0x%x\n", sparse_header->magic); |
| 2745 | dprintf (SPEW, "major_version: 0x%x\n", sparse_header->major_version); |
| 2746 | dprintf (SPEW, "minor_version: 0x%x\n", sparse_header->minor_version); |
| 2747 | dprintf (SPEW, "file_hdr_sz: %d\n", sparse_header->file_hdr_sz); |
| 2748 | dprintf (SPEW, "chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz); |
| 2749 | dprintf (SPEW, "blk_sz: %d\n", sparse_header->blk_sz); |
| 2750 | dprintf (SPEW, "total_blks: %d\n", sparse_header->total_blks); |
| 2751 | dprintf (SPEW, "total_chunks: %d\n", sparse_header->total_chunks); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2752 | |
| 2753 | /* Start processing chunks */ |
| 2754 | for (chunk=0; chunk<sparse_header->total_chunks; chunk++) |
| 2755 | { |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2756 | /* Make sure the total image size does not exceed the partition size */ |
| 2757 | if(((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz) >= size) { |
| 2758 | fastboot_fail("size too large"); |
| 2759 | return; |
| 2760 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2761 | /* Read and skip over chunk header */ |
| 2762 | chunk_header = (chunk_header_t *) data; |
| 2763 | data += sizeof(chunk_header_t); |
| 2764 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 2765 | if (data_end < (uintptr_t)data) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2766 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2767 | return; |
| 2768 | } |
| 2769 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2770 | dprintf (SPEW, "=== Chunk Header ===\n"); |
| 2771 | dprintf (SPEW, "chunk_type: 0x%x\n", chunk_header->chunk_type); |
| 2772 | dprintf (SPEW, "chunk_data_sz: 0x%x\n", chunk_header->chunk_sz); |
| 2773 | dprintf (SPEW, "total_size: 0x%x\n", chunk_header->total_sz); |
| 2774 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2775 | if(sparse_header->chunk_hdr_sz != sizeof(chunk_header_t)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2776 | { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2777 | fastboot_fail("chunk header size mismatch"); |
| 2778 | return; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2781 | if (!sparse_header->blk_sz ){ |
| 2782 | fastboot_fail("Invalid block size\n"); |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2783 | return; |
| 2784 | } |
| 2785 | |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2786 | chunk_data_sz = (uint64_t)sparse_header->blk_sz * chunk_header->chunk_sz; |
| 2787 | |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2788 | /* Make sure that the chunk size calculated from sparse image does not |
| 2789 | * exceed partition size |
| 2790 | */ |
| 2791 | if ((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz + chunk_data_sz > size) |
| 2792 | { |
| 2793 | fastboot_fail("Chunk data size exceeds partition size"); |
| 2794 | return; |
| 2795 | } |
| 2796 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2797 | switch (chunk_header->chunk_type) |
| 2798 | { |
| 2799 | case CHUNK_TYPE_RAW: |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2800 | if((uint64_t)chunk_header->total_sz != ((uint64_t)sparse_header->chunk_hdr_sz + |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2801 | chunk_data_sz)) |
| 2802 | { |
| 2803 | fastboot_fail("Bogus chunk size for chunk type Raw"); |
| 2804 | return; |
| 2805 | } |
| 2806 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 2807 | if (data_end < (uintptr_t)data + chunk_data_sz) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2808 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2809 | return; |
| 2810 | } |
| 2811 | |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2812 | /* chunk_header->total_sz is uint32,So chunk_data_sz is now less than 2^32 |
| 2813 | otherwise it will return in the line above |
| 2814 | */ |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 2815 | if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz), |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2816 | (uint32_t)chunk_data_sz, |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 2817 | (unsigned int*)data)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2818 | { |
| 2819 | fastboot_fail("flash write failure"); |
| 2820 | return; |
| 2821 | } |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2822 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 2823 | fastboot_fail("Bogus size for RAW chunk type"); |
| 2824 | return; |
| 2825 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2826 | total_blocks += chunk_header->chunk_sz; |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2827 | data += (uint32_t)chunk_data_sz; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2828 | break; |
| 2829 | |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2830 | case CHUNK_TYPE_FILL: |
| 2831 | if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz + |
| 2832 | sizeof(uint32_t))) |
| 2833 | { |
| 2834 | fastboot_fail("Bogus chunk size for chunk type FILL"); |
| 2835 | return; |
| 2836 | } |
| 2837 | |
| 2838 | fill_buf = (uint32_t *)memalign(CACHE_LINE, ROUNDUP(sparse_header->blk_sz, CACHE_LINE)); |
| 2839 | if (!fill_buf) |
| 2840 | { |
| 2841 | fastboot_fail("Malloc failed for: CHUNK_TYPE_FILL"); |
| 2842 | return; |
| 2843 | } |
| 2844 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 2845 | if (data_end < (uintptr_t)data + sizeof(uint32_t)) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2846 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
Gaurav Nebhwani | 163cbf8 | 2016-03-17 21:21:27 +0530 | [diff] [blame] | 2847 | free(fill_buf); |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2848 | return; |
| 2849 | } |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2850 | fill_val = *(uint32_t *)data; |
| 2851 | data = (char *) data + sizeof(uint32_t); |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2852 | |
| 2853 | for (i = 0; i < (sparse_header->blk_sz / sizeof(fill_val)); i++) |
| 2854 | { |
| 2855 | fill_buf[i] = fill_val; |
| 2856 | } |
| 2857 | |
Gaurav Nebhwani | e94cbe1 | 2016-03-17 21:16:34 +0530 | [diff] [blame] | 2858 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) |
| 2859 | { |
| 2860 | fastboot_fail("bogus size for chunk FILL type"); |
| 2861 | free(fill_buf); |
| 2862 | return; |
| 2863 | } |
| 2864 | |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2865 | for (i = 0; i < chunk_header->chunk_sz; i++) |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2866 | { |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2867 | /* Make sure that the data written to partition does not exceed partition size */ |
| 2868 | if ((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz + sparse_header->blk_sz > size) |
| 2869 | { |
| 2870 | fastboot_fail("Chunk data size for fill type exceeds partition size"); |
Gaurav Nebhwani | 163cbf8 | 2016-03-17 21:21:27 +0530 | [diff] [blame] | 2871 | free(fill_buf); |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2872 | return; |
| 2873 | } |
| 2874 | |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2875 | if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz), |
| 2876 | sparse_header->blk_sz, |
| 2877 | fill_buf)) |
| 2878 | { |
| 2879 | fastboot_fail("flash write failure"); |
| 2880 | free(fill_buf); |
| 2881 | return; |
| 2882 | } |
| 2883 | |
| 2884 | total_blocks++; |
| 2885 | } |
| 2886 | |
| 2887 | free(fill_buf); |
| 2888 | break; |
| 2889 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2890 | case CHUNK_TYPE_DONT_CARE: |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2891 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 2892 | fastboot_fail("bogus size for chunk DONT CARE type"); |
| 2893 | return; |
| 2894 | } |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 2895 | total_blocks += chunk_header->chunk_sz; |
| 2896 | break; |
| 2897 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2898 | case CHUNK_TYPE_CRC: |
| 2899 | if(chunk_header->total_sz != sparse_header->chunk_hdr_sz) |
| 2900 | { |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2901 | fastboot_fail("Bogus chunk size for chunk type CRC"); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2902 | return; |
| 2903 | } |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2904 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 2905 | fastboot_fail("bogus size for chunk CRC type"); |
| 2906 | return; |
| 2907 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2908 | total_blocks += chunk_header->chunk_sz; |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 2909 | if ((uintptr_t)data > UINT_MAX - chunk_data_sz) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2910 | fastboot_fail("integer overflow occured"); |
| 2911 | return; |
| 2912 | } |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 2913 | data += (uint32_t)chunk_data_sz; |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 2914 | if (data_end < (uintptr_t)data) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 2915 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2916 | return; |
| 2917 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2918 | break; |
| 2919 | |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 2920 | default: |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2921 | dprintf(CRITICAL, "Unkown chunk type: %x\n",chunk_header->chunk_type); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2922 | fastboot_fail("Unknown chunk type"); |
| 2923 | return; |
| 2924 | } |
| 2925 | } |
| 2926 | |
Ajay Dudani | 0c6927b | 2011-05-18 11:12:16 -0700 | [diff] [blame] | 2927 | dprintf(INFO, "Wrote %d blocks, expected to write %d blocks\n", |
| 2928 | total_blocks, sparse_header->total_blks); |
| 2929 | |
| 2930 | if(total_blocks != sparse_header->total_blks) |
| 2931 | { |
| 2932 | fastboot_fail("sparse image write failure"); |
| 2933 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2934 | |
| 2935 | fastboot_okay(""); |
| 2936 | return; |
| 2937 | } |
| 2938 | |
| 2939 | void cmd_flash_mmc(const char *arg, void *data, unsigned sz) |
| 2940 | { |
| 2941 | sparse_header_t *sparse_header; |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2942 | meta_header_t *meta_header; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2943 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 2944 | #ifdef SSD_ENABLE |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 2945 | /* 8 Byte Magic + 2048 Byte xml + Encrypted Data */ |
| 2946 | unsigned int *magic_number = (unsigned int *) data; |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2947 | int ret=0; |
| 2948 | uint32 major_version=0; |
| 2949 | uint32 minor_version=0; |
| 2950 | |
| 2951 | ret = scm_svc_version(&major_version,&minor_version); |
| 2952 | if(!ret) |
| 2953 | { |
| 2954 | if(major_version >= 2) |
| 2955 | { |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 2956 | if( !strcmp(arg, "ssd") || !strcmp(arg, "tqs") ) |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2957 | { |
| 2958 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 2959 | if (ret != 0) { |
| 2960 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 2961 | return; |
| 2962 | } |
| 2963 | |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 2964 | /* Protect only for SSD */ |
| 2965 | if (!strcmp(arg, "ssd")) { |
| 2966 | ret = scm_protect_keystore((uint32 *) data, sz); |
| 2967 | if (ret != 0) { |
| 2968 | dprintf(CRITICAL, "ERROR: scm_protect_keystore Failed\n"); |
| 2969 | return; |
| 2970 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2971 | } |
| 2972 | } |
| 2973 | else |
| 2974 | { |
| 2975 | ret = decrypt_scm_v2((uint32 **) &data, &sz); |
| 2976 | if(ret != 0) |
| 2977 | { |
| 2978 | dprintf(CRITICAL,"ERROR: Decryption Failure\n"); |
| 2979 | return; |
| 2980 | } |
| 2981 | } |
| 2982 | } |
| 2983 | else |
| 2984 | { |
| 2985 | if (magic_number[0] == DECRYPT_MAGIC_0 && |
| 2986 | magic_number[1] == DECRYPT_MAGIC_1) |
| 2987 | { |
| 2988 | ret = decrypt_scm((uint32 **) &data, &sz); |
| 2989 | if (ret != 0) { |
| 2990 | dprintf(CRITICAL, "ERROR: Invalid secure image\n"); |
| 2991 | return; |
| 2992 | } |
| 2993 | } |
| 2994 | else if (magic_number[0] == ENCRYPT_MAGIC_0 && |
| 2995 | magic_number[1] == ENCRYPT_MAGIC_1) |
| 2996 | { |
| 2997 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 2998 | if (ret != 0) { |
| 2999 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 3000 | return; |
| 3001 | } |
| 3002 | } |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 3003 | } |
| 3004 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 3005 | else |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 3006 | { |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 3007 | dprintf(CRITICAL,"INVALID SVC Version\n"); |
| 3008 | return; |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 3009 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 3010 | #endif /* SSD_ENABLE */ |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 3011 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3012 | #if VERIFIED_BOOT |
Channagoud Kadabi | 3529767 | 2015-06-13 11:09:49 -0700 | [diff] [blame] | 3013 | if (target_build_variant_user()) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3014 | { |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3015 | /* if device is locked: |
| 3016 | * common partition will not allow to be flashed |
| 3017 | * critical partition will allow to flash image. |
| 3018 | */ |
| 3019 | if(!device.is_unlocked && !critical_flash_allowed(arg)) { |
| 3020 | fastboot_fail("Partition flashing is not allowed"); |
| 3021 | return; |
| 3022 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3023 | #if !VBOOT_MOTA |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3024 | /* if device critical is locked: |
| 3025 | * common partition will allow to be flashed |
| 3026 | * critical partition will not allow to flash image. |
| 3027 | */ |
| 3028 | if(!device.is_unlock_critical && critical_flash_allowed(arg)) { |
| 3029 | fastboot_fail("Critical partition flashing is not allowed"); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3030 | return; |
| 3031 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3032 | #endif |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3033 | } |
| 3034 | #endif |
| 3035 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 3036 | sparse_header = (sparse_header_t *) data; |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3037 | meta_header = (meta_header_t *) data; |
| 3038 | if (sparse_header->magic == SPARSE_HEADER_MAGIC) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3039 | cmd_flash_mmc_sparse_img(arg, data, sz); |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3040 | else if (meta_header->magic == META_HEADER_MAGIC) |
| 3041 | cmd_flash_meta_img(arg, data, sz); |
| 3042 | else |
| 3043 | cmd_flash_mmc_img(arg, data, sz); |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 3044 | |
| 3045 | #if VERIFIED_BOOT |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3046 | #if !VBOOT_MOTA |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 3047 | if((!strncmp(arg, "system", 6)) && !device.verity_mode) |
| 3048 | { |
| 3049 | // reset dm_verity mode to enforcing |
| 3050 | device.verity_mode = 1; |
| 3051 | write_device_info(&device); |
| 3052 | } |
| 3053 | #endif |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3054 | #endif |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 3055 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3056 | return; |
| 3057 | } |
| 3058 | |
Tanya Brokhman | 84eaaf6 | 2015-02-24 21:57:06 +0200 | [diff] [blame] | 3059 | void cmd_updatevol(const char *vol_name, void *data, unsigned sz) |
| 3060 | { |
| 3061 | struct ptentry *sys_ptn; |
| 3062 | struct ptable *ptable; |
| 3063 | |
| 3064 | ptable = flash_get_ptable(); |
| 3065 | if (ptable == NULL) { |
| 3066 | fastboot_fail("partition table doesn't exist"); |
| 3067 | return; |
| 3068 | } |
| 3069 | |
| 3070 | sys_ptn = ptable_find(ptable, "system"); |
| 3071 | if (sys_ptn == NULL) { |
| 3072 | fastboot_fail("system partition not found"); |
| 3073 | return; |
| 3074 | } |
| 3075 | |
| 3076 | sz = ROUND_TO_PAGE(sz, page_mask); |
| 3077 | if (update_ubi_vol(sys_ptn, vol_name, data, sz)) |
| 3078 | fastboot_fail("update_ubi_vol failed"); |
| 3079 | else |
| 3080 | fastboot_okay(""); |
| 3081 | } |
| 3082 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3083 | void cmd_flash_nand(const char *arg, void *data, unsigned sz) |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3084 | { |
| 3085 | struct ptentry *ptn; |
| 3086 | struct ptable *ptable; |
| 3087 | unsigned extra = 0; |
| 3088 | |
| 3089 | ptable = flash_get_ptable(); |
| 3090 | if (ptable == NULL) { |
| 3091 | fastboot_fail("partition table doesn't exist"); |
| 3092 | return; |
| 3093 | } |
| 3094 | |
| 3095 | ptn = ptable_find(ptable, arg); |
| 3096 | if (ptn == NULL) { |
Tanya Brokhman | 84eaaf6 | 2015-02-24 21:57:06 +0200 | [diff] [blame] | 3097 | dprintf(INFO, "unknown partition name (%s). Trying updatevol\n", |
| 3098 | arg); |
| 3099 | cmd_updatevol(arg, data, sz); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3100 | return; |
| 3101 | } |
| 3102 | |
| 3103 | if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) { |
| 3104 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 3105 | fastboot_fail("image is not a boot image"); |
| 3106 | return; |
| 3107 | } |
| 3108 | } |
| 3109 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 3110 | if (!strcmp(ptn->name, "system") |
Deepa Dinamani | 13e32c4 | 2012-03-12 14:34:17 -0700 | [diff] [blame] | 3111 | || !strcmp(ptn->name, "userdata") |
| 3112 | || !strcmp(ptn->name, "persist") |
Sundarajan Srinivasan | b063a85 | 2013-11-19 14:02:27 -0800 | [diff] [blame] | 3113 | || !strcmp(ptn->name, "recoveryfs") |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 3114 | || !strcmp(ptn->name, "modem")) |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 3115 | extra = 1; |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 3116 | else |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 3117 | sz = ROUND_TO_PAGE(sz, page_mask); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3118 | |
| 3119 | dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name); |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 3120 | if (!memcmp((void *)data, UBI_MAGIC, UBI_MAGIC_SIZE)) { |
| 3121 | if (flash_ubi_img(ptn, data, sz)) { |
| 3122 | fastboot_fail("flash write failure"); |
| 3123 | return; |
| 3124 | } |
| 3125 | } else { |
| 3126 | if (flash_write(ptn, extra, data, sz)) { |
| 3127 | fastboot_fail("flash write failure"); |
| 3128 | return; |
| 3129 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3130 | } |
| 3131 | dprintf(INFO, "partition '%s' updated\n", ptn->name); |
| 3132 | fastboot_okay(""); |
| 3133 | } |
| 3134 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3135 | void cmd_flash(const char *arg, void *data, unsigned sz) |
| 3136 | { |
| 3137 | if(target_is_emmc_boot()) |
| 3138 | cmd_flash_mmc(arg, data, sz); |
| 3139 | else |
| 3140 | cmd_flash_nand(arg, data, sz); |
| 3141 | } |
| 3142 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3143 | void cmd_continue(const char *arg, void *data, unsigned sz) |
| 3144 | { |
| 3145 | fastboot_okay(""); |
Amol Jadi | 7c4316c | 2013-10-07 14:19:26 -0700 | [diff] [blame] | 3146 | fastboot_stop(); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3147 | |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3148 | if (target_is_emmc_boot()) |
| 3149 | { |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 3150 | #if FBCON_DISPLAY_MSG |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 3151 | /* Exit keys' detection thread firstly */ |
| 3152 | exit_menu_keys_detection(); |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 3153 | #endif |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3154 | boot_linux_from_mmc(); |
| 3155 | } |
| 3156 | else |
| 3157 | { |
| 3158 | boot_linux_from_flash(); |
| 3159 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3160 | } |
| 3161 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 3162 | void cmd_reboot(const char *arg, void *data, unsigned sz) |
| 3163 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3164 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 3165 | fastboot_okay(""); |
| 3166 | reboot_device(0); |
| 3167 | } |
| 3168 | |
| 3169 | void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz) |
| 3170 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3171 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 3172 | fastboot_okay(""); |
| 3173 | reboot_device(FASTBOOT_MODE); |
| 3174 | } |
| 3175 | |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 3176 | void cmd_oem_enable_charger_screen(const char *arg, void *data, unsigned size) |
| 3177 | { |
| 3178 | dprintf(INFO, "Enabling charger screen check\n"); |
| 3179 | device.charger_screen_enabled = 1; |
| 3180 | write_device_info(&device); |
| 3181 | fastboot_okay(""); |
| 3182 | } |
| 3183 | |
| 3184 | void cmd_oem_disable_charger_screen(const char *arg, void *data, unsigned size) |
| 3185 | { |
| 3186 | dprintf(INFO, "Disabling charger screen check\n"); |
| 3187 | device.charger_screen_enabled = 0; |
| 3188 | write_device_info(&device); |
| 3189 | fastboot_okay(""); |
| 3190 | } |
| 3191 | |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 3192 | void cmd_oem_off_mode_charger(const char *arg, void *data, unsigned size) |
| 3193 | { |
| 3194 | char *p = NULL; |
| 3195 | const char *delim = " \t\n\r"; |
Parth Dixit | 407f15b | 2016-01-07 14:47:37 +0530 | [diff] [blame] | 3196 | char *sp; |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 3197 | |
| 3198 | if (arg) { |
Parth Dixit | 407f15b | 2016-01-07 14:47:37 +0530 | [diff] [blame] | 3199 | p = strtok_r((char *)arg, delim, &sp); |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 3200 | if (p) { |
| 3201 | if (!strncmp(p, "0", 1)) { |
| 3202 | device.charger_screen_enabled = 0; |
| 3203 | } else if (!strncmp(p, "1", 1)) { |
| 3204 | device.charger_screen_enabled = 1; |
| 3205 | } |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | /* update charger_screen_enabled value for getvar |
| 3210 | * command |
| 3211 | */ |
| 3212 | snprintf(charger_screen_enabled, MAX_RSP_SIZE, "%d", |
| 3213 | device.charger_screen_enabled); |
| 3214 | |
| 3215 | write_device_info(&device); |
| 3216 | fastboot_okay(""); |
| 3217 | } |
| 3218 | |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 3219 | void cmd_oem_select_display_panel(const char *arg, void *data, unsigned size) |
| 3220 | { |
| 3221 | dprintf(INFO, "Selecting display panel %s\n", arg); |
| 3222 | if (arg) |
| 3223 | strlcpy(device.display_panel, arg, |
| 3224 | sizeof(device.display_panel)); |
| 3225 | write_device_info(&device); |
| 3226 | fastboot_okay(""); |
| 3227 | } |
| 3228 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 3229 | void cmd_oem_unlock(const char *arg, void *data, unsigned sz) |
| 3230 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3231 | set_device_unlock(UNLOCK, TRUE); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | void cmd_oem_unlock_go(const char *arg, void *data, unsigned sz) |
| 3235 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3236 | if(!device.is_unlocked) { |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 3237 | if(!is_allow_unlock) { |
| 3238 | fastboot_fail("oem unlock is not allowed"); |
| 3239 | return; |
| 3240 | } |
| 3241 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3242 | set_device_unlock_value(UNLOCK, TRUE); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 3243 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3244 | /* wipe data */ |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 3245 | struct recovery_message msg; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3246 | |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 3247 | snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data"); |
| 3248 | write_misc(0, &msg, sizeof(msg)); |
| 3249 | |
| 3250 | fastboot_okay(""); |
| 3251 | reboot_device(RECOVERY_MODE); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3252 | } |
| 3253 | fastboot_okay(""); |
| 3254 | } |
| 3255 | |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 3256 | static int aboot_frp_unlock(char *pname, void *data, unsigned sz) |
| 3257 | { |
| 3258 | int ret = 1; |
| 3259 | uint32_t secret_key; |
| 3260 | char seckey_buffer[MAX_RSP_SIZE]; |
| 3261 | |
| 3262 | secret_key = aboot_get_secret_key(); |
| 3263 | if (secret_key) |
| 3264 | { |
| 3265 | snprintf((char *) seckey_buffer, MAX_RSP_SIZE, "%x", secret_key); |
| 3266 | if (!memcmp((void *)data, (void *)seckey_buffer, sz)) |
| 3267 | { |
| 3268 | is_allow_unlock = true; |
| 3269 | write_allow_oem_unlock(is_allow_unlock); |
| 3270 | ret = 0; |
| 3271 | } |
| 3272 | } |
| 3273 | return ret; |
| 3274 | } |
| 3275 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3276 | void cmd_oem_lock(const char *arg, void *data, unsigned sz) |
| 3277 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3278 | set_device_unlock(UNLOCK, FALSE); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3281 | void cmd_oem_devinfo(const char *arg, void *data, unsigned sz) |
| 3282 | { |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3283 | char response[MAX_RSP_SIZE]; |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 3284 | snprintf(response, sizeof(response), "\tDevice tampered: %s", (device.is_tampered ? "true" : "false")); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3285 | fastboot_info(response); |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 3286 | snprintf(response, sizeof(response), "\tDevice unlocked: %s", (device.is_unlocked ? "true" : "false")); |
| 3287 | fastboot_info(response); |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3288 | #if !VBOOT_MOTA |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3289 | snprintf(response, sizeof(response), "\tDevice critical unlocked: %s", (device.is_unlock_critical ? "true" : "false")); |
| 3290 | fastboot_info(response); |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3291 | #endif |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 3292 | snprintf(response, sizeof(response), "\tCharger screen enabled: %s", (device.charger_screen_enabled ? "true" : "false")); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3293 | fastboot_info(response); |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 3294 | snprintf(response, sizeof(response), "\tDisplay panel: %s", (device.display_panel)); |
| 3295 | fastboot_info(response); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3296 | fastboot_okay(""); |
| 3297 | } |
| 3298 | |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3299 | void cmd_flashing_get_unlock_ability(const char *arg, void *data, unsigned sz) |
| 3300 | { |
| 3301 | char response[MAX_RSP_SIZE]; |
| 3302 | snprintf(response, sizeof(response), "\tget_unlock_ability: %d", is_allow_unlock); |
| 3303 | fastboot_info(response); |
| 3304 | fastboot_okay(""); |
| 3305 | } |
| 3306 | |
| 3307 | void cmd_flashing_lock_critical(const char *arg, void *data, unsigned sz) |
| 3308 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3309 | set_device_unlock(UNLOCK_CRITICAL, FALSE); |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | void cmd_flashing_unlock_critical(const char *arg, void *data, unsigned sz) |
| 3313 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3314 | set_device_unlock(UNLOCK_CRITICAL, TRUE); |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3315 | } |
| 3316 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 3317 | void cmd_preflash(const char *arg, void *data, unsigned sz) |
| 3318 | { |
| 3319 | fastboot_okay(""); |
| 3320 | } |
| 3321 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3322 | static uint8_t logo_header[LOGO_IMG_HEADER_SIZE]; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3323 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3324 | int splash_screen_check_header(logo_img_header *header) |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3325 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3326 | if (memcmp(header->magic, LOGO_IMG_MAGIC, 8)) |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3327 | return -1; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3328 | if (header->width == 0 || header->height == 0) |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3329 | return -1; |
| 3330 | return 0; |
| 3331 | } |
| 3332 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3333 | int splash_screen_flash() |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3334 | { |
| 3335 | struct ptentry *ptn; |
| 3336 | struct ptable *ptable; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3337 | struct logo_img_header *header; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3338 | struct fbcon_config *fb_display = NULL; |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 3339 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3340 | ptable = flash_get_ptable(); |
| 3341 | if (ptable == NULL) { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3342 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 3343 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3344 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3345 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3346 | ptn = ptable_find(ptable, "splash"); |
| 3347 | if (ptn == NULL) { |
| 3348 | dprintf(CRITICAL, "ERROR: splash Partition not found\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3349 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3350 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3351 | if (flash_read(ptn, 0, (void *)logo_header, LOGO_IMG_HEADER_SIZE)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3352 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3353 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3354 | } |
| 3355 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3356 | header = (struct logo_img_header *)logo_header; |
| 3357 | if (splash_screen_check_header(header)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3358 | dprintf(CRITICAL, "ERROR: Boot image header invalid\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3359 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3360 | } |
| 3361 | |
| 3362 | fb_display = fbcon_display(); |
| 3363 | if (fb_display) { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3364 | if (header->type && (header->blocks != 0)) { // RLE24 compressed data |
| 3365 | uint8_t *base = (uint8_t *) fb_display->base + LOGO_IMG_OFFSET; |
| 3366 | |
| 3367 | /* if the logo is full-screen size, remove "fbcon_clear()" */ |
| 3368 | if ((header->width != fb_display->width) |
| 3369 | || (header->height != fb_display->height)) |
| 3370 | fbcon_clear(); |
| 3371 | |
| 3372 | if (flash_read(ptn + LOGO_IMG_HEADER_SIZE, 0, |
| 3373 | (uint32_t *)base, |
| 3374 | (header->blocks * 512))) { |
| 3375 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 3376 | return -1; |
| 3377 | } |
| 3378 | fbcon_extract_to_screen(header, base); |
| 3379 | return 0; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3380 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3381 | |
Veera Sundaram Sankaran | c33416f | 2015-09-28 10:25:55 -0700 | [diff] [blame] | 3382 | if ((header->width > fb_display->width) || (header->height > fb_display->height)) { |
| 3383 | dprintf(CRITICAL, "Logo config greater than fb config. Fall back default logo\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3384 | return -1; |
| 3385 | } |
| 3386 | |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 3387 | uint8_t *base = (uint8_t *) fb_display->base; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3388 | if (flash_read(ptn + LOGO_IMG_HEADER_SIZE, 0, |
| 3389 | (uint32_t *)base, |
| 3390 | ((((header->width * header->height * fb_display->bpp/8) + 511) >> 9) << 9))) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3391 | fbcon_clear(); |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 3392 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3393 | return -1; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3394 | } |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3395 | } |
| 3396 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3397 | return 0; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3398 | } |
| 3399 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3400 | int splash_screen_mmc() |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3401 | { |
| 3402 | int index = INVALID_PTN; |
| 3403 | unsigned long long ptn = 0; |
| 3404 | struct fbcon_config *fb_display = NULL; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3405 | struct logo_img_header *header; |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3406 | uint32_t blocksize, realsize, readsize; |
| 3407 | uint8_t *base; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3408 | |
| 3409 | index = partition_get_index("splash"); |
| 3410 | if (index == 0) { |
| 3411 | dprintf(CRITICAL, "ERROR: splash Partition table not found\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3412 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | ptn = partition_get_offset(index); |
| 3416 | if (ptn == 0) { |
| 3417 | dprintf(CRITICAL, "ERROR: splash Partition invalid\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3418 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3419 | } |
| 3420 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3421 | mmc_set_lun(partition_get_lun(index)); |
| 3422 | |
| 3423 | blocksize = mmc_get_device_blocksize(); |
| 3424 | if (blocksize == 0) { |
| 3425 | dprintf(CRITICAL, "ERROR:splash Partition invalid blocksize\n"); |
| 3426 | return -1; |
| 3427 | } |
| 3428 | |
| 3429 | fb_display = fbcon_display(); |
Channagoud Kadabi | daf10a6 | 2015-07-22 11:51:55 -0700 | [diff] [blame] | 3430 | if (!fb_display) |
| 3431 | { |
| 3432 | dprintf(CRITICAL, "ERROR: fb config is not allocated\n"); |
| 3433 | return -1; |
| 3434 | } |
| 3435 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3436 | base = (uint8_t *) fb_display->base; |
| 3437 | |
| 3438 | if (mmc_read(ptn, (uint32_t *)(base + LOGO_IMG_OFFSET), blocksize)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3439 | dprintf(CRITICAL, "ERROR: Cannot read splash image header\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3440 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3441 | } |
| 3442 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3443 | header = (struct logo_img_header *)(base + LOGO_IMG_OFFSET); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3444 | if (splash_screen_check_header(header)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3445 | dprintf(CRITICAL, "ERROR: Splash image header invalid\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3446 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3447 | } |
| 3448 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3449 | if (fb_display) { |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3450 | if (header->type && (header->blocks != 0)) { /* 1 RLE24 compressed data */ |
| 3451 | base += LOGO_IMG_OFFSET; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3452 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3453 | realsize = header->blocks * 512; |
| 3454 | readsize = ROUNDUP((realsize + LOGO_IMG_HEADER_SIZE), blocksize) - blocksize; |
| 3455 | |
| 3456 | /* if the logo is not full-screen size, clean screen */ |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3457 | if ((header->width != fb_display->width) |
| 3458 | || (header->height != fb_display->height)) |
| 3459 | fbcon_clear(); |
| 3460 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3461 | if (mmc_read(ptn + blocksize, (uint32_t *)(base + blocksize), readsize)) { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3462 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 3463 | return -1; |
| 3464 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3465 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3466 | fbcon_extract_to_screen(header, (base + LOGO_IMG_HEADER_SIZE)); |
| 3467 | } else { /* 2 Raw BGR data */ |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3468 | |
Veera Sundaram Sankaran | c33416f | 2015-09-28 10:25:55 -0700 | [diff] [blame] | 3469 | if ((header->width > fb_display->width) || (header->height > fb_display->height)) { |
| 3470 | dprintf(CRITICAL, "Logo config greater than fb config. Fall back default logo\n"); |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 3471 | return -1; |
| 3472 | } |
| 3473 | |
| 3474 | realsize = header->width * header->height * fb_display->bpp / 8; |
| 3475 | readsize = ROUNDUP((realsize + LOGO_IMG_HEADER_SIZE), blocksize) - blocksize; |
| 3476 | |
| 3477 | if (blocksize == LOGO_IMG_HEADER_SIZE) { /* read the content directly */ |
| 3478 | if (mmc_read((ptn + LOGO_IMG_HEADER_SIZE), (uint32_t *)base, readsize)) { |
| 3479 | fbcon_clear(); |
| 3480 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 3481 | return -1; |
| 3482 | } |
| 3483 | } else { |
| 3484 | if (mmc_read(ptn + blocksize , |
| 3485 | (uint32_t *)(base + LOGO_IMG_OFFSET + blocksize), readsize)) { |
| 3486 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 3487 | return -1; |
| 3488 | } |
| 3489 | memmove(base, (base + LOGO_IMG_OFFSET + LOGO_IMG_HEADER_SIZE), realsize); |
| 3490 | } |
| 3491 | } |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3492 | } |
| 3493 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3494 | return 0; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3495 | } |
| 3496 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 3497 | int fetch_image_from_partition() |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 3498 | { |
| 3499 | if (target_is_emmc_boot()) { |
| 3500 | return splash_screen_mmc(); |
| 3501 | } else { |
| 3502 | return splash_screen_flash(); |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3503 | } |
| 3504 | } |
| 3505 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 3506 | /* Get the size from partiton name */ |
| 3507 | static void get_partition_size(const char *arg, char *response) |
| 3508 | { |
| 3509 | uint64_t ptn = 0; |
| 3510 | uint64_t size; |
| 3511 | int index = INVALID_PTN; |
| 3512 | |
| 3513 | index = partition_get_index(arg); |
| 3514 | |
| 3515 | if (index == INVALID_PTN) |
| 3516 | { |
| 3517 | dprintf(CRITICAL, "Invalid partition index\n"); |
| 3518 | return; |
| 3519 | } |
| 3520 | |
| 3521 | ptn = partition_get_offset(index); |
| 3522 | |
| 3523 | if(!ptn) |
| 3524 | { |
| 3525 | dprintf(CRITICAL, "Invalid partition name %s\n", arg); |
| 3526 | return; |
| 3527 | } |
| 3528 | |
| 3529 | size = partition_get_size(index); |
| 3530 | |
| 3531 | snprintf(response, MAX_RSP_SIZE, "\t 0x%llx", size); |
| 3532 | return; |
| 3533 | } |
| 3534 | |
| 3535 | /* |
| 3536 | * Publish the partition type & size info |
| 3537 | * fastboot getvar will publish the required information. |
| 3538 | * fastboot getvar partition_size:<partition_name>: partition size in hex |
| 3539 | * fastboot getvar partition_type:<partition_name>: partition type (ext/fat) |
| 3540 | */ |
| 3541 | static void publish_getvar_partition_info(struct getvar_partition_info *info, uint8_t num_parts) |
| 3542 | { |
| 3543 | uint8_t i; |
| 3544 | |
| 3545 | for (i = 0; i < num_parts; i++) { |
| 3546 | get_partition_size(info[i].part_name, info[i].size_response); |
| 3547 | |
| 3548 | if (strlcat(info[i].getvar_size, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 3549 | { |
| 3550 | dprintf(CRITICAL, "partition size name truncated\n"); |
| 3551 | return; |
| 3552 | } |
| 3553 | if (strlcat(info[i].getvar_type, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 3554 | { |
| 3555 | dprintf(CRITICAL, "partition type name truncated\n"); |
| 3556 | return; |
| 3557 | } |
| 3558 | |
| 3559 | /* publish partition size & type info */ |
| 3560 | fastboot_publish((const char *) info[i].getvar_size, (const char *) info[i].size_response); |
| 3561 | fastboot_publish((const char *) info[i].getvar_type, (const char *) info[i].type_response); |
| 3562 | } |
| 3563 | } |
| 3564 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3565 | void get_product_name(unsigned char *buf) |
| 3566 | { |
| 3567 | snprintf((char*)buf, MAX_RSP_SIZE, "%s", TARGET(BOARD)); |
| 3568 | return; |
| 3569 | } |
| 3570 | |
| 3571 | void get_bootloader_version(unsigned char *buf) |
| 3572 | { |
| 3573 | snprintf((char*)buf, MAX_RSP_SIZE, "%s", device.bootloader_version); |
| 3574 | return; |
| 3575 | } |
| 3576 | |
| 3577 | void get_baseband_version(unsigned char *buf) |
| 3578 | { |
| 3579 | snprintf((char*)buf, MAX_RSP_SIZE, "%s", device.radio_version); |
| 3580 | return; |
| 3581 | } |
| 3582 | |
| 3583 | bool is_device_locked() |
| 3584 | { |
| 3585 | return device.is_unlocked ? false:true; |
| 3586 | } |
| 3587 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3588 | /* register commands and variables for fastboot */ |
| 3589 | void aboot_fastboot_register_commands(void) |
| 3590 | { |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3591 | int i; |
lijuang | f16461c | 2015-08-03 17:09:34 +0800 | [diff] [blame] | 3592 | char hw_platform_buf[MAX_RSP_SIZE]; |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3593 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3594 | struct fastboot_cmd_desc cmd_list[] = { |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3595 | /* By default the enabled list is empty. */ |
| 3596 | {"", NULL}, |
| 3597 | /* move commands enclosed within the below ifndef to here |
| 3598 | * if they need to be enabled in user build. |
| 3599 | */ |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3600 | #ifndef DISABLE_FASTBOOT_CMDS |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3601 | /* Register the following commands only for non-user builds */ |
| 3602 | {"flash:", cmd_flash}, |
| 3603 | {"erase:", cmd_erase}, |
| 3604 | {"boot", cmd_boot}, |
| 3605 | {"continue", cmd_continue}, |
| 3606 | {"reboot", cmd_reboot}, |
| 3607 | {"reboot-bootloader", cmd_reboot_bootloader}, |
| 3608 | {"oem unlock", cmd_oem_unlock}, |
| 3609 | {"oem unlock-go", cmd_oem_unlock_go}, |
| 3610 | {"oem lock", cmd_oem_lock}, |
| 3611 | {"flashing unlock", cmd_oem_unlock}, |
| 3612 | {"flashing lock", cmd_oem_lock}, |
| 3613 | {"flashing lock_critical", cmd_flashing_lock_critical}, |
| 3614 | {"flashing unlock_critical", cmd_flashing_unlock_critical}, |
| 3615 | {"flashing get_unlock_ability", cmd_flashing_get_unlock_ability}, |
| 3616 | {"oem device-info", cmd_oem_devinfo}, |
| 3617 | {"preflash", cmd_preflash}, |
| 3618 | {"oem enable-charger-screen", cmd_oem_enable_charger_screen}, |
| 3619 | {"oem disable-charger-screen", cmd_oem_disable_charger_screen}, |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 3620 | {"oem off-mode-charge", cmd_oem_off_mode_charger}, |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3621 | {"oem select-display-panel", cmd_oem_select_display_panel}, |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 3622 | #if UNITTEST_FW_SUPPORT |
Channagoud Kadabi | d5ddf48 | 2015-09-28 10:31:35 -0700 | [diff] [blame] | 3623 | {"oem run-tests", cmd_oem_runtests}, |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 3624 | #endif |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3625 | #endif |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 3626 | }; |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3627 | |
| 3628 | int fastboot_cmds_count = sizeof(cmd_list)/sizeof(cmd_list[0]); |
| 3629 | for (i = 1; i < fastboot_cmds_count; i++) |
| 3630 | fastboot_register(cmd_list[i].name,cmd_list[i].cb); |
| 3631 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3632 | /* publish variables and their values */ |
| 3633 | fastboot_publish("product", TARGET(BOARD)); |
| 3634 | fastboot_publish("kernel", "lk"); |
| 3635 | fastboot_publish("serialno", sn_buf); |
| 3636 | |
| 3637 | /* |
| 3638 | * partition info is supported only for emmc partitions |
| 3639 | * Calling this for NAND prints some error messages which |
| 3640 | * is harmless but misleading. Avoid calling this for NAND |
| 3641 | * devices. |
| 3642 | */ |
| 3643 | if (target_is_emmc_boot()) |
| 3644 | publish_getvar_partition_info(part_info, ARRAY_SIZE(part_info)); |
| 3645 | |
| 3646 | /* Max download size supported */ |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 3647 | snprintf(max_download_size, MAX_RSP_SIZE, "\t0x%x", |
| 3648 | target_get_max_flash_size()); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3649 | fastboot_publish("max-download-size", (const char *) max_download_size); |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 3650 | /* Is the charger screen check enabled */ |
| 3651 | snprintf(charger_screen_enabled, MAX_RSP_SIZE, "%d", |
| 3652 | device.charger_screen_enabled); |
| 3653 | fastboot_publish("charger-screen-enabled", |
| 3654 | (const char *) charger_screen_enabled); |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 3655 | fastboot_publish("off-mode-charge", (const char *) charger_screen_enabled); |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 3656 | snprintf(panel_display_mode, MAX_RSP_SIZE, "%s", |
| 3657 | device.display_panel); |
| 3658 | fastboot_publish("display-panel", |
| 3659 | (const char *) panel_display_mode); |
Channagoud Kadabi | aafbbfc | 2015-03-04 17:52:56 -0800 | [diff] [blame] | 3660 | fastboot_publish("version-bootloader", (const char *) device.bootloader_version); |
| 3661 | fastboot_publish("version-baseband", (const char *) device.radio_version); |
lijuang | f16461c | 2015-08-03 17:09:34 +0800 | [diff] [blame] | 3662 | fastboot_publish("secure", is_secure_boot_enable()? "yes":"no"); |
| 3663 | smem_get_hw_platform_name((unsigned char *) hw_platform_buf, sizeof(hw_platform_buf)); |
| 3664 | snprintf(get_variant, MAX_RSP_SIZE, "%s %s", hw_platform_buf, |
| 3665 | target_is_emmc_boot()? "eMMC":"UFS"); |
| 3666 | fastboot_publish("variant", (const char *) get_variant); |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 3667 | #if CHECK_BAT_VOLTAGE |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 3668 | update_battery_status(); |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 3669 | fastboot_publish("battery-voltage", (const char *) battery_voltage); |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 3670 | fastboot_publish("battery-soc-ok", (const char *) battery_soc_ok); |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 3671 | #endif |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3674 | void aboot_init(const struct app_descriptor *app) |
| 3675 | { |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 3676 | unsigned reboot_mode = 0; |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 3677 | |
lijuang | 3983173 | 2016-01-08 17:49:02 +0800 | [diff] [blame] | 3678 | /* Initialise wdog to catch early lk crashes */ |
| 3679 | #if WDOG_SUPPORT |
| 3680 | msm_wdog_init(); |
| 3681 | #endif |
| 3682 | |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 3683 | /* Setup page size information for nv storage */ |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3684 | if (target_is_emmc_boot()) |
| 3685 | { |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 3686 | page_size = mmc_page_size(); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3687 | page_mask = page_size - 1; |
Gaurav Nebhwani | 4d2389c | 2016-03-17 21:10:05 +0530 | [diff] [blame] | 3688 | mmc_blocksize = mmc_get_device_blocksize(); |
| 3689 | mmc_blocksize_mask = mmc_blocksize - 1; |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3690 | } |
| 3691 | else |
| 3692 | { |
| 3693 | page_size = flash_page_size(); |
| 3694 | page_mask = page_size - 1; |
| 3695 | } |
| 3696 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 3697 | ASSERT((MEMBASE + MEMSIZE) > MEMBASE); |
| 3698 | |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 3699 | read_device_info(&device); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 3700 | read_allow_oem_unlock(&device); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 3701 | |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 3702 | /* Display splash screen if enabled */ |
| 3703 | #if DISPLAY_SPLASH_SCREEN |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 3704 | #if NO_ALARM_DISPLAY |
| 3705 | if (!check_alarm_boot()) { |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 3706 | #endif |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 3707 | dprintf(SPEW, "Display Init: Start\n"); |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 3708 | #if ENABLE_WBC |
Channagoud Kadabi | d801ac7 | 2015-08-26 11:21:51 -0700 | [diff] [blame] | 3709 | /* Wait if the display shutdown is in progress */ |
| 3710 | while(pm_app_display_shutdown_in_prgs()); |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 3711 | if (!pm_appsbl_display_init_done()) |
| 3712 | target_display_init(device.display_panel); |
| 3713 | else |
| 3714 | display_image_on_screen(); |
| 3715 | #else |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 3716 | target_display_init(device.display_panel); |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 3717 | #endif |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 3718 | dprintf(SPEW, "Display Init: Done\n"); |
| 3719 | #if NO_ALARM_DISPLAY |
| 3720 | } |
| 3721 | #endif |
| 3722 | #endif |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 3723 | |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 3724 | target_serialno((unsigned char *) sn_buf); |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 3725 | dprintf(SPEW,"serial number: %s\n",sn_buf); |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 3726 | |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 3727 | memset(display_panel_buf, '\0', MAX_PANEL_BUF_SIZE); |
| 3728 | |
Matthew Qin | defd556 | 2014-07-11 18:02:40 +0800 | [diff] [blame] | 3729 | /* |
| 3730 | * Check power off reason if user force reset, |
| 3731 | * if yes phone will do normal boot. |
| 3732 | */ |
| 3733 | if (is_user_force_reset()) |
| 3734 | goto normal_boot; |
| 3735 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3736 | /* Check if we should do something other than booting up */ |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 3737 | if (keys_get_state(KEY_VOLUMEUP) && keys_get_state(KEY_VOLUMEDOWN)) |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 3738 | { |
Pavel Nedev | a4c9d3a | 2013-05-15 14:42:34 +0300 | [diff] [blame] | 3739 | dprintf(ALWAYS,"dload mode key sequence detected\n"); |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 3740 | reboot_device(EMERGENCY_DLOAD); |
| 3741 | dprintf(CRITICAL,"Failed to reboot into dload mode\n"); |
| 3742 | |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 3743 | boot_into_fastboot = true; |
| 3744 | } |
| 3745 | if (!boot_into_fastboot) |
| 3746 | { |
| 3747 | if (keys_get_state(KEY_HOME) || keys_get_state(KEY_VOLUMEUP)) |
| 3748 | boot_into_recovery = 1; |
| 3749 | if (!boot_into_recovery && |
| 3750 | (keys_get_state(KEY_BACK) || keys_get_state(KEY_VOLUMEDOWN))) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3751 | boot_into_fastboot = true; |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 3752 | } |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3753 | #if NO_KEYPAD_DRIVER |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 3754 | if (fastboot_trigger()) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3755 | boot_into_fastboot = true; |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3756 | #endif |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 3757 | |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3758 | #if USE_PON_REBOOT_REG |
| 3759 | reboot_mode = check_hard_reboot_mode(); |
| 3760 | #else |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 3761 | reboot_mode = check_reboot_mode(); |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3762 | #endif |
| 3763 | if (reboot_mode == RECOVERY_MODE) |
| 3764 | { |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 3765 | boot_into_recovery = 1; |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3766 | } |
| 3767 | else if(reboot_mode == FASTBOOT_MODE) |
| 3768 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3769 | boot_into_fastboot = true; |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3770 | } |
| 3771 | else if(reboot_mode == ALARM_BOOT) |
| 3772 | { |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 3773 | boot_reason_alarm = true; |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3774 | } |
Parth Dixit | 207573a | 2015-10-27 17:26:21 +0530 | [diff] [blame] | 3775 | #if VERIFIED_BOOT |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3776 | #if !VBOOT_MOTA |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3777 | else if (reboot_mode == DM_VERITY_ENFORCING) |
| 3778 | { |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 3779 | device.verity_mode = 1; |
| 3780 | write_device_info(&device); |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3781 | } |
| 3782 | else if (reboot_mode == DM_VERITY_LOGGING) |
| 3783 | { |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 3784 | device.verity_mode = 0; |
| 3785 | write_device_info(&device); |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 3786 | } |
| 3787 | else if (reboot_mode == DM_VERITY_KEYSCLEAR) |
| 3788 | { |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 3789 | if(send_delete_keys_to_tz()) |
| 3790 | ASSERT(0); |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 3791 | } |
Parth Dixit | 207573a | 2015-10-27 17:26:21 +0530 | [diff] [blame] | 3792 | #endif |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 3793 | #endif |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 3794 | |
Matthew Qin | defd556 | 2014-07-11 18:02:40 +0800 | [diff] [blame] | 3795 | normal_boot: |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3796 | if (!boot_into_fastboot) |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3797 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3798 | if (target_is_emmc_boot()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3799 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3800 | if(emmc_recovery_init()) |
| 3801 | dprintf(ALWAYS,"error in emmc_recovery_init\n"); |
| 3802 | if(target_use_signed_kernel()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3803 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3804 | if((device.is_unlocked) || (device.is_tampered)) |
| 3805 | { |
| 3806 | #ifdef TZ_TAMPER_FUSE |
| 3807 | set_tamper_fuse_cmd(); |
| 3808 | #endif |
| 3809 | #if USE_PCOM_SECBOOT |
| 3810 | set_tamper_flag(device.is_tampered); |
| 3811 | #endif |
| 3812 | } |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3813 | } |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 3814 | |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3815 | boot_linux_from_mmc(); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3816 | } |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3817 | else |
| 3818 | { |
| 3819 | recovery_init(); |
| 3820 | #if USE_PCOM_SECBOOT |
| 3821 | if((device.is_unlocked) || (device.is_tampered)) |
| 3822 | set_tamper_flag(device.is_tampered); |
| 3823 | #endif |
| 3824 | boot_linux_from_flash(); |
| 3825 | } |
| 3826 | dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting " |
| 3827 | "to fastboot mode.\n"); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3828 | } |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3829 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3830 | /* We are here means regular boot did not happen. Start fastboot. */ |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 3831 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3832 | /* register aboot specific fastboot commands */ |
| 3833 | aboot_fastboot_register_commands(); |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 3834 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3835 | /* dump partition table for debug info */ |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3836 | partition_dump(); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3837 | |
| 3838 | /* initialize and start fastboot */ |
| 3839 | fastboot_init(target_get_scratch_address(), target_get_max_flash_size()); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3840 | #if FBCON_DISPLAY_MSG |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 3841 | display_fastboot_menu(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 3842 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3843 | } |
| 3844 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 3845 | uint32_t get_page_size() |
| 3846 | { |
| 3847 | return page_size; |
| 3848 | } |
| 3849 | |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3850 | /* |
| 3851 | * Calculated and save hash (SHA256) for non-signed boot image. |
| 3852 | * |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3853 | * @param image_addr - Boot image address |
| 3854 | * @param image_size - Size of the boot image |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3855 | * |
| 3856 | * @return int - 0 on success, negative value on failure. |
| 3857 | */ |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3858 | static int aboot_save_boot_hash_mmc(uint32_t image_addr, uint32_t image_size) |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3859 | { |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3860 | unsigned int digest[8]; |
| 3861 | #if IMAGE_VERIF_ALGO_SHA1 |
| 3862 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA1; |
| 3863 | #else |
| 3864 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA256; |
| 3865 | #endif |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3866 | |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3867 | target_crypto_init_params(); |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 3868 | hash_find((unsigned char *) image_addr, image_size, (unsigned char *)&digest, auth_algo); |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3869 | |
| 3870 | save_kernel_hash_cmd(digest); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3871 | dprintf(INFO, "aboot_save_boot_hash_mmc: imagesize_actual size %d bytes.\n", (int) image_size); |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3872 | |
| 3873 | return 0; |
| 3874 | } |
| 3875 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3876 | APP_START(aboot) |
| 3877 | .init = aboot_init, |
| 3878 | APP_END |