blob: e686d5b3338035b23b506c3a334ae97f2cf7e1fe [file] [log] [blame]
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -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.
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -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>
38#include <smem.h>
39
40#define LINUX_MACHTYPE 1007003
41
42static struct ptable flash_ptable;
43
44/* for these partitions, start will be offset by either what we get from
45 * smem, or from the above offset if smem is not useful. Also, we should
46 * probably have smem_ptable code populate our flash_ptable.
47 *
48 * When smem provides us with a full partition table, we can get rid of
49 * this altogether.
50 *
51 */
52static struct ptentry board_part_list[] = {
53 {
54 .start = 0,
55 .length = 40,
56 .name = "boot",
57 },
58 {
Ajay Dudanid43419e2010-02-10 13:17:39 -080059 .start = 40,
60 .length = 680 /* 85MB */,
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -080061 .name = "system",
62 },
63 {
Ajay Dudanid43419e2010-02-10 13:17:39 -080064 .start = 720,
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -080065 .length = 40 /* 5MB */,
66 .name = "cache",
67 },
68 {
Ajay Dudanid43419e2010-02-10 13:17:39 -080069 .start = 760,
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -080070 .length = 40 /* 5MB */,
71 .name = "recovery",
72 },
73 {
Ajay Dudanid43419e2010-02-10 13:17:39 -080074 .start = 800,
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -080075 .length = 720 /* 90MB */,
76 .name = "userdata",
77 },
78};
79static int num_parts = sizeof(board_part_list)/sizeof(struct ptentry);
80
81void smem_ptable_init(void);
82unsigned smem_get_apps_flash_start(void);
83
84void keypad_init(void);
85
86int target_is_emmc_boot(void);
87
88void target_init(void)
89{
90 unsigned offset;
91 struct flash_info *flash_info;
92 int i;
93
94 dprintf(INFO, "target_init()\n");
95
96#if (!ENABLE_NANDWRITE)
97 keys_init();
98 keypad_init();
99#endif
100
101 if (target_is_emmc_boot())
102 return;
103
104 ptable_init(&flash_ptable);
105 smem_ptable_init();
106
107 flash_init();
108 flash_info = flash_get_info();
109 ASSERT(flash_info);
110
111 offset = smem_get_apps_flash_start();
112 if (offset == 0xffffffff)
113 while(1);
114
115 for (i = 0; i < num_parts; i++) {
116 struct ptentry *ptn = &board_part_list[i];
117 unsigned len = ptn->length;
118
119 if ((len == 0) && (i == num_parts - 1))
120 len = flash_info->num_blocks - offset - ptn->start;
121 ptable_add(&flash_ptable, ptn->name, offset + ptn->start,
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800122 len, ptn->flags, TYPE_APPS_PARTITION, PERM_WRITEABLE);
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -0800123 }
124
Shashank Mittal8e49dec2010-03-01 15:19:04 -0800125 smem_add_modem_partitions(&flash_ptable);
126
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -0800127 ptable_dump(&flash_ptable);
128 flash_set_ptable(&flash_ptable);
129}
130
131unsigned board_machtype(void)
132{
133 return LINUX_MACHTYPE;
134}
135
Chandan Uddaraju94183c02010-01-15 15:13:59 -0800136void reboot_device(unsigned reboot_reason)
137{
138 reboot(reboot_reason);
139}
140
Chandan Uddarajue0adbdb2010-01-09 23:12:46 -0800141unsigned check_reboot_mode(void)
142{
143 unsigned mode[2] = {0, 0};
144 unsigned int mode_len = sizeof(mode);
145 unsigned smem_status;
146
147 smem_status = smem_read_alloc_entry(SMEM_APPS_BOOT_MODE,
148 &mode, mode_len );
149 if(smem_status)
150 {
151 dprintf(CRITICAL, "ERROR: unable to read shared memory for reboot mode\n");
152 return 0;
153 }
154 return mode[0];
155}