blob: 920a5b61e02fb0aa31a14c97667eff85c58397e2 [file] [log] [blame]
Ajay Dudania66de4f2009-11-22 08:57:39 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Duy Truongf3ac7b32013-02-13 01:07:28 -08004 * Copyright (c) 2009-2010, The Linux Foundation. All rights reserved.
Ajay Dudania66de4f2009-11-22 08:57:39 -08005 *
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 Uddarajude85d3f2010-01-05 16:32:33 -080038#include <smem.h>
Ajay Dudania66de4f2009-11-22 08:57:39 -080039
Shashank Mittal86b21482010-11-15 10:37:34 -080040#define LINUX_MACHTYPE 2710
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080041
Chandan Uddarajucc400c22010-01-22 17:19:09 -080042#define VARIABLE_LENGTH 0x10101010
43#define DIFF_START_ADDR 0xF0F0F0F0
44#define NUM_PAGES_PER_BLOCK 0x40
45
Ajay Dudania66de4f2009-11-22 08:57:39 -080046static struct ptable flash_ptable;
47
48/* for these partitions, start will be offset by either what we get from
49 * smem, or from the above offset if smem is not useful. Also, we should
50 * probably have smem_ptable code populate our flash_ptable.
51 *
52 * When smem provides us with a full partition table, we can get rid of
53 * this altogether.
54 *
55 */
56static struct ptentry board_part_list[] = {
57 {
58 .start = 0,
Ajay Dudani7298b632010-08-24 21:59:00 -070059 .length = 5 /* In MB */,
Ajay Dudania66de4f2009-11-22 08:57:39 -080060 .name = "boot",
61 },
62 {
Ajay Dudani7298b632010-08-24 21:59:00 -070063 .start = DIFF_START_ADDR,
David Ng3755bb82010-10-12 18:12:06 -070064 .length = 100 /* In MB */,
Ajay Dudania66de4f2009-11-22 08:57:39 -080065 .name = "system",
66 },
67 {
Ajay Dudani7298b632010-08-24 21:59:00 -070068 .start = DIFF_START_ADDR,
69 .length = 30 /* In MB */,
Ajay Dudania66de4f2009-11-22 08:57:39 -080070 .name = "cache",
71 },
72 {
Ajay Dudani7298b632010-08-24 21:59:00 -070073 .start = DIFF_START_ADDR,
74 .length = 1 /* In MB */,
Subbaraman Narayanamurthyeb92bcc2010-07-20 14:32:46 -070075 .name = "misc",
76 },
77 {
Ajay Dudani7298b632010-08-24 21:59:00 -070078 .start = DIFF_START_ADDR,
Chandan Uddarajucc400c22010-01-22 17:19:09 -080079 .length = VARIABLE_LENGTH,
80 .name = "userdata",
Chandan Uddarajuaeb979e2009-12-14 18:04:26 -080081 },
82 {
Chandan Uddarajucc400c22010-01-22 17:19:09 -080083 .start = DIFF_START_ADDR,
Ajay Dudani7298b632010-08-24 21:59:00 -070084 .length = 5 /* In MB */,
Chandan Uddarajucc400c22010-01-22 17:19:09 -080085 .name = "recovery",
Ajay Dudania66de4f2009-11-22 08:57:39 -080086 },
87};
88static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
89
90void smem_ptable_init(void);
91unsigned smem_get_apps_flash_start(void);
Ajay Dudani35f686f2011-07-22 13:12:09 -070092
Ajay Dudania66de4f2009-11-22 08:57:39 -080093void keypad_init(void);
94
95void target_init(void)
96{
97 unsigned offset;
98 struct flash_info *flash_info;
Chandan Uddarajucc400c22010-01-22 17:19:09 -080099 unsigned total_num_of_blocks;
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800100 unsigned next_ptr_start_adr = 0;
Ajay Dudani7298b632010-08-24 21:59:00 -0700101 unsigned blocks_per_1MB = 8; /* Default value of 2k page size on 256MB flash drive*/
Ajay Dudania66de4f2009-11-22 08:57:39 -0800102 int i;
103
104 dprintf(INFO, "target_init()\n");
105
Chandan Uddarajuaeb979e2009-12-14 18:04:26 -0800106#if (!ENABLE_NANDWRITE)
Ajay Dudania66de4f2009-11-22 08:57:39 -0800107 keys_init();
108 keypad_init();
Chandan Uddarajuaeb979e2009-12-14 18:04:26 -0800109#endif
Ajay Dudania66de4f2009-11-22 08:57:39 -0800110 ptable_init(&flash_ptable);
111 smem_ptable_init();
112
113 flash_init();
114 flash_info = flash_get_info();
115 ASSERT(flash_info);
116
117 offset = smem_get_apps_flash_start();
118 if (offset == 0xffffffff)
119 while(1);
120
Chandan Uddaraju40605112010-08-09 14:25:08 -0700121 total_num_of_blocks = flash_info->num_blocks;
Ajay Dudani7298b632010-08-24 21:59:00 -0700122 blocks_per_1MB = (1 << 20) / (flash_info->block_size);
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800123
Ajay Dudania66de4f2009-11-22 08:57:39 -0800124 for (i = 0; i < num_parts; i++) {
125 struct ptentry *ptn = &board_part_list[i];
Ajay Dudani7298b632010-08-24 21:59:00 -0700126 unsigned len = ((ptn->length) * blocks_per_1MB);
Ajay Dudania66de4f2009-11-22 08:57:39 -0800127
Ajay Dudani7298b632010-08-24 21:59:00 -0700128 if(ptn->start != 0)
129 ASSERT(ptn->start == DIFF_START_ADDR);
130
131 ptn->start = next_ptr_start_adr;
132
133 if(ptn->length == VARIABLE_LENGTH)
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800134 {
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800135 unsigned length_for_prt = 0;
136 unsigned j;
137 for (j = i+1; j < num_parts; j++)
138 {
139 struct ptentry *temp_ptn = &board_part_list[j];
140 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
Ajay Dudani7298b632010-08-24 21:59:00 -0700141 length_for_prt += ((temp_ptn->length) * blocks_per_1MB);
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800142 }
Ajay Dudani7298b632010-08-24 21:59:00 -0700143 len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800144 ASSERT(len >= 0);
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800145 }
Ajay Dudani7298b632010-08-24 21:59:00 -0700146
147 next_ptr_start_adr = ptn->start + len;
Ajay Dudania66de4f2009-11-22 08:57:39 -0800148 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800149 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
Ajay Dudania66de4f2009-11-22 08:57:39 -0800150 }
151
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800152 smem_add_modem_partitions(&flash_ptable);
153
Ajay Dudania66de4f2009-11-22 08:57:39 -0800154 ptable_dump(&flash_ptable);
155 flash_set_ptable(&flash_ptable);
156}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800157
158unsigned board_machtype(void)
159{
160 return LINUX_MACHTYPE;
161}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800162
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800163void reboot_device(unsigned reboot_reason)
164{
165 reboot(reboot_reason);
166}
167
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800168unsigned check_reboot_mode(void)
169{
170 unsigned mode[2] = {0, 0};
171 unsigned int mode_len = sizeof(mode);
172 unsigned smem_status;
173
174 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
175 &mode, mode_len );
176 if(smem_status)
177 {
178 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
179 return 0;
180 }
181 return mode[0];
182}