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