blob: 03ddf2354bc65c852035b6f075bf70862d219488 [file] [log] [blame]
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -08001/*
2 * Copyright (c) 2009, Google Inc.
3 * All rights reserved.
Ajay Dudani32edd472009-11-25 14:43:14 -08004 * Copyright (c) 2009, Code Aurora Forum. All rights reserved.
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -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>
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080039
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080040#define LINUX_MACHTYPE 1008000
41
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
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -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 */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080060 .name = "boot",
61 },
62 {
Chandan Uddarajucc400c22010-01-22 17:19:09 -080063 .start = 40,
64 .length = 680 /* 85MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080065 .name = "system",
66 },
67 {
Chandan Uddarajucc400c22010-01-22 17:19:09 -080068 .start = 720,
Chandan Uddarajuaeb979e2009-12-14 18:04:26 -080069 .length = 40 /* 5MB */,
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080070 .name = "cache",
71 },
72 {
Chandan Uddarajucc400c22010-01-22 17:19:09 -080073 .start = 760,
74 .length = VARIABLE_LENGTH,
75 .name = "userdata",
Chandan Uddarajuaeb979e2009-12-14 18:04:26 -080076 },
77 {
Chandan Uddarajucc400c22010-01-22 17:19:09 -080078 .start = DIFF_START_ADDR,
79 .length = 40 /* 5MB */,
80 .name = "recovery",
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080081 },
82};
83static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
84
85void smem_ptable_init(void);
86unsigned smem_get_apps_flash_start(void);
87
88void keypad_init(void);
89
90void target_init(void)
91{
92 unsigned offset;
93 struct flash_info *flash_info;
Chandan Uddarajucc400c22010-01-22 17:19:09 -080094 unsigned total_num_of_blocks;
95 bool start_addr_changed = false;
96 unsigned next_ptr_start_adr = 0;
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -080097 int i;
98
99 dprintf(INFO, "target_init()\n");
100
Chandan Uddarajuaeb979e2009-12-14 18:04:26 -0800101#if (!ENABLE_NANDWRITE)
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800102 keys_init();
103 keypad_init();
Chandan Uddarajuaeb979e2009-12-14 18:04:26 -0800104#endif
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800105 ptable_init(&flash_ptable);
106 smem_ptable_init();
107
108 flash_init();
109 flash_info = flash_get_info();
110 ASSERT(flash_info);
111
112 offset = smem_get_apps_flash_start();
113 if (offset == 0xffffffff)
114 while(1);
115
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800116 total_num_of_blocks = (flash_info->block_size)/NUM_PAGES_PER_BLOCK;
117
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800118 for (i = 0; i < num_parts; i++) {
119 struct ptentry *ptn = &board_part_list[i];
120 unsigned len = ptn->length;
121
Chandan Uddarajucc400c22010-01-22 17:19:09 -0800122 if(len == VARIABLE_LENGTH)
123 {
124 start_addr_changed = true;
125 unsigned length_for_prt = 0;
126 unsigned j;
127 for (j = i+1; j < num_parts; j++)
128 {
129 struct ptentry *temp_ptn = &board_part_list[j];
130 ASSERT(temp_ptn->length != VARIABLE_LENGTH);
131 length_for_prt += temp_ptn->length;
132 }
133 len = (total_num_of_blocks - 1) - (offset + ptn->start + length_for_prt);
134 ASSERT(len >= 0);
135 next_ptr_start_adr = ptn->start + len;
136 }
137 if((ptn->start == DIFF_START_ADDR) && (start_addr_changed))
138 {
139 ASSERT(next_ptr_start_adr);
140 ptn->start = next_ptr_start_adr;
141 next_ptr_start_adr = ptn->start + ptn->length;
142 }
Chandan Uddaraju8adde5a2009-11-17 11:31:28 -0800143 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
144 len, ptn->flags);
145 }
146
147 ptable_dump(&flash_ptable);
148 flash_set_ptable(&flash_ptable);
149}
Chandan Uddaraju885e4db2009-12-03 22:45:26 -0800150
151unsigned board_machtype(void)
152{
153 return LINUX_MACHTYPE;
154}
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800155
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800156void reboot_device(unsigned reboot_reason)
157{
158 reboot(reboot_reason);
159}
160
Chandan Uddarajude85d3f2010-01-05 16:32:33 -0800161unsigned check_reboot_mode(void)
162{
163 unsigned mode[2] = {0, 0};
164 unsigned int mode_len = sizeof(mode);
165 unsigned smem_status;
166
167 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
168 &mode, mode_len );
169 if(smem_status)
170 {
171 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
172 return 0;
173 }
174 return mode[0];
175}