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