Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2009, Google Inc. |
| 3 | * All rights reserved. |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 4 | * Copyright (c) 2009-2011, The Linux Foundation. All rights reserved. |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * 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 |
| 13 | * the documentation and/or other materials provided with the |
| 14 | * distribution. |
| 15 | * * Neither the name of Google, Inc. nor the names of its contributors |
| 16 | * may be used to endorse or promote products derived from this |
| 17 | * software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 21 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 22 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 23 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 24 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 25 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| 26 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 27 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 28 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 29 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | * SUCH DAMAGE. |
| 31 | */ |
| 32 | |
Amol Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 33 | #include <reg.h> |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 34 | #include <debug.h> |
| 35 | #include <dev/keys.h> |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 36 | #include <lib/ptable.h> |
| 37 | #include <dev/flash.h> |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 38 | #include <smem.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 39 | #include <mmc.h> |
Subbaraman Narayanamurthy | 4b43c35 | 2010-09-24 13:20:52 -0700 | [diff] [blame] | 40 | #include <platform/iomap.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 41 | #include <platform.h> |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 42 | |
Srilakshmi Punuru | cfb5a46 | 2011-02-08 11:55:24 -0800 | [diff] [blame] | 43 | #define LINUX_MACHTYPE_7x27_SURF 2705 |
| 44 | #define LINUX_MACHTYPE_7x27_FFA 2706 |
| 45 | |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 46 | |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 47 | #define VARIABLE_LENGTH 0x10101010 |
| 48 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 49 | #define NUM_PAGES_PER_BLOCK 0x40 |
| 50 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 51 | static struct ptable flash_ptable; |
Subbaraman Narayanamurthy | 31c174e | 2011-02-04 12:35:09 -0800 | [diff] [blame] | 52 | static unsigned mmc_sdc_base[] = { MSM_SDC1_BASE, MSM_SDC2_BASE, MSM_SDC3_BASE, MSM_SDC4_BASE}; |
Srilakshmi Punuru | cfb5a46 | 2011-02-08 11:55:24 -0800 | [diff] [blame] | 53 | static int hw_platform_type = -1; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 54 | |
| 55 | /* for these partitions, start will be offset by either what we get from |
| 56 | * smem, or from the above offset if smem is not useful. Also, we should |
| 57 | * probably have smem_ptable code populate our flash_ptable. |
| 58 | * |
| 59 | * When smem provides us with a full partition table, we can get rid of |
| 60 | * this altogether. |
| 61 | * |
| 62 | */ |
| 63 | static struct ptentry board_part_list[] = { |
| 64 | { |
| 65 | .start = 0, |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 66 | .length = 5 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 67 | .name = "boot", |
| 68 | }, |
| 69 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 70 | .start = DIFF_START_ADDR, |
Channagoud Kadabi | 7252f11 | 2011-11-18 14:11:23 +0530 | [diff] [blame] | 71 | .length = 180 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 72 | .name = "system", |
| 73 | }, |
| 74 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 75 | .start = DIFF_START_ADDR, |
Ajay Dudani | a5362ef | 2011-01-28 20:05:15 -0800 | [diff] [blame] | 76 | .length = 4 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 77 | .name = "cache", |
| 78 | }, |
| 79 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 80 | .start = DIFF_START_ADDR, |
Ajay Dudani | 8199074 | 2011-03-23 17:00:37 -0700 | [diff] [blame] | 81 | .length = 4 /* In MB */, |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 82 | .name = "misc", |
| 83 | }, |
| 84 | { |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 85 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 86 | .length = VARIABLE_LENGTH, |
| 87 | .name = "userdata", |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 88 | }, |
| 89 | { |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 90 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | 49fd643 | 2010-08-12 12:06:54 -0700 | [diff] [blame] | 91 | .length = 2 /* In MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 92 | .name = "persist", |
| 93 | }, |
| 94 | { |
| 95 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 96 | .length = 5 /* In MB */, |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 97 | .name = "recovery", |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 98 | }, |
| 99 | }; |
| 100 | static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry); |
| 101 | |
| 102 | void smem_ptable_init(void); |
| 103 | unsigned smem_get_apps_flash_start(void); |
| 104 | |
| 105 | void keypad_init(void); |
| 106 | |
David Ng | bf2eb3c | 2009-12-09 23:48:07 -0800 | [diff] [blame] | 107 | int target_is_emmc_boot(void); |
| 108 | |
Subbaraman Narayanamurthy | 31c174e | 2011-02-04 12:35:09 -0800 | [diff] [blame] | 109 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 110 | void target_init(void) |
| 111 | { |
| 112 | unsigned offset; |
| 113 | struct flash_info *flash_info; |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 114 | unsigned total_num_of_blocks; |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 115 | unsigned next_ptr_start_adr = 0; |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 116 | unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/ |
Subbaraman Narayanamurthy | 31c174e | 2011-02-04 12:35:09 -0800 | [diff] [blame] | 117 | unsigned char slot; |
| 118 | unsigned int base_addr; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 119 | int i; |
| 120 | |
| 121 | dprintf(INFO, "target_init()\n"); |
| 122 | |
Kinson Chik | ce306ff | 2011-07-08 15:23:33 -0700 | [diff] [blame] | 123 | /* Display splash screen if enabled */ |
| 124 | #if DISPLAY_SPLASH_SCREEN |
| 125 | display_init(); |
| 126 | dprintf(SPEW, "Diplay initialized\n"); |
| 127 | display_image_on_screen(); |
| 128 | #endif |
| 129 | |
Chandan Uddaraju | 852cd2c | 2009-12-17 14:28:28 -0800 | [diff] [blame] | 130 | #if (!ENABLE_NANDWRITE) |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 131 | keys_init(); |
| 132 | keypad_init(); |
Chandan Uddaraju | 852cd2c | 2009-12-17 14:28:28 -0800 | [diff] [blame] | 133 | #endif |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 134 | |
David Ng | bf2eb3c | 2009-12-09 23:48:07 -0800 | [diff] [blame] | 135 | if (target_is_emmc_boot()) |
Ajay Dudani | 2676ea9 | 2010-08-10 07:15:45 -0700 | [diff] [blame] | 136 | { |
Amol Jadi | 2dfe339 | 2011-07-19 16:03:37 -0700 | [diff] [blame] | 137 | /* Must wait for modem-up before we can intialize MMC. |
| 138 | */ |
| 139 | while (readl(MSM_SHARED_BASE + 0x14) != 1); |
| 140 | |
Subbaraman Narayanamurthy | 31c174e | 2011-02-04 12:35:09 -0800 | [diff] [blame] | 141 | /* Trying SDC3 first */ |
| 142 | slot = 3; |
| 143 | base_addr = mmc_sdc_base[slot - 1]; |
| 144 | if(mmc_boot_main(slot, base_addr)) |
Subbaraman Narayanamurthy | 4b43c35 | 2010-09-24 13:20:52 -0700 | [diff] [blame] | 145 | { |
Subbaraman Narayanamurthy | 31c174e | 2011-02-04 12:35:09 -0800 | [diff] [blame] | 146 | /* Trying SDC1 next */ |
| 147 | slot = 1; |
| 148 | base_addr = mmc_sdc_base[slot - 1]; |
| 149 | if(mmc_boot_main(slot, base_addr)) |
| 150 | { |
| 151 | dprintf(CRITICAL, "mmc init failed!"); |
| 152 | ASSERT(0); |
| 153 | } |
Subbaraman Narayanamurthy | 4b43c35 | 2010-09-24 13:20:52 -0700 | [diff] [blame] | 154 | } |
David Ng | bf2eb3c | 2009-12-09 23:48:07 -0800 | [diff] [blame] | 155 | return; |
Ajay Dudani | 2676ea9 | 2010-08-10 07:15:45 -0700 | [diff] [blame] | 156 | } |
David Ng | bf2eb3c | 2009-12-09 23:48:07 -0800 | [diff] [blame] | 157 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 158 | ptable_init(&flash_ptable); |
| 159 | smem_ptable_init(); |
| 160 | |
| 161 | flash_init(); |
| 162 | flash_info = flash_get_info(); |
| 163 | ASSERT(flash_info); |
| 164 | |
| 165 | offset = smem_get_apps_flash_start(); |
| 166 | if (offset == 0xffffffff) |
| 167 | while(1); |
| 168 | |
Chandan Uddaraju | 4060511 | 2010-08-09 14:25:08 -0700 | [diff] [blame] | 169 | total_num_of_blocks = flash_info->num_blocks; |
| 170 | blocks_per_1MB = (1 << 20) / (flash_info->block_size); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 171 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 172 | for (i = 0; i < num_parts; i++) { |
| 173 | struct ptentry *ptn = &board_part_list[i]; |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 174 | unsigned len = ((ptn->length) * blocks_per_1MB); |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 175 | |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 176 | if(ptn->start != 0) |
| 177 | ASSERT(ptn->start == DIFF_START_ADDR); |
| 178 | |
| 179 | ptn->start = next_ptr_start_adr; |
| 180 | |
| 181 | if(ptn->length == VARIABLE_LENGTH) |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 182 | { |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 183 | unsigned length_for_prt = 0; |
| 184 | unsigned j; |
| 185 | for (j = i+1; j < num_parts; j++) |
| 186 | { |
| 187 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 188 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 189 | length_for_prt += ((temp_ptn->length) * blocks_per_1MB); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 190 | } |
Shashank Mittal | 04059b7 | 2011-03-15 20:37:28 -0700 | [diff] [blame] | 191 | len = total_num_of_blocks - (offset + ptn->start + length_for_prt); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 192 | ASSERT(len >= 0); |
Chandan Uddaraju | 9e5ab96 | 2010-01-21 15:36:37 -0800 | [diff] [blame] | 193 | } |
Chandan Uddaraju | a7e8ffe | 2010-07-27 11:08:31 -0700 | [diff] [blame] | 194 | next_ptr_start_adr = ptn->start + len; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 195 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 196 | len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE); |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 199 | smem_add_modem_partitions(&flash_ptable); |
| 200 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 201 | ptable_dump(&flash_ptable); |
| 202 | flash_set_ptable(&flash_ptable); |
| 203 | } |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 204 | |
| 205 | unsigned board_machtype(void) |
| 206 | { |
Srilakshmi Punuru | cfb5a46 | 2011-02-08 11:55:24 -0800 | [diff] [blame] | 207 | struct smem_board_info_v2 board_info_v2; |
| 208 | unsigned int board_info_len = 0; |
| 209 | enum platform platform_type = 0; |
| 210 | unsigned smem_status; |
| 211 | unsigned format = 0; |
| 212 | |
| 213 | if(hw_platform_type != -1) |
| 214 | return hw_platform_type; |
| 215 | |
| 216 | smem_status = smem_read_alloc_entry_offset(SMEM_BOARD_INFO_LOCATION, |
| 217 | &format, sizeof(format), 0); |
| 218 | if(!smem_status) |
| 219 | { |
| 220 | if(format == 2) |
| 221 | { |
| 222 | board_info_len = sizeof(board_info_v2); |
| 223 | |
| 224 | smem_status = smem_read_alloc_entry(SMEM_BOARD_INFO_LOCATION, |
| 225 | &board_info_v2, board_info_len); |
| 226 | if(!smem_status) |
| 227 | { |
| 228 | char *build_type = (char *)(board_info_v2.build_id)+ 12; |
| 229 | switch (*build_type) |
| 230 | { |
| 231 | case 'F': |
| 232 | hw_platform_type = LINUX_MACHTYPE_7x27_FFA; break; |
| 233 | case 'S': |
| 234 | hw_platform_type = LINUX_MACHTYPE_7x27_SURF; break; |
| 235 | default: |
| 236 | hw_platform_type = LINUX_MACHTYPE_7x27_SURF; break; |
| 237 | } |
| 238 | } |
| 239 | } |
| 240 | } else { |
| 241 | hw_platform_type = LINUX_MACHTYPE_7x27_SURF; |
| 242 | } |
| 243 | return hw_platform_type; |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 244 | } |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 245 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 246 | void reboot_device(unsigned reboot_reason) |
| 247 | { |
| 248 | reboot(reboot_reason); |
| 249 | } |
| 250 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 251 | unsigned check_reboot_mode(void) |
| 252 | { |
Chandan Uddaraju | 8a1d37c | 2010-01-06 12:04:28 -0800 | [diff] [blame] | 253 | unsigned mode[2] = {0, 0}; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 254 | unsigned int mode_len = sizeof(mode); |
| 255 | unsigned smem_status; |
| 256 | |
| 257 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
| 258 | &mode, mode_len ); |
| 259 | if(smem_status) |
| 260 | { |
| 261 | dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n"); |
| 262 | return 0; |
| 263 | } |
Chandan Uddaraju | 8a1d37c | 2010-01-06 12:04:28 -0800 | [diff] [blame] | 264 | return mode[0]; |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 265 | } |
Chandan Uddaraju | 7f5b901 | 2010-02-06 16:37:48 -0800 | [diff] [blame] | 266 | |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 267 | static unsigned target_check_power_on_reason(void) |
| 268 | { |
| 269 | unsigned power_on_status = 0; |
| 270 | unsigned int status_len = sizeof(power_on_status); |
| 271 | unsigned smem_status; |
| 272 | |
| 273 | smem_status = smem_read_alloc_entry(SMEM_POWER_ON_STATUS_INFO, |
| 274 | &power_on_status, status_len); |
Ajay Dudani | 35f686f | 2011-07-22 13:12:09 -0700 | [diff] [blame] | 275 | |
Subbaraman Narayanamurthy | bd2424e | 2011-03-29 15:29:21 -0700 | [diff] [blame] | 276 | if (smem_status) |
David Ng | f773dde | 2010-07-26 19:55:08 -0700 | [diff] [blame] | 277 | { |
| 278 | dprintf(CRITICAL, "ERROR: unable to read shared memory for power on reason\n"); |
| 279 | } |
| 280 | |
| 281 | return power_on_status; |
| 282 | } |
| 283 | |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 284 | #if _EMMC_BOOT |
| 285 | void target_serialno(unsigned char *buf) |
| 286 | { |
| 287 | unsigned int serialno; |
| 288 | serialno = mmc_get_psn(); |
| 289 | sprintf(buf,"%x",serialno); |
| 290 | } |
Subbaraman Narayanamurthy | 0e445b0 | 2011-06-19 21:34:46 -0700 | [diff] [blame] | 291 | |
| 292 | int emmc_recovery_init(void) |
| 293 | { |
| 294 | int rc; |
| 295 | rc = _emmc_recovery_init(); |
| 296 | return rc; |
| 297 | } |
Subbaraman Narayanamurthy | f17b4ae | 2011-02-16 20:19:56 -0800 | [diff] [blame] | 298 | #endif |