Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Mayank Grover | 98c4c74 | 2019-04-25 17:21:37 +0530 | [diff] [blame] | 5 | * Copyright (c) 2009-2019, 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> |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 51 | #include <ab_partition_parser.h> |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 52 | #include <verifiedboot.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 53 | #include <platform.h> |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 54 | #include <crypto_hash.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 55 | #include <malloc.h> |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 56 | #include <boot_stats.h> |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 57 | #include <sha.h> |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 58 | #include <platform/iomap.h> |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 59 | #include <boot_device.h> |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 60 | #include <boot_verifier.h> |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 61 | #include <image_verify.h> |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 62 | #include <decompress.h> |
Unnati Gandhi | 17b3bfc | 2015-05-11 12:58:16 +0530 | [diff] [blame] | 63 | #include <platform/timer.h> |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 64 | #include <sys/types.h> |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 65 | #if USE_RPMB_FOR_DEVINFO |
| 66 | #include <rpmb.h> |
| 67 | #endif |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 68 | |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 69 | #if ENABLE_WBC |
| 70 | #include <pm_app_smbchg.h> |
| 71 | #endif |
| 72 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 73 | #if DEVICE_TREE |
| 74 | #include <libfdt.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 75 | #include <dev_tree.h> |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 76 | #endif |
| 77 | |
Aparna Mallavarapu | 118ccae | 2015-06-03 13:47:11 +0530 | [diff] [blame] | 78 | #if WDOG_SUPPORT |
| 79 | #include <wdog.h> |
| 80 | #endif |
| 81 | |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 82 | #include <reboot.h> |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 83 | #include "image_verify.h" |
Shashank Mittal | 024c033 | 2010-02-03 11:44:00 -0800 | [diff] [blame] | 84 | #include "recovery.h" |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 85 | #include "bootimg.h" |
| 86 | #include "fastboot.h" |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 87 | #include "sparse_format.h" |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 88 | #include "meta_format.h" |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 89 | #include "mmc.h" |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 90 | #include "devinfo.h" |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 91 | #include "board.h" |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 92 | #include "scm.h" |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 93 | #include "mdtp.h" |
Sridhar Parasuram | 32b3066 | 2015-07-10 13:33:22 -0700 | [diff] [blame] | 94 | #include "secapp_loader.h" |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 95 | #include <menu_keys_detect.h> |
| 96 | #include <display_menu.h> |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 97 | #include "fastboot_test.h" |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 98 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 99 | extern bool target_use_signed_kernel(void); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 100 | extern void platform_uninit(void); |
Channagoud Kadabi | 33defe2 | 2013-06-18 18:35:40 -0700 | [diff] [blame] | 101 | extern void target_uninit(void); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 102 | extern int get_target_boot_params(const char *cmdline, const char *part, |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 103 | char **buf); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 104 | |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 105 | void *info_buf; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 106 | void write_device_info_mmc(device_info *dev); |
| 107 | void write_device_info_flash(device_info *dev); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 108 | 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] | 109 | static int aboot_frp_unlock(char *pname, void *data, unsigned sz); |
Kishor PK | 38ed93d | 2017-04-25 14:19:26 +0530 | [diff] [blame] | 110 | static inline uint64_t validate_partition_size(); |
Parth Dixit | 54ac3bb | 2017-03-07 15:52:48 +0530 | [diff] [blame] | 111 | bool pwr_key_is_pressed = false; |
Hareesh Gautham | abf1e1e | 2017-04-12 18:09:24 +0530 | [diff] [blame] | 112 | static bool is_systemd_present=false; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 113 | static void publish_getvar_multislot_vars(); |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 114 | /* fastboot command function pointer */ |
| 115 | typedef void (*fastboot_cmd_fn) (const char *, void *, unsigned); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 116 | bool get_perm_attr_status(); |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 117 | |
| 118 | struct fastboot_cmd_desc { |
| 119 | char * name; |
| 120 | fastboot_cmd_fn cb; |
| 121 | }; |
| 122 | |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 123 | #define EXPAND(NAME) #NAME |
| 124 | #define TARGET(NAME) EXPAND(NAME) |
Brian Swetland | 2defe16 | 2009-08-18 14:35:59 -0700 | [diff] [blame] | 125 | |
Ajay Singh Parmar | a7865a8 | 2015-04-16 21:27:52 -0700 | [diff] [blame] | 126 | #define DISPLAY_PANEL_HDMI "hdmi" |
| 127 | |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 128 | #ifdef MEMBASE |
| 129 | #define EMMC_BOOT_IMG_HEADER_ADDR (0xFF000+(MEMBASE)) |
| 130 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 131 | #define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000 |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 132 | #endif |
| 133 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 134 | #ifndef MEMSIZE |
| 135 | #define MEMSIZE 1024*1024 |
| 136 | #endif |
| 137 | |
| 138 | #define MAX_TAGS_SIZE 1024 |
Kishor PK | ee5c0a3 | 2018-03-06 16:49:46 +0530 | [diff] [blame] | 139 | #define PLL_CODES_OFFSET 4096 |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 140 | /* make 4096 as default size to ensure EFS,EXT4's erasing */ |
| 141 | #define DEFAULT_ERASE_SIZE 4096 |
Ujwal Patel | c0b0a25 | 2015-08-16 14:05:35 -0700 | [diff] [blame] | 142 | #define MAX_PANEL_BUF_SIZE 196 |
Vijay Kumar Pendoti | 0b21f46 | 2016-05-02 17:09:18 +0530 | [diff] [blame] | 143 | #define FOOTER_SIZE 16384 |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 144 | |
Dhaval Patel | f83d73b | 2014-06-23 16:24:37 -0700 | [diff] [blame] | 145 | #define DISPLAY_DEFAULT_PREFIX "mdss_mdp" |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 146 | #define BOOT_DEV_MAX_LEN 64 |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 147 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 148 | #define IS_ARM64(ptr) (ptr->magic_64 == KERNEL64_HDR_MAGIC) ? true : false |
| 149 | |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 150 | #define ADD_OF(a, b) (UINT_MAX - b > a) ? (a + b) : UINT_MAX |
| 151 | |
Ameya Thakur | 10a3345 | 2016-06-13 14:24:26 -0700 | [diff] [blame] | 152 | //Size of the header that is used in case the boot image has |
| 153 | //a uncompressed kernel + appended dtb |
| 154 | #define PATCHED_KERNEL_HEADER_SIZE 20 |
| 155 | |
| 156 | //String used to determine if the boot image has |
| 157 | //a uncompressed kernel + appended dtb |
| 158 | #define PATCHED_KERNEL_MAGIC "UNCOMPRESSED_IMG" |
| 159 | |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 160 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 161 | static const char *emmc_cmdline = " androidboot.bootdevice="; |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 162 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 163 | static const char *emmc_cmdline = " androidboot.emmc=true"; |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 164 | #endif |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 165 | static const char *usb_sn_cmdline = " androidboot.serialno="; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 166 | static const char *androidboot_mode = " androidboot.mode="; |
Hareesh Gautham | abf1e1e | 2017-04-12 18:09:24 +0530 | [diff] [blame] | 167 | |
| 168 | static const char *systemd_ffbm_mode = " systemd.unit=ffbm.target"; |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 169 | static const char *alarmboot_cmdline = " androidboot.alarmboot=true"; |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 170 | static const char *loglevel = " quiet"; |
Ajay Dudani | ca3a33c | 2011-11-18 08:31:40 -0800 | [diff] [blame] | 171 | static const char *battchg_pause = " androidboot.mode=charger"; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 172 | static const char *auth_kernel = " androidboot.authorized_kernel=true"; |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 173 | static const char *secondary_gpt_enable = " gpt"; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 174 | #ifdef MDTP_SUPPORT |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 175 | static const char *mdtp_activated_flag = " mdtp"; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 176 | #endif |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 177 | static const char *baseband_apq = " androidboot.baseband=apq"; |
| 178 | static const char *baseband_msm = " androidboot.baseband=msm"; |
| 179 | static const char *baseband_csfb = " androidboot.baseband=csfb"; |
| 180 | static const char *baseband_svlte2a = " androidboot.baseband=svlte2a"; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 181 | static const char *baseband_mdm = " androidboot.baseband=mdm"; |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 182 | static const char *baseband_mdm2 = " androidboot.baseband=mdm2"; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 183 | static const char *baseband_sglte = " androidboot.baseband=sglte"; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 184 | static const char *baseband_dsda = " androidboot.baseband=dsda"; |
| 185 | static const char *baseband_dsda2 = " androidboot.baseband=dsda2"; |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 186 | static const char *baseband_sglte2 = " androidboot.baseband=sglte2"; |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 187 | static const char *warmboot_cmdline = " qpnp-power-on.warm_boot=1"; |
Vijay Kumar Pendoti | b228cfc | 2016-06-13 20:15:23 +0530 | [diff] [blame] | 188 | static const char *baseband_apq_nowgr = " androidboot.baseband=baseband_apq_nowgr"; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 189 | static const char *androidboot_slot_suffix = " androidboot.slot_suffix="; |
| 190 | static const char *skip_ramfs = " skip_initramfs"; |
Mayank Grover | 466d656 | 2018-05-10 14:52:20 +0530 | [diff] [blame] | 191 | |
| 192 | #if HIBERNATION_SUPPORT |
| 193 | static const char *resume = " resume=/dev/mmcblk0p"; |
| 194 | #endif |
| 195 | |
Sourabh Banerjee | 6c7153c | 2018-03-20 01:21:57 +0530 | [diff] [blame] | 196 | #ifdef INIT_BIN_LE |
| 197 | static const char *sys_path_cmdline = " rootwait ro init="INIT_BIN_LE; |
| 198 | #else |
Mayank Grover | 3804be7 | 2017-06-22 11:59:23 +0530 | [diff] [blame] | 199 | static const char *sys_path_cmdline = " rootwait ro init=/init"; |
Sourabh Banerjee | 6c7153c | 2018-03-20 01:21:57 +0530 | [diff] [blame] | 200 | #endif |
Sourabh Banerjee | 386b132 | 2018-02-27 09:37:28 +0530 | [diff] [blame] | 201 | |
| 202 | #if VERITY_LE |
| 203 | static const char *verity_dev = " root=/dev/dm-0"; |
| 204 | static const char *verity_system_part = " dm=\"system"; |
| 205 | static const char *verity_params = " none ro,0 1 android-verity /dev/mmcblk0p"; |
| 206 | #else |
Mayank Grover | 5384ed8 | 2018-05-09 12:09:24 +0530 | [diff] [blame] | 207 | static const char *sys_path = " root=/dev/mmcblk0p"; |
lijuang | 83ef4b2 | 2018-08-23 11:01:55 +0800 | [diff] [blame] | 208 | |
| 209 | #define MAX_DTBO_IDX_STR 64 |
| 210 | static const char *android_boot_dtbo_idx = " androidboot.dtbo_idx="; |
Sourabh Banerjee | 386b132 | 2018-02-27 09:37:28 +0530 | [diff] [blame] | 211 | #endif |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 212 | |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 213 | #if VERIFIED_BOOT |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 214 | static const char *verity_mode = " androidboot.veritymode="; |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 215 | static const char *verified_state= " androidboot.verifiedbootstate="; |
Parth Dixit | a5715a0 | 2015-10-29 12:25:10 +0530 | [diff] [blame] | 216 | static const char *keymaster_v1= " androidboot.keymaster=1"; |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 217 | //indexed based on enum values, green is 0 by default |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 218 | |
| 219 | struct verified_boot_verity_mode vbvm[] = |
| 220 | { |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 221 | #if ENABLE_VB_ATTEST |
| 222 | {false, "eio"}, |
| 223 | #else |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 224 | {false, "logging"}, |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 225 | #endif |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 226 | {true, "enforcing"}, |
| 227 | }; |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 228 | struct verified_boot_state_name vbsn[] = |
| 229 | { |
| 230 | {GREEN, "green"}, |
| 231 | {ORANGE, "orange"}, |
| 232 | {YELLOW,"yellow"}, |
| 233 | {RED,"red" }, |
| 234 | }; |
| 235 | #endif |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 236 | /*As per spec delay wait time before shutdown in Red state*/ |
| 237 | #define DELAY_WAIT 30000 |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 238 | static unsigned page_size = 0; |
| 239 | static unsigned page_mask = 0; |
Gaurav Nebhwani | 4d2389c | 2016-03-17 21:10:05 +0530 | [diff] [blame] | 240 | static unsigned mmc_blocksize = 0; |
| 241 | static unsigned mmc_blocksize_mask = 0; |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 242 | static char ffbm_mode_string[FFBM_MODE_BUF_SIZE]; |
| 243 | static bool boot_into_ffbm; |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 244 | static char *target_boot_params = NULL; |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 245 | static bool boot_reason_alarm; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 246 | static bool devinfo_present = true; |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 247 | bool boot_into_fastboot = false; |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 248 | static uint32_t dt_size = 0; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 249 | static char *vbcmdline; |
| 250 | static bootinfo info = {0}; |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 251 | static void *recovery_dtbo_buf = NULL; |
| 252 | static uint32_t recovery_dtbo_size = 0; |
| 253 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 254 | /* Assuming unauthorized kernel image by default */ |
| 255 | static int auth_kernel_img = 0; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 256 | static device_info device = {DEVICE_MAGIC,0,0,0,0,{0},{0},{0},1,{0},0,{0}}; |
| 257 | |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 258 | static bool is_allow_unlock = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 259 | |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 260 | static char frp_ptns[2][8] = {"config","frp"}; |
| 261 | |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 262 | static const char *critical_flash_allowed_ptn[] = { |
| 263 | "aboot", |
| 264 | "rpm", |
| 265 | "tz", |
| 266 | "sbl", |
| 267 | "sdi", |
| 268 | "sbl1", |
| 269 | "xbl", |
| 270 | "hyp", |
| 271 | "pmic", |
| 272 | "bootloader", |
| 273 | "devinfo", |
| 274 | "partition"}; |
| 275 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 276 | struct atag_ptbl_entry |
| 277 | { |
| 278 | char name[16]; |
| 279 | unsigned offset; |
| 280 | unsigned size; |
| 281 | unsigned flags; |
| 282 | }; |
| 283 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 284 | /* |
| 285 | * Partition info, required to be published |
| 286 | * for fastboot |
| 287 | */ |
| 288 | struct getvar_partition_info { |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 289 | char part_name[MAX_GPT_NAME_SIZE]; /* Partition name */ |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 290 | char getvar_size[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for size */ |
| 291 | char getvar_type[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for type */ |
| 292 | char size_response[MAX_RSP_SIZE]; /* fastboot response for size */ |
| 293 | char type_response[MAX_RSP_SIZE]; /* fastboot response for type */ |
| 294 | }; |
| 295 | |
| 296 | /* |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 297 | * Update the part_type_known for known paritions types. |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 298 | */ |
Mayank Grover | d38fe01 | 2018-03-13 15:33:16 +0530 | [diff] [blame] | 299 | #define RAW_STR "raw" |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 300 | #define EXT_STR "ext4" |
| 301 | #define F2FS_STR "f2fs" |
| 302 | |
| 303 | #define FS_SUPERBLOCK_OFFSET 0x400 |
| 304 | #define EXT_MAGIC 0xEF53 |
| 305 | #define EXT_MAGIC_OFFSET_SB 0x38 |
| 306 | #define F2FS_MAGIC 0xF2F52010 // F2FS Magic Number |
| 307 | #define F2FS_MAGIC_OFFSET_SB 0x0 |
| 308 | |
| 309 | typedef enum fs_signature_type { |
| 310 | EXT_FS_SIGNATURE = 1, |
| 311 | EXT_F2FS_SIGNATURE = 2, |
| 312 | NO_FS = -1 |
| 313 | } fs_signature_type; |
| 314 | |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 315 | struct getvar_partition_info part_info[NUM_PARTITIONS]; |
| 316 | struct getvar_partition_info part_type_known[] = |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 317 | { |
Mayank Grover | 4992021 | 2018-02-09 18:15:55 +0530 | [diff] [blame] | 318 | { "system" , "partition-size:", "partition-type:", "", "ext4" }, |
| 319 | { "userdata" , "partition-size:", "partition-type:", "", "ext4" }, |
| 320 | { "cache" , "partition-size:", "partition-type:", "", "ext4" }, |
| 321 | { "recoveryfs" , "partition-size:", "partition-type:", "", "ext4" }, |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 322 | }; |
| 323 | |
| 324 | char max_download_size[MAX_RSP_SIZE]; |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 325 | char charger_screen_enabled[MAX_RSP_SIZE]; |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 326 | char sn_buf[13]; |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 327 | char display_panel_buf[MAX_PANEL_BUF_SIZE]; |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 328 | char panel_display_mode[MAX_RSP_SIZE]; |
Mayank Grover | a64dfbe | 2018-05-17 14:06:34 +0530 | [diff] [blame] | 329 | char soc_version_str[MAX_RSP_SIZE]; |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 330 | char block_size_string[MAX_RSP_SIZE]; |
Mukesh Ojha | bb6e7f3 | 2018-03-02 15:04:06 +0530 | [diff] [blame] | 331 | #if PRODUCT_IOT |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 332 | |
| 333 | /* For IOT we are using custom version */ |
| 334 | #define PRODUCT_IOT_VERSION "IOT001" |
| 335 | char bootloader_version_string[MAX_RSP_SIZE]; |
| 336 | #endif |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 337 | |
| 338 | #if CHECK_BAT_VOLTAGE |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 339 | char battery_voltage[MAX_RSP_SIZE]; |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 340 | char battery_soc_ok [MAX_RSP_SIZE]; |
| 341 | #endif |
| 342 | |
lijuang | f16461c | 2015-08-03 17:09:34 +0800 | [diff] [blame] | 343 | char get_variant[MAX_RSP_SIZE]; |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 344 | |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 345 | extern int emmc_recovery_init(void); |
| 346 | |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 347 | #if NO_KEYPAD_DRIVER |
| 348 | extern int fastboot_trigger(void); |
| 349 | #endif |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 350 | |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 351 | static void update_ker_tags_rdisk_addr(boot_img_hdr *hdr, bool is_arm64) |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 352 | { |
| 353 | /* overwrite the destination of specified for the project */ |
Channagoud Kadabi | 7042fa3 | 2013-04-26 16:44:14 -0700 | [diff] [blame] | 354 | #ifdef ABOOT_IGNORE_BOOT_HEADER_ADDRS |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 355 | if (is_arm64) |
| 356 | hdr->kernel_addr = ABOOT_FORCE_KERNEL64_ADDR; |
| 357 | else |
| 358 | hdr->kernel_addr = ABOOT_FORCE_KERNEL_ADDR; |
Channagoud Kadabi | 7042fa3 | 2013-04-26 16:44:14 -0700 | [diff] [blame] | 359 | hdr->ramdisk_addr = ABOOT_FORCE_RAMDISK_ADDR; |
| 360 | hdr->tags_addr = ABOOT_FORCE_TAGS_ADDR; |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 361 | #endif |
| 362 | } |
| 363 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 364 | static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn) |
| 365 | { |
| 366 | struct atag_ptbl_entry atag_ptn; |
| 367 | |
| 368 | memcpy(atag_ptn.name, ptn->name, 16); |
| 369 | atag_ptn.name[15] = '\0'; |
| 370 | atag_ptn.offset = ptn->start; |
| 371 | atag_ptn.size = ptn->length; |
| 372 | atag_ptn.flags = ptn->flags; |
| 373 | memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry)); |
| 374 | *ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned); |
| 375 | } |
Mayank Grover | 9df84c0 | 2018-08-30 15:46:35 +0530 | [diff] [blame] | 376 | #ifdef VERIFIED_BOOT_2 |
| 377 | void load_vbmeta_image(void **vbmeta_image_buf, uint32_t *vbmeta_image_sz) |
| 378 | { |
| 379 | int index = 0; |
| 380 | char *vbm_img_buf = NULL; |
| 381 | unsigned long long ptn = 0; |
| 382 | unsigned long long ptn_size = 0; |
| 383 | |
| 384 | /* Immediately return if dtbo is not supported */ |
| 385 | index = partition_get_index("vbmeta"); |
| 386 | ptn = partition_get_offset(index); |
| 387 | if(!ptn) |
| 388 | { |
| 389 | dprintf(CRITICAL, "ERROR: vbmeta partition not found.\n"); |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | ptn_size = partition_get_size(index); |
| 394 | if (ptn_size > MAX_SUPPORTED_VBMETA_IMG_BUF) |
| 395 | { |
| 396 | dprintf(CRITICAL, "ERROR: vbmeta parition size is greater than supported.\n"); |
| 397 | return; |
| 398 | } |
| 399 | |
| 400 | vbm_img_buf = (char *)memalign(CACHE_LINE, ROUNDUP((uint32_t)ptn_size, CACHE_LINE)); |
| 401 | if (!vbm_img_buf) |
| 402 | { |
| 403 | dprintf(CRITICAL, "ERROR: vbmeta unable to locate buffer\n"); |
| 404 | return; |
| 405 | } |
| 406 | |
| 407 | mmc_set_lun(partition_get_lun(index)); |
| 408 | if (mmc_read(ptn, (uint32_t *)vbm_img_buf, (uint32_t)ptn_size)) |
| 409 | { |
| 410 | dprintf(CRITICAL, "ERROR: vbmeta read failure\n"); |
| 411 | free(vbm_img_buf); |
| 412 | return; |
| 413 | } |
| 414 | |
| 415 | *vbmeta_image_buf = vbm_img_buf; |
| 416 | *vbmeta_image_sz = (uint32_t)ptn_size; |
| 417 | return; |
| 418 | } |
| 419 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 420 | |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 421 | #if CHECK_BAT_VOLTAGE |
| 422 | void update_battery_status(void) |
| 423 | { |
| 424 | snprintf(battery_voltage,MAX_RSP_SIZE, "%d",target_get_battery_voltage()); |
| 425 | snprintf(battery_soc_ok ,MAX_RSP_SIZE, "%s",target_battery_soc_ok()? "yes":"no"); |
| 426 | } |
| 427 | #endif |
| 428 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 429 | unsigned char *update_cmdline(const char * cmdline) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 430 | { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 431 | int cmdline_len = 0; |
| 432 | int have_cmdline = 0; |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 433 | unsigned char *cmdline_final = NULL; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 434 | int pause_at_bootup = 0; |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 435 | bool warm_boot = false; |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 436 | bool gpt_exists = partition_gpt_exists(); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 437 | int have_target_boot_params = 0; |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 438 | char *boot_dev_buf = NULL; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 439 | #ifdef MDTP_SUPPORT |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 440 | bool is_mdtp_activated = 0; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 441 | #endif |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 442 | int current_active_slot = INVALID; |
Mayank Grover | 3804be7 | 2017-06-22 11:59:23 +0530 | [diff] [blame] | 443 | int system_ptn_index = -1; |
| 444 | unsigned int lun = 0; |
| 445 | char lun_char_base = 'a'; |
Sourabh Banerjee | 386b132 | 2018-02-27 09:37:28 +0530 | [diff] [blame] | 446 | #if VERITY_LE |
| 447 | int syspath_buflen = strlen(verity_dev) |
| 448 | + strlen(verity_system_part) + (sizeof(char) * 2) + 2 |
| 449 | + strlen(verity_params) + sizeof(int) + 2; |
| 450 | #else |
lijuang | 83ef4b2 | 2018-08-23 11:01:55 +0800 | [diff] [blame] | 451 | int syspath_buflen = strlen(sys_path) + sizeof(int) + 2; /*allocate buflen for largest possible string*/ |
| 452 | char dtbo_idx_str[MAX_DTBO_IDX_STR] = "\0"; |
| 453 | int dtbo_idx = INVALID_PTN; |
Sourabh Banerjee | 386b132 | 2018-02-27 09:37:28 +0530 | [diff] [blame] | 454 | #endif |
Mayank Grover | 3804be7 | 2017-06-22 11:59:23 +0530 | [diff] [blame] | 455 | char syspath_buf[syspath_buflen]; |
Mayank Grover | 466d656 | 2018-05-10 14:52:20 +0530 | [diff] [blame] | 456 | #if HIBERNATION_SUPPORT |
| 457 | int resume_buflen = strlen(resume) + sizeof(int) + 2; |
| 458 | char resume_buf[resume_buflen]; |
| 459 | int swap_ptn_index = INVALID_PTN; |
| 460 | #endif |
| 461 | |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 462 | #if VERIFIED_BOOT |
| 463 | uint32_t boot_state = RED; |
| 464 | #endif |
Hareesh Gautham | abf1e1e | 2017-04-12 18:09:24 +0530 | [diff] [blame] | 465 | |
| 466 | #if USE_LE_SYSTEMD |
| 467 | is_systemd_present=true; |
| 468 | #endif |
| 469 | |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 470 | #if VERIFIED_BOOT |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 471 | if (VB_M <= target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 472 | { |
| 473 | boot_state = boot_verify_get_state(); |
| 474 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 475 | #endif |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 476 | |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 477 | #ifdef MDTP_SUPPORT |
| 478 | mdtp_activated(&is_mdtp_activated); |
| 479 | #endif /* MDTP_SUPPORT */ |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 480 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 481 | if (cmdline && cmdline[0]) { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 482 | cmdline_len = strlen(cmdline); |
| 483 | have_cmdline = 1; |
| 484 | } |
| 485 | if (target_is_emmc_boot()) { |
| 486 | cmdline_len += strlen(emmc_cmdline); |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 487 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 488 | boot_dev_buf = (char *) malloc(sizeof(char) * BOOT_DEV_MAX_LEN); |
| 489 | ASSERT(boot_dev_buf); |
| 490 | platform_boot_dev_cmdline(boot_dev_buf); |
| 491 | cmdline_len += strlen(boot_dev_buf); |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 492 | #endif |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 493 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 494 | |
| 495 | cmdline_len += strlen(usb_sn_cmdline); |
| 496 | cmdline_len += strlen(sn_buf); |
| 497 | |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 498 | #if VERIFIED_BOOT |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 499 | if (VB_M <= target_get_vb_version()) |
Sridhar Parasuram | 7d8bb9a | 2015-09-23 18:21:19 -0700 | [diff] [blame] | 500 | { |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 501 | cmdline_len += strlen(verified_state) + strlen(vbsn[boot_state].name); |
| 502 | if ((device.verity_mode != 0 ) && (device.verity_mode != 1)) |
| 503 | { |
| 504 | dprintf(CRITICAL, "Devinfo paritition possibly corrupted!!!. Please erase devinfo partition to continue booting\n"); |
| 505 | ASSERT(0); |
| 506 | } |
| 507 | cmdline_len += strlen(verity_mode) + strlen(vbvm[device.verity_mode].name); |
| 508 | cmdline_len += strlen(keymaster_v1); |
Sridhar Parasuram | 7d8bb9a | 2015-09-23 18:21:19 -0700 | [diff] [blame] | 509 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 510 | #endif |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 511 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 512 | |
| 513 | if (vbcmdline != NULL) { |
| 514 | dprintf(DEBUG, "UpdateCmdLine vbcmdline present len %d\n", |
| 515 | strlen(vbcmdline)); |
| 516 | cmdline_len += strlen(vbcmdline); |
| 517 | } |
| 518 | |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 519 | if (boot_into_recovery && gpt_exists) |
| 520 | cmdline_len += strlen(secondary_gpt_enable); |
| 521 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 522 | #ifdef MDTP_SUPPORT |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 523 | if(is_mdtp_activated) |
| 524 | cmdline_len += strlen(mdtp_activated_flag); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 525 | #endif |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 526 | if (boot_into_ffbm) { |
| 527 | cmdline_len += strlen(androidboot_mode); |
Hareesh Gautham | abf1e1e | 2017-04-12 18:09:24 +0530 | [diff] [blame] | 528 | |
| 529 | if(is_systemd_present) |
| 530 | cmdline_len += strlen(systemd_ffbm_mode); |
| 531 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 532 | cmdline_len += strlen(ffbm_mode_string); |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 533 | /* reduce kernel console messages to speed-up boot */ |
| 534 | cmdline_len += strlen(loglevel); |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 535 | } else if (boot_reason_alarm) { |
| 536 | cmdline_len += strlen(alarmboot_cmdline); |
Zhenhua Huang | 431dafa | 2015-06-30 16:13:37 +0800 | [diff] [blame] | 537 | } else if ((target_build_variant_user() || device.charger_screen_enabled) |
lijuang | 266b17d | 2018-08-17 18:53:42 +0800 | [diff] [blame] | 538 | && target_pause_for_battery_charge() && !boot_into_recovery) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 539 | pause_at_bootup = 1; |
| 540 | cmdline_len += strlen(battchg_pause); |
| 541 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 542 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 543 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 544 | cmdline_len += strlen(auth_kernel); |
| 545 | } |
| 546 | |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 547 | if (get_target_boot_params(cmdline, boot_into_recovery ? "recoveryfs" : |
| 548 | "system", |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 549 | &target_boot_params) == 0) { |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 550 | have_target_boot_params = 1; |
| 551 | cmdline_len += strlen(target_boot_params); |
| 552 | } |
| 553 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 554 | /* Determine correct androidboot.baseband to use */ |
| 555 | switch(target_baseband()) |
| 556 | { |
| 557 | case BASEBAND_APQ: |
| 558 | cmdline_len += strlen(baseband_apq); |
| 559 | break; |
| 560 | |
| 561 | case BASEBAND_MSM: |
| 562 | cmdline_len += strlen(baseband_msm); |
| 563 | break; |
| 564 | |
| 565 | case BASEBAND_CSFB: |
| 566 | cmdline_len += strlen(baseband_csfb); |
| 567 | break; |
| 568 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 569 | case BASEBAND_SVLTE2A: |
| 570 | cmdline_len += strlen(baseband_svlte2a); |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 571 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 572 | |
| 573 | case BASEBAND_MDM: |
| 574 | cmdline_len += strlen(baseband_mdm); |
| 575 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 576 | |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 577 | case BASEBAND_MDM2: |
| 578 | cmdline_len += strlen(baseband_mdm2); |
| 579 | break; |
| 580 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 581 | case BASEBAND_SGLTE: |
| 582 | cmdline_len += strlen(baseband_sglte); |
| 583 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 584 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 585 | case BASEBAND_SGLTE2: |
| 586 | cmdline_len += strlen(baseband_sglte2); |
| 587 | break; |
| 588 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 589 | case BASEBAND_DSDA: |
| 590 | cmdline_len += strlen(baseband_dsda); |
| 591 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 592 | |
| 593 | case BASEBAND_DSDA2: |
| 594 | cmdline_len += strlen(baseband_dsda2); |
| 595 | break; |
Vijay Kumar Pendoti | b228cfc | 2016-06-13 20:15:23 +0530 | [diff] [blame] | 596 | case BASEBAND_APQ_NOWGR: |
| 597 | cmdline_len += strlen(baseband_apq_nowgr); |
| 598 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 599 | } |
| 600 | |
Vladislav Levenetz | 3cd4524 | 2017-04-05 08:58:07 +0300 | [diff] [blame] | 601 | #if ENABLE_DISPLAY |
Lijuan Gao | 4a5b832 | 2014-07-24 10:38:42 +0800 | [diff] [blame] | 602 | if (cmdline) { |
| 603 | if ((strstr(cmdline, DISPLAY_DEFAULT_PREFIX) == NULL) && |
Padmanabhan Komanduru | bccbcdc | 2015-06-30 16:19:24 +0530 | [diff] [blame] | 604 | target_display_panel_node(display_panel_buf, |
| 605 | MAX_PANEL_BUF_SIZE) && |
Lijuan Gao | 4a5b832 | 2014-07-24 10:38:42 +0800 | [diff] [blame] | 606 | strlen(display_panel_buf)) { |
| 607 | cmdline_len += strlen(display_panel_buf); |
| 608 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 609 | } |
Vladislav Levenetz | 3cd4524 | 2017-04-05 08:58:07 +0300 | [diff] [blame] | 610 | #endif |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 611 | |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 612 | if (target_warm_boot()) { |
| 613 | warm_boot = true; |
| 614 | cmdline_len += strlen(warmboot_cmdline); |
| 615 | } |
| 616 | |
Mayank Grover | 5384ed8 | 2018-05-09 12:09:24 +0530 | [diff] [blame] | 617 | if (target_uses_system_as_root() || |
| 618 | partition_multislot_is_supported()) |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 619 | { |
| 620 | current_active_slot = partition_find_active_slot(); |
| 621 | cmdline_len += (strlen(androidboot_slot_suffix)+ |
| 622 | strlen(SUFFIX_SLOT(current_active_slot))); |
| 623 | |
Mayank Grover | 3804be7 | 2017-06-22 11:59:23 +0530 | [diff] [blame] | 624 | system_ptn_index = partition_get_index("system"); |
| 625 | if (platform_boot_dev_isemmc()) |
| 626 | { |
Sourabh Banerjee | 386b132 | 2018-02-27 09:37:28 +0530 | [diff] [blame] | 627 | #if VERITY_LE |
| 628 | /* |
| 629 | Condition 4: Verity and A/B both enabled |
| 630 | Eventual command line looks like: |
| 631 | ... androidboot.slot_suffix=<slot_suffix> ... rootfstype=ext4 ... |
| 632 | ... root=/dev/dm-0 dm="system_<slot_suffix> none ro,0 1 android-verity /dev/mmcblk0p<NN>" |
| 633 | */ |
| 634 | snprintf(syspath_buf, syspath_buflen, " %s %s%s %s%d\"", |
| 635 | verity_dev, |
| 636 | verity_system_part, suffix_slot[current_active_slot], |
| 637 | verity_params, system_ptn_index + 1); |
| 638 | #else |
| 639 | /* |
| 640 | Condition 5: A/B enabled, but verity disabled |
| 641 | Eventual command line looks like: |
| 642 | ... androidboot.slot_suffix=<slot_suffix> ... rootfstype=ext4 ... |
| 643 | ... root=/dev/mmcblk0p<NN> ... |
| 644 | */ |
| 645 | snprintf(syspath_buf, syspath_buflen, " %s%d", |
| 646 | sys_path, system_ptn_index + 1); |
| 647 | #endif |
Mayank Grover | 3804be7 | 2017-06-22 11:59:23 +0530 | [diff] [blame] | 648 | } |
| 649 | else |
| 650 | { |
| 651 | lun = partition_get_lun(system_ptn_index); |
| 652 | snprintf(syspath_buf, syspath_buflen, " root=/dev/sd%c%d", |
| 653 | lun_char_base + lun, |
| 654 | partition_get_index_in_lun("system", lun)); |
| 655 | } |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 656 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 657 | #ifndef VERIFIED_BOOT_2 |
Mayank Grover | 3804be7 | 2017-06-22 11:59:23 +0530 | [diff] [blame] | 658 | cmdline_len += strlen(syspath_buf); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 659 | #endif |
Mayank Grover | 5384ed8 | 2018-05-09 12:09:24 +0530 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | if (target_uses_system_as_root() || |
| 663 | partition_multislot_is_supported()) |
| 664 | { |
| 665 | cmdline_len += strlen(sys_path_cmdline); |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 666 | if (!boot_into_recovery) |
| 667 | cmdline_len += strlen(skip_ramfs); |
| 668 | } |
| 669 | |
Mayank Grover | 466d656 | 2018-05-10 14:52:20 +0530 | [diff] [blame] | 670 | #if HIBERNATION_SUPPORT |
| 671 | if (platform_boot_dev_isemmc()) |
| 672 | { |
| 673 | swap_ptn_index = partition_get_index("swap"); |
| 674 | if (swap_ptn_index != INVALID_PTN) |
| 675 | { |
| 676 | snprintf(resume_buf, resume_buflen, |
| 677 | " %s%d", resume, |
| 678 | (swap_ptn_index + 1)); |
| 679 | cmdline_len += strlen(resume_buf); |
| 680 | } |
| 681 | else |
| 682 | { |
| 683 | dprintf(INFO, "WARNING: swap partition not found\n"); |
| 684 | } |
| 685 | } |
| 686 | #endif |
| 687 | |
Channagoud Kadabi | 85c7ec3 | 2016-01-28 23:09:21 -0800 | [diff] [blame] | 688 | #if TARGET_CMDLINE_SUPPORT |
| 689 | char *target_cmdline_buf = malloc(TARGET_MAX_CMDLNBUF); |
| 690 | int target_cmd_line_len; |
| 691 | ASSERT(target_cmdline_buf); |
| 692 | target_cmd_line_len = target_update_cmdline(target_cmdline_buf); |
| 693 | cmdline_len += target_cmd_line_len; |
| 694 | #endif |
| 695 | |
lijuang | 83ef4b2 | 2018-08-23 11:01:55 +0800 | [diff] [blame] | 696 | #if !VERITY_LE |
| 697 | dtbo_idx = get_dtbo_idx (); |
| 698 | if (dtbo_idx != INVALID_PTN) { |
| 699 | snprintf(dtbo_idx_str, sizeof(dtbo_idx_str), "%s%d", |
| 700 | android_boot_dtbo_idx, dtbo_idx); |
| 701 | cmdline_len += strlen (dtbo_idx_str); |
| 702 | } |
| 703 | #endif |
| 704 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 705 | if (cmdline_len > 0) { |
| 706 | const char *src; |
Maria Yu | 52254c0 | 2014-07-04 16:14:54 +0800 | [diff] [blame] | 707 | unsigned char *dst; |
| 708 | |
| 709 | cmdline_final = (unsigned char*) malloc((cmdline_len + 4) & (~3)); |
| 710 | ASSERT(cmdline_final != NULL); |
vijay kumar | 287bb54 | 2015-09-29 13:01:52 +0530 | [diff] [blame] | 711 | memset((void *)cmdline_final, 0, sizeof(*cmdline_final)); |
Maria Yu | 52254c0 | 2014-07-04 16:14:54 +0800 | [diff] [blame] | 712 | dst = cmdline_final; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 713 | |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 714 | /* Save start ptr for debug print */ |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 715 | if (have_cmdline) { |
| 716 | src = cmdline; |
| 717 | while ((*dst++ = *src++)); |
| 718 | } |
| 719 | if (target_is_emmc_boot()) { |
| 720 | src = emmc_cmdline; |
| 721 | if (have_cmdline) --dst; |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 722 | have_cmdline = 1; |
| 723 | while ((*dst++ = *src++)); |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 724 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 725 | src = boot_dev_buf; |
| 726 | if (have_cmdline) --dst; |
| 727 | while ((*dst++ = *src++)); |
| 728 | #endif |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 729 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 730 | |
Sridhar Parasuram | 4311b8e | 2015-05-28 17:01:59 -0700 | [diff] [blame] | 731 | #if VERIFIED_BOOT |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 732 | if (VB_M <= target_get_vb_version()) |
Sridhar Parasuram | 7d8bb9a | 2015-09-23 18:21:19 -0700 | [diff] [blame] | 733 | { |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 734 | src = verified_state; |
| 735 | if(have_cmdline) --dst; |
| 736 | have_cmdline = 1; |
| 737 | while ((*dst++ = *src++)); |
| 738 | src = vbsn[boot_state].name; |
| 739 | if(have_cmdline) --dst; |
| 740 | while ((*dst++ = *src++)); |
| 741 | |
| 742 | if ((device.verity_mode != 0 ) && (device.verity_mode != 1)) |
| 743 | { |
| 744 | dprintf(CRITICAL, "Devinfo paritition possibly corrupted!!!. Please erase devinfo partition to continue booting\n"); |
| 745 | ASSERT(0); |
| 746 | } |
| 747 | src = verity_mode; |
| 748 | if(have_cmdline) --dst; |
| 749 | while ((*dst++ = *src++)); |
| 750 | src = vbvm[device.verity_mode].name; |
| 751 | if(have_cmdline) -- dst; |
| 752 | while ((*dst++ = *src++)); |
| 753 | src = keymaster_v1; |
| 754 | if(have_cmdline) --dst; |
| 755 | while ((*dst++ = *src++)); |
Sridhar Parasuram | 7d8bb9a | 2015-09-23 18:21:19 -0700 | [diff] [blame] | 756 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 757 | #endif |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 758 | |
| 759 | if (vbcmdline != NULL) { |
| 760 | src = vbcmdline; |
| 761 | if (have_cmdline) --dst; |
| 762 | while ((*dst++ = *src++)); |
| 763 | } |
| 764 | |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 765 | src = usb_sn_cmdline; |
| 766 | if (have_cmdline) --dst; |
| 767 | have_cmdline = 1; |
| 768 | while ((*dst++ = *src++)); |
| 769 | src = sn_buf; |
| 770 | if (have_cmdline) --dst; |
| 771 | have_cmdline = 1; |
| 772 | while ((*dst++ = *src++)); |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 773 | if (warm_boot) { |
| 774 | if (have_cmdline) --dst; |
| 775 | src = warmboot_cmdline; |
| 776 | while ((*dst++ = *src++)); |
| 777 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 778 | |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 779 | if (boot_into_recovery && gpt_exists) { |
| 780 | src = secondary_gpt_enable; |
| 781 | if (have_cmdline) --dst; |
| 782 | while ((*dst++ = *src++)); |
| 783 | } |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 784 | #ifdef MDTP_SUPPORT |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 785 | if (is_mdtp_activated) { |
| 786 | src = mdtp_activated_flag; |
| 787 | if (have_cmdline) --dst; |
| 788 | while ((*dst++ = *src++)); |
| 789 | } |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 790 | #endif |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 791 | if (boot_into_ffbm) { |
| 792 | src = androidboot_mode; |
| 793 | if (have_cmdline) --dst; |
| 794 | while ((*dst++ = *src++)); |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 795 | src = ffbm_mode_string; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 796 | if (have_cmdline) --dst; |
| 797 | while ((*dst++ = *src++)); |
Hareesh Gautham | abf1e1e | 2017-04-12 18:09:24 +0530 | [diff] [blame] | 798 | |
| 799 | if(is_systemd_present) { |
| 800 | src = systemd_ffbm_mode; |
| 801 | if (have_cmdline) --dst; |
| 802 | while ((*dst++ = *src++)); |
| 803 | } |
| 804 | |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 805 | src = loglevel; |
| 806 | if (have_cmdline) --dst; |
| 807 | while ((*dst++ = *src++)); |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 808 | } else if (boot_reason_alarm) { |
| 809 | src = alarmboot_cmdline; |
| 810 | if (have_cmdline) --dst; |
| 811 | while ((*dst++ = *src++)); |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 812 | } else if (pause_at_bootup) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 813 | src = battchg_pause; |
| 814 | if (have_cmdline) --dst; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 815 | while ((*dst++ = *src++)); |
| 816 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 817 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 818 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 819 | src = auth_kernel; |
| 820 | if (have_cmdline) --dst; |
| 821 | while ((*dst++ = *src++)); |
| 822 | } |
| 823 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 824 | switch(target_baseband()) |
| 825 | { |
| 826 | case BASEBAND_APQ: |
| 827 | src = baseband_apq; |
| 828 | if (have_cmdline) --dst; |
| 829 | while ((*dst++ = *src++)); |
| 830 | break; |
| 831 | |
| 832 | case BASEBAND_MSM: |
| 833 | src = baseband_msm; |
| 834 | if (have_cmdline) --dst; |
| 835 | while ((*dst++ = *src++)); |
| 836 | break; |
| 837 | |
| 838 | case BASEBAND_CSFB: |
| 839 | src = baseband_csfb; |
| 840 | if (have_cmdline) --dst; |
| 841 | while ((*dst++ = *src++)); |
| 842 | break; |
| 843 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 844 | case BASEBAND_SVLTE2A: |
| 845 | src = baseband_svlte2a; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 846 | if (have_cmdline) --dst; |
| 847 | while ((*dst++ = *src++)); |
| 848 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 849 | |
| 850 | case BASEBAND_MDM: |
| 851 | src = baseband_mdm; |
| 852 | if (have_cmdline) --dst; |
| 853 | while ((*dst++ = *src++)); |
| 854 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 855 | |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 856 | case BASEBAND_MDM2: |
| 857 | src = baseband_mdm2; |
| 858 | if (have_cmdline) --dst; |
| 859 | while ((*dst++ = *src++)); |
| 860 | break; |
| 861 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 862 | case BASEBAND_SGLTE: |
| 863 | src = baseband_sglte; |
| 864 | if (have_cmdline) --dst; |
| 865 | while ((*dst++ = *src++)); |
| 866 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 867 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 868 | case BASEBAND_SGLTE2: |
| 869 | src = baseband_sglte2; |
| 870 | if (have_cmdline) --dst; |
| 871 | while ((*dst++ = *src++)); |
| 872 | break; |
| 873 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 874 | case BASEBAND_DSDA: |
| 875 | src = baseband_dsda; |
| 876 | if (have_cmdline) --dst; |
| 877 | while ((*dst++ = *src++)); |
| 878 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 879 | |
| 880 | case BASEBAND_DSDA2: |
| 881 | src = baseband_dsda2; |
| 882 | if (have_cmdline) --dst; |
| 883 | while ((*dst++ = *src++)); |
| 884 | break; |
Vijay Kumar Pendoti | b228cfc | 2016-06-13 20:15:23 +0530 | [diff] [blame] | 885 | case BASEBAND_APQ_NOWGR: |
| 886 | src = baseband_apq_nowgr; |
| 887 | if (have_cmdline) --dst; |
| 888 | while ((*dst++ = *src++)); |
| 889 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 890 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 891 | |
| 892 | if (strlen(display_panel_buf)) { |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 893 | src = display_panel_buf; |
| 894 | if (have_cmdline) --dst; |
| 895 | while ((*dst++ = *src++)); |
| 896 | } |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 897 | |
| 898 | if (have_target_boot_params) { |
| 899 | if (have_cmdline) --dst; |
| 900 | src = target_boot_params; |
| 901 | while ((*dst++ = *src++)); |
vijay kumar | 870515d | 2015-08-31 16:37:24 +0530 | [diff] [blame] | 902 | free(target_boot_params); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 903 | } |
Channagoud Kadabi | 85c7ec3 | 2016-01-28 23:09:21 -0800 | [diff] [blame] | 904 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 905 | if (partition_multislot_is_supported() && have_cmdline) |
| 906 | { |
| 907 | src = androidboot_slot_suffix; |
| 908 | --dst; |
| 909 | while ((*dst++ = *src++)); |
| 910 | --dst; |
| 911 | src = SUFFIX_SLOT(current_active_slot); |
| 912 | while ((*dst++ = *src++)); |
Mayank Grover | 5384ed8 | 2018-05-09 12:09:24 +0530 | [diff] [blame] | 913 | } |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 914 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 915 | |
Mayank Grover | 5384ed8 | 2018-05-09 12:09:24 +0530 | [diff] [blame] | 916 | /* |
| 917 | * System-As-Root behaviour, system.img should contain both |
| 918 | * system content and ramdisk content, and should be mounted at |
| 919 | * root(a/b). |
| 920 | * Apending skip_ramfs for non a/b builds which use, system as root. |
| 921 | */ |
| 922 | if ((target_uses_system_as_root() || |
| 923 | partition_multislot_is_supported()) && |
| 924 | have_cmdline) |
| 925 | { |
| 926 | if (!boot_into_recovery) |
| 927 | { |
| 928 | src = skip_ramfs; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 929 | --dst; |
| 930 | while ((*dst++ = *src++)); |
Mayank Grover | 5384ed8 | 2018-05-09 12:09:24 +0530 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | src = sys_path_cmdline; |
| 934 | --dst; |
| 935 | while ((*dst++ = *src++)); |
Mayank Grover | 3804be7 | 2017-06-22 11:59:23 +0530 | [diff] [blame] | 936 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 937 | #ifndef VERIFIED_BOOT_2 |
Mayank Grover | 5384ed8 | 2018-05-09 12:09:24 +0530 | [diff] [blame] | 938 | src = syspath_buf; |
| 939 | --dst; |
| 940 | while ((*dst++ = *src++)); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 941 | #endif |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 942 | } |
| 943 | |
Mayank Grover | 466d656 | 2018-05-10 14:52:20 +0530 | [diff] [blame] | 944 | #if HIBERNATION_SUPPORT |
| 945 | if (swap_ptn_index != INVALID_PTN) |
| 946 | { |
| 947 | src = resume_buf; |
| 948 | --dst; |
| 949 | while ((*dst++ = *src++)); |
| 950 | } |
| 951 | #endif |
| 952 | |
Channagoud Kadabi | 85c7ec3 | 2016-01-28 23:09:21 -0800 | [diff] [blame] | 953 | #if TARGET_CMDLINE_SUPPORT |
| 954 | if (target_cmdline_buf && target_cmd_line_len) |
| 955 | { |
| 956 | if (have_cmdline) --dst; |
| 957 | src = target_cmdline_buf; |
| 958 | while((*dst++ = *src++)); |
| 959 | free(target_cmdline_buf); |
| 960 | } |
| 961 | #endif |
lijuang | 83ef4b2 | 2018-08-23 11:01:55 +0800 | [diff] [blame] | 962 | |
| 963 | #if !VERITY_LE |
| 964 | if (dtbo_idx != INVALID_PTN) { |
| 965 | src = dtbo_idx_str; |
| 966 | --dst; |
| 967 | while ((*dst++ = *src++)); |
| 968 | } |
| 969 | #endif |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 970 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 971 | |
| 972 | |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 973 | if (boot_dev_buf) |
| 974 | free(boot_dev_buf); |
| 975 | |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 976 | if (cmdline_final) |
| 977 | dprintf(INFO, "cmdline: %s\n", cmdline_final); |
| 978 | else |
| 979 | dprintf(INFO, "cmdline is NULL\n"); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 980 | return cmdline_final; |
| 981 | } |
| 982 | |
| 983 | unsigned *atag_core(unsigned *ptr) |
| 984 | { |
| 985 | /* CORE */ |
| 986 | *ptr++ = 2; |
| 987 | *ptr++ = 0x54410001; |
| 988 | |
| 989 | return ptr; |
| 990 | |
| 991 | } |
| 992 | |
| 993 | unsigned *atag_ramdisk(unsigned *ptr, void *ramdisk, |
| 994 | unsigned ramdisk_size) |
| 995 | { |
| 996 | if (ramdisk_size) { |
| 997 | *ptr++ = 4; |
| 998 | *ptr++ = 0x54420005; |
| 999 | *ptr++ = (unsigned)ramdisk; |
| 1000 | *ptr++ = ramdisk_size; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1001 | } |
| 1002 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1003 | return ptr; |
| 1004 | } |
| 1005 | |
| 1006 | unsigned *atag_ptable(unsigned **ptr_addr) |
| 1007 | { |
| 1008 | int i; |
| 1009 | struct ptable *ptable; |
| 1010 | |
| 1011 | if ((ptable = flash_get_ptable()) && (ptable->count != 0)) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1012 | *(*ptr_addr)++ = 2 + (ptable->count * (sizeof(struct atag_ptbl_entry) / |
| 1013 | sizeof(unsigned))); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1014 | *(*ptr_addr)++ = 0x4d534d70; |
| 1015 | for (i = 0; i < ptable->count; ++i) |
| 1016 | ptentry_to_tag(ptr_addr, ptable_get(ptable, i)); |
| 1017 | } |
| 1018 | |
| 1019 | return (*ptr_addr); |
| 1020 | } |
| 1021 | |
| 1022 | unsigned *atag_cmdline(unsigned *ptr, const char *cmdline) |
| 1023 | { |
| 1024 | int cmdline_length = 0; |
| 1025 | int n; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1026 | char *dest; |
| 1027 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 1028 | cmdline_length = strlen((const char*)cmdline); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1029 | n = (cmdline_length + 4) & (~3); |
| 1030 | |
| 1031 | *ptr++ = (n / 4) + 2; |
| 1032 | *ptr++ = 0x54410009; |
| 1033 | dest = (char *) ptr; |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 1034 | while ((*dest++ = *cmdline++)); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1035 | ptr += (n / 4); |
| 1036 | |
| 1037 | return ptr; |
| 1038 | } |
| 1039 | |
| 1040 | unsigned *atag_end(unsigned *ptr) |
| 1041 | { |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1042 | /* END */ |
| 1043 | *ptr++ = 0; |
| 1044 | *ptr++ = 0; |
| 1045 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1046 | return ptr; |
| 1047 | } |
| 1048 | |
| 1049 | void generate_atags(unsigned *ptr, const char *cmdline, |
| 1050 | void *ramdisk, unsigned ramdisk_size) |
| 1051 | { |
vijay kumar | 21a3745 | 2015-12-29 16:23:21 +0530 | [diff] [blame] | 1052 | unsigned *orig_ptr = ptr; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1053 | ptr = atag_core(ptr); |
| 1054 | ptr = atag_ramdisk(ptr, ramdisk, ramdisk_size); |
| 1055 | ptr = target_atag_mem(ptr); |
| 1056 | |
| 1057 | /* Skip NAND partition ATAGS for eMMC boot */ |
| 1058 | if (!target_is_emmc_boot()){ |
| 1059 | ptr = atag_ptable(&ptr); |
| 1060 | } |
| 1061 | |
vijay kumar | 21a3745 | 2015-12-29 16:23:21 +0530 | [diff] [blame] | 1062 | /* |
| 1063 | * Atags size filled till + cmdline size + 1 unsigned for 4-byte boundary + 4 unsigned |
| 1064 | * for atag identifier in atag_cmdline and atag_end should be with in MAX_TAGS_SIZE bytes |
| 1065 | */ |
Mayank Grover | bc8a2ef | 2018-02-23 18:03:36 +0530 | [diff] [blame] | 1066 | if (!cmdline) |
| 1067 | return; |
| 1068 | |
vijay kumar | 21a3745 | 2015-12-29 16:23:21 +0530 | [diff] [blame] | 1069 | if (((ptr - orig_ptr) + strlen(cmdline) + 5 * sizeof(unsigned)) < MAX_TAGS_SIZE) { |
| 1070 | ptr = atag_cmdline(ptr, cmdline); |
| 1071 | ptr = atag_end(ptr); |
| 1072 | } |
| 1073 | else { |
| 1074 | dprintf(CRITICAL,"Crossing ATAGs Max size allowed\n"); |
| 1075 | ASSERT(0); |
| 1076 | } |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1079 | typedef void entry_func_ptr(unsigned, unsigned, unsigned*); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1080 | void boot_linux(void *kernel, unsigned *tags, |
| 1081 | const char *cmdline, unsigned machtype, |
| 1082 | void *ramdisk, unsigned ramdisk_size) |
| 1083 | { |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 1084 | unsigned char *final_cmdline; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1085 | #if DEVICE_TREE |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 1086 | int ret = 0; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1087 | #endif |
| 1088 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1089 | void (*entry)(unsigned, unsigned, unsigned*) = (entry_func_ptr*)(PA((addr_t)kernel)); |
Deepa Dinamani | 25a9f76 | 2012-11-30 15:57:15 -0800 | [diff] [blame] | 1090 | uint32_t tags_phys = PA((addr_t)tags); |
vijay kumar | 1a50a64 | 2015-11-16 12:41:15 +0530 | [diff] [blame] | 1091 | struct kernel64_hdr *kptr = ((struct kernel64_hdr*)(PA((addr_t)kernel))); |
Deepa Dinamani | 25a9f76 | 2012-11-30 15:57:15 -0800 | [diff] [blame] | 1092 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 1093 | ramdisk = (void *)PA((addr_t)ramdisk); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1094 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 1095 | final_cmdline = update_cmdline((const char*)cmdline); |
| 1096 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 1097 | #if DEVICE_TREE |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1098 | dprintf(INFO, "Updating device tree: start\n"); |
| 1099 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 1100 | /* Update the Device Tree */ |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 1101 | 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] | 1102 | if(ret) |
| 1103 | { |
| 1104 | dprintf(CRITICAL, "ERROR: Updating Device Tree Failed \n"); |
| 1105 | ASSERT(0); |
| 1106 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1107 | dprintf(INFO, "Updating device tree: done\n"); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 1108 | #else |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1109 | /* Generating the Atags */ |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 1110 | generate_atags(tags, final_cmdline, ramdisk, ramdisk_size); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 1111 | #endif |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 1112 | |
Monika Singh | b0db4b8 | 2018-09-26 12:18:02 +0530 | [diff] [blame] | 1113 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
| 1114 | if (VB_M <= target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 1115 | { |
| 1116 | if (device.verity_mode == 0) { |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 1117 | #if FBCON_DISPLAY_MSG |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 1118 | #if ENABLE_VB_ATTEST |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 1119 | display_bootverify_menu(DISPLAY_MENU_EIO); |
| 1120 | wait_for_users_action(); |
| 1121 | if(!pwr_key_is_pressed) |
| 1122 | shutdown_device(); |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 1123 | #else |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 1124 | display_bootverify_menu(DISPLAY_MENU_LOGGING); |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 1125 | #endif |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 1126 | wait_for_users_action(); |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 1127 | #else |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 1128 | dprintf(CRITICAL, |
| 1129 | "The dm-verity is not started in enforcing mode.\nWait for 5 seconds before proceeding\n"); |
| 1130 | mdelay(5000); |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 1131 | #endif |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 1132 | } |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 1133 | } |
lijuang | bdd9bb4 | 2016-03-01 18:22:17 +0800 | [diff] [blame] | 1134 | #endif |
| 1135 | |
| 1136 | #if VERIFIED_BOOT |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 1137 | /* Write protect the device info */ |
Channagoud Kadabi | 3bd9d1e | 2015-05-05 16:18:20 -0700 | [diff] [blame] | 1138 | 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] | 1139 | { |
| 1140 | dprintf(INFO, "Failed to write protect dev info\n"); |
| 1141 | ASSERT(0); |
| 1142 | } |
| 1143 | #endif |
| 1144 | |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 1145 | /* Turn off splash screen if enabled */ |
| 1146 | #if DISPLAY_SPLASH_SCREEN |
| 1147 | target_display_shutdown(); |
| 1148 | #endif |
| 1149 | |
Veera Sundaram Sankaran | 67ea093 | 2015-09-25 10:09:30 -0700 | [diff] [blame] | 1150 | /* Perform target specific cleanup */ |
| 1151 | target_uninit(); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1152 | free_verified_boot_resource(&info); |
| 1153 | if (final_cmdline) |
| 1154 | free(final_cmdline); |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 1155 | |
Deepa Dinamani | 33734bc | 2013-03-06 12:16:06 -0800 | [diff] [blame] | 1156 | 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] | 1157 | entry, ramdisk, ramdisk_size, (void *)tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1158 | |
| 1159 | enter_critical_section(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1160 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 1161 | /* do any platform specific cleanup before kernel entry */ |
| 1162 | platform_uninit(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1163 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1164 | arch_disable_cache(UCACHE); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1165 | |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 1166 | #if ARM_WITH_MMU |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1167 | arch_disable_mmu(); |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 1168 | #endif |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1169 | bs_set_timestamp(BS_KERNEL_ENTRY); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1170 | |
| 1171 | if (IS_ARM64(kptr)) |
| 1172 | /* Jump to a 64bit kernel */ |
| 1173 | scm_elexec_call((paddr_t)kernel, tags_phys); |
| 1174 | else |
| 1175 | /* Jump to a 32bit kernel */ |
| 1176 | entry(0, machtype, (unsigned*)tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1177 | } |
| 1178 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1179 | /* Function to check if the memory address range falls within the aboot |
| 1180 | * boundaries. |
| 1181 | * start: Start of the memory region |
| 1182 | * size: Size of the memory region |
| 1183 | */ |
Vijay Kumar Pendoti | 9c002ad | 2016-03-09 13:52:45 +0530 | [diff] [blame] | 1184 | int check_aboot_addr_range_overlap(uintptr_t start, uint32_t size) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1185 | { |
| 1186 | /* Check for boundary conditions. */ |
Sundarajan Srinivasan | ce2a0ea | 2013-12-16 17:02:56 -0800 | [diff] [blame] | 1187 | if ((UINT_MAX - start) < size) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1188 | return -1; |
| 1189 | |
| 1190 | /* Check for memory overlap. */ |
| 1191 | if ((start < MEMBASE) && ((start + size) <= MEMBASE)) |
| 1192 | return 0; |
Channagoud Kadabi | 9414391 | 2013-10-15 12:53:52 -0700 | [diff] [blame] | 1193 | else if (start >= (MEMBASE + MEMSIZE)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1194 | return 0; |
| 1195 | else |
| 1196 | return -1; |
| 1197 | } |
| 1198 | |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 1199 | /* Function to check if the memory address range falls beyond ddr region. |
| 1200 | * start: Start of the memory region |
| 1201 | * size: Size of the memory region |
| 1202 | */ |
| 1203 | int check_ddr_addr_range_bound(uintptr_t start, uint32_t size) |
| 1204 | { |
| 1205 | uintptr_t ddr_pa_start_addr = PA(get_ddr_start()); |
| 1206 | uint64_t ddr_size = smem_get_ddr_size(); |
| 1207 | uint64_t ddr_pa_end_addr = ddr_pa_start_addr + ddr_size; |
| 1208 | uintptr_t pa_start_addr = PA(start); |
| 1209 | |
| 1210 | /* Check for boundary conditions. */ |
| 1211 | if ((UINT_MAX - start) < size) |
| 1212 | return -1; |
| 1213 | |
| 1214 | /* Check if memory range is beyond the ddr range. */ |
| 1215 | if (pa_start_addr < ddr_pa_start_addr || |
| 1216 | pa_start_addr >= (ddr_pa_end_addr) || |
| 1217 | (pa_start_addr + size) > ddr_pa_end_addr) |
| 1218 | return -1; |
| 1219 | else |
| 1220 | return 0; |
| 1221 | } |
| 1222 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1223 | BUF_DMA_ALIGN(buf, BOOT_IMG_MAX_PAGE_SIZE); //Equal to max-supported pagesize |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1224 | |
Mayank Grover | dd080e8 | 2018-09-04 20:12:13 +0530 | [diff] [blame] | 1225 | int getimage(void **image_buffer, uint32_t *imgsize, |
| 1226 | const char *imgname) |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1227 | { |
Mayank Grover | dd080e8 | 2018-09-04 20:12:13 +0530 | [diff] [blame] | 1228 | uint32_t loadedindex; |
| 1229 | if (image_buffer == NULL || imgsize == NULL || |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1230 | imgname == NULL) { |
| 1231 | dprintf(CRITICAL, "getimage: invalid parameters\n"); |
| 1232 | return -1; |
| 1233 | } |
Mayank Grover | dd080e8 | 2018-09-04 20:12:13 +0530 | [diff] [blame] | 1234 | for (loadedindex = 0; loadedindex < info.num_loaded_images; loadedindex++) { |
| 1235 | if (!strncmp(info.images[loadedindex].name, imgname, |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1236 | strlen(imgname))) { |
Mayank Grover | dd080e8 | 2018-09-04 20:12:13 +0530 | [diff] [blame] | 1237 | *image_buffer = info.images[loadedindex].image_buffer; |
| 1238 | *imgsize = info.images[loadedindex].imgsize; |
Mayank Grover | 027a941 | 2018-09-04 15:12:05 +0530 | [diff] [blame] | 1239 | dprintf(SPEW, "getimage(): Loaded image [%s|%d]\n", |
| 1240 | info.images[loadedindex].name, |
| 1241 | info.images[loadedindex].imgsize); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1242 | return 0; |
| 1243 | } |
| 1244 | } |
| 1245 | return -1; |
| 1246 | } |
| 1247 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1248 | static void verify_signed_bootimg(uint32_t bootimg_addr, uint32_t bootimg_size) |
| 1249 | { |
| 1250 | int ret; |
Channagoud Kadabi | a8c623f | 2015-01-13 14:48:48 -0800 | [diff] [blame] | 1251 | |
| 1252 | #if !VERIFIED_BOOT |
Sundarajan Srinivasan | ce54d6e | 2013-11-11 12:45:00 -0800 | [diff] [blame] | 1253 | #if IMAGE_VERIF_ALGO_SHA1 |
| 1254 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA1; |
| 1255 | #else |
| 1256 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA256; |
| 1257 | #endif |
Channagoud Kadabi | a8c623f | 2015-01-13 14:48:48 -0800 | [diff] [blame] | 1258 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1259 | |
| 1260 | /* Assume device is rooted at this time. */ |
| 1261 | device.is_tampered = 1; |
| 1262 | |
| 1263 | dprintf(INFO, "Authenticating boot image (%d): start\n", bootimg_size); |
| 1264 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1265 | #if VERIFIED_BOOT |
Monika Singh | 7d2fc27 | 2018-03-16 17:16:01 +0530 | [diff] [blame] | 1266 | uint32_t bootstate; |
| 1267 | if(boot_into_recovery && |
Mayank Grover | 68fbf0d | 2017-10-24 14:13:39 +0530 | [diff] [blame] | 1268 | (!partition_multislot_is_supported())) |
Monika Singh | 7d2fc27 | 2018-03-16 17:16:01 +0530 | [diff] [blame] | 1269 | { |
| 1270 | ret = boot_verify_image((unsigned char *)bootimg_addr, |
| 1271 | bootimg_size, "/recovery", &bootstate); |
| 1272 | } |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1273 | else |
Monika Singh | 7d2fc27 | 2018-03-16 17:16:01 +0530 | [diff] [blame] | 1274 | { |
| 1275 | ret = boot_verify_image((unsigned char *)bootimg_addr, |
| 1276 | bootimg_size, "/boot", &bootstate); |
| 1277 | } |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1278 | boot_verify_print_state(); |
| 1279 | #else |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1280 | ret = image_verify((unsigned char *)bootimg_addr, |
| 1281 | (unsigned char *)(bootimg_addr + bootimg_size), |
| 1282 | bootimg_size, |
Sundarajan Srinivasan | ce54d6e | 2013-11-11 12:45:00 -0800 | [diff] [blame] | 1283 | auth_algo); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1284 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1285 | dprintf(INFO, "Authenticating boot image: done return value = %d\n", ret); |
| 1286 | |
| 1287 | if (ret) |
| 1288 | { |
| 1289 | /* Authorized kernel */ |
| 1290 | device.is_tampered = 0; |
Sundarajan Srinivasan | 3fb21f1 | 2013-09-16 18:36:15 -0700 | [diff] [blame] | 1291 | auth_kernel_img = 1; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 1294 | #ifdef MDTP_SUPPORT |
| 1295 | { |
| 1296 | /* Verify MDTP lock. |
| 1297 | * For boot & recovery partitions, use aboot's verification result. |
| 1298 | */ |
| 1299 | mdtp_ext_partition_verification_t ext_partition; |
| 1300 | ext_partition.partition = boot_into_recovery ? MDTP_PARTITION_RECOVERY : MDTP_PARTITION_BOOT; |
| 1301 | ext_partition.integrity_state = device.is_tampered ? MDTP_PARTITION_STATE_INVALID : MDTP_PARTITION_STATE_VALID; |
| 1302 | ext_partition.page_size = 0; /* Not needed since already validated */ |
| 1303 | ext_partition.image_addr = 0; /* Not needed since already validated */ |
| 1304 | ext_partition.image_size = 0; /* Not needed since already validated */ |
| 1305 | ext_partition.sig_avail = FALSE; /* Not needed since already validated */ |
| 1306 | mdtp_fwlock_verify_lock(&ext_partition); |
| 1307 | } |
| 1308 | #endif /* MDTP_SUPPORT */ |
| 1309 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1310 | #if USE_PCOM_SECBOOT |
| 1311 | set_tamper_flag(device.is_tampered); |
| 1312 | #endif |
| 1313 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1314 | #if VERIFIED_BOOT |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 1315 | switch(boot_verify_get_state()) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1316 | { |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 1317 | case RED: |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 1318 | #if FBCON_DISPLAY_MSG |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 1319 | display_bootverify_menu(DISPLAY_MENU_RED); |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 1320 | #if ENABLE_VB_ATTEST |
| 1321 | mdelay(DELAY_WAIT); |
| 1322 | shutdown_device(); |
| 1323 | #else |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 1324 | wait_for_users_action(); |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 1325 | #endif |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 1326 | #else |
| 1327 | dprintf(CRITICAL, |
| 1328 | "Your device has failed verification and may not work properly.\nWait for 5 seconds before proceeding\n"); |
| 1329 | mdelay(5000); |
| 1330 | #endif |
| 1331 | |
| 1332 | break; |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 1333 | case YELLOW: |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 1334 | #if FBCON_DISPLAY_MSG |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 1335 | display_bootverify_menu(DISPLAY_MENU_YELLOW); |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 1336 | wait_for_users_action(); |
| 1337 | #else |
| 1338 | dprintf(CRITICAL, |
| 1339 | "Your device has loaded a different operating system.\nWait for 5 seconds before proceeding\n"); |
| 1340 | mdelay(5000); |
| 1341 | #endif |
| 1342 | break; |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 1343 | default: |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 1344 | break; |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1345 | } |
| 1346 | #endif |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 1347 | #if !VERIFIED_BOOT |
Unnati Gandhi | 1be0475 | 2015-03-27 19:41:53 +0530 | [diff] [blame] | 1348 | if(device.is_tampered) |
| 1349 | { |
| 1350 | write_device_info_mmc(&device); |
| 1351 | #ifdef TZ_TAMPER_FUSE |
Monika Singh | 9825746 | 2018-06-06 11:28:49 +0530 | [diff] [blame] | 1352 | set_tamper_fuse_cmd(HLOS_IMG_TAMPER_FUSE); |
Unnati Gandhi | 1be0475 | 2015-03-27 19:41:53 +0530 | [diff] [blame] | 1353 | #endif |
| 1354 | #ifdef ASSERT_ON_TAMPER |
| 1355 | dprintf(CRITICAL, "Device is tampered. Asserting..\n"); |
| 1356 | ASSERT(0); |
| 1357 | #endif |
| 1358 | } |
Sridhar Parasuram | 8b79242 | 2015-07-05 11:38:13 -0700 | [diff] [blame] | 1359 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 1362 | static bool check_format_bit() |
| 1363 | { |
| 1364 | bool ret = false; |
| 1365 | int index; |
| 1366 | uint64_t offset; |
| 1367 | struct boot_selection_info *in = NULL; |
| 1368 | char *buf = NULL; |
| 1369 | |
| 1370 | index = partition_get_index("bootselect"); |
| 1371 | if (index == INVALID_PTN) |
| 1372 | { |
| 1373 | dprintf(INFO, "Unable to locate /bootselect partition\n"); |
| 1374 | return ret; |
| 1375 | } |
| 1376 | offset = partition_get_offset(index); |
| 1377 | if(!offset) |
| 1378 | { |
| 1379 | dprintf(INFO, "partition /bootselect doesn't exist\n"); |
| 1380 | return ret; |
| 1381 | } |
| 1382 | buf = (char *) memalign(CACHE_LINE, ROUNDUP(page_size, CACHE_LINE)); |
Mayank Grover | 4886040 | 2016-11-29 12:34:53 +0530 | [diff] [blame] | 1383 | mmc_set_lun(partition_get_lun(index)); |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 1384 | ASSERT(buf); |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 1385 | if (mmc_read(offset, (uint32_t *)buf, page_size)) |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 1386 | { |
| 1387 | dprintf(INFO, "mmc read failure /bootselect %d\n", page_size); |
| 1388 | free(buf); |
| 1389 | return ret; |
| 1390 | } |
| 1391 | in = (struct boot_selection_info *) buf; |
| 1392 | if ((in->signature == BOOTSELECT_SIGNATURE) && |
| 1393 | (in->version == BOOTSELECT_VERSION)) { |
| 1394 | if ((in->state_info & BOOTSELECT_FORMAT) && |
| 1395 | !(in->state_info & BOOTSELECT_FACTORY)) |
| 1396 | ret = true; |
| 1397 | } else { |
| 1398 | dprintf(CRITICAL, "Signature: 0x%08x or version: 0x%08x mismatched of /bootselect\n", |
| 1399 | in->signature, in->version); |
| 1400 | ASSERT(0); |
| 1401 | } |
| 1402 | free(buf); |
| 1403 | return ret; |
| 1404 | } |
| 1405 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1406 | void boot_verifier_init() |
| 1407 | { |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1408 | uint32_t boot_state; |
| 1409 | /* Check if device unlock */ |
| 1410 | if(device.is_unlocked) |
| 1411 | { |
| 1412 | boot_verify_send_event(DEV_UNLOCK); |
| 1413 | boot_verify_print_state(); |
| 1414 | dprintf(CRITICAL, "Device is unlocked! Skipping verification...\n"); |
| 1415 | return; |
| 1416 | } |
| 1417 | else |
| 1418 | { |
| 1419 | boot_verify_send_event(BOOT_INIT); |
| 1420 | } |
| 1421 | |
| 1422 | /* Initialize keystore */ |
| 1423 | boot_state = boot_verify_keystore_init(); |
| 1424 | if(boot_state == YELLOW) |
| 1425 | { |
| 1426 | boot_verify_print_state(); |
| 1427 | dprintf(CRITICAL, "Keystore verification failed! Continuing anyways...\n"); |
| 1428 | } |
| 1429 | } |
| 1430 | |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1431 | /* Function to return recovery appended dtbo buffer info */ |
| 1432 | void get_recovery_dtbo_info(uint32_t *dtbo_size, void **dtbo_buf) |
| 1433 | { |
| 1434 | *dtbo_size = recovery_dtbo_size; |
| 1435 | *dtbo_buf = recovery_dtbo_buf; |
| 1436 | return; |
| 1437 | } |
| 1438 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1439 | int boot_linux_from_mmc(void) |
| 1440 | { |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1441 | boot_img_hdr *hdr = (void*) buf; |
| 1442 | boot_img_hdr *uhdr; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1443 | unsigned offset = 0; |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 1444 | int rcode; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1445 | unsigned long long ptn = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1446 | int index = INVALID_PTN; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1447 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1448 | unsigned char *image_addr = 0; |
| 1449 | unsigned kernel_actual; |
| 1450 | unsigned ramdisk_actual; |
| 1451 | unsigned imagesize_actual; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1452 | unsigned second_actual = 0; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1453 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1454 | unsigned int dtb_size = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1455 | unsigned int out_len = 0; |
| 1456 | unsigned int out_avai_len = 0; |
| 1457 | unsigned char *out_addr = NULL; |
| 1458 | uint32_t dtb_offset = 0; |
| 1459 | unsigned char *kernel_start_addr = NULL; |
| 1460 | unsigned int kernel_size = 0; |
Ameya Thakur | 10a3345 | 2016-06-13 14:24:26 -0700 | [diff] [blame] | 1461 | unsigned int patched_kernel_hdr_size = 0; |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1462 | uint64_t image_size = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1463 | int rc; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1464 | #if VERIFIED_BOOT_2 |
| 1465 | int status; |
Mayank Grover | 027a941 | 2018-09-04 15:12:05 +0530 | [diff] [blame] | 1466 | void *dtbo_image_buf = NULL; |
| 1467 | uint32_t dtbo_image_sz = 0; |
Mayank Grover | 9df84c0 | 2018-08-30 15:46:35 +0530 | [diff] [blame] | 1468 | void *vbmeta_image_buf = NULL; |
| 1469 | uint32_t vbmeta_image_sz = 0; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1470 | #endif |
Mayank Grover | c93cad8 | 2017-10-03 12:23:45 +0530 | [diff] [blame] | 1471 | char *ptn_name = NULL; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1472 | #if DEVICE_TREE |
| 1473 | struct dt_table *table; |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1474 | struct dt_entry dt_entry; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1475 | unsigned dt_table_offset; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1476 | uint32_t dt_actual; |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1477 | uint32_t dt_hdr_size; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1478 | unsigned char *best_match_dt_addr = NULL; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 1479 | #endif |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1480 | struct kernel64_hdr *kptr = NULL; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 1481 | int current_active_slot = INVALID; |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1482 | |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 1483 | if (check_format_bit()) |
| 1484 | boot_into_recovery = 1; |
| 1485 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 1486 | if (!boot_into_recovery) { |
| 1487 | memset(ffbm_mode_string, '\0', sizeof(ffbm_mode_string)); |
| 1488 | rcode = get_ffbm(ffbm_mode_string, sizeof(ffbm_mode_string)); |
| 1489 | if (rcode <= 0) { |
| 1490 | boot_into_ffbm = false; |
| 1491 | if (rcode < 0) |
| 1492 | dprintf(CRITICAL,"failed to get ffbm cookie"); |
| 1493 | } else |
| 1494 | boot_into_ffbm = true; |
| 1495 | } else |
| 1496 | boot_into_ffbm = false; |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1497 | uhdr = (boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1498 | if (!memcmp(uhdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 1499 | dprintf(INFO, "Unified boot method!\n"); |
| 1500 | hdr = uhdr; |
| 1501 | goto unified_boot; |
| 1502 | } |
Mayank Grover | c93cad8 | 2017-10-03 12:23:45 +0530 | [diff] [blame] | 1503 | |
| 1504 | /* For a/b recovery image code is on boot partition. |
| 1505 | If we support multislot, always use boot partition. */ |
| 1506 | if (boot_into_recovery && |
Mayank Grover | 8ab4a76 | 2019-04-25 17:23:34 +0530 | [diff] [blame^] | 1507 | ((!partition_multislot_is_supported()) || |
| 1508 | (target_dynamic_partition_supported()))) |
Mayank Grover | c93cad8 | 2017-10-03 12:23:45 +0530 | [diff] [blame] | 1509 | ptn_name = "recovery"; |
| 1510 | else |
| 1511 | ptn_name = "boot"; |
| 1512 | |
| 1513 | index = partition_get_index(ptn_name); |
| 1514 | ptn = partition_get_offset(index); |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1515 | image_size = partition_get_size(index); |
| 1516 | if(ptn == 0 || image_size == 0) { |
Mayank Grover | c93cad8 | 2017-10-03 12:23:45 +0530 | [diff] [blame] | 1517 | dprintf(CRITICAL, "ERROR: No %s partition found\n", ptn_name); |
| 1518 | return -1; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1519 | } |
Mayank Grover | c93cad8 | 2017-10-03 12:23:45 +0530 | [diff] [blame] | 1520 | |
Channagoud Kadabi | ef0547c | 2015-02-10 12:57:38 -0800 | [diff] [blame] | 1521 | /* Set Lun for boot & recovery partitions */ |
| 1522 | mmc_set_lun(partition_get_lun(index)); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1523 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 1524 | if (mmc_read(ptn + offset, (uint32_t *) buf, page_size)) { |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1525 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 1526 | return -1; |
| 1527 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1528 | |
| 1529 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 1530 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 1531 | return ERR_INVALID_BOOT_MAGIC; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1532 | } |
| 1533 | |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 1534 | if (hdr->page_size && (hdr->page_size != page_size)) { |
vijay kumar | 2e21b3a | 2014-06-26 17:40:15 +0530 | [diff] [blame] | 1535 | |
| 1536 | if (hdr->page_size > BOOT_IMG_MAX_PAGE_SIZE) { |
| 1537 | dprintf(CRITICAL, "ERROR: Invalid page size\n"); |
| 1538 | return -1; |
| 1539 | } |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 1540 | page_size = hdr->page_size; |
| 1541 | page_mask = page_size - 1; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1542 | } |
| 1543 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1544 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1545 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 1546 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1547 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1548 | image_addr = (unsigned char *)target_get_scratch_address(); |
Mayank Grover | 6fd3679 | 2018-09-10 13:26:58 +0530 | [diff] [blame] | 1549 | #if VERIFIED_BOOT_2 |
| 1550 | /* Create hole in start of image for VB salt to copy */ |
| 1551 | image_addr += SALT_BUFF_OFFSET; |
| 1552 | #endif |
Kishor PK | 9e91b59 | 2017-05-24 12:14:55 +0530 | [diff] [blame] | 1553 | memcpy(image_addr, (void *)buf, page_size); |
| 1554 | |
| 1555 | /* ensure commandline is terminated */ |
| 1556 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1557 | |
| 1558 | #if DEVICE_TREE |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 1559 | #ifndef OSVERSION_IN_BOOTIMAGE |
| 1560 | dt_size = hdr->dt_size; |
Mayank Grover | 5a50258 | 2018-09-12 11:24:49 +0530 | [diff] [blame] | 1561 | #else |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1562 | dprintf(INFO, "BootImage Header: %d\n", hdr->header_version); |
Mayank Grover | 5a50258 | 2018-09-12 11:24:49 +0530 | [diff] [blame] | 1563 | #endif |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1564 | |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 1565 | dt_actual = ROUND_TO_PAGE(dt_size, page_mask); |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 1566 | if (UINT_MAX < ((uint64_t)kernel_actual + (uint64_t)ramdisk_actual+ (uint64_t)second_actual + (uint64_t)dt_actual + page_size)) { |
Vijay Kumar Pendoti | 208f962 | 2016-06-09 19:34:01 +0530 | [diff] [blame] | 1567 | dprintf(CRITICAL, "Integer overflow detected in bootimage header fields at %u in %s\n",__LINE__,__FILE__); |
| 1568 | return -1; |
| 1569 | } |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 1570 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + second_actual + dt_actual); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1571 | #else |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 1572 | if (UINT_MAX < ((uint64_t)kernel_actual + (uint64_t)ramdisk_actual + (uint64_t)second_actual + page_size)) { |
Vijay Kumar Pendoti | 208f962 | 2016-06-09 19:34:01 +0530 | [diff] [blame] | 1573 | dprintf(CRITICAL, "Integer overflow detected in bootimage header fields at %u in %s\n",__LINE__,__FILE__); |
| 1574 | return -1; |
| 1575 | } |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 1576 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + second_actual); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1577 | #endif |
| 1578 | |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1579 | #ifdef OSVERSION_IN_BOOTIMAGE |
| 1580 | /* If header version is ONE and booting into recovery, |
| 1581 | dtbo is appended with recovery image. |
| 1582 | Doing following: |
| 1583 | * Validating the recovery offset and size. |
| 1584 | * Extracting recovery dtbo to be used as dtbo. |
| 1585 | */ |
| 1586 | if (boot_into_recovery && |
| 1587 | hdr->header_version == BOOT_HEADER_VERSION_ONE) |
| 1588 | { |
| 1589 | struct boot_img_hdr_v1 *hdr1 = |
| 1590 | (struct boot_img_hdr_v1 *) (image_addr + sizeof(boot_img_hdr)); |
Mayank Grover | a1a83c7 | 2018-09-24 11:23:15 +0530 | [diff] [blame] | 1591 | unsigned int recovery_dtbo_actual = 0; |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1592 | |
Mayank Grover | a1a83c7 | 2018-09-24 11:23:15 +0530 | [diff] [blame] | 1593 | recovery_dtbo_actual = ROUND_TO_PAGE(hdr1->recovery_dtbo_size, page_mask); |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1594 | if ((hdr1->header_size != |
| 1595 | sizeof(struct boot_img_hdr_v1) + sizeof(boot_img_hdr))) |
| 1596 | { |
| 1597 | dprintf(CRITICAL, "Invalid boot image header: %d\n", hdr1->header_size); |
| 1598 | return -1; |
| 1599 | } |
| 1600 | |
Mayank Grover | a1a83c7 | 2018-09-24 11:23:15 +0530 | [diff] [blame] | 1601 | if (recovery_dtbo_actual > MAX_SUPPORTED_DTBO_IMG_BUF) |
| 1602 | { |
| 1603 | dprintf(CRITICAL, "Recovery Dtbo Size too big %x, Allowed size %x\n", recovery_dtbo_actual, |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1604 | MAX_SUPPORTED_DTBO_IMG_BUF); |
| 1605 | return -1; |
| 1606 | } |
| 1607 | |
Mayank Grover | a1a83c7 | 2018-09-24 11:23:15 +0530 | [diff] [blame] | 1608 | if (UINT_MAX < ((uint64_t)imagesize_actual + recovery_dtbo_actual)) |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1609 | { |
| 1610 | dprintf(CRITICAL, "Integer overflow detected in recoveryimage header fields at %u in %s\n",__LINE__,__FILE__); |
| 1611 | return -1; |
| 1612 | } |
| 1613 | |
Mayank Grover | a1a83c7 | 2018-09-24 11:23:15 +0530 | [diff] [blame] | 1614 | if (UINT_MAX < (hdr1->recovery_dtbo_offset + recovery_dtbo_actual)) { |
| 1615 | dprintf(CRITICAL, |
| 1616 | "Integer overflow detected in recovery image header fields at %u in %s\n",__LINE__,__FILE__); |
| 1617 | return -1; |
| 1618 | } |
| 1619 | |
| 1620 | if (hdr1->recovery_dtbo_offset + recovery_dtbo_actual > image_size) |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1621 | { |
| 1622 | dprintf(CRITICAL, "Invalid recovery dtbo: Recovery Dtbo Offset=0x%llx," |
| 1623 | " Recovery Dtbo Size=0x%x, Image Size=0x%llx\n", |
| 1624 | hdr1->recovery_dtbo_offset, recovery_dtbo_size, image_size); |
| 1625 | return -1; |
| 1626 | } |
| 1627 | |
| 1628 | recovery_dtbo_buf = (void *)(hdr1->recovery_dtbo_offset + image_addr); |
Mayank Grover | a1a83c7 | 2018-09-24 11:23:15 +0530 | [diff] [blame] | 1629 | recovery_dtbo_size = recovery_dtbo_actual; |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1630 | imagesize_actual += recovery_dtbo_size; |
| 1631 | |
| 1632 | dprintf(SPEW, "Header version: %d\n", hdr->header_version); |
| 1633 | dprintf(SPEW, "Recovery Dtbo Size 0x%x\n", recovery_dtbo_size); |
| 1634 | dprintf(SPEW, "Recovery Dtbo Offset 0x%llx\n", hdr1->recovery_dtbo_offset); |
| 1635 | |
| 1636 | } |
| 1637 | #endif |
| 1638 | |
Saranya Chidura | b1aaf23 | 2018-11-19 15:47:50 +0530 | [diff] [blame] | 1639 | /* Validate the boot/recovery image size is within the bounds of partition size */ |
| 1640 | if (imagesize_actual > image_size) { |
| 1641 | dprintf(CRITICAL, "Image size is greater than partition size.\n"); |
| 1642 | return -1; |
| 1643 | } |
| 1644 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1645 | #if VERIFIED_BOOT |
| 1646 | boot_verifier_init(); |
| 1647 | #endif |
| 1648 | |
Mayank Grover | 1ceaee2 | 2019-04-01 17:54:32 +0530 | [diff] [blame] | 1649 | #if VERIFIED_BOOT_2 |
| 1650 | /* read full partition if device is unlocked */ |
| 1651 | if (device.is_unlocked) |
| 1652 | imagesize_actual = image_size; |
| 1653 | #endif |
| 1654 | |
Vijay Kumar Pendoti | 9c002ad | 2016-03-09 13:52:45 +0530 | [diff] [blame] | 1655 | if (check_aboot_addr_range_overlap((uintptr_t) image_addr, imagesize_actual)) |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1656 | { |
| 1657 | dprintf(CRITICAL, "Boot image buffer address overlaps with aboot addresses.\n"); |
| 1658 | return -1; |
| 1659 | } |
| 1660 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1661 | /* |
| 1662 | * Update loading flow of bootimage to support compressed/uncompressed |
| 1663 | * bootimage on both 64bit and 32bit platform. |
| 1664 | * 1. Load bootimage from emmc partition onto DDR. |
| 1665 | * 2. Check if bootimage is gzip format. If yes, decompress compressed kernel |
| 1666 | * 3. Check kernel header and update kernel load addr for 64bit and 32bit |
| 1667 | * platform accordingly. |
| 1668 | * 4. Sanity Check on kernel_addr and ramdisk_addr and copy data. |
| 1669 | */ |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 1670 | if (partition_multislot_is_supported()) |
| 1671 | { |
| 1672 | current_active_slot = partition_find_active_slot(); |
| 1673 | dprintf(INFO, "Loading boot image (%d) active_slot(%s): start\n", |
| 1674 | imagesize_actual, SUFFIX_SLOT(current_active_slot)); |
| 1675 | } |
| 1676 | else |
| 1677 | { |
| 1678 | dprintf(INFO, "Loading (%s) image (%d): start\n", |
| 1679 | (!boot_into_recovery ? "boot" : "recovery"),imagesize_actual); |
| 1680 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1681 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
| 1682 | |
Gaurav Nebhwani | 43e2a46 | 2016-03-17 21:32:56 +0530 | [diff] [blame] | 1683 | if ((target_get_max_flash_size() - page_size) < imagesize_actual) |
| 1684 | { |
| 1685 | dprintf(CRITICAL, "booimage size is greater than DDR can hold\n"); |
| 1686 | return -1; |
| 1687 | } |
Kishor PK | 9e91b59 | 2017-05-24 12:14:55 +0530 | [diff] [blame] | 1688 | offset = page_size; |
| 1689 | /* Read image without signature and header*/ |
| 1690 | if (mmc_read(ptn + offset, (void *)(image_addr + offset), imagesize_actual - page_size)) |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1691 | { |
| 1692 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 1693 | return -1; |
| 1694 | } |
| 1695 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 1696 | if (partition_multislot_is_supported()) |
| 1697 | { |
| 1698 | dprintf(INFO, "Loading boot image (%d) active_slot(%s): done\n", |
| 1699 | imagesize_actual, SUFFIX_SLOT(current_active_slot)); |
| 1700 | } |
| 1701 | else |
| 1702 | { |
| 1703 | dprintf(INFO, "Loading (%s) image (%d): done\n", |
Channagoud Kadabi | f0705b5 | 2015-08-20 14:16:08 -0700 | [diff] [blame] | 1704 | (!boot_into_recovery ? "boot" : "recovery"),imagesize_actual); |
| 1705 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 1706 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1707 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
| 1708 | |
| 1709 | /* Authenticate Kernel */ |
| 1710 | dprintf(INFO, "use_signed_kernel=%d, is_unlocked=%d, is_tampered=%d.\n", |
| 1711 | (int) target_use_signed_kernel(), |
| 1712 | device.is_unlocked, |
| 1713 | device.is_tampered); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1714 | #if VERIFIED_BOOT_2 |
Mayank Grover | 1ceaee2 | 2019-04-01 17:54:32 +0530 | [diff] [blame] | 1715 | /* if device is unlocked skip reading signature, as full partition is read */ |
| 1716 | if (!device.is_unlocked) |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1717 | { |
Mayank Grover | 1ceaee2 | 2019-04-01 17:54:32 +0530 | [diff] [blame] | 1718 | offset = imagesize_actual; |
| 1719 | if (check_aboot_addr_range_overlap((uintptr_t)image_addr + offset, page_size)) |
| 1720 | { |
| 1721 | dprintf(CRITICAL, "Signature read buffer address overlaps with aboot addresses.\n"); |
| 1722 | return -1; |
| 1723 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1724 | |
Mayank Grover | 1ceaee2 | 2019-04-01 17:54:32 +0530 | [diff] [blame] | 1725 | /* Read signature */ |
| 1726 | if(mmc_read(ptn + offset, (void *)(image_addr + offset), page_size)) |
| 1727 | { |
| 1728 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
| 1729 | return -1; |
| 1730 | } |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1731 | } |
| 1732 | |
Mayank Grover | 027a941 | 2018-09-04 15:12:05 +0530 | [diff] [blame] | 1733 | /* load and validate dtbo partition */ |
| 1734 | load_validate_dtbo_image(&dtbo_image_buf, &dtbo_image_sz); |
| 1735 | |
Mayank Grover | 9df84c0 | 2018-08-30 15:46:35 +0530 | [diff] [blame] | 1736 | /* load vbmeta partition */ |
| 1737 | load_vbmeta_image(&vbmeta_image_buf, &vbmeta_image_sz); |
| 1738 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1739 | memset(&info, 0, sizeof(bootinfo)); |
Mayank Grover | 027a941 | 2018-09-04 15:12:05 +0530 | [diff] [blame] | 1740 | |
| 1741 | /* Pass loaded boot image passed */ |
Mayank Grover | 6fd3679 | 2018-09-10 13:26:58 +0530 | [diff] [blame] | 1742 | info.images[IMG_BOOT].image_buffer = SUB_SALT_BUFF_OFFSET(image_addr); |
Mayank Grover | 027a941 | 2018-09-04 15:12:05 +0530 | [diff] [blame] | 1743 | info.images[IMG_BOOT].imgsize = imagesize_actual; |
| 1744 | info.images[IMG_BOOT].name = ptn_name; |
| 1745 | ++info.num_loaded_images; |
| 1746 | |
| 1747 | /* Pass loaded dtbo image */ |
| 1748 | if (dtbo_image_buf != NULL) { |
Mayank Grover | 6fd3679 | 2018-09-10 13:26:58 +0530 | [diff] [blame] | 1749 | info.images[IMG_DTBO].image_buffer = |
| 1750 | SUB_SALT_BUFF_OFFSET(dtbo_image_buf); |
Mayank Grover | 027a941 | 2018-09-04 15:12:05 +0530 | [diff] [blame] | 1751 | info.images[IMG_DTBO].imgsize = dtbo_image_sz; |
| 1752 | info.images[IMG_DTBO].name = "dtbo"; |
| 1753 | ++info.num_loaded_images; |
| 1754 | } |
| 1755 | |
Mayank Grover | 9df84c0 | 2018-08-30 15:46:35 +0530 | [diff] [blame] | 1756 | /* Pass loaded vbmeta image */ |
| 1757 | if (vbmeta_image_buf != NULL) { |
| 1758 | info.images[IMG_VBMETA].image_buffer = vbmeta_image_buf; |
| 1759 | info.images[IMG_VBMETA].imgsize = vbmeta_image_sz; |
| 1760 | info.images[IMG_VBMETA].name = "vbmeta"; |
| 1761 | ++info.num_loaded_images; |
| 1762 | } |
| 1763 | |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 1764 | info.header_version = hdr->header_version; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1765 | info.multi_slot_boot = partition_multislot_is_supported(); |
| 1766 | info.bootreason_alarm = boot_reason_alarm; |
| 1767 | info.bootinto_recovery = boot_into_recovery; |
| 1768 | status = load_image_and_auth(&info); |
| 1769 | if(status) |
| 1770 | return -1; |
| 1771 | |
| 1772 | vbcmdline = info.vbcmdline; |
Mayank Grover | 9df84c0 | 2018-08-30 15:46:35 +0530 | [diff] [blame] | 1773 | |
| 1774 | /* Free the buffer allocated to vbmeta post verification */ |
Saranya Chidura | b493333 | 2018-10-15 17:30:06 +0530 | [diff] [blame] | 1775 | if (vbmeta_image_buf != NULL) { |
| 1776 | free(vbmeta_image_buf); |
| 1777 | --info.num_loaded_images; |
| 1778 | } |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1779 | #else |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 1780 | /* Change the condition a little bit to include the test framework support. |
| 1781 | * We would never reach this point if device is in fastboot mode, even if we did |
| 1782 | * that means we are in test mode, so execute kernel authentication part for the |
| 1783 | * tests */ |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 1784 | if((target_use_signed_kernel() && (!device.is_unlocked)) || is_test_mode_enabled()) |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1785 | { |
| 1786 | offset = imagesize_actual; |
Vijay Kumar Pendoti | 9c002ad | 2016-03-09 13:52:45 +0530 | [diff] [blame] | 1787 | 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] | 1788 | { |
| 1789 | dprintf(CRITICAL, "Signature read buffer address overlaps with aboot addresses.\n"); |
| 1790 | return -1; |
| 1791 | } |
| 1792 | |
| 1793 | /* Read signature */ |
| 1794 | if(mmc_read(ptn + offset, (void *)(image_addr + offset), page_size)) |
| 1795 | { |
| 1796 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
| 1797 | return -1; |
| 1798 | } |
| 1799 | |
| 1800 | verify_signed_bootimg((uint32_t)image_addr, imagesize_actual); |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 1801 | /* The purpose of our test is done here */ |
Parth Dixit | cb0c608 | 2015-12-30 15:01:13 +0530 | [diff] [blame] | 1802 | if(is_test_mode_enabled() && auth_kernel_img) |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 1803 | return 0; |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1804 | } else { |
| 1805 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 1806 | #ifdef TZ_SAVE_KERNEL_HASH |
| 1807 | aboot_save_boot_hash_mmc((uint32_t) image_addr, imagesize_actual); |
| 1808 | #endif /* TZ_SAVE_KERNEL_HASH */ |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 1809 | |
| 1810 | #ifdef MDTP_SUPPORT |
| 1811 | { |
| 1812 | /* Verify MDTP lock. |
| 1813 | * For boot & recovery partitions, MDTP will use boot_verifier APIs, |
| 1814 | * since verification was skipped in aboot. The signature is not part of the loaded image. |
| 1815 | */ |
| 1816 | mdtp_ext_partition_verification_t ext_partition; |
| 1817 | ext_partition.partition = boot_into_recovery ? MDTP_PARTITION_RECOVERY : MDTP_PARTITION_BOOT; |
| 1818 | ext_partition.integrity_state = MDTP_PARTITION_STATE_UNSET; |
| 1819 | ext_partition.page_size = page_size; |
| 1820 | ext_partition.image_addr = (uint32)image_addr; |
| 1821 | ext_partition.image_size = imagesize_actual; |
| 1822 | ext_partition.sig_avail = FALSE; |
| 1823 | mdtp_fwlock_verify_lock(&ext_partition); |
| 1824 | } |
| 1825 | #endif /* MDTP_SUPPORT */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1826 | } |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1827 | #endif |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1828 | |
Sridhar Parasuram | 00bfedb | 2015-05-26 14:21:27 -0700 | [diff] [blame] | 1829 | #if VERIFIED_BOOT |
taozhang | 93088bd | 2016-11-16 15:50:46 +0800 | [diff] [blame] | 1830 | if((boot_verify_get_state() == ORANGE) && (!boot_into_ffbm)) |
Reut Zysman | ba8a9d5 | 2016-02-18 11:44:04 +0200 | [diff] [blame] | 1831 | { |
| 1832 | #if FBCON_DISPLAY_MSG |
| 1833 | display_bootverify_menu(DISPLAY_MENU_ORANGE); |
| 1834 | wait_for_users_action(); |
| 1835 | #else |
| 1836 | dprintf(CRITICAL, |
| 1837 | "Your device has been unlocked and can't be trusted.\nWait for 5 seconds before proceeding\n"); |
| 1838 | mdelay(5000); |
| 1839 | #endif |
| 1840 | } |
| 1841 | #endif |
| 1842 | |
| 1843 | #if VERIFIED_BOOT |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 1844 | if (VB_M == target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 1845 | { |
| 1846 | /* set boot and system versions. */ |
| 1847 | set_os_version((unsigned char *)image_addr); |
| 1848 | // send root of trust |
| 1849 | if(!send_rot_command((uint32_t)device.is_unlocked)) |
| 1850 | ASSERT(0); |
| 1851 | } |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 1852 | #endif |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1853 | /* |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1854 | * Check if the kernel image is a gzip package. If yes, need to decompress it. |
| 1855 | * If not, continue booting. |
| 1856 | */ |
| 1857 | if (is_gzip_package((unsigned char *)(image_addr + page_size), hdr->kernel_size)) |
| 1858 | { |
| 1859 | out_addr = (unsigned char *)(image_addr + imagesize_actual + page_size); |
| 1860 | out_avai_len = target_get_max_flash_size() - imagesize_actual - page_size; |
Mayank Grover | 027a941 | 2018-09-04 15:12:05 +0530 | [diff] [blame] | 1861 | #if VERIFIED_BOOT_2 |
| 1862 | if (dtbo_image_sz) |
| 1863 | out_avai_len -= DTBO_IMG_BUF; |
| 1864 | #endif |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1865 | dprintf(INFO, "decompressing kernel image: start\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1866 | rc = decompress((unsigned char *)(image_addr + page_size), |
| 1867 | hdr->kernel_size, out_addr, out_avai_len, |
| 1868 | &dtb_offset, &out_len); |
| 1869 | if (rc) |
| 1870 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1871 | dprintf(CRITICAL, "decompressing kernel image failed!!!\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1872 | ASSERT(0); |
| 1873 | } |
| 1874 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1875 | dprintf(INFO, "decompressing kernel image: done\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1876 | kptr = (struct kernel64_hdr *)out_addr; |
| 1877 | kernel_start_addr = out_addr; |
| 1878 | kernel_size = out_len; |
| 1879 | } else { |
Ameya Thakur | 10a3345 | 2016-06-13 14:24:26 -0700 | [diff] [blame] | 1880 | dprintf(INFO, "Uncpmpressed kernel in use\n"); |
| 1881 | if (!strncmp((char*)(image_addr + page_size), |
| 1882 | PATCHED_KERNEL_MAGIC, |
| 1883 | sizeof(PATCHED_KERNEL_MAGIC) - 1)) { |
| 1884 | dprintf(INFO, "Patched kernel detected\n"); |
| 1885 | kptr = (struct kernel64_hdr *)(image_addr + page_size + |
| 1886 | PATCHED_KERNEL_HEADER_SIZE); |
| 1887 | //The size of the kernel is stored at start of kernel image + 16 |
| 1888 | //The dtb would start just after the kernel |
| 1889 | dtb_offset = *((uint32_t*)((unsigned char*) |
| 1890 | (image_addr + page_size + |
| 1891 | sizeof(PATCHED_KERNEL_MAGIC) - |
| 1892 | 1))); |
| 1893 | //The actual kernel starts after the 20 byte header. |
| 1894 | kernel_start_addr = (unsigned char*)(image_addr + |
| 1895 | page_size + PATCHED_KERNEL_HEADER_SIZE); |
| 1896 | kernel_size = hdr->kernel_size; |
| 1897 | patched_kernel_hdr_size = PATCHED_KERNEL_HEADER_SIZE; |
| 1898 | } else { |
| 1899 | dprintf(INFO, "Kernel image not patched..Unable to locate dt offset\n"); |
| 1900 | kptr = (struct kernel64_hdr *)(image_addr + page_size); |
| 1901 | kernel_start_addr = (unsigned char *)(image_addr + page_size); |
| 1902 | kernel_size = hdr->kernel_size; |
| 1903 | } |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | /* |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1907 | * Update the kernel/ramdisk/tags address if the boot image header |
| 1908 | * has default values, these default values come from mkbootimg when |
| 1909 | * the boot image is flashed using fastboot flash:raw |
| 1910 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1911 | update_ker_tags_rdisk_addr(hdr, IS_ARM64(kptr)); |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1912 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1913 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 1914 | hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr)); |
| 1915 | hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr)); |
| 1916 | hdr->tags_addr = VA((addr_t)(hdr->tags_addr)); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1917 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1918 | kernel_size = ROUND_TO_PAGE(kernel_size, page_mask); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1919 | /* Check if the addresses in the header are valid. */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1920 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_size) || |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 1921 | check_ddr_addr_range_bound(hdr->kernel_addr, kernel_size) || |
| 1922 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual) || |
| 1923 | check_ddr_addr_range_bound(hdr->ramdisk_addr, ramdisk_actual)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1924 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 1925 | dprintf(CRITICAL, "kernel/ramdisk addresses are not valid.\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1926 | return -1; |
| 1927 | } |
| 1928 | |
| 1929 | #ifndef DEVICE_TREE |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 1930 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE) || |
| 1931 | check_ddr_addr_range_bound(hdr->tags_addr, MAX_TAGS_SIZE)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1932 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 1933 | dprintf(CRITICAL, "Tags addresses are not valid.\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1934 | return -1; |
| 1935 | } |
| 1936 | #endif |
| 1937 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1938 | /* Move kernel, ramdisk and device tree to correct address */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1939 | memmove((void*) hdr->kernel_addr, kernel_start_addr, kernel_size); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1940 | 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] | 1941 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1942 | #if DEVICE_TREE |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 1943 | if(dt_size) { |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1944 | dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual); |
| 1945 | table = (struct dt_table*) dt_table_offset; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1946 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1947 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
| 1948 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1949 | return -1; |
| 1950 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1951 | |
P.V. Phani Kumar | 8291676 | 2016-03-09 09:20:19 +0530 | [diff] [blame] | 1952 | /* Its Error if, dt_hdr_size (table->num_entries * dt_entry size + Dev_Tree Header) |
| 1953 | goes beyound hdr->dt_size*/ |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 1954 | 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] | 1955 | dprintf(CRITICAL, "ERROR: Invalid Device Tree size \n"); |
| 1956 | return -1; |
| 1957 | } |
| 1958 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1959 | /* Find index of device tree within device tree table */ |
| 1960 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
| 1961 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1962 | return -1; |
| 1963 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1964 | |
P.V. Phani Kumar | 3c33320 | 2016-03-09 11:54:37 +0530 | [diff] [blame] | 1965 | if(dt_entry.offset > (UINT_MAX - dt_entry.size)) { |
| 1966 | dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n"); |
| 1967 | return -1; |
| 1968 | } |
| 1969 | |
| 1970 | /* Ensure we are not overshooting dt_size with the dt_entry selected */ |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 1971 | if ((dt_entry.offset + dt_entry.size) > dt_size) { |
P.V. Phani Kumar | 3c33320 | 2016-03-09 11:54:37 +0530 | [diff] [blame] | 1972 | dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n"); |
| 1973 | return -1; |
| 1974 | } |
| 1975 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1976 | if (is_gzip_package((unsigned char *)dt_table_offset + dt_entry.offset, dt_entry.size)) |
| 1977 | { |
| 1978 | unsigned int compressed_size = 0; |
| 1979 | out_addr += out_len; |
| 1980 | out_avai_len -= out_len; |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1981 | dprintf(INFO, "decompressing dtb: start\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1982 | rc = decompress((unsigned char *)dt_table_offset + dt_entry.offset, |
| 1983 | dt_entry.size, out_addr, out_avai_len, |
| 1984 | &compressed_size, &dtb_size); |
| 1985 | if (rc) |
| 1986 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1987 | dprintf(CRITICAL, "decompressing dtb failed!!!\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1988 | ASSERT(0); |
| 1989 | } |
| 1990 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 1991 | dprintf(INFO, "decompressing dtb: done\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1992 | best_match_dt_addr = out_addr; |
| 1993 | } else { |
| 1994 | best_match_dt_addr = (unsigned char *)dt_table_offset + dt_entry.offset; |
| 1995 | dtb_size = dt_entry.size; |
| 1996 | } |
| 1997 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1998 | /* Validate and Read device device tree in the tags_addr */ |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 1999 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dtb_size) || |
| 2000 | check_ddr_addr_range_bound(hdr->tags_addr, dtb_size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2001 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2002 | dprintf(CRITICAL, "Device tree addresses are not valid\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2003 | return -1; |
| 2004 | } |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2005 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2006 | memmove((void *)hdr->tags_addr, (char *)best_match_dt_addr, dtb_size); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 2007 | } else { |
| 2008 | /* Validate the tags_addr */ |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2009 | if (check_aboot_addr_range_overlap(hdr->tags_addr, kernel_actual) || |
| 2010 | check_ddr_addr_range_bound(hdr->tags_addr, kernel_actual)) |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 2011 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2012 | dprintf(CRITICAL, "Device tree addresses are not valid.\n"); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 2013 | return -1; |
| 2014 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 2015 | /* |
| 2016 | * If appended dev tree is found, update the atags with |
| 2017 | * memory address to the DTB appended location on RAM. |
| 2018 | * Else update with the atags address in the kernel header |
Mayank Grover | 1ed3e8b | 2018-09-19 15:16:50 +0530 | [diff] [blame] | 2019 | * |
| 2020 | * Make sure everything from scratch address is read before next step! |
| 2021 | * In case of dtbo, this API is going to read dtbo on scratch. |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 2022 | */ |
| 2023 | void *dtb; |
Ameya Thakur | 10a3345 | 2016-06-13 14:24:26 -0700 | [diff] [blame] | 2024 | dtb = dev_tree_appended( |
| 2025 | (void*)(image_addr + page_size + |
| 2026 | patched_kernel_hdr_size), |
| 2027 | hdr->kernel_size, dtb_offset, |
| 2028 | (void *)hdr->tags_addr); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 2029 | if (!dtb) { |
| 2030 | dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n"); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 2031 | return -1; |
| 2032 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2033 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 2034 | #endif |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2035 | |
Stanimir Varbanov | 69ec546 | 2013-07-18 18:17:42 +0300 | [diff] [blame] | 2036 | if (boot_into_recovery && !device.is_unlocked && !device.is_tampered) |
| 2037 | target_load_ssd_keystore(); |
| 2038 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2039 | unified_boot: |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2040 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 2041 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 2042 | (const char *)hdr->cmdline, board_machtype(), |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2043 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 2044 | |
| 2045 | return 0; |
| 2046 | } |
| 2047 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2048 | int boot_linux_from_flash(void) |
| 2049 | { |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 2050 | boot_img_hdr *hdr = (void*) buf; |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2051 | struct ptentry *ptn; |
| 2052 | struct ptable *ptable; |
| 2053 | unsigned offset = 0; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 2054 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2055 | unsigned char *image_addr = 0; |
| 2056 | unsigned kernel_actual; |
| 2057 | unsigned ramdisk_actual; |
| 2058 | unsigned imagesize_actual; |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 2059 | unsigned second_actual = 0; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2060 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 2061 | #if DEVICE_TREE |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2062 | struct dt_table *table = NULL; |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 2063 | struct dt_entry dt_entry; |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 2064 | unsigned dt_table_offset; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 2065 | uint32_t dt_actual; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2066 | uint32_t dt_hdr_size = 0; |
Vivek Kumar | 07bd086 | 2018-04-10 14:19:23 +0530 | [diff] [blame] | 2067 | uint32_t dtb_offset = 0; |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 2068 | unsigned int dtb_size = 0; |
| 2069 | unsigned char *best_match_dt_addr = NULL; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 2070 | #endif |
| 2071 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 2072 | if (target_is_emmc_boot()) { |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 2073 | hdr = (boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 2074 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 2075 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
| 2076 | return -1; |
| 2077 | } |
| 2078 | goto continue_boot; |
| 2079 | } |
| 2080 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2081 | ptable = flash_get_ptable(); |
| 2082 | if (ptable == NULL) { |
| 2083 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 2084 | return -1; |
| 2085 | } |
| 2086 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 2087 | if(!boot_into_recovery) |
| 2088 | { |
| 2089 | ptn = ptable_find(ptable, "boot"); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 2090 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 2091 | if (ptn == NULL) { |
| 2092 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 2093 | return -1; |
| 2094 | } |
| 2095 | } |
| 2096 | else |
| 2097 | { |
| 2098 | ptn = ptable_find(ptable, "recovery"); |
| 2099 | if (ptn == NULL) { |
| 2100 | dprintf(CRITICAL, "ERROR: No recovery partition found\n"); |
| 2101 | return -1; |
| 2102 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2103 | } |
| 2104 | |
Mayank Grover | fc7a2ce | 2017-12-20 12:58:17 +0530 | [diff] [blame] | 2105 | /* Read boot.img header from flash */ |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 2106 | if (flash_read(ptn, offset, buf, page_size)) { |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2107 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 2108 | return -1; |
| 2109 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2110 | |
| 2111 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 2112 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2113 | return -1; |
| 2114 | } |
| 2115 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 2116 | if (hdr->page_size != page_size) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 2117 | 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] | 2118 | return -1; |
| 2119 | } |
| 2120 | |
Kishor PK | 9e91b59 | 2017-05-24 12:14:55 +0530 | [diff] [blame] | 2121 | image_addr = (unsigned char *)target_get_scratch_address(); |
| 2122 | memcpy(image_addr, (void *)buf, page_size); |
vijay kumar | 287bb54 | 2015-09-29 13:01:52 +0530 | [diff] [blame] | 2123 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 2124 | /* |
| 2125 | * Update the kernel/ramdisk/tags address if the boot image header |
| 2126 | * has default values, these default values come from mkbootimg when |
| 2127 | * the boot image is flashed using fastboot flash:raw |
| 2128 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 2129 | update_ker_tags_rdisk_addr(hdr, false); |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 2130 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2131 | /* Get virtual addresses since the hdr saves physical addresses. */ |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2132 | hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr)); |
| 2133 | hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr)); |
| 2134 | hdr->tags_addr = VA((addr_t)(hdr->tags_addr)); |
| 2135 | |
| 2136 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 2137 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2138 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2139 | |
Kishor PK | 9e91b59 | 2017-05-24 12:14:55 +0530 | [diff] [blame] | 2140 | /* ensure commandline is terminated */ |
| 2141 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
| 2142 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2143 | /* Check if the addresses in the header are valid. */ |
| 2144 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_actual) || |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2145 | check_ddr_addr_range_bound(hdr->kernel_addr, kernel_actual) || |
| 2146 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual) || |
| 2147 | check_ddr_addr_range_bound(hdr->ramdisk_addr, ramdisk_actual)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2148 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2149 | dprintf(CRITICAL, "kernel/ramdisk addresses are not valid.\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2150 | return -1; |
| 2151 | } |
| 2152 | |
| 2153 | #ifndef DEVICE_TREE |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 2154 | if (UINT_MAX < ((uint64_t)kernel_actual + (uint64_t)ramdisk_actual+ (uint64_t)second_actual + page_size)) { |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2155 | dprintf(CRITICAL, "Integer overflow detected in bootimage header fields\n"); |
| 2156 | return -1; |
| 2157 | } |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 2158 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + second_actual); |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2159 | |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2160 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE) || |
| 2161 | check_ddr_addr_range_bound(hdr->tags_addr, MAX_TAGS_SIZE)) |
Vijay Kumar Pendoti | d3ed20e | 2016-09-20 00:34:46 +0530 | [diff] [blame] | 2162 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2163 | dprintf(CRITICAL, "Tags addresses are not valid.\n"); |
Vijay Kumar Pendoti | d3ed20e | 2016-09-20 00:34:46 +0530 | [diff] [blame] | 2164 | return -1; |
| 2165 | } |
| 2166 | #else |
| 2167 | |
| 2168 | #ifndef OSVERSION_IN_BOOTIMAGE |
| 2169 | dt_size = hdr->dt_size; |
| 2170 | #endif |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2171 | dt_actual = ROUND_TO_PAGE(dt_size, page_mask); |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 2172 | if (UINT_MAX < ((uint64_t)kernel_actual + (uint64_t)ramdisk_actual+ (uint64_t)second_actual + (uint64_t)dt_actual + page_size)) { |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2173 | dprintf(CRITICAL, "Integer overflow detected in bootimage header fields\n"); |
| 2174 | return -1; |
| 2175 | } |
| 2176 | |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 2177 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + second_actual + dt_actual); |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2178 | |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2179 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dt_size) || |
| 2180 | check_ddr_addr_range_bound(hdr->tags_addr, dt_size)) |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2181 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2182 | dprintf(CRITICAL, "Device tree addresses are not valid.\n"); |
Mayank Grover | 032736f | 2017-07-14 20:34:51 +0530 | [diff] [blame] | 2183 | return -1; |
| 2184 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2185 | #endif |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2186 | |
Mayank Grover | fc7a2ce | 2017-12-20 12:58:17 +0530 | [diff] [blame] | 2187 | /* Read full boot.img from flash */ |
| 2188 | dprintf(INFO, "Loading (%s) image (%d): start\n", |
| 2189 | (!boot_into_recovery ? "boot" : "recovery"),imagesize_actual); |
| 2190 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
| 2191 | |
| 2192 | if (UINT_MAX - page_size < imagesize_actual) |
| 2193 | { |
| 2194 | dprintf(CRITICAL,"Integer overflow detected in bootimage header fields %u %s\n", __LINE__,__func__); |
| 2195 | return -1; |
| 2196 | } |
| 2197 | |
| 2198 | /*Check the availability of RAM before reading boot image + max signature length from flash*/ |
| 2199 | if (target_get_max_flash_size() < (imagesize_actual + page_size)) |
| 2200 | { |
| 2201 | dprintf(CRITICAL, "bootimage size is greater than DDR can hold\n"); |
| 2202 | return -1; |
| 2203 | } |
| 2204 | |
| 2205 | offset = page_size; |
| 2206 | /* Read image without signature and header */ |
| 2207 | if (flash_read(ptn, offset, (void *)(image_addr + offset), imagesize_actual - page_size)) |
| 2208 | { |
| 2209 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 2210 | return -1; |
| 2211 | } |
| 2212 | |
| 2213 | dprintf(INFO, "Loading (%s) image (%d): done\n", |
| 2214 | (!boot_into_recovery ? "boot" : "recovery"), imagesize_actual); |
| 2215 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
| 2216 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2217 | /* Authenticate Kernel */ |
Deepa Dinamani | 23b60d4 | 2013-06-24 18:10:52 -0700 | [diff] [blame] | 2218 | if(target_use_signed_kernel() && (!device.is_unlocked)) |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2219 | { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2220 | offset = imagesize_actual; |
Mayank Grover | fc7a2ce | 2017-12-20 12:58:17 +0530 | [diff] [blame] | 2221 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2222 | /* Read signature */ |
| 2223 | if (flash_read(ptn, offset, (void *)(image_addr + offset), page_size)) |
| 2224 | { |
| 2225 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2226 | return -1; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2227 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2228 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 2229 | verify_signed_bootimg((uint32_t)image_addr, imagesize_actual); |
Mayank Grover | fc7a2ce | 2017-12-20 12:58:17 +0530 | [diff] [blame] | 2230 | } |
| 2231 | offset = page_size; |
| 2232 | if(hdr->second_size != 0) { |
| 2233 | if (UINT_MAX - offset < second_actual) |
| 2234 | { |
| 2235 | dprintf(CRITICAL, "ERROR: Integer overflow in boot image header %s\t%d\n",__func__,__LINE__); |
| 2236 | return -1; |
vijay kumar | 8f53e36 | 2015-11-24 13:38:11 +0530 | [diff] [blame] | 2237 | } |
Mayank Grover | fc7a2ce | 2017-12-20 12:58:17 +0530 | [diff] [blame] | 2238 | offset += second_actual; |
| 2239 | /* Second image loading not implemented. */ |
| 2240 | ASSERT(0); |
| 2241 | } |
Mayank Grover | fc7a2ce | 2017-12-20 12:58:17 +0530 | [diff] [blame] | 2242 | /* Move kernel and ramdisk to correct address */ |
| 2243 | memmove((void*) hdr->kernel_addr, (char*) (image_addr + page_size), hdr->kernel_size); |
| 2244 | memmove((void*) hdr->ramdisk_addr, (char*) (image_addr + page_size + kernel_actual), hdr->ramdisk_size); |
| 2245 | |
| 2246 | #if DEVICE_TREE |
| 2247 | if(dt_size != 0) { |
| 2248 | |
| 2249 | dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual); |
| 2250 | |
| 2251 | table = (struct dt_table*) dt_table_offset; |
| 2252 | |
| 2253 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
| 2254 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 2255 | return -1; |
| 2256 | } |
| 2257 | |
| 2258 | /* Its Error if, dt_hdr_size (table->num_entries * dt_entry size + Dev_Tree Header) |
| 2259 | goes beyound hdr->dt_size*/ |
| 2260 | if (dt_hdr_size > ROUND_TO_PAGE(dt_size,hdr->page_size)) { |
| 2261 | dprintf(CRITICAL, "ERROR: Invalid Device Tree size \n"); |
| 2262 | return -1; |
| 2263 | } |
| 2264 | |
| 2265 | /* Find index of device tree within device tree table */ |
| 2266 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
| 2267 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 2268 | return -1; |
| 2269 | } |
| 2270 | |
| 2271 | /* Validate and Read device device tree in the "tags_add */ |
| 2272 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dt_entry.size) || |
| 2273 | check_ddr_addr_range_bound(hdr->tags_addr, dt_entry.size)) |
| 2274 | { |
| 2275 | dprintf(CRITICAL, "Device tree addresses are not valid.\n"); |
| 2276 | return -1; |
| 2277 | } |
| 2278 | |
| 2279 | if(dt_entry.offset > (UINT_MAX - dt_entry.size)) { |
| 2280 | dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n"); |
| 2281 | return -1; |
| 2282 | } |
| 2283 | |
| 2284 | /* Ensure we are not overshooting dt_size with the dt_entry selected */ |
| 2285 | if ((dt_entry.offset + dt_entry.size) > dt_size) { |
| 2286 | dprintf(CRITICAL, "ERROR: Device tree contents are Invalid\n"); |
| 2287 | return -1; |
| 2288 | } |
| 2289 | |
| 2290 | best_match_dt_addr = (unsigned char *)table + dt_entry.offset; |
| 2291 | dtb_size = dt_entry.size; |
| 2292 | memmove((void *)hdr->tags_addr, (char *)best_match_dt_addr, dtb_size); |
Vivek Kumar | 07bd086 | 2018-04-10 14:19:23 +0530 | [diff] [blame] | 2293 | |
| 2294 | } else { |
| 2295 | /* Validate the tags_addr */ |
| 2296 | if (check_aboot_addr_range_overlap(hdr->tags_addr, kernel_actual) || |
| 2297 | check_ddr_addr_range_bound(hdr->tags_addr, kernel_actual)) |
| 2298 | { |
| 2299 | dprintf(CRITICAL, "Device tree addresses are not valid.\n"); |
| 2300 | return -1; |
| 2301 | } |
| 2302 | /* |
| 2303 | * If appended dev tree is found, update the atags with |
| 2304 | * memory address to the DTB appended location on RAM. |
| 2305 | * Else update with the atags address in the kernel header |
Mayank Grover | 1ed3e8b | 2018-09-19 15:16:50 +0530 | [diff] [blame] | 2306 | * |
| 2307 | * Make sure everything from scratch address is read before next step! |
| 2308 | * In case of dtbo, this API is going to read dtbo on scratch. |
Vivek Kumar | 07bd086 | 2018-04-10 14:19:23 +0530 | [diff] [blame] | 2309 | */ |
| 2310 | void *dtb = NULL; |
| 2311 | dtb = dev_tree_appended((void*)(image_addr + page_size ),hdr->kernel_size, dtb_offset, (void *)hdr->tags_addr); |
| 2312 | if (!dtb) { |
| 2313 | dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n"); |
| 2314 | return -1; |
| 2315 | } |
| 2316 | } |
Mayank Grover | fc7a2ce | 2017-12-20 12:58:17 +0530 | [diff] [blame] | 2317 | #endif |
| 2318 | if(target_use_signed_kernel() && (!device.is_unlocked)) |
| 2319 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2320 | /* Make sure everything from scratch address is read before next step!*/ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2321 | if(device.is_tampered) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2322 | { |
| 2323 | write_device_info_flash(&device); |
| 2324 | } |
Channagoud Kadabi | 5c86fe3 | 2012-02-16 10:58:48 +0530 | [diff] [blame] | 2325 | #if USE_PCOM_SECBOOT |
| 2326 | set_tamper_flag(device.is_tampered); |
| 2327 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 2328 | } |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 2329 | continue_boot: |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2330 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2331 | /* TODO: create/pass atags to kernel */ |
| 2332 | |
Ajay Dudani | e28a607 | 2011-07-01 13:59:46 -0700 | [diff] [blame] | 2333 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 2334 | (const char *)hdr->cmdline, board_machtype(), |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2335 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 2336 | |
| 2337 | return 0; |
| 2338 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2339 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2340 | void write_device_info_mmc(device_info *dev) |
| 2341 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2342 | unsigned long long ptn = 0; |
| 2343 | unsigned long long size; |
| 2344 | int index = INVALID_PTN; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2345 | uint8_t lun = 0; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2346 | uint32_t ret = 0; |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2347 | uint32_t device_info_sz = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2348 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2349 | if (devinfo_present) |
| 2350 | index = partition_get_index("devinfo"); |
| 2351 | else |
| 2352 | index = partition_get_index("aboot"); |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 2353 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2354 | ptn = partition_get_offset(index); |
| 2355 | if(ptn == 0) |
| 2356 | { |
| 2357 | return; |
| 2358 | } |
| 2359 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2360 | lun = partition_get_lun(index); |
| 2361 | mmc_set_lun(lun); |
| 2362 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2363 | size = partition_get_size(index); |
| 2364 | |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2365 | device_info_sz = ROUND_TO_PAGE(sizeof(struct device_info), |
| 2366 | mmc_blocksize_mask); |
| 2367 | if (device_info_sz == UINT_MAX) |
| 2368 | { |
| 2369 | dprintf(CRITICAL, "ERROR: Incorrect blocksize of card\n"); |
| 2370 | return; |
| 2371 | } |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 2372 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2373 | if (devinfo_present) |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2374 | ret = mmc_write(ptn, device_info_sz, (void *)info_buf); |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2375 | else |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2376 | ret = mmc_write((ptn + size - device_info_sz), device_info_sz, (void *)info_buf); |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2377 | if (ret) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2378 | { |
| 2379 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 2380 | ASSERT(0); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2381 | } |
| 2382 | } |
| 2383 | |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2384 | void read_device_info_mmc(struct device_info *info) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2385 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2386 | unsigned long long ptn = 0; |
| 2387 | unsigned long long size; |
| 2388 | int index = INVALID_PTN; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2389 | uint32_t ret = 0; |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2390 | uint32_t device_info_sz = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2391 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2392 | if ((index = partition_get_index("devinfo")) < 0) |
| 2393 | { |
| 2394 | devinfo_present = false; |
| 2395 | index = partition_get_index("aboot"); |
| 2396 | } |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 2397 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2398 | ptn = partition_get_offset(index); |
| 2399 | if(ptn == 0) |
| 2400 | { |
| 2401 | return; |
| 2402 | } |
| 2403 | |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 2404 | mmc_set_lun(partition_get_lun(index)); |
| 2405 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2406 | size = partition_get_size(index); |
| 2407 | |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2408 | device_info_sz = ROUND_TO_PAGE(sizeof(struct device_info), |
| 2409 | mmc_blocksize_mask); |
| 2410 | if (device_info_sz == UINT_MAX) |
| 2411 | { |
| 2412 | dprintf(CRITICAL, "ERROR: Incorrect blocksize of card\n"); |
| 2413 | return; |
| 2414 | } |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 2415 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2416 | if (devinfo_present) |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2417 | ret = mmc_read(ptn, (void *)info_buf, device_info_sz); |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2418 | else |
Mayank Grover | ddd348d | 2018-01-23 14:07:09 +0530 | [diff] [blame] | 2419 | ret = mmc_read((ptn + size - device_info_sz), (void *)info_buf, device_info_sz); |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 2420 | if (ret) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2421 | { |
| 2422 | dprintf(CRITICAL, "ERROR: Cannot read device info\n"); |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 2423 | ASSERT(0); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2424 | } |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | void write_device_info_flash(device_info *dev) |
| 2428 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2429 | 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] | 2430 | struct ptentry *ptn; |
| 2431 | struct ptable *ptable; |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2432 | if(info == NULL) |
| 2433 | { |
| 2434 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 2435 | ASSERT(0); |
| 2436 | } |
| 2437 | info_buf = info; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2438 | ptable = flash_get_ptable(); |
| 2439 | if (ptable == NULL) |
| 2440 | { |
| 2441 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 2442 | return; |
| 2443 | } |
| 2444 | |
| 2445 | ptn = ptable_find(ptable, "devinfo"); |
| 2446 | if (ptn == NULL) |
| 2447 | { |
Smita Ghosh | 670c8b8 | 2015-05-07 09:30:03 -0700 | [diff] [blame] | 2448 | dprintf(CRITICAL, "ERROR: No devinfo partition found\n"); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2449 | return; |
| 2450 | } |
| 2451 | |
Mayank Grover | dedbc89 | 2017-10-24 13:41:34 +0530 | [diff] [blame] | 2452 | memset(info, 0, BOOT_IMG_MAX_PAGE_SIZE); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2453 | memcpy(info, dev, sizeof(device_info)); |
| 2454 | |
| 2455 | if (flash_write(ptn, 0, (void *)info_buf, page_size)) |
| 2456 | { |
| 2457 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 2458 | return; |
| 2459 | } |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2460 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2461 | } |
| 2462 | |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2463 | static int read_allow_oem_unlock(device_info *dev) |
| 2464 | { |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2465 | unsigned offset; |
| 2466 | int index; |
| 2467 | unsigned long long ptn; |
| 2468 | unsigned long long ptn_size; |
| 2469 | unsigned blocksize = mmc_get_device_blocksize(); |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 2470 | STACKBUF_DMA_ALIGN(buf, blocksize); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2471 | |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 2472 | index = partition_get_index(frp_ptns[0]); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2473 | if (index == INVALID_PTN) |
| 2474 | { |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 2475 | index = partition_get_index(frp_ptns[1]); |
| 2476 | if (index == INVALID_PTN) |
| 2477 | { |
| 2478 | dprintf(CRITICAL, "Neither '%s' nor '%s' partition found\n", frp_ptns[0],frp_ptns[1]); |
| 2479 | return -1; |
| 2480 | } |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2481 | } |
| 2482 | |
| 2483 | ptn = partition_get_offset(index); |
| 2484 | ptn_size = partition_get_size(index); |
| 2485 | offset = ptn_size - blocksize; |
| 2486 | |
Mayank Grover | 4886040 | 2016-11-29 12:34:53 +0530 | [diff] [blame] | 2487 | /* Set Lun for partition */ |
| 2488 | mmc_set_lun(partition_get_lun(index)); |
| 2489 | |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 2490 | if (mmc_read(ptn + offset, (void *)buf, blocksize)) |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2491 | { |
| 2492 | dprintf(CRITICAL, "Reading MMC failed\n"); |
| 2493 | return -1; |
| 2494 | } |
| 2495 | |
| 2496 | /*is_allow_unlock is a bool value stored at the LSB of last byte*/ |
| 2497 | is_allow_unlock = buf[blocksize-1] & 0x01; |
| 2498 | return 0; |
| 2499 | } |
| 2500 | |
| 2501 | static int write_allow_oem_unlock(bool allow_unlock) |
| 2502 | { |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2503 | unsigned offset; |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2504 | int index; |
| 2505 | unsigned long long ptn; |
| 2506 | unsigned long long ptn_size; |
| 2507 | unsigned blocksize = mmc_get_device_blocksize(); |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 2508 | STACKBUF_DMA_ALIGN(buf, blocksize); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2509 | |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 2510 | index = partition_get_index(frp_ptns[0]); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2511 | if (index == INVALID_PTN) |
| 2512 | { |
vijay kumar | ca2e681 | 2015-07-08 20:28:25 +0530 | [diff] [blame] | 2513 | index = partition_get_index(frp_ptns[1]); |
| 2514 | if (index == INVALID_PTN) |
| 2515 | { |
| 2516 | dprintf(CRITICAL, "Neither '%s' nor '%s' partition found\n", frp_ptns[0],frp_ptns[1]); |
| 2517 | return -1; |
| 2518 | } |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | ptn = partition_get_offset(index); |
| 2522 | ptn_size = partition_get_size(index); |
| 2523 | offset = ptn_size - blocksize; |
Mayank Grover | 4886040 | 2016-11-29 12:34:53 +0530 | [diff] [blame] | 2524 | mmc_set_lun(partition_get_lun(index)); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2525 | |
Channagoud Kadabi | b1fe406 | 2015-08-07 16:08:44 -0700 | [diff] [blame] | 2526 | if (mmc_read(ptn + offset, (void *)buf, blocksize)) |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 2527 | { |
| 2528 | dprintf(CRITICAL, "Reading MMC failed\n"); |
| 2529 | return -1; |
| 2530 | } |
| 2531 | |
| 2532 | /*is_allow_unlock is a bool value stored at the LSB of last byte*/ |
| 2533 | buf[blocksize-1] = allow_unlock; |
| 2534 | if (mmc_write(ptn + offset, blocksize, buf)) |
| 2535 | { |
| 2536 | dprintf(CRITICAL, "Writing MMC failed\n"); |
| 2537 | return -1; |
| 2538 | } |
| 2539 | |
| 2540 | return 0; |
| 2541 | } |
| 2542 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2543 | void read_device_info_flash(device_info *dev) |
| 2544 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2545 | 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] | 2546 | struct ptentry *ptn; |
| 2547 | struct ptable *ptable; |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2548 | if(info == NULL) |
| 2549 | { |
| 2550 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 2551 | ASSERT(0); |
| 2552 | } |
| 2553 | info_buf = info; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2554 | ptable = flash_get_ptable(); |
| 2555 | if (ptable == NULL) |
| 2556 | { |
| 2557 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 2558 | return; |
| 2559 | } |
| 2560 | |
| 2561 | ptn = ptable_find(ptable, "devinfo"); |
| 2562 | if (ptn == NULL) |
| 2563 | { |
Smita Ghosh | 670c8b8 | 2015-05-07 09:30:03 -0700 | [diff] [blame] | 2564 | dprintf(CRITICAL, "ERROR: No devinfo partition found\n"); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2565 | return; |
| 2566 | } |
| 2567 | |
| 2568 | if (flash_read(ptn, 0, (void *)info_buf, page_size)) |
| 2569 | { |
| 2570 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 2571 | return; |
| 2572 | } |
| 2573 | |
| 2574 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 2575 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2576 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
| 2577 | info->is_unlocked = 0; |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2578 | info->is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2579 | write_device_info_flash(info); |
| 2580 | } |
| 2581 | memcpy(dev, info, sizeof(device_info)); |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2582 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | void write_device_info(device_info *dev) |
| 2586 | { |
| 2587 | if(target_is_emmc_boot()) |
| 2588 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2589 | struct device_info *info = memalign(PAGE_SIZE, ROUNDUP(BOOT_IMG_MAX_PAGE_SIZE, PAGE_SIZE)); |
| 2590 | if(info == NULL) |
| 2591 | { |
| 2592 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 2593 | ASSERT(0); |
| 2594 | } |
| 2595 | info_buf = info; |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2596 | memcpy(info, dev, sizeof(struct device_info)); |
| 2597 | |
| 2598 | #if USE_RPMB_FOR_DEVINFO |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 2599 | if (VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 2600 | is_secure_boot_enable()) { |
| 2601 | if((write_device_info_rpmb((void*) info, PAGE_SIZE)) < 0) |
| 2602 | ASSERT(0); |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 2603 | } |
Channagoud Kadabi | c80cb49 | 2015-04-28 16:08:28 -0700 | [diff] [blame] | 2604 | else |
| 2605 | write_device_info_mmc(info); |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2606 | #else |
| 2607 | write_device_info_mmc(info); |
| 2608 | #endif |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2609 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2610 | } |
| 2611 | else |
| 2612 | { |
| 2613 | write_device_info_flash(dev); |
| 2614 | } |
| 2615 | } |
| 2616 | |
Monika Singh | 9431646 | 2018-03-15 18:39:01 +0530 | [diff] [blame] | 2617 | int read_rollback_index(uint32_t loc, uint64_t *roll_back_index) |
| 2618 | { |
| 2619 | if (!devinfo_present) { |
| 2620 | dprintf(CRITICAL, "DeviceInfo not initalized \n"); |
| 2621 | return -EINVAL; |
| 2622 | } |
| 2623 | if (loc >= ARRAY_SIZE(device.rollback_index)) { |
| 2624 | dprintf(CRITICAL, "%s() Loc out of range index: %d, array len: %d\n", |
| 2625 | __func__, loc, ARRAY_SIZE(device.rollback_index)); |
| 2626 | ASSERT(0); |
| 2627 | } |
| 2628 | |
| 2629 | *roll_back_index = device.rollback_index[loc]; |
| 2630 | return 0; |
| 2631 | } |
| 2632 | |
| 2633 | int write_rollback_index(uint32_t loc, uint64_t roll_back_index) |
| 2634 | { |
| 2635 | if (!devinfo_present) { |
| 2636 | dprintf(CRITICAL, "DeviceInfo not initalized \n"); |
| 2637 | return -EINVAL; |
| 2638 | } |
| 2639 | if (loc >= ARRAY_SIZE(device.rollback_index)) { |
| 2640 | dprintf(CRITICAL, "%s() Loc out of range index: %d, array len: %d\n", |
| 2641 | __func__, loc, ARRAY_SIZE(device.rollback_index)); |
| 2642 | ASSERT(0); |
| 2643 | } |
| 2644 | |
| 2645 | device.rollback_index[loc] = roll_back_index; |
| 2646 | write_device_info(&device); |
| 2647 | return 0; |
| 2648 | } |
| 2649 | |
Monika Singh | b0fad82 | 2018-03-15 18:50:55 +0530 | [diff] [blame] | 2650 | int store_userkey(uint8_t *user_key, uint32_t user_key_size) |
| 2651 | { |
| 2652 | if (!devinfo_present) { |
| 2653 | dprintf(CRITICAL, "DeviceInfo not initalized \n"); |
| 2654 | return -EINVAL; |
| 2655 | } |
| 2656 | |
| 2657 | if (user_key_size > ARRAY_SIZE(device.user_public_key)) { |
| 2658 | dprintf(CRITICAL, "StoreUserKey, UserKeySize too large!\n"); |
| 2659 | return -ENODEV; |
| 2660 | } |
| 2661 | |
| 2662 | memcpy(device.user_public_key, user_key, user_key_size); |
| 2663 | device.user_public_key_length = user_key_size; |
| 2664 | write_device_info(&device); |
| 2665 | return 0; |
| 2666 | } |
| 2667 | |
| 2668 | int erase_userkey() |
| 2669 | { |
| 2670 | if (!devinfo_present) { |
| 2671 | dprintf(CRITICAL, "DeviceInfo not initalized \n"); |
| 2672 | return -EINVAL; |
| 2673 | } |
| 2674 | memset(device.user_public_key, 0, ARRAY_SIZE(device.user_public_key)); |
| 2675 | device.user_public_key_length = 0; |
| 2676 | write_device_info(&device); |
| 2677 | return 0; |
| 2678 | } |
| 2679 | |
| 2680 | int get_userkey(uint8_t **user_key, uint32_t *user_key_size) |
| 2681 | { |
| 2682 | if (!devinfo_present) { |
| 2683 | dprintf(CRITICAL, "DeviceInfo not initalized \n"); |
| 2684 | return -EINVAL; |
| 2685 | } |
| 2686 | *user_key = device.user_public_key; |
| 2687 | *user_key_size = device.user_public_key_length; |
| 2688 | return 0; |
| 2689 | } |
| 2690 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2691 | void read_device_info(device_info *dev) |
| 2692 | { |
| 2693 | if(target_is_emmc_boot()) |
| 2694 | { |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2695 | struct device_info *info = memalign(PAGE_SIZE, ROUNDUP(BOOT_IMG_MAX_PAGE_SIZE, PAGE_SIZE)); |
| 2696 | if(info == NULL) |
| 2697 | { |
| 2698 | dprintf(CRITICAL, "Failed to allocate memory for device info struct\n"); |
| 2699 | ASSERT(0); |
| 2700 | } |
| 2701 | info_buf = info; |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2702 | |
| 2703 | #if USE_RPMB_FOR_DEVINFO |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 2704 | if (VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 2705 | is_secure_boot_enable()) { |
| 2706 | if((read_device_info_rpmb((void*) info, PAGE_SIZE)) < 0) |
| 2707 | ASSERT(0); |
Sridhar Parasuram | e1a9792 | 2015-07-27 15:31:22 -0700 | [diff] [blame] | 2708 | } |
Channagoud Kadabi | c80cb49 | 2015-04-28 16:08:28 -0700 | [diff] [blame] | 2709 | else |
| 2710 | read_device_info_mmc(info); |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2711 | #else |
| 2712 | read_device_info_mmc(info); |
| 2713 | #endif |
| 2714 | |
| 2715 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 2716 | { |
| 2717 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 2718 | if (is_secure_boot_enable()) { |
Channagoud Kadabi | 05f78ba | 2015-07-06 11:58:14 -0700 | [diff] [blame] | 2719 | info->is_unlocked = 0; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2720 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 2721 | if (VB_M <= target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 2722 | info->is_unlock_critical = 0; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2723 | #endif |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 2724 | } else { |
Channagoud Kadabi | 2fda409 | 2015-07-07 13:34:11 -0700 | [diff] [blame] | 2725 | info->is_unlocked = 1; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2726 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 2727 | if (VB_M <= target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 2728 | info->is_unlock_critical = 1; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2729 | #endif |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 2730 | } |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2731 | info->is_tampered = 0; |
| 2732 | info->charger_screen_enabled = 0; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2733 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 2734 | if (VB_M <= target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 2735 | info->verity_mode = 1; //enforcing by default |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2736 | #endif |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 2737 | write_device_info(info); |
| 2738 | } |
| 2739 | memcpy(dev, info, sizeof(device_info)); |
Sridhar Parasuram | 7e16d17 | 2015-07-05 11:35:23 -0700 | [diff] [blame] | 2740 | free(info); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2741 | } |
| 2742 | else |
| 2743 | { |
| 2744 | read_device_info_flash(dev); |
| 2745 | } |
| 2746 | } |
| 2747 | |
| 2748 | void reset_device_info() |
| 2749 | { |
| 2750 | dprintf(ALWAYS, "reset_device_info called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2751 | device.is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2752 | write_device_info(&device); |
| 2753 | } |
| 2754 | |
| 2755 | void set_device_root() |
| 2756 | { |
| 2757 | dprintf(ALWAYS, "set_device_root called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2758 | device.is_tampered = 1; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2759 | write_device_info(&device); |
| 2760 | } |
| 2761 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2762 | /* set device unlock value |
| 2763 | * Must check FRP before call this function |
| 2764 | * Need to wipe data when unlock status changed |
| 2765 | * type 0: oem unlock |
| 2766 | * type 1: unlock critical |
| 2767 | * status 0: unlock as false |
| 2768 | * status 1: lock as true |
| 2769 | */ |
| 2770 | void set_device_unlock_value(int type, bool status) |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2771 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2772 | if (type == UNLOCK) |
| 2773 | device.is_unlocked = status; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2774 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 2775 | else if (VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 2776 | type == UNLOCK_CRITICAL) |
| 2777 | device.is_unlock_critical = status; |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2778 | #endif |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2779 | write_device_info(&device); |
| 2780 | } |
| 2781 | |
| 2782 | static void set_device_unlock(int type, bool status) |
| 2783 | { |
| 2784 | int is_unlocked = -1; |
| 2785 | char response[MAX_RSP_SIZE]; |
| 2786 | |
| 2787 | /* check device unlock status if it is as expected */ |
| 2788 | if (type == UNLOCK) |
| 2789 | is_unlocked = device.is_unlocked; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2790 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 2791 | if(VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 2792 | type == UNLOCK_CRITICAL) |
| 2793 | { |
| 2794 | is_unlocked = device.is_unlock_critical; |
| 2795 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 2796 | #endif |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2797 | if (is_unlocked == status) { |
| 2798 | snprintf(response, sizeof(response), "\tDevice already : %s", (status ? "unlocked!" : "locked!")); |
| 2799 | fastboot_info(response); |
| 2800 | fastboot_okay(""); |
| 2801 | return; |
| 2802 | } |
| 2803 | |
| 2804 | /* status is true, it means to unlock device */ |
lijuang | 07c5d6e | 2018-04-23 18:32:13 +0800 | [diff] [blame] | 2805 | if (status && !is_allow_unlock) { |
| 2806 | fastboot_fail("oem unlock is not allowed"); |
| 2807 | return; |
| 2808 | } |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2809 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2810 | #if FBCON_DISPLAY_MSG |
lijuang | 07c5d6e | 2018-04-23 18:32:13 +0800 | [diff] [blame] | 2811 | display_unlock_menu(type, status); |
| 2812 | fastboot_okay(""); |
| 2813 | return; |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2814 | #else |
lijuang | 07c5d6e | 2018-04-23 18:32:13 +0800 | [diff] [blame] | 2815 | if (status && type == UNLOCK) { |
| 2816 | fastboot_fail("Need wipe userdata. Do 'fastboot oem unlock-go'"); |
| 2817 | return; |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2818 | } |
lijuang | 07c5d6e | 2018-04-23 18:32:13 +0800 | [diff] [blame] | 2819 | #endif |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2820 | |
| 2821 | set_device_unlock_value(type, status); |
| 2822 | |
| 2823 | /* wipe data */ |
| 2824 | struct recovery_message msg; |
Kishor PK | 60a6821 | 2017-05-08 16:55:57 +0530 | [diff] [blame] | 2825 | memset(&msg, 0, sizeof(msg)); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 2826 | snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data"); |
| 2827 | write_misc(0, &msg, sizeof(msg)); |
| 2828 | |
| 2829 | fastboot_okay(""); |
| 2830 | reboot_device(RECOVERY_MODE); |
lijuang | 21f12f5 | 2015-08-22 16:22:19 +0800 | [diff] [blame] | 2831 | } |
| 2832 | |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 2833 | static bool critical_flash_allowed(const char * entry) |
| 2834 | { |
| 2835 | uint32_t i = 0; |
| 2836 | if (entry == NULL) |
| 2837 | return false; |
| 2838 | |
| 2839 | for (i = 0; i < ARRAY_SIZE(critical_flash_allowed_ptn); i++) { |
| 2840 | if(!strcmp(entry, critical_flash_allowed_ptn[i])) |
| 2841 | return true; |
| 2842 | } |
| 2843 | return false; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | #if DEVICE_TREE |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2847 | int copy_dtb(uint8_t *boot_image_start, unsigned int scratch_offset) |
| 2848 | { |
| 2849 | uint32 dt_image_offset = 0; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2850 | uint32_t n; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2851 | struct dt_table *table = NULL; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2852 | struct dt_entry dt_entry; |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2853 | uint32_t dt_hdr_size = 0; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2854 | unsigned int compressed_size = 0; |
| 2855 | unsigned int dtb_size = 0; |
| 2856 | unsigned int out_avai_len = 0; |
| 2857 | unsigned char *out_addr = NULL; |
| 2858 | unsigned char *best_match_dt_addr = NULL; |
| 2859 | int rc; |
| 2860 | |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 2861 | boot_img_hdr *hdr = (boot_img_hdr *) (boot_image_start); |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2862 | |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 2863 | #ifndef OSVERSION_IN_BOOTIMAGE |
| 2864 | dt_size = hdr->dt_size; |
| 2865 | #endif |
| 2866 | |
| 2867 | if(dt_size != 0) { |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2868 | /* add kernel offset */ |
| 2869 | dt_image_offset += page_size; |
| 2870 | n = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 2871 | dt_image_offset += n; |
| 2872 | |
| 2873 | /* add ramdisk offset */ |
| 2874 | n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 2875 | dt_image_offset += n; |
| 2876 | |
| 2877 | /* add second offset */ |
| 2878 | if(hdr->second_size != 0) { |
| 2879 | n = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 2880 | dt_image_offset += n; |
| 2881 | } |
| 2882 | |
| 2883 | /* offset now point to start of dt.img */ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 2884 | table = (struct dt_table*)(boot_image_start + dt_image_offset); |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2885 | |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 2886 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2887 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 2888 | return -1; |
| 2889 | } |
P.V. Phani Kumar | 8291676 | 2016-03-09 09:20:19 +0530 | [diff] [blame] | 2890 | |
| 2891 | /* Its Error if, dt_hdr_size (table->num_entries * dt_entry size + Dev_Tree Header) |
| 2892 | goes beyound hdr->dt_size*/ |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 2893 | 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] | 2894 | dprintf(CRITICAL, "ERROR: Invalid Device Tree size \n"); |
| 2895 | return -1; |
| 2896 | } |
| 2897 | |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 2898 | /* Find index of device tree within device tree table */ |
| 2899 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2900 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 2901 | return -1; |
| 2902 | } |
| 2903 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2904 | best_match_dt_addr = (unsigned char *)boot_image_start + dt_image_offset + dt_entry.offset; |
| 2905 | if (is_gzip_package(best_match_dt_addr, dt_entry.size)) |
| 2906 | { |
| 2907 | out_addr = (unsigned char *)target_get_scratch_address() + scratch_offset; |
| 2908 | out_avai_len = target_get_max_flash_size() - scratch_offset; |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2909 | dprintf(INFO, "decompressing dtb: start\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2910 | rc = decompress(best_match_dt_addr, |
| 2911 | dt_entry.size, out_addr, out_avai_len, |
| 2912 | &compressed_size, &dtb_size); |
| 2913 | if (rc) |
| 2914 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2915 | dprintf(CRITICAL, "decompressing dtb failed!!!\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2916 | ASSERT(0); |
| 2917 | } |
| 2918 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 2919 | dprintf(INFO, "decompressing dtb: done\n"); |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2920 | best_match_dt_addr = out_addr; |
| 2921 | } else { |
| 2922 | dtb_size = dt_entry.size; |
| 2923 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2924 | /* Validate and Read device device tree in the "tags_add */ |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2925 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dtb_size) || |
| 2926 | check_ddr_addr_range_bound(hdr->tags_addr, dtb_size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2927 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 2928 | dprintf(CRITICAL, "Device tree addresses are not valid.\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2929 | return -1; |
| 2930 | } |
| 2931 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2932 | /* Read device device tree in the "tags_add */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2933 | memmove((void*) hdr->tags_addr, (void *)best_match_dt_addr, dtb_size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2934 | } else |
| 2935 | return -1; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 2936 | |
| 2937 | /* Everything looks fine. Return success. */ |
| 2938 | return 0; |
| 2939 | } |
| 2940 | #endif |
| 2941 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2942 | void cmd_boot(const char *arg, void *data, unsigned sz) |
| 2943 | { |
| 2944 | unsigned kernel_actual; |
| 2945 | unsigned ramdisk_actual; |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 2946 | unsigned second_actual; |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 2947 | uint32_t image_actual; |
| 2948 | uint32_t dt_actual = 0; |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 2949 | boot_img_hdr *hdr = NULL; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2950 | struct kernel64_hdr *kptr = NULL; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2951 | char *ptr = ((char*) data); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 2952 | int ret = 0; |
| 2953 | uint8_t dtb_copied = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2954 | unsigned int out_len = 0; |
| 2955 | unsigned int out_avai_len = 0; |
| 2956 | unsigned char *out_addr = NULL; |
| 2957 | uint32_t dtb_offset = 0; |
| 2958 | unsigned char *kernel_start_addr = NULL; |
| 2959 | unsigned int kernel_size = 0; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 2960 | unsigned int scratch_offset = 0; |
Saranya Chidura | b493333 | 2018-10-15 17:30:06 +0530 | [diff] [blame] | 2961 | #if VERIFIED_BOOT_2 |
| 2962 | void *dtbo_image_buf = NULL; |
| 2963 | uint32_t dtbo_image_sz = 0; |
| 2964 | void *vbmeta_image_buf = NULL; |
| 2965 | uint32_t vbmeta_image_sz = 0; |
| 2966 | #endif |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2967 | #if !VERIFIED_BOOT_2 |
| 2968 | uint32_t sig_actual = 0; |
| 2969 | uint32_t sig_size = 0; |
| 2970 | #ifdef MDTP_SUPPORT |
| 2971 | static bool is_mdtp_activated = 0; |
| 2972 | #endif /* MDTP_SUPPORT */ |
| 2973 | #endif |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 2974 | |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2975 | #if FBCON_DISPLAY_MSG |
| 2976 | /* Exit keys' detection thread firstly */ |
| 2977 | exit_menu_keys_detection(); |
| 2978 | #endif |
| 2979 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 2980 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Channagoud Kadabi | 6d5375e | 2015-06-23 17:15:42 -0700 | [diff] [blame] | 2981 | if(target_build_variant_user() && !device.is_unlocked) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2982 | { |
| 2983 | fastboot_fail("unlock device to use this command"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2984 | goto boot_failed; |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2985 | } |
| 2986 | #endif |
| 2987 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2988 | if (sz < sizeof(hdr)) { |
| 2989 | fastboot_fail("invalid bootimage header"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 2990 | goto boot_failed; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2991 | } |
| 2992 | |
Mayank Grover | e1ab96c | 2018-09-04 20:31:31 +0530 | [diff] [blame] | 2993 | hdr = (boot_img_hdr *)data; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2994 | |
| 2995 | /* ensure commandline is terminated */ |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2996 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2997 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 2998 | if(target_is_emmc_boot() && hdr->page_size) { |
| 2999 | page_size = hdr->page_size; |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 3000 | page_mask = page_size - 1; |
| 3001 | } |
| 3002 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 3003 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 3004 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 3005 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 3006 | #if DEVICE_TREE |
Parth Dixit | 4097b62 | 2016-03-15 14:42:27 +0530 | [diff] [blame] | 3007 | #ifndef OSVERSION_IN_BOOTIMAGE |
| 3008 | dt_size = hdr->dt_size; |
| 3009 | #endif |
| 3010 | dt_actual = ROUND_TO_PAGE(dt_size, page_mask); |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 3011 | #endif |
| 3012 | |
| 3013 | image_actual = ADD_OF(page_size, kernel_actual); |
| 3014 | image_actual = ADD_OF(image_actual, ramdisk_actual); |
Kishor PK | d8ddcad | 2017-07-27 13:53:57 +0530 | [diff] [blame] | 3015 | image_actual = ADD_OF(image_actual, second_actual); |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 3016 | image_actual = ADD_OF(image_actual, dt_actual); |
| 3017 | |
Kishor PK | 5134b33 | 2017-05-09 17:50:08 +0530 | [diff] [blame] | 3018 | /* Checking to prevent oob access in read_der_message_length */ |
| 3019 | if (image_actual > sz) { |
| 3020 | fastboot_fail("bootimage header fields are invalid"); |
| 3021 | goto boot_failed; |
| 3022 | } |
Saranya Chidura | b493333 | 2018-10-15 17:30:06 +0530 | [diff] [blame] | 3023 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3024 | #if VERIFIED_BOOT_2 |
Mayank Grover | 1ceaee2 | 2019-04-01 17:54:32 +0530 | [diff] [blame] | 3025 | /* Pass size of boot partition, as imgsize, to avoid |
| 3026 | read fewer bytes error */ |
| 3027 | image_actual = partition_get_size(partition_get_index("boot")); |
Saranya Chidura | b493333 | 2018-10-15 17:30:06 +0530 | [diff] [blame] | 3028 | |
| 3029 | /* load and validate dtbo partition */ |
| 3030 | load_validate_dtbo_image(&dtbo_image_buf, &dtbo_image_sz); |
| 3031 | |
| 3032 | /* load vbmeta partition */ |
| 3033 | load_vbmeta_image(&vbmeta_image_buf, &vbmeta_image_sz); |
| 3034 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3035 | memset(&info, 0, sizeof(bootinfo)); |
Saranya Chidura | b493333 | 2018-10-15 17:30:06 +0530 | [diff] [blame] | 3036 | |
| 3037 | info.images[IMG_BOOT].image_buffer = SUB_SALT_BUFF_OFFSET(data); |
| 3038 | info.images[IMG_BOOT].imgsize = image_actual; |
| 3039 | info.images[IMG_BOOT].name = "boot"; |
| 3040 | ++info.num_loaded_images; |
| 3041 | |
| 3042 | /* Pass loaded dtbo image */ |
| 3043 | if (dtbo_image_buf != NULL) { |
| 3044 | info.images[IMG_DTBO].image_buffer = SUB_SALT_BUFF_OFFSET(dtbo_image_buf); |
| 3045 | info.images[IMG_DTBO].imgsize = dtbo_image_sz; |
| 3046 | info.images[IMG_DTBO].name = "dtbo"; |
| 3047 | ++info.num_loaded_images; |
| 3048 | } |
| 3049 | |
| 3050 | /* Pass loaded vbmeta image */ |
| 3051 | if (vbmeta_image_buf != NULL) { |
| 3052 | info.images[IMG_VBMETA].image_buffer = vbmeta_image_buf; |
| 3053 | info.images[IMG_VBMETA].imgsize = vbmeta_image_sz; |
| 3054 | info.images[IMG_VBMETA].name = "vbmeta"; |
| 3055 | ++info.num_loaded_images; |
| 3056 | } |
| 3057 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3058 | info.multi_slot_boot = partition_multislot_is_supported(); |
| 3059 | if (load_image_and_auth(&info)) |
| 3060 | goto boot_failed; |
| 3061 | vbcmdline = info.vbcmdline; |
Saranya Chidura | b493333 | 2018-10-15 17:30:06 +0530 | [diff] [blame] | 3062 | |
| 3063 | /* Free the buffer allocated to vbmeta post verification */ |
| 3064 | if (vbmeta_image_buf != NULL) { |
| 3065 | free(vbmeta_image_buf); |
| 3066 | --info.num_loaded_images; |
| 3067 | } |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3068 | #else |
Kishor PK | 5134b33 | 2017-05-09 17:50:08 +0530 | [diff] [blame] | 3069 | sig_size = sz - image_actual; |
| 3070 | |
P.V. Phani Kumar | eecfd82 | 2016-03-09 20:09:03 +0530 | [diff] [blame] | 3071 | if (target_use_signed_kernel() && (!device.is_unlocked)) { |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3072 | unsigned chk; |
P.V. Phani Kumar | eecfd82 | 2016-03-09 20:09:03 +0530 | [diff] [blame] | 3073 | /* Calculate the signature length from boot image */ |
| 3074 | sig_actual = read_der_message_length( |
Kishor PK | 5134b33 | 2017-05-09 17:50:08 +0530 | [diff] [blame] | 3075 | (unsigned char*)(data + image_actual), sig_size); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3076 | chk = ADD_OF(image_actual, sig_actual); |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 3077 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3078 | if (chk > sz) { |
Kishor PK | 5134b33 | 2017-05-09 17:50:08 +0530 | [diff] [blame] | 3079 | fastboot_fail("bootimage header fields are invalid"); |
| 3080 | goto boot_failed; |
| 3081 | } |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 3082 | } |
| 3083 | |
Sridhar Parasuram | 361e4cd | 2015-09-24 11:19:19 -0700 | [diff] [blame] | 3084 | // Initialize boot state before trying to verify boot.img |
| 3085 | #if VERIFIED_BOOT |
Channagoud Kadabi | 699466e | 2015-11-03 12:37:42 -0800 | [diff] [blame] | 3086 | boot_verifier_init(); |
Mayank Grover | b337e93 | 2017-01-18 20:00:40 +0530 | [diff] [blame] | 3087 | #endif |
Channagoud Kadabi | bf6ce7d | 2015-09-17 13:25:35 -0700 | [diff] [blame] | 3088 | /* Handle overflow if the input image size is greater than |
| 3089 | * boot image buffer can hold |
| 3090 | */ |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3091 | if ((target_get_max_flash_size() - page_size) < image_actual) |
Channagoud Kadabi | bf6ce7d | 2015-09-17 13:25:35 -0700 | [diff] [blame] | 3092 | { |
| 3093 | fastboot_fail("booimage: size is greater than boot image buffer can hold"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 3094 | goto boot_failed; |
Channagoud Kadabi | bf6ce7d | 2015-09-17 13:25:35 -0700 | [diff] [blame] | 3095 | } |
Sridhar Parasuram | 361e4cd | 2015-09-24 11:19:19 -0700 | [diff] [blame] | 3096 | |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 3097 | /* Verify the boot image |
| 3098 | * device & page_size are initialized in aboot_init |
| 3099 | */ |
Sridhar Parasuram | 7ae9fbc | 2015-09-17 09:56:30 -0700 | [diff] [blame] | 3100 | if (target_use_signed_kernel() && (!device.is_unlocked)) { |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 3101 | /* Pass size excluding signature size, otherwise we would try to |
| 3102 | * access signature beyond its length |
| 3103 | */ |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3104 | verify_signed_bootimg((uint32_t)data, image_actual); |
Sridhar Parasuram | 7ae9fbc | 2015-09-17 09:56:30 -0700 | [diff] [blame] | 3105 | } |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 3106 | #ifdef MDTP_SUPPORT |
| 3107 | else |
| 3108 | { |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 3109 | /* fastboot boot is not allowed when MDTP is activated */ |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 3110 | mdtp_ext_partition_verification_t ext_partition; |
Amit Blay | 8a51030 | 2015-08-17 09:20:01 +0300 | [diff] [blame] | 3111 | |
| 3112 | if (!is_mdtp_activated) { |
| 3113 | ext_partition.partition = MDTP_PARTITION_NONE; |
| 3114 | mdtp_fwlock_verify_lock(&ext_partition); |
| 3115 | } |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 3116 | } |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 3117 | |
Amir Kotzer | 7c768c0 | 2016-04-13 09:08:05 +0300 | [diff] [blame] | 3118 | /* If mdtp state cannot be validate, block fastboot boot*/ |
| 3119 | if(mdtp_activated(&is_mdtp_activated)){ |
| 3120 | dprintf(CRITICAL, "mdtp_activated cannot validate state.\n"); |
| 3121 | dprintf(CRITICAL, "Can not proceed with fastboot boot command.\n"); |
| 3122 | goto boot_failed; |
| 3123 | } |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 3124 | if(is_mdtp_activated){ |
| 3125 | dprintf(CRITICAL, "fastboot boot command is not available.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 3126 | goto boot_failed; |
Shay Nachmani | 062aa3f | 2015-05-17 17:28:44 +0300 | [diff] [blame] | 3127 | } |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 3128 | #endif /* MDTP_SUPPORT */ |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3129 | #endif /* VERIFIED_BOOT_2 else */ |
Amit Blay | 4aa292f | 2015-04-28 21:55:59 +0300 | [diff] [blame] | 3130 | |
Sridhar Parasuram | 361e4cd | 2015-09-24 11:19:19 -0700 | [diff] [blame] | 3131 | #if VERIFIED_BOOT |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3132 | if (VB_M == target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 3133 | { |
| 3134 | /* set boot and system versions. */ |
| 3135 | set_os_version((unsigned char *)data); |
| 3136 | // send root of trust |
| 3137 | if(!send_rot_command((uint32_t)device.is_unlocked)) |
| 3138 | ASSERT(0); |
| 3139 | } |
Parth Dixit | bc9b649 | 2015-10-18 00:41:38 +0530 | [diff] [blame] | 3140 | #endif |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 3141 | /* |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3142 | * Check if the kernel image is a gzip package. If yes, need to decompress it. |
| 3143 | * If not, continue booting. |
| 3144 | */ |
| 3145 | if (is_gzip_package((unsigned char *)(data + page_size), hdr->kernel_size)) |
| 3146 | { |
| 3147 | out_addr = (unsigned char *)target_get_scratch_address(); |
| 3148 | out_addr = (unsigned char *)(out_addr + image_actual + page_size); |
| 3149 | out_avai_len = target_get_max_flash_size() - image_actual - page_size; |
Saranya Chidura | b493333 | 2018-10-15 17:30:06 +0530 | [diff] [blame] | 3150 | #if VERIFIED_BOOT_2 |
| 3151 | if (dtbo_image_sz) |
| 3152 | out_avai_len -= DTBO_IMG_BUF; |
| 3153 | #endif |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 3154 | dprintf(INFO, "decompressing kernel image: start\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3155 | ret = decompress((unsigned char *)(ptr + page_size), |
| 3156 | hdr->kernel_size, out_addr, out_avai_len, |
| 3157 | &dtb_offset, &out_len); |
| 3158 | if (ret) |
| 3159 | { |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 3160 | dprintf(CRITICAL, "decompressing image failed!!!\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3161 | ASSERT(0); |
| 3162 | } |
| 3163 | |
Matthew Qin | 0b15b32 | 2015-05-19 05:20:54 -0400 | [diff] [blame] | 3164 | dprintf(INFO, "decompressing kernel image: done\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3165 | kptr = (struct kernel64_hdr *)out_addr; |
| 3166 | kernel_start_addr = out_addr; |
| 3167 | kernel_size = out_len; |
| 3168 | } else { |
| 3169 | kptr = (struct kernel64_hdr*)((char *)data + page_size); |
| 3170 | kernel_start_addr = (unsigned char *)((char *)data + page_size); |
| 3171 | kernel_size = hdr->kernel_size; |
| 3172 | } |
| 3173 | |
| 3174 | /* |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 3175 | * Update the kernel/ramdisk/tags address if the boot image header |
| 3176 | * has default values, these default values come from mkbootimg when |
| 3177 | * the boot image is flashed using fastboot flash:raw |
| 3178 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 3179 | update_ker_tags_rdisk_addr(hdr, IS_ARM64(kptr)); |
Dima Zavin | 3cadfff | 2013-03-21 14:30:48 -0700 | [diff] [blame] | 3180 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 3181 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 3182 | hdr->kernel_addr = VA(hdr->kernel_addr); |
| 3183 | hdr->ramdisk_addr = VA(hdr->ramdisk_addr); |
| 3184 | hdr->tags_addr = VA(hdr->tags_addr); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3185 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3186 | kernel_size = ROUND_TO_PAGE(kernel_size, page_mask); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 3187 | /* Check if the addresses in the header are valid. */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3188 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_size) || |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 3189 | check_ddr_addr_range_bound(hdr->kernel_addr, kernel_size) || |
| 3190 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual) || |
| 3191 | check_ddr_addr_range_bound(hdr->ramdisk_addr, ramdisk_actual)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 3192 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 3193 | dprintf(CRITICAL, "kernel/ramdisk addresses are not valid.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 3194 | goto boot_failed; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 3195 | } |
| 3196 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 3197 | #if DEVICE_TREE |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 3198 | scratch_offset = image_actual + page_size + out_len; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 3199 | /* find correct dtb and copy it to right location */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 3200 | ret = copy_dtb(data, scratch_offset); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 3201 | |
| 3202 | dtb_copied = !ret ? 1 : 0; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 3203 | #else |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 3204 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE) || |
| 3205 | check_ddr_addr_range_bound(hdr->tags_addr, MAX_TAGS_SIZE)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 3206 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 3207 | dprintf(CRITICAL, "Tags addresses are not valid.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 3208 | goto boot_failed; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 3209 | } |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 3210 | #endif |
| 3211 | |
| 3212 | /* Load ramdisk & kernel */ |
| 3213 | 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] | 3214 | memmove((void*) hdr->kernel_addr, (char*) (kernel_start_addr), kernel_size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 3215 | |
| 3216 | #if DEVICE_TREE |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 3217 | if (check_aboot_addr_range_overlap(hdr->tags_addr, kernel_actual) || |
| 3218 | check_ddr_addr_range_bound(hdr->tags_addr, kernel_actual)) |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3219 | { |
Mayank Grover | e559cec | 2017-10-17 15:12:03 +0530 | [diff] [blame] | 3220 | dprintf(CRITICAL, "Tags addresses are not valid.\n"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 3221 | goto boot_failed; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3222 | } |
| 3223 | |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 3224 | /* |
| 3225 | * If dtb is not found look for appended DTB in the kernel. |
| 3226 | * If appended dev tree is found, update the atags with |
| 3227 | * memory address to the DTB appended location on RAM. |
| 3228 | * Else update with the atags address in the kernel header |
| 3229 | */ |
| 3230 | if (!dtb_copied) { |
| 3231 | void *dtb; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 3232 | dtb = dev_tree_appended((void*)(ptr + page_size), |
| 3233 | hdr->kernel_size, dtb_offset, |
Dima Zavin | e63e557 | 2013-05-03 12:23:06 -0700 | [diff] [blame] | 3234 | (void *)hdr->tags_addr); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 3235 | if (!dtb) { |
| 3236 | fastboot_fail("dtb not found"); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 3237 | goto boot_failed; |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 3238 | } |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 3239 | } |
| 3240 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3241 | |
| 3242 | fastboot_okay(""); |
Amol Jadi | 7c4316c | 2013-10-07 14:19:26 -0700 | [diff] [blame] | 3243 | fastboot_stop(); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3244 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 3245 | boot_linux((void*) hdr->kernel_addr, (void*) hdr->tags_addr, |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 3246 | (const char*) hdr->cmdline, board_machtype(), |
| 3247 | (void*) hdr->ramdisk_addr, hdr->ramdisk_size); |
lijuang | 2008ff2 | 2016-03-07 17:56:27 +0800 | [diff] [blame] | 3248 | |
| 3249 | /* fastboot already stop, it's no need to show fastboot menu */ |
| 3250 | return; |
| 3251 | boot_failed: |
| 3252 | #if FBCON_DISPLAY_MSG |
| 3253 | /* revert to fastboot menu if boot failed */ |
| 3254 | display_fastboot_menu(); |
| 3255 | #endif |
| 3256 | return; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3257 | } |
| 3258 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3259 | void cmd_erase_nand(const char *arg, void *data, unsigned sz) |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3260 | { |
| 3261 | struct ptentry *ptn; |
| 3262 | struct ptable *ptable; |
| 3263 | |
| 3264 | ptable = flash_get_ptable(); |
| 3265 | if (ptable == NULL) { |
| 3266 | fastboot_fail("partition table doesn't exist"); |
| 3267 | return; |
| 3268 | } |
| 3269 | |
| 3270 | ptn = ptable_find(ptable, arg); |
| 3271 | if (ptn == NULL) { |
| 3272 | fastboot_fail("unknown partition name"); |
| 3273 | return; |
| 3274 | } |
| 3275 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3276 | if (!strncmp(arg, "avb_custom_key", strlen("avb_custom_key"))) { |
| 3277 | dprintf(INFO, "erasing avb_custom_key\n"); |
| 3278 | if (erase_userkey()) { |
| 3279 | fastboot_fail("Erasing avb_custom_key failed"); |
| 3280 | } else { |
| 3281 | fastboot_okay(""); |
| 3282 | } |
| 3283 | return; |
| 3284 | } |
| 3285 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 3286 | if (flash_erase(ptn)) { |
| 3287 | fastboot_fail("failed to erase partition"); |
| 3288 | return; |
| 3289 | } |
| 3290 | fastboot_okay(""); |
| 3291 | } |
| 3292 | |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 3293 | |
| 3294 | void cmd_erase_mmc(const char *arg, void *data, unsigned sz) |
| 3295 | { |
| 3296 | unsigned long long ptn = 0; |
Oliver Wang | cee448d | 2013-10-22 18:40:13 +0800 | [diff] [blame] | 3297 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3298 | int index = INVALID_PTN; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3299 | uint8_t lun = 0; |
Vijay Kumar Pendoti | 0b21f46 | 2016-05-02 17:09:18 +0530 | [diff] [blame] | 3300 | char *footer = NULL; |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 3301 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3302 | #if VERIFIED_BOOT |
| 3303 | if(!strcmp(arg, KEYSTORE_PTN_NAME)) |
| 3304 | { |
| 3305 | if(!device.is_unlocked) |
| 3306 | { |
| 3307 | fastboot_fail("unlock device to erase keystore"); |
| 3308 | return; |
| 3309 | } |
| 3310 | } |
| 3311 | #endif |
| 3312 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3313 | index = partition_get_index(arg); |
| 3314 | ptn = partition_get_offset(index); |
Oliver Wang | cee448d | 2013-10-22 18:40:13 +0800 | [diff] [blame] | 3315 | size = partition_get_size(index); |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 3316 | |
Monika Singh | c4778b7 | 2018-05-16 11:16:42 +0530 | [diff] [blame] | 3317 | if (!strncmp(arg, "avb_custom_key", strlen("avb_custom_key"))) { |
| 3318 | dprintf(INFO, "erasing avb_custom_key\n"); |
| 3319 | if (erase_userkey()) { |
| 3320 | fastboot_fail("Erasing avb_custom_key failed"); |
| 3321 | } else { |
| 3322 | fastboot_okay(""); |
| 3323 | } |
| 3324 | return; |
| 3325 | } |
| 3326 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3327 | if(ptn == 0) { |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 3328 | fastboot_fail("Partition table doesn't exist\n"); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 3329 | return; |
| 3330 | } |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 3331 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3332 | lun = partition_get_lun(index); |
| 3333 | mmc_set_lun(lun); |
| 3334 | |
Sridhar Parasuram | d795712 | 2015-02-27 11:33:40 -0800 | [diff] [blame] | 3335 | if (platform_boot_dev_isemmc()) |
| 3336 | { |
| 3337 | if (mmc_erase_card(ptn, size)) { |
| 3338 | fastboot_fail("failed to erase partition\n"); |
| 3339 | return; |
| 3340 | } |
| 3341 | } else { |
| 3342 | BUF_DMA_ALIGN(out, DEFAULT_ERASE_SIZE); |
| 3343 | size = partition_get_size(index); |
| 3344 | if (size > DEFAULT_ERASE_SIZE) |
| 3345 | size = DEFAULT_ERASE_SIZE; |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 3346 | |
Sridhar Parasuram | d795712 | 2015-02-27 11:33:40 -0800 | [diff] [blame] | 3347 | /* Simple inefficient version of erase. Just writing |
| 3348 | 0 in first several blocks */ |
| 3349 | if (mmc_write(ptn , size, (unsigned int *)out)) { |
| 3350 | fastboot_fail("failed to erase partition"); |
| 3351 | return; |
| 3352 | } |
Vijay Kumar Pendoti | 0b21f46 | 2016-05-02 17:09:18 +0530 | [diff] [blame] | 3353 | /*Erase FDE metadata at the userdata footer*/ |
| 3354 | if(!(strncmp(arg, "userdata", 8))) |
| 3355 | { |
| 3356 | footer = memalign(CACHE_LINE, FOOTER_SIZE); |
| 3357 | memset((void *)footer, 0, FOOTER_SIZE); |
| 3358 | |
| 3359 | size = partition_get_size(index); |
| 3360 | |
| 3361 | if (mmc_write((ptn + size) - FOOTER_SIZE , FOOTER_SIZE, (unsigned int *)footer)) { |
| 3362 | fastboot_fail("failed to erase userdata footer"); |
| 3363 | free(footer); |
| 3364 | return; |
| 3365 | } |
| 3366 | free(footer); |
| 3367 | } |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 3368 | } |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3369 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 3370 | if (VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 3371 | !(strncmp(arg, "userdata", 8)) && |
| 3372 | send_delete_keys_to_tz()) |
Sridhar Parasuram | 32b3066 | 2015-07-10 13:33:22 -0700 | [diff] [blame] | 3373 | ASSERT(0); |
| 3374 | #endif |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 3375 | fastboot_okay(""); |
| 3376 | } |
| 3377 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3378 | void cmd_erase(const char *arg, void *data, unsigned sz) |
| 3379 | { |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3380 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Channagoud Kadabi | 3529767 | 2015-06-13 11:09:49 -0700 | [diff] [blame] | 3381 | if (target_build_variant_user()) |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 3382 | { |
Sridhar Parasuram | c32d07d | 2015-07-12 10:57:48 -0700 | [diff] [blame] | 3383 | if(!device.is_unlocked) |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 3384 | { |
Channagoud Kadabi | 3529767 | 2015-06-13 11:09:49 -0700 | [diff] [blame] | 3385 | fastboot_fail("device is locked. Cannot erase"); |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 3386 | return; |
| 3387 | } |
| 3388 | } |
| 3389 | #endif |
| 3390 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 3391 | if(target_is_emmc_boot()) |
| 3392 | cmd_erase_mmc(arg, data, sz); |
| 3393 | else |
| 3394 | cmd_erase_nand(arg, data, sz); |
| 3395 | } |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 3396 | |
Mayank Grover | 11ff969 | 2018-01-11 11:54:49 +0530 | [diff] [blame] | 3397 | /* Get the size from partiton name */ |
| 3398 | static void get_partition_size(const char *arg, char *response) |
| 3399 | { |
| 3400 | uint64_t ptn = 0; |
| 3401 | uint64_t size; |
| 3402 | int index = INVALID_PTN; |
| 3403 | |
| 3404 | index = partition_get_index(arg); |
| 3405 | |
| 3406 | if (index == INVALID_PTN) |
| 3407 | { |
| 3408 | dprintf(CRITICAL, "Invalid partition index\n"); |
| 3409 | return; |
| 3410 | } |
| 3411 | |
| 3412 | ptn = partition_get_offset(index); |
| 3413 | |
| 3414 | if(!ptn) |
| 3415 | { |
| 3416 | dprintf(CRITICAL, "Invalid partition name %s\n", arg); |
| 3417 | return; |
| 3418 | } |
| 3419 | |
| 3420 | size = partition_get_size(index); |
| 3421 | |
| 3422 | snprintf(response, MAX_RSP_SIZE, "\t 0x%llx", size); |
| 3423 | return; |
| 3424 | } |
| 3425 | |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3426 | /* Function to check partition type of a partition*/ |
| 3427 | static fs_signature_type |
| 3428 | check_partition_fs_signature(const char *arg) |
| 3429 | { |
| 3430 | fs_signature_type ret = NO_FS; |
| 3431 | int index; |
| 3432 | unsigned long long ptn; |
Mayank Grover | 399826a | 2018-08-27 12:15:15 +0530 | [diff] [blame] | 3433 | char *buffer = memalign(CACHE_LINE, mmc_blocksize); |
| 3434 | uint32_t sb_blk_offset = 0; |
| 3435 | char *sb_buffer = buffer; |
| 3436 | |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3437 | if (!sb_buffer) |
| 3438 | { |
| 3439 | dprintf(CRITICAL, "ERROR: Failed to allocate buffer for superblock\n"); |
| 3440 | goto out; |
| 3441 | } |
| 3442 | |
| 3443 | /* Read super block */ |
| 3444 | if ((index = partition_get_index(arg)) < 0) |
| 3445 | { |
| 3446 | dprintf(CRITICAL, "ERROR: %s() doesn't exsit\n", arg); |
| 3447 | goto out; |
| 3448 | } |
| 3449 | ptn = partition_get_offset(index); |
| 3450 | mmc_set_lun(partition_get_lun(index)); |
Mayank Grover | 399826a | 2018-08-27 12:15:15 +0530 | [diff] [blame] | 3451 | sb_blk_offset = (FS_SUPERBLOCK_OFFSET/mmc_blocksize); |
| 3452 | |
| 3453 | if(mmc_read(ptn + (sb_blk_offset * mmc_blocksize), |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3454 | (void *)sb_buffer, mmc_blocksize)) |
| 3455 | { |
| 3456 | dprintf(CRITICAL, "ERROR: Failed to read Superblock\n"); |
| 3457 | goto out; |
| 3458 | } |
| 3459 | |
Mayank Grover | 399826a | 2018-08-27 12:15:15 +0530 | [diff] [blame] | 3460 | if (sb_blk_offset == 0) |
| 3461 | sb_buffer += FS_SUPERBLOCK_OFFSET; |
| 3462 | |
| 3463 | if (*((uint16 *)(&sb_buffer[EXT_MAGIC_OFFSET_SB])) == (uint16)EXT_MAGIC) |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3464 | { |
| 3465 | dprintf(SPEW, "%s() Found EXT FS\n", arg); |
| 3466 | ret = EXT_FS_SIGNATURE; |
| 3467 | } |
Mayank Grover | 399826a | 2018-08-27 12:15:15 +0530 | [diff] [blame] | 3468 | else if (*((uint32 *)(&sb_buffer[F2FS_MAGIC_OFFSET_SB])) == F2FS_MAGIC) |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3469 | { |
| 3470 | dprintf(SPEW, "%s() Found F2FS FS\n", arg); |
| 3471 | ret = EXT_F2FS_SIGNATURE; |
| 3472 | } |
| 3473 | else |
| 3474 | { |
| 3475 | dprintf(SPEW, "%s() Reverting to default 0x%x\n", |
| 3476 | arg, *((uint16 *)(&sb_buffer[EXT_MAGIC_OFFSET_SB]))); |
| 3477 | ret = NO_FS; |
| 3478 | } |
| 3479 | |
| 3480 | out: |
Mayank Grover | 399826a | 2018-08-27 12:15:15 +0530 | [diff] [blame] | 3481 | if(buffer) |
| 3482 | free(buffer); |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3483 | return ret; |
| 3484 | } |
| 3485 | |
Mayank Grover | d38fe01 | 2018-03-13 15:33:16 +0530 | [diff] [blame] | 3486 | /* Function to get partition type */ |
| 3487 | static void get_partition_type(const char *arg, char *response) |
| 3488 | { |
| 3489 | uint n = 0; |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3490 | fs_signature_type fs_signature; |
Mayank Grover | d38fe01 | 2018-03-13 15:33:16 +0530 | [diff] [blame] | 3491 | |
| 3492 | if (arg == NULL || |
| 3493 | response == NULL) |
| 3494 | { |
| 3495 | dprintf(CRITICAL, "Invalid input parameter\n"); |
| 3496 | return; |
| 3497 | } |
| 3498 | |
| 3499 | /* By default copy raw to response */ |
Mayank Grover | 0e55904 | 2018-04-11 17:49:30 +0530 | [diff] [blame] | 3500 | strlcpy(response, RAW_STR, MAX_RSP_SIZE); |
Mayank Grover | d38fe01 | 2018-03-13 15:33:16 +0530 | [diff] [blame] | 3501 | |
| 3502 | /* Mark partiton type for known paritions only */ |
| 3503 | for (n=0; n < ARRAY_SIZE(part_type_known); n++) |
| 3504 | { |
| 3505 | if (!strncmp(part_type_known[n].part_name, arg, strlen(arg))) |
| 3506 | { |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3507 | /* Check partition for FS signature */ |
| 3508 | fs_signature = check_partition_fs_signature(arg); |
| 3509 | switch (fs_signature) |
| 3510 | { |
| 3511 | case EXT_FS_SIGNATURE: |
Mayank Grover | 0e55904 | 2018-04-11 17:49:30 +0530 | [diff] [blame] | 3512 | strlcpy(response, EXT_STR, MAX_RSP_SIZE); |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3513 | break; |
| 3514 | case EXT_F2FS_SIGNATURE: |
Mayank Grover | 0e55904 | 2018-04-11 17:49:30 +0530 | [diff] [blame] | 3515 | strlcpy(response, F2FS_STR, MAX_RSP_SIZE); |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3516 | break; |
| 3517 | case NO_FS: |
Mayank Grover | 0e55904 | 2018-04-11 17:49:30 +0530 | [diff] [blame] | 3518 | strlcpy(response, part_type_known[n].type_response, MAX_RSP_SIZE); |
Mayank Grover | 52cd10a | 2018-03-15 12:57:54 +0530 | [diff] [blame] | 3519 | } |
Mayank Grover | d38fe01 | 2018-03-13 15:33:16 +0530 | [diff] [blame] | 3520 | } |
| 3521 | } |
| 3522 | return; |
| 3523 | } |
| 3524 | |
Mayank Grover | 11ff969 | 2018-01-11 11:54:49 +0530 | [diff] [blame] | 3525 | /* |
| 3526 | * Publish the partition type & size info |
| 3527 | * fastboot getvar will publish the required information. |
| 3528 | * fastboot getvar partition_size:<partition_name>: partition size in hex |
| 3529 | * fastboot getvar partition_type:<partition_name>: partition type (ext/fat) |
| 3530 | */ |
| 3531 | static void publish_getvar_partition_info(struct getvar_partition_info *info, uint8_t num_parts) |
| 3532 | { |
Mayank Grover | d38fe01 | 2018-03-13 15:33:16 +0530 | [diff] [blame] | 3533 | uint8_t i; |
Mayank Grover | 11ff969 | 2018-01-11 11:54:49 +0530 | [diff] [blame] | 3534 | static bool published = false; |
| 3535 | struct partition_entry *ptn_entry = |
| 3536 | partition_get_partition_entries(); |
| 3537 | memset(info, 0, sizeof(struct getvar_partition_info)* num_parts); |
| 3538 | |
| 3539 | for (i = 0; i < num_parts; i++) { |
| 3540 | strlcat(info[i].part_name, (const char *)ptn_entry[i].name, MAX_RSP_SIZE); |
| 3541 | strlcat(info[i].getvar_size, "partition-size:", MAX_GET_VAR_NAME_SIZE); |
| 3542 | strlcat(info[i].getvar_type, "partition-type:", MAX_GET_VAR_NAME_SIZE); |
| 3543 | |
Mayank Grover | d38fe01 | 2018-03-13 15:33:16 +0530 | [diff] [blame] | 3544 | get_partition_type(info[i].part_name, info[i].type_response); |
Mayank Grover | 11ff969 | 2018-01-11 11:54:49 +0530 | [diff] [blame] | 3545 | get_partition_size(info[i].part_name, info[i].size_response); |
Mayank Grover | 11ff969 | 2018-01-11 11:54:49 +0530 | [diff] [blame] | 3546 | if (strlcat(info[i].getvar_size, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 3547 | { |
| 3548 | dprintf(CRITICAL, "partition size name truncated\n"); |
| 3549 | return; |
| 3550 | } |
| 3551 | if (strlcat(info[i].getvar_type, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 3552 | { |
| 3553 | dprintf(CRITICAL, "partition type name truncated\n"); |
| 3554 | return; |
| 3555 | } |
| 3556 | |
| 3557 | if (!published) |
| 3558 | { |
| 3559 | /* publish partition size & type info */ |
| 3560 | fastboot_publish((const char *) info[i].getvar_size, (const char *) info[i].size_response); |
| 3561 | fastboot_publish((const char *) info[i].getvar_type, (const char *) info[i].type_response); |
| 3562 | } |
| 3563 | } |
| 3564 | if (!published) |
| 3565 | published = true; |
| 3566 | } |
| 3567 | |
| 3568 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3569 | void cmd_flash_mmc_img(const char *arg, void *data, unsigned sz) |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 3570 | { |
| 3571 | unsigned long long ptn = 0; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 3572 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3573 | int index = INVALID_PTN; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3574 | char *token = NULL; |
| 3575 | char *pname = NULL; |
Sridhar Parasuram | efc133f | 2015-05-04 13:35:41 -0700 | [diff] [blame] | 3576 | char *sp; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3577 | uint8_t lun = 0; |
| 3578 | bool lun_set = false; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 3579 | int current_active_slot = INVALID; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 3580 | |
Sridhar Parasuram | efc133f | 2015-05-04 13:35:41 -0700 | [diff] [blame] | 3581 | token = strtok_r((char *)arg, ":", &sp); |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3582 | pname = token; |
Sridhar Parasuram | efc133f | 2015-05-04 13:35:41 -0700 | [diff] [blame] | 3583 | token = strtok_r(NULL, ":", &sp); |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3584 | if(token) |
| 3585 | { |
| 3586 | lun = atoi(token); |
| 3587 | mmc_set_lun(lun); |
| 3588 | lun_set = true; |
| 3589 | } |
| 3590 | |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 3591 | if (pname) |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 3592 | { |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 3593 | if (!strncmp(pname, "frp-unlock", strlen("frp-unlock"))) |
| 3594 | { |
| 3595 | if (!aboot_frp_unlock(pname, data, sz)) |
| 3596 | { |
| 3597 | fastboot_info("FRP unlock successful"); |
| 3598 | fastboot_okay(""); |
| 3599 | } |
| 3600 | else |
| 3601 | fastboot_fail("Secret key is invalid, please update the bootloader with secret key"); |
| 3602 | |
| 3603 | return; |
| 3604 | } |
| 3605 | |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 3606 | if (!strcmp(pname, "partition")) |
| 3607 | { |
| 3608 | dprintf(INFO, "Attempt to write partition image.\n"); |
| 3609 | if (write_partition(sz, (unsigned char *) data)) { |
| 3610 | fastboot_fail("failed to write partition"); |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 3611 | return; |
| 3612 | } |
Mayank Grover | 11ff969 | 2018-01-11 11:54:49 +0530 | [diff] [blame] | 3613 | /* Re-publish partition table */ |
| 3614 | publish_getvar_partition_info(part_info, partition_get_partition_count()); |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 3615 | |
| 3616 | /* Rescan partition table to ensure we have multislot support*/ |
| 3617 | if (partition_scan_for_multislot()) |
| 3618 | { |
| 3619 | current_active_slot = partition_find_active_slot(); |
| 3620 | dprintf(INFO, "Multislot supported: Slot %s active", |
| 3621 | (SUFFIX_SLOT(current_active_slot))); |
| 3622 | } |
| 3623 | partition_mark_active_slot(current_active_slot); |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 3624 | } |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 3625 | else |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3626 | { |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3627 | #if VERIFIED_BOOT |
| 3628 | if(!strcmp(pname, KEYSTORE_PTN_NAME)) |
| 3629 | { |
| 3630 | if(!device.is_unlocked) |
| 3631 | { |
| 3632 | fastboot_fail("unlock device to flash keystore"); |
| 3633 | return; |
| 3634 | } |
Gaurav Nebhwani | c7313cc | 2015-12-15 22:25:04 +0530 | [diff] [blame] | 3635 | if(!boot_verify_validate_keystore((unsigned char *)data,sz)) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 3636 | { |
| 3637 | fastboot_fail("image is not a keystore file"); |
| 3638 | return; |
| 3639 | } |
| 3640 | } |
| 3641 | #endif |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 3642 | index = partition_get_index(pname); |
| 3643 | ptn = partition_get_offset(index); |
| 3644 | if(ptn == 0) { |
| 3645 | fastboot_fail("partition table doesn't exist"); |
| 3646 | return; |
| 3647 | } |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3648 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 3649 | if (!strncmp(pname, "boot", strlen("boot")) |
| 3650 | || !strcmp(pname, "recovery")) |
| 3651 | { |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 3652 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 3653 | fastboot_fail("image is not a boot image"); |
| 3654 | return; |
| 3655 | } |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 3656 | |
| 3657 | /* Reset multislot_partition attributes in case of flashing boot */ |
| 3658 | if (partition_multislot_is_supported()) |
| 3659 | { |
| 3660 | partition_reset_attributes(index); |
| 3661 | } |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | if(!lun_set) |
| 3665 | { |
| 3666 | lun = partition_get_lun(index); |
| 3667 | mmc_set_lun(lun); |
| 3668 | } |
| 3669 | |
| 3670 | size = partition_get_size(index); |
Gaurav Nebhwani | 4d2389c | 2016-03-17 21:10:05 +0530 | [diff] [blame] | 3671 | if (ROUND_TO_PAGE(sz, mmc_blocksize_mask) > size) { |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 3672 | fastboot_fail("size too large"); |
| 3673 | return; |
| 3674 | } |
| 3675 | else if (mmc_write(ptn , sz, (unsigned int *)data)) { |
| 3676 | fastboot_fail("flash write failure"); |
| 3677 | return; |
| 3678 | } |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 3679 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 3680 | } |
| 3681 | fastboot_okay(""); |
| 3682 | return; |
| 3683 | } |
| 3684 | |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3685 | void cmd_flash_meta_img(const char *arg, void *data, unsigned sz) |
| 3686 | { |
| 3687 | int i, images; |
| 3688 | meta_header_t *meta_header; |
| 3689 | img_header_entry_t *img_header_entry; |
Parth Dixit | 3e2d303 | 2016-03-04 17:11:52 +0530 | [diff] [blame] | 3690 | /*End of the image address*/ |
| 3691 | uintptr_t data_end; |
| 3692 | |
| 3693 | if( (UINT_MAX - sz) > (uintptr_t)data ) |
| 3694 | data_end = (uintptr_t)data + sz; |
| 3695 | else |
| 3696 | { |
| 3697 | fastboot_fail("Cannot flash: image header corrupt"); |
| 3698 | return; |
| 3699 | } |
| 3700 | |
| 3701 | if( data_end < ((uintptr_t)data + sizeof(meta_header_t))) |
| 3702 | { |
| 3703 | fastboot_fail("Cannot flash: image header corrupt"); |
| 3704 | return; |
| 3705 | } |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3706 | |
lijuang | 8ee2188 | 2016-04-19 16:57:11 +0800 | [diff] [blame] | 3707 | /* If device is locked: |
| 3708 | * Forbid to flash image to avoid the device to bypass the image |
| 3709 | * which with "any" name other than bootloader. Because it maybe |
| 3710 | * a meta package of all partitions. |
| 3711 | */ |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 3712 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
lijuang | 8ee2188 | 2016-04-19 16:57:11 +0800 | [diff] [blame] | 3713 | if (target_build_variant_user()) { |
| 3714 | if (!device.is_unlocked) { |
| 3715 | fastboot_fail("Device is locked, meta image flashing is not allowed"); |
| 3716 | return; |
| 3717 | } |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 3718 | |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 3719 | if (VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 3720 | !device.is_unlock_critical) |
| 3721 | { |
lijuang | 8ee2188 | 2016-04-19 16:57:11 +0800 | [diff] [blame] | 3722 | fastboot_fail("Device is critical locked, Meta image flashing is not allowed"); |
| 3723 | return; |
| 3724 | } |
lijuang | 8ee2188 | 2016-04-19 16:57:11 +0800 | [diff] [blame] | 3725 | } |
| 3726 | #endif |
| 3727 | |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3728 | meta_header = (meta_header_t*) data; |
Parth Dixit | 3e2d303 | 2016-03-04 17:11:52 +0530 | [diff] [blame] | 3729 | if( data_end < ((uintptr_t)data + meta_header->img_hdr_sz)) |
| 3730 | { |
| 3731 | fastboot_fail("Cannot flash: image header corrupt"); |
| 3732 | return; |
| 3733 | } |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3734 | img_header_entry = (img_header_entry_t*) (data+sizeof(meta_header_t)); |
| 3735 | |
| 3736 | images = meta_header->img_hdr_sz / sizeof(img_header_entry_t); |
| 3737 | |
| 3738 | for (i=0; i<images; i++) { |
| 3739 | |
| 3740 | if((img_header_entry[i].ptn_name == NULL) || |
| 3741 | (img_header_entry[i].start_offset == 0) || |
| 3742 | (img_header_entry[i].size == 0)) |
| 3743 | break; |
Kishor PK | 4983150 | 2017-04-21 17:55:43 +0530 | [diff] [blame] | 3744 | if ((UINT_MAX - img_header_entry[i].start_offset) < (uintptr_t)data) { |
| 3745 | fastboot_fail("Integer overflow detected in start_offset of img"); |
| 3746 | break; |
| 3747 | } |
| 3748 | else if ((UINT_MAX - (img_header_entry[i].start_offset + (uintptr_t)data)) < img_header_entry[i].size) { |
| 3749 | fastboot_fail("Integer overflow detected in size of img"); |
| 3750 | break; |
| 3751 | } |
Parth Dixit | 3e2d303 | 2016-03-04 17:11:52 +0530 | [diff] [blame] | 3752 | if( data_end < ((uintptr_t)data + img_header_entry[i].start_offset |
| 3753 | + img_header_entry[i].size) ) |
| 3754 | { |
| 3755 | fastboot_fail("Cannot flash: image size mismatch"); |
| 3756 | break; |
| 3757 | } |
| 3758 | |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3759 | cmd_flash_mmc_img(img_header_entry[i].ptn_name, |
| 3760 | (void *) data + img_header_entry[i].start_offset, |
| 3761 | img_header_entry[i].size); |
| 3762 | } |
| 3763 | |
Channagoud Kadabi | aafbbfc | 2015-03-04 17:52:56 -0800 | [diff] [blame] | 3764 | if (!strncmp(arg, "bootloader", strlen("bootloader"))) |
| 3765 | { |
| 3766 | strlcpy(device.bootloader_version, TARGET(BOARD), MAX_VERSION_LEN); |
| 3767 | strlcat(device.bootloader_version, "-", MAX_VERSION_LEN); |
| 3768 | strlcat(device.bootloader_version, meta_header->img_version, MAX_VERSION_LEN); |
| 3769 | } |
| 3770 | else |
| 3771 | { |
| 3772 | strlcpy(device.radio_version, TARGET(BOARD), MAX_VERSION_LEN); |
| 3773 | strlcat(device.radio_version, "-", MAX_VERSION_LEN); |
| 3774 | strlcat(device.radio_version, meta_header->img_version, MAX_VERSION_LEN); |
| 3775 | } |
| 3776 | |
| 3777 | write_device_info(&device); |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 3778 | fastboot_okay(""); |
| 3779 | return; |
| 3780 | } |
| 3781 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3782 | void cmd_flash_mmc_sparse_img(const char *arg, void *data, unsigned sz) |
| 3783 | { |
| 3784 | unsigned int chunk; |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 3785 | uint64_t chunk_data_sz; |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 3786 | uint32_t *fill_buf = NULL; |
| 3787 | uint32_t fill_val; |
Mayank Grover | 4f50bba | 2017-07-19 18:17:08 +0530 | [diff] [blame] | 3788 | uint32_t blk_sz_actual = 0; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3789 | sparse_header_t *sparse_header; |
| 3790 | chunk_header_t *chunk_header; |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 3791 | uint32_t total_blocks = 0; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3792 | unsigned long long ptn = 0; |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 3793 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3794 | int index = INVALID_PTN; |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 3795 | uint32_t i; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3796 | uint8_t lun = 0; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3797 | /*End of the sparse image address*/ |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 3798 | uintptr_t data_end = (uintptr_t)data + sz; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3799 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3800 | index = partition_get_index(arg); |
| 3801 | ptn = partition_get_offset(index); |
| 3802 | if(ptn == 0) { |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3803 | fastboot_fail("partition table doesn't exist"); |
| 3804 | return; |
| 3805 | } |
| 3806 | |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 3807 | size = partition_get_size(index); |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 3808 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 3809 | lun = partition_get_lun(index); |
| 3810 | mmc_set_lun(lun); |
| 3811 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3812 | if (sz < sizeof(sparse_header_t)) { |
| 3813 | fastboot_fail("size too low"); |
| 3814 | return; |
| 3815 | } |
| 3816 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3817 | /* Read and skip over sparse image header */ |
| 3818 | sparse_header = (sparse_header_t *) data; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3819 | |
Mayank Grover | 48bd9bb | 2017-07-19 12:04:16 +0530 | [diff] [blame] | 3820 | if (!sparse_header->blk_sz || (sparse_header->blk_sz % 4)){ |
| 3821 | fastboot_fail("Invalid block size\n"); |
| 3822 | return; |
| 3823 | } |
| 3824 | |
vijay kumar | 1321f34 | 2015-03-27 12:13:42 +0530 | [diff] [blame] | 3825 | 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] | 3826 | fastboot_fail("size too large"); |
| 3827 | return; |
| 3828 | } |
| 3829 | |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 3830 | data += sizeof(sparse_header_t); |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3831 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 3832 | if (data_end < (uintptr_t)data) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3833 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 3834 | return; |
| 3835 | } |
| 3836 | |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 3837 | if(sparse_header->file_hdr_sz != sizeof(sparse_header_t)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3838 | { |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 3839 | fastboot_fail("sparse header size mismatch"); |
| 3840 | return; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3841 | } |
| 3842 | |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 3843 | dprintf (SPEW, "=== Sparse Image Header ===\n"); |
| 3844 | dprintf (SPEW, "magic: 0x%x\n", sparse_header->magic); |
| 3845 | dprintf (SPEW, "major_version: 0x%x\n", sparse_header->major_version); |
| 3846 | dprintf (SPEW, "minor_version: 0x%x\n", sparse_header->minor_version); |
| 3847 | dprintf (SPEW, "file_hdr_sz: %d\n", sparse_header->file_hdr_sz); |
| 3848 | dprintf (SPEW, "chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz); |
| 3849 | dprintf (SPEW, "blk_sz: %d\n", sparse_header->blk_sz); |
| 3850 | dprintf (SPEW, "total_blks: %d\n", sparse_header->total_blks); |
| 3851 | dprintf (SPEW, "total_chunks: %d\n", sparse_header->total_chunks); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3852 | |
| 3853 | /* Start processing chunks */ |
| 3854 | for (chunk=0; chunk<sparse_header->total_chunks; chunk++) |
| 3855 | { |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 3856 | /* Make sure the total image size does not exceed the partition size */ |
| 3857 | if(((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz) >= size) { |
| 3858 | fastboot_fail("size too large"); |
| 3859 | return; |
| 3860 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3861 | /* Read and skip over chunk header */ |
| 3862 | chunk_header = (chunk_header_t *) data; |
| 3863 | data += sizeof(chunk_header_t); |
| 3864 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 3865 | if (data_end < (uintptr_t)data) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3866 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 3867 | return; |
| 3868 | } |
| 3869 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3870 | dprintf (SPEW, "=== Chunk Header ===\n"); |
| 3871 | dprintf (SPEW, "chunk_type: 0x%x\n", chunk_header->chunk_type); |
| 3872 | dprintf (SPEW, "chunk_data_sz: 0x%x\n", chunk_header->chunk_sz); |
| 3873 | dprintf (SPEW, "total_size: 0x%x\n", chunk_header->total_sz); |
| 3874 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3875 | if(sparse_header->chunk_hdr_sz != sizeof(chunk_header_t)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3876 | { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3877 | fastboot_fail("chunk header size mismatch"); |
| 3878 | return; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3879 | } |
| 3880 | |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 3881 | chunk_data_sz = (uint64_t)sparse_header->blk_sz * chunk_header->chunk_sz; |
| 3882 | |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 3883 | /* Make sure that the chunk size calculated from sparse image does not |
| 3884 | * exceed partition size |
| 3885 | */ |
| 3886 | if ((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz + chunk_data_sz > size) |
| 3887 | { |
| 3888 | fastboot_fail("Chunk data size exceeds partition size"); |
| 3889 | return; |
| 3890 | } |
| 3891 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3892 | switch (chunk_header->chunk_type) |
| 3893 | { |
| 3894 | case CHUNK_TYPE_RAW: |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 3895 | 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] | 3896 | chunk_data_sz)) |
| 3897 | { |
| 3898 | fastboot_fail("Bogus chunk size for chunk type Raw"); |
| 3899 | return; |
| 3900 | } |
| 3901 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 3902 | if (data_end < (uintptr_t)data + chunk_data_sz) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3903 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 3904 | return; |
| 3905 | } |
| 3906 | |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 3907 | /* chunk_header->total_sz is uint32,So chunk_data_sz is now less than 2^32 |
| 3908 | otherwise it will return in the line above |
| 3909 | */ |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 3910 | if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz), |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 3911 | (uint32_t)chunk_data_sz, |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 3912 | (unsigned int*)data)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3913 | { |
| 3914 | fastboot_fail("flash write failure"); |
| 3915 | return; |
| 3916 | } |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 3917 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 3918 | fastboot_fail("Bogus size for RAW chunk type"); |
| 3919 | return; |
| 3920 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3921 | total_blocks += chunk_header->chunk_sz; |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 3922 | data += (uint32_t)chunk_data_sz; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3923 | break; |
| 3924 | |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 3925 | case CHUNK_TYPE_FILL: |
| 3926 | if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz + |
| 3927 | sizeof(uint32_t))) |
| 3928 | { |
| 3929 | fastboot_fail("Bogus chunk size for chunk type FILL"); |
| 3930 | return; |
| 3931 | } |
| 3932 | |
Mayank Grover | 4f50bba | 2017-07-19 18:17:08 +0530 | [diff] [blame] | 3933 | blk_sz_actual = ROUNDUP(sparse_header->blk_sz, CACHE_LINE); |
| 3934 | /* Integer overflow detected */ |
| 3935 | if (blk_sz_actual < sparse_header->blk_sz) |
| 3936 | { |
| 3937 | fastboot_fail("Invalid block size"); |
| 3938 | return; |
| 3939 | } |
| 3940 | |
| 3941 | fill_buf = (uint32_t *)memalign(CACHE_LINE, blk_sz_actual); |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 3942 | if (!fill_buf) |
| 3943 | { |
| 3944 | fastboot_fail("Malloc failed for: CHUNK_TYPE_FILL"); |
| 3945 | return; |
| 3946 | } |
| 3947 | |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 3948 | if (data_end < (uintptr_t)data + sizeof(uint32_t)) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3949 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
Gaurav Nebhwani | 163cbf8 | 2016-03-17 21:21:27 +0530 | [diff] [blame] | 3950 | free(fill_buf); |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 3951 | return; |
| 3952 | } |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 3953 | fill_val = *(uint32_t *)data; |
| 3954 | data = (char *) data + sizeof(uint32_t); |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 3955 | |
| 3956 | for (i = 0; i < (sparse_header->blk_sz / sizeof(fill_val)); i++) |
| 3957 | { |
| 3958 | fill_buf[i] = fill_val; |
| 3959 | } |
| 3960 | |
Gaurav Nebhwani | e94cbe1 | 2016-03-17 21:16:34 +0530 | [diff] [blame] | 3961 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) |
| 3962 | { |
| 3963 | fastboot_fail("bogus size for chunk FILL type"); |
| 3964 | free(fill_buf); |
| 3965 | return; |
| 3966 | } |
| 3967 | |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 3968 | for (i = 0; i < chunk_header->chunk_sz; i++) |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 3969 | { |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 3970 | /* Make sure that the data written to partition does not exceed partition size */ |
| 3971 | if ((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz + sparse_header->blk_sz > size) |
| 3972 | { |
| 3973 | fastboot_fail("Chunk data size for fill type exceeds partition size"); |
Gaurav Nebhwani | 163cbf8 | 2016-03-17 21:21:27 +0530 | [diff] [blame] | 3974 | free(fill_buf); |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 3975 | return; |
| 3976 | } |
| 3977 | |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 3978 | if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz), |
| 3979 | sparse_header->blk_sz, |
| 3980 | fill_buf)) |
| 3981 | { |
| 3982 | fastboot_fail("flash write failure"); |
| 3983 | free(fill_buf); |
| 3984 | return; |
| 3985 | } |
| 3986 | |
| 3987 | total_blocks++; |
| 3988 | } |
| 3989 | |
| 3990 | free(fill_buf); |
| 3991 | break; |
| 3992 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 3993 | case CHUNK_TYPE_DONT_CARE: |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 3994 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 3995 | fastboot_fail("bogus size for chunk DONT CARE type"); |
| 3996 | return; |
| 3997 | } |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 3998 | total_blocks += chunk_header->chunk_sz; |
| 3999 | break; |
| 4000 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4001 | case CHUNK_TYPE_CRC: |
| 4002 | if(chunk_header->total_sz != sparse_header->chunk_hdr_sz) |
| 4003 | { |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 4004 | fastboot_fail("Bogus chunk size for chunk type CRC"); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4005 | return; |
| 4006 | } |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 4007 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 4008 | fastboot_fail("bogus size for chunk CRC type"); |
| 4009 | return; |
| 4010 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4011 | total_blocks += chunk_header->chunk_sz; |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 4012 | if ((uintptr_t)data > UINT_MAX - chunk_data_sz) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 4013 | fastboot_fail("integer overflow occured"); |
| 4014 | return; |
| 4015 | } |
wufeng.jiang | 813dc35 | 2015-06-02 23:02:46 -0400 | [diff] [blame] | 4016 | data += (uint32_t)chunk_data_sz; |
Parth Dixit | 64b1a48 | 2016-03-07 16:31:26 +0530 | [diff] [blame] | 4017 | if (data_end < (uintptr_t)data) { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame] | 4018 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 4019 | return; |
| 4020 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4021 | break; |
| 4022 | |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 4023 | default: |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 4024 | dprintf(CRITICAL, "Unkown chunk type: %x\n",chunk_header->chunk_type); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4025 | fastboot_fail("Unknown chunk type"); |
| 4026 | return; |
| 4027 | } |
| 4028 | } |
| 4029 | |
Ajay Dudani | 0c6927b | 2011-05-18 11:12:16 -0700 | [diff] [blame] | 4030 | dprintf(INFO, "Wrote %d blocks, expected to write %d blocks\n", |
| 4031 | total_blocks, sparse_header->total_blks); |
| 4032 | |
| 4033 | if(total_blocks != sparse_header->total_blks) |
| 4034 | { |
| 4035 | fastboot_fail("sparse image write failure"); |
| 4036 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4037 | |
| 4038 | fastboot_okay(""); |
| 4039 | return; |
| 4040 | } |
| 4041 | |
| 4042 | void cmd_flash_mmc(const char *arg, void *data, unsigned sz) |
| 4043 | { |
| 4044 | sparse_header_t *sparse_header; |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 4045 | meta_header_t *meta_header; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4046 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 4047 | #ifdef SSD_ENABLE |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 4048 | /* 8 Byte Magic + 2048 Byte xml + Encrypted Data */ |
| 4049 | unsigned int *magic_number = (unsigned int *) data; |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 4050 | int ret=0; |
| 4051 | uint32 major_version=0; |
| 4052 | uint32 minor_version=0; |
| 4053 | |
| 4054 | ret = scm_svc_version(&major_version,&minor_version); |
| 4055 | if(!ret) |
| 4056 | { |
| 4057 | if(major_version >= 2) |
| 4058 | { |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 4059 | if( !strcmp(arg, "ssd") || !strcmp(arg, "tqs") ) |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 4060 | { |
| 4061 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 4062 | if (ret != 0) { |
| 4063 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 4064 | return; |
| 4065 | } |
| 4066 | |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 4067 | /* Protect only for SSD */ |
| 4068 | if (!strcmp(arg, "ssd")) { |
| 4069 | ret = scm_protect_keystore((uint32 *) data, sz); |
| 4070 | if (ret != 0) { |
| 4071 | dprintf(CRITICAL, "ERROR: scm_protect_keystore Failed\n"); |
| 4072 | return; |
| 4073 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 4074 | } |
| 4075 | } |
| 4076 | else |
| 4077 | { |
| 4078 | ret = decrypt_scm_v2((uint32 **) &data, &sz); |
| 4079 | if(ret != 0) |
| 4080 | { |
| 4081 | dprintf(CRITICAL,"ERROR: Decryption Failure\n"); |
| 4082 | return; |
| 4083 | } |
| 4084 | } |
| 4085 | } |
| 4086 | else |
| 4087 | { |
| 4088 | if (magic_number[0] == DECRYPT_MAGIC_0 && |
| 4089 | magic_number[1] == DECRYPT_MAGIC_1) |
| 4090 | { |
| 4091 | ret = decrypt_scm((uint32 **) &data, &sz); |
| 4092 | if (ret != 0) { |
| 4093 | dprintf(CRITICAL, "ERROR: Invalid secure image\n"); |
| 4094 | return; |
| 4095 | } |
| 4096 | } |
| 4097 | else if (magic_number[0] == ENCRYPT_MAGIC_0 && |
| 4098 | magic_number[1] == ENCRYPT_MAGIC_1) |
| 4099 | { |
| 4100 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 4101 | if (ret != 0) { |
| 4102 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 4103 | return; |
| 4104 | } |
| 4105 | } |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 4106 | } |
| 4107 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 4108 | else |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 4109 | { |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 4110 | dprintf(CRITICAL,"INVALID SVC Version\n"); |
| 4111 | return; |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 4112 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 4113 | #endif /* SSD_ENABLE */ |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 4114 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 4115 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Channagoud Kadabi | 3529767 | 2015-06-13 11:09:49 -0700 | [diff] [blame] | 4116 | if (target_build_variant_user()) |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 4117 | { |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4118 | /* if device is locked: |
| 4119 | * common partition will not allow to be flashed |
| 4120 | * critical partition will allow to flash image. |
| 4121 | */ |
| 4122 | if(!device.is_unlocked && !critical_flash_allowed(arg)) { |
| 4123 | fastboot_fail("Partition flashing is not allowed"); |
| 4124 | return; |
| 4125 | } |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 4126 | |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4127 | /* if device critical is locked: |
| 4128 | * common partition will allow to be flashed |
| 4129 | * critical partition will not allow to flash image. |
| 4130 | */ |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 4131 | if (VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 4132 | !device.is_unlock_critical && |
| 4133 | critical_flash_allowed(arg)) { |
| 4134 | fastboot_fail("Critical partition flashing is not allowed"); |
| 4135 | return; |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 4136 | } |
| 4137 | } |
| 4138 | #endif |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 4139 | if (!strncmp(arg, "avb_custom_key", strlen("avb_custom_key"))) { |
| 4140 | dprintf(INFO, "flashing avb_custom_key\n"); |
| 4141 | if (store_userkey(data, sz)) { |
| 4142 | fastboot_fail("Flashing avb_custom_key failed"); |
| 4143 | } else { |
| 4144 | fastboot_okay(""); |
| 4145 | } |
| 4146 | return; |
| 4147 | } |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 4148 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 4149 | sparse_header = (sparse_header_t *) data; |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 4150 | meta_header = (meta_header_t *) data; |
| 4151 | if (sparse_header->magic == SPARSE_HEADER_MAGIC) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4152 | cmd_flash_mmc_sparse_img(arg, data, sz); |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 4153 | else if (meta_header->magic == META_HEADER_MAGIC) |
| 4154 | cmd_flash_meta_img(arg, data, sz); |
| 4155 | else |
| 4156 | cmd_flash_mmc_img(arg, data, sz); |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 4157 | |
| 4158 | #if VERIFIED_BOOT |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 4159 | if (VB_M <= target_get_vb_version() && |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 4160 | (!strncmp(arg, "system", 6)) && |
| 4161 | !device.verity_mode) |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 4162 | // reset dm_verity mode to enforcing |
| 4163 | device.verity_mode = 1; |
| 4164 | write_device_info(&device); |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 4165 | #endif |
Sridhar Parasuram | d69f790 | 2015-07-10 13:31:17 -0700 | [diff] [blame] | 4166 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 4167 | return; |
| 4168 | } |
| 4169 | |
Tanya Brokhman | 84eaaf6 | 2015-02-24 21:57:06 +0200 | [diff] [blame] | 4170 | void cmd_updatevol(const char *vol_name, void *data, unsigned sz) |
| 4171 | { |
| 4172 | struct ptentry *sys_ptn; |
| 4173 | struct ptable *ptable; |
| 4174 | |
| 4175 | ptable = flash_get_ptable(); |
| 4176 | if (ptable == NULL) { |
| 4177 | fastboot_fail("partition table doesn't exist"); |
| 4178 | return; |
| 4179 | } |
| 4180 | |
| 4181 | sys_ptn = ptable_find(ptable, "system"); |
| 4182 | if (sys_ptn == NULL) { |
| 4183 | fastboot_fail("system partition not found"); |
| 4184 | return; |
| 4185 | } |
| 4186 | |
| 4187 | sz = ROUND_TO_PAGE(sz, page_mask); |
| 4188 | if (update_ubi_vol(sys_ptn, vol_name, data, sz)) |
| 4189 | fastboot_fail("update_ubi_vol failed"); |
| 4190 | else |
| 4191 | fastboot_okay(""); |
| 4192 | } |
| 4193 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 4194 | void cmd_flash_nand(const char *arg, void *data, unsigned sz) |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4195 | { |
| 4196 | struct ptentry *ptn; |
| 4197 | struct ptable *ptable; |
| 4198 | unsigned extra = 0; |
Gaurav Nebhwani | d973071 | 2016-05-06 14:28:29 +0530 | [diff] [blame] | 4199 | uint64_t partition_size = 0; |
Vijay Kumar Pendoti | c6f22a7 | 2017-05-19 22:44:34 +0530 | [diff] [blame] | 4200 | unsigned bytes_to_round_page = 0; |
| 4201 | unsigned rounded_size = 0; |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4202 | |
Kishor PK | 38ed93d | 2017-04-25 14:19:26 +0530 | [diff] [blame] | 4203 | if((uintptr_t)data > (UINT_MAX - sz)) { |
| 4204 | fastboot_fail("Cannot flash: image header corrupt"); |
| 4205 | return; |
| 4206 | } |
| 4207 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4208 | ptable = flash_get_ptable(); |
| 4209 | if (ptable == NULL) { |
| 4210 | fastboot_fail("partition table doesn't exist"); |
| 4211 | return; |
| 4212 | } |
| 4213 | |
| 4214 | ptn = ptable_find(ptable, arg); |
| 4215 | if (ptn == NULL) { |
Tanya Brokhman | 84eaaf6 | 2015-02-24 21:57:06 +0200 | [diff] [blame] | 4216 | dprintf(INFO, "unknown partition name (%s). Trying updatevol\n", |
| 4217 | arg); |
| 4218 | cmd_updatevol(arg, data, sz); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4219 | return; |
| 4220 | } |
| 4221 | |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 4222 | if (!strncmp(arg, "avb_custom_key", strlen("avb_custom_key"))) { |
| 4223 | dprintf(INFO, "flashing avb_custom_key\n"); |
| 4224 | if (store_userkey(data, sz)) { |
| 4225 | fastboot_fail("Flashing avb_custom_key failed"); |
| 4226 | } else { |
| 4227 | fastboot_okay(""); |
| 4228 | } |
| 4229 | return; |
| 4230 | } |
| 4231 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4232 | if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) { |
Kishor PK | 38ed93d | 2017-04-25 14:19:26 +0530 | [diff] [blame] | 4233 | if((sz > BOOT_MAGIC_SIZE) && (!memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE))) { |
| 4234 | dprintf(INFO, "Verified the BOOT_MAGIC in image header \n"); |
| 4235 | } else { |
| 4236 | fastboot_fail("Image is not a boot image"); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4237 | return; |
| 4238 | } |
| 4239 | } |
| 4240 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 4241 | if (!strcmp(ptn->name, "system") |
Deepa Dinamani | 13e32c4 | 2012-03-12 14:34:17 -0700 | [diff] [blame] | 4242 | || !strcmp(ptn->name, "userdata") |
| 4243 | || !strcmp(ptn->name, "persist") |
Sundarajan Srinivasan | b063a85 | 2013-11-19 14:02:27 -0800 | [diff] [blame] | 4244 | || !strcmp(ptn->name, "recoveryfs") |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 4245 | || !strcmp(ptn->name, "modem")) |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 4246 | extra = 1; |
Kishor PK | 38ed93d | 2017-04-25 14:19:26 +0530 | [diff] [blame] | 4247 | else { |
Vijay Kumar Pendoti | c6f22a7 | 2017-05-19 22:44:34 +0530 | [diff] [blame] | 4248 | rounded_size = ROUNDUP(sz, page_size); |
| 4249 | bytes_to_round_page = rounded_size - sz; |
| 4250 | if (bytes_to_round_page) { |
| 4251 | if (((uintptr_t)data + sz ) > (UINT_MAX - bytes_to_round_page)) { |
| 4252 | fastboot_fail("Integer overflow detected"); |
| 4253 | return; |
| 4254 | } |
| 4255 | if (((uintptr_t)data + sz + bytes_to_round_page) > |
| 4256 | ((uintptr_t)target_get_scratch_address() + target_get_max_flash_size())) { |
| 4257 | fastboot_fail("Buffer size is not aligned to page_size"); |
| 4258 | return; |
| 4259 | } |
| 4260 | else { |
| 4261 | memset(data + sz, 0, bytes_to_round_page); |
| 4262 | sz = rounded_size; |
| 4263 | } |
Kishor PK | 38ed93d | 2017-04-25 14:19:26 +0530 | [diff] [blame] | 4264 | } |
Gaurav Nebhwani | d973071 | 2016-05-06 14:28:29 +0530 | [diff] [blame] | 4265 | } |
| 4266 | |
Kishor PK | 38ed93d | 2017-04-25 14:19:26 +0530 | [diff] [blame] | 4267 | /*Checking partition_size for the possible integer overflow */ |
| 4268 | partition_size = validate_partition_size(ptn); |
| 4269 | |
Gaurav Nebhwani | d973071 | 2016-05-06 14:28:29 +0530 | [diff] [blame] | 4270 | if (sz > partition_size) { |
| 4271 | fastboot_fail("Image size too large"); |
| 4272 | return; |
| 4273 | } |
| 4274 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4275 | dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name); |
Mayank Grover | 6cde935 | 2017-06-06 18:45:23 +0530 | [diff] [blame] | 4276 | if ((sz > UBI_EC_HDR_SIZE) && |
| 4277 | (!memcmp((void *)data, UBI_MAGIC, UBI_MAGIC_SIZE))) { |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 4278 | if (flash_ubi_img(ptn, data, sz)) { |
| 4279 | fastboot_fail("flash write failure"); |
| 4280 | return; |
| 4281 | } |
| 4282 | } else { |
| 4283 | if (flash_write(ptn, extra, data, sz)) { |
| 4284 | fastboot_fail("flash write failure"); |
| 4285 | return; |
| 4286 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4287 | } |
| 4288 | dprintf(INFO, "partition '%s' updated\n", ptn->name); |
| 4289 | fastboot_okay(""); |
| 4290 | } |
| 4291 | |
Kishor PK | 38ed93d | 2017-04-25 14:19:26 +0530 | [diff] [blame] | 4292 | |
| 4293 | static inline uint64_t validate_partition_size(struct ptentry *ptn) |
| 4294 | { |
| 4295 | if (ptn->length && flash_num_pages_per_blk() && page_size) { |
| 4296 | if ((ptn->length < ( UINT_MAX / flash_num_pages_per_blk())) && ((ptn->length * flash_num_pages_per_blk()) < ( UINT_MAX / page_size))) { |
| 4297 | return ptn->length * flash_num_pages_per_blk() * page_size; |
| 4298 | } |
| 4299 | } |
| 4300 | return 0; |
| 4301 | } |
| 4302 | |
| 4303 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 4304 | void cmd_flash(const char *arg, void *data, unsigned sz) |
| 4305 | { |
| 4306 | if(target_is_emmc_boot()) |
| 4307 | cmd_flash_mmc(arg, data, sz); |
| 4308 | else |
| 4309 | cmd_flash_nand(arg, data, sz); |
| 4310 | } |
| 4311 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4312 | void cmd_continue(const char *arg, void *data, unsigned sz) |
| 4313 | { |
| 4314 | fastboot_okay(""); |
Amol Jadi | 7c4316c | 2013-10-07 14:19:26 -0700 | [diff] [blame] | 4315 | fastboot_stop(); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 4316 | |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 4317 | if (target_is_emmc_boot()) |
| 4318 | { |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 4319 | #if FBCON_DISPLAY_MSG |
lijuang | de34d50 | 2016-02-26 16:04:50 +0800 | [diff] [blame] | 4320 | /* Exit keys' detection thread firstly */ |
| 4321 | exit_menu_keys_detection(); |
lijuang | a40d630 | 2015-07-20 20:10:13 +0800 | [diff] [blame] | 4322 | #endif |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 4323 | boot_linux_from_mmc(); |
| 4324 | } |
| 4325 | else |
| 4326 | { |
| 4327 | boot_linux_from_flash(); |
| 4328 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 4329 | } |
| 4330 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 4331 | void cmd_reboot(const char *arg, void *data, unsigned sz) |
| 4332 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 4333 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 4334 | fastboot_okay(""); |
| 4335 | reboot_device(0); |
| 4336 | } |
| 4337 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4338 | void cmd_set_active(const char *arg, void *data, unsigned sz) |
| 4339 | { |
Mayank Grover | 6ccc1c9 | 2017-07-04 17:36:46 +0530 | [diff] [blame] | 4340 | char *p, *sp = NULL; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4341 | unsigned i,current_active_slot; |
| 4342 | const char *current_slot_suffix; |
| 4343 | |
| 4344 | if (!partition_multislot_is_supported()) |
| 4345 | { |
| 4346 | fastboot_fail("Command not supported"); |
| 4347 | return; |
| 4348 | } |
| 4349 | |
| 4350 | if (arg) |
| 4351 | { |
Mayank Grover | 6ccc1c9 | 2017-07-04 17:36:46 +0530 | [diff] [blame] | 4352 | p = strtok_r((char *)arg, ":", &sp); |
Mayank Grover | 5eb5f69 | 2017-07-19 20:16:04 +0530 | [diff] [blame] | 4353 | if (p) |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4354 | { |
| 4355 | current_active_slot = partition_find_active_slot(); |
| 4356 | |
| 4357 | /* Check if trying to make curent slot active */ |
| 4358 | current_slot_suffix = SUFFIX_SLOT(current_active_slot); |
Mayank Grover | 6ccc1c9 | 2017-07-04 17:36:46 +0530 | [diff] [blame] | 4359 | current_slot_suffix = strtok_r((char *)current_slot_suffix, |
| 4360 | (char *)suffix_delimiter, &sp); |
| 4361 | |
Mayank Grover | 5eb5f69 | 2017-07-19 20:16:04 +0530 | [diff] [blame] | 4362 | if (current_slot_suffix && |
| 4363 | !strncmp(p, current_slot_suffix, strlen(current_slot_suffix))) |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4364 | { |
| 4365 | fastboot_okay("Slot already set active"); |
| 4366 | return; |
| 4367 | } |
| 4368 | else |
| 4369 | { |
| 4370 | for (i = 0; i < AB_SUPPORTED_SLOTS; i++) |
| 4371 | { |
| 4372 | current_slot_suffix = SUFFIX_SLOT(i); |
Mayank Grover | 6ccc1c9 | 2017-07-04 17:36:46 +0530 | [diff] [blame] | 4373 | current_slot_suffix = strtok_r((char *)current_slot_suffix, |
| 4374 | (char *)suffix_delimiter, &sp); |
Mayank Grover | 5eb5f69 | 2017-07-19 20:16:04 +0530 | [diff] [blame] | 4375 | if (current_slot_suffix && |
| 4376 | !strncmp(p, current_slot_suffix, strlen(current_slot_suffix))) |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4377 | { |
| 4378 | partition_switch_slots(current_active_slot, i); |
| 4379 | publish_getvar_multislot_vars(); |
| 4380 | fastboot_okay(""); |
| 4381 | return; |
| 4382 | } |
| 4383 | } |
| 4384 | } |
| 4385 | } |
| 4386 | } |
| 4387 | fastboot_fail("Invalid slot suffix."); |
| 4388 | return; |
| 4389 | } |
| 4390 | |
Mayank Grover | 98c4c74 | 2019-04-25 17:21:37 +0530 | [diff] [blame] | 4391 | #if DYNAMIC_PARTITION_SUPPORT |
| 4392 | void cmd_reboot_fastboot(const char *arg, void *data, unsigned sz) |
| 4393 | { |
| 4394 | dprintf(INFO, "rebooting the device - userspace fastboot\n"); |
| 4395 | if (send_recovery_cmd(RECOVERY_BOOT_FASTBOOT_CMD)) { |
| 4396 | dprintf(CRITICAL, "ERROR: Failed to update recovery commands\n"); |
| 4397 | fastboot_fail("Failed to update recovery command"); |
| 4398 | return; |
| 4399 | } |
| 4400 | fastboot_okay(""); |
| 4401 | reboot_device(REBOOT_MODE_UNKNOWN); |
| 4402 | |
| 4403 | //shouldn't come here. |
| 4404 | dprintf(CRITICAL, "ERROR: Failed to reboot device\n"); |
| 4405 | return; |
| 4406 | } |
| 4407 | |
| 4408 | void cmd_reboot_recovery(const char *arg, void *data, unsigned sz) |
| 4409 | { |
| 4410 | dprintf(INFO, "rebooting the device - recovery\n"); |
| 4411 | if (send_recovery_cmd(RECOVERY_BOOT_RECOVERY_CMD)) { |
| 4412 | dprintf(CRITICAL, "ERROR: Failed to update recovery commands\n"); |
| 4413 | fastboot_fail("Failed to update recovery command"); |
| 4414 | return; |
| 4415 | } |
| 4416 | fastboot_okay(""); |
| 4417 | reboot_device(REBOOT_MODE_UNKNOWN); |
| 4418 | |
| 4419 | //shouldn't come here. |
| 4420 | dprintf(CRITICAL, "ERROR: Failed to reboot device\n"); |
| 4421 | return; |
| 4422 | } |
| 4423 | #endif |
| 4424 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 4425 | void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz) |
| 4426 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 4427 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 4428 | fastboot_okay(""); |
| 4429 | reboot_device(FASTBOOT_MODE); |
| 4430 | } |
| 4431 | |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 4432 | void cmd_oem_enable_charger_screen(const char *arg, void *data, unsigned size) |
| 4433 | { |
| 4434 | dprintf(INFO, "Enabling charger screen check\n"); |
| 4435 | device.charger_screen_enabled = 1; |
| 4436 | write_device_info(&device); |
| 4437 | fastboot_okay(""); |
| 4438 | } |
| 4439 | |
| 4440 | void cmd_oem_disable_charger_screen(const char *arg, void *data, unsigned size) |
| 4441 | { |
| 4442 | dprintf(INFO, "Disabling charger screen check\n"); |
| 4443 | device.charger_screen_enabled = 0; |
| 4444 | write_device_info(&device); |
| 4445 | fastboot_okay(""); |
| 4446 | } |
| 4447 | |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 4448 | void cmd_oem_off_mode_charger(const char *arg, void *data, unsigned size) |
| 4449 | { |
| 4450 | char *p = NULL; |
| 4451 | const char *delim = " \t\n\r"; |
Parth Dixit | 407f15b | 2016-01-07 14:47:37 +0530 | [diff] [blame] | 4452 | char *sp; |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 4453 | |
| 4454 | if (arg) { |
Parth Dixit | 407f15b | 2016-01-07 14:47:37 +0530 | [diff] [blame] | 4455 | p = strtok_r((char *)arg, delim, &sp); |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 4456 | if (p) { |
| 4457 | if (!strncmp(p, "0", 1)) { |
| 4458 | device.charger_screen_enabled = 0; |
| 4459 | } else if (!strncmp(p, "1", 1)) { |
| 4460 | device.charger_screen_enabled = 1; |
| 4461 | } |
| 4462 | } |
| 4463 | } |
| 4464 | |
| 4465 | /* update charger_screen_enabled value for getvar |
| 4466 | * command |
| 4467 | */ |
| 4468 | snprintf(charger_screen_enabled, MAX_RSP_SIZE, "%d", |
| 4469 | device.charger_screen_enabled); |
| 4470 | |
| 4471 | write_device_info(&device); |
| 4472 | fastboot_okay(""); |
| 4473 | } |
| 4474 | |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 4475 | void cmd_oem_select_display_panel(const char *arg, void *data, unsigned size) |
| 4476 | { |
| 4477 | dprintf(INFO, "Selecting display panel %s\n", arg); |
| 4478 | if (arg) |
| 4479 | strlcpy(device.display_panel, arg, |
| 4480 | sizeof(device.display_panel)); |
| 4481 | write_device_info(&device); |
| 4482 | fastboot_okay(""); |
| 4483 | } |
| 4484 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 4485 | void cmd_oem_unlock(const char *arg, void *data, unsigned sz) |
| 4486 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4487 | set_device_unlock(UNLOCK, TRUE); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | void cmd_oem_unlock_go(const char *arg, void *data, unsigned sz) |
| 4491 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4492 | if(!device.is_unlocked) { |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 4493 | if(!is_allow_unlock) { |
| 4494 | fastboot_fail("oem unlock is not allowed"); |
| 4495 | return; |
| 4496 | } |
| 4497 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4498 | set_device_unlock_value(UNLOCK, TRUE); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 4499 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4500 | /* wipe data */ |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 4501 | struct recovery_message msg; |
Kishor PK | 60a6821 | 2017-05-08 16:55:57 +0530 | [diff] [blame] | 4502 | memset(&msg, 0, sizeof(msg)); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 4503 | snprintf(msg.recovery, sizeof(msg.recovery), "recovery\n--wipe_data"); |
| 4504 | write_misc(0, &msg, sizeof(msg)); |
| 4505 | |
| 4506 | fastboot_okay(""); |
| 4507 | reboot_device(RECOVERY_MODE); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 4508 | } |
| 4509 | fastboot_okay(""); |
| 4510 | } |
| 4511 | |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 4512 | static int aboot_frp_unlock(char *pname, void *data, unsigned sz) |
| 4513 | { |
Mayank Grover | 70f8b0e | 2017-05-17 11:49:00 +0530 | [diff] [blame] | 4514 | int ret=1; |
| 4515 | bool authentication_success=false; |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 4516 | |
Mayank Grover | 70f8b0e | 2017-05-17 11:49:00 +0530 | [diff] [blame] | 4517 | /* |
| 4518 | Authentication method not implemented. |
| 4519 | |
| 4520 | OEM to implement, authentication system which on successful validataion, |
| 4521 | calls write_allow_oem_unlock() with is_allow_unlock. |
| 4522 | */ |
| 4523 | #if 0 |
| 4524 | authentication_success = oem_specific_auth_mthd(); |
| 4525 | #endif |
| 4526 | |
| 4527 | if (authentication_success) |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 4528 | { |
Mayank Grover | 70f8b0e | 2017-05-17 11:49:00 +0530 | [diff] [blame] | 4529 | is_allow_unlock = true; |
| 4530 | write_allow_oem_unlock(is_allow_unlock); |
| 4531 | ret = 0; |
Channagoud Kadabi | ad25983 | 2015-05-29 11:14:17 -0700 | [diff] [blame] | 4532 | } |
| 4533 | return ret; |
| 4534 | } |
| 4535 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 4536 | void cmd_oem_lock(const char *arg, void *data, unsigned sz) |
| 4537 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4538 | set_device_unlock(UNLOCK, FALSE); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 4539 | } |
| 4540 | |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 4541 | void cmd_oem_devinfo(const char *arg, void *data, unsigned sz) |
| 4542 | { |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4543 | char response[MAX_RSP_SIZE]; |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 4544 | snprintf(response, sizeof(response), "\tDevice tampered: %s", (device.is_tampered ? "true" : "false")); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 4545 | fastboot_info(response); |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 4546 | snprintf(response, sizeof(response), "\tDevice unlocked: %s", (device.is_unlocked ? "true" : "false")); |
| 4547 | fastboot_info(response); |
Monika Singh | 292b3e9 | 2018-03-17 22:40:23 +0530 | [diff] [blame] | 4548 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 4549 | if (VB_M <= target_get_vb_version()) |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 4550 | { |
| 4551 | snprintf(response, sizeof(response), "\tDevice critical unlocked: %s", |
| 4552 | (device.is_unlock_critical ? "true" : "false")); |
| 4553 | fastboot_info(response); |
| 4554 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 4555 | #endif |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 4556 | 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] | 4557 | fastboot_info(response); |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 4558 | snprintf(response, sizeof(response), "\tDisplay panel: %s", (device.display_panel)); |
| 4559 | fastboot_info(response); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 4560 | fastboot_okay(""); |
| 4561 | } |
| 4562 | |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4563 | void cmd_flashing_get_unlock_ability(const char *arg, void *data, unsigned sz) |
| 4564 | { |
| 4565 | char response[MAX_RSP_SIZE]; |
| 4566 | snprintf(response, sizeof(response), "\tget_unlock_ability: %d", is_allow_unlock); |
| 4567 | fastboot_info(response); |
| 4568 | fastboot_okay(""); |
| 4569 | } |
| 4570 | |
| 4571 | void cmd_flashing_lock_critical(const char *arg, void *data, unsigned sz) |
| 4572 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4573 | set_device_unlock(UNLOCK_CRITICAL, FALSE); |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4574 | } |
| 4575 | |
| 4576 | void cmd_flashing_unlock_critical(const char *arg, void *data, unsigned sz) |
| 4577 | { |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4578 | set_device_unlock(UNLOCK_CRITICAL, TRUE); |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4579 | } |
| 4580 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 4581 | void cmd_preflash(const char *arg, void *data, unsigned sz) |
| 4582 | { |
| 4583 | fastboot_okay(""); |
| 4584 | } |
| 4585 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4586 | static uint8_t logo_header[LOGO_IMG_HEADER_SIZE]; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4587 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4588 | int splash_screen_check_header(logo_img_header *header) |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4589 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4590 | if (memcmp(header->magic, LOGO_IMG_MAGIC, 8)) |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4591 | return -1; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4592 | if (header->width == 0 || header->height == 0) |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4593 | return -1; |
| 4594 | return 0; |
| 4595 | } |
| 4596 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4597 | int splash_screen_flash() |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 4598 | { |
| 4599 | struct ptentry *ptn; |
| 4600 | struct ptable *ptable; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4601 | struct logo_img_header *header; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 4602 | struct fbcon_config *fb_display = NULL; |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 4603 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4604 | ptable = flash_get_ptable(); |
| 4605 | if (ptable == NULL) { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4606 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 4607 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4608 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4609 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4610 | ptn = ptable_find(ptable, "splash"); |
| 4611 | if (ptn == NULL) { |
| 4612 | dprintf(CRITICAL, "ERROR: splash Partition not found\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4613 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4614 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4615 | if (flash_read(ptn, 0, (void *)logo_header, LOGO_IMG_HEADER_SIZE)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4616 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4617 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4618 | } |
| 4619 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4620 | header = (struct logo_img_header *)logo_header; |
| 4621 | if (splash_screen_check_header(header)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4622 | dprintf(CRITICAL, "ERROR: Boot image header invalid\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4623 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4624 | } |
| 4625 | |
| 4626 | fb_display = fbcon_display(); |
| 4627 | if (fb_display) { |
raghavendra ambadas | 554f4fd | 2018-10-09 15:50:40 +0530 | [diff] [blame] | 4628 | if (header->type && (header->blocks != 0) && |
| 4629 | (UINT_MAX >= header->blocks * 512) && |
| 4630 | ((header->blocks * 512) <= (fb_display->width * |
| 4631 | fb_display->height * (fb_display->bpp / 8)))) { |
| 4632 | /* RLE24 compressed data */ |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4633 | uint8_t *base = (uint8_t *) fb_display->base + LOGO_IMG_OFFSET; |
| 4634 | |
| 4635 | /* if the logo is full-screen size, remove "fbcon_clear()" */ |
| 4636 | if ((header->width != fb_display->width) |
| 4637 | || (header->height != fb_display->height)) |
| 4638 | fbcon_clear(); |
| 4639 | |
| 4640 | if (flash_read(ptn + LOGO_IMG_HEADER_SIZE, 0, |
| 4641 | (uint32_t *)base, |
| 4642 | (header->blocks * 512))) { |
| 4643 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 4644 | return -1; |
| 4645 | } |
| 4646 | fbcon_extract_to_screen(header, base); |
| 4647 | return 0; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 4648 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4649 | |
Veera Sundaram Sankaran | c33416f | 2015-09-28 10:25:55 -0700 | [diff] [blame] | 4650 | if ((header->width > fb_display->width) || (header->height > fb_display->height)) { |
| 4651 | 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] | 4652 | return -1; |
| 4653 | } |
| 4654 | |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 4655 | uint8_t *base = (uint8_t *) fb_display->base; |
Sachin Bhayare | 619e9e4 | 2017-05-15 13:10:31 +0530 | [diff] [blame] | 4656 | uint32_t fb_size = ROUNDUP(fb_display->width * |
| 4657 | fb_display->height * |
| 4658 | (fb_display->bpp / 8), 4096); |
| 4659 | uint32_t splash_size = ((((header->width * header->height * |
| 4660 | fb_display->bpp/8) + 511) >> 9) << 9); |
| 4661 | |
| 4662 | if (splash_size > fb_size) { |
| 4663 | dprintf(CRITICAL, "ERROR: Splash image size invalid\n"); |
| 4664 | return -1; |
| 4665 | } |
| 4666 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4667 | if (flash_read(ptn + LOGO_IMG_HEADER_SIZE, 0, |
| 4668 | (uint32_t *)base, |
| 4669 | ((((header->width * header->height * fb_display->bpp/8) + 511) >> 9) << 9))) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4670 | fbcon_clear(); |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 4671 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4672 | return -1; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 4673 | } |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4674 | } |
| 4675 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4676 | return 0; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4677 | } |
| 4678 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4679 | int splash_screen_mmc() |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4680 | { |
| 4681 | int index = INVALID_PTN; |
| 4682 | unsigned long long ptn = 0; |
| 4683 | struct fbcon_config *fb_display = NULL; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4684 | struct logo_img_header *header; |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4685 | uint32_t blocksize, realsize, readsize; |
| 4686 | uint8_t *base; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4687 | |
| 4688 | index = partition_get_index("splash"); |
| 4689 | if (index == 0) { |
| 4690 | dprintf(CRITICAL, "ERROR: splash Partition table not found\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4691 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4692 | } |
| 4693 | |
| 4694 | ptn = partition_get_offset(index); |
| 4695 | if (ptn == 0) { |
| 4696 | dprintf(CRITICAL, "ERROR: splash Partition invalid\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4697 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4698 | } |
| 4699 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4700 | mmc_set_lun(partition_get_lun(index)); |
| 4701 | |
| 4702 | blocksize = mmc_get_device_blocksize(); |
| 4703 | if (blocksize == 0) { |
| 4704 | dprintf(CRITICAL, "ERROR:splash Partition invalid blocksize\n"); |
| 4705 | return -1; |
| 4706 | } |
| 4707 | |
| 4708 | fb_display = fbcon_display(); |
Channagoud Kadabi | daf10a6 | 2015-07-22 11:51:55 -0700 | [diff] [blame] | 4709 | if (!fb_display) |
| 4710 | { |
| 4711 | dprintf(CRITICAL, "ERROR: fb config is not allocated\n"); |
| 4712 | return -1; |
| 4713 | } |
| 4714 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4715 | base = (uint8_t *) fb_display->base; |
| 4716 | |
Kishor PK | ee5c0a3 | 2018-03-06 16:49:46 +0530 | [diff] [blame] | 4717 | if (mmc_read(ptn + PLL_CODES_OFFSET, (uint32_t *)(base + LOGO_IMG_OFFSET), blocksize)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4718 | dprintf(CRITICAL, "ERROR: Cannot read splash image header\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4719 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4720 | } |
| 4721 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4722 | header = (struct logo_img_header *)(base + LOGO_IMG_OFFSET); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4723 | if (splash_screen_check_header(header)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4724 | dprintf(CRITICAL, "ERROR: Splash image header invalid\n"); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4725 | return -1; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4726 | } |
| 4727 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4728 | if (fb_display) { |
raghavendra ambadas | 554f4fd | 2018-10-09 15:50:40 +0530 | [diff] [blame] | 4729 | if (header->type && (header->blocks != 0) && |
| 4730 | (UINT_MAX >= header->blocks * 512 + LOGO_IMG_HEADER_SIZE) && |
| 4731 | ((header->blocks * 512) <= (fb_display->width * |
| 4732 | fb_display->height * (fb_display->bpp / 8)))) { |
| 4733 | /* 1 RLE24 compressed data */ |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4734 | base += LOGO_IMG_OFFSET; |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4735 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4736 | realsize = header->blocks * 512; |
| 4737 | readsize = ROUNDUP((realsize + LOGO_IMG_HEADER_SIZE), blocksize) - blocksize; |
| 4738 | |
| 4739 | /* if the logo is not full-screen size, clean screen */ |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4740 | if ((header->width != fb_display->width) |
| 4741 | || (header->height != fb_display->height)) |
| 4742 | fbcon_clear(); |
| 4743 | |
Sachin Bhayare | 619e9e4 | 2017-05-15 13:10:31 +0530 | [diff] [blame] | 4744 | uint32_t fb_size = ROUNDUP(fb_display->width * |
| 4745 | fb_display->height * |
| 4746 | (fb_display->bpp / 8), 4096); |
| 4747 | |
| 4748 | if (readsize > fb_size) { |
| 4749 | dprintf(CRITICAL, "ERROR: Splash image size invalid\n"); |
| 4750 | return -1; |
| 4751 | } |
| 4752 | |
Kishor PK | ee5c0a3 | 2018-03-06 16:49:46 +0530 | [diff] [blame] | 4753 | if (mmc_read(ptn + PLL_CODES_OFFSET + blocksize, (uint32_t *)(base + blocksize), readsize)) { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4754 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 4755 | return -1; |
| 4756 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4757 | |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4758 | fbcon_extract_to_screen(header, (base + LOGO_IMG_HEADER_SIZE)); |
| 4759 | } else { /* 2 Raw BGR data */ |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4760 | |
Veera Sundaram Sankaran | c33416f | 2015-09-28 10:25:55 -0700 | [diff] [blame] | 4761 | if ((header->width > fb_display->width) || (header->height > fb_display->height)) { |
| 4762 | 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] | 4763 | return -1; |
| 4764 | } |
| 4765 | |
| 4766 | realsize = header->width * header->height * fb_display->bpp / 8; |
| 4767 | readsize = ROUNDUP((realsize + LOGO_IMG_HEADER_SIZE), blocksize) - blocksize; |
| 4768 | |
| 4769 | if (blocksize == LOGO_IMG_HEADER_SIZE) { /* read the content directly */ |
Kishor PK | ee5c0a3 | 2018-03-06 16:49:46 +0530 | [diff] [blame] | 4770 | if (mmc_read((ptn + PLL_CODES_OFFSET + LOGO_IMG_HEADER_SIZE), (uint32_t *)base, readsize)) { |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4771 | fbcon_clear(); |
| 4772 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 4773 | return -1; |
| 4774 | } |
| 4775 | } else { |
Kishor PK | ee5c0a3 | 2018-03-06 16:49:46 +0530 | [diff] [blame] | 4776 | if (mmc_read(ptn + PLL_CODES_OFFSET + blocksize , |
Mao Flynn | 1893a7f | 2015-06-03 12:03:36 +0800 | [diff] [blame] | 4777 | (uint32_t *)(base + LOGO_IMG_OFFSET + blocksize), readsize)) { |
| 4778 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
| 4779 | return -1; |
| 4780 | } |
| 4781 | memmove(base, (base + LOGO_IMG_OFFSET + LOGO_IMG_HEADER_SIZE), realsize); |
| 4782 | } |
| 4783 | } |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4784 | } |
| 4785 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4786 | return 0; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4787 | } |
| 4788 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 4789 | int fetch_image_from_partition() |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 4790 | { |
| 4791 | if (target_is_emmc_boot()) { |
| 4792 | return splash_screen_mmc(); |
| 4793 | } else { |
| 4794 | return splash_screen_flash(); |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 4795 | } |
| 4796 | } |
| 4797 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4798 | void publish_getvar_multislot_vars() |
| 4799 | { |
| 4800 | int i,count; |
| 4801 | static bool published = false; |
| 4802 | static char slot_count[MAX_RSP_SIZE]; |
| 4803 | static struct ab_slot_info slot_info[AB_SUPPORTED_SLOTS]; |
| 4804 | static char active_slot_suffix[MAX_RSP_SIZE]; |
| 4805 | static char has_slot_pname[NUM_PARTITIONS][MAX_GET_VAR_NAME_SIZE]; |
| 4806 | static char has_slot_reply[NUM_PARTITIONS][MAX_RSP_SIZE]; |
| 4807 | const char *tmp; |
| 4808 | char tmpbuff[MAX_GET_VAR_NAME_SIZE]; |
Mayank Grover | 2bd84bb | 2017-06-20 11:06:07 +0530 | [diff] [blame] | 4809 | signed active_slt; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4810 | |
| 4811 | if (!published) |
| 4812 | { |
| 4813 | /* Update slot meta info */ |
| 4814 | count = partition_fill_partition_meta(has_slot_pname, has_slot_reply, |
| 4815 | partition_get_partition_count()); |
| 4816 | for(i=0; i<count; i++) |
| 4817 | { |
| 4818 | memset(tmpbuff, 0, MAX_GET_VAR_NAME_SIZE); |
Mayank Grover | 2bd84bb | 2017-06-20 11:06:07 +0530 | [diff] [blame] | 4819 | snprintf(tmpbuff, MAX_GET_VAR_NAME_SIZE,"has-slot:%s", |
| 4820 | has_slot_pname[i]); |
| 4821 | strlcpy(has_slot_pname[i], tmpbuff, MAX_GET_VAR_NAME_SIZE); |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4822 | fastboot_publish(has_slot_pname[i], has_slot_reply[i]); |
| 4823 | } |
| 4824 | |
| 4825 | for (i=0; i<AB_SUPPORTED_SLOTS; i++) |
| 4826 | { |
| 4827 | tmp = SUFFIX_SLOT(i); |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 4828 | tmp++; // to remove "_" from slot_suffix. |
Mayank Grover | 2bd84bb | 2017-06-20 11:06:07 +0530 | [diff] [blame] | 4829 | snprintf(slot_info[i].slot_is_unbootable, sizeof(slot_info[i].slot_is_unbootable), |
| 4830 | "slot-unbootable:%s", tmp); |
| 4831 | snprintf(slot_info[i].slot_is_active, sizeof(slot_info[i].slot_is_active), |
| 4832 | "slot-active:%s", tmp); |
| 4833 | snprintf(slot_info[i].slot_is_succesful, sizeof(slot_info[i].slot_is_succesful), |
| 4834 | "slot-success:%s", tmp); |
| 4835 | snprintf(slot_info[i].slot_retry_count, sizeof(slot_info[i].slot_retry_count), |
| 4836 | "slot-retry-count:%s", tmp); |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4837 | fastboot_publish(slot_info[i].slot_is_unbootable, |
| 4838 | slot_info[i].slot_is_unbootable_rsp); |
| 4839 | fastboot_publish(slot_info[i].slot_is_active, |
| 4840 | slot_info[i].slot_is_active_rsp); |
| 4841 | fastboot_publish(slot_info[i].slot_is_succesful, |
| 4842 | slot_info[i].slot_is_succesful_rsp); |
| 4843 | fastboot_publish(slot_info[i].slot_retry_count, |
| 4844 | slot_info[i].slot_retry_count_rsp); |
| 4845 | } |
| 4846 | fastboot_publish("current-slot", active_slot_suffix); |
| 4847 | snprintf(slot_count, sizeof(slot_count),"%d", AB_SUPPORTED_SLOTS); |
| 4848 | fastboot_publish("slot-count", slot_count); |
| 4849 | published = true; |
| 4850 | } |
| 4851 | |
Mayank Grover | 2bd84bb | 2017-06-20 11:06:07 +0530 | [diff] [blame] | 4852 | active_slt = partition_find_active_slot(); |
| 4853 | if (active_slt != INVALID) |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 4854 | { |
| 4855 | tmp = SUFFIX_SLOT(active_slt); |
| 4856 | tmp++; // to remove "_" from slot_suffix. |
| 4857 | snprintf(active_slot_suffix, sizeof(active_slot_suffix), "%s", tmp); |
| 4858 | } |
Mayank Grover | 2bd84bb | 2017-06-20 11:06:07 +0530 | [diff] [blame] | 4859 | else |
| 4860 | strlcpy(active_slot_suffix, "INVALID", sizeof(active_slot_suffix)); |
| 4861 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4862 | /* Update partition meta information */ |
| 4863 | partition_fill_slot_meta(slot_info); |
| 4864 | return; |
| 4865 | } |
| 4866 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4867 | void get_product_name(unsigned char *buf) |
| 4868 | { |
| 4869 | snprintf((char*)buf, MAX_RSP_SIZE, "%s", TARGET(BOARD)); |
| 4870 | return; |
| 4871 | } |
| 4872 | |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 4873 | #if PRODUCT_IOT |
| 4874 | void get_bootloader_version_iot(unsigned char *buf) |
| 4875 | { |
| 4876 | if (buf != NULL) |
| 4877 | { |
| 4878 | strlcpy(buf, TARGET(BOARD), MAX_VERSION_LEN); |
| 4879 | strlcat(buf, "-", MAX_VERSION_LEN); |
| 4880 | strlcat(buf, PRODUCT_IOT_VERSION, MAX_VERSION_LEN); |
| 4881 | } |
| 4882 | return; |
| 4883 | } |
| 4884 | #endif |
| 4885 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4886 | void get_bootloader_version(unsigned char *buf) |
| 4887 | { |
| 4888 | snprintf((char*)buf, MAX_RSP_SIZE, "%s", device.bootloader_version); |
| 4889 | return; |
| 4890 | } |
| 4891 | |
| 4892 | void get_baseband_version(unsigned char *buf) |
| 4893 | { |
| 4894 | snprintf((char*)buf, MAX_RSP_SIZE, "%s", device.radio_version); |
| 4895 | return; |
| 4896 | } |
| 4897 | |
Monika Singh | 32a09f7 | 2018-03-14 13:08:29 +0530 | [diff] [blame] | 4898 | bool is_device_locked_critical() |
| 4899 | { |
| 4900 | return device.is_unlock_critical ? false:true; |
| 4901 | } |
| 4902 | |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 4903 | bool is_device_locked() |
| 4904 | { |
| 4905 | return device.is_unlocked ? false:true; |
| 4906 | } |
| 4907 | |
Monika Singh | 32a09f7 | 2018-03-14 13:08:29 +0530 | [diff] [blame] | 4908 | bool is_verity_enforcing() |
| 4909 | { |
| 4910 | return device.verity_mode ? true:false; |
| 4911 | } |
| 4912 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 4913 | /* register commands and variables for fastboot */ |
| 4914 | void aboot_fastboot_register_commands(void) |
| 4915 | { |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 4916 | int i; |
lijuang | f16461c | 2015-08-03 17:09:34 +0800 | [diff] [blame] | 4917 | char hw_platform_buf[MAX_RSP_SIZE]; |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 4918 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 4919 | struct fastboot_cmd_desc cmd_list[] = { |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4920 | /* By default the enabled list is empty. */ |
| 4921 | {"", NULL}, |
| 4922 | /* move commands enclosed within the below ifndef to here |
| 4923 | * if they need to be enabled in user build. |
| 4924 | */ |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 4925 | #ifndef DISABLE_FASTBOOT_CMDS |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4926 | /* Register the following commands only for non-user builds */ |
| 4927 | {"flash:", cmd_flash}, |
| 4928 | {"erase:", cmd_erase}, |
| 4929 | {"boot", cmd_boot}, |
| 4930 | {"continue", cmd_continue}, |
| 4931 | {"reboot", cmd_reboot}, |
| 4932 | {"reboot-bootloader", cmd_reboot_bootloader}, |
| 4933 | {"oem unlock", cmd_oem_unlock}, |
| 4934 | {"oem unlock-go", cmd_oem_unlock_go}, |
| 4935 | {"oem lock", cmd_oem_lock}, |
| 4936 | {"flashing unlock", cmd_oem_unlock}, |
| 4937 | {"flashing lock", cmd_oem_lock}, |
| 4938 | {"flashing lock_critical", cmd_flashing_lock_critical}, |
| 4939 | {"flashing unlock_critical", cmd_flashing_unlock_critical}, |
| 4940 | {"flashing get_unlock_ability", cmd_flashing_get_unlock_ability}, |
| 4941 | {"oem device-info", cmd_oem_devinfo}, |
| 4942 | {"preflash", cmd_preflash}, |
| 4943 | {"oem enable-charger-screen", cmd_oem_enable_charger_screen}, |
| 4944 | {"oem disable-charger-screen", cmd_oem_disable_charger_screen}, |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 4945 | {"oem off-mode-charge", cmd_oem_off_mode_charger}, |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4946 | {"oem select-display-panel", cmd_oem_select_display_panel}, |
Mayank Grover | 6ccc1c9 | 2017-07-04 17:36:46 +0530 | [diff] [blame] | 4947 | {"set_active",cmd_set_active}, |
Mayank Grover | 98c4c74 | 2019-04-25 17:21:37 +0530 | [diff] [blame] | 4948 | #if DYNAMIC_PARTITION_SUPPORT |
| 4949 | {"reboot-fastboot",cmd_reboot_fastboot}, |
| 4950 | {"reboot-recovery",cmd_reboot_recovery}, |
| 4951 | #endif |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 4952 | #if UNITTEST_FW_SUPPORT |
Channagoud Kadabi | d5ddf48 | 2015-09-28 10:31:35 -0700 | [diff] [blame] | 4953 | {"oem run-tests", cmd_oem_runtests}, |
Channagoud Kadabi | 736c496 | 2015-08-21 11:56:52 -0700 | [diff] [blame] | 4954 | #endif |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 4955 | #endif |
lijuang | 511a2b5 | 2015-08-14 20:50:51 +0800 | [diff] [blame] | 4956 | }; |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 4957 | |
| 4958 | int fastboot_cmds_count = sizeof(cmd_list)/sizeof(cmd_list[0]); |
| 4959 | for (i = 1; i < fastboot_cmds_count; i++) |
| 4960 | fastboot_register(cmd_list[i].name,cmd_list[i].cb); |
| 4961 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 4962 | /* publish variables and their values */ |
| 4963 | fastboot_publish("product", TARGET(BOARD)); |
| 4964 | fastboot_publish("kernel", "lk"); |
| 4965 | fastboot_publish("serialno", sn_buf); |
| 4966 | |
Mayank Grover | a64dfbe | 2018-05-17 14:06:34 +0530 | [diff] [blame] | 4967 | /*publish hw-revision major(upper 16 bits) and minor(lower 16 bits)*/ |
| 4968 | snprintf(soc_version_str, MAX_RSP_SIZE, "%x", board_soc_version()); |
| 4969 | fastboot_publish("hw-revision", soc_version_str); |
| 4970 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 4971 | /* |
| 4972 | * partition info is supported only for emmc partitions |
| 4973 | * Calling this for NAND prints some error messages which |
| 4974 | * is harmless but misleading. Avoid calling this for NAND |
| 4975 | * devices. |
| 4976 | */ |
| 4977 | if (target_is_emmc_boot()) |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 4978 | publish_getvar_partition_info(part_info, partition_get_partition_count()); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 4979 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 4980 | if (partition_multislot_is_supported()) |
| 4981 | publish_getvar_multislot_vars(); |
| 4982 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 4983 | /* Max download size supported */ |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 4984 | snprintf(max_download_size, MAX_RSP_SIZE, "\t0x%x", |
| 4985 | target_get_max_flash_size()); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 4986 | fastboot_publish("max-download-size", (const char *) max_download_size); |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 4987 | /* Is the charger screen check enabled */ |
| 4988 | snprintf(charger_screen_enabled, MAX_RSP_SIZE, "%d", |
| 4989 | device.charger_screen_enabled); |
| 4990 | fastboot_publish("charger-screen-enabled", |
| 4991 | (const char *) charger_screen_enabled); |
lijuang | a25d8bb | 2015-09-16 13:11:52 +0800 | [diff] [blame] | 4992 | fastboot_publish("off-mode-charge", (const char *) charger_screen_enabled); |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 4993 | snprintf(panel_display_mode, MAX_RSP_SIZE, "%s", |
| 4994 | device.display_panel); |
| 4995 | fastboot_publish("display-panel", |
| 4996 | (const char *) panel_display_mode); |
Mukesh Ojha | bb6e7f3 | 2018-03-02 15:04:06 +0530 | [diff] [blame] | 4997 | |
| 4998 | if (target_is_emmc_boot()) |
| 4999 | { |
| 5000 | mmc_blocksize = mmc_get_device_blocksize(); |
| 5001 | } |
| 5002 | else |
| 5003 | { |
| 5004 | mmc_blocksize = flash_block_size(); |
| 5005 | } |
| 5006 | snprintf(block_size_string, MAX_RSP_SIZE, "0x%x", mmc_blocksize); |
| 5007 | fastboot_publish("erase-block-size", (const char *) block_size_string); |
| 5008 | fastboot_publish("logical-block-size", (const char *) block_size_string); |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 5009 | #if PRODUCT_IOT |
| 5010 | get_bootloader_version_iot(&bootloader_version_string); |
| 5011 | fastboot_publish("version-bootloader", (const char *) bootloader_version_string); |
| 5012 | |
| 5013 | /* Version baseband is n/a for apq iot devices */ |
| 5014 | fastboot_publish("version-baseband", "N/A"); |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 5015 | #else |
Channagoud Kadabi | aafbbfc | 2015-03-04 17:52:56 -0800 | [diff] [blame] | 5016 | fastboot_publish("version-bootloader", (const char *) device.bootloader_version); |
| 5017 | fastboot_publish("version-baseband", (const char *) device.radio_version); |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 5018 | #endif |
lijuang | f16461c | 2015-08-03 17:09:34 +0800 | [diff] [blame] | 5019 | fastboot_publish("secure", is_secure_boot_enable()? "yes":"no"); |
Mayank Grover | 7b8a8f8 | 2017-10-27 13:07:59 +0530 | [diff] [blame] | 5020 | fastboot_publish("unlocked", device.is_unlocked ? "yes":"no"); |
lijuang | f16461c | 2015-08-03 17:09:34 +0800 | [diff] [blame] | 5021 | smem_get_hw_platform_name((unsigned char *) hw_platform_buf, sizeof(hw_platform_buf)); |
| 5022 | snprintf(get_variant, MAX_RSP_SIZE, "%s %s", hw_platform_buf, |
| 5023 | target_is_emmc_boot()? "eMMC":"UFS"); |
| 5024 | fastboot_publish("variant", (const char *) get_variant); |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 5025 | #if CHECK_BAT_VOLTAGE |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 5026 | update_battery_status(); |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 5027 | fastboot_publish("battery-voltage", (const char *) battery_voltage); |
lijuang | 102dfa9 | 2015-10-09 18:31:03 +0800 | [diff] [blame] | 5028 | fastboot_publish("battery-soc-ok", (const char *) battery_soc_ok); |
lijuang | 65c5a82 | 2015-08-29 16:35:36 +0800 | [diff] [blame] | 5029 | #endif |
Mayank Grover | 98c4c74 | 2019-04-25 17:21:37 +0530 | [diff] [blame] | 5030 | if (target_dynamic_partition_supported()) |
| 5031 | fastboot_publish("is-userspace", "no"); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 5032 | } |
| 5033 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 5034 | void aboot_init(const struct app_descriptor *app) |
| 5035 | { |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 5036 | unsigned reboot_mode = 0; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5037 | int boot_err_type = 0; |
| 5038 | int boot_slot = INVALID; |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 5039 | |
lijuang | 3983173 | 2016-01-08 17:49:02 +0800 | [diff] [blame] | 5040 | /* Initialise wdog to catch early lk crashes */ |
| 5041 | #if WDOG_SUPPORT |
| 5042 | msm_wdog_init(); |
| 5043 | #endif |
| 5044 | |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 5045 | /* Setup page size information for nv storage */ |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 5046 | if (target_is_emmc_boot()) |
| 5047 | { |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 5048 | page_size = mmc_page_size(); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 5049 | page_mask = page_size - 1; |
Gaurav Nebhwani | 4d2389c | 2016-03-17 21:10:05 +0530 | [diff] [blame] | 5050 | mmc_blocksize = mmc_get_device_blocksize(); |
| 5051 | mmc_blocksize_mask = mmc_blocksize - 1; |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 5052 | } |
| 5053 | else |
| 5054 | { |
| 5055 | page_size = flash_page_size(); |
| 5056 | page_mask = page_size - 1; |
| 5057 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 5058 | ASSERT((MEMBASE + MEMSIZE) > MEMBASE); |
| 5059 | |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 5060 | read_device_info(&device); |
vijay kumar | c65876c | 2015-04-24 13:29:16 +0530 | [diff] [blame] | 5061 | read_allow_oem_unlock(&device); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 5062 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5063 | /* Detect multi-slot support */ |
| 5064 | if (partition_multislot_is_supported()) |
| 5065 | { |
| 5066 | boot_slot = partition_find_active_slot(); |
| 5067 | if (boot_slot == INVALID) |
| 5068 | { |
| 5069 | boot_into_fastboot = true; |
| 5070 | dprintf(INFO, "Active Slot: (INVALID)\n"); |
| 5071 | } |
| 5072 | else |
| 5073 | { |
| 5074 | /* Setting the state of system to boot active slot */ |
| 5075 | partition_mark_active_slot(boot_slot); |
| 5076 | dprintf(INFO, "Active Slot: (%s)\n", SUFFIX_SLOT(boot_slot)); |
| 5077 | } |
| 5078 | } |
| 5079 | |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 5080 | /* Display splash screen if enabled */ |
| 5081 | #if DISPLAY_SPLASH_SCREEN |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 5082 | #if NO_ALARM_DISPLAY |
| 5083 | if (!check_alarm_boot()) { |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 5084 | #endif |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 5085 | dprintf(SPEW, "Display Init: Start\n"); |
Ajay Singh Parmar | a7865a8 | 2015-04-16 21:27:52 -0700 | [diff] [blame] | 5086 | #if DISPLAY_HDMI_PRIMARY |
| 5087 | if (!strlen(device.display_panel)) |
| 5088 | strlcpy(device.display_panel, DISPLAY_PANEL_HDMI, |
| 5089 | sizeof(device.display_panel)); |
| 5090 | #endif |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 5091 | #if ENABLE_WBC |
Channagoud Kadabi | d801ac7 | 2015-08-26 11:21:51 -0700 | [diff] [blame] | 5092 | /* Wait if the display shutdown is in progress */ |
| 5093 | while(pm_app_display_shutdown_in_prgs()); |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 5094 | if (!pm_appsbl_display_init_done()) |
| 5095 | target_display_init(device.display_panel); |
| 5096 | else |
| 5097 | display_image_on_screen(); |
| 5098 | #else |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 5099 | target_display_init(device.display_panel); |
Channagoud Kadabi | 90869ce | 2015-04-27 11:15:14 -0700 | [diff] [blame] | 5100 | #endif |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 5101 | dprintf(SPEW, "Display Init: Done\n"); |
| 5102 | #if NO_ALARM_DISPLAY |
| 5103 | } |
| 5104 | #endif |
| 5105 | #endif |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 5106 | |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 5107 | target_serialno((unsigned char *) sn_buf); |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 5108 | dprintf(SPEW,"serial number: %s\n",sn_buf); |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 5109 | |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 5110 | memset(display_panel_buf, '\0', MAX_PANEL_BUF_SIZE); |
| 5111 | |
Matthew Qin | defd556 | 2014-07-11 18:02:40 +0800 | [diff] [blame] | 5112 | /* |
| 5113 | * Check power off reason if user force reset, |
| 5114 | * if yes phone will do normal boot. |
| 5115 | */ |
| 5116 | if (is_user_force_reset()) |
| 5117 | goto normal_boot; |
| 5118 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 5119 | /* Check if we should do something other than booting up */ |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 5120 | if (keys_get_state(KEY_VOLUMEUP) && keys_get_state(KEY_VOLUMEDOWN)) |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 5121 | { |
Pavel Nedev | a4c9d3a | 2013-05-15 14:42:34 +0300 | [diff] [blame] | 5122 | dprintf(ALWAYS,"dload mode key sequence detected\n"); |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 5123 | reboot_device(EMERGENCY_DLOAD); |
| 5124 | dprintf(CRITICAL,"Failed to reboot into dload mode\n"); |
| 5125 | |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 5126 | boot_into_fastboot = true; |
| 5127 | } |
| 5128 | if (!boot_into_fastboot) |
| 5129 | { |
| 5130 | if (keys_get_state(KEY_HOME) || keys_get_state(KEY_VOLUMEUP)) |
| 5131 | boot_into_recovery = 1; |
| 5132 | if (!boot_into_recovery && |
| 5133 | (keys_get_state(KEY_BACK) || keys_get_state(KEY_VOLUMEDOWN))) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5134 | boot_into_fastboot = true; |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 5135 | } |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 5136 | #if NO_KEYPAD_DRIVER |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 5137 | if (fastboot_trigger()) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5138 | boot_into_fastboot = true; |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 5139 | #endif |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 5140 | |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 5141 | #if USE_PON_REBOOT_REG |
| 5142 | reboot_mode = check_hard_reboot_mode(); |
| 5143 | #else |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 5144 | reboot_mode = check_reboot_mode(); |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 5145 | #endif |
| 5146 | if (reboot_mode == RECOVERY_MODE) |
| 5147 | { |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 5148 | boot_into_recovery = 1; |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 5149 | } |
| 5150 | else if(reboot_mode == FASTBOOT_MODE) |
| 5151 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5152 | boot_into_fastboot = true; |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 5153 | } |
| 5154 | else if(reboot_mode == ALARM_BOOT) |
| 5155 | { |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 5156 | boot_reason_alarm = true; |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 5157 | } |
Monika Singh | b0db4b8 | 2018-09-26 12:18:02 +0530 | [diff] [blame] | 5158 | #if VERIFIED_BOOT || VERIFIED_BOOT_2 |
Mayank Grover | 912eaa6 | 2017-10-26 12:08:53 +0530 | [diff] [blame] | 5159 | else if (VB_M <= target_get_vb_version()) |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 5160 | { |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 5161 | if (reboot_mode == DM_VERITY_ENFORCING) |
| 5162 | { |
| 5163 | device.verity_mode = 1; |
| 5164 | write_device_info(&device); |
| 5165 | } |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 5166 | #if ENABLE_VB_ATTEST |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 5167 | else if (reboot_mode == DM_VERITY_EIO) |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 5168 | #else |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 5169 | else if (reboot_mode == DM_VERITY_LOGGING) |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 5170 | #endif |
Mayank Grover | 889be1b | 2017-09-12 20:12:23 +0530 | [diff] [blame] | 5171 | { |
| 5172 | device.verity_mode = 0; |
| 5173 | write_device_info(&device); |
| 5174 | } |
| 5175 | else if (reboot_mode == DM_VERITY_KEYSCLEAR) |
| 5176 | { |
| 5177 | if(send_delete_keys_to_tz()) |
| 5178 | ASSERT(0); |
| 5179 | } |
Channagoud Kadabi | cfcfcc5 | 2015-08-05 16:23:42 -0700 | [diff] [blame] | 5180 | } |
Parth Dixit | ddbc735 | 2015-10-18 03:13:31 +0530 | [diff] [blame] | 5181 | #endif |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 5182 | |
Matthew Qin | defd556 | 2014-07-11 18:02:40 +0800 | [diff] [blame] | 5183 | normal_boot: |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5184 | if (!boot_into_fastboot) |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 5185 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5186 | if (target_is_emmc_boot()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 5187 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5188 | if(emmc_recovery_init()) |
| 5189 | dprintf(ALWAYS,"error in emmc_recovery_init\n"); |
| 5190 | if(target_use_signed_kernel()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 5191 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5192 | if((device.is_unlocked) || (device.is_tampered)) |
| 5193 | { |
| 5194 | #ifdef TZ_TAMPER_FUSE |
Monika Singh | 9825746 | 2018-06-06 11:28:49 +0530 | [diff] [blame] | 5195 | set_tamper_fuse_cmd(HLOS_IMG_TAMPER_FUSE); |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5196 | #endif |
| 5197 | #if USE_PCOM_SECBOOT |
| 5198 | set_tamper_flag(device.is_tampered); |
| 5199 | #endif |
| 5200 | } |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 5201 | } |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 5202 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5203 | retry_boot: |
| 5204 | /* Trying to boot active partition */ |
| 5205 | if (partition_multislot_is_supported()) |
| 5206 | { |
| 5207 | boot_slot = partition_find_boot_slot(); |
| 5208 | partition_mark_active_slot(boot_slot); |
| 5209 | if (boot_slot == INVALID) |
| 5210 | goto fastboot; |
| 5211 | } |
| 5212 | |
| 5213 | boot_err_type = boot_linux_from_mmc(); |
| 5214 | switch (boot_err_type) |
| 5215 | { |
| 5216 | case ERR_INVALID_PAGE_SIZE: |
| 5217 | case ERR_DT_PARSE: |
| 5218 | case ERR_ABOOT_ADDR_OVERLAP: |
Mayank Grover | 10cabbe | 2017-10-30 19:11:05 +0530 | [diff] [blame] | 5219 | case ERR_INVALID_BOOT_MAGIC: |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5220 | if(partition_multislot_is_supported()) |
Mayank Grover | 10cabbe | 2017-10-30 19:11:05 +0530 | [diff] [blame] | 5221 | { |
| 5222 | /* |
| 5223 | * Deactivate current slot, as it failed to |
| 5224 | * boot, and retry next slot. |
| 5225 | */ |
| 5226 | partition_deactivate_slot(boot_slot); |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5227 | goto retry_boot; |
Mayank Grover | 10cabbe | 2017-10-30 19:11:05 +0530 | [diff] [blame] | 5228 | } |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5229 | else |
| 5230 | break; |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5231 | default: |
| 5232 | break; |
| 5233 | /* going to fastboot menu */ |
| 5234 | } |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 5235 | } |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 5236 | else |
| 5237 | { |
| 5238 | recovery_init(); |
| 5239 | #if USE_PCOM_SECBOOT |
| 5240 | if((device.is_unlocked) || (device.is_tampered)) |
| 5241 | set_tamper_flag(device.is_tampered); |
| 5242 | #endif |
| 5243 | boot_linux_from_flash(); |
| 5244 | } |
| 5245 | dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting " |
| 5246 | "to fastboot mode.\n"); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 5247 | } |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 5248 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5249 | fastboot: |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 5250 | /* We are here means regular boot did not happen. Start fastboot. */ |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 5251 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 5252 | /* register aboot specific fastboot commands */ |
| 5253 | aboot_fastboot_register_commands(); |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 5254 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 5255 | /* dump partition table for debug info */ |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 5256 | partition_dump(); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 5257 | |
| 5258 | /* initialize and start fastboot */ |
Saranya Chidura | 41b3453 | 2018-10-16 12:29:52 +0530 | [diff] [blame] | 5259 | #if !VERIFIED_BOOT_2 |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 5260 | fastboot_init(target_get_scratch_address(), target_get_max_flash_size()); |
Saranya Chidura | 41b3453 | 2018-10-16 12:29:52 +0530 | [diff] [blame] | 5261 | #else |
| 5262 | /* Add salt buffer offset at start of image address to copy VB salt */ |
| 5263 | fastboot_init(ADD_SALT_BUFF_OFFSET(target_get_scratch_address()), |
| 5264 | SUB_SALT_BUFF_OFFSET(target_get_max_flash_size())); |
| 5265 | #endif |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 5266 | #if FBCON_DISPLAY_MSG |
lijuang | 9a7d3b9 | 2015-11-30 14:41:24 +0800 | [diff] [blame] | 5267 | display_fastboot_menu(); |
lijuang | 4ece1e7 | 2015-08-14 21:02:36 +0800 | [diff] [blame] | 5268 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 5269 | } |
| 5270 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 5271 | uint32_t get_page_size() |
| 5272 | { |
| 5273 | return page_size; |
| 5274 | } |
| 5275 | |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 5276 | /* |
| 5277 | * Calculated and save hash (SHA256) for non-signed boot image. |
| 5278 | * |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 5279 | * @param image_addr - Boot image address |
| 5280 | * @param image_size - Size of the boot image |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 5281 | * |
| 5282 | * @return int - 0 on success, negative value on failure. |
| 5283 | */ |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 5284 | 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] | 5285 | { |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 5286 | unsigned int digest[8]; |
| 5287 | #if IMAGE_VERIF_ALGO_SHA1 |
| 5288 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA1; |
| 5289 | #else |
| 5290 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA256; |
| 5291 | #endif |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 5292 | |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 5293 | target_crypto_init_params(); |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 5294 | 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] | 5295 | |
| 5296 | save_kernel_hash_cmd(digest); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 5297 | 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] | 5298 | |
| 5299 | return 0; |
| 5300 | } |
| 5301 | |
Mayank Grover | 351a75e | 2017-05-30 20:06:08 +0530 | [diff] [blame] | 5302 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 5303 | APP_START(aboot) |
| 5304 | .init = aboot_init, |
| 5305 | APP_END |