Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Channagoud Kadabi | a8c623f | 2015-01-13 14:48:48 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2015, The Linux Foundation. All rights reserved. |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 6 | * |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions are met: |
| 9 | * * Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * * Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 14 | * * Neither the name of The Linux Foundation nor |
Chandan Uddaraju | 5fa471a | 2009-12-02 17:31:34 -0800 | [diff] [blame] | 15 | * the names of its contributors may be used to endorse or promote |
| 16 | * products derived from this software without specific prior written |
| 17 | * permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 20 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 22 | * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 26 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 28 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 29 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | * |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <app.h> |
| 34 | #include <debug.h> |
| 35 | #include <arch/arm.h> |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 36 | #include <string.h> |
Channagoud Kadabi | 132ff55 | 2013-04-19 14:34:44 -0700 | [diff] [blame] | 37 | #include <stdlib.h> |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 38 | #include <limits.h> |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 39 | #include <kernel/thread.h> |
| 40 | #include <arch/ops.h> |
| 41 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 42 | #include <dev/flash.h> |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 43 | #include <dev/flash-ubi.h> |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 44 | #include <lib/ptable.h> |
Dima Zavin | b428360 | 2009-01-26 16:36:57 -0800 | [diff] [blame] | 45 | #include <dev/keys.h> |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 46 | #include <dev/fbcon.h> |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 47 | #include <baseband.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 48 | #include <target.h> |
| 49 | #include <mmc.h> |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 50 | #include <partition_parser.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 51 | #include <platform.h> |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 52 | #include <crypto_hash.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 53 | #include <malloc.h> |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 54 | #include <boot_stats.h> |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 55 | #include <sha.h> |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 56 | #include <platform/iomap.h> |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 57 | #include <boot_device.h> |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 58 | #include <boot_verifier.h> |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 59 | #include <image_verify.h> |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 60 | #include <decompress.h> |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 61 | #if USE_RPMB_FOR_DEVINFO |
| 62 | #include <rpmb.h> |
| 63 | #endif |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 64 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 65 | #if DEVICE_TREE |
| 66 | #include <libfdt.h> |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 67 | #include <dev_tree.h> |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 68 | #endif |
| 69 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 70 | #include "image_verify.h" |
Shashank Mittal | 024c033 | 2010-02-03 11:44:00 -0800 | [diff] [blame] | 71 | #include "recovery.h" |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 72 | #include "bootimg.h" |
| 73 | #include "fastboot.h" |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 74 | #include "sparse_format.h" |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 75 | #include "meta_format.h" |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 76 | #include "mmc.h" |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 77 | #include "devinfo.h" |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 78 | #include "board.h" |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 79 | #include "scm.h" |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 80 | #include "mdtp.h" |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 81 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 82 | extern bool target_use_signed_kernel(void); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 83 | extern void platform_uninit(void); |
Channagoud Kadabi | 33defe2 | 2013-06-18 18:35:40 -0700 | [diff] [blame] | 84 | extern void target_uninit(void); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 85 | extern int get_target_boot_params(const char *cmdline, const char *part, |
| 86 | char *buf, int buflen); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 87 | |
| 88 | void write_device_info_mmc(device_info *dev); |
| 89 | void write_device_info_flash(device_info *dev); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 90 | static int aboot_save_boot_hash_mmc(uint32_t image_addr, uint32_t image_size); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 91 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 92 | /* fastboot command function pointer */ |
| 93 | typedef void (*fastboot_cmd_fn) (const char *, void *, unsigned); |
| 94 | |
| 95 | struct fastboot_cmd_desc { |
| 96 | char * name; |
| 97 | fastboot_cmd_fn cb; |
| 98 | }; |
| 99 | |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 100 | #define EXPAND(NAME) #NAME |
| 101 | #define TARGET(NAME) EXPAND(NAME) |
Brian Swetland | 2defe16 | 2009-08-18 14:35:59 -0700 | [diff] [blame] | 102 | |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 103 | #ifdef MEMBASE |
| 104 | #define EMMC_BOOT_IMG_HEADER_ADDR (0xFF000+(MEMBASE)) |
| 105 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 106 | #define EMMC_BOOT_IMG_HEADER_ADDR 0xFF000 |
Ajay Dudani | cd01f9b | 2010-02-23 21:13:04 -0800 | [diff] [blame] | 107 | #endif |
| 108 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 109 | #ifndef MEMSIZE |
| 110 | #define MEMSIZE 1024*1024 |
| 111 | #endif |
| 112 | |
| 113 | #define MAX_TAGS_SIZE 1024 |
| 114 | |
lijuang | 7287580 | 2015-02-10 10:35:12 +0800 | [diff] [blame] | 115 | #define RECOVERY_HARD_RESET_MODE 0x01 |
| 116 | #define FASTBOOT_HARD_RESET_MODE 0x02 |
| 117 | #define RTC_HARD_RESET_MODE 0x03 |
| 118 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 119 | #define RECOVERY_MODE 0x77665502 |
| 120 | #define FASTBOOT_MODE 0x77665500 |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 121 | #define ALARM_BOOT 0x77665503 |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 122 | |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 123 | /* make 4096 as default size to ensure EFS,EXT4's erasing */ |
| 124 | #define DEFAULT_ERASE_SIZE 4096 |
Kuogee Hsieh | 55e92c5 | 2013-12-20 08:34:10 -0800 | [diff] [blame] | 125 | #define MAX_PANEL_BUF_SIZE 128 |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 126 | |
Dhaval Patel | f83d73b | 2014-06-23 16:24:37 -0700 | [diff] [blame] | 127 | #define DISPLAY_DEFAULT_PREFIX "mdss_mdp" |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 128 | #define BOOT_DEV_MAX_LEN 64 |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 129 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 130 | #define IS_ARM64(ptr) (ptr->magic_64 == KERNEL64_HDR_MAGIC) ? true : false |
| 131 | |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 132 | #define ADD_OF(a, b) (UINT_MAX - b > a) ? (a + b) : UINT_MAX |
| 133 | |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 134 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 135 | static const char *emmc_cmdline = " androidboot.bootdevice="; |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 136 | #else |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 137 | static const char *emmc_cmdline = " androidboot.emmc=true"; |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 138 | #endif |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 139 | static const char *usb_sn_cmdline = " androidboot.serialno="; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 140 | static const char *androidboot_mode = " androidboot.mode="; |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 141 | static const char *alarmboot_cmdline = " androidboot.alarmboot=true"; |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 142 | static const char *loglevel = " quiet"; |
Ajay Dudani | ca3a33c | 2011-11-18 08:31:40 -0800 | [diff] [blame] | 143 | static const char *battchg_pause = " androidboot.mode=charger"; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 144 | static const char *auth_kernel = " androidboot.authorized_kernel=true"; |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 145 | static const char *secondary_gpt_enable = " gpt"; |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 146 | static const char *mdtp_activated_flag = " mdtp"; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 147 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 148 | static const char *baseband_apq = " androidboot.baseband=apq"; |
| 149 | static const char *baseband_msm = " androidboot.baseband=msm"; |
| 150 | static const char *baseband_csfb = " androidboot.baseband=csfb"; |
| 151 | static const char *baseband_svlte2a = " androidboot.baseband=svlte2a"; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 152 | static const char *baseband_mdm = " androidboot.baseband=mdm"; |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 153 | static const char *baseband_mdm2 = " androidboot.baseband=mdm2"; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 154 | static const char *baseband_sglte = " androidboot.baseband=sglte"; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 155 | static const char *baseband_dsda = " androidboot.baseband=dsda"; |
| 156 | static const char *baseband_dsda2 = " androidboot.baseband=dsda2"; |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 157 | static const char *baseband_sglte2 = " androidboot.baseband=sglte2"; |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 158 | static const char *warmboot_cmdline = " qpnp-power-on.warm_boot=1"; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 159 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 160 | static unsigned page_size = 0; |
| 161 | static unsigned page_mask = 0; |
| 162 | static char ffbm_mode_string[FFBM_MODE_BUF_SIZE]; |
| 163 | static bool boot_into_ffbm; |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 164 | static char target_boot_params[64]; |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 165 | static bool boot_reason_alarm; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 166 | static bool devinfo_present = true; |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 167 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 168 | /* Assuming unauthorized kernel image by default */ |
| 169 | static int auth_kernel_img = 0; |
| 170 | |
Channagoud Kadabi | aafbbfc | 2015-03-04 17:52:56 -0800 | [diff] [blame] | 171 | static device_info device = {DEVICE_MAGIC, 0, 0, 0, 0, {0}, {0},{0}}; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 172 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 173 | struct atag_ptbl_entry |
| 174 | { |
| 175 | char name[16]; |
| 176 | unsigned offset; |
| 177 | unsigned size; |
| 178 | unsigned flags; |
| 179 | }; |
| 180 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 181 | /* |
| 182 | * Partition info, required to be published |
| 183 | * for fastboot |
| 184 | */ |
| 185 | struct getvar_partition_info { |
| 186 | const char part_name[MAX_GPT_NAME_SIZE]; /* Partition name */ |
| 187 | char getvar_size[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for size */ |
| 188 | char getvar_type[MAX_GET_VAR_NAME_SIZE]; /* fastboot get var name for type */ |
| 189 | char size_response[MAX_RSP_SIZE]; /* fastboot response for size */ |
| 190 | char type_response[MAX_RSP_SIZE]; /* fastboot response for type */ |
| 191 | }; |
| 192 | |
| 193 | /* |
| 194 | * Right now, we are publishing the info for only |
| 195 | * three partitions |
| 196 | */ |
| 197 | struct getvar_partition_info part_info[] = |
| 198 | { |
| 199 | { "system" , "partition-size:", "partition-type:", "", "ext4" }, |
| 200 | { "userdata", "partition-size:", "partition-type:", "", "ext4" }, |
| 201 | { "cache" , "partition-size:", "partition-type:", "", "ext4" }, |
| 202 | }; |
| 203 | |
| 204 | char max_download_size[MAX_RSP_SIZE]; |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 205 | char charger_screen_enabled[MAX_RSP_SIZE]; |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 206 | char sn_buf[13]; |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 207 | char display_panel_buf[MAX_PANEL_BUF_SIZE]; |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 208 | char panel_display_mode[MAX_RSP_SIZE]; |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 209 | |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 210 | extern int emmc_recovery_init(void); |
| 211 | |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 212 | #if NO_KEYPAD_DRIVER |
| 213 | extern int fastboot_trigger(void); |
| 214 | #endif |
Greg Grisco | d2471ef | 2011-07-14 13:00:42 -0700 | [diff] [blame] | 215 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 216 | static void update_ker_tags_rdisk_addr(struct boot_img_hdr *hdr, bool is_arm64) |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 217 | { |
| 218 | /* overwrite the destination of specified for the project */ |
Channagoud Kadabi | 7042fa3 | 2013-04-26 16:44:14 -0700 | [diff] [blame] | 219 | #ifdef ABOOT_IGNORE_BOOT_HEADER_ADDRS |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 220 | if (is_arm64) |
| 221 | hdr->kernel_addr = ABOOT_FORCE_KERNEL64_ADDR; |
| 222 | else |
| 223 | hdr->kernel_addr = ABOOT_FORCE_KERNEL_ADDR; |
Channagoud Kadabi | 7042fa3 | 2013-04-26 16:44:14 -0700 | [diff] [blame] | 224 | hdr->ramdisk_addr = ABOOT_FORCE_RAMDISK_ADDR; |
| 225 | hdr->tags_addr = ABOOT_FORCE_TAGS_ADDR; |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 226 | #endif |
| 227 | } |
| 228 | |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 229 | static void ptentry_to_tag(unsigned **ptr, struct ptentry *ptn) |
| 230 | { |
| 231 | struct atag_ptbl_entry atag_ptn; |
| 232 | |
| 233 | memcpy(atag_ptn.name, ptn->name, 16); |
| 234 | atag_ptn.name[15] = '\0'; |
| 235 | atag_ptn.offset = ptn->start; |
| 236 | atag_ptn.size = ptn->length; |
| 237 | atag_ptn.flags = ptn->flags; |
| 238 | memcpy(*ptr, &atag_ptn, sizeof(struct atag_ptbl_entry)); |
| 239 | *ptr += sizeof(struct atag_ptbl_entry) / sizeof(unsigned); |
| 240 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 241 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 242 | unsigned char *update_cmdline(const char * cmdline) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 243 | { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 244 | int cmdline_len = 0; |
| 245 | int have_cmdline = 0; |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 246 | unsigned char *cmdline_final = NULL; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 247 | int pause_at_bootup = 0; |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 248 | bool warm_boot = false; |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 249 | bool gpt_exists = partition_gpt_exists(); |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 250 | int have_target_boot_params = 0; |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 251 | char *boot_dev_buf = NULL; |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 252 | bool is_mdtp_activated = 0; |
| 253 | #ifdef MDTP_SUPPORT |
| 254 | mdtp_activated(&is_mdtp_activated); |
| 255 | #endif /* MDTP_SUPPORT */ |
Dima Zavin | 42168f2 | 2009-01-30 11:52:22 -0800 | [diff] [blame] | 256 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 257 | if (cmdline && cmdline[0]) { |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 258 | cmdline_len = strlen(cmdline); |
| 259 | have_cmdline = 1; |
| 260 | } |
| 261 | if (target_is_emmc_boot()) { |
| 262 | cmdline_len += strlen(emmc_cmdline); |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 263 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 264 | boot_dev_buf = (char *) malloc(sizeof(char) * BOOT_DEV_MAX_LEN); |
| 265 | ASSERT(boot_dev_buf); |
| 266 | platform_boot_dev_cmdline(boot_dev_buf); |
| 267 | cmdline_len += strlen(boot_dev_buf); |
Sundarajan Srinivasan | 3827a10 | 2013-09-10 13:57:40 -0700 | [diff] [blame] | 268 | #endif |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 269 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 270 | |
| 271 | cmdline_len += strlen(usb_sn_cmdline); |
| 272 | cmdline_len += strlen(sn_buf); |
| 273 | |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 274 | if (boot_into_recovery && gpt_exists) |
| 275 | cmdline_len += strlen(secondary_gpt_enable); |
| 276 | |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 277 | if(is_mdtp_activated) |
| 278 | cmdline_len += strlen(mdtp_activated_flag); |
| 279 | |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 280 | if (boot_into_ffbm) { |
| 281 | cmdline_len += strlen(androidboot_mode); |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 282 | cmdline_len += strlen(ffbm_mode_string); |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 283 | /* reduce kernel console messages to speed-up boot */ |
| 284 | cmdline_len += strlen(loglevel); |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 285 | } else if (boot_reason_alarm) { |
| 286 | cmdline_len += strlen(alarmboot_cmdline); |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 287 | } else if (device.charger_screen_enabled && |
| 288 | target_pause_for_battery_charge()) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 289 | pause_at_bootup = 1; |
| 290 | cmdline_len += strlen(battchg_pause); |
| 291 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 292 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 293 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 294 | cmdline_len += strlen(auth_kernel); |
| 295 | } |
| 296 | |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 297 | if (get_target_boot_params(cmdline, boot_into_recovery ? "recoveryfs" : |
| 298 | "system", |
| 299 | target_boot_params, |
| 300 | sizeof(target_boot_params)) == 0) { |
| 301 | have_target_boot_params = 1; |
| 302 | cmdline_len += strlen(target_boot_params); |
| 303 | } |
| 304 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 305 | /* Determine correct androidboot.baseband to use */ |
| 306 | switch(target_baseband()) |
| 307 | { |
| 308 | case BASEBAND_APQ: |
| 309 | cmdline_len += strlen(baseband_apq); |
| 310 | break; |
| 311 | |
| 312 | case BASEBAND_MSM: |
| 313 | cmdline_len += strlen(baseband_msm); |
| 314 | break; |
| 315 | |
| 316 | case BASEBAND_CSFB: |
| 317 | cmdline_len += strlen(baseband_csfb); |
| 318 | break; |
| 319 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 320 | case BASEBAND_SVLTE2A: |
| 321 | cmdline_len += strlen(baseband_svlte2a); |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 322 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 323 | |
| 324 | case BASEBAND_MDM: |
| 325 | cmdline_len += strlen(baseband_mdm); |
| 326 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 327 | |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 328 | case BASEBAND_MDM2: |
| 329 | cmdline_len += strlen(baseband_mdm2); |
| 330 | break; |
| 331 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 332 | case BASEBAND_SGLTE: |
| 333 | cmdline_len += strlen(baseband_sglte); |
| 334 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 335 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 336 | case BASEBAND_SGLTE2: |
| 337 | cmdline_len += strlen(baseband_sglte2); |
| 338 | break; |
| 339 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 340 | case BASEBAND_DSDA: |
| 341 | cmdline_len += strlen(baseband_dsda); |
| 342 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 343 | |
| 344 | case BASEBAND_DSDA2: |
| 345 | cmdline_len += strlen(baseband_dsda2); |
| 346 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 347 | } |
| 348 | |
Lijuan Gao | 4a5b832 | 2014-07-24 10:38:42 +0800 | [diff] [blame] | 349 | if (cmdline) { |
| 350 | if ((strstr(cmdline, DISPLAY_DEFAULT_PREFIX) == NULL) && |
| 351 | target_display_panel_node(device.display_panel, |
| 352 | display_panel_buf, MAX_PANEL_BUF_SIZE) && |
| 353 | strlen(display_panel_buf)) { |
| 354 | cmdline_len += strlen(display_panel_buf); |
| 355 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 358 | if (target_warm_boot()) { |
| 359 | warm_boot = true; |
| 360 | cmdline_len += strlen(warmboot_cmdline); |
| 361 | } |
| 362 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 363 | if (cmdline_len > 0) { |
| 364 | const char *src; |
Maria Yu | 52254c0 | 2014-07-04 16:14:54 +0800 | [diff] [blame] | 365 | unsigned char *dst; |
| 366 | |
| 367 | cmdline_final = (unsigned char*) malloc((cmdline_len + 4) & (~3)); |
| 368 | ASSERT(cmdline_final != NULL); |
| 369 | dst = cmdline_final; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 370 | |
Amol Jadi | 168b771 | 2012-03-06 16:15:00 -0800 | [diff] [blame] | 371 | /* Save start ptr for debug print */ |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 372 | if (have_cmdline) { |
| 373 | src = cmdline; |
| 374 | while ((*dst++ = *src++)); |
| 375 | } |
| 376 | if (target_is_emmc_boot()) { |
| 377 | src = emmc_cmdline; |
| 378 | if (have_cmdline) --dst; |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 379 | have_cmdline = 1; |
| 380 | while ((*dst++ = *src++)); |
Sridhar Parasuram | 7bd4aaf | 2015-02-12 11:14:38 -0800 | [diff] [blame] | 381 | #if USE_BOOTDEV_CMDLINE |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 382 | src = boot_dev_buf; |
| 383 | if (have_cmdline) --dst; |
| 384 | while ((*dst++ = *src++)); |
| 385 | #endif |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 386 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 387 | |
| 388 | src = usb_sn_cmdline; |
| 389 | if (have_cmdline) --dst; |
| 390 | have_cmdline = 1; |
| 391 | while ((*dst++ = *src++)); |
| 392 | src = sn_buf; |
| 393 | if (have_cmdline) --dst; |
| 394 | have_cmdline = 1; |
| 395 | while ((*dst++ = *src++)); |
Hanumant Singh | 8e1ac23 | 2014-01-29 13:41:51 -0800 | [diff] [blame] | 396 | if (warm_boot) { |
| 397 | if (have_cmdline) --dst; |
| 398 | src = warmboot_cmdline; |
| 399 | while ((*dst++ = *src++)); |
| 400 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 401 | |
Pavel Nedev | 5614d22 | 2013-06-17 18:01:02 +0300 | [diff] [blame] | 402 | if (boot_into_recovery && gpt_exists) { |
| 403 | src = secondary_gpt_enable; |
| 404 | if (have_cmdline) --dst; |
| 405 | while ((*dst++ = *src++)); |
| 406 | } |
| 407 | |
Shay Nachmani | bc10dfe | 2015-02-10 14:45:55 +0200 | [diff] [blame] | 408 | if (is_mdtp_activated) { |
| 409 | src = mdtp_activated_flag; |
| 410 | if (have_cmdline) --dst; |
| 411 | while ((*dst++ = *src++)); |
| 412 | } |
| 413 | |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 414 | if (boot_into_ffbm) { |
| 415 | src = androidboot_mode; |
| 416 | if (have_cmdline) --dst; |
| 417 | while ((*dst++ = *src++)); |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 418 | src = ffbm_mode_string; |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 419 | if (have_cmdline) --dst; |
| 420 | while ((*dst++ = *src++)); |
Pavel Nedev | 898298c | 2013-02-27 12:36:09 -0800 | [diff] [blame] | 421 | src = loglevel; |
| 422 | if (have_cmdline) --dst; |
| 423 | while ((*dst++ = *src++)); |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 424 | } else if (boot_reason_alarm) { |
| 425 | src = alarmboot_cmdline; |
| 426 | if (have_cmdline) --dst; |
| 427 | while ((*dst++ = *src++)); |
Pavel Nedev | 328ac82 | 2013-04-05 15:25:11 +0300 | [diff] [blame] | 428 | } else if (pause_at_bootup) { |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 429 | src = battchg_pause; |
| 430 | if (have_cmdline) --dst; |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 431 | while ((*dst++ = *src++)); |
| 432 | } |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 433 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 434 | if(target_use_signed_kernel() && auth_kernel_img) { |
| 435 | src = auth_kernel; |
| 436 | if (have_cmdline) --dst; |
| 437 | while ((*dst++ = *src++)); |
| 438 | } |
| 439 | |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 440 | switch(target_baseband()) |
| 441 | { |
| 442 | case BASEBAND_APQ: |
| 443 | src = baseband_apq; |
| 444 | if (have_cmdline) --dst; |
| 445 | while ((*dst++ = *src++)); |
| 446 | break; |
| 447 | |
| 448 | case BASEBAND_MSM: |
| 449 | src = baseband_msm; |
| 450 | if (have_cmdline) --dst; |
| 451 | while ((*dst++ = *src++)); |
| 452 | break; |
| 453 | |
| 454 | case BASEBAND_CSFB: |
| 455 | src = baseband_csfb; |
| 456 | if (have_cmdline) --dst; |
| 457 | while ((*dst++ = *src++)); |
| 458 | break; |
| 459 | |
Ajay Dudani | 6cff85e | 2011-02-04 16:02:16 -0800 | [diff] [blame] | 460 | case BASEBAND_SVLTE2A: |
| 461 | src = baseband_svlte2a; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 462 | if (have_cmdline) --dst; |
| 463 | while ((*dst++ = *src++)); |
| 464 | break; |
Ajay Dudani | 403bc49 | 2011-09-30 16:17:21 -0700 | [diff] [blame] | 465 | |
| 466 | case BASEBAND_MDM: |
| 467 | src = baseband_mdm; |
| 468 | if (have_cmdline) --dst; |
| 469 | while ((*dst++ = *src++)); |
| 470 | break; |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 471 | |
Sundarajan Srinivasan | aaa8aff | 2013-11-12 17:19:14 -0800 | [diff] [blame] | 472 | case BASEBAND_MDM2: |
| 473 | src = baseband_mdm2; |
| 474 | if (have_cmdline) --dst; |
| 475 | while ((*dst++ = *src++)); |
| 476 | break; |
| 477 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 478 | case BASEBAND_SGLTE: |
| 479 | src = baseband_sglte; |
| 480 | if (have_cmdline) --dst; |
| 481 | while ((*dst++ = *src++)); |
| 482 | break; |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 483 | |
sundarajan srinivasan | f8e9f3f | 2013-03-04 15:56:58 -0800 | [diff] [blame] | 484 | case BASEBAND_SGLTE2: |
| 485 | src = baseband_sglte2; |
| 486 | if (have_cmdline) --dst; |
| 487 | while ((*dst++ = *src++)); |
| 488 | break; |
| 489 | |
Channagoud Kadabi | 141f298 | 2012-10-31 11:23:02 +0530 | [diff] [blame] | 490 | case BASEBAND_DSDA: |
| 491 | src = baseband_dsda; |
| 492 | if (have_cmdline) --dst; |
| 493 | while ((*dst++ = *src++)); |
| 494 | break; |
Amol Jadi | 2a15a27 | 2013-01-22 12:03:36 -0800 | [diff] [blame] | 495 | |
| 496 | case BASEBAND_DSDA2: |
| 497 | src = baseband_dsda2; |
| 498 | if (have_cmdline) --dst; |
| 499 | while ((*dst++ = *src++)); |
| 500 | break; |
Ajay Dudani | d04110c | 2011-01-17 23:55:07 -0800 | [diff] [blame] | 501 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 502 | |
| 503 | if (strlen(display_panel_buf)) { |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 504 | src = display_panel_buf; |
| 505 | if (have_cmdline) --dst; |
| 506 | while ((*dst++ = *src++)); |
| 507 | } |
Joonwoo Park | 6111278 | 2013-10-02 19:50:39 -0700 | [diff] [blame] | 508 | |
| 509 | if (have_target_boot_params) { |
| 510 | if (have_cmdline) --dst; |
| 511 | src = target_boot_params; |
| 512 | while ((*dst++ = *src++)); |
| 513 | } |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 514 | } |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 515 | |
| 516 | |
Sundarajan Srinivasan | e52065a | 2014-03-20 16:25:59 -0700 | [diff] [blame] | 517 | if (boot_dev_buf) |
| 518 | free(boot_dev_buf); |
| 519 | |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 520 | if (cmdline_final) |
| 521 | dprintf(INFO, "cmdline: %s\n", cmdline_final); |
| 522 | else |
| 523 | dprintf(INFO, "cmdline is NULL\n"); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 524 | return cmdline_final; |
| 525 | } |
| 526 | |
| 527 | unsigned *atag_core(unsigned *ptr) |
| 528 | { |
| 529 | /* CORE */ |
| 530 | *ptr++ = 2; |
| 531 | *ptr++ = 0x54410001; |
| 532 | |
| 533 | return ptr; |
| 534 | |
| 535 | } |
| 536 | |
| 537 | unsigned *atag_ramdisk(unsigned *ptr, void *ramdisk, |
| 538 | unsigned ramdisk_size) |
| 539 | { |
| 540 | if (ramdisk_size) { |
| 541 | *ptr++ = 4; |
| 542 | *ptr++ = 0x54420005; |
| 543 | *ptr++ = (unsigned)ramdisk; |
| 544 | *ptr++ = ramdisk_size; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 547 | return ptr; |
| 548 | } |
| 549 | |
| 550 | unsigned *atag_ptable(unsigned **ptr_addr) |
| 551 | { |
| 552 | int i; |
| 553 | struct ptable *ptable; |
| 554 | |
| 555 | if ((ptable = flash_get_ptable()) && (ptable->count != 0)) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 556 | *(*ptr_addr)++ = 2 + (ptable->count * (sizeof(struct atag_ptbl_entry) / |
| 557 | sizeof(unsigned))); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 558 | *(*ptr_addr)++ = 0x4d534d70; |
| 559 | for (i = 0; i < ptable->count; ++i) |
| 560 | ptentry_to_tag(ptr_addr, ptable_get(ptable, i)); |
| 561 | } |
| 562 | |
| 563 | return (*ptr_addr); |
| 564 | } |
| 565 | |
| 566 | unsigned *atag_cmdline(unsigned *ptr, const char *cmdline) |
| 567 | { |
| 568 | int cmdline_length = 0; |
| 569 | int n; |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 570 | char *dest; |
| 571 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 572 | cmdline_length = strlen((const char*)cmdline); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 573 | n = (cmdline_length + 4) & (~3); |
| 574 | |
| 575 | *ptr++ = (n / 4) + 2; |
| 576 | *ptr++ = 0x54410009; |
| 577 | dest = (char *) ptr; |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 578 | while ((*dest++ = *cmdline++)); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 579 | ptr += (n / 4); |
| 580 | |
| 581 | return ptr; |
| 582 | } |
| 583 | |
| 584 | unsigned *atag_end(unsigned *ptr) |
| 585 | { |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 586 | /* END */ |
| 587 | *ptr++ = 0; |
| 588 | *ptr++ = 0; |
| 589 | |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 590 | return ptr; |
| 591 | } |
| 592 | |
| 593 | void generate_atags(unsigned *ptr, const char *cmdline, |
| 594 | void *ramdisk, unsigned ramdisk_size) |
| 595 | { |
| 596 | |
| 597 | ptr = atag_core(ptr); |
| 598 | ptr = atag_ramdisk(ptr, ramdisk, ramdisk_size); |
| 599 | ptr = target_atag_mem(ptr); |
| 600 | |
| 601 | /* Skip NAND partition ATAGS for eMMC boot */ |
| 602 | if (!target_is_emmc_boot()){ |
| 603 | ptr = atag_ptable(&ptr); |
| 604 | } |
| 605 | |
| 606 | ptr = atag_cmdline(ptr, cmdline); |
| 607 | ptr = atag_end(ptr); |
| 608 | } |
| 609 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 610 | typedef void entry_func_ptr(unsigned, unsigned, unsigned*); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 611 | void boot_linux(void *kernel, unsigned *tags, |
| 612 | const char *cmdline, unsigned machtype, |
| 613 | void *ramdisk, unsigned ramdisk_size) |
| 614 | { |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 615 | unsigned char *final_cmdline; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 616 | #if DEVICE_TREE |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 617 | int ret = 0; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 618 | #endif |
| 619 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 620 | void (*entry)(unsigned, unsigned, unsigned*) = (entry_func_ptr*)(PA((addr_t)kernel)); |
Deepa Dinamani | 25a9f76 | 2012-11-30 15:57:15 -0800 | [diff] [blame] | 621 | uint32_t tags_phys = PA((addr_t)tags); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 622 | struct kernel64_hdr *kptr = (struct kernel64_hdr*)kernel; |
Deepa Dinamani | 25a9f76 | 2012-11-30 15:57:15 -0800 | [diff] [blame] | 623 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 624 | ramdisk = (void *)PA((addr_t)ramdisk); |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 625 | |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 626 | final_cmdline = update_cmdline((const char*)cmdline); |
| 627 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 628 | #if DEVICE_TREE |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 629 | dprintf(INFO, "Updating device tree: start\n"); |
| 630 | |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 631 | /* Update the Device Tree */ |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 632 | 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] | 633 | if(ret) |
| 634 | { |
| 635 | dprintf(CRITICAL, "ERROR: Updating Device Tree Failed \n"); |
| 636 | ASSERT(0); |
| 637 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 638 | dprintf(INFO, "Updating device tree: done\n"); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 639 | #else |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 640 | /* Generating the Atags */ |
Amol Jadi | 10c7d1c | 2013-01-25 13:24:29 -0800 | [diff] [blame] | 641 | generate_atags(tags, final_cmdline, ramdisk, ramdisk_size); |
Neeti Desai | 17379b8 | 2012-06-04 18:42:53 -0700 | [diff] [blame] | 642 | #endif |
Neeti Desai | e245d49 | 2012-06-01 12:52:13 -0700 | [diff] [blame] | 643 | |
Maria Yu | 52254c0 | 2014-07-04 16:14:54 +0800 | [diff] [blame] | 644 | free(final_cmdline); |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 645 | |
| 646 | #if VERIFIED_BOOT |
| 647 | /* Write protect the device info */ |
Channagoud Kadabi | 3bd9d1e | 2015-05-05 16:18:20 -0700 | [diff] [blame] | 648 | 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] | 649 | { |
| 650 | dprintf(INFO, "Failed to write protect dev info\n"); |
| 651 | ASSERT(0); |
| 652 | } |
| 653 | #endif |
| 654 | |
Channagoud Kadabi | 33defe2 | 2013-06-18 18:35:40 -0700 | [diff] [blame] | 655 | /* Perform target specific cleanup */ |
| 656 | target_uninit(); |
| 657 | |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 658 | /* Turn off splash screen if enabled */ |
| 659 | #if DISPLAY_SPLASH_SCREEN |
| 660 | target_display_shutdown(); |
| 661 | #endif |
| 662 | |
| 663 | |
Deepa Dinamani | 33734bc | 2013-03-06 12:16:06 -0800 | [diff] [blame] | 664 | 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] | 665 | entry, ramdisk, ramdisk_size, (void *)tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 666 | |
| 667 | enter_critical_section(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 668 | |
Amol Jadi | 4421e65 | 2011-06-16 15:00:48 -0700 | [diff] [blame] | 669 | /* do any platform specific cleanup before kernel entry */ |
| 670 | platform_uninit(); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 671 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 672 | arch_disable_cache(UCACHE); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 673 | |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 674 | #if ARM_WITH_MMU |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 675 | arch_disable_mmu(); |
Amol Jadi | 504f9fe | 2012-08-16 13:56:48 -0700 | [diff] [blame] | 676 | #endif |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 677 | bs_set_timestamp(BS_KERNEL_ENTRY); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 678 | |
| 679 | if (IS_ARM64(kptr)) |
| 680 | /* Jump to a 64bit kernel */ |
| 681 | scm_elexec_call((paddr_t)kernel, tags_phys); |
| 682 | else |
| 683 | /* Jump to a 32bit kernel */ |
| 684 | entry(0, machtype, (unsigned*)tags_phys); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 685 | } |
| 686 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 687 | /* Function to check if the memory address range falls within the aboot |
| 688 | * boundaries. |
| 689 | * start: Start of the memory region |
| 690 | * size: Size of the memory region |
| 691 | */ |
| 692 | int check_aboot_addr_range_overlap(uint32_t start, uint32_t size) |
| 693 | { |
| 694 | /* Check for boundary conditions. */ |
Sundarajan Srinivasan | ce2a0ea | 2013-12-16 17:02:56 -0800 | [diff] [blame] | 695 | if ((UINT_MAX - start) < size) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 696 | return -1; |
| 697 | |
| 698 | /* Check for memory overlap. */ |
| 699 | if ((start < MEMBASE) && ((start + size) <= MEMBASE)) |
| 700 | return 0; |
Channagoud Kadabi | 9414391 | 2013-10-15 12:53:52 -0700 | [diff] [blame] | 701 | else if (start >= (MEMBASE + MEMSIZE)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 702 | return 0; |
| 703 | else |
| 704 | return -1; |
| 705 | } |
| 706 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 707 | #define ROUND_TO_PAGE(x,y) (((x) + (y)) & (~(y))) |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 708 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 709 | BUF_DMA_ALIGN(buf, BOOT_IMG_MAX_PAGE_SIZE); //Equal to max-supported pagesize |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 710 | #if DEVICE_TREE |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 711 | BUF_DMA_ALIGN(dt_buf, BOOT_IMG_MAX_PAGE_SIZE); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 712 | #endif |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 713 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 714 | static void verify_signed_bootimg(uint32_t bootimg_addr, uint32_t bootimg_size) |
| 715 | { |
| 716 | int ret; |
Channagoud Kadabi | a8c623f | 2015-01-13 14:48:48 -0800 | [diff] [blame] | 717 | |
| 718 | #if !VERIFIED_BOOT |
Sundarajan Srinivasan | ce54d6e | 2013-11-11 12:45:00 -0800 | [diff] [blame] | 719 | #if IMAGE_VERIF_ALGO_SHA1 |
| 720 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA1; |
| 721 | #else |
| 722 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA256; |
| 723 | #endif |
Channagoud Kadabi | a8c623f | 2015-01-13 14:48:48 -0800 | [diff] [blame] | 724 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 725 | |
| 726 | /* Assume device is rooted at this time. */ |
| 727 | device.is_tampered = 1; |
| 728 | |
| 729 | dprintf(INFO, "Authenticating boot image (%d): start\n", bootimg_size); |
| 730 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 731 | #if VERIFIED_BOOT |
| 732 | if(boot_into_recovery) |
| 733 | { |
| 734 | ret = boot_verify_image((unsigned char *)bootimg_addr, |
Unnati Gandhi | 4705125 | 2015-03-02 15:21:09 +0530 | [diff] [blame] | 735 | bootimg_size, "/recovery"); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 736 | } |
| 737 | else |
| 738 | { |
| 739 | ret = boot_verify_image((unsigned char *)bootimg_addr, |
Unnati Gandhi | 4705125 | 2015-03-02 15:21:09 +0530 | [diff] [blame] | 740 | bootimg_size, "/boot"); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 741 | } |
| 742 | boot_verify_print_state(); |
| 743 | #else |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 744 | ret = image_verify((unsigned char *)bootimg_addr, |
| 745 | (unsigned char *)(bootimg_addr + bootimg_size), |
| 746 | bootimg_size, |
Sundarajan Srinivasan | ce54d6e | 2013-11-11 12:45:00 -0800 | [diff] [blame] | 747 | auth_algo); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 748 | #endif |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 749 | dprintf(INFO, "Authenticating boot image: done return value = %d\n", ret); |
| 750 | |
| 751 | if (ret) |
| 752 | { |
| 753 | /* Authorized kernel */ |
| 754 | device.is_tampered = 0; |
Sundarajan Srinivasan | 3fb21f1 | 2013-09-16 18:36:15 -0700 | [diff] [blame] | 755 | auth_kernel_img = 1; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | #if USE_PCOM_SECBOOT |
| 759 | set_tamper_flag(device.is_tampered); |
| 760 | #endif |
| 761 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 762 | #if VERIFIED_BOOT |
| 763 | if(boot_verify_get_state() == RED) |
| 764 | { |
| 765 | if(!boot_into_recovery) |
| 766 | { |
| 767 | dprintf(CRITICAL, |
| 768 | "Device verification failed. Rebooting into recovery.\n"); |
| 769 | reboot_device(RECOVERY_MODE); |
| 770 | } |
| 771 | else |
| 772 | { |
| 773 | dprintf(CRITICAL, |
| 774 | "Recovery image verification failed. Asserting..\n"); |
| 775 | ASSERT(0); |
| 776 | } |
| 777 | } |
| 778 | #endif |
Unnati Gandhi | 1be0475 | 2015-03-27 19:41:53 +0530 | [diff] [blame] | 779 | |
| 780 | if(device.is_tampered) |
| 781 | { |
| 782 | write_device_info_mmc(&device); |
| 783 | #ifdef TZ_TAMPER_FUSE |
| 784 | set_tamper_fuse_cmd(); |
| 785 | #endif |
| 786 | #ifdef ASSERT_ON_TAMPER |
| 787 | dprintf(CRITICAL, "Device is tampered. Asserting..\n"); |
| 788 | ASSERT(0); |
| 789 | #endif |
| 790 | } |
| 791 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 792 | } |
| 793 | |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 794 | static bool check_format_bit() |
| 795 | { |
| 796 | bool ret = false; |
| 797 | int index; |
| 798 | uint64_t offset; |
| 799 | struct boot_selection_info *in = NULL; |
| 800 | char *buf = NULL; |
| 801 | |
| 802 | index = partition_get_index("bootselect"); |
| 803 | if (index == INVALID_PTN) |
| 804 | { |
| 805 | dprintf(INFO, "Unable to locate /bootselect partition\n"); |
| 806 | return ret; |
| 807 | } |
| 808 | offset = partition_get_offset(index); |
| 809 | if(!offset) |
| 810 | { |
| 811 | dprintf(INFO, "partition /bootselect doesn't exist\n"); |
| 812 | return ret; |
| 813 | } |
| 814 | buf = (char *) memalign(CACHE_LINE, ROUNDUP(page_size, CACHE_LINE)); |
| 815 | ASSERT(buf); |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 816 | if (mmc_read(offset, (uint32_t *)buf, page_size)) |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 817 | { |
| 818 | dprintf(INFO, "mmc read failure /bootselect %d\n", page_size); |
| 819 | free(buf); |
| 820 | return ret; |
| 821 | } |
| 822 | in = (struct boot_selection_info *) buf; |
| 823 | if ((in->signature == BOOTSELECT_SIGNATURE) && |
| 824 | (in->version == BOOTSELECT_VERSION)) { |
| 825 | if ((in->state_info & BOOTSELECT_FORMAT) && |
| 826 | !(in->state_info & BOOTSELECT_FACTORY)) |
| 827 | ret = true; |
| 828 | } else { |
| 829 | dprintf(CRITICAL, "Signature: 0x%08x or version: 0x%08x mismatched of /bootselect\n", |
| 830 | in->signature, in->version); |
| 831 | ASSERT(0); |
| 832 | } |
| 833 | free(buf); |
| 834 | return ret; |
| 835 | } |
| 836 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 837 | void boot_verifier_init() |
| 838 | { |
| 839 | |
| 840 | uint32_t boot_state; |
| 841 | /* Check if device unlock */ |
| 842 | if(device.is_unlocked) |
| 843 | { |
| 844 | boot_verify_send_event(DEV_UNLOCK); |
| 845 | boot_verify_print_state(); |
| 846 | dprintf(CRITICAL, "Device is unlocked! Skipping verification...\n"); |
| 847 | return; |
| 848 | } |
| 849 | else |
| 850 | { |
| 851 | boot_verify_send_event(BOOT_INIT); |
| 852 | } |
| 853 | |
| 854 | /* Initialize keystore */ |
| 855 | boot_state = boot_verify_keystore_init(); |
| 856 | if(boot_state == YELLOW) |
| 857 | { |
| 858 | boot_verify_print_state(); |
| 859 | dprintf(CRITICAL, "Keystore verification failed! Continuing anyways...\n"); |
| 860 | } |
| 861 | } |
| 862 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 863 | int boot_linux_from_mmc(void) |
| 864 | { |
| 865 | struct boot_img_hdr *hdr = (void*) buf; |
| 866 | struct boot_img_hdr *uhdr; |
| 867 | unsigned offset = 0; |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 868 | int rcode; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 869 | unsigned long long ptn = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 870 | int index = INVALID_PTN; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 871 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 872 | unsigned char *image_addr = 0; |
| 873 | unsigned kernel_actual; |
| 874 | unsigned ramdisk_actual; |
| 875 | unsigned imagesize_actual; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 876 | unsigned second_actual = 0; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 877 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 878 | unsigned int dtb_size = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 879 | unsigned int out_len = 0; |
| 880 | unsigned int out_avai_len = 0; |
| 881 | unsigned char *out_addr = NULL; |
| 882 | uint32_t dtb_offset = 0; |
| 883 | unsigned char *kernel_start_addr = NULL; |
| 884 | unsigned int kernel_size = 0; |
| 885 | int rc; |
| 886 | |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 887 | #if DEVICE_TREE |
| 888 | struct dt_table *table; |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 889 | struct dt_entry dt_entry; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 890 | unsigned dt_table_offset; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 891 | uint32_t dt_actual; |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 892 | uint32_t dt_hdr_size; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 893 | unsigned char *best_match_dt_addr = NULL; |
Neeti Desai | 465491e | 2012-07-31 12:53:35 -0700 | [diff] [blame] | 894 | #endif |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 895 | struct kernel64_hdr *kptr = NULL; |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 896 | |
Maunik Shah | 0f3c8ac | 2014-03-02 17:47:58 +0530 | [diff] [blame] | 897 | if (check_format_bit()) |
| 898 | boot_into_recovery = 1; |
| 899 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 900 | if (!boot_into_recovery) { |
| 901 | memset(ffbm_mode_string, '\0', sizeof(ffbm_mode_string)); |
| 902 | rcode = get_ffbm(ffbm_mode_string, sizeof(ffbm_mode_string)); |
| 903 | if (rcode <= 0) { |
| 904 | boot_into_ffbm = false; |
| 905 | if (rcode < 0) |
| 906 | dprintf(CRITICAL,"failed to get ffbm cookie"); |
| 907 | } else |
| 908 | boot_into_ffbm = true; |
| 909 | } else |
| 910 | boot_into_ffbm = false; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 911 | uhdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
| 912 | if (!memcmp(uhdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 913 | dprintf(INFO, "Unified boot method!\n"); |
| 914 | hdr = uhdr; |
| 915 | goto unified_boot; |
| 916 | } |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 917 | if (!boot_into_recovery) { |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 918 | index = partition_get_index("boot"); |
| 919 | ptn = partition_get_offset(index); |
| 920 | if(ptn == 0) { |
Shashank Mittal | 85b91f6 | 2010-10-30 10:12:38 -0700 | [diff] [blame] | 921 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 922 | return -1; |
| 923 | } |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 924 | } |
| 925 | else { |
| 926 | index = partition_get_index("recovery"); |
| 927 | ptn = partition_get_offset(index); |
| 928 | if(ptn == 0) { |
Shashank Mittal | 85b91f6 | 2010-10-30 10:12:38 -0700 | [diff] [blame] | 929 | dprintf(CRITICAL, "ERROR: No recovery partition found\n"); |
| 930 | return -1; |
| 931 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 932 | } |
Channagoud Kadabi | ef0547c | 2015-02-10 12:57:38 -0800 | [diff] [blame] | 933 | /* Set Lun for boot & recovery partitions */ |
| 934 | mmc_set_lun(partition_get_lun(index)); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 935 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 936 | if (mmc_read(ptn + offset, (uint32_t *) buf, page_size)) { |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 937 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 938 | return -1; |
| 939 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 940 | |
| 941 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 942 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 943 | return -1; |
| 944 | } |
| 945 | |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 946 | if (hdr->page_size && (hdr->page_size != page_size)) { |
vijay kumar | 2e21b3a | 2014-06-26 17:40:15 +0530 | [diff] [blame] | 947 | |
| 948 | if (hdr->page_size > BOOT_IMG_MAX_PAGE_SIZE) { |
| 949 | dprintf(CRITICAL, "ERROR: Invalid page size\n"); |
| 950 | return -1; |
| 951 | } |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 952 | page_size = hdr->page_size; |
| 953 | page_mask = page_size - 1; |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 954 | } |
| 955 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 956 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 957 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 958 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 959 | image_addr = (unsigned char *)target_get_scratch_address(); |
| 960 | |
| 961 | #if DEVICE_TREE |
| 962 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
| 963 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual); |
| 964 | #else |
| 965 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual); |
| 966 | #endif |
| 967 | |
| 968 | #if VERIFIED_BOOT |
| 969 | boot_verifier_init(); |
| 970 | #endif |
| 971 | |
| 972 | if (check_aboot_addr_range_overlap((uint32_t) image_addr, imagesize_actual)) |
| 973 | { |
| 974 | dprintf(CRITICAL, "Boot image buffer address overlaps with aboot addresses.\n"); |
| 975 | return -1; |
| 976 | } |
| 977 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 978 | /* |
| 979 | * Update loading flow of bootimage to support compressed/uncompressed |
| 980 | * bootimage on both 64bit and 32bit platform. |
| 981 | * 1. Load bootimage from emmc partition onto DDR. |
| 982 | * 2. Check if bootimage is gzip format. If yes, decompress compressed kernel |
| 983 | * 3. Check kernel header and update kernel load addr for 64bit and 32bit |
| 984 | * platform accordingly. |
| 985 | * 4. Sanity Check on kernel_addr and ramdisk_addr and copy data. |
| 986 | */ |
| 987 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 988 | dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual); |
| 989 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
| 990 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 991 | /* Read image without signature */ |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 992 | if (mmc_read(ptn + offset, (void *)image_addr, imagesize_actual)) |
| 993 | { |
| 994 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 995 | return -1; |
| 996 | } |
| 997 | |
| 998 | dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual); |
| 999 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
| 1000 | |
| 1001 | /* Authenticate Kernel */ |
| 1002 | dprintf(INFO, "use_signed_kernel=%d, is_unlocked=%d, is_tampered=%d.\n", |
| 1003 | (int) target_use_signed_kernel(), |
| 1004 | device.is_unlocked, |
| 1005 | device.is_tampered); |
| 1006 | |
| 1007 | if(target_use_signed_kernel() && (!device.is_unlocked)) |
| 1008 | { |
| 1009 | offset = imagesize_actual; |
| 1010 | if (check_aboot_addr_range_overlap((uint32_t)image_addr + offset, page_size)) |
| 1011 | { |
| 1012 | dprintf(CRITICAL, "Signature read buffer address overlaps with aboot addresses.\n"); |
| 1013 | return -1; |
| 1014 | } |
| 1015 | |
| 1016 | /* Read signature */ |
| 1017 | if(mmc_read(ptn + offset, (void *)(image_addr + offset), page_size)) |
| 1018 | { |
| 1019 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
| 1020 | return -1; |
| 1021 | } |
| 1022 | |
| 1023 | verify_signed_bootimg((uint32_t)image_addr, imagesize_actual); |
| 1024 | } else { |
| 1025 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 1026 | #ifdef TZ_SAVE_KERNEL_HASH |
| 1027 | aboot_save_boot_hash_mmc((uint32_t) image_addr, imagesize_actual); |
| 1028 | #endif /* TZ_SAVE_KERNEL_HASH */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1031 | /* |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1032 | * Check if the kernel image is a gzip package. If yes, need to decompress it. |
| 1033 | * If not, continue booting. |
| 1034 | */ |
| 1035 | if (is_gzip_package((unsigned char *)(image_addr + page_size), hdr->kernel_size)) |
| 1036 | { |
| 1037 | out_addr = (unsigned char *)(image_addr + imagesize_actual + page_size); |
| 1038 | out_avai_len = target_get_max_flash_size() - imagesize_actual - page_size; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1039 | dprintf(SPEW, "decompress image start\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1040 | rc = decompress((unsigned char *)(image_addr + page_size), |
| 1041 | hdr->kernel_size, out_addr, out_avai_len, |
| 1042 | &dtb_offset, &out_len); |
| 1043 | if (rc) |
| 1044 | { |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1045 | dprintf(CRITICAL, "decompress image failed!!!\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1046 | ASSERT(0); |
| 1047 | } |
| 1048 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1049 | dprintf(SPEW, "decompressed image finished.\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1050 | kptr = (struct kernel64_hdr *)out_addr; |
| 1051 | kernel_start_addr = out_addr; |
| 1052 | kernel_size = out_len; |
| 1053 | } else { |
| 1054 | kptr = (struct kernel64_hdr *)(image_addr + page_size); |
| 1055 | kernel_start_addr = (unsigned char *)(image_addr + page_size); |
| 1056 | kernel_size = hdr->kernel_size; |
| 1057 | } |
| 1058 | |
| 1059 | /* |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1060 | * Update the kernel/ramdisk/tags address if the boot image header |
| 1061 | * has default values, these default values come from mkbootimg when |
| 1062 | * the boot image is flashed using fastboot flash:raw |
| 1063 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1064 | update_ker_tags_rdisk_addr(hdr, IS_ARM64(kptr)); |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1065 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1066 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 1067 | hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr)); |
| 1068 | hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr)); |
| 1069 | hdr->tags_addr = VA((addr_t)(hdr->tags_addr)); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1070 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1071 | kernel_size = ROUND_TO_PAGE(kernel_size, page_mask); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1072 | /* Check if the addresses in the header are valid. */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1073 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_size) || |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1074 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual)) |
| 1075 | { |
| 1076 | dprintf(CRITICAL, "kernel/ramdisk addresses overlap with aboot addresses.\n"); |
| 1077 | return -1; |
| 1078 | } |
| 1079 | |
| 1080 | #ifndef DEVICE_TREE |
| 1081 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE)) |
| 1082 | { |
| 1083 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
| 1084 | return -1; |
| 1085 | } |
| 1086 | #endif |
| 1087 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1088 | /* Move kernel, ramdisk and device tree to correct address */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1089 | memmove((void*) hdr->kernel_addr, kernel_start_addr, kernel_size); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1090 | 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] | 1091 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1092 | #if DEVICE_TREE |
| 1093 | if(hdr->dt_size) { |
| 1094 | dt_table_offset = ((uint32_t)image_addr + page_size + kernel_actual + ramdisk_actual + second_actual); |
| 1095 | table = (struct dt_table*) dt_table_offset; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1096 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1097 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
| 1098 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1099 | return -1; |
| 1100 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1101 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1102 | /* Find index of device tree within device tree table */ |
| 1103 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
| 1104 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1105 | return -1; |
| 1106 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1107 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1108 | if (is_gzip_package((unsigned char *)dt_table_offset + dt_entry.offset, dt_entry.size)) |
| 1109 | { |
| 1110 | unsigned int compressed_size = 0; |
| 1111 | out_addr += out_len; |
| 1112 | out_avai_len -= out_len; |
| 1113 | dprintf(SPEW, "decompress dtb start\n"); |
| 1114 | rc = decompress((unsigned char *)dt_table_offset + dt_entry.offset, |
| 1115 | dt_entry.size, out_addr, out_avai_len, |
| 1116 | &compressed_size, &dtb_size); |
| 1117 | if (rc) |
| 1118 | { |
| 1119 | dprintf(CRITICAL, "decompress dtb failed!!!\n"); |
| 1120 | ASSERT(0); |
| 1121 | } |
| 1122 | |
| 1123 | dprintf(SPEW, "decompressed dtb finished.\n"); |
| 1124 | best_match_dt_addr = out_addr; |
| 1125 | } else { |
| 1126 | best_match_dt_addr = (unsigned char *)dt_table_offset + dt_entry.offset; |
| 1127 | dtb_size = dt_entry.size; |
| 1128 | } |
| 1129 | |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1130 | /* Validate and Read device device tree in the tags_addr */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1131 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dtb_size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1132 | { |
| 1133 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1134 | return -1; |
| 1135 | } |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1136 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1137 | memmove((void *)hdr->tags_addr, (char *)best_match_dt_addr, dtb_size); |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1138 | } else { |
| 1139 | /* Validate the tags_addr */ |
| 1140 | if (check_aboot_addr_range_overlap(hdr->tags_addr, kernel_actual)) |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 1141 | { |
| 1142 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1143 | return -1; |
| 1144 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1145 | /* |
| 1146 | * If appended dev tree is found, update the atags with |
| 1147 | * memory address to the DTB appended location on RAM. |
| 1148 | * Else update with the atags address in the kernel header |
| 1149 | */ |
| 1150 | void *dtb; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1151 | dtb = dev_tree_appended((void*)(image_addr + page_size), |
| 1152 | hdr->kernel_size, dtb_offset, |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1153 | (void *)hdr->tags_addr); |
| 1154 | if (!dtb) { |
| 1155 | dprintf(CRITICAL, "ERROR: Appended Device Tree Blob not found\n"); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 1156 | return -1; |
| 1157 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1158 | } |
Matthew Qin | 49e51fa | 2015-02-09 10:40:45 +0800 | [diff] [blame] | 1159 | #endif |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1160 | |
Stanimir Varbanov | 69ec546 | 2013-07-18 18:17:42 +0300 | [diff] [blame] | 1161 | if (boot_into_recovery && !device.is_unlocked && !device.is_tampered) |
| 1162 | target_load_ssd_keystore(); |
| 1163 | |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1164 | unified_boot: |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1165 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 1166 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 1167 | (const char *)hdr->cmdline, board_machtype(), |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 1168 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 1169 | |
| 1170 | return 0; |
| 1171 | } |
| 1172 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1173 | int boot_linux_from_flash(void) |
| 1174 | { |
| 1175 | struct boot_img_hdr *hdr = (void*) buf; |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1176 | struct ptentry *ptn; |
| 1177 | struct ptable *ptable; |
| 1178 | unsigned offset = 0; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 1179 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1180 | unsigned char *image_addr = 0; |
| 1181 | unsigned kernel_actual; |
| 1182 | unsigned ramdisk_actual; |
| 1183 | unsigned imagesize_actual; |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1184 | unsigned second_actual; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1185 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1186 | #if DEVICE_TREE |
| 1187 | struct dt_table *table; |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1188 | struct dt_entry dt_entry; |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1189 | uint32_t dt_actual; |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1190 | uint32_t dt_hdr_size; |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1191 | #endif |
| 1192 | |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 1193 | if (target_is_emmc_boot()) { |
| 1194 | hdr = (struct boot_img_hdr *)EMMC_BOOT_IMG_HEADER_ADDR; |
| 1195 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 1196 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
| 1197 | return -1; |
| 1198 | } |
| 1199 | goto continue_boot; |
| 1200 | } |
| 1201 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1202 | ptable = flash_get_ptable(); |
| 1203 | if (ptable == NULL) { |
| 1204 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1205 | return -1; |
| 1206 | } |
| 1207 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 1208 | if(!boot_into_recovery) |
| 1209 | { |
| 1210 | ptn = ptable_find(ptable, "boot"); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1211 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 1212 | if (ptn == NULL) { |
| 1213 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 1214 | return -1; |
| 1215 | } |
| 1216 | } |
| 1217 | else |
| 1218 | { |
| 1219 | ptn = ptable_find(ptable, "recovery"); |
| 1220 | if (ptn == NULL) { |
| 1221 | dprintf(CRITICAL, "ERROR: No recovery partition found\n"); |
| 1222 | return -1; |
| 1223 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1224 | } |
| 1225 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 1226 | if (flash_read(ptn, offset, buf, page_size)) { |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1227 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
| 1228 | return -1; |
| 1229 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1230 | |
| 1231 | if (memcmp(hdr->magic, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 1232 | dprintf(CRITICAL, "ERROR: Invalid boot image header\n"); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1233 | return -1; |
| 1234 | } |
| 1235 | |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 1236 | if (hdr->page_size != page_size) { |
Kinson Chik kchik@codeaurora.org | 82e4ae6 | 2011-04-12 17:42:07 -0700 | [diff] [blame] | 1237 | 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] | 1238 | return -1; |
| 1239 | } |
| 1240 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1241 | /* |
| 1242 | * Update the kernel/ramdisk/tags address if the boot image header |
| 1243 | * has default values, these default values come from mkbootimg when |
| 1244 | * the boot image is flashed using fastboot flash:raw |
| 1245 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1246 | update_ker_tags_rdisk_addr(hdr, false); |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1247 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1248 | /* Get virtual addresses since the hdr saves physical addresses. */ |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1249 | hdr->kernel_addr = VA((addr_t)(hdr->kernel_addr)); |
| 1250 | hdr->ramdisk_addr = VA((addr_t)(hdr->ramdisk_addr)); |
| 1251 | hdr->tags_addr = VA((addr_t)(hdr->tags_addr)); |
| 1252 | |
| 1253 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1254 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 1255 | |
| 1256 | /* Check if the addresses in the header are valid. */ |
| 1257 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_actual) || |
| 1258 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual)) |
| 1259 | { |
| 1260 | dprintf(CRITICAL, "kernel/ramdisk addresses overlap with aboot addresses.\n"); |
| 1261 | return -1; |
| 1262 | } |
| 1263 | |
| 1264 | #ifndef DEVICE_TREE |
| 1265 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE)) |
| 1266 | { |
| 1267 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
| 1268 | return -1; |
| 1269 | } |
| 1270 | #endif |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1271 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1272 | /* Authenticate Kernel */ |
Deepa Dinamani | 23b60d4 | 2013-06-24 18:10:52 -0700 | [diff] [blame] | 1273 | if(target_use_signed_kernel() && (!device.is_unlocked)) |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1274 | { |
| 1275 | image_addr = (unsigned char *)target_get_scratch_address(); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1276 | offset = 0; |
| 1277 | |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1278 | #if DEVICE_TREE |
| 1279 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
| 1280 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual + dt_actual); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1281 | |
| 1282 | if (check_aboot_addr_range_overlap(hdr->tags_addr, hdr->dt_size)) |
| 1283 | { |
| 1284 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1285 | return -1; |
| 1286 | } |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1287 | #else |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1288 | imagesize_actual = (page_size + kernel_actual + ramdisk_actual); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1289 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1290 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1291 | dprintf(INFO, "Loading boot image (%d): start\n", imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1292 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1293 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1294 | /* Read image without signature */ |
| 1295 | if (flash_read(ptn, offset, (void *)image_addr, imagesize_actual)) |
| 1296 | { |
| 1297 | dprintf(CRITICAL, "ERROR: Cannot read boot image\n"); |
| 1298 | return -1; |
| 1299 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1300 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1301 | dprintf(INFO, "Loading boot image (%d): done\n", imagesize_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1302 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1303 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1304 | offset = imagesize_actual; |
| 1305 | /* Read signature */ |
| 1306 | if (flash_read(ptn, offset, (void *)(image_addr + offset), page_size)) |
| 1307 | { |
| 1308 | dprintf(CRITICAL, "ERROR: Cannot read boot image signature\n"); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1309 | return -1; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1310 | } |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1311 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 1312 | verify_signed_bootimg((uint32_t)image_addr, imagesize_actual); |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1313 | |
| 1314 | /* Move kernel and ramdisk to correct address */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1315 | memmove((void*) hdr->kernel_addr, (char*) (image_addr + page_size), hdr->kernel_size); |
| 1316 | memmove((void*) hdr->ramdisk_addr, (char*) (image_addr + page_size + kernel_actual), hdr->ramdisk_size); |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1317 | #if DEVICE_TREE |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1318 | /* Validate and Read device device tree in the "tags_add */ |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1319 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dt_entry.size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1320 | { |
| 1321 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1322 | return -1; |
| 1323 | } |
| 1324 | |
Deepa Dinamani | 7aaf83d | 2012-12-21 11:27:01 -0800 | [diff] [blame] | 1325 | memmove((void*) hdr->tags_addr, (char *)(image_addr + page_size + kernel_actual + ramdisk_actual), hdr->dt_size); |
| 1326 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1327 | |
| 1328 | /* Make sure everything from scratch address is read before next step!*/ |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1329 | if(device.is_tampered) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1330 | { |
| 1331 | write_device_info_flash(&device); |
| 1332 | } |
Channagoud Kadabi | 5c86fe3 | 2012-02-16 10:58:48 +0530 | [diff] [blame] | 1333 | #if USE_PCOM_SECBOOT |
| 1334 | set_tamper_flag(device.is_tampered); |
| 1335 | #endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1336 | } |
| 1337 | else |
| 1338 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1339 | offset = page_size; |
| 1340 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1341 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1342 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 1343 | second_actual = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 1344 | |
| 1345 | dprintf(INFO, "Loading boot image (%d): start\n", |
| 1346 | kernel_actual + ramdisk_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1347 | bs_set_timestamp(BS_KERNEL_LOAD_START); |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1348 | |
| 1349 | if (flash_read(ptn, offset, (void *)hdr->kernel_addr, kernel_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1350 | dprintf(CRITICAL, "ERROR: Cannot read kernel image\n"); |
| 1351 | return -1; |
| 1352 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1353 | offset += kernel_actual; |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1354 | |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1355 | if (flash_read(ptn, offset, (void *)hdr->ramdisk_addr, ramdisk_actual)) { |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1356 | dprintf(CRITICAL, "ERROR: Cannot read ramdisk image\n"); |
| 1357 | return -1; |
| 1358 | } |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1359 | offset += ramdisk_actual; |
| 1360 | |
| 1361 | dprintf(INFO, "Loading boot image (%d): done\n", |
| 1362 | kernel_actual + ramdisk_actual); |
Amol Jadi | 492d5a5 | 2013-03-15 16:12:34 -0700 | [diff] [blame] | 1363 | bs_set_timestamp(BS_KERNEL_LOAD_DONE); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1364 | |
| 1365 | if(hdr->second_size != 0) { |
Amol Jadi | b6be5c1 | 2012-11-14 13:39:51 -0800 | [diff] [blame] | 1366 | offset += second_actual; |
| 1367 | /* Second image loading not implemented. */ |
| 1368 | ASSERT(0); |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1369 | } |
| 1370 | |
| 1371 | #if DEVICE_TREE |
| 1372 | if(hdr->dt_size != 0) { |
| 1373 | |
| 1374 | /* Read the device tree table into buffer */ |
| 1375 | if(flash_read(ptn, offset, (void *) dt_buf, page_size)) { |
| 1376 | dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n"); |
| 1377 | return -1; |
| 1378 | } |
| 1379 | |
| 1380 | table = (struct dt_table*) dt_buf; |
| 1381 | |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1382 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1383 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1384 | return -1; |
| 1385 | } |
| 1386 | |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1387 | table = (struct dt_table*) memalign(CACHE_LINE, dt_hdr_size); |
| 1388 | if (!table) |
| 1389 | return -1; |
| 1390 | |
| 1391 | /* Read the entire device tree table into buffer */ |
| 1392 | if(flash_read(ptn, offset, (void *)table, dt_hdr_size)) { |
| 1393 | dprintf(CRITICAL, "ERROR: Cannot read the Device Tree Table\n"); |
| 1394 | return -1; |
| 1395 | } |
| 1396 | |
| 1397 | |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1398 | /* Find index of device tree within device tree table */ |
| 1399 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1400 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1401 | return -1; |
| 1402 | } |
| 1403 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1404 | /* Validate and Read device device tree in the "tags_add */ |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1405 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dt_entry.size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1406 | { |
| 1407 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1408 | return -1; |
| 1409 | } |
| 1410 | |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1411 | /* Read device device tree in the "tags_add */ |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1412 | if(flash_read(ptn, offset + dt_entry.offset, |
| 1413 | (void *)hdr->tags_addr, dt_entry.size)) { |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1414 | dprintf(CRITICAL, "ERROR: Cannot read device tree\n"); |
| 1415 | return -1; |
| 1416 | } |
| 1417 | } |
| 1418 | #endif |
| 1419 | |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 1420 | } |
David Ng | 183a742 | 2009-12-07 14:55:21 -0800 | [diff] [blame] | 1421 | continue_boot: |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1422 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1423 | /* TODO: create/pass atags to kernel */ |
| 1424 | |
Ajay Dudani | e28a607 | 2011-07-01 13:59:46 -0700 | [diff] [blame] | 1425 | boot_linux((void *)hdr->kernel_addr, (void *)hdr->tags_addr, |
Dima Zavin | bd3daa0 | 2013-03-26 11:06:44 -0700 | [diff] [blame] | 1426 | (const char *)hdr->cmdline, board_machtype(), |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1427 | (void *)hdr->ramdisk_addr, hdr->ramdisk_size); |
| 1428 | |
| 1429 | return 0; |
| 1430 | } |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1431 | |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1432 | BUF_DMA_ALIGN(info_buf, BOOT_IMG_MAX_PAGE_SIZE); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1433 | void write_device_info_mmc(device_info *dev) |
| 1434 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1435 | unsigned long long ptn = 0; |
| 1436 | unsigned long long size; |
| 1437 | int index = INVALID_PTN; |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1438 | uint32_t blocksize; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 1439 | uint8_t lun = 0; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1440 | uint32_t ret = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1441 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1442 | if (devinfo_present) |
| 1443 | index = partition_get_index("devinfo"); |
| 1444 | else |
| 1445 | index = partition_get_index("aboot"); |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 1446 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1447 | ptn = partition_get_offset(index); |
| 1448 | if(ptn == 0) |
| 1449 | { |
| 1450 | return; |
| 1451 | } |
| 1452 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 1453 | lun = partition_get_lun(index); |
| 1454 | mmc_set_lun(lun); |
| 1455 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1456 | size = partition_get_size(index); |
| 1457 | |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1458 | blocksize = mmc_get_device_blocksize(); |
| 1459 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1460 | if (devinfo_present) |
| 1461 | ret = mmc_write(ptn, blocksize, (void *)info_buf); |
| 1462 | else |
| 1463 | ret = mmc_write((ptn + size - blocksize), blocksize, (void *)info_buf); |
| 1464 | if (ret) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1465 | { |
| 1466 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1467 | return; |
| 1468 | } |
| 1469 | } |
| 1470 | |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1471 | void read_device_info_mmc(struct device_info *info) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1472 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1473 | unsigned long long ptn = 0; |
| 1474 | unsigned long long size; |
| 1475 | int index = INVALID_PTN; |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1476 | uint32_t blocksize; |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1477 | uint32_t ret = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1478 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1479 | if ((index = partition_get_index("devinfo")) < 0) |
| 1480 | { |
| 1481 | devinfo_present = false; |
| 1482 | index = partition_get_index("aboot"); |
| 1483 | } |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 1484 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1485 | ptn = partition_get_offset(index); |
| 1486 | if(ptn == 0) |
| 1487 | { |
| 1488 | return; |
| 1489 | } |
| 1490 | |
Channagoud Kadabi | 5d0371c | 2014-10-21 22:27:07 -0700 | [diff] [blame] | 1491 | mmc_set_lun(partition_get_lun(index)); |
| 1492 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1493 | size = partition_get_size(index); |
| 1494 | |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 1495 | blocksize = mmc_get_device_blocksize(); |
| 1496 | |
Channagoud Kadabi | 80a182b | 2015-03-11 17:04:23 -0700 | [diff] [blame] | 1497 | if (devinfo_present) |
| 1498 | ret = mmc_read(ptn, (void *)info_buf, blocksize); |
| 1499 | else |
| 1500 | ret = mmc_read((ptn + size - blocksize), (void *)info_buf, blocksize); |
| 1501 | if (ret) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1502 | { |
| 1503 | dprintf(CRITICAL, "ERROR: Cannot read device info\n"); |
| 1504 | return; |
| 1505 | } |
| 1506 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1507 | } |
| 1508 | |
| 1509 | void write_device_info_flash(device_info *dev) |
| 1510 | { |
| 1511 | struct device_info *info = (void *) info_buf; |
| 1512 | struct ptentry *ptn; |
| 1513 | struct ptable *ptable; |
| 1514 | |
| 1515 | ptable = flash_get_ptable(); |
| 1516 | if (ptable == NULL) |
| 1517 | { |
| 1518 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1519 | return; |
| 1520 | } |
| 1521 | |
| 1522 | ptn = ptable_find(ptable, "devinfo"); |
| 1523 | if (ptn == NULL) |
| 1524 | { |
| 1525 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 1526 | return; |
| 1527 | } |
| 1528 | |
| 1529 | memcpy(info, dev, sizeof(device_info)); |
| 1530 | |
| 1531 | if (flash_write(ptn, 0, (void *)info_buf, page_size)) |
| 1532 | { |
| 1533 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1534 | return; |
| 1535 | } |
| 1536 | } |
| 1537 | |
| 1538 | void read_device_info_flash(device_info *dev) |
| 1539 | { |
| 1540 | struct device_info *info = (void*) info_buf; |
| 1541 | struct ptentry *ptn; |
| 1542 | struct ptable *ptable; |
| 1543 | |
| 1544 | ptable = flash_get_ptable(); |
| 1545 | if (ptable == NULL) |
| 1546 | { |
| 1547 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
| 1548 | return; |
| 1549 | } |
| 1550 | |
| 1551 | ptn = ptable_find(ptable, "devinfo"); |
| 1552 | if (ptn == NULL) |
| 1553 | { |
| 1554 | dprintf(CRITICAL, "ERROR: No boot partition found\n"); |
| 1555 | return; |
| 1556 | } |
| 1557 | |
| 1558 | if (flash_read(ptn, 0, (void *)info_buf, page_size)) |
| 1559 | { |
| 1560 | dprintf(CRITICAL, "ERROR: Cannot write device info\n"); |
| 1561 | return; |
| 1562 | } |
| 1563 | |
| 1564 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 1565 | { |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1566 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
| 1567 | info->is_unlocked = 0; |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1568 | info->is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1569 | write_device_info_flash(info); |
| 1570 | } |
| 1571 | memcpy(dev, info, sizeof(device_info)); |
| 1572 | } |
| 1573 | |
| 1574 | void write_device_info(device_info *dev) |
| 1575 | { |
| 1576 | if(target_is_emmc_boot()) |
| 1577 | { |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1578 | struct device_info *info = (void*) info_buf; |
| 1579 | memcpy(info, dev, sizeof(struct device_info)); |
| 1580 | |
| 1581 | #if USE_RPMB_FOR_DEVINFO |
| 1582 | if (is_secure_boot_enable()) |
| 1583 | write_device_info_rpmb((void*) info, mmc_get_device_blocksize()); |
Channagoud Kadabi | c80cb49 | 2015-04-28 16:08:28 -0700 | [diff] [blame] | 1584 | else |
| 1585 | write_device_info_mmc(info); |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1586 | #else |
| 1587 | write_device_info_mmc(info); |
| 1588 | #endif |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1589 | } |
| 1590 | else |
| 1591 | { |
| 1592 | write_device_info_flash(dev); |
| 1593 | } |
| 1594 | } |
| 1595 | |
| 1596 | void read_device_info(device_info *dev) |
| 1597 | { |
| 1598 | if(target_is_emmc_boot()) |
| 1599 | { |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1600 | struct device_info *info = (void*) info_buf; |
| 1601 | |
| 1602 | #if USE_RPMB_FOR_DEVINFO |
| 1603 | if (is_secure_boot_enable()) |
| 1604 | read_device_info_rpmb((void*) info, mmc_get_device_blocksize()); |
Channagoud Kadabi | c80cb49 | 2015-04-28 16:08:28 -0700 | [diff] [blame] | 1605 | else |
| 1606 | read_device_info_mmc(info); |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1607 | #else |
| 1608 | read_device_info_mmc(info); |
| 1609 | #endif |
| 1610 | |
| 1611 | if (memcmp(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE)) |
| 1612 | { |
| 1613 | memcpy(info->magic, DEVICE_MAGIC, DEVICE_MAGIC_SIZE); |
| 1614 | if (is_secure_boot_enable()) |
| 1615 | info->is_unlocked = 0; |
| 1616 | else |
| 1617 | info->is_unlocked = 1; |
| 1618 | info->is_verified = 0; |
| 1619 | info->is_tampered = 0; |
Unnati Gandhi | a49daa1 | 2015-03-23 18:08:38 +0530 | [diff] [blame] | 1620 | #if USER_BUILD_VARIANT |
| 1621 | info->charger_screen_enabled = 1; |
| 1622 | #else |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1623 | info->charger_screen_enabled = 0; |
Unnati Gandhi | a49daa1 | 2015-03-23 18:08:38 +0530 | [diff] [blame] | 1624 | #endif |
Channagoud Kadabi | 036c605 | 2015-02-09 15:19:59 -0800 | [diff] [blame] | 1625 | write_device_info(info); |
| 1626 | } |
| 1627 | memcpy(dev, info, sizeof(device_info)); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1628 | } |
| 1629 | else |
| 1630 | { |
| 1631 | read_device_info_flash(dev); |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | void reset_device_info() |
| 1636 | { |
| 1637 | dprintf(ALWAYS, "reset_device_info called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1638 | device.is_tampered = 0; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1639 | write_device_info(&device); |
| 1640 | } |
| 1641 | |
| 1642 | void set_device_root() |
| 1643 | { |
| 1644 | dprintf(ALWAYS, "set_device_root called."); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 1645 | device.is_tampered = 1; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 1646 | write_device_info(&device); |
| 1647 | } |
| 1648 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1649 | #if DEVICE_TREE |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1650 | int copy_dtb(uint8_t *boot_image_start, unsigned int scratch_offset) |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1651 | { |
| 1652 | uint32 dt_image_offset = 0; |
| 1653 | uint32_t n; |
| 1654 | struct dt_table *table; |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1655 | struct dt_entry dt_entry; |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1656 | uint32_t dt_hdr_size; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1657 | unsigned int compressed_size = 0; |
| 1658 | unsigned int dtb_size = 0; |
| 1659 | unsigned int out_avai_len = 0; |
| 1660 | unsigned char *out_addr = NULL; |
| 1661 | unsigned char *best_match_dt_addr = NULL; |
| 1662 | int rc; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1663 | |
| 1664 | struct boot_img_hdr *hdr = (struct boot_img_hdr *) (boot_image_start); |
| 1665 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1666 | if(hdr->dt_size != 0) { |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1667 | /* add kernel offset */ |
| 1668 | dt_image_offset += page_size; |
| 1669 | n = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1670 | dt_image_offset += n; |
| 1671 | |
| 1672 | /* add ramdisk offset */ |
| 1673 | n = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
| 1674 | dt_image_offset += n; |
| 1675 | |
| 1676 | /* add second offset */ |
| 1677 | if(hdr->second_size != 0) { |
| 1678 | n = ROUND_TO_PAGE(hdr->second_size, page_mask); |
| 1679 | dt_image_offset += n; |
| 1680 | } |
| 1681 | |
| 1682 | /* offset now point to start of dt.img */ |
Deepa Dinamani | 28c0ffe | 2012-09-24 11:45:21 -0700 | [diff] [blame] | 1683 | table = (struct dt_table*)(boot_image_start + dt_image_offset); |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1684 | |
Deepa Dinamani | 19648b4 | 2013-09-05 17:05:55 -0700 | [diff] [blame] | 1685 | if (dev_tree_validate(table, hdr->page_size, &dt_hdr_size) != 0) { |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1686 | dprintf(CRITICAL, "ERROR: Cannot validate Device Tree Table \n"); |
| 1687 | return -1; |
| 1688 | } |
Joel King | aa335dc | 2013-06-03 16:11:08 -0700 | [diff] [blame] | 1689 | /* Find index of device tree within device tree table */ |
| 1690 | if(dev_tree_get_entry_info(table, &dt_entry) != 0){ |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1691 | dprintf(CRITICAL, "ERROR: Getting device tree address failed\n"); |
| 1692 | return -1; |
| 1693 | } |
| 1694 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1695 | best_match_dt_addr = (unsigned char *)boot_image_start + dt_image_offset + dt_entry.offset; |
| 1696 | if (is_gzip_package(best_match_dt_addr, dt_entry.size)) |
| 1697 | { |
| 1698 | out_addr = (unsigned char *)target_get_scratch_address() + scratch_offset; |
| 1699 | out_avai_len = target_get_max_flash_size() - scratch_offset; |
| 1700 | dprintf(SPEW, "decompress dtb start\n"); |
| 1701 | rc = decompress(best_match_dt_addr, |
| 1702 | dt_entry.size, out_addr, out_avai_len, |
| 1703 | &compressed_size, &dtb_size); |
| 1704 | if (rc) |
| 1705 | { |
| 1706 | dprintf(CRITICAL, "decompress dtb failed!!!\n"); |
| 1707 | ASSERT(0); |
| 1708 | } |
| 1709 | |
| 1710 | dprintf(SPEW, "decompressed dtb finished.\n"); |
| 1711 | best_match_dt_addr = out_addr; |
| 1712 | } else { |
| 1713 | dtb_size = dt_entry.size; |
| 1714 | } |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1715 | /* Validate and Read device device tree in the "tags_add */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1716 | if (check_aboot_addr_range_overlap(hdr->tags_addr, dtb_size)) |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1717 | { |
| 1718 | dprintf(CRITICAL, "Device tree addresses overlap with aboot addresses.\n"); |
| 1719 | return -1; |
| 1720 | } |
| 1721 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1722 | /* Read device device tree in the "tags_add */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1723 | memmove((void*) hdr->tags_addr, (void *)best_match_dt_addr, dtb_size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1724 | } else |
| 1725 | return -1; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1726 | |
| 1727 | /* Everything looks fine. Return success. */ |
| 1728 | return 0; |
| 1729 | } |
| 1730 | #endif |
| 1731 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1732 | void cmd_boot(const char *arg, void *data, unsigned sz) |
| 1733 | { |
| 1734 | unsigned kernel_actual; |
| 1735 | unsigned ramdisk_actual; |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 1736 | uint32_t image_actual; |
| 1737 | uint32_t dt_actual = 0; |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 1738 | uint32_t sig_actual = SIGNATURE_SIZE; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1739 | struct boot_img_hdr *hdr = NULL; |
| 1740 | struct kernel64_hdr *kptr = NULL; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1741 | char *ptr = ((char*) data); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1742 | int ret = 0; |
| 1743 | uint8_t dtb_copied = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1744 | unsigned int out_len = 0; |
| 1745 | unsigned int out_avai_len = 0; |
| 1746 | unsigned char *out_addr = NULL; |
| 1747 | uint32_t dtb_offset = 0; |
| 1748 | unsigned char *kernel_start_addr = NULL; |
| 1749 | unsigned int kernel_size = 0; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1750 | unsigned int scratch_offset = 0; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1751 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1752 | |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 1753 | #ifdef MDTP_SUPPORT |
| 1754 | /* Go through Firmware Lock verification before continue with boot process */ |
| 1755 | mdtp_fwlock_verify_lock(); |
Reut Zysman | 1841127 | 2015-02-09 13:47:27 +0200 | [diff] [blame] | 1756 | display_image_on_screen(); |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 1757 | #endif /* MDTP_SUPPORT */ |
| 1758 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1759 | #if VERIFIED_BOOT |
| 1760 | if(!device.is_unlocked) |
| 1761 | { |
| 1762 | fastboot_fail("unlock device to use this command"); |
| 1763 | return; |
| 1764 | } |
| 1765 | #endif |
| 1766 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1767 | if (sz < sizeof(hdr)) { |
| 1768 | fastboot_fail("invalid bootimage header"); |
| 1769 | return; |
| 1770 | } |
| 1771 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1772 | hdr = (struct boot_img_hdr *)data; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1773 | |
| 1774 | /* ensure commandline is terminated */ |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1775 | hdr->cmdline[BOOT_ARGS_SIZE-1] = 0; |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1776 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1777 | if(target_is_emmc_boot() && hdr->page_size) { |
| 1778 | page_size = hdr->page_size; |
Subbaraman Narayanamurthy | fbe13a0 | 2010-09-10 11:51:12 -0700 | [diff] [blame] | 1779 | page_mask = page_size - 1; |
| 1780 | } |
| 1781 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1782 | kernel_actual = ROUND_TO_PAGE(hdr->kernel_size, page_mask); |
| 1783 | ramdisk_actual = ROUND_TO_PAGE(hdr->ramdisk_size, page_mask); |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 1784 | #if DEVICE_TREE |
| 1785 | dt_actual = ROUND_TO_PAGE(hdr->dt_size, page_mask); |
| 1786 | #endif |
| 1787 | |
| 1788 | image_actual = ADD_OF(page_size, kernel_actual); |
| 1789 | image_actual = ADD_OF(image_actual, ramdisk_actual); |
| 1790 | image_actual = ADD_OF(image_actual, dt_actual); |
| 1791 | |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 1792 | if (target_use_signed_kernel() && (!device.is_unlocked)) |
| 1793 | image_actual = ADD_OF(image_actual, sig_actual); |
| 1794 | |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 1795 | /* sz should have atleast raw boot image */ |
| 1796 | if (image_actual > sz) { |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 1797 | fastboot_fail("bootimage: incomplete or not signed"); |
Channagoud Kadabi | fc3b31f | 2014-06-18 17:41:01 -0700 | [diff] [blame] | 1798 | return; |
| 1799 | } |
| 1800 | |
| 1801 | /* Verify the boot image |
| 1802 | * device & page_size are initialized in aboot_init |
| 1803 | */ |
| 1804 | if (target_use_signed_kernel() && (!device.is_unlocked)) |
Channagoud Kadabi | 3d83901 | 2014-06-26 14:26:39 -0700 | [diff] [blame] | 1805 | /* Pass size excluding signature size, otherwise we would try to |
| 1806 | * access signature beyond its length |
| 1807 | */ |
| 1808 | verify_signed_bootimg((uint32_t)data, (image_actual - sig_actual)); |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1809 | |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1810 | /* |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1811 | * Check if the kernel image is a gzip package. If yes, need to decompress it. |
| 1812 | * If not, continue booting. |
| 1813 | */ |
| 1814 | if (is_gzip_package((unsigned char *)(data + page_size), hdr->kernel_size)) |
| 1815 | { |
| 1816 | out_addr = (unsigned char *)target_get_scratch_address(); |
| 1817 | out_addr = (unsigned char *)(out_addr + image_actual + page_size); |
| 1818 | out_avai_len = target_get_max_flash_size() - image_actual - page_size; |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1819 | dprintf(SPEW, "decompress image start\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1820 | ret = decompress((unsigned char *)(ptr + page_size), |
| 1821 | hdr->kernel_size, out_addr, out_avai_len, |
| 1822 | &dtb_offset, &out_len); |
| 1823 | if (ret) |
| 1824 | { |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1825 | dprintf(CRITICAL, "decompress image failed!!!\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1826 | ASSERT(0); |
| 1827 | } |
| 1828 | |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1829 | dprintf(SPEW, "decompressed image finished.\n"); |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1830 | kptr = (struct kernel64_hdr *)out_addr; |
| 1831 | kernel_start_addr = out_addr; |
| 1832 | kernel_size = out_len; |
| 1833 | } else { |
| 1834 | kptr = (struct kernel64_hdr*)((char *)data + page_size); |
| 1835 | kernel_start_addr = (unsigned char *)((char *)data + page_size); |
| 1836 | kernel_size = hdr->kernel_size; |
| 1837 | } |
| 1838 | |
| 1839 | /* |
Channagoud Kadabi | a22144f | 2013-03-20 11:49:01 -0700 | [diff] [blame] | 1840 | * Update the kernel/ramdisk/tags address if the boot image header |
| 1841 | * has default values, these default values come from mkbootimg when |
| 1842 | * the boot image is flashed using fastboot flash:raw |
| 1843 | */ |
Abhimanyu Kapur | 0f79d57 | 2014-02-19 22:03:02 -0800 | [diff] [blame] | 1844 | update_ker_tags_rdisk_addr(hdr, IS_ARM64(kptr)); |
Dima Zavin | 3cadfff | 2013-03-21 14:30:48 -0700 | [diff] [blame] | 1845 | |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1846 | /* Get virtual addresses since the hdr saves physical addresses. */ |
| 1847 | hdr->kernel_addr = VA(hdr->kernel_addr); |
| 1848 | hdr->ramdisk_addr = VA(hdr->ramdisk_addr); |
| 1849 | hdr->tags_addr = VA(hdr->tags_addr); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1850 | |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1851 | kernel_size = ROUND_TO_PAGE(kernel_size, page_mask); |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1852 | /* Check if the addresses in the header are valid. */ |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1853 | if (check_aboot_addr_range_overlap(hdr->kernel_addr, kernel_size) || |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1854 | check_aboot_addr_range_overlap(hdr->ramdisk_addr, ramdisk_actual)) |
| 1855 | { |
| 1856 | dprintf(CRITICAL, "kernel/ramdisk addresses overlap with aboot addresses.\n"); |
Channagoud Kadabi | 881856c | 2013-12-03 11:19:20 -0800 | [diff] [blame] | 1857 | return; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1860 | #if DEVICE_TREE |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1861 | scratch_offset = image_actual + page_size + out_len; |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1862 | /* find correct dtb and copy it to right location */ |
Matthew Qin | 271927e | 2015-03-31 22:07:07 -0400 | [diff] [blame] | 1863 | ret = copy_dtb(data, scratch_offset); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1864 | |
| 1865 | dtb_copied = !ret ? 1 : 0; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1866 | #else |
| 1867 | if (check_aboot_addr_range_overlap(hdr->tags_addr, MAX_TAGS_SIZE)) |
| 1868 | { |
| 1869 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
Channagoud Kadabi | 881856c | 2013-12-03 11:19:20 -0800 | [diff] [blame] | 1870 | return; |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 1871 | } |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1872 | #endif |
| 1873 | |
| 1874 | /* Load ramdisk & kernel */ |
| 1875 | 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] | 1876 | memmove((void*) hdr->kernel_addr, (char*) (kernel_start_addr), kernel_size); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1877 | |
| 1878 | #if DEVICE_TREE |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1879 | if (check_aboot_addr_range_overlap(hdr->tags_addr, kernel_actual)) |
| 1880 | { |
| 1881 | dprintf(CRITICAL, "Tags addresses overlap with aboot addresses.\n"); |
| 1882 | return; |
| 1883 | } |
| 1884 | |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1885 | /* |
| 1886 | * If dtb is not found look for appended DTB in the kernel. |
| 1887 | * If appended dev tree is found, update the atags with |
| 1888 | * memory address to the DTB appended location on RAM. |
| 1889 | * Else update with the atags address in the kernel header |
| 1890 | */ |
| 1891 | if (!dtb_copied) { |
| 1892 | void *dtb; |
Matthew Qin | bb7923d | 2015-02-09 10:56:09 +0800 | [diff] [blame] | 1893 | dtb = dev_tree_appended((void*)(ptr + page_size), |
| 1894 | hdr->kernel_size, dtb_offset, |
Dima Zavin | e63e557 | 2013-05-03 12:23:06 -0700 | [diff] [blame] | 1895 | (void *)hdr->tags_addr); |
Channagoud Kadabi | 8e9020f | 2013-04-16 11:24:32 -0700 | [diff] [blame] | 1896 | if (!dtb) { |
| 1897 | fastboot_fail("dtb not found"); |
| 1898 | return; |
| 1899 | } |
Amol Jadi | cb52407 | 2012-08-09 16:40:18 -0700 | [diff] [blame] | 1900 | } |
| 1901 | #endif |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1902 | |
| 1903 | fastboot_okay(""); |
Amol Jadi | 7c4316c | 2013-10-07 14:19:26 -0700 | [diff] [blame] | 1904 | fastboot_stop(); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1905 | |
Dima Zavin | 77e41f3 | 2013-03-06 16:10:43 -0800 | [diff] [blame] | 1906 | boot_linux((void*) hdr->kernel_addr, (void*) hdr->tags_addr, |
Deepa Dinamani | 0bf2f44 | 2012-10-19 11:41:06 -0700 | [diff] [blame] | 1907 | (const char*) hdr->cmdline, board_machtype(), |
| 1908 | (void*) hdr->ramdisk_addr, hdr->ramdisk_size); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 1909 | } |
| 1910 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 1911 | void cmd_erase_nand(const char *arg, void *data, unsigned sz) |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 1912 | { |
| 1913 | struct ptentry *ptn; |
| 1914 | struct ptable *ptable; |
| 1915 | |
| 1916 | ptable = flash_get_ptable(); |
| 1917 | if (ptable == NULL) { |
| 1918 | fastboot_fail("partition table doesn't exist"); |
| 1919 | return; |
| 1920 | } |
| 1921 | |
| 1922 | ptn = ptable_find(ptable, arg); |
| 1923 | if (ptn == NULL) { |
| 1924 | fastboot_fail("unknown partition name"); |
| 1925 | return; |
| 1926 | } |
| 1927 | |
| 1928 | if (flash_erase(ptn)) { |
| 1929 | fastboot_fail("failed to erase partition"); |
| 1930 | return; |
| 1931 | } |
| 1932 | fastboot_okay(""); |
| 1933 | } |
| 1934 | |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1935 | |
| 1936 | void cmd_erase_mmc(const char *arg, void *data, unsigned sz) |
| 1937 | { |
| 1938 | unsigned long long ptn = 0; |
Oliver Wang | cee448d | 2013-10-22 18:40:13 +0800 | [diff] [blame] | 1939 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1940 | int index = INVALID_PTN; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 1941 | uint8_t lun = 0; |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1942 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 1943 | #if VERIFIED_BOOT |
| 1944 | if(!strcmp(arg, KEYSTORE_PTN_NAME)) |
| 1945 | { |
| 1946 | if(!device.is_unlocked) |
| 1947 | { |
| 1948 | fastboot_fail("unlock device to erase keystore"); |
| 1949 | return; |
| 1950 | } |
| 1951 | } |
| 1952 | #endif |
| 1953 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1954 | index = partition_get_index(arg); |
| 1955 | ptn = partition_get_offset(index); |
Oliver Wang | cee448d | 2013-10-22 18:40:13 +0800 | [diff] [blame] | 1956 | size = partition_get_size(index); |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 1957 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 1958 | if(ptn == 0) { |
Neeti Desai | ca8c960 | 2011-10-06 11:40:00 -0700 | [diff] [blame] | 1959 | fastboot_fail("Partition table doesn't exist\n"); |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1960 | return; |
| 1961 | } |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 1962 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 1963 | lun = partition_get_lun(index); |
| 1964 | mmc_set_lun(lun); |
| 1965 | |
Sridhar Parasuram | d795712 | 2015-02-27 11:33:40 -0800 | [diff] [blame] | 1966 | if (platform_boot_dev_isemmc()) |
| 1967 | { |
| 1968 | if (mmc_erase_card(ptn, size)) { |
| 1969 | fastboot_fail("failed to erase partition\n"); |
| 1970 | return; |
| 1971 | } |
| 1972 | } else { |
| 1973 | BUF_DMA_ALIGN(out, DEFAULT_ERASE_SIZE); |
| 1974 | size = partition_get_size(index); |
| 1975 | if (size > DEFAULT_ERASE_SIZE) |
| 1976 | size = DEFAULT_ERASE_SIZE; |
Kun Liang | 2f1601a | 2013-08-12 16:29:54 +0800 | [diff] [blame] | 1977 | |
Sridhar Parasuram | d795712 | 2015-02-27 11:33:40 -0800 | [diff] [blame] | 1978 | /* Simple inefficient version of erase. Just writing |
| 1979 | 0 in first several blocks */ |
| 1980 | if (mmc_write(ptn , size, (unsigned int *)out)) { |
| 1981 | fastboot_fail("failed to erase partition"); |
| 1982 | return; |
| 1983 | } |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 1984 | } |
| 1985 | fastboot_okay(""); |
| 1986 | } |
| 1987 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 1988 | void cmd_erase(const char *arg, void *data, unsigned sz) |
| 1989 | { |
Channagoud Kadabi | ce3cf42 | 2015-04-17 16:02:30 -0700 | [diff] [blame] | 1990 | #if VERIFIED_BOOT |
| 1991 | if(!device.is_unlocked && !device.is_verified) |
| 1992 | { |
| 1993 | fastboot_fail("device is locked. Cannot erase"); |
| 1994 | return; |
| 1995 | } |
| 1996 | if(!device.is_unlocked && device.is_verified) |
| 1997 | { |
| 1998 | if(!boot_verify_flash_allowed(arg)) |
| 1999 | { |
| 2000 | fastboot_fail("cannot flash this partition in verified state"); |
| 2001 | return; |
| 2002 | } |
| 2003 | } |
| 2004 | #endif |
| 2005 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2006 | if(target_is_emmc_boot()) |
| 2007 | cmd_erase_mmc(arg, data, sz); |
| 2008 | else |
| 2009 | cmd_erase_nand(arg, data, sz); |
| 2010 | } |
Bikas Gurung | d48bd24 | 2010-09-04 19:54:32 -0700 | [diff] [blame] | 2011 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2012 | void cmd_flash_mmc_img(const char *arg, void *data, unsigned sz) |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2013 | { |
| 2014 | unsigned long long ptn = 0; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 2015 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2016 | int index = INVALID_PTN; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2017 | char *token = NULL; |
| 2018 | char *pname = NULL; |
| 2019 | uint8_t lun = 0; |
| 2020 | bool lun_set = false; |
Subbaraman Narayanamurthy | c95b5b1 | 2010-08-31 13:19:48 -0700 | [diff] [blame] | 2021 | |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 2022 | token = strtok((char *)arg, ":"); |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2023 | pname = token; |
| 2024 | token = strtok(NULL, ":"); |
| 2025 | if(token) |
| 2026 | { |
| 2027 | lun = atoi(token); |
| 2028 | mmc_set_lun(lun); |
| 2029 | lun_set = true; |
| 2030 | } |
| 2031 | |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2032 | if (pname) |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 2033 | { |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2034 | if (!strcmp(pname, "partition")) |
| 2035 | { |
| 2036 | dprintf(INFO, "Attempt to write partition image.\n"); |
| 2037 | if (write_partition(sz, (unsigned char *) data)) { |
| 2038 | fastboot_fail("failed to write partition"); |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 2039 | return; |
| 2040 | } |
| 2041 | } |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2042 | else |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2043 | { |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2044 | #if VERIFIED_BOOT |
| 2045 | if(!strcmp(pname, KEYSTORE_PTN_NAME)) |
| 2046 | { |
| 2047 | if(!device.is_unlocked) |
| 2048 | { |
| 2049 | fastboot_fail("unlock device to flash keystore"); |
| 2050 | return; |
| 2051 | } |
| 2052 | if(!boot_verify_validate_keystore((unsigned char *)data)) |
| 2053 | { |
| 2054 | fastboot_fail("image is not a keystore file"); |
| 2055 | return; |
| 2056 | } |
| 2057 | } |
| 2058 | #endif |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2059 | index = partition_get_index(pname); |
| 2060 | ptn = partition_get_offset(index); |
| 2061 | if(ptn == 0) { |
| 2062 | fastboot_fail("partition table doesn't exist"); |
| 2063 | return; |
| 2064 | } |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2065 | |
Mao Jinlong | 226f33a | 2014-07-04 17:24:10 +0800 | [diff] [blame] | 2066 | if (!strcmp(pname, "boot") || !strcmp(pname, "recovery")) { |
| 2067 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 2068 | fastboot_fail("image is not a boot image"); |
| 2069 | return; |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | if(!lun_set) |
| 2074 | { |
| 2075 | lun = partition_get_lun(index); |
| 2076 | mmc_set_lun(lun); |
| 2077 | } |
| 2078 | |
| 2079 | size = partition_get_size(index); |
| 2080 | if (ROUND_TO_PAGE(sz,511) > size) { |
| 2081 | fastboot_fail("size too large"); |
| 2082 | return; |
| 2083 | } |
| 2084 | else if (mmc_write(ptn , sz, (unsigned int *)data)) { |
| 2085 | fastboot_fail("flash write failure"); |
| 2086 | return; |
| 2087 | } |
Greg Grisco | 6e75477 | 2011-06-23 12:19:39 -0700 | [diff] [blame] | 2088 | } |
Shashank Mittal | 23b8f42 | 2010-04-16 19:27:21 -0700 | [diff] [blame] | 2089 | } |
| 2090 | fastboot_okay(""); |
| 2091 | return; |
| 2092 | } |
| 2093 | |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2094 | void cmd_flash_meta_img(const char *arg, void *data, unsigned sz) |
| 2095 | { |
| 2096 | int i, images; |
| 2097 | meta_header_t *meta_header; |
| 2098 | img_header_entry_t *img_header_entry; |
| 2099 | |
| 2100 | meta_header = (meta_header_t*) data; |
| 2101 | img_header_entry = (img_header_entry_t*) (data+sizeof(meta_header_t)); |
| 2102 | |
| 2103 | images = meta_header->img_hdr_sz / sizeof(img_header_entry_t); |
| 2104 | |
| 2105 | for (i=0; i<images; i++) { |
| 2106 | |
| 2107 | if((img_header_entry[i].ptn_name == NULL) || |
| 2108 | (img_header_entry[i].start_offset == 0) || |
| 2109 | (img_header_entry[i].size == 0)) |
| 2110 | break; |
| 2111 | |
| 2112 | cmd_flash_mmc_img(img_header_entry[i].ptn_name, |
| 2113 | (void *) data + img_header_entry[i].start_offset, |
| 2114 | img_header_entry[i].size); |
| 2115 | } |
| 2116 | |
Channagoud Kadabi | aafbbfc | 2015-03-04 17:52:56 -0800 | [diff] [blame] | 2117 | if (!strncmp(arg, "bootloader", strlen("bootloader"))) |
| 2118 | { |
| 2119 | strlcpy(device.bootloader_version, TARGET(BOARD), MAX_VERSION_LEN); |
| 2120 | strlcat(device.bootloader_version, "-", MAX_VERSION_LEN); |
| 2121 | strlcat(device.bootloader_version, meta_header->img_version, MAX_VERSION_LEN); |
| 2122 | } |
| 2123 | else |
| 2124 | { |
| 2125 | strlcpy(device.radio_version, TARGET(BOARD), MAX_VERSION_LEN); |
| 2126 | strlcat(device.radio_version, "-", MAX_VERSION_LEN); |
| 2127 | strlcat(device.radio_version, meta_header->img_version, MAX_VERSION_LEN); |
| 2128 | } |
| 2129 | |
| 2130 | write_device_info(&device); |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2131 | fastboot_okay(""); |
| 2132 | return; |
| 2133 | } |
| 2134 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2135 | void cmd_flash_mmc_sparse_img(const char *arg, void *data, unsigned sz) |
| 2136 | { |
| 2137 | unsigned int chunk; |
| 2138 | unsigned int chunk_data_sz; |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2139 | uint32_t *fill_buf = NULL; |
| 2140 | uint32_t fill_val; |
| 2141 | uint32_t chunk_blk_cnt = 0; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2142 | sparse_header_t *sparse_header; |
| 2143 | chunk_header_t *chunk_header; |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 2144 | uint32_t total_blocks = 0; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2145 | unsigned long long ptn = 0; |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 2146 | unsigned long long size = 0; |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2147 | int index = INVALID_PTN; |
Unnati Gandhi | 0c8e7c5 | 2014-07-17 14:33:09 +0530 | [diff] [blame] | 2148 | uint32_t i; |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2149 | uint8_t lun = 0; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2150 | /*End of the sparse image address*/ |
| 2151 | uint32_t data_end = (uint32_t)data + sz; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2152 | |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 2153 | index = partition_get_index(arg); |
| 2154 | ptn = partition_get_offset(index); |
| 2155 | if(ptn == 0) { |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2156 | fastboot_fail("partition table doesn't exist"); |
| 2157 | return; |
| 2158 | } |
| 2159 | |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 2160 | size = partition_get_size(index); |
Channagoud Kadabi | 65b9100 | 2011-10-11 17:34:33 +0530 | [diff] [blame] | 2161 | |
Sundarajan Srinivasan | d3514bb | 2013-12-04 17:02:00 -0800 | [diff] [blame] | 2162 | lun = partition_get_lun(index); |
| 2163 | mmc_set_lun(lun); |
| 2164 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2165 | if (sz < sizeof(sparse_header_t)) { |
| 2166 | fastboot_fail("size too low"); |
| 2167 | return; |
| 2168 | } |
| 2169 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2170 | /* Read and skip over sparse image header */ |
| 2171 | sparse_header = (sparse_header_t *) data; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2172 | |
vijay kumar | 1321f34 | 2015-03-27 12:13:42 +0530 | [diff] [blame] | 2173 | 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] | 2174 | fastboot_fail("size too large"); |
| 2175 | return; |
| 2176 | } |
| 2177 | |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 2178 | data += sizeof(sparse_header_t); |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2179 | |
| 2180 | if (data_end < (uint32_t)data) { |
| 2181 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2182 | return; |
| 2183 | } |
| 2184 | |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 2185 | if(sparse_header->file_hdr_sz != sizeof(sparse_header_t)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2186 | { |
vijay kumar | de4fcf6 | 2015-04-23 13:05:49 +0530 | [diff] [blame] | 2187 | fastboot_fail("sparse header size mismatch"); |
| 2188 | return; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 2191 | dprintf (SPEW, "=== Sparse Image Header ===\n"); |
| 2192 | dprintf (SPEW, "magic: 0x%x\n", sparse_header->magic); |
| 2193 | dprintf (SPEW, "major_version: 0x%x\n", sparse_header->major_version); |
| 2194 | dprintf (SPEW, "minor_version: 0x%x\n", sparse_header->minor_version); |
| 2195 | dprintf (SPEW, "file_hdr_sz: %d\n", sparse_header->file_hdr_sz); |
| 2196 | dprintf (SPEW, "chunk_hdr_sz: %d\n", sparse_header->chunk_hdr_sz); |
| 2197 | dprintf (SPEW, "blk_sz: %d\n", sparse_header->blk_sz); |
| 2198 | dprintf (SPEW, "total_blks: %d\n", sparse_header->total_blks); |
| 2199 | dprintf (SPEW, "total_chunks: %d\n", sparse_header->total_chunks); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2200 | |
| 2201 | /* Start processing chunks */ |
| 2202 | for (chunk=0; chunk<sparse_header->total_chunks; chunk++) |
| 2203 | { |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2204 | /* Make sure the total image size does not exceed the partition size */ |
| 2205 | if(((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz) >= size) { |
| 2206 | fastboot_fail("size too large"); |
| 2207 | return; |
| 2208 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2209 | /* Read and skip over chunk header */ |
| 2210 | chunk_header = (chunk_header_t *) data; |
| 2211 | data += sizeof(chunk_header_t); |
| 2212 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2213 | if (data_end < (uint32_t)data) { |
| 2214 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2215 | return; |
| 2216 | } |
| 2217 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2218 | dprintf (SPEW, "=== Chunk Header ===\n"); |
| 2219 | dprintf (SPEW, "chunk_type: 0x%x\n", chunk_header->chunk_type); |
| 2220 | dprintf (SPEW, "chunk_data_sz: 0x%x\n", chunk_header->chunk_sz); |
| 2221 | dprintf (SPEW, "total_size: 0x%x\n", chunk_header->total_sz); |
| 2222 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2223 | if(sparse_header->chunk_hdr_sz != sizeof(chunk_header_t)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2224 | { |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2225 | fastboot_fail("chunk header size mismatch"); |
| 2226 | return; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | chunk_data_sz = sparse_header->blk_sz * chunk_header->chunk_sz; |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2230 | |
| 2231 | /* Make sure multiplication does not overflow uint32 size */ |
| 2232 | if (sparse_header->blk_sz && (chunk_header->chunk_sz != chunk_data_sz / sparse_header->blk_sz)) |
| 2233 | { |
| 2234 | fastboot_fail("Bogus size sparse and chunk header"); |
| 2235 | return; |
| 2236 | } |
| 2237 | |
| 2238 | /* Make sure that the chunk size calculated from sparse image does not |
| 2239 | * exceed partition size |
| 2240 | */ |
| 2241 | if ((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz + chunk_data_sz > size) |
| 2242 | { |
| 2243 | fastboot_fail("Chunk data size exceeds partition size"); |
| 2244 | return; |
| 2245 | } |
| 2246 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2247 | switch (chunk_header->chunk_type) |
| 2248 | { |
| 2249 | case CHUNK_TYPE_RAW: |
| 2250 | if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz + |
| 2251 | chunk_data_sz)) |
| 2252 | { |
| 2253 | fastboot_fail("Bogus chunk size for chunk type Raw"); |
| 2254 | return; |
| 2255 | } |
| 2256 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2257 | if (data_end < (uint32_t)data + chunk_data_sz) { |
| 2258 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2259 | return; |
| 2260 | } |
| 2261 | |
Ajay Dudani | ab18f02 | 2011-05-12 14:39:22 -0700 | [diff] [blame] | 2262 | if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz), |
| 2263 | chunk_data_sz, |
| 2264 | (unsigned int*)data)) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2265 | { |
| 2266 | fastboot_fail("flash write failure"); |
| 2267 | return; |
| 2268 | } |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2269 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 2270 | fastboot_fail("Bogus size for RAW chunk type"); |
| 2271 | return; |
| 2272 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2273 | total_blocks += chunk_header->chunk_sz; |
| 2274 | data += chunk_data_sz; |
| 2275 | break; |
| 2276 | |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2277 | case CHUNK_TYPE_FILL: |
| 2278 | if(chunk_header->total_sz != (sparse_header->chunk_hdr_sz + |
| 2279 | sizeof(uint32_t))) |
| 2280 | { |
| 2281 | fastboot_fail("Bogus chunk size for chunk type FILL"); |
| 2282 | return; |
| 2283 | } |
| 2284 | |
| 2285 | fill_buf = (uint32_t *)memalign(CACHE_LINE, ROUNDUP(sparse_header->blk_sz, CACHE_LINE)); |
| 2286 | if (!fill_buf) |
| 2287 | { |
| 2288 | fastboot_fail("Malloc failed for: CHUNK_TYPE_FILL"); |
| 2289 | return; |
| 2290 | } |
| 2291 | |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2292 | if (data_end < (uint32_t)data + sizeof(uint32_t)) { |
| 2293 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2294 | return; |
| 2295 | } |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2296 | fill_val = *(uint32_t *)data; |
| 2297 | data = (char *) data + sizeof(uint32_t); |
| 2298 | chunk_blk_cnt = chunk_data_sz / sparse_header->blk_sz; |
| 2299 | |
| 2300 | for (i = 0; i < (sparse_header->blk_sz / sizeof(fill_val)); i++) |
| 2301 | { |
| 2302 | fill_buf[i] = fill_val; |
| 2303 | } |
| 2304 | |
| 2305 | for (i = 0; i < chunk_blk_cnt; i++) |
| 2306 | { |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2307 | /* Make sure that the data written to partition does not exceed partition size */ |
| 2308 | if ((uint64_t)total_blocks * (uint64_t)sparse_header->blk_sz + sparse_header->blk_sz > size) |
| 2309 | { |
| 2310 | fastboot_fail("Chunk data size for fill type exceeds partition size"); |
| 2311 | return; |
| 2312 | } |
| 2313 | |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2314 | if(mmc_write(ptn + ((uint64_t)total_blocks*sparse_header->blk_sz), |
| 2315 | sparse_header->blk_sz, |
| 2316 | fill_buf)) |
| 2317 | { |
| 2318 | fastboot_fail("flash write failure"); |
| 2319 | free(fill_buf); |
| 2320 | return; |
| 2321 | } |
| 2322 | |
| 2323 | total_blocks++; |
| 2324 | } |
| 2325 | |
| 2326 | free(fill_buf); |
| 2327 | break; |
| 2328 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2329 | case CHUNK_TYPE_DONT_CARE: |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2330 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 2331 | fastboot_fail("bogus size for chunk DONT CARE type"); |
| 2332 | return; |
| 2333 | } |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 2334 | total_blocks += chunk_header->chunk_sz; |
| 2335 | break; |
| 2336 | |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2337 | case CHUNK_TYPE_CRC: |
| 2338 | if(chunk_header->total_sz != sparse_header->chunk_hdr_sz) |
| 2339 | { |
| 2340 | fastboot_fail("Bogus chunk size for chunk type Dont Care"); |
| 2341 | return; |
| 2342 | } |
Aparna Mallavarapu | 2ae741a | 2015-03-28 01:41:08 +0530 | [diff] [blame] | 2343 | if(total_blocks > (UINT_MAX - chunk_header->chunk_sz)) { |
| 2344 | fastboot_fail("bogus size for chunk CRC type"); |
| 2345 | return; |
| 2346 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2347 | total_blocks += chunk_header->chunk_sz; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2348 | if ((uint32_t)data > UINT_MAX - chunk_data_sz) { |
| 2349 | fastboot_fail("integer overflow occured"); |
| 2350 | return; |
| 2351 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2352 | data += chunk_data_sz; |
vijay kumar | 800255e | 2015-04-24 20:26:19 +0530 | [diff] [blame^] | 2353 | if (data_end < (uint32_t)data) { |
| 2354 | fastboot_fail("buffer overreads occured due to invalid sparse header"); |
| 2355 | return; |
| 2356 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2357 | break; |
| 2358 | |
Kinson Chik kchik@codeaurora.org | da29b1e | 2011-05-06 17:36:39 -0700 | [diff] [blame] | 2359 | default: |
Channagoud Kadabi | f627cf8 | 2013-09-09 14:08:20 -0700 | [diff] [blame] | 2360 | dprintf(CRITICAL, "Unkown chunk type: %x\n",chunk_header->chunk_type); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2361 | fastboot_fail("Unknown chunk type"); |
| 2362 | return; |
| 2363 | } |
| 2364 | } |
| 2365 | |
Ajay Dudani | 0c6927b | 2011-05-18 11:12:16 -0700 | [diff] [blame] | 2366 | dprintf(INFO, "Wrote %d blocks, expected to write %d blocks\n", |
| 2367 | total_blocks, sparse_header->total_blks); |
| 2368 | |
| 2369 | if(total_blocks != sparse_header->total_blks) |
| 2370 | { |
| 2371 | fastboot_fail("sparse image write failure"); |
| 2372 | } |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2373 | |
| 2374 | fastboot_okay(""); |
| 2375 | return; |
| 2376 | } |
| 2377 | |
| 2378 | void cmd_flash_mmc(const char *arg, void *data, unsigned sz) |
| 2379 | { |
| 2380 | sparse_header_t *sparse_header; |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2381 | meta_header_t *meta_header; |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2382 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 2383 | #ifdef SSD_ENABLE |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 2384 | /* 8 Byte Magic + 2048 Byte xml + Encrypted Data */ |
| 2385 | unsigned int *magic_number = (unsigned int *) data; |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2386 | int ret=0; |
| 2387 | uint32 major_version=0; |
| 2388 | uint32 minor_version=0; |
| 2389 | |
| 2390 | ret = scm_svc_version(&major_version,&minor_version); |
| 2391 | if(!ret) |
| 2392 | { |
| 2393 | if(major_version >= 2) |
| 2394 | { |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 2395 | if( !strcmp(arg, "ssd") || !strcmp(arg, "tqs") ) |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2396 | { |
| 2397 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 2398 | if (ret != 0) { |
| 2399 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 2400 | return; |
| 2401 | } |
| 2402 | |
Amir Samuelov | bb65ce0 | 2013-05-05 12:20:18 +0300 | [diff] [blame] | 2403 | /* Protect only for SSD */ |
| 2404 | if (!strcmp(arg, "ssd")) { |
| 2405 | ret = scm_protect_keystore((uint32 *) data, sz); |
| 2406 | if (ret != 0) { |
| 2407 | dprintf(CRITICAL, "ERROR: scm_protect_keystore Failed\n"); |
| 2408 | return; |
| 2409 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | else |
| 2413 | { |
| 2414 | ret = decrypt_scm_v2((uint32 **) &data, &sz); |
| 2415 | if(ret != 0) |
| 2416 | { |
| 2417 | dprintf(CRITICAL,"ERROR: Decryption Failure\n"); |
| 2418 | return; |
| 2419 | } |
| 2420 | } |
| 2421 | } |
| 2422 | else |
| 2423 | { |
| 2424 | if (magic_number[0] == DECRYPT_MAGIC_0 && |
| 2425 | magic_number[1] == DECRYPT_MAGIC_1) |
| 2426 | { |
| 2427 | ret = decrypt_scm((uint32 **) &data, &sz); |
| 2428 | if (ret != 0) { |
| 2429 | dprintf(CRITICAL, "ERROR: Invalid secure image\n"); |
| 2430 | return; |
| 2431 | } |
| 2432 | } |
| 2433 | else if (magic_number[0] == ENCRYPT_MAGIC_0 && |
| 2434 | magic_number[1] == ENCRYPT_MAGIC_1) |
| 2435 | { |
| 2436 | ret = encrypt_scm((uint32 **) &data, &sz); |
| 2437 | if (ret != 0) { |
| 2438 | dprintf(CRITICAL, "ERROR: Encryption Failure\n"); |
| 2439 | return; |
| 2440 | } |
| 2441 | } |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 2442 | } |
| 2443 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2444 | else |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 2445 | { |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2446 | dprintf(CRITICAL,"INVALID SVC Version\n"); |
| 2447 | return; |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 2448 | } |
sundarajan srinivasan | d4b1c48 | 2013-02-27 14:15:43 -0800 | [diff] [blame] | 2449 | #endif /* SSD_ENABLE */ |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 2450 | |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2451 | #if VERIFIED_BOOT |
| 2452 | if(!device.is_unlocked && !device.is_verified) |
| 2453 | { |
| 2454 | fastboot_fail("device is locked. Cannot flash images"); |
| 2455 | return; |
| 2456 | } |
| 2457 | if(!device.is_unlocked && device.is_verified) |
| 2458 | { |
| 2459 | if(!boot_verify_flash_allowed(arg)) |
| 2460 | { |
| 2461 | fastboot_fail("cannot flash this partition in verified state"); |
| 2462 | return; |
| 2463 | } |
| 2464 | } |
| 2465 | #endif |
| 2466 | |
kchik@codeaurora.org | bce18ea | 2011-04-18 20:22:28 -0700 | [diff] [blame] | 2467 | sparse_header = (sparse_header_t *) data; |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2468 | meta_header = (meta_header_t *) data; |
| 2469 | if (sparse_header->magic == SPARSE_HEADER_MAGIC) |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2470 | cmd_flash_mmc_sparse_img(arg, data, sz); |
Ajay Dudani | de98479 | 2015-03-02 09:57:41 -0800 | [diff] [blame] | 2471 | else if (meta_header->magic == META_HEADER_MAGIC) |
| 2472 | cmd_flash_meta_img(arg, data, sz); |
| 2473 | else |
| 2474 | cmd_flash_mmc_img(arg, data, sz); |
Ajay Dudani | 5c76113 | 2011-04-07 20:19:04 -0700 | [diff] [blame] | 2475 | return; |
| 2476 | } |
| 2477 | |
Tanya Brokhman | 84eaaf6 | 2015-02-24 21:57:06 +0200 | [diff] [blame] | 2478 | void cmd_updatevol(const char *vol_name, void *data, unsigned sz) |
| 2479 | { |
| 2480 | struct ptentry *sys_ptn; |
| 2481 | struct ptable *ptable; |
| 2482 | |
| 2483 | ptable = flash_get_ptable(); |
| 2484 | if (ptable == NULL) { |
| 2485 | fastboot_fail("partition table doesn't exist"); |
| 2486 | return; |
| 2487 | } |
| 2488 | |
| 2489 | sys_ptn = ptable_find(ptable, "system"); |
| 2490 | if (sys_ptn == NULL) { |
| 2491 | fastboot_fail("system partition not found"); |
| 2492 | return; |
| 2493 | } |
| 2494 | |
| 2495 | sz = ROUND_TO_PAGE(sz, page_mask); |
| 2496 | if (update_ubi_vol(sys_ptn, vol_name, data, sz)) |
| 2497 | fastboot_fail("update_ubi_vol failed"); |
| 2498 | else |
| 2499 | fastboot_okay(""); |
| 2500 | } |
| 2501 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2502 | void cmd_flash_nand(const char *arg, void *data, unsigned sz) |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2503 | { |
| 2504 | struct ptentry *ptn; |
| 2505 | struct ptable *ptable; |
| 2506 | unsigned extra = 0; |
| 2507 | |
| 2508 | ptable = flash_get_ptable(); |
| 2509 | if (ptable == NULL) { |
| 2510 | fastboot_fail("partition table doesn't exist"); |
| 2511 | return; |
| 2512 | } |
| 2513 | |
| 2514 | ptn = ptable_find(ptable, arg); |
| 2515 | if (ptn == NULL) { |
Tanya Brokhman | 84eaaf6 | 2015-02-24 21:57:06 +0200 | [diff] [blame] | 2516 | dprintf(INFO, "unknown partition name (%s). Trying updatevol\n", |
| 2517 | arg); |
| 2518 | cmd_updatevol(arg, data, sz); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2519 | return; |
| 2520 | } |
| 2521 | |
| 2522 | if (!strcmp(ptn->name, "boot") || !strcmp(ptn->name, "recovery")) { |
| 2523 | if (memcmp((void *)data, BOOT_MAGIC, BOOT_MAGIC_SIZE)) { |
| 2524 | fastboot_fail("image is not a boot image"); |
| 2525 | return; |
| 2526 | } |
| 2527 | } |
| 2528 | |
Amol Jadi | 5c61a95 | 2012-05-04 17:05:35 -0700 | [diff] [blame] | 2529 | if (!strcmp(ptn->name, "system") |
Deepa Dinamani | 13e32c4 | 2012-03-12 14:34:17 -0700 | [diff] [blame] | 2530 | || !strcmp(ptn->name, "userdata") |
| 2531 | || !strcmp(ptn->name, "persist") |
Sundarajan Srinivasan | b063a85 | 2013-11-19 14:02:27 -0800 | [diff] [blame] | 2532 | || !strcmp(ptn->name, "recoveryfs") |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 2533 | || !strcmp(ptn->name, "modem")) |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 2534 | extra = 1; |
Sundarajan Srinivasan | 595b71e | 2013-11-05 12:44:34 -0800 | [diff] [blame] | 2535 | else |
Shashank Mittal | dcc2e35 | 2009-11-19 19:11:16 -0800 | [diff] [blame] | 2536 | sz = ROUND_TO_PAGE(sz, page_mask); |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2537 | |
| 2538 | dprintf(INFO, "writing %d bytes to '%s'\n", sz, ptn->name); |
Tanya Brokhman | 1c94f1a | 2015-02-15 09:05:03 +0200 | [diff] [blame] | 2539 | if (!memcmp((void *)data, UBI_MAGIC, UBI_MAGIC_SIZE)) { |
| 2540 | if (flash_ubi_img(ptn, data, sz)) { |
| 2541 | fastboot_fail("flash write failure"); |
| 2542 | return; |
| 2543 | } |
| 2544 | } else { |
| 2545 | if (flash_write(ptn, extra, data, sz)) { |
| 2546 | fastboot_fail("flash write failure"); |
| 2547 | return; |
| 2548 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2549 | } |
| 2550 | dprintf(INFO, "partition '%s' updated\n", ptn->name); |
| 2551 | fastboot_okay(""); |
| 2552 | } |
| 2553 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2554 | void cmd_flash(const char *arg, void *data, unsigned sz) |
| 2555 | { |
| 2556 | if(target_is_emmc_boot()) |
| 2557 | cmd_flash_mmc(arg, data, sz); |
| 2558 | else |
| 2559 | cmd_flash_nand(arg, data, sz); |
| 2560 | } |
| 2561 | |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2562 | void cmd_continue(const char *arg, void *data, unsigned sz) |
| 2563 | { |
| 2564 | fastboot_okay(""); |
Amol Jadi | 7c4316c | 2013-10-07 14:19:26 -0700 | [diff] [blame] | 2565 | fastboot_stop(); |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2566 | |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 2567 | #ifdef MDTP_SUPPORT |
| 2568 | /* Go through Firmware Lock verification before continue with boot process */ |
| 2569 | mdtp_fwlock_verify_lock(); |
Reut Zysman | 1841127 | 2015-02-09 13:47:27 +0200 | [diff] [blame] | 2570 | display_image_on_screen(); |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 2571 | #endif /* MDTP_SUPPORT */ |
| 2572 | |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 2573 | if (target_is_emmc_boot()) |
| 2574 | { |
| 2575 | boot_linux_from_mmc(); |
| 2576 | } |
| 2577 | else |
| 2578 | { |
| 2579 | boot_linux_from_flash(); |
| 2580 | } |
Dima Zavin | 214cc64 | 2009-01-26 11:16:21 -0800 | [diff] [blame] | 2581 | } |
| 2582 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 2583 | void cmd_reboot(const char *arg, void *data, unsigned sz) |
| 2584 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 2585 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 2586 | fastboot_okay(""); |
| 2587 | reboot_device(0); |
| 2588 | } |
| 2589 | |
| 2590 | void cmd_reboot_bootloader(const char *arg, void *data, unsigned sz) |
| 2591 | { |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 2592 | dprintf(INFO, "rebooting the device\n"); |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 2593 | fastboot_okay(""); |
| 2594 | reboot_device(FASTBOOT_MODE); |
| 2595 | } |
| 2596 | |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 2597 | void cmd_oem_enable_charger_screen(const char *arg, void *data, unsigned size) |
| 2598 | { |
| 2599 | dprintf(INFO, "Enabling charger screen check\n"); |
| 2600 | device.charger_screen_enabled = 1; |
| 2601 | write_device_info(&device); |
| 2602 | fastboot_okay(""); |
| 2603 | } |
| 2604 | |
| 2605 | void cmd_oem_disable_charger_screen(const char *arg, void *data, unsigned size) |
| 2606 | { |
| 2607 | dprintf(INFO, "Disabling charger screen check\n"); |
| 2608 | device.charger_screen_enabled = 0; |
| 2609 | write_device_info(&device); |
| 2610 | fastboot_okay(""); |
| 2611 | } |
| 2612 | |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 2613 | void cmd_oem_select_display_panel(const char *arg, void *data, unsigned size) |
| 2614 | { |
| 2615 | dprintf(INFO, "Selecting display panel %s\n", arg); |
| 2616 | if (arg) |
| 2617 | strlcpy(device.display_panel, arg, |
| 2618 | sizeof(device.display_panel)); |
| 2619 | write_device_info(&device); |
| 2620 | fastboot_okay(""); |
| 2621 | } |
| 2622 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2623 | void cmd_oem_unlock(const char *arg, void *data, unsigned sz) |
| 2624 | { |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2625 | /* TODO: Wipe user data */ |
| 2626 | if(!device.is_unlocked || device.is_verified) |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2627 | { |
| 2628 | device.is_unlocked = 1; |
Shashank Mittal | d3e54dd | 2014-08-28 15:24:02 -0700 | [diff] [blame] | 2629 | device.is_verified = 0; |
| 2630 | write_device_info(&device); |
| 2631 | } |
| 2632 | fastboot_okay(""); |
| 2633 | } |
| 2634 | |
| 2635 | void cmd_oem_lock(const char *arg, void *data, unsigned sz) |
| 2636 | { |
| 2637 | /* TODO: Wipe user data */ |
| 2638 | if(device.is_unlocked || device.is_verified) |
| 2639 | { |
| 2640 | device.is_unlocked = 0; |
| 2641 | device.is_verified = 0; |
| 2642 | write_device_info(&device); |
| 2643 | } |
| 2644 | fastboot_okay(""); |
| 2645 | } |
| 2646 | |
| 2647 | void cmd_oem_verified(const char *arg, void *data, unsigned sz) |
| 2648 | { |
| 2649 | /* TODO: Wipe user data */ |
| 2650 | if(device.is_unlocked || !device.is_verified) |
| 2651 | { |
| 2652 | device.is_unlocked = 0; |
| 2653 | device.is_verified = 1; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2654 | write_device_info(&device); |
| 2655 | } |
| 2656 | fastboot_okay(""); |
| 2657 | } |
| 2658 | |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2659 | void cmd_oem_devinfo(const char *arg, void *data, unsigned sz) |
| 2660 | { |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 2661 | char response[128]; |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 2662 | snprintf(response, sizeof(response), "\tDevice tampered: %s", (device.is_tampered ? "true" : "false")); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2663 | fastboot_info(response); |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 2664 | snprintf(response, sizeof(response), "\tDevice unlocked: %s", (device.is_unlocked ? "true" : "false")); |
| 2665 | fastboot_info(response); |
| 2666 | 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] | 2667 | fastboot_info(response); |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 2668 | snprintf(response, sizeof(response), "\tDisplay panel: %s", (device.display_panel)); |
| 2669 | fastboot_info(response); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 2670 | fastboot_okay(""); |
| 2671 | } |
| 2672 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 2673 | void cmd_preflash(const char *arg, void *data, unsigned sz) |
| 2674 | { |
| 2675 | fastboot_okay(""); |
| 2676 | } |
| 2677 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2678 | struct fbimage* splash_screen_flash(); |
| 2679 | |
| 2680 | int splash_screen_check_header(struct fbimage *logo) |
| 2681 | { |
| 2682 | if (memcmp(logo->header.magic, LOGO_IMG_MAGIC, 8)) |
| 2683 | return -1; |
| 2684 | if (logo->header.width == 0 || logo->header.height == 0) |
| 2685 | return -1; |
| 2686 | return 0; |
| 2687 | } |
| 2688 | |
| 2689 | struct fbimage* splash_screen_flash() |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 2690 | { |
| 2691 | struct ptentry *ptn; |
| 2692 | struct ptable *ptable; |
| 2693 | struct fbcon_config *fb_display = NULL; |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2694 | struct fbimage *logo = NULL; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 2695 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2696 | |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2697 | logo = (struct fbimage *) malloc(ROUNDUP(page_size, sizeof(struct fbimage))); |
| 2698 | ASSERT(logo); |
| 2699 | |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2700 | ptable = flash_get_ptable(); |
| 2701 | if (ptable == NULL) { |
| 2702 | dprintf(CRITICAL, "ERROR: Partition table not found\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2703 | goto err; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2704 | } |
| 2705 | ptn = ptable_find(ptable, "splash"); |
| 2706 | if (ptn == NULL) { |
| 2707 | dprintf(CRITICAL, "ERROR: splash Partition not found\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2708 | goto err; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2709 | } |
| 2710 | |
| 2711 | if (flash_read(ptn, 0,(unsigned int *) logo, sizeof(logo->header))) { |
| 2712 | dprintf(CRITICAL, "ERROR: Cannot read boot image header\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2713 | goto err; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | if (splash_screen_check_header(logo)) { |
| 2717 | dprintf(CRITICAL, "ERROR: Boot image header invalid\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2718 | goto err; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | fb_display = fbcon_display(); |
| 2722 | if (fb_display) { |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 2723 | if ((logo->header.width != fb_display->width) || (logo->header.height != fb_display->height)) { |
| 2724 | dprintf(CRITICAL, "Logo config doesn't match with fb config. Fall back to default logo\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2725 | goto err; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 2726 | } |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 2727 | uint8_t *base = (uint8_t *) fb_display->base; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2728 | if (flash_read(ptn + sizeof(logo->header), 0, |
| 2729 | base, |
| 2730 | ((((logo->header.width * logo->header.height * fb_display->bpp/8) + 511) >> 9) << 9))) { |
| 2731 | fbcon_clear(); |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 2732 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2733 | goto err; |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 2734 | } |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2735 | logo->image = base; |
| 2736 | } |
| 2737 | |
| 2738 | return logo; |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2739 | |
| 2740 | err: |
| 2741 | free(logo); |
| 2742 | return NULL; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | struct fbimage* splash_screen_mmc() |
| 2746 | { |
| 2747 | int index = INVALID_PTN; |
| 2748 | unsigned long long ptn = 0; |
| 2749 | struct fbcon_config *fb_display = NULL; |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2750 | struct fbimage *logo = NULL; |
Channagoud Kadabi | da11739 | 2014-11-24 11:01:12 -0800 | [diff] [blame] | 2751 | uint32_t blocksize; |
| 2752 | uint32_t readsize; |
Channagoud Kadabi | cccd02c | 2015-02-19 17:51:40 -0800 | [diff] [blame] | 2753 | uint32_t logosize; |
Channagoud Kadabi | da11739 | 2014-11-24 11:01:12 -0800 | [diff] [blame] | 2754 | uint32_t ptn_size; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2755 | |
| 2756 | index = partition_get_index("splash"); |
| 2757 | if (index == 0) { |
| 2758 | dprintf(CRITICAL, "ERROR: splash Partition table not found\n"); |
| 2759 | return NULL; |
| 2760 | } |
| 2761 | |
| 2762 | ptn = partition_get_offset(index); |
| 2763 | if (ptn == 0) { |
| 2764 | dprintf(CRITICAL, "ERROR: splash Partition invalid\n"); |
| 2765 | return NULL; |
| 2766 | } |
| 2767 | |
Channagoud Kadabi | da11739 | 2014-11-24 11:01:12 -0800 | [diff] [blame] | 2768 | ptn_size = partition_get_size(index); |
| 2769 | blocksize = mmc_get_device_blocksize(); |
Channagoud Kadabi | cccd02c | 2015-02-19 17:51:40 -0800 | [diff] [blame] | 2770 | logosize = ROUNDUP(sizeof(logo->header), blocksize); |
Channagoud Kadabi | da11739 | 2014-11-24 11:01:12 -0800 | [diff] [blame] | 2771 | |
Channagoud Kadabi | cccd02c | 2015-02-19 17:51:40 -0800 | [diff] [blame] | 2772 | logo = (struct fbimage *)memalign(CACHE_LINE, ROUNDUP(logosize, CACHE_LINE)); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2773 | ASSERT(logo); |
| 2774 | |
Channagoud Kadabi | cccd02c | 2015-02-19 17:51:40 -0800 | [diff] [blame] | 2775 | if (mmc_read(ptn, (uint32_t *) logo, logosize)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2776 | dprintf(CRITICAL, "ERROR: Cannot read splash image header\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2777 | goto err; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | if (splash_screen_check_header(logo)) { |
| 2781 | dprintf(CRITICAL, "ERROR: Splash image header invalid\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2782 | goto err; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | fb_display = fbcon_display(); |
| 2786 | if (fb_display) { |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 2787 | if ((logo->header.width != fb_display->width) || (logo->header.height != fb_display->height)) { |
| 2788 | dprintf(CRITICAL, "Logo config doesn't match with fb config. Fall back default logo\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2789 | goto err; |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 2790 | } |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2791 | uint8_t *base = (uint8_t *) fb_display->base; |
Channagoud Kadabi | da11739 | 2014-11-24 11:01:12 -0800 | [diff] [blame] | 2792 | readsize = ROUNDUP((logo->header.width * logo->header.height * fb_display->bpp/8), blocksize); |
| 2793 | |
| 2794 | if (readsize > ptn_size) |
| 2795 | { |
| 2796 | dprintf(CRITICAL, "@%d:Invalid logo header readsize:%u exceeds ptn_size:%u\n", __LINE__, readsize,ptn_size); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2797 | goto err; |
Channagoud Kadabi | da11739 | 2014-11-24 11:01:12 -0800 | [diff] [blame] | 2798 | } |
| 2799 | |
Channagoud Kadabi | cccd02c | 2015-02-19 17:51:40 -0800 | [diff] [blame] | 2800 | if (mmc_read(ptn + logosize,(uint32_t *)base, readsize)) { |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2801 | fbcon_clear(); |
Vineet Bajaj | 99291ed | 2014-09-09 12:29:46 +0530 | [diff] [blame] | 2802 | dprintf(CRITICAL, "ERROR: Cannot read splash image from partition\n"); |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2803 | goto err; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2804 | } |
| 2805 | |
| 2806 | logo->image = base; |
| 2807 | } |
| 2808 | |
| 2809 | return logo; |
Channagoud Kadabi | b3ccf5c | 2014-12-03 12:39:29 -0800 | [diff] [blame] | 2810 | |
| 2811 | err: |
| 2812 | free(logo); |
| 2813 | return NULL; |
Aparna Mallavarapu | ad8c1ec | 2013-08-23 17:55:47 +0530 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | |
| 2817 | struct fbimage* fetch_image_from_partition() |
| 2818 | { |
| 2819 | if (target_is_emmc_boot()) { |
| 2820 | return splash_screen_mmc(); |
| 2821 | } else { |
| 2822 | return splash_screen_flash(); |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 2823 | } |
| 2824 | } |
| 2825 | |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 2826 | /* Get the size from partiton name */ |
| 2827 | static void get_partition_size(const char *arg, char *response) |
| 2828 | { |
| 2829 | uint64_t ptn = 0; |
| 2830 | uint64_t size; |
| 2831 | int index = INVALID_PTN; |
| 2832 | |
| 2833 | index = partition_get_index(arg); |
| 2834 | |
| 2835 | if (index == INVALID_PTN) |
| 2836 | { |
| 2837 | dprintf(CRITICAL, "Invalid partition index\n"); |
| 2838 | return; |
| 2839 | } |
| 2840 | |
| 2841 | ptn = partition_get_offset(index); |
| 2842 | |
| 2843 | if(!ptn) |
| 2844 | { |
| 2845 | dprintf(CRITICAL, "Invalid partition name %s\n", arg); |
| 2846 | return; |
| 2847 | } |
| 2848 | |
| 2849 | size = partition_get_size(index); |
| 2850 | |
| 2851 | snprintf(response, MAX_RSP_SIZE, "\t 0x%llx", size); |
| 2852 | return; |
| 2853 | } |
| 2854 | |
| 2855 | /* |
| 2856 | * Publish the partition type & size info |
| 2857 | * fastboot getvar will publish the required information. |
| 2858 | * fastboot getvar partition_size:<partition_name>: partition size in hex |
| 2859 | * fastboot getvar partition_type:<partition_name>: partition type (ext/fat) |
| 2860 | */ |
| 2861 | static void publish_getvar_partition_info(struct getvar_partition_info *info, uint8_t num_parts) |
| 2862 | { |
| 2863 | uint8_t i; |
| 2864 | |
| 2865 | for (i = 0; i < num_parts; i++) { |
| 2866 | get_partition_size(info[i].part_name, info[i].size_response); |
| 2867 | |
| 2868 | if (strlcat(info[i].getvar_size, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 2869 | { |
| 2870 | dprintf(CRITICAL, "partition size name truncated\n"); |
| 2871 | return; |
| 2872 | } |
| 2873 | if (strlcat(info[i].getvar_type, info[i].part_name, MAX_GET_VAR_NAME_SIZE) >= MAX_GET_VAR_NAME_SIZE) |
| 2874 | { |
| 2875 | dprintf(CRITICAL, "partition type name truncated\n"); |
| 2876 | return; |
| 2877 | } |
| 2878 | |
| 2879 | /* publish partition size & type info */ |
| 2880 | fastboot_publish((const char *) info[i].getvar_size, (const char *) info[i].size_response); |
| 2881 | fastboot_publish((const char *) info[i].getvar_type, (const char *) info[i].type_response); |
| 2882 | } |
| 2883 | } |
| 2884 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 2885 | /* register commands and variables for fastboot */ |
| 2886 | void aboot_fastboot_register_commands(void) |
| 2887 | { |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2888 | int i; |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 2889 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2890 | struct fastboot_cmd_desc cmd_list[] = { |
| 2891 | /* By default the enabled list is empty. */ |
| 2892 | {"", NULL}, |
| 2893 | /* move commands enclosed within the below ifndef to here |
| 2894 | * if they need to be enabled in user build. |
| 2895 | */ |
| 2896 | #ifndef DISABLE_FASTBOOT_CMDS |
| 2897 | /* Register the following commands only for non-user builds */ |
| 2898 | {"flash:", cmd_flash}, |
| 2899 | {"erase:", cmd_erase}, |
| 2900 | {"boot", cmd_boot}, |
| 2901 | {"continue", cmd_continue}, |
| 2902 | {"reboot", cmd_reboot}, |
| 2903 | {"reboot-bootloader", cmd_reboot_bootloader}, |
| 2904 | {"oem unlock", cmd_oem_unlock}, |
| 2905 | {"oem lock", cmd_oem_lock}, |
| 2906 | {"oem verified", cmd_oem_verified}, |
| 2907 | {"oem device-info", cmd_oem_devinfo}, |
| 2908 | {"preflash", cmd_preflash}, |
| 2909 | {"oem enable-charger-screen", cmd_oem_enable_charger_screen}, |
| 2910 | {"oem disable-charger-screen", cmd_oem_disable_charger_screen}, |
Aravind Venkateswaran | bcca9b1 | 2014-11-04 17:04:01 -0800 | [diff] [blame] | 2911 | {"oem select-display-panel", cmd_oem_select_display_panel}, |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 2912 | #endif |
| 2913 | }; |
| 2914 | |
| 2915 | int fastboot_cmds_count = sizeof(cmd_list)/sizeof(cmd_list[0]); |
| 2916 | for (i = 1; i < fastboot_cmds_count; i++) |
| 2917 | fastboot_register(cmd_list[i].name,cmd_list[i].cb); |
| 2918 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 2919 | /* publish variables and their values */ |
| 2920 | fastboot_publish("product", TARGET(BOARD)); |
| 2921 | fastboot_publish("kernel", "lk"); |
| 2922 | fastboot_publish("serialno", sn_buf); |
| 2923 | |
| 2924 | /* |
| 2925 | * partition info is supported only for emmc partitions |
| 2926 | * Calling this for NAND prints some error messages which |
| 2927 | * is harmless but misleading. Avoid calling this for NAND |
| 2928 | * devices. |
| 2929 | */ |
| 2930 | if (target_is_emmc_boot()) |
| 2931 | publish_getvar_partition_info(part_info, ARRAY_SIZE(part_info)); |
| 2932 | |
| 2933 | /* Max download size supported */ |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 2934 | snprintf(max_download_size, MAX_RSP_SIZE, "\t0x%x", |
| 2935 | target_get_max_flash_size()); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 2936 | fastboot_publish("max-download-size", (const char *) max_download_size); |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 2937 | /* Is the charger screen check enabled */ |
| 2938 | snprintf(charger_screen_enabled, MAX_RSP_SIZE, "%d", |
| 2939 | device.charger_screen_enabled); |
| 2940 | fastboot_publish("charger-screen-enabled", |
| 2941 | (const char *) charger_screen_enabled); |
Unnati Gandhi | 62c8ab8 | 2014-01-24 11:01:01 +0530 | [diff] [blame] | 2942 | snprintf(panel_display_mode, MAX_RSP_SIZE, "%s", |
| 2943 | device.display_panel); |
| 2944 | fastboot_publish("display-panel", |
| 2945 | (const char *) panel_display_mode); |
Channagoud Kadabi | aafbbfc | 2015-03-04 17:52:56 -0800 | [diff] [blame] | 2946 | fastboot_publish("version-bootloader", (const char *) device.bootloader_version); |
| 2947 | fastboot_publish("version-baseband", (const char *) device.radio_version); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 2948 | } |
| 2949 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 2950 | void aboot_init(const struct app_descriptor *app) |
| 2951 | { |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 2952 | unsigned reboot_mode = 0; |
lijuang | 7287580 | 2015-02-10 10:35:12 +0800 | [diff] [blame] | 2953 | unsigned hard_reboot_mode = 0; |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 2954 | bool boot_into_fastboot = false; |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 2955 | |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 2956 | /* Setup page size information for nv storage */ |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 2957 | if (target_is_emmc_boot()) |
| 2958 | { |
Channagoud Kadabi | 749b0f8 | 2013-09-10 22:36:02 -0700 | [diff] [blame] | 2959 | page_size = mmc_page_size(); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 2960 | page_mask = page_size - 1; |
| 2961 | } |
| 2962 | else |
| 2963 | { |
| 2964 | page_size = flash_page_size(); |
| 2965 | page_mask = page_size - 1; |
| 2966 | } |
| 2967 | |
Deepa Dinamani | 0e163a4 | 2013-05-24 17:08:15 -0700 | [diff] [blame] | 2968 | ASSERT((MEMBASE + MEMSIZE) > MEMBASE); |
| 2969 | |
Ameya Thakur | 11cf1a6 | 2013-08-05 12:44:48 -0700 | [diff] [blame] | 2970 | read_device_info(&device); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2971 | |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 2972 | /* Display splash screen if enabled */ |
| 2973 | #if DISPLAY_SPLASH_SCREEN |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 2974 | #if NO_ALARM_DISPLAY |
| 2975 | if (!check_alarm_boot()) { |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 2976 | #endif |
lijuang | 99c02d8 | 2015-02-13 19:04:34 +0800 | [diff] [blame] | 2977 | dprintf(SPEW, "Display Init: Start\n"); |
| 2978 | target_display_init(device.display_panel); |
| 2979 | dprintf(SPEW, "Display Init: Done\n"); |
| 2980 | #if NO_ALARM_DISPLAY |
| 2981 | } |
| 2982 | #endif |
| 2983 | #endif |
Aravind Venkateswaran | 8f07624 | 2014-02-25 16:25:30 -0800 | [diff] [blame] | 2984 | |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 2985 | target_serialno((unsigned char *) sn_buf); |
Ajay Dudani | b06c05f | 2011-05-12 14:46:10 -0700 | [diff] [blame] | 2986 | dprintf(SPEW,"serial number: %s\n",sn_buf); |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 2987 | |
Dhaval Patel | 223ec95 | 2013-07-18 14:49:44 -0700 | [diff] [blame] | 2988 | memset(display_panel_buf, '\0', MAX_PANEL_BUF_SIZE); |
| 2989 | |
Matthew Qin | defd556 | 2014-07-11 18:02:40 +0800 | [diff] [blame] | 2990 | /* |
| 2991 | * Check power off reason if user force reset, |
| 2992 | * if yes phone will do normal boot. |
| 2993 | */ |
| 2994 | if (is_user_force_reset()) |
| 2995 | goto normal_boot; |
| 2996 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 2997 | /* Check if we should do something other than booting up */ |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 2998 | if (keys_get_state(KEY_VOLUMEUP) && keys_get_state(KEY_VOLUMEDOWN)) |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 2999 | { |
Pavel Nedev | a4c9d3a | 2013-05-15 14:42:34 +0300 | [diff] [blame] | 3000 | dprintf(ALWAYS,"dload mode key sequence detected\n"); |
| 3001 | if (set_download_mode(EMERGENCY_DLOAD)) |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 3002 | { |
Pavel Nedev | a4c9d3a | 2013-05-15 14:42:34 +0300 | [diff] [blame] | 3003 | dprintf(CRITICAL,"dload mode not supported by target\n"); |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 3004 | } |
| 3005 | else |
| 3006 | { |
Aparna Mallavarapu | 0751f7f | 2014-04-01 22:40:39 +0530 | [diff] [blame] | 3007 | reboot_device(DLOAD); |
Pavel Nedev | a4c9d3a | 2013-05-15 14:42:34 +0300 | [diff] [blame] | 3008 | dprintf(CRITICAL,"Failed to reboot into dload mode\n"); |
Ameya Thakur | 0b9c244 | 2013-05-10 13:22:56 -0700 | [diff] [blame] | 3009 | } |
| 3010 | boot_into_fastboot = true; |
| 3011 | } |
| 3012 | if (!boot_into_fastboot) |
| 3013 | { |
| 3014 | if (keys_get_state(KEY_HOME) || keys_get_state(KEY_VOLUMEUP)) |
| 3015 | boot_into_recovery = 1; |
| 3016 | if (!boot_into_recovery && |
| 3017 | (keys_get_state(KEY_BACK) || keys_get_state(KEY_VOLUMEDOWN))) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3018 | boot_into_fastboot = true; |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 3019 | } |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3020 | #if NO_KEYPAD_DRIVER |
Kinson Chik | 0b1c816 | 2011-08-31 16:31:57 -0700 | [diff] [blame] | 3021 | if (fastboot_trigger()) |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3022 | boot_into_fastboot = true; |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3023 | #endif |
Chandan Uddaraju | bedca15 | 2010-06-02 23:05:15 -0700 | [diff] [blame] | 3024 | |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 3025 | reboot_mode = check_reboot_mode(); |
lijuang | 7287580 | 2015-02-10 10:35:12 +0800 | [diff] [blame] | 3026 | hard_reboot_mode = check_hard_reboot_mode(); |
| 3027 | if (reboot_mode == RECOVERY_MODE || |
| 3028 | hard_reboot_mode == RECOVERY_HARD_RESET_MODE) { |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 3029 | boot_into_recovery = 1; |
lijuang | 7287580 | 2015-02-10 10:35:12 +0800 | [diff] [blame] | 3030 | } else if(reboot_mode == FASTBOOT_MODE || |
| 3031 | hard_reboot_mode == FASTBOOT_HARD_RESET_MODE) { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3032 | boot_into_fastboot = true; |
lijuang | 7287580 | 2015-02-10 10:35:12 +0800 | [diff] [blame] | 3033 | } else if(reboot_mode == ALARM_BOOT || |
| 3034 | hard_reboot_mode == RTC_HARD_RESET_MODE) { |
Matthew Qin | d886f3c | 2014-01-17 16:52:01 +0800 | [diff] [blame] | 3035 | boot_reason_alarm = true; |
Ajay Dudani | 7742129 | 2010-10-27 19:34:06 -0700 | [diff] [blame] | 3036 | } |
| 3037 | |
Matthew Qin | defd556 | 2014-07-11 18:02:40 +0800 | [diff] [blame] | 3038 | normal_boot: |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3039 | if (!boot_into_fastboot) |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3040 | { |
Amit Blay | 8e2731c | 2015-04-28 21:54:55 +0300 | [diff] [blame] | 3041 | #ifdef MDTP_SUPPORT |
| 3042 | /* Go through Firmware Lock verification before continue with boot process */ |
| 3043 | mdtp_fwlock_verify_lock(); |
| 3044 | display_image_on_screen(); |
| 3045 | #endif /* MDTP_SUPPORT */ |
| 3046 | |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3047 | if (target_is_emmc_boot()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3048 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3049 | if(emmc_recovery_init()) |
| 3050 | dprintf(ALWAYS,"error in emmc_recovery_init\n"); |
| 3051 | if(target_use_signed_kernel()) |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3052 | { |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3053 | if((device.is_unlocked) || (device.is_tampered)) |
| 3054 | { |
| 3055 | #ifdef TZ_TAMPER_FUSE |
| 3056 | set_tamper_fuse_cmd(); |
| 3057 | #endif |
| 3058 | #if USE_PCOM_SECBOOT |
| 3059 | set_tamper_flag(device.is_tampered); |
| 3060 | #endif |
| 3061 | } |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3062 | } |
Amit Blay | 6281ebc | 2015-01-11 14:44:08 +0200 | [diff] [blame] | 3063 | |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3064 | boot_linux_from_mmc(); |
Shashank Mittal | a003228 | 2011-08-26 14:50:11 -0700 | [diff] [blame] | 3065 | } |
Pavel Nedev | 5d91d41 | 2013-04-29 11:34:24 +0300 | [diff] [blame] | 3066 | else |
| 3067 | { |
| 3068 | recovery_init(); |
| 3069 | #if USE_PCOM_SECBOOT |
| 3070 | if((device.is_unlocked) || (device.is_tampered)) |
| 3071 | set_tamper_flag(device.is_tampered); |
| 3072 | #endif |
| 3073 | boot_linux_from_flash(); |
| 3074 | } |
| 3075 | dprintf(CRITICAL, "ERROR: Could not do normal boot. Reverting " |
| 3076 | "to fastboot mode.\n"); |
Shashank Mittal | d8c42bf | 2010-06-09 15:44:28 -0700 | [diff] [blame] | 3077 | } |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 3078 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3079 | /* We are here means regular boot did not happen. Start fastboot. */ |
Channagoud Kadabi | 4c4884e | 2013-04-09 17:12:13 -0700 | [diff] [blame] | 3080 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3081 | /* register aboot specific fastboot commands */ |
| 3082 | aboot_fastboot_register_commands(); |
Amol Jadi | 57abe4c | 2011-05-24 15:47:27 -0700 | [diff] [blame] | 3083 | |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3084 | /* dump partition table for debug info */ |
Kinson Chik | f1a4351 | 2011-07-14 11:28:39 -0700 | [diff] [blame] | 3085 | partition_dump(); |
Amol Jadi | 5edf355 | 2013-07-23 14:15:34 -0700 | [diff] [blame] | 3086 | |
| 3087 | /* initialize and start fastboot */ |
| 3088 | fastboot_init(target_get_scratch_address(), target_get_max_flash_size()); |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3089 | } |
| 3090 | |
Deepa Dinamani | 41fa8d6 | 2013-05-23 13:25:36 -0700 | [diff] [blame] | 3091 | uint32_t get_page_size() |
| 3092 | { |
| 3093 | return page_size; |
| 3094 | } |
| 3095 | |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3096 | /* |
| 3097 | * Calculated and save hash (SHA256) for non-signed boot image. |
| 3098 | * |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3099 | * @param image_addr - Boot image address |
| 3100 | * @param image_size - Size of the boot image |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3101 | * |
| 3102 | * @return int - 0 on success, negative value on failure. |
| 3103 | */ |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3104 | 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] | 3105 | { |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3106 | unsigned int digest[8]; |
| 3107 | #if IMAGE_VERIF_ALGO_SHA1 |
| 3108 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA1; |
| 3109 | #else |
| 3110 | uint32_t auth_algo = CRYPTO_AUTH_ALG_SHA256; |
| 3111 | #endif |
Amir Samuelov | 57a6fa2 | 2013-06-05 16:36:43 +0300 | [diff] [blame] | 3112 | |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3113 | target_crypto_init_params(); |
Veera Sundaram Sankaran | f991546 | 2014-12-09 11:54:59 -0800 | [diff] [blame] | 3114 | 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] | 3115 | |
| 3116 | save_kernel_hash_cmd(digest); |
Channagoud Kadabi | 82cf5c6 | 2014-08-24 22:17:34 -0700 | [diff] [blame] | 3117 | 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] | 3118 | |
| 3119 | return 0; |
| 3120 | } |
| 3121 | |
Brian Swetland | 9c4c075 | 2009-01-25 16:23:50 -0800 | [diff] [blame] | 3122 | APP_START(aboot) |
| 3123 | .init = aboot_init, |
| 3124 | APP_END |