blob: db58e21b373f434508ff627e718a99d8e85986ac [file] [log] [blame]
Ajay Dudania66de4f2009-11-22 08:57:39 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Shashank Mittal8e49dec2010-03-01 15:19:04 -08004 * Copyright (c) 2009-2010, Code Aurora Forum. 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
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080040#define LINUX_MACHTYPE 1007015
41
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -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,
Chandan Uddarajucc400c22010-01-22 17:19:09 -080059 .length = 40 /* 5MB */,
Ajay Dudania66de4f2009-11-22 08:57:39 -080060 .name = "boot",
61 },
62 {
Chandan Uddarajucc400c22010-01-22 17:19:09 -080063 .start = 40,
Ajay Dudanid43419e2010-02-10 13:17:39 -080064 .length =760 /* 95MB */,
Ajay Dudania66de4f2009-11-22 08:57:39 -080065 .name = "system",
66 },
67 {
Chandan Uddaraju2943fd62010-06-21 10:56:39 -070068 .start = 800,
69 .length = 8,
70 .name = "splash",
71 },
72 {
73 .start = 808,
Chandan Uddarajucc400c22010-01-22 17:19:09 -080074 .length = 40 /* 5MB */,
Ajay Dudania66de4f2009-11-22 08:57:39 -080075 .name = "cache",
76 },
77 {
Chandan Uddaraju2943fd62010-06-21 10:56:39 -070078 .start = 848,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080079 .length = VARIABLE_LENGTH,
80 .name = "userdata",
Chandan Uddarajude85d3f2010-01-05 16:32:33 -080081 },
82 {
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080083 .start = DIFF_START_ADDR,
Chandan Uddaraju535fa092010-01-26 19:14:48 -080084 .length = 12 /* 1.5MB */,
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -080085 .name = "persist",
86 },
87 {
88 .start = DIFF_START_ADDR,
89 .length = 40 /* 5MB */,
90 .name = "recovery",
Ajay Dudania66de4f2009-11-22 08:57:39 -080091 },
92};
93static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
94
95void smem_ptable_init(void);
96unsigned smem_get_apps_flash_start(void);
97
98void keypad_init(void);
99
David Ngbf2eb3c2009-12-09 23:48:07 -0800100int target_is_emmc_boot(void);
101
Ajay Dudania66de4f2009-11-22 08:57:39 -0800102void target_init(void)
103{
104 unsigned offset;
105 struct flash_info *flash_info;
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800106 unsigned total_num_of_blocks;
107 bool start_addr_changed = false;
108 unsigned next_ptr_start_adr = 0;
Ajay Dudania66de4f2009-11-22 08:57:39 -0800109 int i;
110
111 dprintf(INFO, "target_init()\n");
112
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800113#if (!ENABLE_NANDWRITE)
Ajay Dudania66de4f2009-11-22 08:57:39 -0800114 keys_init();
115 keypad_init();
Chandan Uddaraju852cd2c2009-12-17 14:28:28 -0800116#endif
Ajay Dudania66de4f2009-11-22 08:57:39 -0800117
David Ngbf2eb3c2009-12-09 23:48:07 -0800118 if (target_is_emmc_boot())
119 return;
120
Ajay Dudania66de4f2009-11-22 08:57:39 -0800121 ptable_init(&flash_ptable);
122 smem_ptable_init();
123
124 flash_init();
125 flash_info = flash_get_info();
126 ASSERT(flash_info);
127
128 offset = smem_get_apps_flash_start();
129 if (offset == 0xffffffff)
130 while(1);
131
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800132 total_num_of_blocks = (flash_info->block_size)/NUM_PAGES_PER_BLOCK;
133
Ajay Dudania66de4f2009-11-22 08:57:39 -0800134 for (i = 0; i < num_parts; i++) {
135 struct ptentry *ptn = &board_part_list[i];
136 unsigned len = ptn->length;
137
Chandan Uddaraju9e5ab962010-01-21 15:36:37 -0800138 if(len == VARIABLE_LENGTH)
139 {
140 start_addr_changed = true;
141 unsigned length_for_prt = 0;
142 unsigned j;
143 for (j = i+1; j < num_parts; j++)
144 {
145 struct ptentry *temp_ptn = &board_part_list[j];
146 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
147 length_for_prt += temp_ptn->length;
148 }
149 len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
150 ASSERT(len >= 0);
151 next_ptr_start_adr = ptn->start + len;
152 }
153 if((ptn->start == DIFF_START_ADDR) && (start_addr_changed))
154 {
155 ASSERT(next_ptr_start_adr);
156 ptn->start = next_ptr_start_adr;
157 next_ptr_start_adr = ptn->start + ptn->length;
158 }
Ajay Dudania66de4f2009-11-22 08:57:39 -0800159 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800160 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
Ajay Dudania66de4f2009-11-22 08:57:39 -0800161 }
162
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800163 smem_add_modem_partitions(&flash_ptable);
164
Ajay Dudania66de4f2009-11-22 08:57:39 -0800165 ptable_dump(&flash_ptable);
166 flash_set_ptable(&flash_ptable);
167}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800168
169unsigned board_machtype(void)
170{
171 return LINUX_MACHTYPE;
172}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800173
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800174void reboot_device(unsigned reboot_reason)
175{
176 reboot(reboot_reason);
177}
178
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800179unsigned check_reboot_mode(void)
180{
Chandan Uddaraju8a1d37c2010-01-06 12:04:28 -0800181 unsigned mode[2] = {0, 0};
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800182 unsigned int mode_len = sizeof(mode);
183 unsigned smem_status;
184
185 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
186 &mode, mode_len );
187 if(smem_status)
188 {
189 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
190 return 0;
191 }
Chandan Uddaraju8a1d37c2010-01-06 12:04:28 -0800192 return mode[0];
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800193}
Chandan Uddaraju7f5b9012010-02-06 16:37:48 -0800194
195void target_battery_charging_enable(unsigned enable, unsigned disconnect)
196{
197}