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 | |
| 33 | #include <debug.h> |
| 34 | #include <dev/keys.h> |
| 35 | #include <dev/gpio_keypad.h> |
| 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 <platform.h> |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 40 | |
Shashank Mittal | 86b2148 | 2010-11-15 10:37:34 -0800 | [diff] [blame] | 41 | #define LINUX_MACHTYPE 2708 |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 42 | |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 43 | #define VARIABLE_LENGTH 0x10101010 |
| 44 | #define DIFF_START_ADDR 0xF0F0F0F0 |
| 45 | #define NUM_PAGES_PER_BLOCK 0x40 |
| 46 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 47 | static struct ptable flash_ptable; |
| 48 | |
| 49 | /* for these partitions, start will be offset by either what we get from |
| 50 | * smem, or from the above offset if smem is not useful. Also, we should |
| 51 | * probably have smem_ptable code populate our flash_ptable. |
| 52 | * |
| 53 | * When smem provides us with a full partition table, we can get rid of |
| 54 | * this altogether. |
| 55 | * |
| 56 | */ |
| 57 | static struct ptentry board_part_list[] = { |
| 58 | { |
| 59 | .start = 0, |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 60 | .length = 5 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 61 | .name = "boot", |
| 62 | }, |
| 63 | { |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 64 | .start = DIFF_START_ADDR, |
David Ng | 3755bb8 | 2010-10-12 18:12:06 -0700 | [diff] [blame] | 65 | .length = 100 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 66 | .name = "system", |
| 67 | }, |
| 68 | { |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 69 | .start = DIFF_START_ADDR, |
| 70 | .length = 30 /* In MB */, |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 71 | .name = "cache", |
| 72 | }, |
| 73 | { |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 74 | .start = DIFF_START_ADDR, |
| 75 | .length = 1 /* In MB */, |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 76 | .name = "misc", |
| 77 | }, |
| 78 | { |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 79 | .start = DIFF_START_ADDR, |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 80 | .length = VARIABLE_LENGTH, |
| 81 | .name = "userdata", |
Chandan Uddaraju | aeb979e | 2009-12-14 18:04:26 -0800 | [diff] [blame] | 82 | }, |
| 83 | { |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 84 | .start = DIFF_START_ADDR, |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 85 | .length = 5 /* In MB */, |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 86 | .name = "recovery", |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 87 | }, |
| 88 | }; |
| 89 | static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry); |
| 90 | |
| 91 | void smem_ptable_init(void); |
| 92 | unsigned smem_get_apps_flash_start(void); |
Ajay Dudani | 35f686f | 2011-07-22 13:12:09 -0700 | [diff] [blame] | 93 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 94 | void keypad_init(void); |
| 95 | |
| 96 | void target_init(void) |
| 97 | { |
| 98 | unsigned offset; |
| 99 | struct flash_info *flash_info; |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 100 | unsigned total_num_of_blocks; |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 101 | unsigned next_ptr_start_adr = 0; |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 102 | unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/ |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 103 | int i; |
| 104 | |
| 105 | dprintf(INFO, "target_init()\n"); |
| 106 | |
Chandan Uddaraju | aeb979e | 2009-12-14 18:04:26 -0800 | [diff] [blame] | 107 | #if (!ENABLE_NANDWRITE) |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 108 | keys_init(); |
| 109 | keypad_init(); |
Chandan Uddaraju | aeb979e | 2009-12-14 18:04:26 -0800 | [diff] [blame] | 110 | #endif |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 111 | ptable_init(&flash_ptable); |
| 112 | smem_ptable_init(); |
| 113 | |
| 114 | flash_init(); |
| 115 | flash_info = flash_get_info(); |
| 116 | ASSERT(flash_info); |
| 117 | |
| 118 | offset = smem_get_apps_flash_start(); |
| 119 | if (offset == 0xffffffff) |
| 120 | while(1); |
| 121 | |
Chandan Uddaraju | 4060511 | 2010-08-09 14:25:08 -0700 | [diff] [blame] | 122 | total_num_of_blocks = flash_info->num_blocks; |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 123 | blocks_per_1MB = (1 << 20) / (flash_info->block_size); |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 124 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 125 | for (i = 0; i < num_parts; i++) { |
| 126 | struct ptentry *ptn = &board_part_list[i]; |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 127 | unsigned len = ((ptn->length) * blocks_per_1MB); |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 128 | |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 129 | if(ptn->start != 0) |
| 130 | ASSERT(ptn->start == DIFF_START_ADDR); |
| 131 | |
| 132 | ptn->start = next_ptr_start_adr; |
| 133 | |
| 134 | if(ptn->length == VARIABLE_LENGTH) |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 135 | { |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 136 | unsigned length_for_prt = 0; |
| 137 | unsigned j; |
| 138 | for (j = i+1; j < num_parts; j++) |
| 139 | { |
| 140 | struct ptentry *temp_ptn = &board_part_list[j]; |
| 141 | ASSERT(temp_ptn->length != VARIABLE_LENGTH); |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 142 | length_for_prt += ((temp_ptn->length) * blocks_per_1MB); |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 143 | } |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 144 | len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt); |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 145 | ASSERT(len >= 0); |
Chandan Uddaraju | cc400c2 | 2010-01-22 17:19:09 -0800 | [diff] [blame] | 146 | } |
Ajay Dudani | 7298b63 | 2010-08-24 21:59:00 -0700 | [diff] [blame] | 147 | |
| 148 | next_ptr_start_adr = ptn->start + len; |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 149 | ptable_add(&flash_ptable, ptn->name, offset + ptn->start, |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 150 | len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE); |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 151 | } |
| 152 | |
Shashank Mittal | 8e49dec | 2010-03-01 15:19:04 -0800 | [diff] [blame] | 153 | smem_add_modem_partitions(&flash_ptable); |
| 154 | |
Chandan Uddaraju | 8adde5a | 2009-11-17 11:31:28 -0800 | [diff] [blame] | 155 | ptable_dump(&flash_ptable); |
| 156 | flash_set_ptable(&flash_ptable); |
| 157 | } |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 158 | |
| 159 | unsigned board_machtype(void) |
| 160 | { |
| 161 | return LINUX_MACHTYPE; |
| 162 | } |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 163 | |
Chandan Uddaraju | 94183c0 | 2010-01-15 15:13:59 -0800 | [diff] [blame] | 164 | void reboot_device(unsigned reboot_reason) |
| 165 | { |
| 166 | reboot(reboot_reason); |
| 167 | } |
| 168 | |
Chandan Uddaraju | de85d3f | 2010-01-05 16:32:33 -0800 | [diff] [blame] | 169 | unsigned check_reboot_mode(void) |
| 170 | { |
| 171 | unsigned mode[2] = {0, 0}; |
| 172 | unsigned int mode_len = sizeof(mode); |
| 173 | unsigned smem_status; |
| 174 | |
| 175 | smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE, |
| 176 | &mode, mode_len ); |
| 177 | if(smem_status) |
| 178 | { |
| 179 | dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n"); |
| 180 | return 0; |
| 181 | } |
| 182 | return mode[0]; |
| 183 | } |